diff -r 5dd517bec9f3 -r 8f2c6c71db93 src/contrib/flow-monitor/ipv4-flow-probe.cc --- a/src/contrib/flow-monitor/ipv4-flow-probe.cc Thu Apr 01 02:25:48 2010 +0800 +++ b/src/contrib/flow-monitor/ipv4-flow-probe.cc Thu Apr 01 05:26:31 2010 +0800 @@ -25,16 +25,126 @@ #include "ns3/flow-monitor.h" #include "ns3/log.h" #include "ns3/pointer.h" +#include "ns3/config.h" +#include "ns3/flow-id-tag.h" +#include namespace ns3 { +using namespace std; + NS_LOG_COMPONENT_DEFINE ("Ipv4FlowProbe"); + + ////////////////////////////////////// + // FlowProbeTag class implementation // + ////////////////////////////////////// + +class FlowProbeTag : public Tag +{ +public: + static TypeId GetTypeId (void); + virtual TypeId GetInstanceTypeId (void) const; + virtual uint32_t GetSerializedSize (void) const; + virtual void Serialize (TagBuffer buf) const; + virtual void Deserialize (TagBuffer buf); + virtual void Print (std::ostream &os) const; + FlowProbeTag (); + FlowProbeTag (uint32_t flowId, uint32_t packetId, uint32_t packetSize); + void SetFlowId (uint32_t flowId); + void SetPacketId (uint32_t packetId); + void SetPacketSize (uint32_t packetSize); + uint32_t GetFlowId (void) const; + uint32_t GetPacketId (void) const; + uint32_t GetPacketSize (void) const; +private: + uint32_t m_flowId; + uint32_t m_packetId; + uint32_t m_packetSize; +}; -Ipv4FlowProbe::~Ipv4FlowProbe () +TypeId +FlowProbeTag::GetTypeId (void) { + static TypeId tid = TypeId ("ns3::FlowProbeTag") + .SetParent () + .AddConstructor () + ; + return tid; } - +TypeId +FlowProbeTag::GetInstanceTypeId (void) const +{ + return GetTypeId (); +} +uint32_t +FlowProbeTag::GetSerializedSize (void) const +{ + return 4 + 4 + 4; +} +void +FlowProbeTag::Serialize (TagBuffer buf) const +{ + buf.WriteU32 (m_flowId); + buf.WriteU32 (m_packetId); + buf.WriteU32 (m_packetSize); +} +void +FlowProbeTag::Deserialize (TagBuffer buf) +{ + m_flowId = buf.ReadU32 (); + m_packetId = buf.ReadU32 (); + m_packetSize = buf.ReadU32 (); +} +void +FlowProbeTag::Print (std::ostream &os) const +{ + os << "FlowId=" << m_flowId; + os << "PacketId=" << m_packetId; + os << "PacketSize=" << m_packetSize; +} +FlowProbeTag::FlowProbeTag () + : Tag () +{} + +FlowProbeTag::FlowProbeTag (uint32_t flowId, uint32_t packetId, uint32_t packetSize) + : Tag (), m_flowId (flowId), m_packetId (packetId), m_packetSize (packetSize) +{} + +void +FlowProbeTag::SetFlowId (uint32_t id) +{ + m_flowId = id; +} +void +FlowProbeTag::SetPacketId (uint32_t id) +{ + m_packetId = id; +} +void +FlowProbeTag::SetPacketSize (uint32_t size) +{ + m_packetSize = size; +} +uint32_t +FlowProbeTag::GetFlowId (void) const +{ + return m_flowId; +} +uint32_t +FlowProbeTag::GetPacketId (void) const +{ + return m_packetId; +} +uint32_t +FlowProbeTag::GetPacketSize (void) const +{ + return m_packetSize; +} + + //////////////////////////////////////// + // Ipv4FlowProbe class implementation // + //////////////////////////////////////// Ipv4FlowProbe::Ipv4FlowProbe (Ptr monitor, Ptr classifier, @@ -67,6 +177,11 @@ { NS_FATAL_ERROR ("trace fail"); } + + // code copied from point-to-point-helper.cc + std::ostringstream oss; + oss << "/NodeList/" << node->GetId () << "/DeviceList/*/TxQueue/Drop"; + Config::ConnectWithoutContext (oss.str (), MakeCallback (&Ipv4FlowProbe::QueueDropLogger, Ptr (this))); } void @@ -76,11 +191,16 @@ FlowPacketId packetId; if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId)) - { + { uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ()); NS_LOG_DEBUG ("ReportFirstTx ("<ReportFirstTx (this, flowId, packetId, size); + + // tag the packet with the flow id and packet id, so that the packet can be identified even + // when Ipv4Header is not accessible at some non-IPv4 protocol layer + FlowProbeTag fTag (flowId, packetId, size); + ipPayload->AddPacketTag (fTag); } } @@ -107,6 +227,11 @@ if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId)) { + // remove the tags that are added by Ipv4FlowProbe::SendOutgoingLogger () + FlowProbeTag fTag; + bool tagFound = ConstCast (ipPayload)->RemovePacketTag (fTag); + NS_ASSERT_MSG (tagFound, "FlowProbeTag is missing"); + uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ()); NS_LOG_DEBUG ("ReportLastRx ("<ReportLastRx (this, flowId, packetId, size); @@ -140,9 +265,14 @@ if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId)) { + // remove the tags that are added by Ipv4FlowProbe::SendOutgoingLogger () + FlowProbeTag fTag; + bool tagFound = ConstCast (ipPayload)->RemovePacketTag (fTag); + NS_ASSERT_MSG (tagFound, "FlowProbeTag is missing"); + uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ()); - NS_LOG_DEBUG ("Drop ("< ipPayload) +{ + // remove the tags that are added by Ipv4FlowProbe::SendOutgoingLogger () + FlowProbeTag fTag; + bool tagFound = ConstCast (ipPayload)->RemovePacketTag (fTag); + + if (tagFound) + { + FlowId flowId = fTag.GetFlowId (); + FlowPacketId packetId = fTag.GetPacketId (); + uint32_t size = fTag.GetPacketSize (); + NS_LOG_DEBUG ("Drop ("<ReportDrop (this, flowId, packetId, size, DROP_QUEUE); + } +} } // namespace ns3 diff -r 5dd517bec9f3 -r 8f2c6c71db93 src/contrib/flow-monitor/ipv4-flow-probe.h --- a/src/contrib/flow-monitor/ipv4-flow-probe.h Thu Apr 01 02:25:48 2010 +0800 +++ b/src/contrib/flow-monitor/ipv4-flow-probe.h Thu Apr 01 05:26:31 2010 +0800 @@ -41,7 +41,7 @@ public: Ipv4FlowProbe (Ptr monitor, Ptr classifier, Ptr node); - virtual ~Ipv4FlowProbe (); + //virtual ~Ipv4FlowProbe (); /// \brief enumeration of possible reasons why a packet may be dropped enum DropReason @@ -52,8 +52,8 @@ DROP_TTL_EXPIRE, /// Packet dropped due to invalid checksum in the IPv4 header DROP_BAD_CHECKSUM, - - // DROP_QUEUE, // TODO: this is not easy to do + /// Packet dropped due to queue overflow + DROP_QUEUE, // TODO: this is not easy to do DROP_INVALID_REASON, }; @@ -64,6 +64,7 @@ void ForwardUpLogger (const Ipv4Header &ipHeader, Ptr ipPayload, uint32_t interface); void DropLogger (const Ipv4Header &ipHeader, Ptr ipPayload, Ipv4L3Protocol::DropReason reason, uint32_t ifIndex); + void QueueDropLogger (Ptr ipPayload); Ptr m_classifier; };