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");
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");
132  NS_TEST_ASSERT_MSG_EQ (10, first, "201");
133  NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "202");
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 
Ipv4ARouting::RouteInput
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)
Definition: ipv4-list-routing-test-suite.cc:35
ns3::Ipv4Header
Packet header for IPv4.
Definition: ipv4-header.h:34
Ipv4ARouting::NotifyInterfaceUp
void NotifyInterfaceUp(uint32_t interface)
Definition: ipv4-list-routing-test-suite.cc:38
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
ns3::Ipv4ListRouting::AddRoutingProtocol
virtual void AddRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol, int16_t priority)
Register a new routing protocol to be used in this IPv4 stack.
Definition: ipv4-list-routing.cc:253
first
Definition: first.py:1
ns3::Socket::SocketErrno
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
ns3::Callback
Callback template class.
Definition: callback.h:1279
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ipv4ARouting::NotifyRemoveAddress
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
Definition: ipv4-list-routing-test-suite.cc:41
Ipv4ListRoutingPositiveTestCase
IPv4 ListRouting positive test.
Definition: ipv4-list-routing-test-suite.cc:107
Ipv4ListRoutingTestSuite
IPv4 ListRouting TestSuite.
Definition: ipv4-list-routing-test-suite.cc:146
Ipv4ListRoutingTestSuite::Ipv4ListRoutingTestSuite
Ipv4ListRoutingTestSuite()
Definition: ipv4-list-routing-test-suite.cc:148
Ipv4ARouting::RouteOutput
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.
Definition: ipv4-list-routing-test-suite.cc:34
Ipv4ARouting::NotifyInterfaceDown
void NotifyInterfaceDown(uint32_t interface)
Definition: ipv4-list-routing-test-suite.cc:39
ns3::TestCase
encapsulates test code
Definition: test.h:1154
Ipv4ARouting::NotifyAddAddress
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
Definition: ipv4-list-routing-test-suite.cc:40
Ipv4BRouting::NotifyInterfaceDown
void NotifyInterfaceDown(uint32_t interface)
Definition: ipv4-list-routing-test-suite.cc:59
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Ipv4ARouting::PrintRoutingTable
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const
Print the Routing Table entries.
Definition: ipv4-list-routing-test-suite.cc:43
Ipv4ListRoutingNegativeTestCase::Ipv4ListRoutingNegativeTestCase
Ipv4ListRoutingNegativeTestCase()
Definition: ipv4-list-routing-test-suite.cc:79
Ipv4BRouting::PrintRoutingTable
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const
Print the Routing Table entries.
Definition: ipv4-list-routing-test-suite.cc:63
Ipv4BRouting::NotifyInterfaceUp
void NotifyInterfaceUp(uint32_t interface)
Definition: ipv4-list-routing-test-suite.cc:58
Ipv4ListRoutingNegativeTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: ipv4-list-routing-test-suite.cc:84
ns3::Ipv4InterfaceAddress
a class to store IPv4 address information on an interface
Definition: ipv4-interface-address.h:44
Ipv4BRouting::NotifyRemoveAddress
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
Definition: ipv4-list-routing-test-suite.cc:61
Ipv4BRouting::NotifyAddAddress
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
Definition: ipv4-list-routing-test-suite.cc:60
first.address
address
Definition: first.py:44
second
Definition: second.py:1
Ipv4ListRoutingNegativeTestCase
IPv4 ListRouting negative test.
Definition: ipv4-list-routing-test-suite.cc:73
ns3::Ipv4RoutingProtocol
Abstract base class for IPv4 routing protocols.
Definition: ipv4-routing-protocol.h:57
Ipv4ListRoutingPositiveTestCase::Ipv4ListRoutingPositiveTestCase
Ipv4ListRoutingPositiveTestCase()
Definition: ipv4-list-routing-test-suite.cc:113
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
NS_TEST_ASSERT_MSG_EQ
#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:166
ns3::TestSuite::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1353
Ipv4BRouting::RouteOutput
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.
Definition: ipv4-list-routing-test-suite.cc:54
Ipv4ARouting::SetIpv4
void SetIpv4(Ptr< Ipv4 > ipv4)
Definition: ipv4-list-routing-test-suite.cc:42
Ipv4BRouting::RouteInput
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)
Definition: ipv4-list-routing-test-suite.cc:55
g_ipv4ListRoutingTestSuite
static Ipv4ListRoutingTestSuite g_ipv4ListRoutingTestSuite
Static variable for test initialization.
Definition: ipv4-list-routing-test-suite.cc:156
Ipv4BRouting::SetIpv4
void SetIpv4(Ptr< Ipv4 > ipv4)
Definition: ipv4-list-routing-test-suite.cc:62
Ipv4ListRoutingPositiveTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: ipv4-list-routing-test-suite.cc:118
ns3::Ipv4ListRouting::GetRoutingProtocol
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: ipv4-list-routing.cc:272
ns3::Time::Unit
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:110
ns3::Ipv4ListRouting::GetNRoutingProtocols
virtual uint32_t GetNRoutingProtocols(void) const
Definition: ipv4-list-routing.cc:265
Ipv4BRouting
IPv4 dummy routing class (B)
Definition: ipv4-list-routing-test-suite.cc:52
Ipv4ARouting
IPv4 dummy routing class (A)
Definition: ipv4-list-routing-test-suite.cc:32