From 1811703940a5cc09b751fe45b92f2b05f0164d97 Mon Sep 17 00:00:00 2001 From: Pavel Boyko Date: Mon, 22 Jun 2009 21:14:30 +0400 Subject: [PATCH] RX/TX/FWD stats in MeshPointDevice --- src/devices/mesh/dot11s/dot11s-installer.cc | 4 ++ src/devices/mesh/mesh-point-device.cc | 50 ++++++++++++++++++++- src/devices/mesh/mesh-point-device.h | 26 +++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/devices/mesh/dot11s/dot11s-installer.cc b/src/devices/mesh/dot11s/dot11s-installer.cc index 26ebccb94..87c8132ef 100644 --- a/src/devices/mesh/dot11s/dot11s-installer.cc +++ b/src/devices/mesh/dot11s/dot11s-installer.cc @@ -71,6 +71,8 @@ Dot11sStack::InstallStack (Ptr mp) void Dot11sStack::Report (const Ptr mp, std::ostream& os) { + mp->Report (os); + std::vector > ifaces = mp->GetInterfaces (); for (std::vector >::const_iterator i = ifaces.begin(); i != ifaces.end(); ++i) { @@ -89,6 +91,8 @@ Dot11sStack::Report (const Ptr mp, std::ostream& os) void Dot11sStack::ResetStats (const Ptr mp) { + mp->ResetStats (); + std::vector > ifaces = mp->GetInterfaces (); for (std::vector >::const_iterator i = ifaces.begin(); i != ifaces.end(); ++i) { diff --git a/src/devices/mesh/mesh-point-device.cc b/src/devices/mesh/mesh-point-device.cc index a3809cb9c..ec71ace74 100644 --- a/src/devices/mesh/mesh-point-device.cc +++ b/src/devices/mesh/mesh-point-device.cc @@ -95,6 +95,9 @@ MeshPointDevice::ReceiveFromDevice (Ptr incomingPort, PtrGetSize (); } return; } @@ -104,6 +107,9 @@ MeshPointDevice::ReceiveFromDevice (Ptr incomingPort, PtrGetIfIndex (), src48, dst48, packet_copy, realProtocol)) { m_rxCallback (this, packet_copy, realProtocol, src); + + m_rxStats.unicastData ++; + m_rxStats.unicastDataBytes += packet->GetSize (); } return; } @@ -390,7 +396,22 @@ MeshPointDevice::DoSend (bool success, Ptr packet, Mac48Address src, Mac NS_LOG_DEBUG ("Resolve failed"); return; } - // Ok, now I know the route, just SendFrom + + // Count statistics + Statistics * stats = ((src == m_address) ? & m_txStats : & m_fwdStats); + + if (dst.IsBroadcast ()) + { + stats->broadcastData ++; + stats->broadcastDataBytes += packet->GetSize (); + } + else + { + stats->unicastData ++; + stats->unicastDataBytes += packet->GetSize (); + } + + // Send if (outIface != 0xffffffff) GetInterface (outIface)->SendFrom(packet, src, dst, protocol); else @@ -398,4 +419,31 @@ MeshPointDevice::DoSend (bool success, Ptr packet, Mac48Address src, Mac (*i) -> SendFrom (packet->Copy (), src, dst, protocol); } +void +MeshPointDevice::Report (std::ostream & os) const +{ + os << "\n"; +} + +void +MeshPointDevice::ResetStats () +{ + m_rxStats = Statistics (); + m_txStats = Statistics (); + m_fwdStats = Statistics (); +} + } // namespace ns3 diff --git a/src/devices/mesh/mesh-point-device.h b/src/devices/mesh/mesh-point-device.h index 2e754296c..ae6292308 100644 --- a/src/devices/mesh/mesh-point-device.h +++ b/src/devices/mesh/mesh-point-device.h @@ -118,6 +118,14 @@ public: virtual void DoDispose (); //\} + ///\name Statistics + //\{ + /// Print statistics counters + void Report (std::ostream & os) const; + /// Reset statistics counters + void ResetStats (); + //\} + private: /// Receive packet from interface void ReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, @@ -170,6 +178,24 @@ private: MeshL2RoutingProtocol::RouteReplyCallback m_myResponse; /// Current routing protocol, used mainly by GetRoutingProtocol Ptr m_routingProtocol; + + /// Device statistics counters + struct Statistics + { + uint32_t unicastData; + uint32_t unicastDataBytes; + uint32_t broadcastData; + uint32_t broadcastDataBytes; + + Statistics () : unicastData (0), + unicastDataBytes (0), + broadcastData (0), + broadcastDataBytes (0) + { + } + }; + /// Counters + Statistics m_rxStats, m_txStats, m_fwdStats; }; } //namespace ns3 #endif