A Discrete-Event Network Simulator
API
ipv4-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/ipv4-routing-protocol.h"
25 #include "ns3/ipv4-list-routing.h"
26 #include "ns3/ipv4-l3-protocol.h"
27 #include "ns3/ipv4-interface.h"
28 #include "ns3/arp-cache.h"
29 #include "ns3/names.h"
30 #include "ipv4-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, &Ipv4RoutingHelper::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, &Ipv4RoutingHelper::PrintEvery, printInterval, node, stream, unit);
55  }
56 }
57 
58 void
60 {
61  Simulator::Schedule (printTime, &Ipv4RoutingHelper::Print, node, stream, unit);
62 }
63 
64 void
66 {
67  Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintEvery, printInterval, node, stream, unit);
68 }
69 
70 void
72 {
73  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
74  if (ipv4)
75  {
76  Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol ();
77  NS_ASSERT (rp);
78  rp->PrintRoutingTable (stream, unit);
79  }
80 }
81 
82 void
84 {
85  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
86  if (ipv4)
87  {
88  Ptr<Ipv4RoutingProtocol> rp = ipv4->GetRoutingProtocol ();
89  NS_ASSERT (rp);
90  rp->PrintRoutingTable (stream, unit);
91  Simulator::Schedule (printInterval, &Ipv4RoutingHelper::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, &Ipv4RoutingHelper::PrintArpCache, node, stream);
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, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream);
112  }
113 }
114 
115 void
117 {
118  Simulator::Schedule (printTime, &Ipv4RoutingHelper::PrintArpCache, node, stream);
119 }
120 
121 void
123 {
124  Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream);
125 }
126 
127 void
129 {
131  if (ipv4)
132  {
133  std::ostream* os = stream->GetStream ();
134 
135  *os << "ARP 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 ().GetSeconds () << "\n";
146 
147  for (uint32_t i=0; i<ipv4->GetNInterfaces(); i++)
148  {
149  Ptr<ArpCache> arpCache = ipv4->GetInterface (i)->GetArpCache ();
150  if (arpCache)
151  {
152  arpCache->PrintArpCache (stream);
153  }
154  }
155  }
156 }
157 
158 void
160 {
162  if (ipv4)
163  {
164  std::ostream* os = stream->GetStream ();
165 
166  *os << "ARP 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 ().GetSeconds () << "\n";
177 
178  for (uint32_t i=0; i<ipv4->GetNInterfaces(); i++)
179  {
180  Ptr<ArpCache> arpCache = ipv4->GetInterface (i)->GetArpCache ();
181  if (arpCache)
182  {
183  arpCache->PrintArpCache (stream);
184  }
185  }
186  Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream);
187  }
188 }
189 
190 } // namespace ns3
static void PrintNeighborCacheAllAt(Time printTime, Ptr< OutputStreamWrapper > stream)
prints the neighbor cache of all nodes at a particular time.
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
static uint32_t GetNNodes(void)
Definition: node-list.cc:247
static void PrintNeighborCacheAllEvery(Time printInterval, Ptr< OutputStreamWrapper > stream)
prints the neighbor cache of all nodes at regular intervals specified by user.
void PrintArpCache(Ptr< OutputStreamWrapper > stream)
Print the ARP cache entries.
Definition: arp-cache.cc:260
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:241
#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
static void PrintNeighborCacheEvery(Time printInterval, Ptr< Node > node, Ptr< OutputStreamWrapper > stream)
prints the neighbor cache of a node 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 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 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.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1375
static void PrintArpCacheEvery(Time printInterval, Ptr< Node > node, Ptr< OutputStreamWrapper > stream)
prints the neighbor cache of a node at regular intervals specified by user.
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
Implement the IPv4 layer.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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 Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
uint32_t GetId(void) const
Definition: node.cc:107
static void PrintArpCache(Ptr< Node > node, Ptr< OutputStreamWrapper > stream)
prints the neighbor cache of a node.
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:819
static void Print(Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of a node.
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
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 PrintNeighborCacheAt(Time printTime, Ptr< Node > node, Ptr< OutputStreamWrapper > stream)
prints the neighbor cache of a node at a particular time.