flow-monitor coding style changes

This commit is contained in:
Josh Pelkey
2011-05-13 14:54:37 -04:00
parent c8e53cb5a3
commit cbcde10781
14 changed files with 123 additions and 119 deletions

View File

@@ -46,7 +46,7 @@ Ptr<FlowMonitor>
FlowMonitorHelper::GetMonitor ()
{
if (!m_flowMonitor)
{
{
m_flowMonitor = m_monitorFactory.Create<FlowMonitor> ();
m_flowClassifier = Create<Ipv4FlowClassifier> ();
m_flowMonitor->SetFlowClassifier (m_flowClassifier);
@@ -59,7 +59,7 @@ Ptr<FlowClassifier>
FlowMonitorHelper::GetClassifier ()
{
if (!m_flowClassifier)
{
{
m_flowClassifier = Create<Ipv4FlowClassifier> ();
}
return m_flowClassifier;
@@ -103,7 +103,7 @@ FlowMonitorHelper::InstallAll ()
Install (node);
}
}
return m_flowMonitor;
return m_flowMonitor;
}

View File

@@ -29,7 +29,7 @@
namespace ns3 {
class AttributeValue;
class Ipv4FlowClassifier;
class Ipv4FlowClassifier;
/// \brief Helper to enable IPv4 flow monitoring on a set of Nodes
class FlowMonitorHelper
@@ -38,7 +38,7 @@ public:
/// \brief Construct a FlowMonitorHelper class which makes it easier to
/// configure and use the FlowMonitor
FlowMonitorHelper ();
/// \brief Set an attribute for the to-be-created FlowMonitor object
void SetMonitorAttribute (std::string n1, const AttributeValue &v1);
@@ -56,7 +56,7 @@ public:
/// \brief Retrieve the FlowClassifier object created by the Install* methods
Ptr<FlowClassifier> GetClassifier ();
private:
ObjectFactory m_monitorFactory;
Ptr<FlowMonitor> m_flowMonitor;

View File

@@ -24,12 +24,13 @@ namespace ns3 {
FlowClassifier::FlowClassifier ()
:
m_lastNewFlowId (0)
m_lastNewFlowId (0)
{
}
FlowClassifier::~FlowClassifier ()
{}
{
}
FlowId
FlowClassifier::GetNewFlowId ()

View File

@@ -34,7 +34,7 @@ namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("FlowMonitor");
NS_OBJECT_ENSURE_REGISTERED (FlowMonitor);
TypeId
FlowMonitor::GetTypeId (void)
@@ -58,7 +58,7 @@ FlowMonitor::GetTypeId (void)
.AddAttribute ("JitterBinWidth", ("The width used in the jitter histogram."),
DoubleValue (0.001),
MakeDoubleAccessor (&FlowMonitor::m_jitterBinWidth),
MakeDoubleChecker <double> ())
MakeDoubleChecker <double> ())
.AddAttribute ("PacketSizeBinWidth", ("The width used in the packetSize histogram."),
DoubleValue (20),
MakeDoubleAccessor (&FlowMonitor::m_packetSizeBinWidth),
@@ -71,7 +71,7 @@ FlowMonitor::GetTypeId (void)
TimeValue (Seconds (0.5)),
MakeTimeAccessor (&FlowMonitor::m_flowInterruptionsMinTime),
MakeTimeChecker ())
;
;
return tid;
}
@@ -82,9 +82,9 @@ FlowMonitor::GetInstanceTypeId (void) const
}
FlowMonitor::FlowMonitor ()
: m_enabled (false)
: m_enabled (false)
{
// m_histogramBinWidth=DEFAULT_BIN_WIDTH;
// m_histogramBinWidth=DEFAULT_BIN_WIDTH;
}
@@ -131,7 +131,7 @@ FlowMonitor::ReportFirstTx (Ptr<FlowProbe> probe, uint32_t flowId, uint32_t pack
tracked.lastSeenTime = tracked.firstSeenTime;
tracked.timesForwarded = 0;
NS_LOG_DEBUG ("ReportFirstTx: adding tracked packet (flowId=" << flowId << ", packetId=" << packetId
<< ").");
<< ").");
probe->AddPacketStats (flowId, packetSize, Seconds (0));
@@ -158,7 +158,7 @@ FlowMonitor::ReportForwarding (Ptr<FlowProbe> probe, uint32_t flowId, uint32_t p
if (tracked == m_trackedPackets.end ())
{
NS_LOG_WARN ("Received packet forward report (flowId=" << flowId << ", packetId=" << packetId
<< ") but not known to be transmitted.");
<< ") but not known to be transmitted.");
return;
}
@@ -181,7 +181,7 @@ FlowMonitor::ReportLastRx (Ptr<FlowProbe> probe, uint32_t flowId, uint32_t packe
if (tracked == m_trackedPackets.end ())
{
NS_LOG_WARN ("Received packet last-tx report (flowId=" << flowId << ", packetId=" << packetId
<< ") but not known to be transmitted.");
<< ") but not known to be transmitted.");
return;
}
@@ -196,18 +196,18 @@ FlowMonitor::ReportLastRx (Ptr<FlowProbe> probe, uint32_t flowId, uint32_t packe
{
Time jitter = stats.lastDelay - delay;
if (jitter > Seconds (0))
{
stats.jitterSum += jitter;
stats.jitterHistogram.AddValue (jitter.GetSeconds ());
}
{
stats.jitterSum += jitter;
stats.jitterHistogram.AddValue (jitter.GetSeconds ());
}
else
{
stats.jitterSum -= jitter;
stats.jitterHistogram.AddValue (-jitter.GetSeconds());
}
{
stats.jitterSum -= jitter;
stats.jitterHistogram.AddValue (-jitter.GetSeconds());
}
}
stats.lastDelay = delay;
stats.rxBytes += packetSize;
stats.packetSizeHistogram.AddValue ((double) packetSize);
stats.rxPackets++;
@@ -277,7 +277,7 @@ void
FlowMonitor::CheckForLostPackets (Time maxDelay)
{
Time now = Simulator::Now ();
for (TrackedPacketMap::iterator iter = m_trackedPackets.begin ();
iter != m_trackedPackets.end (); )
{
@@ -285,7 +285,7 @@ FlowMonitor::CheckForLostPackets (Time maxDelay)
{
// packet is considered lost, add it to the loss statistics
std::map<FlowId, FlowStats>::iterator
flow = m_flowStats.find (iter->first.first);
flow = m_flowStats.find (iter->first.first);
NS_ASSERT (flow != m_flowStats.end ());
flow->second.lostPackets++;
@@ -387,7 +387,7 @@ void
FlowMonitor::SerializeToXmlStream (std::ostream &os, int indent, bool enableHistograms, bool enableProbes)
{
CheckForLostPackets ();
INDENT(indent); os << "<FlowMonitor>\n";
indent += 2;
INDENT(indent); os << "<FlowStats>\n";
@@ -395,24 +395,24 @@ FlowMonitor::SerializeToXmlStream (std::ostream &os, int indent, bool enableHist
for (std::map<FlowId, FlowStats>::const_iterator flowI = m_flowStats.begin ();
flowI != m_flowStats.end (); flowI++)
{
INDENT(indent);
#define ATTRIB(name) << " "#name"=\"" << flowI->second.name << "\""
#define ATTRIB(name) << " " # name "=\"" << flowI->second.name << "\""
os << "<Flow flowId=\"" << flowI->first << "\""
ATTRIB(timeFirstTxPacket)
ATTRIB(timeFirstRxPacket)
ATTRIB(timeLastTxPacket)
ATTRIB(timeLastRxPacket)
ATTRIB(delaySum)
ATTRIB(jitterSum)
ATTRIB(lastDelay)
ATTRIB(txBytes)
ATTRIB(rxBytes)
ATTRIB(txPackets)
ATTRIB(rxPackets)
ATTRIB(lostPackets)
ATTRIB(timesForwarded)
<< ">\n";
ATTRIB(timeFirstTxPacket)
ATTRIB(timeFirstRxPacket)
ATTRIB(timeLastTxPacket)
ATTRIB(timeLastRxPacket)
ATTRIB(delaySum)
ATTRIB(jitterSum)
ATTRIB(lastDelay)
ATTRIB(txBytes)
ATTRIB(rxBytes)
ATTRIB(txPackets)
ATTRIB(rxPackets)
ATTRIB(lostPackets)
ATTRIB(timesForwarded)
<< ">\n";
#undef ATTRIB
@@ -462,7 +462,7 @@ FlowMonitor::SerializeToXmlStream (std::ostream &os, int indent, bool enableHist
indent -= 2;
INDENT(indent); os << "</FlowMonitor>\n";
}
std::string
FlowMonitor::SerializeToXmlString (int indent, bool enableHistograms, bool enableProbes)

View File

@@ -54,7 +54,7 @@ public:
/// was received by an end node, i.e. the time when the flow
/// reception starts
Time timeFirstRxPacket;
/// Contains the absolute time when the last packet in the flow
/// was transmitted, i.e. the time when the flow transmission
/// ends
@@ -133,7 +133,7 @@ public:
/// Set the FlowClassifier to be used by the flow monitor.
void SetFlowClassifier (Ptr<FlowClassifier> classifier);
/// Set the time, counting from the current time, from which to start monitoring flows
void Start (const Time &time);
/// Set the time, counting from the current time, from which to stop monitoring flows
@@ -171,7 +171,7 @@ public:
/// Check right now for packets that appear to be lost, considering
/// packets as lost if not seen in the network for a time larger
/// than maxDelay
void CheckForLostPackets (Time maxDelay);
void CheckForLostPackets (Time maxDelay);
// --- methods to get the results ---
/// Retrieve all collected the flow statistics. Note, if the

View File

@@ -28,7 +28,7 @@ FlowProbe::~FlowProbe ()
{
}
FlowProbe::FlowProbe (Ptr<FlowMonitor> flowMonitor)
: m_flowMonitor (flowMonitor)
{
@@ -72,7 +72,7 @@ FlowProbe::SerializeToXmlStream (std::ostream &os, int indent, uint32_t index) c
INDENT(indent); os << "<FlowProbe index=\"" << index << "\">\n";
indent += 2;
for (Stats::const_iterator iter = m_stats.begin (); iter != m_stats.end (); iter++)
{
INDENT(indent);

View File

@@ -31,7 +31,7 @@
namespace ns3 {
class FlowMonitor;
/// The FlowProbe class is responsible for listening for packet events
/// in a specific point of the simulated space, report those events to
/// the global FlowMonitor, and collect its own flow statistics
@@ -41,11 +41,11 @@ class FlowProbe : public SimpleRefCount<FlowProbe>
private:
FlowProbe (FlowProbe const &);
FlowProbe& operator= (FlowProbe const &);
protected:
FlowProbe (Ptr<FlowMonitor> flowMonitor);
public:
virtual ~FlowProbe ();
@@ -65,9 +65,9 @@ public:
/// Number of packets seen of this flow
uint32_t packets;
};
typedef std::map<FlowId, FlowStats> Stats;
void AddPacketStats (FlowId flowId, uint32_t packetSize, Time delayFromFirstProbe);
void AddPacketDropStats (FlowId flowId, uint32_t packetSize, uint32_t reasonCode);

View File

@@ -23,7 +23,7 @@
#include "ns3/simulator.h"
#include "ns3/log.h"
#define DEFAULT_BIN_WIDTH 1
#define DEFAULT_BIN_WIDTH 1
// #define RESERVED_BINS_INC 10
@@ -42,7 +42,7 @@ Histogram::GetNBins () const
{
return m_histogram.size ();
}
double
Histogram::GetBinStart (uint32_t index)
{
@@ -74,22 +74,22 @@ Histogram::GetBinCount (uint32_t index)
NS_ASSERT (index < m_histogram.size ());
return m_histogram[index];
}
void
Histogram::AddValue (double value)
{
uint32_t index = (uint32_t)floor (value/m_binWidth);
//check if we need to resize the vector
NS_LOG_DEBUG ("AddValue: index=" << index << ", m_histogram.size()=" << m_histogram.size ());
if (index >= m_histogram.size ())
{
m_histogram.resize (index + 1, 0);
}
m_histogram[index]++;
}
Histogram::Histogram (double binWidth)
{
m_binWidth = binWidth;
@@ -105,12 +105,12 @@ void
Histogram::SerializeToXmlStream (std::ostream &os, int indent, std::string elementName) const
{
#define INDENT(level) for (int __xpto = 0; __xpto < level; __xpto++) os << ' ';
INDENT(indent); os << "<" << elementName // << " binWidth=\"" << m_binWidth << "\""
<< " nBins=\"" << m_histogram.size () << "\""
<< " >\n";
indent += 2;
#if 1 // two alternative forms of representing bin data, one more verbose than the other one
for (uint32_t index = 0; index < m_histogram.size (); index++)
{

View File

@@ -42,10 +42,10 @@ public:
double GetBinWidth (uint32_t index) const;
void SetDefaultBinWidth (double binWidth);
uint32_t GetBinCount (uint32_t index);
// Method for adding values
void AddValue (double value);
void SerializeToXmlStream (std::ostream &os, int indent, std::string elementName) const;

View File

@@ -61,7 +61,7 @@ bool operator < (const Ipv4FlowClassifier::FiveTuple &t1,
{
return false;
}
if (t1.sourcePort < t2.sourcePort)
{
return true;
@@ -137,11 +137,11 @@ Ipv4FlowClassifier::Classify (const Ipv4Header &ipHeader, Ptr<const Packet> ipPa
default:
return false;
}
// try to insert the tuple, but check if it already exists
std::pair<std::map<FiveTuple, FlowId>::iterator, bool> insert
= m_flowMap.insert (std::pair<FiveTuple, FlowId> (tuple, 0));
// if the insertion succeeded, we need to assign this tuple a new flow identifier
if (insert.second)
{
@@ -159,7 +159,7 @@ Ipv4FlowClassifier::FiveTuple
Ipv4FlowClassifier::FindFlow (FlowId flowId) const
{
for (std::map<FiveTuple, FlowId>::const_iterator
iter = m_flowMap.begin (); iter != m_flowMap.end (); iter++)
iter = m_flowMap.begin (); iter != m_flowMap.end (); iter++)
{
if (iter->second == flowId)
{
@@ -168,7 +168,7 @@ Ipv4FlowClassifier::FindFlow (FlowId flowId) const
}
NS_FATAL_ERROR ("Could not find the flow with ID " << flowId);
FiveTuple retval = { Ipv4Address::GetZero (), Ipv4Address::GetZero (), 0, 0, 0 };
return retval;
return retval;
}
void
@@ -180,7 +180,7 @@ Ipv4FlowClassifier::SerializeToXmlStream (std::ostream &os, int indent) const
indent += 2;
for (std::map<FiveTuple, FlowId>::const_iterator
iter = m_flowMap.begin (); iter != m_flowMap.end (); iter++)
iter = m_flowMap.begin (); iter != m_flowMap.end (); iter++)
{
INDENT(indent);
os << "<Flow flowId=\"" << iter->second << "\""
@@ -194,7 +194,7 @@ Ipv4FlowClassifier::SerializeToXmlStream (std::ostream &os, int indent) const
indent -= 2;
INDENT(indent); os << "</Ipv4FlowClassifier>\n";
#undef INDENT
}

View File

@@ -64,13 +64,13 @@ public:
private:
std::map<FiveTuple, FlowId> m_flowMap;
};
bool operator < (const Ipv4FlowClassifier::FiveTuple &t1, const Ipv4FlowClassifier::FiveTuple &t2);
bool operator == (const Ipv4FlowClassifier::FiveTuple &t1, const Ipv4FlowClassifier::FiveTuple &t2);
} // namespace ns3

View File

@@ -34,9 +34,9 @@ using namespace std;
NS_LOG_COMPONENT_DEFINE ("Ipv4FlowProbe");
//////////////////////////////////////
// Ipv4FlowProbeTag class implementation //
//////////////////////////////////////
//////////////////////////////////////
// Ipv4FlowProbeTag class implementation //
//////////////////////////////////////
class Ipv4FlowProbeTag : public Tag
{
@@ -59,7 +59,7 @@ private:
uint32_t m_flowId;
uint32_t m_packetId;
uint32_t m_packetSize;
};
TypeId
@@ -68,7 +68,7 @@ Ipv4FlowProbeTag::GetTypeId (void)
static TypeId tid = TypeId ("ns3::Ipv4FlowProbeTag")
.SetParent<Tag> ()
.AddConstructor<Ipv4FlowProbeTag> ()
;
;
return tid;
}
TypeId
@@ -104,11 +104,13 @@ Ipv4FlowProbeTag::Print (std::ostream &os) const
}
Ipv4FlowProbeTag::Ipv4FlowProbeTag ()
: Tag ()
{}
{
}
Ipv4FlowProbeTag::Ipv4FlowProbeTag (uint32_t flowId, uint32_t packetId, uint32_t packetSize)
: Tag (), m_flowId (flowId), m_packetId (packetId), m_packetSize (packetSize)
{}
{
}
void
Ipv4FlowProbeTag::SetFlowId (uint32_t id)
@@ -129,7 +131,7 @@ uint32_t
Ipv4FlowProbeTag::GetFlowId (void) const
{
return m_flowId;
}
}
uint32_t
Ipv4FlowProbeTag::GetPacketId (void) const
{
@@ -141,9 +143,9 @@ Ipv4FlowProbeTag::GetPacketSize (void) const
return m_packetSize;
}
////////////////////////////////////////
// Ipv4FlowProbe class implementation //
////////////////////////////////////////
////////////////////////////////////////
// Ipv4FlowProbe class implementation //
////////////////////////////////////////
Ipv4FlowProbe::Ipv4FlowProbe (Ptr<FlowMonitor> monitor,
Ptr<Ipv4FlowClassifier> classifier,
@@ -192,12 +194,12 @@ Ipv4FlowProbe::SendOutgoingLogger (const Ipv4Header &ipHeader, Ptr<const Packet>
{
FlowId flowId;
FlowPacketId packetId;
if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId))
{
uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ());
NS_LOG_DEBUG ("ReportFirstTx ("<<this<<", "<<flowId<<", "<<packetId<<", "<<size<<"); "
<< ipHeader << *ipPayload);
<< ipHeader << *ipPayload);
m_flowMonitor->ReportFirstTx (this, flowId, packetId, size);
// tag the packet with the flow id and packet id, so that the packet can be identified even
@@ -212,7 +214,7 @@ Ipv4FlowProbe::ForwardLogger (const Ipv4Header &ipHeader, Ptr<const Packet> ipPa
{
FlowId flowId;
FlowPacketId packetId;
if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId))
{
uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ());
@@ -224,10 +226,10 @@ Ipv4FlowProbe::ForwardLogger (const Ipv4Header &ipHeader, Ptr<const Packet> ipPa
void
Ipv4FlowProbe::ForwardUpLogger (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload, uint32_t interface)
{
{
FlowId flowId;
FlowPacketId packetId;
if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId))
{
// remove the tags that are added by Ipv4FlowProbe::SendOutgoingLogger ()
@@ -251,7 +253,7 @@ Ipv4FlowProbe::DropLogger (const Ipv4Header &ipHeader, Ptr<const Packet> ipPaylo
{
case Ipv4L3Protocol::DROP_NO_ROUTE:
break;
case Ipv4L3Protocol::DROP_TTL_EXPIRED:
case Ipv4L3Protocol::DROP_BAD_CHECKSUM:
Ipv4Address addri = m_ipv4->GetAddress (ifIndex);
@@ -277,8 +279,8 @@ Ipv4FlowProbe::DropLogger (const Ipv4Header &ipHeader, Ptr<const Packet> ipPaylo
uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ());
NS_LOG_DEBUG ("Drop ("<<this<<", "<<flowId<<", "<<packetId<<", "<<size<<", " << reason
<< ", destIp=" << ipHeader.GetDestination () << "); "
<< "HDR: " << ipHeader << " PKT: " << *ipPayload);
<< ", destIp=" << ipHeader.GetDestination () << "); "
<< "HDR: " << ipHeader << " PKT: " << *ipPayload);
DropReason myReason;
@@ -325,13 +327,13 @@ Ipv4FlowProbe::QueueDropLogger (Ptr<const Packet> ipPayload)
bool tagFound;
tagFound = ConstCast<Packet> (ipPayload)->RemovePacketTag (fTag);
NS_ASSERT_MSG (tagFound, "FlowProbeTag is missing");
FlowId flowId = fTag.GetFlowId ();
FlowPacketId packetId = fTag.GetPacketId ();
uint32_t size = fTag.GetPacketSize ();
NS_LOG_DEBUG ("Drop ("<<this<<", "<<flowId<<", "<<packetId<<", "<<size<<", " << DROP_QUEUE
<< "); ");
<< "); ");
m_flowMonitor->ReportDrop (this, flowId, packetId, size, DROP_QUEUE);
}

View File

@@ -38,34 +38,34 @@ class Node;
/// Ipv4L3Protocol interface of the node.
class Ipv4FlowProbe : public FlowProbe
{
public:
Ipv4FlowProbe (Ptr<FlowMonitor> monitor, Ptr<Ipv4FlowClassifier> classifier, Ptr<Node> node);
virtual ~Ipv4FlowProbe ();
/// \brief enumeration of possible reasons why a packet may be dropped
enum DropReason
{
/// Packet dropped due to missing route to the destination
DROP_NO_ROUTE = 0,
{
/// Packet dropped due to missing route to the destination
DROP_NO_ROUTE = 0,
/// Packet dropped due to TTL decremented to zero during IPv4 forwarding
DROP_TTL_EXPIRE,
/// Packet dropped due to TTL decremented to zero during IPv4 forwarding
DROP_TTL_EXPIRE,
/// Packet dropped due to invalid checksum in the IPv4 header
DROP_BAD_CHECKSUM,
/// Packet dropped due to invalid checksum in the IPv4 header
DROP_BAD_CHECKSUM,
/// Packet dropped due to queue overflow. Note: only works for
/// NetDevices that provide a TxQueue attribute of type Queue
/// with a Drop trace source. It currently works with Csma and
/// PointToPoint devices, but not with WiFi or WiMax.
DROP_QUEUE,
/// Packet dropped due to queue overflow. Note: only works for
/// NetDevices that provide a TxQueue attribute of type Queue
/// with a Drop trace source. It currently works with Csma and
/// PointToPoint devices, but not with WiFi or WiMax.
DROP_QUEUE,
DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
DROP_ROUTE_ERROR, /**< Route error */
DROP_INVALID_REASON,
};
DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
DROP_ROUTE_ERROR, /**< Route error */
DROP_INVALID_REASON,
};
private:

View File

@@ -34,7 +34,8 @@ public:
HistogramTestCase::HistogramTestCase ()
: ns3::TestCase ("Histogram")
{}
{
}
void
@@ -47,19 +48,19 @@ HistogramTestCase::DoRun (void)
{
h0.AddValue (3.4);
}
for (int i=1; i <= 5; i++)
{
{
h0.AddValue (3.6);
}
NS_TEST_EXPECT_MSG_EQ_TOL (h0.GetBinWidth (0), 3.5, 1e-6, "");
NS_TEST_EXPECT_MSG_EQ (h0.GetNBins (), 2, "");
NS_TEST_EXPECT_MSG_EQ_TOL (h0.GetBinStart (1), 3.5, 1e-6, "");
NS_TEST_EXPECT_MSG_EQ (h0.GetBinCount (0), 10, "");
NS_TEST_EXPECT_MSG_EQ (h0.GetBinCount (1), 5, "");
}
{
// Testing bin expansion
h0.AddValue (74.3);