A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
olsr-helper.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#include "
olsr-helper.h
"
21
#include "ns3/olsr-routing-protocol.h"
22
#include "ns3/node-list.h"
23
#include "ns3/names.h"
24
#include "ns3/ptr.h"
25
#include "ns3/ipv4-list-routing.h"
26
27
namespace
ns3 {
28
29
OlsrHelper::OlsrHelper
()
30
{
31
m_agentFactory
.
SetTypeId
(
"ns3::olsr::RoutingProtocol"
);
32
}
33
34
OlsrHelper::OlsrHelper
(
const
OlsrHelper
&o)
35
: m_agentFactory (o.m_agentFactory)
36
{
37
m_interfaceExclusions
= o.
m_interfaceExclusions
;
38
}
39
40
OlsrHelper
*
41
OlsrHelper::Copy
(
void
)
const
42
{
43
return
new
OlsrHelper
(*
this
);
44
}
45
46
void
47
OlsrHelper::ExcludeInterface
(
Ptr<Node>
node, uint32_t interface)
48
{
49
std::map< Ptr<Node>, std::set<uint32_t> >::iterator it =
m_interfaceExclusions
.find (node);
50
51
if
(it ==
m_interfaceExclusions
.end ())
52
{
53
std::set<uint32_t> interfaces;
54
interfaces.insert (interface);
55
56
m_interfaceExclusions
.insert (std::make_pair (node, std::set<uint32_t> (interfaces) ));
57
}
58
else
59
{
60
it->second.insert (interface);
61
}
62
}
63
64
Ptr<Ipv4RoutingProtocol>
65
OlsrHelper::Create
(
Ptr<Node>
node)
const
66
{
67
Ptr<olsr::RoutingProtocol>
agent =
m_agentFactory
.
Create
<
olsr::RoutingProtocol
> ();
68
69
std::map<Ptr<Node>, std::set<uint32_t> >::const_iterator it =
m_interfaceExclusions
.find (node);
70
71
if
(it !=
m_interfaceExclusions
.end ())
72
{
73
agent->SetInterfaceExclusions (it->second);
74
}
75
76
node->
AggregateObject
(agent);
77
return
agent;
78
}
79
80
void
81
OlsrHelper::Set
(std::string name,
const
AttributeValue
&value)
82
{
83
m_agentFactory
.
Set
(name, value);
84
}
85
86
int64_t
87
OlsrHelper::AssignStreams
(
NodeContainer
c, int64_t stream)
88
{
89
int64_t currentStream = stream;
90
Ptr<Node>
node;
91
for
(
NodeContainer::Iterator
i = c.
Begin
(); i != c.
End
(); ++i)
92
{
93
node = (*i);
94
Ptr<Ipv4>
ipv4 = node->
GetObject
<
Ipv4
> ();
95
NS_ASSERT_MSG
(ipv4,
"Ipv4 not installed on node"
);
96
Ptr<Ipv4RoutingProtocol>
proto = ipv4->
GetRoutingProtocol
();
97
NS_ASSERT_MSG
(proto,
"Ipv4 routing not installed on node"
);
98
Ptr<olsr::RoutingProtocol>
olsr = DynamicCast<olsr::RoutingProtocol> (proto);
99
if
(olsr)
100
{
101
currentStream += olsr->AssignStreams (currentStream);
102
continue
;
103
}
104
// Olsr may also be in a list
105
Ptr<Ipv4ListRouting>
list
= DynamicCast<Ipv4ListRouting> (proto);
106
if
(list)
107
{
108
int16_t priority;
109
Ptr<Ipv4RoutingProtocol>
listProto;
110
Ptr<olsr::RoutingProtocol>
listOlsr;
111
for
(uint32_t i = 0; i < list->GetNRoutingProtocols (); i++)
112
{
113
listProto = list->GetRoutingProtocol (i, priority);
114
listOlsr = DynamicCast<olsr::RoutingProtocol> (listProto);
115
if
(listOlsr)
116
{
117
currentStream += listOlsr->AssignStreams (currentStream);
118
break
;
119
}
120
}
121
}
122
}
123
return
(currentStream - stream);
124
125
}
126
127
}
// namespace ns3
src
olsr
helper
olsr-helper.cc
Generated on Tue Nov 13 2012 10:32:21 for ns-3 by
1.8.1.2