A Discrete-Event Network Simulator
API
aodv-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
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  * Authors: Pavel Boyko <boyko@iitp.ru>, written after OlsrHelper by Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #include "aodv-helper.h"
21 #include "ns3/aodv-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 
32 {
33  m_agentFactory.SetTypeId ("ns3::aodv::RoutingProtocol");
34 }
35 
36 AodvHelper*
37 AodvHelper::Copy (void) const
38 {
39  return new AodvHelper (*this);
40 }
41 
44 {
46  node->AggregateObject (agent);
47  return agent;
48 }
49 
50 void
51 AodvHelper::Set (std::string name, const AttributeValue &value)
52 {
53  m_agentFactory.Set (name, value);
54 }
55 
56 int64_t
58 {
59  int64_t currentStream = stream;
60  Ptr<Node> node;
61  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
62  {
63  node = (*i);
64  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
65  NS_ASSERT_MSG (ipv4, "Ipv4 not installed on node");
66  Ptr<Ipv4RoutingProtocol> proto = ipv4->GetRoutingProtocol ();
67  NS_ASSERT_MSG (proto, "Ipv4 routing not installed on node");
68  Ptr<aodv::RoutingProtocol> aodv = DynamicCast<aodv::RoutingProtocol> (proto);
69  if (aodv)
70  {
71  currentStream += aodv->AssignStreams (currentStream);
72  continue;
73  }
74  // Aodv may also be in a list
75  Ptr<Ipv4ListRouting> list = DynamicCast<Ipv4ListRouting> (proto);
76  if (list)
77  {
78  int16_t priority;
79  Ptr<Ipv4RoutingProtocol> listProto;
81  for (uint32_t i = 0; i < list->GetNRoutingProtocols (); i++)
82  {
83  listProto = list->GetRoutingProtocol (i, priority);
84  listAodv = DynamicCast<aodv::RoutingProtocol> (listProto);
85  if (listAodv)
86  {
87  currentStream += listAodv->AssignStreams (currentStream);
88  break;
89  }
90  }
91  }
92  }
93  return (currentStream - stream);
94 }
95 
96 }
Helper class that adds AODV routing to nodes.
Definition: aodv-helper.h:35
virtual Ptr< Ipv4RoutingProtocol > Create(Ptr< Node > node) const
Definition: aodv-helper.cc:43
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: aodv-helper.cc:57
AodvHelper * Copy(void) const
Definition: aodv-helper.cc:37
void Set(std::string name, const AttributeValue &value)
Definition: aodv-helper.cc:51
ObjectFactory m_agentFactory
the factory to create AODV routing object
Definition: aodv-helper.h:79
Hold a value for an Attribute.
Definition: attribute.h:69
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:77
a factory to create ns3::Ipv4RoutingProtocol objects
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
#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:88
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define list