A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
flow-probe.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 //
3 // Copyright (c) 2009 INESC Porto
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License version 2 as
7 // published by the Free Software Foundation;
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 //
18 // Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt> <gjcarneiro@gmail.com>
19 //
20 
21 #include "ns3/flow-probe.h"
22 #include "ns3/flow-monitor.h"
23 
24 namespace ns3 {
25 
26 
27 FlowProbe::~FlowProbe ()
28 {
29 }
30 
31 
32 FlowProbe::FlowProbe (Ptr<FlowMonitor> flowMonitor)
33  : m_flowMonitor (flowMonitor)
34 {
35  m_flowMonitor->AddProbe (this);
36 }
37 
38 void
40 {
41  m_flowMonitor = 0;
43 }
44 
45 void
46 FlowProbe::AddPacketStats (FlowId flowId, uint32_t packetSize, Time delayFromFirstProbe)
47 {
48  FlowStats &flow = m_stats[flowId];
49  flow.delayFromFirstProbeSum += delayFromFirstProbe;
50  flow.bytes += packetSize;
51  ++flow.packets;
52 }
53 
54 void
55 FlowProbe::AddPacketDropStats (FlowId flowId, uint32_t packetSize, uint32_t reasonCode)
56 {
57  FlowStats &flow = m_stats[flowId];
58 
59  if (flow.packetsDropped.size () < reasonCode + 1)
60  {
61  flow.packetsDropped.resize (reasonCode + 1, 0);
62  flow.bytesDropped.resize (reasonCode + 1, 0);
63  }
64  ++flow.packetsDropped[reasonCode];
65  flow.bytesDropped[reasonCode] += packetSize;
66 }
67 
68 FlowProbe::Stats
70 {
71  return m_stats;
72 }
73 
74 void
75 FlowProbe::SerializeToXmlStream (std::ostream &os, int indent, uint32_t index) const
76 {
77  #define INDENT(level) for (int __xpto = 0; __xpto < level; __xpto++) os << ' ';
78 
79  INDENT (indent); os << "<FlowProbe index=\"" << index << "\">\n";
80 
81  indent += 2;
82 
83  for (Stats::const_iterator iter = m_stats.begin (); iter != m_stats.end (); iter++)
84  {
85  INDENT (indent);
86  os << "<FlowStats "
87  << " flowId=\"" << iter->first << "\""
88  << " packets=\"" << iter->second.packets << "\""
89  << " bytes=\"" << iter->second.bytes << "\""
90  << " delayFromFirstProbeSum=\"" << iter->second.delayFromFirstProbeSum << "\""
91  << " >\n";
92  indent += 2;
93  for (uint32_t reasonCode = 0; reasonCode < iter->second.packetsDropped.size (); reasonCode++)
94  {
95  INDENT (indent);
96  os << "<packetsDropped reasonCode=\"" << reasonCode << "\""
97  << " number=\"" << iter->second.packetsDropped[reasonCode]
98  << "\" />\n";
99  }
100  for (uint32_t reasonCode = 0; reasonCode < iter->second.bytesDropped.size (); reasonCode++)
101  {
102  INDENT (indent);
103  os << "<bytesDropped reasonCode=\"" << reasonCode << "\""
104  << " bytes=\"" << iter->second.bytesDropped[reasonCode]
105  << "\" />\n";
106  }
107  indent -= 2;
108  INDENT (indent); os << "</FlowStats>\n";
109  }
110  indent -= 2;
111  INDENT (indent); os << "</FlowProbe>\n";
112 }
113 
114 
115 
116 } // namespace ns3
117 
118 
keep track of time unit.
Definition: nstime.h:149
virtual void DoDispose(void)
Definition: object.cc:335
Stats GetStats() const
Definition: flow-probe.cc:69
virtual void DoDispose(void)
Definition: flow-probe.cc:39