A Discrete-Event Network Simulator
API
ipv6-ripng-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 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/socket.h"
28 #include "ns3/boolean.h"
29 #include "ns3/enum.h"
30 
31 #include "ns3/log.h"
32 #include "ns3/node.h"
33 #include "ns3/inet6-socket-address.h"
34 
35 #include "ns3/internet-stack-helper.h"
36 #include "ns3/ipv6-address-helper.h"
37 #include "ns3/ipv6-l3-protocol.h"
38 #include "ns3/icmpv6-l4-protocol.h"
39 #include "ns3/udp-l4-protocol.h"
40 #include "ns3/ripng.h"
41 #include "ns3/ripng-helper.h"
42 #include "ns3/node-container.h"
43 
44 #include <string>
45 #include <limits>
46 
47 using namespace ns3;
48 
55 class Ipv6RipngTest : public TestCase
56 {
58 
64  void DoSendData (Ptr<Socket> socket, std::string to);
70  void SendData (Ptr<Socket> socket, std::string to);
71 
72 public:
73  virtual void DoRun (void);
74  Ipv6RipngTest ();
75 
80  void ReceivePkt (Ptr<Socket> socket);
81 };
82 
84  : TestCase ("RIPng")
85 {
86 }
87 
89 {
90  uint32_t availableData;
91  availableData = socket->GetRxAvailable ();
93  NS_TEST_ASSERT_MSG_EQ (availableData, m_receivedPacket->GetSize (), "Received packet size is not equal to Rx buffer size");
94  //cast availableData to void, to suppress 'availableData' set but not used
95  //compiler warning
96  (void) availableData;
97 }
98 
99 void
100 Ipv6RipngTest::DoSendData (Ptr<Socket> socket, std::string to)
101 {
102  Address realTo = Inet6SocketAddress (Ipv6Address (to.c_str ()), 1234);
103  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
104  123, "100");
105 }
106 
107 void
108 Ipv6RipngTest::SendData (Ptr<Socket> socket, std::string to)
109 {
110  m_receivedPacket = Create<Packet> ();
111  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (60),
112  &Ipv6RipngTest::DoSendData, this, socket, to);
113  Simulator::Stop (Seconds (66));
114  Simulator::Run ();
115 }
116 
117 void
119 {
120  // Create topology
121 
122  Ptr<Node> txNode = CreateObject<Node> ();
123  Ptr<Node> rxNode = CreateObject<Node> ();
124  Ptr<Node> routerA = CreateObject<Node> ();
125  Ptr<Node> routerB = CreateObject<Node> ();
126  Ptr<Node> routerC = CreateObject<Node> ();
127 
128  NodeContainer nodes (txNode, rxNode);
129  NodeContainer routers (routerA, routerB, routerC);
130  NodeContainer all (nodes, routers);
131 
132  RipNgHelper ripNgRouting;
133  InternetStackHelper internetv6routers;
134  internetv6routers.SetRoutingHelper (ripNgRouting);
135  internetv6routers.Install (routers);
136 
137  InternetStackHelper internetv6nodes;
138  internetv6nodes.Install (nodes);
139 
140  NetDeviceContainer net1;
141  NetDeviceContainer net2;
142  NetDeviceContainer net3;
143  NetDeviceContainer net4;
144 
145  // Sender Node
146  Ptr<SimpleNetDevice> txDev;
147  {
148  txDev = CreateObject<SimpleNetDevice> ();
149  txDev->SetAddress (Mac48Address ("00:00:00:00:00:01"));
150  txNode->AddDevice (txDev);
151  }
152  net1.Add (txDev);
153 
154  // Router A
155  Ptr<SimpleNetDevice> fwDev1routerA, 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, fwDev2routerB;
172  { // first interface
173  fwDev1routerB = CreateObject<SimpleNetDevice> ();
174  fwDev1routerB->SetAddress (Mac48Address ("00:00:00:00:00:04"));
175  routerB->AddDevice (fwDev1routerB);
176  }
177  net2.Add (fwDev1routerB);
178 
179  { // second interface
180  fwDev2routerB = CreateObject<SimpleNetDevice> ();
181  fwDev2routerB->SetAddress (Mac48Address ("00:00:00:00:00:05"));
182  routerB->AddDevice (fwDev2routerB);
183  }
184  net3.Add (fwDev2routerB);
185 
186  // Router C
187  Ptr<SimpleNetDevice> fwDev1routerC, fwDev2routerC;
188  { // first interface
189  fwDev1routerC = CreateObject<SimpleNetDevice> ();
190  fwDev1routerC->SetAddress (Mac48Address ("00:00:00:00:00:06"));
191  routerC->AddDevice (fwDev1routerC);
192  }
193  net3.Add (fwDev1routerC);
194 
195  { // second interface
196  fwDev2routerC = CreateObject<SimpleNetDevice> ();
197  fwDev2routerC->SetAddress (Mac48Address ("00:00:00:00:00:07"));
198  routerC->AddDevice (fwDev2routerC);
199  }
200  net4.Add (fwDev2routerC);
201 
202  // Rx node
203  Ptr<SimpleNetDevice> rxDev;
204  { // first interface
205  rxDev = CreateObject<SimpleNetDevice> ();
206  rxDev->SetAddress (Mac48Address ("00:00:00:00:00:08"));
207  rxNode->AddDevice (rxDev);
208  }
209  net4.Add (rxDev);
210 
211  // link the channels
212  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
213  txDev->SetChannel (channel1);
214  fwDev1routerA->SetChannel (channel1);
215 
216  Ptr<SimpleChannel> channel2 = CreateObject<SimpleChannel> ();
217  fwDev2routerA->SetChannel (channel2);
218  fwDev1routerB->SetChannel (channel2);
219 
220  Ptr<SimpleChannel> channel3 = CreateObject<SimpleChannel> ();
221  fwDev2routerB->SetChannel (channel3);
222  fwDev1routerC->SetChannel (channel3);
223 
224  Ptr<SimpleChannel> channel4 = CreateObject<SimpleChannel> ();
225  fwDev2routerC->SetChannel (channel4);
226  rxDev->SetChannel (channel4);
227 
228  // Setup IPv6 addresses and forwarding
229  Ipv6AddressHelper ipv6;
230 
231  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
232  Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutOnLink (net1);
233  iic1.SetForwarding (1, true);
234  iic1.SetDefaultRouteInAllNodes (1);
235 
236  Ipv6InterfaceContainer iic2 = ipv6.AssignWithoutAddress (net2);
237  iic2.SetForwarding (0, true);
238  iic2.SetForwarding (1, true);
239 
240  Ipv6InterfaceContainer iic3 = ipv6.AssignWithoutAddress (net3);
241  iic3.SetForwarding (0, true);
242  iic3.SetForwarding (1, true);
243 
244  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
245  Ipv6InterfaceContainer iic4 = ipv6.AssignWithoutOnLink (net4);
246  iic4.SetForwarding (0, true);
247  iic4.SetDefaultRouteInAllNodes (0);
248 
249  // Create the UDP sockets
250  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
251  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
252  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("2001:2::200:ff:fe00:8"), 1234)), 0, "trivial");
253  rxSocket->SetRecvCallback (MakeCallback (&Ipv6RipngTest::ReceivePkt, this));
254 
255  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
256  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
257  txSocket->SetAllowBroadcast (true);
258 
259  // ------ Now the tests ------------
260 
261  // Unicast test
262  SendData (txSocket, "2001:2::200:ff:fe00:8");
263  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "IPv6 RIPng should work.");
264 
266 
267  Simulator::Destroy ();
268 }
269 
270 // Ipv6RipngCountToInfinityTest
271 
279 {
281 
287  void DoSendData (Ptr<Socket> socket, std::string to);
293  void SendData (Ptr<Socket> socket, std::string to);
294 
295 public:
296  virtual void DoRun (void);
298 
303  void ReceivePkt (Ptr<Socket> socket);
304 };
305 
307  : TestCase ("RIPng counting to infinity")
308 {
309 }
310 
312 {
313  uint32_t availableData;
314  availableData = socket->GetRxAvailable ();
316  NS_TEST_ASSERT_MSG_EQ (availableData, m_receivedPacket->GetSize (), "Received packet size is not equal to Rx buffer size");
317  //cast availableData to void, to suppress 'availableData' set but not used
318  //compiler warning
319  (void) availableData;
320 }
321 
322 void
324 {
325  Address realTo = Inet6SocketAddress (Ipv6Address (to.c_str ()), 1234);
326  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
327  123, "100");
328 }
329 
330 void
332 {
333  m_receivedPacket = Create<Packet> ();
334  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (60),
335  &Ipv6RipngCountToInfinityTest::DoSendData, this, socket, to);
336  Simulator::Stop (Seconds (66));
337  Simulator::Run ();
338 }
339 
340 void
342 {
343  // Create topology
344 
345  Ptr<Node> txNode = CreateObject<Node> ();
346  Ptr<Node> rxNode = CreateObject<Node> ();
347  Ptr<Node> routerA = CreateObject<Node> ();
348  Ptr<Node> routerB = CreateObject<Node> ();
349  Ptr<Node> routerC = CreateObject<Node> ();
350 
351  NodeContainer nodes (txNode, rxNode);
352  NodeContainer routers (routerA, routerB, routerC);
353  NodeContainer all (nodes, routers);
354 
355  RipNgHelper ripNgRouting;
356  // Change the router's interface metric to 10, must not send packets (count to infinity)
357  // note: Interface 0 is the loopback.
358  ripNgRouting.SetInterfaceMetric (routerA, 2, 10);
359  ripNgRouting.SetInterfaceMetric (routerB, 1, 10);
360  ripNgRouting.SetInterfaceMetric (routerB, 2, 10);
361  ripNgRouting.SetInterfaceMetric (routerC, 1, 10);
362 
363  InternetStackHelper internetv6routers;
364  internetv6routers.SetRoutingHelper (ripNgRouting);
365  internetv6routers.Install (routers);
366 
367  InternetStackHelper internetv6nodes;
368  internetv6nodes.Install (nodes);
369 
370  NetDeviceContainer net1;
371  NetDeviceContainer net2;
372  NetDeviceContainer net3;
373  NetDeviceContainer net4;
374 
375  // Sender Node
376  Ptr<SimpleNetDevice> txDev;
377  {
378  txDev = CreateObject<SimpleNetDevice> ();
379  txDev->SetAddress (Mac48Address ("00:00:00:00:00:01"));
380  txNode->AddDevice (txDev);
381  }
382  net1.Add (txDev);
383 
384  // Router A
385  Ptr<SimpleNetDevice> fwDev1routerA, fwDev2routerA;
386  { // first interface
387  fwDev1routerA = CreateObject<SimpleNetDevice> ();
388  fwDev1routerA->SetAddress (Mac48Address ("00:00:00:00:00:02"));
389  routerA->AddDevice (fwDev1routerA);
390  }
391  net1.Add (fwDev1routerA);
392 
393  { // second interface
394  fwDev2routerA = CreateObject<SimpleNetDevice> ();
395  fwDev2routerA->SetAddress (Mac48Address ("00:00:00:00:00:03"));
396  routerA->AddDevice (fwDev2routerA);
397  }
398  net2.Add (fwDev2routerA);
399 
400  // Router B
401  Ptr<SimpleNetDevice> fwDev1routerB, fwDev2routerB;
402  { // first interface
403  fwDev1routerB = CreateObject<SimpleNetDevice> ();
404  fwDev1routerB->SetAddress (Mac48Address ("00:00:00:00:00:04"));
405  routerB->AddDevice (fwDev1routerB);
406  }
407  net2.Add (fwDev1routerB);
408 
409  { // second interface
410  fwDev2routerB = CreateObject<SimpleNetDevice> ();
411  fwDev2routerB->SetAddress (Mac48Address ("00:00:00:00:00:05"));
412  routerB->AddDevice (fwDev2routerB);
413  }
414  net3.Add (fwDev2routerB);
415 
416  // Router C
417  Ptr<SimpleNetDevice> fwDev1routerC, fwDev2routerC;
418  { // first interface
419  fwDev1routerC = CreateObject<SimpleNetDevice> ();
420  fwDev1routerC->SetAddress (Mac48Address ("00:00:00:00:00:06"));
421  routerC->AddDevice (fwDev1routerC);
422  }
423  net3.Add (fwDev1routerC);
424 
425  { // second interface
426  fwDev2routerC = CreateObject<SimpleNetDevice> ();
427  fwDev2routerC->SetAddress (Mac48Address ("00:00:00:00:00:07"));
428  routerC->AddDevice (fwDev2routerC);
429  }
430  net4.Add (fwDev2routerC);
431 
432  // Rx node
433  Ptr<SimpleNetDevice> rxDev;
434  { // first interface
435  rxDev = CreateObject<SimpleNetDevice> ();
436  rxDev->SetAddress (Mac48Address ("00:00:00:00:00:08"));
437  rxNode->AddDevice (rxDev);
438  }
439  net4.Add (rxDev);
440 
441  // link the channels
442  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
443  txDev->SetChannel (channel1);
444  fwDev1routerA->SetChannel (channel1);
445 
446  Ptr<SimpleChannel> channel2 = CreateObject<SimpleChannel> ();
447  fwDev2routerA->SetChannel (channel2);
448  fwDev1routerB->SetChannel (channel2);
449 
450  Ptr<SimpleChannel> channel3 = CreateObject<SimpleChannel> ();
451  fwDev2routerB->SetChannel (channel3);
452  fwDev1routerC->SetChannel (channel3);
453 
454  Ptr<SimpleChannel> channel4 = CreateObject<SimpleChannel> ();
455  fwDev2routerC->SetChannel (channel4);
456  rxDev->SetChannel (channel4);
457 
458  // Setup IPv6 addresses and forwarding
459  Ipv6AddressHelper ipv6;
460 
461  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
462  Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutOnLink (net1);
463  iic1.SetForwarding (1, true);
464  iic1.SetDefaultRouteInAllNodes (1);
465 
466  Ipv6InterfaceContainer iic2 = ipv6.AssignWithoutAddress (net2);
467  iic2.SetForwarding (0, true);
468  iic2.SetForwarding (1, true);
469 
470  Ipv6InterfaceContainer iic3 = ipv6.AssignWithoutAddress (net3);
471  iic3.SetForwarding (0, true);
472  iic3.SetForwarding (1, true);
473 
474  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
475  Ipv6InterfaceContainer iic4 = ipv6.AssignWithoutOnLink (net4);
476  iic4.SetForwarding (0, true);
477  iic4.SetDefaultRouteInAllNodes (0);
478 
479  // Create the UDP sockets
480  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
481  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
482  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("2001:2::200:ff:fe00:8"), 1234)), 0, "trivial");
483  rxSocket->SetRecvCallback (MakeCallback (&Ipv6RipngCountToInfinityTest::ReceivePkt, this));
484 
485  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
486  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
487  txSocket->SetAllowBroadcast (true);
488 
489  // ------ Now the tests ------------
490 
491  SendData (txSocket, "2001:2::200:ff:fe00:8");
492  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "RIPng counting to infinity.");
493 
494  Simulator::Destroy ();
495 }
496 
504 {
507 
508 public:
509  virtual void DoRun (void);
515 
520  void ReceivePktProbe (Ptr<Socket> socket);
521 };
522 
524  : TestCase ("RIPng Split Horizon strategy")
525 {
526  m_setStrategy = strategy;
527 }
528 
530 {
531  uint32_t availableData;
532  availableData = socket->GetRxAvailable ();
533  Address srcAddr;
534  Ptr<Packet> receivedPacketProbe = socket->RecvFrom (std::numeric_limits<uint32_t>::max (), 0, srcAddr);
535  NS_TEST_ASSERT_MSG_EQ (availableData, receivedPacketProbe->GetSize (), "ReceivedPacketProbe size is not equal to the Rx buffer size");
536  Ipv6Address senderAddress = Inet6SocketAddress::ConvertFrom (srcAddr).GetIpv6 ();
537 
538  if (senderAddress == "fe80::200:ff:fe00:4")
539  {
540  RipNgHeader hdr;
541  receivedPacketProbe->RemoveHeader (hdr);
542  std::list<RipNgRte> rtes = hdr.GetRteList ();
543 
544  // validate the RTEs before processing
545  for (std::list<RipNgRte>::iterator iter = rtes.begin ();
546  iter != rtes.end (); iter++)
547  {
548  if (iter->GetPrefix () == "2001:1::")
549  {
550  bool correct = false;
551  if (iter->GetRouteMetric () == 16)
552  {
553  correct = true;
554  m_detectedStrategy = RipNg::POISON_REVERSE;
555  }
556  else if (iter->GetRouteMetric () == 2)
557  {
558  correct = true;
559  m_detectedStrategy = RipNg::NO_SPLIT_HORIZON;
560  }
561  NS_TEST_EXPECT_MSG_EQ (correct, true, "RIPng: unexpected metric value: " << iter->GetRouteMetric ());
562  }
563  }
564  }
565 
566  //cast availableData to void, to suppress 'availableData' set but not used
567  //compiler warning
568  (void) availableData;
569 }
570 
571 void
573 {
574  // Create topology
575 
576  Ptr<Node> fakeNode = CreateObject<Node> ();
577  Ptr<Node> listener = CreateObject<Node> ();
578 
579  Ptr<Node> routerA = CreateObject<Node> ();
580  Ptr<Node> routerB = CreateObject<Node> ();
581 
582  NodeContainer listeners (listener, fakeNode);
583  NodeContainer routers (routerA, routerB);
584  NodeContainer all (routers, listeners);
585 
586  RipNgHelper ripNgRouting;
587  ripNgRouting.Set ("SplitHorizon", EnumValue (m_setStrategy));
588 
589  InternetStackHelper internetv6routers;
590  internetv6routers.SetRoutingHelper (ripNgRouting);
591  internetv6routers.Install (routers);
592 
593  InternetStackHelper internetv6nodes;
594  internetv6nodes.Install (listeners);
595 
596  NetDeviceContainer net0;
597  NetDeviceContainer net1;
598 
599  // Fake Node
600  Ptr<SimpleNetDevice> silentDev;
601  {
602  silentDev = CreateObject<SimpleNetDevice> ();
603  silentDev->SetAddress (Mac48Address ("00:00:00:00:00:01"));
604  fakeNode->AddDevice (silentDev);
605  }
606  net0.Add (silentDev);
607 
608  // Router A
609  Ptr<SimpleNetDevice> silentDevRouterA, fwDevRouterA;
610  { // silent interface
611  silentDevRouterA = CreateObject<SimpleNetDevice> ();
612  silentDevRouterA->SetAddress (Mac48Address ("00:00:00:00:00:02"));
613  routerA->AddDevice (silentDevRouterA);
614  }
615  net0.Add (silentDevRouterA);
616 
617  { // first interface
618  fwDevRouterA = CreateObject<SimpleNetDevice> ();
619  fwDevRouterA->SetAddress (Mac48Address ("00:00:00:00:00:03"));
620  routerA->AddDevice (fwDevRouterA);
621  }
622  net1.Add (fwDevRouterA);
623 
624  // Router B
625  Ptr<SimpleNetDevice> fwDevRouterB;
626  { // first interface
627  fwDevRouterB = CreateObject<SimpleNetDevice> ();
628  fwDevRouterB->SetAddress (Mac48Address ("00:00:00:00:00:04"));
629  routerB->AddDevice (fwDevRouterB);
630  }
631  net1.Add (fwDevRouterB);
632 
633  // listener A
634  Ptr<SimpleNetDevice> listenerDev;
635  {
636  listenerDev = CreateObject<SimpleNetDevice> ();
637  listenerDev->SetAddress (Mac48Address ("00:00:00:00:00:05"));
638  listener->AddDevice (listenerDev);
639  }
640  net1.Add (listenerDev);
641 
642  // link the channels
643  Ptr<SimpleChannel> channel0 = CreateObject<SimpleChannel> ();
644  silentDev->SetChannel (channel0);
645  silentDevRouterA->SetChannel (channel0);
646 
647  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
648  fwDevRouterA->SetChannel (channel1);
649  fwDevRouterB->SetChannel (channel1);
650  listenerDev->SetChannel (channel1);
651 
652  // Setup IPv6 addresses and forwarding
653  Ipv6AddressHelper ipv6;
654 
655  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
656  Ipv6InterfaceContainer iic0 = ipv6.AssignWithoutOnLink (net0);
657 
658  Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutAddress (net1);
659  iic1.SetForwarding (0, true);
660  iic1.SetForwarding (1, true);
661 
662  // Create the UDP sockets
663  Ptr<SocketFactory> rxSocketFactory = listener->GetObject<UdpSocketFactory> ();
664  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
665  rxSocket->BindToNetDevice (listenerDev);
666  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("ff02::9"), 521)), 0, "trivial");
667  rxSocket->SetRecvCallback (MakeCallback (&Ipv6RipngSplitHorizonStrategyTest::ReceivePktProbe, this));
668 
669  // ------ Now the tests ------------
670 
671  // If the strategy is Split Horizon, then no packet will be received.
672  m_detectedStrategy = RipNg::SPLIT_HORIZON;
673 
674  Simulator::Stop (Seconds (66));
675  Simulator::Run ();
676  NS_TEST_EXPECT_MSG_EQ (m_detectedStrategy, m_setStrategy, "RIPng counting to infinity.");
677 
678  Simulator::Destroy ();
679 }
680 
688 {
689 public:
690  Ipv6RipngTestSuite () : TestSuite ("ipv6-ripng", UNIT)
691  {
692  AddTestCase (new Ipv6RipngTest, TestCase::QUICK);
693  AddTestCase (new Ipv6RipngCountToInfinityTest, TestCase::QUICK);
694  AddTestCase (new Ipv6RipngSplitHorizonStrategyTest (RipNg::POISON_REVERSE), TestCase::QUICK);
695  AddTestCase (new Ipv6RipngSplitHorizonStrategyTest (RipNg::SPLIT_HORIZON), TestCase::QUICK);
696  AddTestCase (new Ipv6RipngSplitHorizonStrategyTest (RipNg::NO_SPLIT_HORIZON), TestCase::QUICK);
697  }
698 };
699 
#define max(a, b)
Definition: 80211b.c:43
IPv6 RIPng count to infinity Test.
void SendData(Ptr< Socket > socket, std::string to)
Send data.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
Ptr< Packet > m_receivedPacket
Received packet.
virtual void DoRun(void)
Implementation to actually run this TestCase.
IPv6 RIPng SplitHorizon strategy Test.
Ipv6RipngSplitHorizonStrategyTest(RipNg::SplitHorizonType_e strategy)
Constructor.
RipNg::SplitHorizonType_e m_setStrategy
Strategy set.
RipNg::SplitHorizonType_e m_detectedStrategy
Strategy detected.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void ReceivePktProbe(Ptr< Socket > socket)
Receive data.
IPv6 RIPng Test.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ptr< Packet > m_receivedPacket
Received packet.
void SendData(Ptr< Socket > socket, std::string to)
Send data.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
IPv6 RIPng TestSuite.
a polymophic address class
Definition: address.h:91
Hold variables of type enum.
Definition: enum.h:55
An Inet6 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)
Helper class to auto-assign global IPv6 unicast addresses.
Ipv6InterfaceContainer AssignWithoutAddress(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer but do not assign any IPv6 addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer AssignWithoutOnLink(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses, but do not set the on-link property ...
Describes an IPv6 address.
Definition: ipv6-address.h:50
Keep track of a set of IPv6 interfaces.
void SetForwarding(uint32_t i, bool state)
Set the state of the stack (act as a router or as an host) for the specified index.
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
an EUI-48 address
Definition: mac48-address.h:44
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 GetId(void) const
Definition: node.cc:109
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
Definition: packet.cc:371
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
RipNgHeader - see RFC 2080
Definition: ripng-header.h:147
std::list< RipNgRte > GetRteList(void) const
Get the list of the RTEs included in the message.
Helper class that adds RIPng routing to nodes.
Definition: ripng-helper.h:41
void SetInterfaceMetric(Ptr< Node > node, uint32_t interface, uint8_t metric)
Set a metric for an interface.
void Set(std::string name, const AttributeValue &value)
Definition: ripng-helper.cc:81
SplitHorizonType_e
Split Horizon strategy type.
Definition: ripng.h:207
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
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:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
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:141
#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:240
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
static Ipv6RipngTestSuite g_ipv6ripngTestSuite
Static variable for test initialization.
nodes
Definition: first.py:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648