A Discrete-Event Network Simulator
API
ipv6-routing-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 
21 #include "ns3/node.h"
22 #include "ns3/node-list.h"
23 #include "ns3/simulator.h"
24 #include "ns3/ipv6-routing-protocol.h"
25 #include "ns3/ipv6-list-routing.h"
26 #include "ns3/ipv6-l3-protocol.h"
27 #include "ns3/ipv6-interface.h"
28 #include "ns3/ndisc-cache.h"
29 #include "ns3/names.h"
30 #include "ipv6-routing-helper.h"
31 
32 namespace ns3 {
33 
35 {
36 }
37 
38 void
40 {
41  for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
42  {
43  Ptr<Node> node = NodeList::GetNode (i);
44  Simulator::Schedule (printTime, &Ipv6RoutingHelper::Print, node, stream, unit);
45  }
46 }
47 
48 void
50 {
51  for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
52  {
53  Ptr<Node> node = NodeList::GetNode (i);
54  Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintEvery, printInterval, node, stream, unit);
55  }
56 }
57 
58 void
60 {
61  Simulator::Schedule (printTime, &Ipv6RoutingHelper::Print, node, stream, unit);
62 }
63 
64 void
66 {
67  Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintEvery, printInterval, node, stream, unit);
68 }
69 
70 void
72 {
73  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
74  if (ipv6)
75  {
76  Ptr<Ipv6RoutingProtocol> rp = ipv6->GetRoutingProtocol ();
77  NS_ASSERT (rp);
78  rp->PrintRoutingTable (stream, unit);
79  }
80 }
81 
82 void
84 {
85  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
86  if (ipv6)
87  {
88  Ptr<Ipv6RoutingProtocol> rp = ipv6->GetRoutingProtocol ();
89  NS_ASSERT (rp);
90  rp->PrintRoutingTable (stream, unit);
91  Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintEvery, printInterval, node, stream, unit);
92  }
93 }
94 
95 void
97 {
98  for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
99  {
100  Ptr<Node> node = NodeList::GetNode (i);
101  Simulator::Schedule (printTime, &Ipv6RoutingHelper::PrintNdiscCache, node, stream, unit);
102  }
103 }
104 
105 void
107 {
108  for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
109  {
110  Ptr<Node> node = NodeList::GetNode (i);
111  Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream, unit);
112  }
113 }
114 
115 void
117 {
118  Simulator::Schedule (printTime, &Ipv6RoutingHelper::PrintNdiscCache, node, stream, unit);
119 }
120 
121 void
123 {
124  Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream, unit);
125 }
126 
127 void
129 {
131  if (ipv6)
132  {
133  std::ostream* os = stream->GetStream ();
134 
135  *os << "NDISC Cache of node ";
136  std::string found = Names::FindName (node);
137  if (Names::FindName (node) != "")
138  {
139  *os << found;
140  }
141  else
142  {
143  *os << static_cast<int> (node->GetId ());
144  }
145  *os << " at time " << Simulator::Now ().As (unit) << "\n";
146 
147  for (uint32_t i=0; i<ipv6->GetNInterfaces(); i++)
148  {
149  Ptr<NdiscCache> ndiscCache = ipv6->GetInterface (i)->GetNdiscCache ();
150  if (ndiscCache)
151  {
152  ndiscCache->PrintNdiscCache (stream);
153  }
154  }
155  }
156 }
157 
158 void
160 {
162  if (ipv6)
163  {
164  std::ostream* os = stream->GetStream ();
165 
166  *os << "NDISC Cache of node ";
167  std::string found = Names::FindName (node);
168  if (Names::FindName (node) != "")
169  {
170  *os << found;
171  }
172  else
173  {
174  *os << static_cast<int> (node->GetId ());
175  }
176  *os << " at time " << Simulator::Now ().As (unit) << "\n";
177 
178  for (uint32_t i=0; i<ipv6->GetNInterfaces(); i++)
179  {
180  Ptr<NdiscCache> ndiscCache = ipv6->GetInterface (i)->GetNdiscCache ();
181  if (ndiscCache)
182  {
183  ndiscCache->PrintNdiscCache (stream);
184  }
185  }
186  Simulator::Schedule (printInterval, &Ipv6RoutingHelper::PrintNdiscCacheEvery, printInterval, node, stream, unit);
187  }
188 }
189 
190 } // namespace ns3
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
ns3::Ipv6RoutingHelper::PrintNeighborCacheEvery
static void PrintNeighborCacheEvery(Time printInterval, Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of a node at regular intervals specified by user.
Definition: ipv6-routing-helper.cc:122
ns3::Ipv6RoutingHelper::Print
static void Print(Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit)
prints the routing tables of a node.
Definition: ipv6-routing-helper.cc:71
ns3::Node::GetId
uint32_t GetId(void) const
Definition: node.cc:109
ns3::Ipv6RoutingHelper::PrintNdiscCacheEvery
static void PrintNdiscCacheEvery(Time printInterval, Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of a node at regular intervals specified by user.
Definition: ipv6-routing-helper.cc:159
ns3::Ipv6RoutingHelper::PrintRoutingTableAt
static void PrintRoutingTableAt(Time printTime, Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of a node at a particular time.
Definition: ipv6-routing-helper.cc:59
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
ns3::Ipv6L3Protocol
IPv6 layer implementation.
Definition: ipv6-l3-protocol.h:63
ns3::NodeList::GetNNodes
static uint32_t GetNNodes(void)
Definition: node-list.cc:247
ns3::OutputStreamWrapper::GetStream
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
Definition: output-stream-wrapper.cc:58
ns3::Time::As
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:429
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
ns3::Ipv6RoutingHelper::PrintNeighborCacheAllEvery
static void PrintNeighborCacheAllEvery(Time printInterval, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of all nodes at regular intervals specified by user.
Definition: ipv6-routing-helper.cc:106
ns3::Ptr< OutputStreamWrapper >
ns3::Ipv6RoutingHelper::PrintEvery
static void PrintEvery(Time printInterval, Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit)
prints the routing tables of a node at regular intervals specified by user.
Definition: ipv6-routing-helper.cc:83
ns3::Names::FindName
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and,...
Definition: names.cc:817
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::Ipv6RoutingHelper::PrintRoutingTableAllEvery
static void PrintRoutingTableAllEvery(Time printInterval, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of all nodes at regular intervals specified by user.
Definition: ipv6-routing-helper.cc:49
ns3::Ipv6RoutingHelper::PrintRoutingTableAllAt
static void PrintRoutingTableAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of all nodes at a particular time.
Definition: ipv6-routing-helper.cc:39
ns3::Ipv6RoutingHelper::PrintNeighborCacheAt
static void PrintNeighborCacheAt(Time printTime, Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of a node at a particular time.
Definition: ipv6-routing-helper.cc:116
ns3::Ipv6RoutingHelper::PrintNeighborCacheAllAt
static void PrintNeighborCacheAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of all nodes at a particular time.
Definition: ipv6-routing-helper.cc:96
ns3::Ipv6RoutingHelper::PrintNdiscCache
static void PrintNdiscCache(Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of a node.
Definition: ipv6-routing-helper.cc:128
ipv6-routing-helper.h
ns3::Ipv6
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
ns3::Ipv6RoutingHelper::PrintRoutingTableEvery
static void PrintRoutingTableEvery(Time printInterval, Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of a node at regular intervals specified by user.
Definition: ipv6-routing-helper.cc:65
ns3::NodeList::GetNode
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:241
ns3::Time::Unit
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:110
ns3::Ipv6RoutingHelper::~Ipv6RoutingHelper
virtual ~Ipv6RoutingHelper()
Destroy an Ipv6 Ipv6RoutingHelper.
Definition: ipv6-routing-helper.cc:34
ns3::NdiscCache::PrintNdiscCache
void PrintNdiscCache(Ptr< OutputStreamWrapper > stream)
Print the NDISC cache entries.
Definition: ndisc-cache.cc:177