A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv4-list-routing-test-suite.cc
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 
61 Ipv4ListRoutingNegativeTestCase::Ipv4ListRoutingNegativeTestCase()
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, "XXX");
77  Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
78  NS_TEST_ASSERT_MSG_EQ (-5, first, "XXX");
79  NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "XXX");
80 }
81 
83 {
84 public:
86  virtual void DoRun (void);
87 };
88 
89 Ipv4ListRoutingPositiveTestCase::Ipv4ListRoutingPositiveTestCase()
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, "XXX");
107  Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
108  NS_TEST_ASSERT_MSG_EQ (10, first, "XXX");
109  NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "XXX");
110  Ptr<Ipv4RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
111  NS_TEST_ASSERT_MSG_EQ (5, second, "XXX");
112  NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "XXX");
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 
125 } g_ipv4ListRoutingTestSuite;
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.
Callback template class.
Definition: callback.h:369
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(uint32_t index, int16_t &priority) const
A suite of tests to run.
Definition: test.h:962
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:834
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Definition: test.cc:354
Packet header for IPv4.
Definition: ipv4-header.h:31
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
void NotifyInterfaceDown(uint32_t interface)
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
virtual uint32_t GetNRoutingProtocols(void) const
void NotifyInterfaceUp(uint32_t interface)
void NotifyInterfaceDown(uint32_t interface)
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
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 test case.
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 test case.
Abstract base class for IPv4 routing protocols.
void NotifyInterfaceUp(uint32_t interface)
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
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)