A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-routing-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20#include "ipv6-routing-helper.h"
21
22#include "ns3/ipv6-interface.h"
23#include "ns3/ipv6-l3-protocol.h"
24#include "ns3/ipv6-list-routing.h"
25#include "ns3/ipv6-routing-protocol.h"
26#include "ns3/names.h"
27#include "ns3/ndisc-cache.h"
28#include "ns3/node-list.h"
29#include "ns3/node.h"
30#include "ns3/simulator.h"
31
32namespace ns3
33{
34
36{
37}
38
39void
42 Time::Unit unit)
43{
44 for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
45 {
47 Simulator::Schedule(printTime, &Ipv6RoutingHelper::Print, node, stream, unit);
48 }
49}
50
51void
54 Time::Unit unit)
55{
56 for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
57 {
59 Simulator::Schedule(printInterval,
61 printInterval,
62 node,
63 stream,
64 unit);
65 }
66}
67
68void
70 Ptr<Node> node,
72 Time::Unit unit)
73{
74 Simulator::Schedule(printTime, &Ipv6RoutingHelper::Print, node, stream, unit);
75}
76
77void
79 Ptr<Node> node,
81 Time::Unit unit)
82{
83 Simulator::Schedule(printInterval,
85 printInterval,
86 node,
87 stream,
88 unit);
89}
90
91void
93{
94 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
95 if (ipv6)
96 {
97 Ptr<Ipv6RoutingProtocol> rp = ipv6->GetRoutingProtocol();
98 NS_ASSERT(rp);
99 rp->PrintRoutingTable(stream, unit);
100 }
101}
102
103void
105 Ptr<Node> node,
107 Time::Unit unit)
108{
109 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
110 if (ipv6)
111 {
112 Ptr<Ipv6RoutingProtocol> rp = ipv6->GetRoutingProtocol();
113 NS_ASSERT(rp);
114 rp->PrintRoutingTable(stream, unit);
115 Simulator::Schedule(printInterval,
117 printInterval,
118 node,
119 stream,
120 unit);
121 }
122}
123
124void
127 Time::Unit unit /* = Time::S */)
128{
129 for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
130 {
132 Simulator::Schedule(printTime, &Ipv6RoutingHelper::PrintNdiscCache, node, stream, unit);
133 }
134}
135
136void
139 Time::Unit unit /* = Time::S */)
140{
141 for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
142 {
144 Simulator::Schedule(printInterval,
146 printInterval,
147 node,
148 stream,
149 unit);
150 }
151}
152
153void
155 Ptr<Node> node,
157 Time::Unit unit /* = Time::S */)
158{
159 Simulator::Schedule(printTime, &Ipv6RoutingHelper::PrintNdiscCache, node, stream, unit);
160}
161
162void
164 Ptr<Node> node,
166 Time::Unit unit /* = Time::S */)
167{
168 Simulator::Schedule(printInterval,
170 printInterval,
171 node,
172 stream,
173 unit);
174}
175
176void
179 Time::Unit unit /* = Time::S */)
180{
181 Ptr<Ipv6L3Protocol> ipv6 = node->GetObject<Ipv6L3Protocol>();
182 if (ipv6)
183 {
184 std::ostream* os = stream->GetStream();
185
186 *os << "NDISC Cache of node ";
187 std::string found = Names::FindName(node);
188 if (!Names::FindName(node).empty())
189 {
190 *os << found;
191 }
192 else
193 {
194 *os << static_cast<int>(node->GetId());
195 }
196 *os << " at time " << Simulator::Now().As(unit) << "\n";
197
198 for (uint32_t i = 0; i < ipv6->GetNInterfaces(); i++)
199 {
200 Ptr<NdiscCache> ndiscCache = ipv6->GetInterface(i)->GetNdiscCache();
201 if (ndiscCache)
202 {
203 ndiscCache->PrintNdiscCache(stream);
204 }
205 }
206 }
207}
208
209void
211 Ptr<Node> node,
213 Time::Unit unit /* = Time::S */)
214{
215 Ptr<Ipv6L3Protocol> ipv6 = node->GetObject<Ipv6L3Protocol>();
216 if (ipv6)
217 {
218 std::ostream* os = stream->GetStream();
219
220 *os << "NDISC Cache of node ";
221 std::string found = Names::FindName(node);
222 if (!Names::FindName(node).empty())
223 {
224 *os << found;
225 }
226 else
227 {
228 *os << static_cast<int>(node->GetId());
229 }
230 *os << " at time " << Simulator::Now().As(unit) << "\n";
231
232 for (uint32_t i = 0; i < ipv6->GetNInterfaces(); i++)
233 {
234 Ptr<NdiscCache> ndiscCache = ipv6->GetInterface(i)->GetNdiscCache();
235 if (ndiscCache)
236 {
237 ndiscCache->PrintNdiscCache(stream);
238 }
239 }
240 Simulator::Schedule(printInterval,
242 printInterval,
243 node,
244 stream,
245 unit);
246 }
247}
248
249} // namespace ns3
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
IPv6 layer implementation.
static void PrintRoutingTableAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of all nodes at a particular time.
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.
static void PrintNeighborCacheAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of all nodes at a particular time.
static void PrintNdiscCache(Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of a node.
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.
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.
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.
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.
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.
virtual ~Ipv6RoutingHelper()
Destroy an Ipv6 Ipv6RoutingHelper.
static void Print(Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit)
prints the routing tables of a node.
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.
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.
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:830
static uint32_t GetNNodes()
Definition: node-list.cc:258
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:251
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:417
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:111
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
Every class exported by the ns3 library is enclosed in the ns3 namespace.