A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
flow-monitor-helper.cc
Go to the documentation of this file.
1//
2// Copyright (c) 2009 INESC Porto
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License version 2 as
6// published by the Free Software Foundation;
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt> <gjcarneiro@gmail.com>
18//
19
20#include "flow-monitor-helper.h"
21
22#include "ns3/flow-monitor.h"
23#include "ns3/ipv4-flow-classifier.h"
24#include "ns3/ipv4-flow-probe.h"
25#include "ns3/ipv4-l3-protocol.h"
26#include "ns3/ipv6-flow-classifier.h"
27#include "ns3/ipv6-flow-probe.h"
28#include "ns3/ipv6-l3-protocol.h"
29#include "ns3/node-list.h"
30#include "ns3/node.h"
31
32namespace ns3
33{
34
36{
37 m_monitorFactory.SetTypeId("ns3::FlowMonitor");
38}
39
41{
42 if (m_flowMonitor)
43 {
44 m_flowMonitor->Dispose();
45 m_flowMonitor = nullptr;
46 m_flowClassifier4 = nullptr;
47 m_flowClassifier6 = nullptr;
48 }
49}
50
51void
53{
54 m_monitorFactory.Set(n1, v1);
55}
56
59{
60 if (!m_flowMonitor)
61 {
63 m_flowClassifier4 = Create<Ipv4FlowClassifier>();
64 m_flowMonitor->AddFlowClassifier(m_flowClassifier4);
65 m_flowClassifier6 = Create<Ipv6FlowClassifier>();
66 m_flowMonitor->AddFlowClassifier(m_flowClassifier6);
67 }
68 return m_flowMonitor;
69}
70
73{
75 {
76 m_flowClassifier4 = Create<Ipv4FlowClassifier>();
77 }
78 return m_flowClassifier4;
79}
80
83{
85 {
86 m_flowClassifier6 = Create<Ipv6FlowClassifier>();
87 }
88 return m_flowClassifier6;
89}
90
93{
94 Ptr<FlowMonitor> monitor = GetMonitor();
96 Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol>();
97 if (ipv4)
98 {
99 Ptr<Ipv4FlowProbe> probe =
100 Create<Ipv4FlowProbe>(monitor, DynamicCast<Ipv4FlowClassifier>(classifier), node);
101 }
102 Ptr<FlowClassifier> classifier6 = GetClassifier6();
103 Ptr<Ipv6L3Protocol> ipv6 = node->GetObject<Ipv6L3Protocol>();
104 if (ipv6)
105 {
106 Ptr<Ipv6FlowProbe> probe6 =
107 Create<Ipv6FlowProbe>(monitor, DynamicCast<Ipv6FlowClassifier>(classifier6), node);
108 }
109 return m_flowMonitor;
110}
111
114{
115 for (auto i = nodes.Begin(); i != nodes.End(); ++i)
116 {
117 Ptr<Node> node = *i;
118 if (node->GetObject<Ipv4L3Protocol>() || node->GetObject<Ipv6L3Protocol>())
119 {
120 Install(node);
121 }
122 }
123 return m_flowMonitor;
124}
125
128{
129 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
130 {
131 Ptr<Node> node = *i;
132 if (node->GetObject<Ipv4L3Protocol>() || node->GetObject<Ipv6L3Protocol>())
133 {
134 Install(node);
135 }
136 }
137 return m_flowMonitor;
138}
139
140void
142 uint16_t indent,
143 bool enableHistograms,
144 bool enableProbes)
145{
146 if (m_flowMonitor)
147 {
148 m_flowMonitor->SerializeToXmlStream(os, indent, enableHistograms, enableProbes);
149 }
150}
151
152std::string
153FlowMonitorHelper::SerializeToXmlString(uint16_t indent, bool enableHistograms, bool enableProbes)
154{
155 std::ostringstream os;
156 if (m_flowMonitor)
157 {
158 m_flowMonitor->SerializeToXmlStream(os, indent, enableHistograms, enableProbes);
159 }
160 return os.str();
161}
162
163void
165 bool enableHistograms,
166 bool enableProbes)
167{
168 if (m_flowMonitor)
169 {
170 m_flowMonitor->SerializeToXmlFile(fileName, enableHistograms, enableProbes);
171 }
172}
173
174} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
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:52
Implement the IPv4 layer.
IPv6 layer implementation.
keep track of a set of node pointers.
static Iterator Begin()
Definition: node-list.cc:237
static Iterator End()
Definition: node-list.cc:244
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.