Added Rx and Tx callbacks on TCP

Also moved AckState enum to TcpSocketState (to avoid conflict with state in
the TcpSocketBase).
This commit is contained in:
Natale Patriciello
2015-10-16 10:42:44 -07:00
parent 4b8027f849
commit 62fe16a69d
2 changed files with 53 additions and 3 deletions

View File

@@ -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> 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> 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<Packet> p = Create<Packet> ();
h.SetFlags (TcpHeader::RST);
h.SetSequenceNumber (m_nextTxSequence);
h.SetAckNumber (m_rxBuffer->NextRxSequence ());
@@ -1185,7 +1198,8 @@ TcpSocketBase::DoForwardUp (Ptr<Packet> packet, const Address &fromAddress,
h.SetDestinationPort (tcpHeader.GetSourcePort ());
h.SetWindowSize (AdvertisedWindowSize ());
AddOptions (h);
m_tcp->SendPacket (Create<Packet> (), 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 ());

View File

@@ -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); // 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<const Packet> packet, const TcpHeader& header,
const Ptr<const TcpSocketBase> 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<Ptr<const Packet>, const TcpHeader&,
Ptr<const TcpSocketBase> > m_txTrace; //!< Trace of transmitted packets
TracedCallback<Ptr<const Packet>, const TcpHeader&,
Ptr<const TcpSocketBase> > m_rxTrace; //!< Trace of received packets
};
/**