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
ipv6-test.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 Strasbourg University
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
* Authors: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19
* Faker Moatamri <faker.moatamri@sophia.inria.fr>
20
*/
21
#include "ns3/simulator.h"
22
#include "ns3/test.h"
23
#include "ns3/log.h"
24
#include "ns3/boolean.h"
25
#include "ns3/inet6-socket-address.h"
26
#include "ns3/node.h"
27
#include "ns3/simple-net-device.h"
28
29
#include "ns3/ipv6-interface.h"
30
#include "ns3/ipv6-l3-protocol.h"
31
#include "ns3/icmpv6-l4-protocol.h"
32
33
namespace
ns3 {
34
35
class
Ipv6L3ProtocolTestCase
:
public
TestCase
36
{
37
public
:
41
Ipv6L3ProtocolTestCase
();
42
46
virtual
47
~Ipv6L3ProtocolTestCase
();
48
53
virtual
void
54
DoRun
();
55
};
56
Ipv6L3ProtocolTestCase::Ipv6L3ProtocolTestCase
() :
57
TestCase
(
"Verify the IPv6 layer 3 protocol"
)
58
{
59
}
60
Ipv6L3ProtocolTestCase::~Ipv6L3ProtocolTestCase
()
61
{
62
}
63
void
64
Ipv6L3ProtocolTestCase::DoRun
()
65
{
66
Ptr<Node>
node = CreateObject<Node> ();
67
Ptr<Ipv6L3Protocol>
ipv6 = CreateObject<Ipv6L3Protocol> ();
68
Ptr<Icmpv6L4Protocol>
icmpv6 = CreateObject<Icmpv6L4Protocol> ();
69
Ptr<Ipv6Interface>
interface
=
CreateObject
<Ipv6Interface> ();
70
Ptr<Ipv6Interface>
interface2 = CreateObject<Ipv6Interface> ();
71
Ptr<SimpleNetDevice>
device = CreateObject<SimpleNetDevice> ();
72
Ptr<SimpleNetDevice>
device2 = CreateObject<SimpleNetDevice> ();
73
uint32_t index = 0;
74
75
/* init */
76
icmpv6->
SetAttribute
(
"DAD"
,
BooleanValue
(
false
));
77
node->
AggregateObject
(ipv6);
78
node->
AggregateObject
(icmpv6);
79
ipv6->Insert (icmpv6);
80
81
/* first real interface (loopback is also installed) */
82
node->
AddDevice
(device);
83
interface->SetDevice (device);
84
interface->SetNode (node);
85
index = ipv6->AddIpv6Interface (interface);
86
NS_TEST_ASSERT_MSG_EQ
(index, 1,
"The index is not 1??"
);
87
88
/* second interface */
89
node->
AddDevice
(device2);
90
interface2->SetDevice (device2);
91
interface2->SetNode (node);
92
index = ipv6->AddIpv6Interface (interface2);
93
NS_TEST_ASSERT_MSG_EQ
(index, 2,
"The index is not 2??"
);
94
95
Ipv6InterfaceAddress
ifaceAddr = interface->GetLinkLocalAddress ();
96
NS_TEST_ASSERT_MSG_EQ
(ifaceAddr.
GetAddress
().
IsLinkLocal
(),
true
,
97
"Should be link local??"
);
98
99
interface->SetUp ();
100
NS_TEST_ASSERT_MSG_EQ
(interface->GetNAddresses (), 1,
101
"interface has always a link-local address"
);
/* interface has always a link-local address */
102
103
interface2->SetUp ();
104
105
Ipv6InterfaceAddress
ifaceAddr1 =
Ipv6InterfaceAddress
(
106
"2001:1234:5678:9000::1"
,
Ipv6Prefix
(64));
107
interface->AddAddress (ifaceAddr1);
108
Ipv6InterfaceAddress
ifaceAddr2 =
Ipv6InterfaceAddress
(
109
"2001:ffff:5678:9000::1"
,
Ipv6Prefix
(64));
110
interface->AddAddress (ifaceAddr2);
111
112
Ipv6InterfaceAddress
ifaceAddr3 =
Ipv6InterfaceAddress
(
113
"2001:ffff:5678:9001::2"
,
Ipv6Prefix
(64));
114
interface2->AddAddress (ifaceAddr3);
115
116
uint32_t num = interface->GetNAddresses ();
117
NS_TEST_ASSERT_MSG_EQ
(num, 3,
"Number of addresses should be 3??"
);
/* 2 global addresses + link-local ones */
118
119
num = interface2->GetNAddresses ();
120
NS_TEST_ASSERT_MSG_EQ
(num, 2,
"1 global addresses + link-local ones"
);
/* 1 global addresses + link-local ones */
121
122
interface->RemoveAddress (2);
123
num = interface->GetNAddresses ();
124
NS_TEST_ASSERT_MSG_EQ
(num, 2,
"Number of addresses should be 2??"
);
125
126
Ipv6InterfaceAddress
output = interface->
GetAddress
(1);
127
NS_TEST_ASSERT_MSG_EQ
(ifaceAddr1, output,
128
"Should be the interface address 1?"
);
129
130
index = ipv6->GetInterfaceForPrefix (
"2001:1234:5678:9000::0"
,
131
Ipv6Prefix
(64));
132
NS_TEST_ASSERT_MSG_EQ
(index, 1,
"We should get one address??"
);
/* link-local address is always index 0 */
133
134
index = ipv6->GetInterfaceForAddress (
"2001:ffff:5678:9001::2"
);
135
NS_TEST_ASSERT_MSG_EQ
(index, 2,
"Number of addresses should be 2??"
);
136
137
index = ipv6->GetInterfaceForAddress (
"2001:ffff:5678:9000::1"
);
/* address we just remove */
138
NS_TEST_ASSERT_MSG_EQ
(index, (uint32_t) -1,
"Address should not be found??"
);
139
Simulator::Destroy
();
140
}
//end DoRun
141
static
class
IPv6L3ProtocolTestSuite
:
public
TestSuite
142
{
143
public
:
144
IPv6L3ProtocolTestSuite
() :
145
TestSuite
(
"ipv6-protocol"
,
UNIT
)
146
{
147
AddTestCase
(
new
Ipv6L3ProtocolTestCase
(),
TestCase::QUICK
);
148
}
149
}
g_ipv6protocolTestSuite
;
150
151
}
// namespace ns3
src
internet
test
ipv6-test.cc
Generated on Tue May 14 2013 11:08:24 for ns-3 by
1.8.1.2