A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
olsr-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#include "olsr-helper.h"
20
21#include "ns3/ipv4-list-routing.h"
22#include "ns3/names.h"
23#include "ns3/node-list.h"
24#include "ns3/olsr-routing-protocol.h"
25#include "ns3/ptr.h"
26
27namespace ns3
28{
29
31{
32 m_agentFactory.SetTypeId("ns3::olsr::RoutingProtocol");
33}
34
36 : m_agentFactory(o.m_agentFactory)
37{
39}
40
43{
44 return new OlsrHelper(*this);
45}
46
47void
49{
50 auto it = m_interfaceExclusions.find(node);
51
52 if (it == m_interfaceExclusions.end())
53 {
54 std::set<uint32_t> interfaces;
55 interfaces.insert(interface);
56
57 m_interfaceExclusions.insert(std::make_pair(node, std::set<uint32_t>(interfaces)));
58 }
59 else
60 {
61 it->second.insert(interface);
62 }
63}
64
67{
69
70 auto it = m_interfaceExclusions.find(node);
71
72 if (it != m_interfaceExclusions.end())
73 {
74 agent->SetInterfaceExclusions(it->second);
75 }
76
77 node->AggregateObject(agent);
78 return agent;
79}
80
81void
82OlsrHelper::Set(std::string name, const AttributeValue& value)
83{
84 m_agentFactory.Set(name, value);
85}
86
87int64_t
89{
90 int64_t currentStream = stream;
91 Ptr<Node> node;
92 for (auto i = c.Begin(); i != c.End(); ++i)
93 {
94 node = (*i);
95 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
96 NS_ASSERT_MSG(ipv4, "Ipv4 not installed on node");
97 Ptr<Ipv4RoutingProtocol> proto = ipv4->GetRoutingProtocol();
98 NS_ASSERT_MSG(proto, "Ipv4 routing not installed on node");
99 Ptr<olsr::RoutingProtocol> olsr = DynamicCast<olsr::RoutingProtocol>(proto);
100 if (olsr)
101 {
102 currentStream += olsr->AssignStreams(currentStream);
103 continue;
104 }
105 // Olsr may also be in a list
106 Ptr<Ipv4ListRouting> list = DynamicCast<Ipv4ListRouting>(proto);
107 if (list)
108 {
109 int16_t priority;
110 Ptr<Ipv4RoutingProtocol> listProto;
112 for (uint32_t i = 0; i < list->GetNRoutingProtocols(); i++)
113 {
114 listProto = list->GetRoutingProtocol(i, priority);
115 listOlsr = DynamicCast<olsr::RoutingProtocol>(listProto);
116 if (listOlsr)
117 {
118 currentStream += listOlsr->AssignStreams(currentStream);
119 break;
120 }
121 }
122 }
123 }
124 return (currentStream - stream);
125}
126
127} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:80
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
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.
Helper class that adds OLSR routing to nodes.
Definition: olsr-helper.h:42
void Set(std::string name, const AttributeValue &value)
Definition: olsr-helper.cc:82
void ExcludeInterface(Ptr< Node > node, uint32_t interface)
Definition: olsr-helper.cc:48
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: olsr-helper.cc:88
OlsrHelper()
Create an OlsrHelper that makes life easier for people who want to install OLSR routing to nodes.
Definition: olsr-helper.cc:30
OlsrHelper * Copy() const override
Definition: olsr-helper.cc:42
std::map< Ptr< Node >, std::set< uint32_t > > m_interfaceExclusions
container of interfaces excluded from OLSR operations
Definition: olsr-helper.h:110
Ptr< Ipv4RoutingProtocol > Create(Ptr< Node > node) const override
Definition: olsr-helper.cc:66
ObjectFactory m_agentFactory
Object factory.
Definition: olsr-helper.h:107
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
OLSR routing protocol for IPv4.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: olsr.py:1
#define list