A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
olsr-helper.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008 INRIA
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7
*/
8
#include "
olsr-helper.h
"
9
10
#include "ns3/ipv4-list-routing.h"
11
#include "ns3/names.h"
12
#include "ns3/node-list.h"
13
#include "ns3/olsr-routing-protocol.h"
14
#include "ns3/ptr.h"
15
16
namespace
ns3
17
{
18
19
OlsrHelper::OlsrHelper
()
20
{
21
m_agentFactory
.SetTypeId(
"ns3::olsr::RoutingProtocol"
);
22
}
23
24
OlsrHelper::OlsrHelper
(
const
OlsrHelper
& o)
25
:
m_agentFactory
(o.
m_agentFactory
)
26
{
27
m_interfaceExclusions
= o.
m_interfaceExclusions
;
28
}
29
30
OlsrHelper
*
31
OlsrHelper::Copy
()
const
32
{
33
return
new
OlsrHelper
(*
this
);
34
}
35
36
void
37
OlsrHelper::ExcludeInterface
(
Ptr<Node>
node,
uint32_t
interface)
38
{
39
auto
it =
m_interfaceExclusions
.find(node);
40
41
if
(it ==
m_interfaceExclusions
.end())
42
{
43
std::set<uint32_t> interfaces;
44
interfaces.insert(interface);
45
46
m_interfaceExclusions
.insert(std::make_pair(node, std::set<uint32_t>(interfaces)));
47
}
48
else
49
{
50
it->second.insert(interface);
51
}
52
}
53
54
Ptr<Ipv4RoutingProtocol>
55
OlsrHelper::Create
(
Ptr<Node>
node)
const
56
{
57
Ptr<olsr::RoutingProtocol>
agent =
m_agentFactory
.Create<
olsr::RoutingProtocol
>();
58
59
auto
it =
m_interfaceExclusions
.find(node);
60
61
if
(it !=
m_interfaceExclusions
.end())
62
{
63
agent->SetInterfaceExclusions(it->second);
64
}
65
66
node->AggregateObject(agent);
67
return
agent;
68
}
69
70
void
71
OlsrHelper::Set
(std::string name,
const
AttributeValue
& value)
72
{
73
m_agentFactory
.Set(name, value);
74
}
75
76
int64_t
77
OlsrHelper::AssignStreams
(
NodeContainer
c, int64_t stream)
78
{
79
int64_t currentStream = stream;
80
Ptr<Node>
node;
81
for
(
auto
i = c.
Begin
(); i != c.
End
(); ++i)
82
{
83
node = (*i);
84
Ptr<Ipv4>
ipv4 = node->GetObject<
Ipv4
>();
85
NS_ASSERT_MSG
(ipv4,
"Ipv4 not installed on node"
);
86
Ptr<Ipv4RoutingProtocol>
proto = ipv4->GetRoutingProtocol();
87
NS_ASSERT_MSG
(proto,
"Ipv4 routing not installed on node"
);
88
Ptr<olsr::RoutingProtocol>
olsr
=
DynamicCast<olsr::RoutingProtocol>
(proto);
89
if
(
olsr
)
90
{
91
currentStream +=
olsr
->AssignStreams(currentStream);
92
continue
;
93
}
94
// Olsr may also be in a list
95
Ptr<Ipv4ListRouting>
list
=
DynamicCast<Ipv4ListRouting>
(proto);
96
if
(
list
)
97
{
98
int16_t priority;
99
Ptr<Ipv4RoutingProtocol>
listProto;
100
Ptr<olsr::RoutingProtocol>
listOlsr;
101
for
(
uint32_t
i = 0; i <
list
->GetNRoutingProtocols(); i++)
102
{
103
listProto =
list
->GetRoutingProtocol(i, priority);
104
listOlsr =
DynamicCast<olsr::RoutingProtocol>
(listProto);
105
if
(listOlsr)
106
{
107
currentStream += listOlsr->AssignStreams(currentStream);
108
break
;
109
}
110
}
111
}
112
}
113
return
(currentStream - stream);
114
}
115
116
}
// namespace ns3
ns3::AttributeValue
Hold a value for an Attribute.
Definition
attribute.h:59
ns3::Ipv4
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition
ipv4.h:69
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
ns3::NodeContainer::End
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Definition
node-container.cc:55
ns3::NodeContainer::Begin
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Definition
node-container.cc:49
ns3::OlsrHelper
Helper class that adds OLSR routing to nodes.
Definition
olsr-helper.h:31
ns3::OlsrHelper::Set
void Set(std::string name, const AttributeValue &value)
Definition
olsr-helper.cc:71
ns3::OlsrHelper::ExcludeInterface
void ExcludeInterface(Ptr< Node > node, uint32_t interface)
Definition
olsr-helper.cc:37
ns3::OlsrHelper::AssignStreams
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:77
ns3::OlsrHelper::OlsrHelper
OlsrHelper()
Create an OlsrHelper that makes life easier for people who want to install OLSR routing to nodes.
Definition
olsr-helper.cc:19
ns3::OlsrHelper::Copy
OlsrHelper * Copy() const override
Definition
olsr-helper.cc:31
ns3::OlsrHelper::m_interfaceExclusions
std::map< Ptr< Node >, std::set< uint32_t > > m_interfaceExclusions
container of interfaces excluded from OLSR operations
Definition
olsr-helper.h:99
ns3::OlsrHelper::Create
Ptr< Ipv4RoutingProtocol > Create(Ptr< Node > node) const override
Definition
olsr-helper.cc:55
ns3::OlsrHelper::m_agentFactory
ObjectFactory m_agentFactory
Object factory.
Definition
olsr-helper.h:96
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::olsr::RoutingProtocol
OLSR routing protocol for IPv4.
Definition
olsr-routing-protocol.h:74
uint32_t
NS_ASSERT_MSG
#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:75
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DynamicCast
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition
ptr.h:580
olsr
Definition
olsr.py:1
olsr-helper.h
list
#define list
Definition
openflow-interface.h:35
src
olsr
helper
olsr-helper.cc
Generated on Wed Jun 11 2025 13:15:36 for ns-3 by
1.13.2