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 * 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
16namespace ns3
17{
18
20{
21 m_agentFactory.SetTypeId("ns3::olsr::RoutingProtocol");
22}
23
25 : m_agentFactory(o.m_agentFactory)
26{
28}
29
32{
33 return new OlsrHelper(*this);
34}
35
36void
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
56{
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
70void
71OlsrHelper::Set(std::string name, const AttributeValue& value)
72{
73 m_agentFactory.Set(name, value);
74}
75
76int64_t
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");
89 if (olsr)
90 {
91 currentStream += olsr->AssignStreams(currentStream);
92 continue;
93 }
94 // Olsr may also be in a list
96 if (list)
97 {
98 int16_t priority;
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
Hold a value for an Attribute.
Definition attribute.h:59
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
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:31
void Set(std::string name, const AttributeValue &value)
void ExcludeInterface(Ptr< Node > node, uint32_t interface)
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
OlsrHelper()
Create an OlsrHelper that makes life easier for people who want to install OLSR routing to nodes.
OlsrHelper * Copy() const override
std::map< Ptr< Node >, std::set< uint32_t > > m_interfaceExclusions
container of interfaces excluded from OLSR operations
Definition olsr-helper.h:99
Ptr< Ipv4RoutingProtocol > Create(Ptr< Node > node) const override
ObjectFactory m_agentFactory
Object factory.
Definition olsr-helper.h:96
Smart pointer class similar to boost::intrusive_ptr.
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:75
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
Definition olsr.py:1