A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 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, "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 
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  {
123  }
124 
126 
127 } // namespace ns3
128 
129