20 #include "ns3/node-container.h"
21 #include "ns3/tcp-socket-base.h"
22 #include "ns3/simple-net-device-helper.h"
23 #include "ns3/ipv4-address-helper.h"
24 #include "ns3/internet-stack-helper.h"
26 #include "ns3/tcp-l4-protocol.h"
27 #include "../model/ipv4-end-point.h"
28 #include "../model/ipv6-end-point.h"
36 uint32_t pktSize, uint32_t pktCount,
37 const Time& pktInterval,
39 uint32_t initialSlowStartThresh, uint32_t initialCwnd,
44 m_congControlTypeId (congestionControl),
45 m_propagationDelay (propagationDelay),
46 m_startTime (startTime),
49 m_pktCount (pktCount),
50 m_interPacketInterval (pktInterval),
51 m_initialSlowStartThresh (initialSlowStartThresh),
52 m_initialCwnd (initialCwnd),
53 m_segmentSize (segmentSize),
71 while ((packet = socket->
RecvFrom (from)))
82 uint32_t pktCount,
Time pktInterval )
88 socket->
Send (Create<Packet> (pktSize));
90 socket, pktSize, pktCount - 1, pktInterval);
132 senderDev->SetMtu (
m_mtu);
133 senderDev->GetQueue ()->TraceConnect (
"Drop",
"SENDER",
135 senderDev->TraceConnect (
"PhyRxDrop",
"sender",
138 receiverDev->SetMtu (
m_mtu);
139 receiverDev->GetQueue ()->TraceConnect (
"Drop",
"RECEIVER",
141 receiverDev->TraceConnect (
"PhyRxDrop",
"RECEIVER",
144 senderDev->SetReceiveErrorModel (senderEM);
145 receiverDev->SetReceiveErrorModel (receiverEM);
148 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
240 congestionAlgorithmFactory.
SetTypeId (congControl);
247 socket->SetNode (node);
249 socket->SetRtt (rtt);
250 socket->SetCongestionControlAlgorithm (algo);
286 if (context.compare (
"SENDER") == 0)
290 else if (context.compare (
"RECEIVER") == 0)
296 NS_FATAL_ERROR (
"Packet dropped in a queue, but queue not recognized");
303 if (context.compare (
"SENDER") == 0)
307 else if (context.compare (
"RECEIVER") == 0)
313 NS_FATAL_ERROR (
"Packet dropped in a queue, but queue not recognized");
466 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_retxThresh;
483 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_dupAckCount;
500 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_delAckMaxCount;
551 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_rto.Get ();
585 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_cnTimeout;
619 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_clockGranularity;
623 return DynamicCast<TcpSocketMsgBase> (
m_receiverSocket)->m_clockGranularity;
636 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_state.Get ();
654 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_rWnd.Get ();
672 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_persistEvent;
690 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_persistTimeout;
745 .SetGroupName (
"Internet")
754 return CopyObject<TcpSocketMsgBase> (
this);
823 .SetGroupName (
"Internet")
879 NS_LOG_WARN (
"Failed to send empty packet due to null endpoint");
895 header.SetFlags (flags);
896 header.SetSequenceNumber (s);
899 if (hasSyn || hasFin)
901 header.SetAckNumber (
m_rxBuffer->NextRxSequence ());
920 header.SetAckNumber (ackSeq);
978 NS_LOG_LOGIC (
"Schedule retransmission timeout at time "
994 return CopyObject<TcpSocketSmallAcks> (
this);
virtual void ProcessedAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who)
Processed ack.
Ipv6Address GetLocalAddress()
Get the local address.
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
Time GetMinRto(SocketWho who)
Get the minimun RTO attribute.
Simulation virtual time values and global simulation resolution.
virtual void DoTeardown(void)
Teardown the TCP test.
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
Time GetPersistentTimeout(SocketWho who)
Get the persistent timeout of the selected socket.
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void SendEmptyPacket(uint8_t flags)
Send empty packet, copied/pasted from TcpSocketBase.
Ptr< TcpSocketMsgBase > m_senderSocket
Pointer to sender socket.
void PhyDropCb(std::string context, Ptr< const Packet > p)
Time m_propagationDelay
Propagation delay of the channel.
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
uint32_t GetDelAckCount(SocketWho who)
Get the number of delayed ack (if present)
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
Class for inserting callbacks special points of the flow of TCP sockets.
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
holds a vector of std::pair of Ptr and interface index.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
uint32_t m_synRetries
Number of connection attempts.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
void SetForkCb(Callback< void, Ptr< TcpSocketMsgBase > > cb)
Set the callback invoked after the forking.
virtual void DoRun(void)
Execute the tcp test.
void NormalCloseCb(Ptr< Socket > socket)
EventId m_retxEvent
Retransmission event.
virtual void PhyDrop(SocketWho who)
Link drop.
void QueueDropCb(std::string context, Ptr< const Packet > p)
virtual void ErrorClose(SocketWho who)
Socket closed with an error.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
bool IsNull(void) const
Check for null implementation.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
virtual void FinalChecks()
Performs the (eventual) final checks through test asserts.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< TcpSocketState > m_tcb
Congestion control informations.
void DoConnect()
Scheduled at 0.0, SENDER starts the connection to RECEIVER.
void SendPacket(Ptr< Socket > socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval)
Send packets to other endpoint.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
aggregate IP/TCP/UDP functionality to existing Nodes.
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
bool IsManualIpTos(void) const
Checks if the socket has a specific IPv4 ToS set.
void SetCloseCallbacks(Callback< void, Ptr< Socket > > normalClose, Callback< void, Ptr< Socket > > errorClose)
Detect socket recv() events such as graceful shutdown or error.
AckManagementCallback m_rcvAckCb
Both sides have shutdown but we still have data we have to finish sending.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
Time m_cnTimeout
Timeout for connection retry.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Callback< R > MakeNullCallback(void)
static TypeId GetTypeId(void)
Get the type ID.
void SetTos(uint8_t tos)
Set the tag's TOS.
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.
virtual void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received an ACK packet.
T Get(void) const
Get the underlying value.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
TracedValue< TcpStates_t > m_state
TCP state.
virtual Ptr< ErrorModel > CreateSenderErrorModel()
Create and return the error model to install in the sender node.
uint32_t m_initialCwnd
Initial congestion window.
a polymophic address class
uint16_t GetPeerPort()
Get the peer port.
Tcp socket creation and multiplexing/demultiplexing.
uint32_t m_delAckCount
Delayed ACK counter.
RetrCallback m_retrCallback
void SetRcvAckCb(AckManagementCallback cb)
Set the callback invoked when an ACK is received (at the beginning of the processing) ...
TcpGeneralTest(const std::string &desc, uint32_t pktSize=500, uint32_t pktCount=10, const Time &pktInterval=Seconds(0.01), const Time &propagationDelay=Seconds(0.5), const Time &startTime=Seconds(10), uint32_t initialSlowStartThresh=0xffff, uint32_t initialCwnd=1, uint32_t segmentSize=500, TypeId congestionControl=TcpNewReno::GetTypeId(), uint32_t mtu=1500)
TcpGeneralTest constructor.
uint32_t GetRWnd(SocketWho who)
Get the rWnd of the selected socket.
virtual void Retransmit(void)
Halving cwnd and call DoRetransmit()
Our side has shutdown, waiting to complete transmission of remaining buffered data.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
virtual void ReceivePacket(Ptr< Socket > socket)
Packet received.
Time GetDelAckTimeout(SocketWho who)
Get the timeout of delayed ack (if present)
void ErrorCloseCb(Ptr< Socket > socket)
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
static void EnablePrinting(void)
Enable printing packets metadata.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
AttributeValue implementation for Time.
uint32_t GetDupAckCount(SocketWho who)
Get the number of dupack received.
virtual void Retransmit(void)
Halving cwnd and call DoRetransmit()
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
uint16_t GetLocalPort()
Get the local port.
virtual Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
Hold an unsigned integer type.
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
Base class for all RTT Estimators.
Ipv4Address GetLocalAddress(void)
Get the local address.
holds a vector of ns3::NetDevice pointers
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
void SetRetransmitCb(RetrCallback cb)
Set the callback invoked after the processing of a retransmit timeout.
uint32_t m_pktCount
Count of the application packet.
Time m_interPacketInterval
Time between sending application packet.
Time GetConnTimeout(SocketWho who)
Get the retransmission time for the SYN segments.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
A base class for implementation of a stream socket using TCP.
Ptr< RttEstimator > m_rtt
Round trip time estimator.
Ptr< TcpRxBuffer > m_rxBuffer
Rx buffer (reordering buffer)
void ProcessedAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Ptr< TcpL4Protocol > m_tcp
the associated TCP L4 protocol
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
virtual void RcvAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who)
Received ack.
AckManagementCallback m_processedAckCb
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
void RxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
virtual void AddOptions(TcpHeader &tcpHeader)
Add options to TcpHeader.
Ptr< TcpSocketMsgBase > m_receiverSocket
Pointer to receiver socket.
Time GetRto(SocketWho who)
Get the retransmission time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
virtual void QueueDrop(SocketWho who)
Drop on the queue.
Congestion control abstract class.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
indicates whether the socket has IPV6_TCLASS set.
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
uint32_t GetReTxThreshold(SocketWho who)
Get the retransmission threshold.
static TypeId GetTypeId(void)
void ForkCb(Ptr< TcpSocketMsgBase > tcp)
Time GetClockGranularity(SocketWho who)
Get the clock granularity attribute.
static Time Now(void)
Return the current simulation virtual time.
void SetProcessedAckCb(AckManagementCallback cb)
Set the callback invoked when an ACK is received and processed (at the end of the processing) ...
Time m_minRto
minimum value of the Retransmit timeout
virtual void CongStateTrace(const TcpSocketState::TcpCongState_t oldValue, const TcpSocketState::TcpCongState_t newValue)
State on Ack state machine changes.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
Instantiate subclasses of ns3::Object.
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Ipv4 addresses are stored in host order in this class.
virtual void NormalClose(SocketWho who)
Socket closed normally.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ptr< RttEstimator > GetRttEstimator(SocketWho who)
Get the Rtt estimator of the socket.
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
uint32_t GetId(void) const
TracedValue< Time > m_rto
Retransmit timeout.
An identifier for simulation events.
uint16_t GetLocalPort(void)
Get the local port.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
Ipv6Address GetPeerAddress()
Get the peer address.
static TypeId GetTypeId(void)
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
virtual Ptr< SimpleChannel > CreateChannel()
Create and return the channel installed between the two socket.
Time Seconds(double value)
Construct a Time in the indicated unit.
void TxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
Ipv4Address GetPeerAddress(void)
Get the peer address.
Ptr< TcpSocketState > GetTcb(SocketWho who)
Get the TCB from selected socket.
uint32_t m_synCount
Count of remaining connection retries.
void RtoExpiredCb(const Ptr< const TcpSocketState > tcb, const Ptr< const TcpSocketBase > tcp)
uint16_t GetPeerPort(void)
Get the peer port.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
uint32_t m_mtu
MTU of the environment.
Callback< void, Ptr< TcpSocketMsgBase > > m_forkCb
A TCP socket which sends ACKs smaller than the segment received.
EventId GetPersistentEvent(SocketWho who)
Get the persistent event of the selected socket.
virtual Ptr< ErrorModel > CreateReceiverErrorModel()
Create and return the error model to install in the receiver node.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
virtual void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received an ACK packet.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
uint32_t m_initialSlowStartThresh
Initial slow start threshold.
void RcvAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
uint32_t m_bytesLeftToBeAcked
void CloseAndNotify(void)
Peacefully close the socket by notifying the upper layer and deallocate end point.
SequenceNumber32 m_lastAckedSeq
InetSocketAddress m_remoteAddr
void SetRcvBufSize(SocketWho who, uint32_t size)
Forcefully set a defined size for rx buffer.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
TcpStates_t
Names of the 11 TCP states.
build a set of SimpleNetDevice objects
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
uint32_t m_segmentSize
Segment size.
virtual void RTOExpired(const Ptr< const TcpSocketState > tcb, SocketWho who)
Rto has expired.
virtual int Close(void)=0
Close a socket.
Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
indicates whether the socket has IP_TOS set.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Our side has shutdown after remote has shutdown.
EventId m_delAckEvent
Delayed ACK timeout event.
a unique identifier for an interface.
virtual void CWndTrace(uint32_t oldValue, uint32_t newValue)
Congestion window changes.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Time m_clockGranularity
Clock Granularity used in RTO calcs.
uint32_t m_pktSize
Size of the application packet.
virtual uint16_t AdvertisedWindowSize(void) const
The amount of Rx window announced to the peer.
TracedCallback< Ptr< const Packet >, const TcpHeader &, Ptr< const TcpSocketBase > > m_txTrace
Trace of transmitted packets.
TcpSocket::TcpStates_t GetTcpState(SocketWho who)
Get the state of the TCP state machine.
Time m_startTime
Data transmission time.
void HandleAccept(Ptr< Socket > socket, const Address &from)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
TypeId m_congControlTypeId
Congestion control.