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