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
24using namespace ns3;
25
33public:
37 LocalDeliverCallback lcb, ErrorCallback ecb) { return false; }
38 void NotifyInterfaceUp (uint32_t interface) {}
39 void NotifyInterfaceDown (uint32_t interface) {}
42 void SetIpv4 (Ptr<Ipv4> ipv4) {}
44};
45
53public:
57 LocalDeliverCallback lcb, ErrorCallback ecb) { return false; }
58 void NotifyInterfaceUp (uint32_t interface) {}
59 void NotifyInterfaceDown (uint32_t interface) {}
62 void SetIpv4 (Ptr<Ipv4> ipv4) {}
64};
65
73{
74public:
76 virtual void DoRun (void);
77};
78
80 : TestCase ("Check negative priorities")
81{
82}
83void
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{
108public:
110 virtual void DoRun (void);
111};
112
114 : TestCase ("Check positive priorities")
115{
116}
117void
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{
147public:
149 : TestSuite ("ipv4-list-routing", UNIT)
150 {
151 AddTestCase (new Ipv4ListRoutingPositiveTestCase (), TestCase::QUICK);
152 AddTestCase (new Ipv4ListRoutingNegativeTestCase (), TestCase::QUICK);
153 }
154};
155
IPv4 dummy routing class (A)
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)
void NotifyInterfaceUp(uint32_t interface)
void NotifyInterfaceDown(uint32_t interface)
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const
Print the Routing Table entries.
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
void SetIpv4(Ptr< Ipv4 > ipv4)
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 (B)
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
void NotifyInterfaceUp(uint32_t interface)
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
void SetIpv4(Ptr< Ipv4 > ipv4)
void NotifyInterfaceDown(uint32_t interface)
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const
Print the Routing Table entries.
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.
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.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Callback template class.
Definition: callback.h:1279
Packet header for IPv4.
Definition: ipv4-header.h:34
a class to store IPv4 address information on an interface
Abstract base class for IPv4 routing protocols.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
#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:141
static Ipv4ListRoutingTestSuite g_ipv4ListRoutingTestSuite
Static variable for test initialization.
Definition: first.py:1
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: second.py:1