A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-routing-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
10
11#include "ns3/arp-cache.h"
12#include "ns3/ipv4-interface.h"
13#include "ns3/ipv4-l3-protocol.h"
14#include "ns3/ipv4-list-routing.h"
15#include "ns3/ipv4-routing-protocol.h"
16#include "ns3/names.h"
17#include "ns3/node-list.h"
18#include "ns3/node.h"
19#include "ns3/simulator.h"
20
21namespace ns3
22{
23
27
28void
31 Time::Unit unit)
32{
33 for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
34 {
36 Simulator::Schedule(printTime, &Ipv4RoutingHelper::Print, node, stream, unit);
37 }
38}
39
40void
43 Time::Unit unit)
44{
45 for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
46 {
48 Simulator::Schedule(printInterval,
50 printInterval,
51 node,
52 stream,
53 unit);
54 }
55}
56
57void
59 Ptr<Node> node,
61 Time::Unit unit)
62{
63 Simulator::Schedule(printTime, &Ipv4RoutingHelper::Print, node, stream, unit);
64}
65
66void
68 Ptr<Node> node,
70 Time::Unit unit)
71{
72 Simulator::Schedule(printInterval,
74 printInterval,
75 node,
76 stream,
77 unit);
78}
79
80void
82{
83 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
84 if (ipv4)
85 {
86 Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol();
87 NS_ASSERT(rp);
88 rp->PrintRoutingTable(stream, unit);
89 }
90}
91
92void
94 Ptr<Node> node,
96 Time::Unit unit)
97{
98 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
99 if (ipv4)
100 {
101 Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol();
102 NS_ASSERT(rp);
103 rp->PrintRoutingTable(stream, unit);
104 Simulator::Schedule(printInterval,
106 printInterval,
107 node,
108 stream,
109 unit);
110 }
111}
112
113void
116 Time::Unit unit /* = Time::S */)
117{
118 for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
119 {
121 Simulator::Schedule(printTime, &Ipv4RoutingHelper::PrintArpCache, node, stream, unit);
122 }
123}
124
125void
128 Time::Unit unit)
129{
130 for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
131 {
133 Simulator::Schedule(printInterval,
135 printInterval,
136 node,
137 stream,
138 unit);
139 }
140}
141
142void
144 Ptr<Node> node,
146 Time::Unit unit)
147{
148 Simulator::Schedule(printTime, &Ipv4RoutingHelper::PrintArpCache, node, stream, unit);
149}
150
151void
153 Ptr<Node> node,
155 Time::Unit unit)
156{
157 Simulator::Schedule(printInterval,
159 printInterval,
160 node,
161 stream,
162 unit);
163}
164
165void
167{
168 Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol>();
169 if (ipv4)
170 {
171 std::ostream* os = stream->GetStream();
172
173 *os << "ARP Cache of node ";
174 std::string found = Names::FindName(node);
175 if (!Names::FindName(node).empty())
176 {
177 *os << found;
178 }
179 else
180 {
181 *os << static_cast<int>(node->GetId());
182 }
183 *os << " at time " << Simulator::Now().GetSeconds() << "\n";
184
185 for (uint32_t i = 0; i < ipv4->GetNInterfaces(); i++)
186 {
187 Ptr<ArpCache> arpCache = ipv4->GetInterface(i)->GetArpCache();
188 if (arpCache)
189 {
190 arpCache->PrintArpCache(stream);
191 }
192 }
193 }
194}
195
196void
198 Ptr<Node> node,
200 Time::Unit unit)
201{
202 Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol>();
203 if (ipv4)
204 {
205 std::ostream* os = stream->GetStream();
206
207 *os << "ARP Cache of node ";
208 std::string found = Names::FindName(node);
209 if (!Names::FindName(node).empty())
210 {
211 *os << found;
212 }
213 else
214 {
215 *os << static_cast<int>(node->GetId());
216 }
217 *os << " at time " << Simulator::Now().GetSeconds() << "\n";
218
219 for (uint32_t i = 0; i < ipv4->GetNInterfaces(); i++)
220 {
221 Ptr<ArpCache> arpCache = ipv4->GetInterface(i)->GetArpCache();
222 if (arpCache)
223 {
224 arpCache->PrintArpCache(stream);
225 }
226 }
227 Simulator::Schedule(printInterval,
229 printInterval,
230 node,
231 stream,
232 unit);
233 }
234}
235
236} // namespace ns3
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
Implement the IPv4 layer.
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 PrintRoutingTableAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of all nodes at a particular time.
static void PrintArpCache(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 PrintEvery(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.
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 Print(Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
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 PrintArpCacheEvery(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 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.
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 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:818
static uint32_t GetNNodes()
Definition node-list.cc:247
static Ptr< Node > GetNode(uint32_t n)
Definition node-list.cc:240
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:100
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Every class exported by the ns3 library is enclosed in the ns3 namespace.