A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
using namespace
ns3;
25
26
class
Ipv4ARouting
:
public
Ipv4RoutingProtocol
{
27
public
:
28
Ptr<Ipv4Route>
RouteOutput
(
Ptr<Packet>
p,
const
Ipv4Header
&header,
Ptr<NetDevice>
oif,
Socket::SocketErrno
&sockerr) {
return
0; }
29
bool
RouteInput (
Ptr<const Packet>
p,
const
Ipv4Header
&header,
Ptr<const NetDevice>
idev,
30
UnicastForwardCallback
ucb,
MulticastForwardCallback
mcb,
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) {}
37
void
PrintRoutingTable
(
Ptr<OutputStreamWrapper>
stream)
const
{}
38
};
39
40
class
Ipv4BRouting
:
public
Ipv4RoutingProtocol
{
41
public
:
42
Ptr<Ipv4Route>
RouteOutput
(
Ptr<Packet>
p,
const
Ipv4Header
&header,
Ptr<NetDevice>
oif,
Socket::SocketErrno
&sockerr) {
return
0; }
43
bool
RouteInput (
Ptr<const Packet>
p,
const
Ipv4Header
&header,
Ptr<const NetDevice>
idev,
44
UnicastForwardCallback
ucb,
MulticastForwardCallback
mcb,
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) {}
51
void
PrintRoutingTable
(
Ptr<OutputStreamWrapper>
stream)
const
{}
52
};
53
54
class
Ipv4ListRoutingNegativeTestCase
:
public
TestCase
55
{
56
public
:
57
Ipv4ListRoutingNegativeTestCase
();
58
virtual
void
DoRun (
void
);
59
};
60
61
Ipv4ListRoutingNegativeTestCase::Ipv4ListRoutingNegativeTestCase
()
62
:
TestCase
(
"Check negative priorities"
)
63
{
64
}
65
void
66
Ipv4ListRoutingNegativeTestCase::DoRun
(
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
82
class
Ipv4ListRoutingPositiveTestCase
:
public
TestCase
83
{
84
public
:
85
Ipv4ListRoutingPositiveTestCase
();
86
virtual
void
DoRun
(
void
);
87
};
88
89
Ipv4ListRoutingPositiveTestCase::Ipv4ListRoutingPositiveTestCase
()
90
:
TestCase
(
"Check positive priorities"
)
91
{
92
}
93
void
94
Ipv4ListRoutingPositiveTestCase::DoRun
(
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
:
118
Ipv4ListRoutingTestSuite
()
119
:
TestSuite
(
"ipv4-list-routing"
,
UNIT
)
120
{
121
AddTestCase
(
new
Ipv4ListRoutingPositiveTestCase
());
122
AddTestCase
(
new
Ipv4ListRoutingNegativeTestCase
());
123
}
124
125
}
g_ipv4ListRoutingTestSuite
;
src
internet
test
ipv4-list-routing-test-suite.cc
Generated on Fri Dec 21 2012 19:00:38 for ns-3 by
1.8.1.2