A Discrete-Event Network Simulator
API
ipv6-list-routing-test-suite.cc
Go to the documentation of this file.
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 
34 public:
35  Ptr<Ipv6Route> RouteOutput (Ptr<Packet> p, const Ipv6Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0; }
38  LocalDeliverCallback lcb, ErrorCallback ecb) { return false; }
39  void NotifyInterfaceUp (uint32_t interface) {}
40  void NotifyInterfaceDown (uint32_t interface) {}
41  void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
42  void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
43  void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::
44  GetZero ()) {}
45  void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
46  void SetIpv6 (Ptr<Ipv6> ipv6) {}
47  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream, Time::Unit unit) const {};
48 };
49 
57 public:
58  Ptr<Ipv6Route> RouteOutput (Ptr<Packet> p, const Ipv6Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0; }
61  LocalDeliverCallback lcb, ErrorCallback ecb) { return false; }
62  void NotifyInterfaceUp (uint32_t interface) {}
63  void NotifyInterfaceDown (uint32_t interface) {}
64  void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
65  void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
66  void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::
67  GetZero ()) {}
68  void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
69  void SetIpv6 (Ptr<Ipv6> ipv6) {}
70  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream, Time::Unit unit) const {};
71 };
72 
80 {
81 public:
83  virtual void DoRun (void);
84 };
85 
87  : TestCase ("Check negative priorities")
88 {
89 }
90 void
92 {
93  Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting> ();
94  Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting> ();
95  Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting> ();
96  // The Ipv6BRouting should be added with higher priority (larger integer value)
97  lr->AddRoutingProtocol (aRouting, -10);
98  lr->AddRoutingProtocol (bRouting, -5);
99  int16_t first = 3;
100  uint32_t num = lr->GetNRoutingProtocols ();
101  NS_TEST_ASSERT_MSG_EQ (num, 2, "100");
102  Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
103  NS_TEST_ASSERT_MSG_EQ (-5, first, "101");
104  NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "102");
105 }
106 
114 {
115 public:
117  virtual void DoRun (void);
118 };
119 
121  : TestCase ("Check positive priorities")
122 {
123 }
124 void
126 {
127  Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting> ();
128  Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting> ();
129  Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting> ();
130  // The Ipv6ARouting should be added with higher priority (larger integer
131  // value) and will be fetched first below
132  lr->AddRoutingProtocol (aRouting, 10);
133  lr->AddRoutingProtocol (bRouting, 5);
134  int16_t first = 3;
135  int16_t second = 3;
136  uint32_t num = lr->GetNRoutingProtocols ();
137  NS_TEST_ASSERT_MSG_EQ (num, 2, "200");
138  Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
139  NS_TEST_ASSERT_MSG_EQ (10, first, "201");
140  NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "202");
141  Ptr<Ipv6RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
142  NS_TEST_ASSERT_MSG_EQ (5, second, "203");
143  NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "204");
144 }
145 
153 {
154 public:
156  : TestSuite ("ipv6-list-routing", UNIT)
157  {
158  AddTestCase (new Ipv6ListRoutingPositiveTestCase (), TestCase::QUICK);
159  AddTestCase (new Ipv6ListRoutingNegativeTestCase (), TestCase::QUICK);
160  }
161 
162 };
163 
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
Packet header for IPv6.
Definition: ipv6-header.h:34
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
virtual uint32_t GetNRoutingProtocols(void) const
Get the number of routing protocols.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Callback template class.
Definition: callback.h:1176
Definition: second.py:1
A suite of tests to run.
Definition: test.h:1342
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:1155
This test suite implements a Unit Test.
Definition: test.h:1352
IPv6 ListRouting negative test.
void NotifyInterfaceUp(uint32_t interface)
Notify when specified interface goes UP.
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify a new route.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const
Print the Routing Table entries.
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 TestCase.
void NotifyInterfaceDown(uint32_t interface)
Notify when specified interface goes DOWN.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const
Print the Routing Table entries.
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.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
IPv6 ListRouting positive test.
#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:168
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IPv6 dummy routing class (A)
IPv6 dummy routing class (B)
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 TestCase.
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
Notify route removing.
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:48
Describes an IPv6 prefix.
Definition: ipv6-address.h:394
tuple address
Definition: first.py:37
Definition: first.py:1
Abstract base class for IPv6 routing protocols.
IPv6 ListRouting TestSuite.
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.
static Ipv6ListRoutingTestSuite g_ipv6ListRoutingTestSuite
Static variable for test initialization.
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
Notify route removing.