A Discrete-Event Network Simulator
API
flow-monitor-helper.cc
Go to the documentation of this file.
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 "flow-monitor-helper.h"
22 
23 #include "ns3/flow-monitor.h"
24 #include "ns3/ipv4-flow-classifier.h"
25 #include "ns3/ipv4-flow-probe.h"
26 #include "ns3/ipv4-l3-protocol.h"
27 #include "ns3/ipv6-flow-classifier.h"
28 #include "ns3/ipv6-flow-probe.h"
29 #include "ns3/ipv6-l3-protocol.h"
30 #include "ns3/node.h"
31 #include "ns3/node-list.h"
32 
33 
34 namespace ns3 {
35 
37 {
38  m_monitorFactory.SetTypeId ("ns3::FlowMonitor");
39 }
40 
42 {
43  if (m_flowMonitor)
44  {
45  m_flowMonitor->Dispose ();
46  m_flowMonitor = 0;
49  }
50 }
51 
52 void
54 {
55  m_monitorFactory.Set (n1, v1);
56 }
57 
58 
61 {
62  if (!m_flowMonitor)
63  {
65  m_flowClassifier4 = Create<Ipv4FlowClassifier> ();
66  m_flowMonitor->AddFlowClassifier (m_flowClassifier4);
67  m_flowClassifier6 = Create<Ipv6FlowClassifier> ();
68  m_flowMonitor->AddFlowClassifier (m_flowClassifier6);
69  }
70  return m_flowMonitor;
71 }
72 
73 
76 {
77  if (!m_flowClassifier4)
78  {
79  m_flowClassifier4 = Create<Ipv4FlowClassifier> ();
80  }
81  return m_flowClassifier4;
82 }
83 
84 
87 {
88  if (!m_flowClassifier6)
89  {
90  m_flowClassifier6 = Create<Ipv6FlowClassifier> ();
91  }
92  return m_flowClassifier6;
93 }
94 
95 
98 {
99  Ptr<FlowMonitor> monitor = GetMonitor ();
100  Ptr<FlowClassifier> classifier = GetClassifier ();
102  if (ipv4)
103  {
104  Ptr<Ipv4FlowProbe> probe = Create<Ipv4FlowProbe> (monitor,
105  DynamicCast<Ipv4FlowClassifier> (classifier),
106  node);
107  }
108  Ptr<FlowClassifier> classifier6 = GetClassifier6 ();
110  if (ipv6)
111  {
112  Ptr<Ipv6FlowProbe> probe6 = Create<Ipv6FlowProbe> (monitor,
113  DynamicCast<Ipv6FlowClassifier> (classifier6),
114  node);
115  }
116  return m_flowMonitor;
117 }
118 
119 
122 {
123  for (NodeContainer::Iterator i = nodes.Begin (); i != nodes.End (); ++i)
124  {
125  Ptr<Node> node = *i;
126  if (node->GetObject<Ipv4L3Protocol> () || node->GetObject<Ipv6L3Protocol> ())
127  {
128  Install (node);
129  }
130  }
131  return m_flowMonitor;
132 }
133 
136 {
137  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
138  {
139  Ptr<Node> node = *i;
140  if (node->GetObject<Ipv4L3Protocol> () || node->GetObject<Ipv6L3Protocol> ())
141  {
142  Install (node);
143  }
144  }
145  return m_flowMonitor;
146 }
147 
148 void
149 FlowMonitorHelper::SerializeToXmlStream (std::ostream &os, uint16_t indent, bool enableHistograms, bool enableProbes)
150 {
151  if (m_flowMonitor)
152  {
153  m_flowMonitor->SerializeToXmlStream (os, indent, enableHistograms, enableProbes);
154  }
155 }
156 
157 std::string
158 FlowMonitorHelper::SerializeToXmlString (uint16_t indent, bool enableHistograms, bool enableProbes)
159 {
160  std::ostringstream os;
161  if (m_flowMonitor)
162  {
163  m_flowMonitor->SerializeToXmlStream (os, indent, enableHistograms, enableProbes);
164  }
165  return os.str ();
166 }
167 
168 void
169 FlowMonitorHelper::SerializeToXmlFile (std::string fileName, bool enableHistograms, bool enableProbes)
170 {
171  if (m_flowMonitor)
172  {
173  m_flowMonitor->SerializeToXmlFile (fileName, enableHistograms, enableProbes);
174  }
175 }
176 
177 
178 } // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:69
Ptr< FlowClassifier > m_flowClassifier6
the FlowClassifier object for IPv6
std::string SerializeToXmlString(uint16_t indent, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but returns the output as a std::string.
Ptr< FlowClassifier > GetClassifier6()
Retrieve the FlowClassifier object for IPv6 created by the Install* methods.
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object for IPv4 created by the Install* methods.
void SetMonitorAttribute(std::string n1, const AttributeValue &v1)
Set an attribute for the to-be-created FlowMonitor object.
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
void SerializeToXmlStream(std::ostream &os, uint16_t indent, bool enableHistograms, bool enableProbes)
Serializes the results to an std::ostream in XML format.
Ptr< FlowMonitor > GetMonitor()
Retrieve the FlowMonitor object created by the Install* methods.
Ptr< FlowClassifier > m_flowClassifier4
the FlowClassifier object for IPv4
Ptr< FlowMonitor > Install(NodeContainer nodes)
Enable flow monitoring on a set of nodes.
ObjectFactory m_monitorFactory
Object factory.
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
Ptr< FlowMonitor > m_flowMonitor
the FlowMonitor object
An object that monitors and reports back packet flows observed during a simulation.
Definition: flow-monitor.h:51
Implement the IPv4 layer.
IPv6 layer implementation.
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
static Iterator End(void)
Definition: node-list.cc:235
static Iterator Begin(void)
Definition: node-list.cc:229
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition: node-list.h:44
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
def indent(source, debug, level)
Definition: check-style.py:432
nodes
Definition: first.py:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.