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