From 62fe16a69db975076317e9310ba22e8889e949d2 Mon Sep 17 00:00:00 2001 From: Natale Patriciello Date: Fri, 16 Oct 2015 10:42:44 -0700 Subject: [PATCH] Added Rx and Tx callbacks on TCP Also moved AckState enum to TcpSocketState (to avoid conflict with state in the TcpSocketBase). --- src/internet/model/tcp-socket-base.cc | 28 ++++++++++++++++++++++++--- src/internet/model/tcp-socket-base.h | 28 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/internet/model/tcp-socket-base.cc b/src/internet/model/tcp-socket-base.cc index c1307cb8d..71ac2c473 100644 --- a/src/internet/model/tcp-socket-base.cc +++ b/src/internet/model/tcp-socket-base.cc @@ -151,7 +151,7 @@ TcpSocketBase::GetTypeId (void) .AddTraceSource ("AckState", "TCP ACK machine state", MakeTraceSourceAccessor (&TcpSocketBase::m_ackStateTrace), - "ns3::TcpAckStatesTracedValueCallback") + "ns3::TcpSocketState::TcpAckStatesTracedValueCallback") .AddTraceSource ("RWND", "Remote side's flow control window", MakeTraceSourceAccessor (&TcpSocketBase::m_rWnd), @@ -172,6 +172,14 @@ TcpSocketBase::GetTypeId (void) "TCP slow start threshold (bytes)", MakeTraceSourceAccessor (&TcpSocketBase::m_ssThTrace), "ns3::TracedValueCallback::Uint32") + .AddTraceSource ("Tx", + "Send tcp packet to IP protocol", + MakeTraceSourceAccessor (&TcpSocketBase::m_txTrace), + "ns3::TcpSocketBase::TcpTxRxTracedCallback") + .AddTraceSource ("Rx", + "Receive tcp packet from IP protocol", + MakeTraceSourceAccessor (&TcpSocketBase::m_rxTrace), + "ns3::TcpSocketBase::TcpTxRxTracedCallback") ; return tid; } @@ -319,7 +327,9 @@ TcpSocketBase::TcpSocketBase (const TcpSocketBase& sock) m_retxThresh (sock.m_retxThresh), m_limitedTx (sock.m_limitedTx), m_tcb (sock.m_tcb), - m_isFirstPartialAck (sock.m_isFirstPartialAck) + m_isFirstPartialAck (sock.m_isFirstPartialAck), + m_txTrace (sock.m_txTrace), + m_rxTrace (sock.m_rxTrace) { NS_LOG_FUNCTION (this); NS_LOG_LOGIC ("Invoked the copy constructor"); @@ -1117,6 +1127,8 @@ TcpSocketBase::DoForwardUp (Ptr packet, const Address &fromAddress, return; // Discard invalid packet } + m_rxTrace (packet, tcpHeader, this); + ReadOptions (tcpHeader); if (tcpHeader.GetFlags () & TcpHeader::ACK) @@ -1178,6 +1190,7 @@ TcpSocketBase::DoForwardUp (Ptr packet, const Address &fromAddress, if ((tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG)) != TcpHeader::RST) { // Since m_endPoint is not configured yet, we cannot use SendRST here TcpHeader h; + Ptr p = Create (); h.SetFlags (TcpHeader::RST); h.SetSequenceNumber (m_nextTxSequence); h.SetAckNumber (m_rxBuffer->NextRxSequence ()); @@ -1185,7 +1198,8 @@ TcpSocketBase::DoForwardUp (Ptr packet, const Address &fromAddress, h.SetDestinationPort (tcpHeader.GetSourcePort ()); h.SetWindowSize (AdvertisedWindowSize ()); AddOptions (h); - m_tcp->SendPacket (Create (), h, toAddress, fromAddress, m_boundnetdevice); + m_txTrace (p, h, this); + m_tcp->SendPacket (p, h, toAddress, fromAddress, m_boundnetdevice); } break; case SYN_SENT: @@ -2056,6 +2070,9 @@ TcpSocketBase::SendEmptyPacket (uint8_t flags) m_tcp->SendPacket (p, header, m_endPoint6->GetLocalAddress (), m_endPoint6->GetPeerAddress (), m_boundnetdevice); } + + m_txTrace (p, header, this); + if (flags & TcpHeader::ACK) { // If sending an ACK, cancel the delay ACK as well m_delAckEvent.Cancel (); @@ -2334,6 +2351,8 @@ TcpSocketBase::SendDataPacket (SequenceNumber32 seq, uint32_t maxSize, bool with ". Header " << header); } + m_txTrace (p, header, this); + // update the history of sequence numbers used to calculate the RTT if (isRetransmission == false) { // This is the next expected one, just log at end @@ -2710,6 +2729,9 @@ TcpSocketBase::PersistTimeout () m_tcp->SendPacket (p, tcpHeader, m_endPoint6->GetLocalAddress (), m_endPoint6->GetPeerAddress (), m_boundnetdevice); } + + m_txTrace (p, tcpHeader, this); + NS_LOG_LOGIC ("Schedule persist timeout at time " << Simulator::Now ().GetSeconds () << " to expire at time " << (Simulator::Now () + m_persistTimeout).GetSeconds ()); diff --git a/src/internet/model/tcp-socket-base.h b/src/internet/model/tcp-socket-base.h index 39d349039..b68a9af3a 100644 --- a/src/internet/model/tcp-socket-base.h +++ b/src/internet/model/tcp-socket-base.h @@ -129,6 +129,16 @@ public: LAST_ACKSTATE /**< Used only in debug messages */ } TcpAckState_t; + /** + * \ingroup tcp + * TracedValue Callback signature for TcpAckState_t + * + * \param [in] oldValue original value of the traced variable + * \param [in] newValue new value of the traced variable + */ + typedef void (* TcpAckStatesTracedValueCallback)(const TcpAckState_t oldValue, + const TcpAckState_t newValue); + /** * \brief Literal names of TCP states for use in log messages */ @@ -369,6 +379,17 @@ public: virtual int GetSockName (Address &address) const; // Return local addr:port in address virtual void BindToNetDevice (Ptr netdevice); // NetDevice with my m_endPoint + /** + * TracedCallback signature for tcp packet transmission or reception events. + * + * \param [in] packet The packet. + * \param [in] ipv4 + * \param [in] interface + */ + typedef void (* TcpTxRxTracedCallback) + (const Ptr packet, const TcpHeader& header, + const Ptr socket); + protected: // Implementing ns3::TcpSocket -- Attribute get/set // inherited, no need to doc @@ -955,6 +976,13 @@ protected: // Guesses over the other connection end bool m_isFirstPartialAck;//!< First partial ACK during RECOVERY + + // The following two traces pass a packet with a TCP header + TracedCallback, const TcpHeader&, + Ptr > m_txTrace; //!< Trace of transmitted packets + + TracedCallback, const TcpHeader&, + Ptr > m_rxTrace; //!< Trace of received packets }; /**