A Discrete-Event Network Simulator
API
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 
30 {
31  m_agentFactory.SetTypeId ("ns3::olsr::RoutingProtocol");
32 }
33 
35  : m_agentFactory (o.m_agentFactory)
36 {
38 }
39 
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 
66 {
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
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;
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
OlsrHelper * Copy(void) const
Definition: olsr-helper.cc:41
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Hold a value for an Attribute.
Definition: attribute.h:68
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
void Set(std::string name, const AttributeValue &value)
Definition: olsr-helper.cc:81
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:87
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:40
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
std::map< Ptr< Node >, std::set< uint32_t > > m_interfaceExclusions
container of interfaces excluded from OLSR operations
Definition: olsr-helper.h:109
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
ObjectFactory m_agentFactory
Object factory.
Definition: olsr-helper.h:107
OLSR routing protocol for IPv4.
#define list
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
Definition: olsr.py:1
interfaces
Definition: first.py:41
virtual Ptr< Ipv4RoutingProtocol > Create(Ptr< Node > node) const
Definition: olsr-helper.cc:65
OlsrHelper()
Create an OlsrHelper that makes life easier for people who want to install OLSR routing to nodes...
Definition: olsr-helper.cc:29
void ExcludeInterface(Ptr< Node > node, uint32_t interface)
Definition: olsr-helper.cc:47
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.