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-test.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License version 2 as
5
* published by the Free Software Foundation;
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
* Author: Faker Moatamri <faker.moatamri@sophia.inria.fr>
16
*
17
*/
22
#include "ns3/simulator.h"
23
#include "ns3/test.h"
24
#include "ns3/log.h"
25
#include "ns3/inet-socket-address.h"
26
#include "ns3/node.h"
27
28
#include "ns3/ipv4-l3-protocol.h"
29
#include "ns3/arp-l3-protocol.h"
30
#include "ns3/ipv4-interface.h"
31
#include "ns3/loopback-net-device.h"
32
33
namespace
ns3 {
34
35
class
Ipv4L3ProtocolTestCase
:
public
TestCase
36
{
37
public
:
41
Ipv4L3ProtocolTestCase
();
45
virtual
46
~Ipv4L3ProtocolTestCase
();
51
virtual
void
52
DoRun
(
void
);
53
54
};
55
56
Ipv4L3ProtocolTestCase::Ipv4L3ProtocolTestCase
() :
57
TestCase
(
"Verify the IPv4 layer 3 protocol"
)
58
{
59
}
60
61
Ipv4L3ProtocolTestCase::~Ipv4L3ProtocolTestCase
()
62
{
63
}
64
void
65
Ipv4L3ProtocolTestCase::DoRun
(
void
)
66
{
67
Ptr<Node>
node = CreateObject<Node> ();
68
Ptr<Ipv4L3Protocol>
ipv4 = CreateObject<Ipv4L3Protocol> ();
69
Ptr<Ipv4Interface>
interface
=
CreateObject
<Ipv4Interface> ();
70
Ptr<LoopbackNetDevice>
device = CreateObject<LoopbackNetDevice> ();
71
node->
AddDevice
(device);
72
interface->SetDevice (device);
73
interface->SetNode (node);
74
uint32_t index = ipv4->AddIpv4Interface (interface);
75
NS_TEST_ASSERT_MSG_EQ
(index, 0,
"No interface should be found??"
);
76
interface->SetUp ();
77
Ipv4InterfaceAddress
ifaceAddr1 =
Ipv4InterfaceAddress
(
"192.168.0.1"
,
78
"255.255.255.0"
);
79
interface->AddAddress (ifaceAddr1);
80
Ipv4InterfaceAddress
ifaceAddr2 =
Ipv4InterfaceAddress
(
"192.168.0.2"
,
81
"255.255.255.0"
);
82
interface->AddAddress (ifaceAddr2);
83
Ipv4InterfaceAddress
ifaceAddr3 =
Ipv4InterfaceAddress
(
"10.30.0.1"
,
84
"255.255.255.0"
);
85
interface->AddAddress (ifaceAddr3);
86
Ipv4InterfaceAddress
ifaceAddr4 =
Ipv4InterfaceAddress
(
"250.0.0.1"
,
87
"255.255.255.0"
);
88
interface->AddAddress (ifaceAddr4);
89
uint32_t num = interface->GetNAddresses ();
90
NS_TEST_ASSERT_MSG_EQ
(num, 4,
"Should find 4 interfaces??"
);
91
interface->RemoveAddress (2);
92
num = interface->GetNAddresses ();
93
NS_TEST_ASSERT_MSG_EQ
(num, 3,
"Should find 3 interfaces??"
);
94
Ipv4InterfaceAddress
output = interface->GetAddress (2);
95
NS_TEST_ASSERT_MSG_EQ
(ifaceAddr4, output,
96
"The addresses should be identical"
);
97
Simulator::Destroy
();
98
}
99
100
static
class
IPv4L3ProtocolTestSuite
:
public
TestSuite
101
{
102
public
:
103
IPv4L3ProtocolTestSuite
() :
104
TestSuite
(
"ipv4-protocol"
,
UNIT
)
105
{
106
AddTestCase
(
new
Ipv4L3ProtocolTestCase
(),
TestCase::QUICK
);
107
}
108
}
g_ipv4protocolTestSuite
;
109
110
}
// namespace ns3
src
internet
test
ipv4-test.cc
Generated on Tue May 14 2013 11:08:23 for ns-3 by
1.8.1.2