A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv6-list-routing-test-suite.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
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  */
19 
20 #include "ns3/test.h"
21 #include "ns3/ipv6-list-routing.h"
22 #include "ns3/ipv6-route.h"
23 #include "ns3/ipv6-routing-protocol.h"
24 
25 using namespace ns3;
26 
28 public:
29  Ptr<Ipv6Route> RouteOutput (Ptr<Packet> p, const Ipv6Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0; }
32  LocalDeliverCallback lcb, ErrorCallback ecb) { return false; }
33  void NotifyInterfaceUp (uint32_t interface) {}
34  void NotifyInterfaceDown (uint32_t interface) {}
35  void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
36  void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
37  void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::
38  GetZero ()) {}
39  void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
40  void SetIpv6 (Ptr<Ipv6> ipv6) {}
41  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const {};
42 };
43 
45 public:
46  Ptr<Ipv6Route> RouteOutput (Ptr<Packet> p, const Ipv6Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0; }
49  LocalDeliverCallback lcb, ErrorCallback ecb) { return false; }
50  void NotifyInterfaceUp (uint32_t interface) {}
51  void NotifyInterfaceDown (uint32_t interface) {}
52  void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
53  void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
54  void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::
55  GetZero ()) {}
56  void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
57  void SetIpv6 (Ptr<Ipv6> ipv6) {}
58  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const {};
59 };
60 
62 {
63 public:
65  virtual void DoRun (void);
66 };
67 
68 Ipv6ListRoutingNegativeTestCase::Ipv6ListRoutingNegativeTestCase()
69  : TestCase ("Check negative priorities")
70 {
71 }
72 void
74 {
75  Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting> ();
76  Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting> ();
77  Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting> ();
78  // The Ipv6BRouting should be added with higher priority (larger integer value)
79  lr->AddRoutingProtocol (aRouting, -10);
80  lr->AddRoutingProtocol (bRouting, -5);
81  int16_t first = 3;
82  uint32_t num = lr->GetNRoutingProtocols ();
83  NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
84  Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
85  NS_TEST_ASSERT_MSG_EQ (-5, first, "XXX");
86  NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "XXX");
87 }
88 
90 {
91 public:
93  virtual void DoRun (void);
94 };
95 
96 Ipv6ListRoutingPositiveTestCase::Ipv6ListRoutingPositiveTestCase()
97  : TestCase ("Check positive priorities")
98 {
99 }
100 void
102 {
103  Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting> ();
104  Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting> ();
105  Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting> ();
106  // The Ipv6ARouting should be added with higher priority (larger integer
107  // value) and will be fetched first below
108  lr->AddRoutingProtocol (aRouting, 10);
109  lr->AddRoutingProtocol (bRouting, 5);
110  int16_t first = 3;
111  int16_t second = 3;
112  uint32_t num = lr->GetNRoutingProtocols ();
113  NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
114  Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
115  NS_TEST_ASSERT_MSG_EQ (10, first, "XXX");
116  NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "XXX");
117  Ptr<Ipv6RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
118  NS_TEST_ASSERT_MSG_EQ (5, second, "XXX");
119  NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "XXX");
120 }
121 
122 static class Ipv6ListRoutingTestSuite : public TestSuite
123 {
124 public:
126  : TestSuite ("ipv6-list-routing", UNIT)
127  {
128  AddTestCase (new Ipv6ListRoutingPositiveTestCase (), TestCase::QUICK);
129  AddTestCase (new Ipv6ListRoutingNegativeTestCase (), TestCase::QUICK);
130  }
131 
132 } g_ipv6ListRoutingTestSuite;
Packet header for IPv6.
Definition: ipv6-header.h:33
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
virtual uint32_t GetNRoutingProtocols(void) const
Get the number of routing protocols.
Callback template class.
Definition: callback.h:369
A suite of tests to run.
Definition: test.h:962
void SetIpv6(Ptr< Ipv6 > ipv6)
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
IPv6 address associated with an interface.
Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
encapsulates test code
Definition: test.h:834
void NotifyInterfaceUp(uint32_t interface)
Notify when specified interface goes UP.
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Definition: test.cc:354
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify a new route.
void NotifyInterfaceUp(uint32_t interface)
Notify when specified interface goes UP.
virtual void AddRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol, int16_t priority)
Register a new routing protocol to be used in this IPv4 stack.
void NotifyInterfaceDown(uint32_t interface)
Notify when specified interface goes DOWN.
virtual void DoRun(void)
Implementation to actually run this test case.
void NotifyInterfaceDown(uint32_t interface)
Notify when specified interface goes DOWN.
void SetIpv6(Ptr< Ipv6 > ipv6)
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify a new route.
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
virtual void DoRun(void)
Implementation to actually run this test case.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
Notify route removing.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
Describes an IPv6 address.
Definition: ipv6-address.h:44
Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
Definition: ipv6-address.h:326
Abstract base class for Ipv6 routing protocols.
virtual Ptr< Ipv6RoutingProtocol > GetRoutingProtocol(uint32_t index, int16_t &priority) const
Get pointer to routing protocol stored at index,.
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
Notify route removing.