19 #define __STDC_LIMIT_MACROS
21 #include "ns3/node-container.h"
22 #include "ns3/tcp-socket-base.h"
23 #include "ns3/simple-net-device-helper.h"
24 #include "ns3/ipv4-address-helper.h"
25 #include "ns3/internet-stack-helper.h"
27 #include "ns3/tcp-l4-protocol.h"
28 #include "../model/ipv4-end-point.h"
29 #include "../model/ipv6-end-point.h"
38 m_congControlTypeId (
TcpNewReno::GetTypeId ()),
56 while ((packet = socket->
RecvFrom (from)))
67 uint32_t pktCount,
Time pktInterval )
73 socket->
Send (Create<Packet> (pktSize));
75 socket, pktSize, pktCount - 1, pktInterval);
143 senderDev->SetMtu (
m_mtu);
144 senderDev->GetQueue ()->TraceConnect (
"Drop",
"SENDER",
146 senderDev->TraceConnect (
"PhyRxDrop",
"sender",
149 receiverDev->SetMtu (
m_mtu);
150 receiverDev->GetQueue ()->TraceConnect (
"Drop",
"RECEIVER",
152 receiverDev->TraceConnect (
"PhyRxDrop",
"RECEIVER",
155 senderDev->SetReceiveErrorModel (senderEM);
156 receiverDev->SetReceiveErrorModel (receiverEM);
159 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
262 congestionAlgorithmFactory.
SetTypeId (congControl);
269 socket->SetNode (node);
271 socket->SetRtt (rtt);
272 socket->SetCongestionControlAlgorithm (algo);
304 if (context.compare (
"SENDER") == 0)
308 else if (context.compare (
"RECEIVER") == 0)
314 NS_FATAL_ERROR (
"Packet dropped in a queue, but queue not recognized");
321 if (context.compare (
"SENDER") == 0)
325 else if (context.compare (
"RECEIVER") == 0)
331 NS_FATAL_ERROR (
"Packet dropped in a queue, but queue not recognized");
355 bool isRetransmission)
520 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_retxThresh;
537 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_dupAckCount;
554 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_delAckMaxCount;
605 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_highTxMark;
639 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->GetInitialSSThresh ();
643 return DynamicCast<TcpSocketMsgBase> (
m_receiverSocket)->GetInitialSSThresh ();
656 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_rto.Get ();
690 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_cnTimeout;
724 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_clockGranularity;
728 return DynamicCast<TcpSocketMsgBase> (
m_receiverSocket)->m_clockGranularity;
741 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_state.Get ();
759 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_rWnd.Get ();
777 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_persistEvent;
795 return DynamicCast<TcpSocketMsgBase> (
m_senderSocket)->m_persistTimeout;
901 .SetGroupName (
"Internet")
910 return CopyObject<TcpSocketMsgBase> (
this);
969 bool isRetransmission)
997 .SetGroupName (
"Internet")
1053 NS_LOG_WARN (
"Failed to send empty packet due to null endpoint");
1069 header.SetFlags (flags);
1070 header.SetSequenceNumber (s);
1073 if (hasSyn || hasFin)
1075 header.SetAckNumber (
m_rxBuffer->NextRxSequence ());
1094 header.SetAckNumber (ackSeq);
1152 NS_LOG_LOGIC (
"Schedule retransmission timeout at time "
1168 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)
void DataSentCb(Ptr< Socket > socket, uint32_t size)
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.
TcpGeneralTest(const std::string &desc)
TcpGeneralTest constructor.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
AckManagementCb m_rcvAckCb
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.
void SetCongestionControl(TypeId congControl)
Congestion control of the sender socket.
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.
virtual void DataSent(uint32_t size, SocketWho who)
Notifying application for sent data.
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.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
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.
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
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).
void SetTransmitStart(Time startTime)
Set the initial time at which the application sends the first data packet.
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.
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.
virtual void SsThreshTrace(uint32_t oldValue, uint32_t newValue)
Slow start threshold changes.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Callback< R > MakeNullCallback(void)
static TypeId GetTypeId(void)
Get the type ID.
void SetRcvAckCb(AckManagementCb cb)
Set the callback invoked when an ACK is received (at the beginning of the processing) ...
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.
The NewReno implementation.
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.
a polymophic address class
uint16_t GetPeerPort()
Get the peer port.
Tcp socket creation and multiplexing/demultiplexing.
uint32_t m_delAckCount
Delayed ACK counter.
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)
SequenceNumber32 GetHighestTxMark(SocketWho who)
Get the highest tx mark of the node specified.
void ErrorCloseCb(Ptr< Socket > socket)
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
virtual void UpdateRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
Update the RTT history, when we send TCP segments.
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.
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
virtual Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
virtual void ConfigureProperties(void)
Change the configuration of the socket properties.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
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.
uint32_t m_pktCount
Count of the application packet.
Time m_interPacketInterval
Time between sending application packet.
void SetRetransmitCb(RetrCb cb)
Set the callback invoked after the processing of a retransmit timeout.
void SetInitialCwnd(SocketWho who, uint32_t initialCwnd)
Forcefully set the initial cwnd.
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.
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.
uint32_t GetInitialCwnd(SocketWho who)
Get the initial congestion window.
virtual void AddOptions(TcpHeader &tcpHeader)
Add options to TcpHeader.
AckManagementCb m_processedAckCb
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 SetAppPktCount(uint32_t pktCount)
Set app packet count.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
uint32_t GetInitialSsThresh(SocketWho who)
Get the initial slow start threshold.
void SetAppPktInterval(Time pktInterval)
Interval between app-generated packet.
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.
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.
void SetInitialSsThresh(SocketWho who, uint32_t initialSsThresh)
Forcefully set the initial ssth.
void UpdateRttHistoryCb(Ptr< const TcpSocketBase > tcp, const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
UpdateRttCallback m_updateRttCb
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.
virtual void ConfigureEnvironment(void)
Change the configuration of the evironment.
#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.
void SetUpdateRttHistoryCb(UpdateRttCallback cb)
Set the callback invoked when we update rtt history.
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.
virtual void BytesInFlightTrace(uint32_t oldValue, uint32_t newValue)
Bytes in flight changes.
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
virtual void UpdatedRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission, SocketWho who)
Updated the Rtt history.
A TCP socket which sends ACKs smaller than the segment received.
virtual void RttTrace(Time oldTime, Time newTime)
Rtt changes.
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.
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.
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.
void SetProcessedAckCb(AckManagementCb cb)
Set the callback invoked when an ACK is received and processed (at the end of the processing) ...
indicates whether the socket has IP_TOS set.
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
virtual void UpdateRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
Update the RTT history, when we send TCP segments.
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.
void SetPropagationDelay(Time propDelay)
Propagation delay of the bottleneck link.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
TypeId m_congControlTypeId
Congestion control.