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 
27 public:
28  Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0; }
31  LocalDeliverCallback lcb, ErrorCallback ecb) { return false; }
32  void NotifyInterfaceUp (uint32_t interface) {}
33  void NotifyInterfaceDown (uint32_t interface) {}
34  void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
35  void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
36  void SetIpv4 (Ptr<Ipv4> ipv4) {}
38 };
39 
41 public:
42  Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0; }
45  LocalDeliverCallback lcb, ErrorCallback ecb) { return false; }
46  void NotifyInterfaceUp (uint32_t interface) {}
47  void NotifyInterfaceDown (uint32_t interface) {}
48  void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
49  void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
50  void SetIpv4 (Ptr<Ipv4> ipv4) {}
52 };
53 
55 {
56 public:
58  virtual void DoRun (void);
59 };
60 
62  : TestCase ("Check negative priorities")
63 {
64 }
65 void
67 {
68  Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting> ();
69  Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting> ();
70  Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting> ();
71  // The Ipv4BRouting should be added with higher priority (larger integer value)
72  lr->AddRoutingProtocol (aRouting, -10);
73  lr->AddRoutingProtocol (bRouting, -5);
74  int16_t first = 3;
75  uint32_t num = lr->GetNRoutingProtocols ();
76  NS_TEST_ASSERT_MSG_EQ (num, 2, "100");
77  Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
78  NS_TEST_ASSERT_MSG_EQ (-5, first, "101");
79  NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "102");
80 }
81 
83 {
84 public:
86  virtual void DoRun (void);
87 };
88 
90  : TestCase ("Check positive priorities")
91 {
92 }
93 void
95 {
96  Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting> ();
97  Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting> ();
98  Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting> ();
99  // The Ipv4ARouting should be added with higher priority (larger integer
100  // value) and will be fetched first below
101  lr->AddRoutingProtocol (aRouting, 10);
102  lr->AddRoutingProtocol (bRouting, 5);
103  int16_t first = 3;
104  int16_t second = 3;
105  uint32_t num = lr->GetNRoutingProtocols ();
106  NS_TEST_ASSERT_MSG_EQ (num, 2, "200");
107  Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
108  NS_TEST_ASSERT_MSG_EQ (10, first, "201");
109  NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "202");
110  Ptr<Ipv4RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
111  NS_TEST_ASSERT_MSG_EQ (5, second, "203");
112  NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "204");
113 }
114 
115 static class Ipv4ListRoutingTestSuite : public TestSuite
116 {
117 public:
119  : TestSuite ("ipv4-list-routing", UNIT)
120  {
121  AddTestCase (new Ipv4ListRoutingPositiveTestCase (), TestCase::QUICK);
122  AddTestCase (new Ipv4ListRoutingNegativeTestCase (), TestCase::QUICK);
123  }
124 
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.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
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
A suite of tests to run.
Definition: test.h:1333
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)
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
Packet header for IPv4.
Definition: ipv4-header.h:33
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
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:161
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.
Ipv4ListRoutingTestSuite g_ipv4ListRoutingTestSuite
void NotifyInterfaceUp(uint32_t interface)
tuple address
Definition: first.py:37
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
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)