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, 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, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream, unit);
112  }
113 }
114 
115 void
117 {
118  Simulator::Schedule (printTime, &Ipv4RoutingHelper::PrintArpCache, node, stream, unit);
119 }
120 
121 void
123 {
124  Simulator::Schedule (printInterval, &Ipv4RoutingHelper::PrintArpCacheEvery, printInterval, node, stream, unit);
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, unit);
187  }
188 }
189 
190 } // namespace ns3
void PrintArpCache(Ptr< OutputStreamWrapper > stream)
Print the ARP cache entries.
Definition: arp-cache.cc:260
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:77
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:817
uint32_t GetId(void) const
Definition: node.cc:109
static uint32_t GetNNodes(void)
Definition: node-list.cc:247
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:241
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.