A Discrete-Event Network Simulator
API
ipv4-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/ipv4-list-routing.h"
22 #include "ns3/ipv4-routing-protocol.h"
23 
24 using namespace ns3;
25 
33 public:
34  Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0; }
37  LocalDeliverCallback lcb, ErrorCallback ecb) { return false; }
38  void NotifyInterfaceUp (uint32_t interface) {}
39  void NotifyInterfaceDown (uint32_t interface) {}
40  void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
41  void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
42  void SetIpv4 (Ptr<Ipv4> ipv4) {}
44 };
45 
53 public:
54  Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0; }
57  LocalDeliverCallback lcb, ErrorCallback ecb) { return false; }
58  void NotifyInterfaceUp (uint32_t interface) {}
59  void NotifyInterfaceDown (uint32_t interface) {}
60  void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
61  void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
62  void SetIpv4 (Ptr<Ipv4> ipv4) {}
64 };
65 
73 {
74 public:
76  virtual void DoRun (void);
77 };
78 
80  : TestCase ("Check negative priorities")
81 {
82 }
83 void
85 {
86  Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting> ();
87  Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting> ();
88  Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting> ();
89  // The Ipv4BRouting should be added with higher priority (larger integer value)
90  lr->AddRoutingProtocol (aRouting, -10);
91  lr->AddRoutingProtocol (bRouting, -5);
92  int16_t first = 3;
93  uint32_t num = lr->GetNRoutingProtocols ();
94  NS_TEST_ASSERT_MSG_EQ (num, 2, "100");
95  Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
96  NS_TEST_ASSERT_MSG_EQ (-5, first, "101");
97  NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "102");
98 }
99 
107 {
108 public:
110  virtual void DoRun (void);
111 };
112 
114  : TestCase ("Check positive priorities")
115 {
116 }
117 void
119 {
120  Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting> ();
121  Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting> ();
122  Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting> ();
123  // The Ipv4ARouting should be added with higher priority (larger integer
124  // value) and will be fetched first below
125  lr->AddRoutingProtocol (aRouting, 10);
126  lr->AddRoutingProtocol (bRouting, 5);
127  int16_t first = 3;
128  int16_t second = 3;
129  uint32_t num = lr->GetNRoutingProtocols ();
130  NS_TEST_ASSERT_MSG_EQ (num, 2, "200");
131  Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
132  NS_TEST_ASSERT_MSG_EQ (10, first, "201");
133  NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "202");
134  Ptr<Ipv4RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
135  NS_TEST_ASSERT_MSG_EQ (5, second, "203");
136  NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "204");
137 }
138 
146 {
147 public:
149  : TestSuite ("ipv4-list-routing", UNIT)
150  {
151  AddTestCase (new Ipv4ListRoutingPositiveTestCase (), TestCase::QUICK);
152  AddTestCase (new Ipv4ListRoutingNegativeTestCase (), TestCase::QUICK);
153  }
154 };
155 
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
IPv4 dummy routing class (A)
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
IPv4 dummy routing class (B)
Callback template class.
Definition: callback.h:1176
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(uint32_t index, int16_t &priority) const
Return pointer to routing protocol stored at index, with the first protocol (index 0) the highest pri...
Definition: second.py:1
IPv4 ListRouting TestSuite.
A suite of tests to run.
Definition: test.h:1342
virtual void AddRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol, int16_t priority)
Register a new routing protocol to be used in this IPv4 stack.
void SetIpv4(Ptr< Ipv4 > ipv4)
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const
Print the Routing Table entries.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const
Print the Routing Table entries.
encapsulates test code
Definition: test.h:1155
This test suite implements a Unit Test.
Definition: test.h:1352
IPv4 ListRouting negative test.
Packet header for IPv4.
Definition: ipv4-header.h:33
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
IPv4 ListRouting positive test.
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
#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
void NotifyInterfaceDown(uint32_t interface)
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual uint32_t GetNRoutingProtocols(void) const
void NotifyInterfaceUp(uint32_t interface)
void NotifyInterfaceDown(uint32_t interface)
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SetIpv4(Ptr< Ipv4 > ipv4)
a class to store IPv4 address information on an interface
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &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.
Abstract base class for IPv4 routing protocols.
void NotifyInterfaceUp(uint32_t interface)
static Ipv4ListRoutingTestSuite g_ipv4ListRoutingTestSuite
Static variable for test initialization.
tuple address
Definition: first.py:37
Definition: first.py:1
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)