A Discrete-Event Network Simulator
API
ipv4-rip-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 Universita' di Firenze
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: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19  */
20 
21 #include "ns3/test.h"
22 #include "ns3/socket-factory.h"
23 #include "ns3/udp-socket-factory.h"
24 #include "ns3/simulator.h"
25 #include "ns3/simple-channel.h"
26 #include "ns3/simple-net-device.h"
27 #include "ns3/drop-tail-queue.h"
28 #include "ns3/socket.h"
29 #include "ns3/boolean.h"
30 #include "ns3/enum.h"
31 
32 #include "ns3/log.h"
33 #include "ns3/node.h"
34 #include "ns3/inet-socket-address.h"
35 
36 #include "ns3/internet-stack-helper.h"
37 #include "ns3/ipv4-address-helper.h"
38 #include "ns3/ipv4-l3-protocol.h"
39 #include "ns3/icmpv4-l4-protocol.h"
40 #include "ns3/udp-l4-protocol.h"
41 #include "ns3/rip.h"
42 #include "ns3/rip-helper.h"
43 #include "ns3/node-container.h"
44 #include "ns3/ipv4-static-routing.h"
45 
46 #include <string>
47 #include <limits>
48 
49 using namespace ns3;
50 
51 // Ipv4RipTest
52 
53 class Ipv4RipTest : public TestCase
54 {
56  void DoSendData (Ptr<Socket> socket, std::string to);
57  void SendData (Ptr<Socket> socket, std::string to);
58 
59 public:
60  virtual void DoRun (void);
61  Ipv4RipTest ();
62 
63  void ReceivePkt (Ptr<Socket> socket);
64 };
65 
67  : TestCase ("RIP")
68 {
69 }
70 
72 {
73  uint32_t availableData;
74  availableData = socket->GetRxAvailable ();
76  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
77  //cast availableData to void, to suppress 'availableData' set but not used
78  //compiler warning
79  (void) availableData;
80 }
81 
82 void
83 Ipv4RipTest::DoSendData (Ptr<Socket> socket, std::string to)
84 {
85  Address realTo = InetSocketAddress (Ipv4Address (to.c_str ()), 1234);
86  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
87  123, "100");
88 }
89 
90 void
91 Ipv4RipTest::SendData (Ptr<Socket> socket, std::string to)
92 {
93  m_receivedPacket = Create<Packet> ();
94  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (60),
95  &Ipv4RipTest::DoSendData, this, socket, to);
96  Simulator::Stop (Seconds (66));
97  Simulator::Run ();
98 }
99 
100 void
102 {
103  // Create topology
104 
105  Ptr<Node> txNode = CreateObject<Node> ();
106  Ptr<Node> rxNode = CreateObject<Node> ();
107  Ptr<Node> routerA = CreateObject<Node> ();
108  Ptr<Node> routerB = CreateObject<Node> ();
109  Ptr<Node> routerC = CreateObject<Node> ();
110 
111  NodeContainer nodes (txNode, rxNode);
112  NodeContainer routers (routerA, routerB, routerC);
113  NodeContainer all (nodes, routers);
114 
115  RipHelper ripRouting;
116  InternetStackHelper internetRouters;
117  internetRouters.SetRoutingHelper (ripRouting);
118  internetRouters.Install (routers);
119 
120  InternetStackHelper internetNodes;
121  internetNodes.Install (nodes);
122 
123  NetDeviceContainer net1;
124  NetDeviceContainer net2;
125  NetDeviceContainer net3;
126  NetDeviceContainer net4;
127 
128  // Sender Node
129  Ptr<SimpleNetDevice> txDev;
130  {
131  txDev = CreateObject<SimpleNetDevice> ();
132  txDev->SetAddress (Mac48Address ("00:00:00:00:00:01"));
133  txNode->AddDevice (txDev);
134  }
135  net1.Add (txDev);
136 
137  // Router A
138  Ptr<SimpleNetDevice> fwDev1routerA, fwDev2routerA;
139  { // first interface
140  fwDev1routerA = CreateObject<SimpleNetDevice> ();
141  fwDev1routerA->SetAddress (Mac48Address ("00:00:00:00:00:02"));
142  routerA->AddDevice (fwDev1routerA);
143  }
144  net1.Add (fwDev1routerA);
145 
146  { // second interface
147  fwDev2routerA = CreateObject<SimpleNetDevice> ();
148  fwDev2routerA->SetAddress (Mac48Address ("00:00:00:00:00:03"));
149  routerA->AddDevice (fwDev2routerA);
150  }
151  net2.Add (fwDev2routerA);
152 
153  // Router B
154  Ptr<SimpleNetDevice> fwDev1routerB, fwDev2routerB;
155  { // first interface
156  fwDev1routerB = CreateObject<SimpleNetDevice> ();
157  fwDev1routerB->SetAddress (Mac48Address ("00:00:00:00:00:04"));
158  routerB->AddDevice (fwDev1routerB);
159  }
160  net2.Add (fwDev1routerB);
161 
162  { // second interface
163  fwDev2routerB = CreateObject<SimpleNetDevice> ();
164  fwDev2routerB->SetAddress (Mac48Address ("00:00:00:00:00:05"));
165  routerB->AddDevice (fwDev2routerB);
166  }
167  net3.Add (fwDev2routerB);
168 
169  // Router C
170  Ptr<SimpleNetDevice> fwDev1routerC, fwDev2routerC;
171  { // first interface
172  fwDev1routerC = CreateObject<SimpleNetDevice> ();
173  fwDev1routerC->SetAddress (Mac48Address ("00:00:00:00:00:06"));
174  routerC->AddDevice (fwDev1routerC);
175  }
176  net3.Add (fwDev1routerC);
177 
178  { // second interface
179  fwDev2routerC = CreateObject<SimpleNetDevice> ();
180  fwDev2routerC->SetAddress (Mac48Address ("00:00:00:00:00:07"));
181  routerC->AddDevice (fwDev2routerC);
182  }
183  net4.Add (fwDev2routerC);
184 
185  // Rx node
186  Ptr<SimpleNetDevice> rxDev;
187  { // first interface
188  rxDev = CreateObject<SimpleNetDevice> ();
189  rxDev->SetAddress (Mac48Address ("00:00:00:00:00:08"));
190  rxNode->AddDevice (rxDev);
191  }
192  net4.Add (rxDev);
193 
194  // link the channels
195  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
196  txDev->SetChannel (channel1);
197  fwDev1routerA->SetChannel (channel1);
198 
199  Ptr<SimpleChannel> channel2 = CreateObject<SimpleChannel> ();
200  fwDev2routerA->SetChannel (channel2);
201  fwDev1routerB->SetChannel (channel2);
202 
203  Ptr<SimpleChannel> channel3 = CreateObject<SimpleChannel> ();
204  fwDev2routerB->SetChannel (channel3);
205  fwDev1routerC->SetChannel (channel3);
206 
207  Ptr<SimpleChannel> channel4 = CreateObject<SimpleChannel> ();
208  fwDev2routerC->SetChannel (channel4);
209  rxDev->SetChannel (channel4);
210 
211  // Setup IPv4 addresses and forwarding
212  Ipv4AddressHelper ipv4;
213 
214  ipv4.SetBase (Ipv4Address ("10.0.1.0"), Ipv4Mask ("255.255.255.0"));
215  Ipv4InterfaceContainer iic1 = ipv4.Assign (net1);
216 
217  ipv4.SetBase (Ipv4Address ("192.168.0.0"), Ipv4Mask ("255.255.255.0"));
218  Ipv4InterfaceContainer iic2 = ipv4.Assign (net2);
219 
220  ipv4.SetBase (Ipv4Address ("192.168.1.0"), Ipv4Mask ("255.255.255.0"));
221  Ipv4InterfaceContainer iic3 = ipv4.Assign (net3);
222 
223  ipv4.SetBase (Ipv4Address ("10.0.2.0"), Ipv4Mask ("255.255.255.0"));
224  Ipv4InterfaceContainer iic4 = ipv4.Assign (net4);
225 
226  Ptr<Ipv4StaticRouting> staticRouting;
227  staticRouting = Ipv4RoutingHelper::GetRouting <Ipv4StaticRouting> (txNode->GetObject<Ipv4> ()->GetRoutingProtocol ());
228  staticRouting->SetDefaultRoute ("10.0.1.2", 1 );
229  staticRouting = Ipv4RoutingHelper::GetRouting <Ipv4StaticRouting> (rxNode->GetObject<Ipv4> ()->GetRoutingProtocol ());
230  staticRouting->SetDefaultRoute ("10.0.2.1", 1 );
231 
232  // Create the UDP sockets
233  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
234  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
235  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.2.2"), 1234)), 0, "trivial");
236  rxSocket->SetRecvCallback (MakeCallback (&Ipv4RipTest::ReceivePkt, this));
237 
238  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
239  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
240  txSocket->SetAllowBroadcast (true);
241 
242  // ------ Now the tests ------------
243 
244  // Unicast test
245  SendData (txSocket, "10.0.2.2");
246  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "IPv4 RIP should work.");
247 
249 
250  Simulator::Destroy ();
251 }
252 
253 // Ipv4RipCountToInfinityTest
254 
256 {
258  void DoSendData (Ptr<Socket> socket, std::string to);
259  void SendData (Ptr<Socket> socket, std::string to);
260 
261 public:
262  virtual void DoRun (void);
264 
265  void ReceivePkt (Ptr<Socket> socket);
266 };
267 
269  : TestCase ("RIP counting to infinity")
270 {
271 }
272 
274 {
275  uint32_t availableData;
276  availableData = socket->GetRxAvailable ();
278  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
279  //cast availableData to void, to suppress 'availableData' set but not used
280  //compiler warning
281  (void) availableData;
282 }
283 
284 void
286 {
287  Address realTo = InetSocketAddress (Ipv4Address (to.c_str ()), 1234);
288  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
289  123, "100");
290 }
291 
292 void
294 {
295  m_receivedPacket = Create<Packet> ();
296  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (60),
297  &Ipv4RipCountToInfinityTest::DoSendData, this, socket, to);
298  Simulator::Stop (Seconds (66));
299  Simulator::Run ();
300 }
301 
302 void
304 {
305  // Create topology
306 
307  Ptr<Node> txNode = CreateObject<Node> ();
308  Ptr<Node> rxNode = CreateObject<Node> ();
309  Ptr<Node> routerA = CreateObject<Node> ();
310  Ptr<Node> routerB = CreateObject<Node> ();
311  Ptr<Node> routerC = CreateObject<Node> ();
312 
313  NodeContainer nodes (txNode, rxNode);
314  NodeContainer routers (routerA, routerB, routerC);
315  NodeContainer all (nodes, routers);
316 
317  RipHelper ripNgRouting;
318  // Change the router's interface metric to 10, must not send packets (count to infinity)
319  // note: Interface 0 is the loopback.
320  ripNgRouting.SetInterfaceMetric (routerA, 2, 10);
321  ripNgRouting.SetInterfaceMetric (routerB, 1, 10);
322  ripNgRouting.SetInterfaceMetric (routerB, 2, 10);
323  ripNgRouting.SetInterfaceMetric (routerC, 1, 10);
324 
325  InternetStackHelper internetv6routers;
326  internetv6routers.SetRoutingHelper (ripNgRouting);
327  internetv6routers.Install (routers);
328 
329  InternetStackHelper internetv6nodes;
330  internetv6nodes.Install (nodes);
331 
332  NetDeviceContainer net1;
333  NetDeviceContainer net2;
334  NetDeviceContainer net3;
335  NetDeviceContainer net4;
336 
337  // Sender Node
338  Ptr<SimpleNetDevice> txDev;
339  {
340  txDev = CreateObject<SimpleNetDevice> ();
341  txDev->SetAddress (Mac48Address ("00:00:00:00:00:01"));
342  txNode->AddDevice (txDev);
343  }
344  net1.Add (txDev);
345 
346  // Router A
347  Ptr<SimpleNetDevice> fwDev1routerA, fwDev2routerA;
348  { // first interface
349  fwDev1routerA = CreateObject<SimpleNetDevice> ();
350  fwDev1routerA->SetAddress (Mac48Address ("00:00:00:00:00:02"));
351  routerA->AddDevice (fwDev1routerA);
352  }
353  net1.Add (fwDev1routerA);
354 
355  { // second interface
356  fwDev2routerA = CreateObject<SimpleNetDevice> ();
357  fwDev2routerA->SetAddress (Mac48Address ("00:00:00:00:00:03"));
358  routerA->AddDevice (fwDev2routerA);
359  }
360  net2.Add (fwDev2routerA);
361 
362  // Router B
363  Ptr<SimpleNetDevice> fwDev1routerB, fwDev2routerB;
364  { // first interface
365  fwDev1routerB = CreateObject<SimpleNetDevice> ();
366  fwDev1routerB->SetAddress (Mac48Address ("00:00:00:00:00:04"));
367  routerB->AddDevice (fwDev1routerB);
368  }
369  net2.Add (fwDev1routerB);
370 
371  { // second interface
372  fwDev2routerB = CreateObject<SimpleNetDevice> ();
373  fwDev2routerB->SetAddress (Mac48Address ("00:00:00:00:00:05"));
374  routerB->AddDevice (fwDev2routerB);
375  }
376  net3.Add (fwDev2routerB);
377 
378  // Router C
379  Ptr<SimpleNetDevice> fwDev1routerC, fwDev2routerC;
380  { // first interface
381  fwDev1routerC = CreateObject<SimpleNetDevice> ();
382  fwDev1routerC->SetAddress (Mac48Address ("00:00:00:00:00:06"));
383  routerC->AddDevice (fwDev1routerC);
384  }
385  net3.Add (fwDev1routerC);
386 
387  { // second interface
388  fwDev2routerC = CreateObject<SimpleNetDevice> ();
389  fwDev2routerC->SetAddress (Mac48Address ("00:00:00:00:00:07"));
390  routerC->AddDevice (fwDev2routerC);
391  }
392  net4.Add (fwDev2routerC);
393 
394  // Rx node
395  Ptr<SimpleNetDevice> rxDev;
396  { // first interface
397  rxDev = CreateObject<SimpleNetDevice> ();
398  rxDev->SetAddress (Mac48Address ("00:00:00:00:00:08"));
399  rxNode->AddDevice (rxDev);
400  }
401  net4.Add (rxDev);
402 
403  // link the channels
404  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
405  txDev->SetChannel (channel1);
406  fwDev1routerA->SetChannel (channel1);
407 
408  Ptr<SimpleChannel> channel2 = CreateObject<SimpleChannel> ();
409  fwDev2routerA->SetChannel (channel2);
410  fwDev1routerB->SetChannel (channel2);
411 
412  Ptr<SimpleChannel> channel3 = CreateObject<SimpleChannel> ();
413  fwDev2routerB->SetChannel (channel3);
414  fwDev1routerC->SetChannel (channel3);
415 
416  Ptr<SimpleChannel> channel4 = CreateObject<SimpleChannel> ();
417  fwDev2routerC->SetChannel (channel4);
418  rxDev->SetChannel (channel4);
419 
420  // Setup IPv4 addresses and forwarding
421  Ipv4AddressHelper ipv4;
422 
423  ipv4.SetBase (Ipv4Address ("10.0.1.0"), Ipv4Mask ("255.255.255.0"));
424  Ipv4InterfaceContainer iic1 = ipv4.Assign (net1);
425 
426  ipv4.SetBase (Ipv4Address ("192.168.0.0"), Ipv4Mask ("255.255.255.0"));
427  Ipv4InterfaceContainer iic2 = ipv4.Assign (net2);
428 
429  ipv4.SetBase (Ipv4Address ("192.168.1.0"), Ipv4Mask ("255.255.255.0"));
430  Ipv4InterfaceContainer iic3 = ipv4.Assign (net3);
431 
432  ipv4.SetBase (Ipv4Address ("10.0.2.0"), Ipv4Mask ("255.255.255.0"));
433  Ipv4InterfaceContainer iic4 = ipv4.Assign (net4);
434 
435  Ptr<Ipv4StaticRouting> staticRouting;
436  staticRouting = Ipv4RoutingHelper::GetRouting <Ipv4StaticRouting> (txNode->GetObject<Ipv4> ()->GetRoutingProtocol ());
437  staticRouting->SetDefaultRoute ("10.0.1.2", 1 );
438  staticRouting = Ipv4RoutingHelper::GetRouting <Ipv4StaticRouting> (rxNode->GetObject<Ipv4> ()->GetRoutingProtocol ());
439  staticRouting->SetDefaultRoute ("10.0.2.1", 1 );
440 
441 
442  // Create the UDP sockets
443  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
444  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
445  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.2.2"), 1234)), 0, "trivial");
446  rxSocket->SetRecvCallback (MakeCallback (&Ipv4RipCountToInfinityTest::ReceivePkt, this));
447 
448  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
449  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
450  txSocket->SetAllowBroadcast (true);
451 
452  // ------ Now the tests ------------
453 
454  SendData (txSocket, "10.0.2.2");
455  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "RIP counting to infinity.");
456 
457  Simulator::Destroy ();
458 }
459 
460 // Ipv4RipSplitHorizonStrategyTest
461 
463 {
466 
467 public:
468  virtual void DoRun (void);
470 
471  void ReceivePktProbe (Ptr<Socket> socket);
472 };
473 
475  : TestCase ("RIP Split Horizon strategy")
476 {
477  m_setStrategy = strategy;
478 }
479 
481 {
482  uint32_t availableData;
483  availableData = socket->GetRxAvailable ();
484  Ptr<Packet> receivedPacketProbe = socket->Recv (std::numeric_limits<uint32_t>::max (), 0);
485  NS_ASSERT (availableData == receivedPacketProbe->GetSize ());
486  SocketAddressTag tag;
487  receivedPacketProbe->RemovePacketTag (tag);
488  Ipv4Address senderAddress = InetSocketAddress::ConvertFrom (tag.GetAddress ()).GetIpv4 ();
489 
490  if (senderAddress == "192.168.0.2")
491  {
492  RipHeader hdr;
493  receivedPacketProbe->RemoveHeader (hdr);
494 
495  std::list<RipRte> rtes = hdr.GetRteList ();
496 
497  // validate the RTEs before processing
498  for (std::list<RipRte>::iterator iter = rtes.begin ();
499  iter != rtes.end (); iter++)
500  {
501  if (iter->GetPrefix () == "10.0.1.0")
502  {
503  bool correct = false;
504  if (iter->GetRouteMetric () == 16)
505  {
506  correct = true;
507  m_detectedStrategy = Rip::POISON_REVERSE;
508  }
509  else if (iter->GetRouteMetric () == 2)
510  {
511  correct = true;
512  m_detectedStrategy = Rip::NO_SPLIT_HORIZON;
513  }
514  NS_TEST_EXPECT_MSG_EQ (correct, true, "RIP: unexpected metric value: " << iter->GetRouteMetric ());
515  }
516  }
517  }
518 
519  //cast availableData to void, to suppress 'availableData' set but not used
520  //compiler warning
521  (void) availableData;
522 }
523 
524 void
526 {
527  // Create topology
528 
529  Ptr<Node> fakeNode = CreateObject<Node> ();
530  Ptr<Node> listener = CreateObject<Node> ();
531 
532  Ptr<Node> routerA = CreateObject<Node> ();
533  Ptr<Node> routerB = CreateObject<Node> ();
534 
535  NodeContainer listeners (listener, fakeNode);
536  NodeContainer routers (routerA, routerB);
537  NodeContainer all (routers, listeners);
538 
539  RipHelper ripNgRouting;
540  ripNgRouting.Set ("SplitHorizon", EnumValue (m_setStrategy));
541 
542  InternetStackHelper internetRouters;
543  internetRouters.SetRoutingHelper (ripNgRouting);
544  internetRouters.Install (routers);
545 
546  InternetStackHelper internetNodes;
547  internetNodes.Install (listeners);
548 
549  NetDeviceContainer net0;
550  NetDeviceContainer net1;
551 
552  // Fake Node
553  Ptr<SimpleNetDevice> silentDev;
554  {
555  silentDev = CreateObject<SimpleNetDevice> ();
556  silentDev->SetAddress (Mac48Address ("00:00:00:00:00:01"));
557  fakeNode->AddDevice (silentDev);
558  }
559  net0.Add (silentDev);
560 
561  // Router A
562  Ptr<SimpleNetDevice> silentDevRouterA, fwDevRouterA;
563  { // silent interface
564  silentDevRouterA = CreateObject<SimpleNetDevice> ();
565  silentDevRouterA->SetAddress (Mac48Address ("00:00:00:00:00:02"));
566  routerA->AddDevice (silentDevRouterA);
567  }
568  net0.Add (silentDevRouterA);
569 
570  { // first interface
571  fwDevRouterA = CreateObject<SimpleNetDevice> ();
572  fwDevRouterA->SetAddress (Mac48Address ("00:00:00:00:00:03"));
573  routerA->AddDevice (fwDevRouterA);
574  }
575  net1.Add (fwDevRouterA);
576 
577  // Router B
578  Ptr<SimpleNetDevice> fwDevRouterB;
579  { // first interface
580  fwDevRouterB = CreateObject<SimpleNetDevice> ();
581  fwDevRouterB->SetAddress (Mac48Address ("00:00:00:00:00:04"));
582  routerB->AddDevice (fwDevRouterB);
583  }
584  net1.Add (fwDevRouterB);
585 
586  // listener A
587  Ptr<SimpleNetDevice> listenerDev;
588  {
589  listenerDev = CreateObject<SimpleNetDevice> ();
590  listenerDev->SetAddress (Mac48Address ("00:00:00:00:00:05"));
591  listener->AddDevice (listenerDev);
592  }
593  net1.Add (listenerDev);
594 
595  // link the channels
596  Ptr<SimpleChannel> channel0 = CreateObject<SimpleChannel> ();
597  silentDev->SetChannel (channel0);
598  silentDevRouterA->SetChannel (channel0);
599 
600  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
601  fwDevRouterA->SetChannel (channel1);
602  fwDevRouterB->SetChannel (channel1);
603  listenerDev->SetChannel (channel1);
604 
605  // Setup IPv6 addresses and forwarding
606  Ipv4AddressHelper ipv4;
607 
608  ipv4.SetBase (Ipv4Address ("10.0.1.0"), Ipv4Mask ("255.255.255.0"));
609  Ipv4InterfaceContainer iic0 = ipv4.Assign (net0);
610 
611  ipv4.SetBase (Ipv4Address ("192.168.0.0"), Ipv4Mask ("255.255.255.0"));
612  Ipv4InterfaceContainer iic1 = ipv4.Assign (net1);
613 
614  // Create the UDP sockets
615  Ptr<SocketFactory> rxSocketFactory = listener->GetObject<UdpSocketFactory> ();
616  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
617  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("224.0.0.9"), 520)), 0, "trivial");
618  rxSocket->BindToNetDevice (listenerDev);
619  rxSocket->SetRecvCallback (MakeCallback (&Ipv4RipSplitHorizonStrategyTest::ReceivePktProbe, this));
620 
621  // ------ Now the tests ------------
622 
623  // If the strategy is Split Horizon, then no packet will be received.
624  m_detectedStrategy = Rip::SPLIT_HORIZON;
625 
626  Simulator::Stop (Seconds (66));
627  Simulator::Run ();
628  NS_TEST_EXPECT_MSG_EQ (m_detectedStrategy, m_setStrategy, "RIP counting to infinity.");
629 
630  Simulator::Destroy ();
631 }
632 
633 
634 //-----------------------------------------------------------------------------
635 //-----------------------------------------------------------------------------
637 {
638 public:
639  Ipv4RipTestSuite () : TestSuite ("ipv4-rip", UNIT)
640  {
641  AddTestCase (new Ipv4RipTest, TestCase::QUICK);
642  AddTestCase (new Ipv4RipCountToInfinityTest, TestCase::QUICK);
643  AddTestCase (new Ipv4RipSplitHorizonStrategyTest (Rip::POISON_REVERSE), TestCase::QUICK);
644  AddTestCase (new Ipv4RipSplitHorizonStrategyTest (Rip::SPLIT_HORIZON), TestCase::QUICK);
645  AddTestCase (new Ipv4RipSplitHorizonStrategyTest (Rip::NO_SPLIT_HORIZON), TestCase::QUICK);
646  }
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
an Inet address class
Ptr< Packet > m_receivedPacket
holds a vector of std::pair of Ptr and interface index.
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
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:234
A suite of tests to run.
Definition: test.h:1333
std::list< RipRte > GetRteList(void) const
Get the list of the RTEs included in the message.
Definition: rip-header.cc:264
#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
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:278
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:786
virtual Ptr< Socket > CreateSocket(void)=0
Helper class that adds RIP routing to nodes.
Definition: rip-helper.h:38
encapsulates test code
Definition: test.h:1147
Rip::SplitHorizonType_e m_detectedStrategy
This test suite implements a Unit Test.
Definition: test.h:1343
Ipv4RipSplitHorizonStrategyTest(Rip::SplitHorizonType_e strategy)
a polymophic address class
Definition: address.h:90
void Set(std::string name, const AttributeValue &value)
Definition: rip-helper.cc:81
tuple nodes
Definition: first.py:25
SplitHorizonType_e
Split Horizon strategy type.
Definition: rip.h:201
void ReceivePkt(Ptr< Socket > socket)
Hold variables of type enum.
Definition: enum.h:54
#define max(a, b)
Definition: 80211b.c:45
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:297
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Rip::SplitHorizonType_e m_setStrategy
void SendData(Ptr< Socket > socket, std::string to)
holds a vector of ns3::NetDevice pointers
void ReceivePkt(Ptr< Socket > socket)
This class implements a tag that carries an address of a packet across the socket interface...
Definition: socket.h:1005
virtual void DoRun(void)
Implementation to actually run this TestCase.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1480
void SendData(Ptr< Socket > socket, std::string to)
RipHeader - see RFC 2453
Definition: rip-header.h:157
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
an EUI-48 address
Definition: mac48-address.h:43
void SetInterfaceMetric(Ptr< Node > node, uint32_t interface, uint8_t metric)
Set a metric for an interface.
Definition: rip-helper.cc:176
Ipv4RipTestSuite g_ipv4ripTestSuite
void DoSendData(Ptr< Socket > socket, std::string to)
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
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:128
uint32_t GetId(void) const
Definition: node.cc:107
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
virtual void DoRun(void)
Implementation to actually run this TestCase.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:831
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:895
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
Definition: packet.cc:349
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.
API to create UDP socket instances.
void SetChannel(Ptr< SimpleChannel > channel)
Attach a channel to this net device.
void ReceivePktProbe(Ptr< Socket > socket)
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
void DoSendData(Ptr< Socket > socket, std::string to)
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.