A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
flow-monitor-helper.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 "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/node.h"
28 #include "ns3/node-list.h"
29 
30 
31 namespace ns3 {
32 
34 {
35  m_monitorFactory.SetTypeId ("ns3::FlowMonitor");
36 }
37 
39 {
40  if (m_flowMonitor)
41  {
42  m_flowMonitor->Dispose ();
43  m_flowMonitor = 0;
44  m_flowClassifier = 0;
45  }
46 }
47 
48 void
50 {
51  m_monitorFactory.Set (n1, v1);
52 }
53 
54 
57 {
58  if (!m_flowMonitor)
59  {
60  m_flowMonitor = m_monitorFactory.Create<FlowMonitor> ();
61  m_flowClassifier = Create<Ipv4FlowClassifier> ();
62  m_flowMonitor->SetFlowClassifier (m_flowClassifier);
63  }
64  return m_flowMonitor;
65 }
66 
67 
70 {
71  if (!m_flowClassifier)
72  {
73  m_flowClassifier = Create<Ipv4FlowClassifier> ();
74  }
75  return m_flowClassifier;
76 }
77 
78 
81 {
82  Ptr<FlowMonitor> monitor = GetMonitor ();
83  Ptr<FlowClassifier> classifier = GetClassifier ();
84  Ptr<Ipv4FlowProbe> probe = Create<Ipv4FlowProbe> (monitor,
85  DynamicCast<Ipv4FlowClassifier> (classifier),
86  node);
87  return m_flowMonitor;
88 }
89 
90 
93 {
94  for (NodeContainer::Iterator i = nodes.Begin (); i != nodes.End (); ++i)
95  {
96  Ptr<Node> node = *i;
97  if (node->GetObject<Ipv4L3Protocol> ())
98  {
99  Install (node);
100  }
101  }
102  return m_flowMonitor;
103 }
104 
107 {
108  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
109  {
110  Ptr<Node> node = *i;
111  if (node->GetObject<Ipv4L3Protocol> ())
112  {
113  Install (node);
114  }
115  }
116  return m_flowMonitor;
117 }
118 
119 
120 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Hold a value for an Attribute.
Definition: attribute.h:51
void SetTypeId(TypeId tid)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Ptr< FlowMonitor > GetMonitor()
Retrieve the FlowMonitor object created by the Install* methods.
Ptr< FlowMonitor > Install(NodeContainer nodes)
Enable flow monitoring on a set of nodes.
Ptr< Object > Create(void) const
static Iterator End(void)
Definition: node-list.cc:186
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
void SetMonitorAttribute(std::string n1, const AttributeValue &v1)
Set an attribute for the to-be-created FlowMonitor object.
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object created by the Install* methods.
Implement the Ipv4 layer.
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
void Set(std::string name, const AttributeValue &value)
FlowMonitorHelper()
Construct a FlowMonitorHelper class which makes it easier to configure and use the FlowMonitor...
~FlowMonitorHelper()
Dispose of objects allocated by the helper.
static Iterator Begin(void)
Definition: node-list.cc:180
Ptr< T > GetObject(void) const
Definition: object.h:332
An object that monitors and reports back packet flows observed during a simulation.
Definition: flow-monitor.h:41