A Discrete-Event Network Simulator
API
ipv4-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 "ipv4-routing-helper.h"
21 
22 #include "ns3/arp-cache.h"
23 #include "ns3/ipv4-interface.h"
24 #include "ns3/ipv4-l3-protocol.h"
25 #include "ns3/ipv4-list-routing.h"
26 #include "ns3/ipv4-routing-protocol.h"
27 #include "ns3/names.h"
28 #include "ns3/node-list.h"
29 #include "ns3/node.h"
30 #include "ns3/simulator.h"
31 
32 namespace ns3
33 {
34 
36 {
37 }
38 
39 void
42  Time::Unit unit)
43 {
44  for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
45  {
46  Ptr<Node> node = NodeList::GetNode(i);
47  Simulator::Schedule(printTime, &Ipv4RoutingHelper::Print, node, stream, unit);
48  }
49 }
50 
51 void
54  Time::Unit unit)
55 {
56  for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
57  {
58  Ptr<Node> node = NodeList::GetNode(i);
59  Simulator::Schedule(printInterval,
61  printInterval,
62  node,
63  stream,
64  unit);
65  }
66 }
67 
68 void
70  Ptr<Node> node,
72  Time::Unit unit)
73 {
74  Simulator::Schedule(printTime, &Ipv4RoutingHelper::Print, node, stream, unit);
75 }
76 
77 void
79  Ptr<Node> node,
81  Time::Unit unit)
82 {
83  Simulator::Schedule(printInterval,
85  printInterval,
86  node,
87  stream,
88  unit);
89 }
90 
91 void
93 {
94  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
95  if (ipv4)
96  {
97  Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol();
98  NS_ASSERT(rp);
99  rp->PrintRoutingTable(stream, unit);
100  }
101 }
102 
103 void
105  Ptr<Node> node,
107  Time::Unit unit)
108 {
109  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
110  if (ipv4)
111  {
112  Ptr<Ipv4RoutingProtocol> rp = ipv4->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 
124 void
127  Time::Unit unit /* = Time::S */)
128 {
129  for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
130  {
131  Ptr<Node> node = NodeList::GetNode(i);
132  Simulator::Schedule(printTime, &Ipv4RoutingHelper::PrintArpCache, node, stream, unit);
133  }
134 }
135 
136 void
139  Time::Unit unit)
140 {
141  for (uint32_t i = 0; i < NodeList::GetNNodes(); i++)
142  {
143  Ptr<Node> node = NodeList::GetNode(i);
144  Simulator::Schedule(printInterval,
146  printInterval,
147  node,
148  stream,
149  unit);
150  }
151 }
152 
153 void
155  Ptr<Node> node,
157  Time::Unit unit)
158 {
159  Simulator::Schedule(printTime, &Ipv4RoutingHelper::PrintArpCache, node, stream, unit);
160 }
161 
162 void
164  Ptr<Node> node,
166  Time::Unit unit)
167 {
168  Simulator::Schedule(printInterval,
170  printInterval,
171  node,
172  stream,
173  unit);
174 }
175 
176 void
178 {
180  if (ipv4)
181  {
182  std::ostream* os = stream->GetStream();
183 
184  *os << "ARP Cache of node ";
185  std::string found = Names::FindName(node);
186  if (!Names::FindName(node).empty())
187  {
188  *os << found;
189  }
190  else
191  {
192  *os << static_cast<int>(node->GetId());
193  }
194  *os << " at time " << Simulator::Now().GetSeconds() << "\n";
195 
196  for (uint32_t i = 0; i < ipv4->GetNInterfaces(); i++)
197  {
198  Ptr<ArpCache> arpCache = ipv4->GetInterface(i)->GetArpCache();
199  if (arpCache)
200  {
201  arpCache->PrintArpCache(stream);
202  }
203  }
204  }
205 }
206 
207 void
209  Ptr<Node> node,
211  Time::Unit unit)
212 {
214  if (ipv4)
215  {
216  std::ostream* os = stream->GetStream();
217 
218  *os << "ARP Cache of node ";
219  std::string found = Names::FindName(node);
220  if (!Names::FindName(node).empty())
221  {
222  *os << found;
223  }
224  else
225  {
226  *os << static_cast<int>(node->GetId());
227  }
228  *os << " at time " << Simulator::Now().GetSeconds() << "\n";
229 
230  for (uint32_t i = 0; i < ipv4->GetNInterfaces(); i++)
231  {
232  Ptr<ArpCache> arpCache = ipv4->GetInterface(i)->GetArpCache();
233  if (arpCache)
234  {
235  arpCache->PrintArpCache(stream);
236  }
237  }
238  Simulator::Schedule(printInterval,
240  printInterval,
241  node,
242  stream,
243  unit);
244  }
245 }
246 
247 } // namespace ns3
void PrintArpCache(Ptr< OutputStreamWrapper > stream)
Print the ARP cache entries.
Definition: arp-cache.cc:262
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:80
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:829
uint32_t GetId() const
Definition: node.cc:117
static uint32_t GetNNodes()
Definition: node-list.cc:258
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:251
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
std::ostream * GetStream()
Return a pointer to an ostream previously set in the wrapper.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
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.