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/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/inet6-socket-address.h"
35 
36 #include "ns3/internet-stack-helper.h"
37 #include "ns3/ipv6-address-helper.h"
38 #include "ns3/ipv6-l3-protocol.h"
39 #include "ns3/icmpv6-l4-protocol.h"
40 #include "ns3/udp-l4-protocol.h"
41 #include "ns3/ripng.h"
42 #include "ns3/ripng-helper.h"
43 #include "ns3/node-container.h"
44 
45 #include <string>
46 #include <limits>
47 
48 using namespace ns3;
49 
50 // Ipv6RipngTest
51 
52 class Ipv6RipngTest : public TestCase
53 {
55  void DoSendData (Ptr<Socket> socket, std::string to);
56  void SendData (Ptr<Socket> socket, std::string to);
57 
58 public:
59  virtual void DoRun (void);
60  Ipv6RipngTest ();
61 
62  void ReceivePkt (Ptr<Socket> socket);
63 };
64 
66  : TestCase ("RIPng")
67 {
68 }
69 
71 {
72  uint32_t availableData;
73  availableData = socket->GetRxAvailable ();
75  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
76  //cast availableData to void, to suppress 'availableData' set but not used
77  //compiler warning
78  (void) availableData;
79 }
80 
81 void
82 Ipv6RipngTest::DoSendData (Ptr<Socket> socket, std::string to)
83 {
84  Address realTo = Inet6SocketAddress (Ipv6Address (to.c_str ()), 1234);
85  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
86  123, "100");
87 }
88 
89 void
90 Ipv6RipngTest::SendData (Ptr<Socket> socket, std::string to)
91 {
92  m_receivedPacket = Create<Packet> ();
93  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (60),
94  &Ipv6RipngTest::DoSendData, this, socket, to);
95  Simulator::Stop (Seconds (66));
96  Simulator::Run ();
97 }
98 
99 void
101 {
102  // Create topology
103 
104  Ptr<Node> txNode = CreateObject<Node> ();
105  Ptr<Node> rxNode = CreateObject<Node> ();
106  Ptr<Node> routerA = CreateObject<Node> ();
107  Ptr<Node> routerB = CreateObject<Node> ();
108  Ptr<Node> routerC = CreateObject<Node> ();
109 
110  NodeContainer nodes (txNode, rxNode);
111  NodeContainer routers (routerA, routerB, routerC);
112  NodeContainer all (nodes, routers);
113 
114  RipNgHelper ripNgRouting;
115  InternetStackHelper internetv6routers;
116  internetv6routers.SetRoutingHelper (ripNgRouting);
117  internetv6routers.Install (routers);
118 
119  InternetStackHelper internetv6nodes;
120  internetv6nodes.Install (nodes);
121 
122  NetDeviceContainer net1;
123  NetDeviceContainer net2;
124  NetDeviceContainer net3;
125  NetDeviceContainer net4;
126 
127  // Sender Node
128  Ptr<SimpleNetDevice> txDev;
129  {
130  txDev = CreateObject<SimpleNetDevice> ();
131  txDev->SetAddress (Mac48Address ("00:00:00:00:00:01"));
132  txNode->AddDevice (txDev);
133  }
134  net1.Add (txDev);
135 
136  // Router A
137  Ptr<SimpleNetDevice> fwDev1routerA, fwDev2routerA;
138  { // first interface
139  fwDev1routerA = CreateObject<SimpleNetDevice> ();
140  fwDev1routerA->SetAddress (Mac48Address ("00:00:00:00:00:02"));
141  routerA->AddDevice (fwDev1routerA);
142  }
143  net1.Add (fwDev1routerA);
144 
145  { // second interface
146  fwDev2routerA = CreateObject<SimpleNetDevice> ();
147  fwDev2routerA->SetAddress (Mac48Address ("00:00:00:00:00:03"));
148  routerA->AddDevice (fwDev2routerA);
149  }
150  net2.Add (fwDev2routerA);
151 
152  // Router B
153  Ptr<SimpleNetDevice> fwDev1routerB, fwDev2routerB;
154  { // first interface
155  fwDev1routerB = CreateObject<SimpleNetDevice> ();
156  fwDev1routerB->SetAddress (Mac48Address ("00:00:00:00:00:04"));
157  routerB->AddDevice (fwDev1routerB);
158  }
159  net2.Add (fwDev1routerB);
160 
161  { // second interface
162  fwDev2routerB = CreateObject<SimpleNetDevice> ();
163  fwDev2routerB->SetAddress (Mac48Address ("00:00:00:00:00:05"));
164  routerB->AddDevice (fwDev2routerB);
165  }
166  net3.Add (fwDev2routerB);
167 
168  // Router C
169  Ptr<SimpleNetDevice> fwDev1routerC, fwDev2routerC;
170  { // first interface
171  fwDev1routerC = CreateObject<SimpleNetDevice> ();
172  fwDev1routerC->SetAddress (Mac48Address ("00:00:00:00:00:06"));
173  routerC->AddDevice (fwDev1routerC);
174  }
175  net3.Add (fwDev1routerC);
176 
177  { // second interface
178  fwDev2routerC = CreateObject<SimpleNetDevice> ();
179  fwDev2routerC->SetAddress (Mac48Address ("00:00:00:00:00:07"));
180  routerC->AddDevice (fwDev2routerC);
181  }
182  net4.Add (fwDev2routerC);
183 
184  // Rx node
185  Ptr<SimpleNetDevice> rxDev;
186  { // first interface
187  rxDev = CreateObject<SimpleNetDevice> ();
188  rxDev->SetAddress (Mac48Address ("00:00:00:00:00:08"));
189  rxNode->AddDevice (rxDev);
190  }
191  net4.Add (rxDev);
192 
193  // link the channels
194  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
195  txDev->SetChannel (channel1);
196  fwDev1routerA->SetChannel (channel1);
197 
198  Ptr<SimpleChannel> channel2 = CreateObject<SimpleChannel> ();
199  fwDev2routerA->SetChannel (channel2);
200  fwDev1routerB->SetChannel (channel2);
201 
202  Ptr<SimpleChannel> channel3 = CreateObject<SimpleChannel> ();
203  fwDev2routerB->SetChannel (channel3);
204  fwDev1routerC->SetChannel (channel3);
205 
206  Ptr<SimpleChannel> channel4 = CreateObject<SimpleChannel> ();
207  fwDev2routerC->SetChannel (channel4);
208  rxDev->SetChannel (channel4);
209 
210  // Setup IPv6 addresses and forwarding
211  Ipv6AddressHelper ipv6;
212 
213  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
214  Ipv6InterfaceContainer iic1 = ipv6.Assign (net1);
215  iic1.SetForwarding (1, true);
216  iic1.SetDefaultRouteInAllNodes (1);
217 
218  Ipv6InterfaceContainer iic2 = ipv6.AssignWithoutAddress (net2);
219  iic2.SetForwarding (0, true);
220  iic2.SetForwarding (1, true);
221 
222  Ipv6InterfaceContainer iic3 = ipv6.AssignWithoutAddress (net3);
223  iic3.SetForwarding (0, true);
224  iic3.SetForwarding (1, true);
225 
226  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
227  Ipv6InterfaceContainer iic4 = ipv6.Assign (net4);
228  iic4.SetForwarding (0, true);
229  iic4.SetDefaultRouteInAllNodes (0);
230 
231  // Create the UDP sockets
232  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
233  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
234  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("2001:2::200:ff:fe00:8"), 1234)), 0, "trivial");
235  rxSocket->SetRecvCallback (MakeCallback (&Ipv6RipngTest::ReceivePkt, this));
236 
237  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
238  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
239  txSocket->SetAllowBroadcast (true);
240 
241  // ------ Now the tests ------------
242 
243  // Unicast test
244  SendData (txSocket, "2001:2::200:ff:fe00:8");
245  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "IPv6 RIPng should work.");
246 
248 
249  Simulator::Destroy ();
250 }
251 
252 // Ipv6RipngCountToInfinityTest
253 
255 {
257  void DoSendData (Ptr<Socket> socket, std::string to);
258  void SendData (Ptr<Socket> socket, std::string to);
259 
260 public:
261  virtual void DoRun (void);
263 
264  void ReceivePkt (Ptr<Socket> socket);
265 };
266 
268  : TestCase ("RIPng counting to infinity")
269 {
270 }
271 
273 {
274  uint32_t availableData;
275  availableData = socket->GetRxAvailable ();
277  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
278  //cast availableData to void, to suppress 'availableData' set but not used
279  //compiler warning
280  (void) availableData;
281 }
282 
283 void
285 {
286  Address realTo = Inet6SocketAddress (Ipv6Address (to.c_str ()), 1234);
287  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
288  123, "100");
289 }
290 
291 void
293 {
294  m_receivedPacket = Create<Packet> ();
295  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (60),
296  &Ipv6RipngCountToInfinityTest::DoSendData, this, socket, to);
297  Simulator::Stop (Seconds (66));
298  Simulator::Run ();
299 }
300 
301 void
303 {
304  // Create topology
305 
306  Ptr<Node> txNode = CreateObject<Node> ();
307  Ptr<Node> rxNode = CreateObject<Node> ();
308  Ptr<Node> routerA = CreateObject<Node> ();
309  Ptr<Node> routerB = CreateObject<Node> ();
310  Ptr<Node> routerC = CreateObject<Node> ();
311 
312  NodeContainer nodes (txNode, rxNode);
313  NodeContainer routers (routerA, routerB, routerC);
314  NodeContainer all (nodes, routers);
315 
316  RipNgHelper ripNgRouting;
317  // Change the router's interface metric to 10, must not send packets (count to infinity)
318  // note: Interface 0 is the loopback.
319  ripNgRouting.SetInterfaceMetric (routerA, 2, 10);
320  ripNgRouting.SetInterfaceMetric (routerB, 1, 10);
321  ripNgRouting.SetInterfaceMetric (routerB, 2, 10);
322  ripNgRouting.SetInterfaceMetric (routerC, 1, 10);
323 
324  InternetStackHelper internetv6routers;
325  internetv6routers.SetRoutingHelper (ripNgRouting);
326  internetv6routers.Install (routers);
327 
328  InternetStackHelper internetv6nodes;
329  internetv6nodes.Install (nodes);
330 
331  NetDeviceContainer net1;
332  NetDeviceContainer net2;
333  NetDeviceContainer net3;
334  NetDeviceContainer net4;
335 
336  // Sender Node
337  Ptr<SimpleNetDevice> txDev;
338  {
339  txDev = CreateObject<SimpleNetDevice> ();
340  txDev->SetAddress (Mac48Address ("00:00:00:00:00:01"));
341  txNode->AddDevice (txDev);
342  }
343  net1.Add (txDev);
344 
345  // Router A
346  Ptr<SimpleNetDevice> fwDev1routerA, fwDev2routerA;
347  { // first interface
348  fwDev1routerA = CreateObject<SimpleNetDevice> ();
349  fwDev1routerA->SetAddress (Mac48Address ("00:00:00:00:00:02"));
350  routerA->AddDevice (fwDev1routerA);
351  }
352  net1.Add (fwDev1routerA);
353 
354  { // second interface
355  fwDev2routerA = CreateObject<SimpleNetDevice> ();
356  fwDev2routerA->SetAddress (Mac48Address ("00:00:00:00:00:03"));
357  routerA->AddDevice (fwDev2routerA);
358  }
359  net2.Add (fwDev2routerA);
360 
361  // Router B
362  Ptr<SimpleNetDevice> fwDev1routerB, fwDev2routerB;
363  { // first interface
364  fwDev1routerB = CreateObject<SimpleNetDevice> ();
365  fwDev1routerB->SetAddress (Mac48Address ("00:00:00:00:00:04"));
366  routerB->AddDevice (fwDev1routerB);
367  }
368  net2.Add (fwDev1routerB);
369 
370  { // second interface
371  fwDev2routerB = CreateObject<SimpleNetDevice> ();
372  fwDev2routerB->SetAddress (Mac48Address ("00:00:00:00:00:05"));
373  routerB->AddDevice (fwDev2routerB);
374  }
375  net3.Add (fwDev2routerB);
376 
377  // Router C
378  Ptr<SimpleNetDevice> fwDev1routerC, fwDev2routerC;
379  { // first interface
380  fwDev1routerC = CreateObject<SimpleNetDevice> ();
381  fwDev1routerC->SetAddress (Mac48Address ("00:00:00:00:00:06"));
382  routerC->AddDevice (fwDev1routerC);
383  }
384  net3.Add (fwDev1routerC);
385 
386  { // second interface
387  fwDev2routerC = CreateObject<SimpleNetDevice> ();
388  fwDev2routerC->SetAddress (Mac48Address ("00:00:00:00:00:07"));
389  routerC->AddDevice (fwDev2routerC);
390  }
391  net4.Add (fwDev2routerC);
392 
393  // Rx node
394  Ptr<SimpleNetDevice> rxDev;
395  { // first interface
396  rxDev = CreateObject<SimpleNetDevice> ();
397  rxDev->SetAddress (Mac48Address ("00:00:00:00:00:08"));
398  rxNode->AddDevice (rxDev);
399  }
400  net4.Add (rxDev);
401 
402  // link the channels
403  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
404  txDev->SetChannel (channel1);
405  fwDev1routerA->SetChannel (channel1);
406 
407  Ptr<SimpleChannel> channel2 = CreateObject<SimpleChannel> ();
408  fwDev2routerA->SetChannel (channel2);
409  fwDev1routerB->SetChannel (channel2);
410 
411  Ptr<SimpleChannel> channel3 = CreateObject<SimpleChannel> ();
412  fwDev2routerB->SetChannel (channel3);
413  fwDev1routerC->SetChannel (channel3);
414 
415  Ptr<SimpleChannel> channel4 = CreateObject<SimpleChannel> ();
416  fwDev2routerC->SetChannel (channel4);
417  rxDev->SetChannel (channel4);
418 
419  // Setup IPv6 addresses and forwarding
420  Ipv6AddressHelper ipv6;
421 
422  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
423  Ipv6InterfaceContainer iic1 = ipv6.Assign (net1);
424  iic1.SetForwarding (1, true);
425  iic1.SetDefaultRouteInAllNodes (1);
426 
427  Ipv6InterfaceContainer iic2 = ipv6.AssignWithoutAddress (net2);
428  iic2.SetForwarding (0, true);
429  iic2.SetForwarding (1, true);
430 
431  Ipv6InterfaceContainer iic3 = ipv6.AssignWithoutAddress (net3);
432  iic3.SetForwarding (0, true);
433  iic3.SetForwarding (1, true);
434 
435  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
436  Ipv6InterfaceContainer iic4 = ipv6.Assign (net4);
437  iic4.SetForwarding (0, true);
438  iic4.SetDefaultRouteInAllNodes (0);
439 
440  // Create the UDP sockets
441  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
442  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
443  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("2001:2::200:ff:fe00:8"), 1234)), 0, "trivial");
444  rxSocket->SetRecvCallback (MakeCallback (&Ipv6RipngCountToInfinityTest::ReceivePkt, this));
445 
446  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
447  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
448  txSocket->SetAllowBroadcast (true);
449 
450  // ------ Now the tests ------------
451 
452  SendData (txSocket, "2001:2::200:ff:fe00:8");
453  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "RIPng counting to infinity.");
454 
455  Simulator::Destroy ();
456 }
457 
458 // Ipv6RipngSplitHorizonStrategyTest
459 
461 {
464 
465 public:
466  virtual void DoRun (void);
468 
469  void ReceivePktProbe (Ptr<Socket> socket);
470 };
471 
473  : TestCase ("RIPng Split Horizon strategy")
474 {
475  m_setStrategy = strategy;
476 }
477 
479 {
480  uint32_t availableData;
481  availableData = socket->GetRxAvailable ();
482  Address srcAddr;
483  Ptr<Packet> receivedPacketProbe = socket->RecvFrom (std::numeric_limits<uint32_t>::max (), 0, srcAddr);
484  NS_ASSERT (availableData == receivedPacketProbe->GetSize ());
485  Ipv6Address senderAddress = Inet6SocketAddress::ConvertFrom (srcAddr).GetIpv6 ();
486 
487  if (senderAddress == "fe80::200:ff:fe00:4")
488  {
489  RipNgHeader hdr;
490  receivedPacketProbe->RemoveHeader (hdr);
491  std::list<RipNgRte> rtes = hdr.GetRteList ();
492 
493  // validate the RTEs before processing
494  for (std::list<RipNgRte>::iterator iter = rtes.begin ();
495  iter != rtes.end (); iter++)
496  {
497  if (iter->GetPrefix () == "2001:1::")
498  {
499  bool correct = false;
500  if (iter->GetRouteMetric () == 16)
501  {
502  correct = true;
503  m_detectedStrategy = RipNg::POISON_REVERSE;
504  }
505  else if (iter->GetRouteMetric () == 2)
506  {
507  correct = true;
508  m_detectedStrategy = RipNg::NO_SPLIT_HORIZON;
509  }
510  NS_TEST_EXPECT_MSG_EQ (correct, true, "RIPng: unexpected metric value: " << iter->GetRouteMetric ());
511  }
512  }
513  }
514 
515  //cast availableData to void, to suppress 'availableData' set but not used
516  //compiler warning
517  (void) availableData;
518 }
519 
520 void
522 {
523  // Create topology
524 
525  Ptr<Node> fakeNode = CreateObject<Node> ();
526  Ptr<Node> listener = CreateObject<Node> ();
527 
528  Ptr<Node> routerA = CreateObject<Node> ();
529  Ptr<Node> routerB = CreateObject<Node> ();
530 
531  NodeContainer listeners (listener, fakeNode);
532  NodeContainer routers (routerA, routerB);
533  NodeContainer all (routers, listeners);
534 
535  RipNgHelper ripNgRouting;
536  ripNgRouting.Set ("SplitHorizon", EnumValue (m_setStrategy));
537 
538  InternetStackHelper internetv6routers;
539  internetv6routers.SetRoutingHelper (ripNgRouting);
540  internetv6routers.Install (routers);
541 
542  InternetStackHelper internetv6nodes;
543  internetv6nodes.Install (listeners);
544 
545  NetDeviceContainer net0;
546  NetDeviceContainer net1;
547 
548  // Fake Node
549  Ptr<SimpleNetDevice> silentDev;
550  {
551  silentDev = CreateObject<SimpleNetDevice> ();
552  silentDev->SetAddress (Mac48Address ("00:00:00:00:00:01"));
553  fakeNode->AddDevice (silentDev);
554  }
555  net0.Add (silentDev);
556 
557  // Router A
558  Ptr<SimpleNetDevice> silentDevRouterA, fwDevRouterA;
559  { // silent interface
560  silentDevRouterA = CreateObject<SimpleNetDevice> ();
561  silentDevRouterA->SetAddress (Mac48Address ("00:00:00:00:00:02"));
562  routerA->AddDevice (silentDevRouterA);
563  }
564  net0.Add (silentDevRouterA);
565 
566  { // first interface
567  fwDevRouterA = CreateObject<SimpleNetDevice> ();
568  fwDevRouterA->SetAddress (Mac48Address ("00:00:00:00:00:03"));
569  routerA->AddDevice (fwDevRouterA);
570  }
571  net1.Add (fwDevRouterA);
572 
573  // Router B
574  Ptr<SimpleNetDevice> fwDevRouterB;
575  { // first interface
576  fwDevRouterB = CreateObject<SimpleNetDevice> ();
577  fwDevRouterB->SetAddress (Mac48Address ("00:00:00:00:00:04"));
578  routerB->AddDevice (fwDevRouterB);
579  }
580  net1.Add (fwDevRouterB);
581 
582  // listener A
583  Ptr<SimpleNetDevice> listenerDev;
584  {
585  listenerDev = CreateObject<SimpleNetDevice> ();
586  listenerDev->SetAddress (Mac48Address ("00:00:00:00:00:05"));
587  listener->AddDevice (listenerDev);
588  }
589  net1.Add (listenerDev);
590 
591  // link the channels
592  Ptr<SimpleChannel> channel0 = CreateObject<SimpleChannel> ();
593  silentDev->SetChannel (channel0);
594  silentDevRouterA->SetChannel (channel0);
595 
596  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
597  fwDevRouterA->SetChannel (channel1);
598  fwDevRouterB->SetChannel (channel1);
599  listenerDev->SetChannel (channel1);
600 
601  // Setup IPv6 addresses and forwarding
602  Ipv6AddressHelper ipv6;
603 
604  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
605  Ipv6InterfaceContainer iic0 = ipv6.Assign (net0);
606 
607  Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutAddress (net1);
608  iic1.SetForwarding (0, true);
609  iic1.SetForwarding (1, true);
610 
611  // Create the UDP sockets
612  Ptr<SocketFactory> rxSocketFactory = listener->GetObject<UdpSocketFactory> ();
613  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
614  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("ff02::9"), 521)), 0, "trivial");
615  rxSocket->BindToNetDevice (listenerDev);
616  rxSocket->SetRecvCallback (MakeCallback (&Ipv6RipngSplitHorizonStrategyTest::ReceivePktProbe, this));
617 
618  // ------ Now the tests ------------
619 
620  // If the strategy is Split Horizon, then no packet will be received.
621  m_detectedStrategy = RipNg::SPLIT_HORIZON;
622 
623  Simulator::Stop (Seconds (66));
624  Simulator::Run ();
625  NS_TEST_EXPECT_MSG_EQ (m_detectedStrategy, m_setStrategy, "RIPng counting to infinity.");
626 
627  Simulator::Destroy ();
628 }
629 
630 //-----------------------------------------------------------------------------
631 //-----------------------------------------------------------------------------
633 {
634 public:
635  Ipv6RipngTestSuite () : TestSuite ("ipv6-ripng", UNIT)
636  {
637  AddTestCase (new Ipv6RipngTest, TestCase::QUICK);
638  AddTestCase (new Ipv6RipngCountToInfinityTest, TestCase::QUICK);
639  AddTestCase (new Ipv6RipngSplitHorizonStrategyTest (RipNg::POISON_REVERSE), TestCase::QUICK);
640  AddTestCase (new Ipv6RipngSplitHorizonStrategyTest (RipNg::SPLIT_HORIZON), TestCase::QUICK);
641  AddTestCase (new Ipv6RipngSplitHorizonStrategyTest (RipNg::NO_SPLIT_HORIZON), TestCase::QUICK);
642  }
Ptr< Packet > m_receivedPacket
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
virtual void DoRun(void)
Implementation to actually run this TestCase.
std::list< RipNgRte > GetRteList(void) const
Get the list of the RTEs included in the message.
Keep track of a set of IPv6 interfaces.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:462
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
A suite of tests to run.
Definition: test.h:1333
#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:792
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Helper class that adds RIPng routing to nodes.
Definition: ripng-helper.h:40
virtual Ptr< Socket > CreateSocket(void)=0
void ReceivePktProbe(Ptr< Socket > socket)
void ReceivePkt(Ptr< Socket > socket)
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
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.
a polymophic address class
Definition: address.h:90
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
tuple nodes
Definition: first.py:25
Hold variables of type enum.
Definition: enum.h:54
#define max(a, b)
Definition: 80211b.c:45
void DoSendData(Ptr< Socket > socket, std::string to)
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ipv6RipngTestSuite g_ipv6ripngTestSuite
void SetInterfaceMetric(Ptr< Node > node, uint32_t interface, uint8_t metric)
Set a metric for an interface.
RipNg::SplitHorizonType_e m_detectedStrategy
SplitHorizonType_e
Split Horizon strategy type.
Definition: ripng.h:207
holds a vector of ns3::NetDevice pointers
An Inet6 address class.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
RipNg::SplitHorizonType_e m_setStrategy
void SendData(Ptr< Socket > socket, std::string to)
RipNgHeader - see RFC 2080
Definition: ripng-header.h:146
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void Set(std::string name, const AttributeValue &value)
Definition: ripng-helper.cc:81
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...
void DoSendData(Ptr< Socket > socket, std::string to)
Ipv6RipngSplitHorizonStrategyTest(RipNg::SplitHorizonType_e strategy)
an EUI-48 address
Definition: mac48-address.h:43
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Helper class to auto-assign global IPv6 unicast addresses.
Describes an IPv6 address.
Definition: ipv6-address.h:48
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.
void SendData(Ptr< Socket > socket, std::string to)
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
Describes an IPv6 prefix.
Definition: ipv6-address.h:394
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
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.
Ipv6InterfaceContainer AssignWithoutAddress(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer but do not assign any IPv6 addresses.
void SetChannel(Ptr< SimpleChannel > channel)
Attach a channel to this net device.
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void ReceivePkt(Ptr< Socket > socket)
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.