A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ipv4-global-routing-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  */
16 
17 #include <vector>
18 #include "ns3/boolean.h"
19 #include "ns3/config.h"
20 #include "ns3/inet-socket-address.h"
21 #include "ns3/internet-stack-helper.h"
22 #include "ns3/ipv4-address-helper.h"
23 #include "ns3/ipv4-global-routing-helper.h"
24 #include "ns3/ipv4-static-routing-helper.h"
25 #include "ns3/node.h"
26 #include "ns3/node-container.h"
27 #include "ns3/packet.h"
28 #include "ns3/simple-net-device-helper.h"
29 #include "ns3/pointer.h"
30 #include "ns3/simulator.h"
31 #include "ns3/string.h"
32 #include "ns3/test.h"
33 #include "ns3/uinteger.h"
34 #include "ns3/ipv4-packet-info-tag.h"
35 #include "ns3/simple-net-device.h"
36 #include "ns3/simple-channel.h"
37 #include "ns3/socket-factory.h"
38 #include "ns3/udp-socket-factory.h"
39 
40 using namespace ns3;
41 
43 {
44 public:
47 
48 private:
49  void SendData (uint8_t index);
50  void ShutDownSock (uint8_t index);
51  void SinkRx (std::string path, Ptr<const Packet> p, const Address &address);
52  void HandleRead (Ptr<Socket>);
53  virtual void DoRun (void);
54 
55  int m_count;
56  std::vector<std::pair<Ptr<Socket>, bool> > m_sendSocks;
58  uint16_t m_packetSize;
59  std::vector<uint8_t> m_firstInterface;
60  std::vector<uint8_t> m_secondInterface;
61 };
62 
63 // Add some help text to this case to describe what it is intended to test
65  : TestCase ("Dynamic global routing example"), m_count (0)
66 {
67  m_firstInterface.resize (16);
68  m_secondInterface.resize (16);
69  m_dataRate = DataRate ("2kbps");
70  m_packetSize = 50;
71 }
72 
74 {
75  std::vector<std::pair<Ptr<Socket>, bool> >::iterator iter;
76 
77  for (iter = m_sendSocks.begin (); iter != m_sendSocks.end (); iter++)
78  {
79  if (iter->second)
80  {
81  iter->second = false;
82  iter->first->Close ();
83  iter->first = 0;
84  }
85  }
86 }
87 
88 void
90 {
92  bool found;
93  found = p->PeekPacketTag (tag);
94  uint8_t now = static_cast<uint8_t> (Simulator::Now ().GetSeconds ());
95  if (found)
96  {
97  ;
98  }
99  m_firstInterface[now]++;
100  m_count++;
101 }
102 
103 void
105 {
106  Ptr<Packet> packet;
107  Address from;
108  while ((packet = socket->RecvFrom (from)))
109  {
110  if (packet->GetSize () == 0)
111  { //EOF
112  break;
113  }
114  Ipv4PacketInfoTag tag;
115  bool found;
116  found = packet->PeekPacketTag (tag);
117  uint8_t now = static_cast<uint8_t> (Simulator::Now ().GetSeconds ());
118  if (found)
119  {
120  if (tag.GetRecvIf () == 1)
121  {
122  m_firstInterface[now]++;
123  }
124  if (tag.GetRecvIf () == 2)
125  {
126  m_secondInterface[now]++;
127  }
128  m_count++;
129  }
130  }
131 }
132 
133 void
135 {
136  if (m_sendSocks[index].second == false)
137  {
138  return;
139  }
140  Ptr<Packet> packet = Create<Packet> (m_packetSize);
141  m_sendSocks[index].first->Send (packet);
142 
143  Time tNext (Seconds (m_packetSize * 8 / static_cast<double> (m_dataRate.GetBitRate ())));
144  Simulator::Schedule (tNext, &Ipv4DynamicGlobalRoutingTestCase::SendData, this, index);
145 }
146 
147 void
149 {
150  m_sendSocks[index].second = false;
151  m_sendSocks[index].first->Close ();
152  m_sendSocks[index].first = 0;
153 }
154 
155 // Test derived from examples/routing/dynamic-global-routing.cc
156 //
157 // Network topology
158 //
159 // n0
160 // \ p-p
161 // \ (shared csma/cd)
162 // n2 -------------------------n3
163 // / | |
164 // / p-p n4 n5 ---------- n6
165 // n1 p-p
166 // | |
167 // ----------------------------------------
168 // p-p
169 //
170 // Test that for node n6, the interface facing n5 receives packets at
171 // times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface
172 // facing n1 receives packets at times (2-4), (6-8), (12-13)
173 //
174 void
176 {
177  // The below value configures the default behavior of global routing.
178  // By default, it is disabled. To respond to interface events, set to true
179  Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true));
180 
181  NodeContainer c;
182  c.Create (7);
183  NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
184  NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
185  NodeContainer n5n6 = NodeContainer (c.Get (5), c.Get (6));
186  NodeContainer n1n6 = NodeContainer (c.Get (1), c.Get (6));
187  NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5));
188 
189  InternetStackHelper internet;
190  internet.Install (c);
191 
192  // We create the channels first without any IP addressing information
193  SimpleNetDeviceHelper devHelper;
194 
195  devHelper.SetNetDevicePointToPointMode (true);
196  NetDeviceContainer d0d2 = devHelper.Install (n0n2);
197  devHelper.SetNetDevicePointToPointMode (false);
198 
199  NetDeviceContainer d1d6 = devHelper.Install (n1n6);
200  NetDeviceContainer d1d2 = devHelper.Install (n1n2);
201  NetDeviceContainer d5d6 = devHelper.Install (n5n6);
202  NetDeviceContainer d2345 = devHelper.Install (n2345);
203 
204  // Later, we add IP addresses.
205  Ipv4AddressHelper ipv4;
206  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
207  ipv4.Assign (d0d2);
208 
209  ipv4.SetBase ("10.1.2.0", "255.255.255.0");
210  ipv4.Assign (d1d2);
211 
212  ipv4.SetBase ("10.1.3.0", "255.255.255.0");
213  Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d6);
214 
215  ipv4.SetBase ("10.250.1.0", "255.255.255.0");
216  ipv4.Assign (d2345);
217 
218  ipv4.SetBase ("172.16.1.0", "255.255.255.0");
219  Ipv4InterfaceContainer i1i6 = ipv4.Assign (d1d6);
220 
221  // Create router nodes, initialize routing database and set up the routing
222  // tables in the nodes.
223  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
224 
225  // Create the applications to send UDP datagrams of size
226  // 50 bytes at a rate of 2 Kb/s
227  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
228  uint16_t port = 9; // Discard port (RFC 863)
229 
230  std::pair<Ptr<Socket>, bool> sendSockA;
231  sendSockA.first = Socket::CreateSocket (c.Get (1), tid);
232  sendSockA.first->Bind ();
233  sendSockA.first->Connect (InetSocketAddress (i5i6.GetAddress (1), port));
234  sendSockA.second = true;
235  m_sendSocks.push_back (sendSockA);
236  Simulator::Schedule (Seconds (1.0), &Ipv4DynamicGlobalRoutingTestCase::SendData, this, 0);
237  Simulator::Schedule (Seconds (10.0), &Ipv4DynamicGlobalRoutingTestCase::ShutDownSock, this, 0);
238 
239  std::pair<Ptr<Socket>, bool> sendSockB;
240  sendSockB.first = Socket::CreateSocket (c.Get (1), tid);
241  sendSockB.first->Bind ();
242  sendSockB.first->Connect (InetSocketAddress (i1i6.GetAddress (1), port));
243  sendSockB.second = true;
244  m_sendSocks.push_back (sendSockB);
245  Simulator::Schedule (Seconds (11.0), &Ipv4DynamicGlobalRoutingTestCase::SendData, this, 1);
246  Simulator::Schedule (Seconds (16.0), &Ipv4DynamicGlobalRoutingTestCase::ShutDownSock, this, 1);
247 
248 
249  // Create an optional packet sink to receive these packets
250  Ptr<Socket> sink2 = Socket::CreateSocket (c.Get (6), tid);
251  sink2->Bind (Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
252  sink2->Listen ();
253  sink2->ShutdownSend ();
254 
255  sink2->SetRecvPktInfo (true);
257 
258  Ptr<Node> n1 = c.Get (1);
259  Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4> ();
260  // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
261  // then the next p2p is numbered 2
262  uint32_t ipv4ifIndex1 = 2;
263 
264  // Trace receptions
265  Config::Connect ("/NodeList/6/ApplicationList/*/$ns3::PacketSink/Rx",
267 
268  Simulator::Schedule (Seconds (2), &Ipv4::SetDown,ipv41, ipv4ifIndex1);
269  Simulator::Schedule (Seconds (4), &Ipv4::SetUp,ipv41, ipv4ifIndex1);
270 
271  Ptr<Node> n6 = c.Get (6);
272  Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4> ();
273  // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
274  // then the next p2p is numbered 2
275  uint32_t ipv4ifIndex6 = 2;
276  Simulator::Schedule (Seconds (6), &Ipv4::SetDown,ipv46, ipv4ifIndex6);
277  Simulator::Schedule (Seconds (8), &Ipv4::SetUp,ipv46, ipv4ifIndex6);
278 
279  Simulator::Schedule (Seconds (12), &Ipv4::SetDown,ipv41, ipv4ifIndex1);
280  Simulator::Schedule (Seconds (14), &Ipv4::SetUp,ipv41, ipv4ifIndex1);
281 
282  Simulator::Run ();
283 
284  NS_TEST_ASSERT_MSG_EQ (m_count, 70, "Dynamic global routing did not deliver all packets");
285 // Test that for node n6, the interface facing n5 receives packets at
286 // times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface
287 // facing n1 receives packets at times (2-4), (6-8), (12-13)
288  NS_TEST_ASSERT_MSG_EQ (m_firstInterface[1], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[1]));
289  NS_TEST_ASSERT_MSG_EQ (m_secondInterface[2], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[2]));
290  NS_TEST_ASSERT_MSG_EQ (m_secondInterface[3], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[3]));
291  NS_TEST_ASSERT_MSG_EQ (m_firstInterface[4], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[4]));
292  NS_TEST_ASSERT_MSG_EQ (m_firstInterface[5], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[5]));
293  NS_TEST_ASSERT_MSG_EQ (m_secondInterface[6], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[6]));
294  NS_TEST_ASSERT_MSG_EQ (m_secondInterface[7], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[7]));
295  NS_TEST_ASSERT_MSG_EQ (m_firstInterface[8], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[8]));
296  NS_TEST_ASSERT_MSG_EQ (m_firstInterface[9], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[9]));
297  NS_TEST_ASSERT_MSG_EQ (m_firstInterface[10], 0, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[10]));
298  NS_TEST_ASSERT_MSG_EQ (m_firstInterface[11], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[11]));
299  NS_TEST_ASSERT_MSG_EQ (m_secondInterface[12], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[12]));
300  NS_TEST_ASSERT_MSG_EQ (m_secondInterface[13], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[13]));
301  NS_TEST_ASSERT_MSG_EQ (m_firstInterface[14], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[14]));
302  NS_TEST_ASSERT_MSG_EQ (m_firstInterface[15], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[15]));
303  Simulator::Destroy ();
304 }
305 
307 {
308 public:
311 
313  void ReceivePkt (Ptr<Socket> socket);
314  void DoSendData (Ptr<Socket> socket, std::string to);
315  void SendData (Ptr<Socket> socket, std::string to);
316 
317 private:
318  virtual void DoRun (void);
319 };
320 
321 // Add some help text to this case to describe what it is intended to test
323  : TestCase ("Slash 32 global routing example")
324 {
325 }
326 
328 {
329 }
330 
331 void
333 {
334  uint32_t availableData;
335  availableData = socket->GetRxAvailable ();
336  m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max (), 0);
337  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
338  //cast availableData to void, to suppress 'availableData' set but not used
339  //compiler warning
340  (void) availableData;
341 }
342 
343 void
345 {
346  Address realTo = InetSocketAddress (Ipv4Address (to.c_str ()), 1234);
347  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
348  123, "100");
349 }
350 
351 void
353 {
354  m_receivedPacket = Create<Packet> ();
355  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (60),
357  Simulator::Stop (Seconds (66));
358  Simulator::Run ();
359 }
360 
361 // Test program for this 3-router scenario, using global routing
362 //
363 // (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
364 //
365 void
367 {
368  Ptr<Node> nA = CreateObject<Node> ();
369  Ptr<Node> nB = CreateObject<Node> ();
370  Ptr<Node> nC = CreateObject<Node> ();
371 
372  NodeContainer c = NodeContainer (nA, nB, nC);
373 
374  InternetStackHelper internet;
375  internet.Install (c);
376 
377  // simple links
378  NodeContainer nAnB = NodeContainer (nA, nB);
379  NodeContainer nBnC = NodeContainer (nB, nC);
380 
381  SimpleNetDeviceHelper devHelper;
382 
383  Ptr<SimpleNetDevice> deviceA = CreateObject<SimpleNetDevice> ();
384  deviceA->SetAddress (Mac48Address::Allocate ());
385  nA->AddDevice (deviceA);
386 
387  NetDeviceContainer dAdB = devHelper.Install (nAnB);
388  NetDeviceContainer dBdC = devHelper.Install (nBnC);
389 
390  Ptr<SimpleNetDevice> deviceC = CreateObject<SimpleNetDevice> ();
391  deviceC->SetAddress (Mac48Address::Allocate ());
392  nC->AddDevice (deviceC);
393 
394  // Later, we add IP addresses.
395  Ipv4AddressHelper ipv4;
396  ipv4.SetBase ("10.1.1.0", "255.255.255.252");
397  Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
398 
399  ipv4.SetBase ("10.1.1.4", "255.255.255.252");
400  Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
401 
402  Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
403  Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4> ();
404  Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
405 
406  int32_t ifIndexA = ipv4A->AddInterface (deviceA);
407  int32_t ifIndexC = ipv4C->AddInterface (deviceC);
408 
409  Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("/32"));
410  ipv4A->AddAddress (ifIndexA, ifInAddrA);
411  ipv4A->SetMetric (ifIndexA, 1);
412  ipv4A->SetUp (ifIndexA);
413 
414  Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("/32"));
415  ipv4C->AddAddress (ifIndexC, ifInAddrC);
416  ipv4C->SetMetric (ifIndexC, 1);
417  ipv4C->SetUp (ifIndexC);
418 
419  // Create router nodes, initialize routing database and set up the routing
420  // tables in the nodes.
421  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
422 
423  // Create the UDP sockets
424  Ptr<SocketFactory> rxSocketFactory = nC->GetObject<UdpSocketFactory> ();
425  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
426  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("192.168.1.1"), 1234)), 0, "trivial");
427  rxSocket->SetRecvCallback (MakeCallback (&Ipv4GlobalRoutingSlash32TestCase::ReceivePkt, this));
428 
429  Ptr<SocketFactory> txSocketFactory = nA->GetObject<UdpSocketFactory> ();
430  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
431  txSocket->SetAllowBroadcast (true);
432 
433  // ------ Now the tests ------------
434 
435  // Unicast test
436  SendData (txSocket, "192.168.1.1");
437  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "Static routing with /32 did not deliver all packets.");
438 
439  Simulator::Destroy ();
440 }
441 
442 
444 {
445 public:
447 };
448 
450  : TestSuite ("ipv4-global-routing", UNIT)
451 {
452  AddTestCase (new Ipv4DynamicGlobalRoutingTestCase, TestCase::QUICK);
453  AddTestCase (new Ipv4GlobalRoutingSlash32TestCase, TestCase::QUICK);
454 }
455 
456 // Do not forget to allocate an instance of this TestSuite
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
an Inet address class
Hold a bool native type.
Definition: boolean.h:38
virtual void DoRun(void)
Implementation to actually run this TestCase.
NodeContainer n1n2
Definition: red-tests.cc:63
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
holds a vector of std::pair of Ptr and interface index.
void SinkRx(std::string path, Ptr< const Packet > p, const Address &address)
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:222
virtual int ShutdownSend(void)=0
A suite of tests to run.
Definition: test.h:1289
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:265
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
virtual Ptr< Socket > CreateSocket(void)=0
encapsulates test code
Definition: test.h:1113
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:738
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:86
void SetUp(char *deviceName)
virtual int Listen(void)=0
Listen for incoming connections.
std::vector< std::pair< Ptr< Socket >, bool > > m_sendSocks
Class for representing data rates.
Definition: data-rate.h:71
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
Definition: socket.cc:357
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:322
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:863
virtual void SetUp(uint32_t interface)=0
uint32_t GetRecvIf(void) const
Get the tag's receiving interface.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:148
void DoSendData(Ptr< Socket > socket, std::string to)
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1283
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Definition: socket.cc:127
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:677
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
keep track of a set of node pointers.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
uint64_t GetBitRate() const
Get the underlying bitrate.
Definition: data-rate.cc:235
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SendData(Ptr< Socket > socket, std::string to)
static Ipv4GlobalRoutingTestSuite globalRoutingTestSuite
NodeContainer n0n2
Definition: red-tests.cc:62
virtual void DoRun(void)
Implementation to actually run this TestCase.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:184
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:120
uint32_t GetId(void) const
Definition: node.cc:106
a class to store IPv4 address information on an interface
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
virtual void SetAddress(Address address)
Set the address of this interface.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:845
virtual void SetMetric(uint32_t interface, uint16_t metric)=0
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
tuple address
Definition: first.py:37
API to create UDP socket instances.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
build a set of SimpleNetDevice objects
static void SinkRx(std::string path, Ptr< const Packet > p, const Address &address)
Ptr< T > GetObject(void) const
Definition: object.h:362
a unique identifier for an interface.
Definition: type-id.h:49
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.