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-address-helper-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) 2012 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
#include "ns3/ipv6-address-helper.h"
20
#include "ns3/ipv6-address-generator.h"
21
#include "ns3/ipv4-address-helper.h"
22
#include "ns3/simple-net-device.h"
23
#include "ns3/net-device-container.h"
24
#include "ns3/node-container.h"
25
#include "ns3/internet-stack-helper.h"
26
#include "ns3/test.h"
27
#include "ns3/log.h"
28
29
using namespace
ns3;
30
31
class
IpAddressHelperTestCasev6
:
public
TestCase
32
{
33
public
:
34
IpAddressHelperTestCasev6
();
35
virtual
~
IpAddressHelperTestCasev6
();
36
37
private
:
38
virtual
void
DoRun (
void
);
39
virtual
void
DoTeardown (
void
);
40
};
41
42
IpAddressHelperTestCasev6::IpAddressHelperTestCasev6
()
43
:
TestCase
(
"IpAddressHelper Ipv6 test case"
)
44
{
45
}
46
47
IpAddressHelperTestCasev6::~IpAddressHelperTestCasev6
()
48
{
49
}
50
51
void
52
IpAddressHelperTestCasev6::DoRun
(
void
)
53
{
54
Ipv6AddressHelper
ip1;
55
Ipv6Address
ipAddr1;
56
ipAddr1 = ip1.
NewAddress
();
57
// Ipv6AddressHelper that is unconfigured
58
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv6Address
(
"2001:db8::1"
),
"Ipv6AddressHelper failure"
);
59
ipAddr1 = ip1.
NewAddress
();
60
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv6Address
(
"2001:db8::2"
),
"Ipv6AddressHelper failure"
);
61
ip1.
NewNetwork
();
62
ipAddr1 = ip1.
NewAddress
();
63
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv6Address
(
"2001:db8:0:1:0:0:0:1"
),
"Ipv6AddressHelper failure"
);
64
65
// Reset
66
ip1.
SetBase
(
Ipv6Address
(
"2001:db81::"
),
Ipv6Prefix
(32),
Ipv6Address
(
"::1"
));
67
ipAddr1 = ip1.
NewAddress
();
68
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv6Address
(
"2001:db81::1"
),
"Ipv6AddressHelper failure"
);
69
// Skip a few addresses
70
ip1.
SetBase
(
Ipv6Address
(
"2001:db81::"
),
Ipv6Prefix
(32),
Ipv6Address
(
"::15"
));
71
ipAddr1 = ip1.
NewAddress
();
72
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv6Address
(
"2001:db81::15"
),
"Ipv6AddressHelper failure"
);
73
ipAddr1 = ip1.
NewAddress
();
74
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv6Address
(
"2001:db81::16"
),
"Ipv6AddressHelper failure"
);
75
// Increment network
76
ip1.
NewNetwork
();
77
ipAddr1 = ip1.
NewAddress
();
78
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv6Address
(
"2001:db81:0:1::15"
),
"Ipv6AddressHelper failure"
);
79
// Reset
80
ip1.
SetBase
(
Ipv6Address
(
"2001:dddd::"
),
Ipv6Prefix
(32),
Ipv6Address
(
"::1"
));
81
ipAddr1 = ip1.
NewAddress
();
// ::1
82
ipAddr1 = ip1.
NewAddress
();
// ::2
83
ipAddr1 = ip1.
NewAddress
();
// ::3
84
ip1.
NewNetwork
();
// 0:1
85
ip1.
NewNetwork
();
// 0:2
86
ipAddr1 = ip1.
NewAddress
();
// ::1 again
87
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv6Address
(
"2001:dddd:0:2::1"
),
"Ipv6AddressHelper failure"
);
88
89
// Set again
90
ip1.
SetBase
(
Ipv6Address
(
"2001:db82::1"
),
Ipv6Prefix
(32));
91
ipAddr1 = ip1.
NewAddress
();
92
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv6Address
(
"2001:db82::1"
),
"Ipv6AddressHelper failure"
);
93
94
// Test container assignment
95
NodeContainer
n;
96
n.
Create
(2);
97
98
/* Install IPv4/IPv6 stack */
99
InternetStackHelper
internetv6;
100
internetv6.
SetIpv4StackInstall
(
false
);
101
internetv6.
Install
(n);
102
103
NetDeviceContainer
d;
104
Ptr<SimpleNetDevice>
s1 = CreateObject<SimpleNetDevice> ();
105
s1->
SetAddress
(Mac48Address::Allocate ());
106
n.
Get
(0)->
AddDevice
(s1);
107
108
Ptr<SimpleNetDevice>
s2 = CreateObject<SimpleNetDevice> ();
109
s2->
SetAddress
(Mac48Address::Allocate ());
110
n.
Get
(1)->
AddDevice
(s2);
111
d.
Add
(s1);
112
d.
Add
(s2);
113
114
ip1.
SetBase
(
Ipv6Address
(
"2001:00aa::"
),
Ipv6Prefix
(56));
115
Ipv6InterfaceContainer
ic;
116
ic = ip1.
Assign
(d);
117
118
// Check that d got intended addresses
119
Ipv6InterfaceAddress
d1addr;
120
Ipv6InterfaceAddress
d2addr;
121
// Interface 0 is loopback, interface 1 is s1, and the 0th addr is linklocal
122
// so we look at address (1,1)
123
d1addr = n.
Get
(0)->
GetObject
<
Ipv6
> ()->GetAddress (1, 1);
124
NS_TEST_ASSERT_MSG_EQ
(d1addr.
GetAddress
(),
Ipv6Address
(
"2001:00aa:0000:0000:0200:00ff:fe00:0001"
),
"Ipv6AddressHelper failure"
);
125
// Look also at the interface container (device 0, address 1)
126
NS_TEST_ASSERT_MSG_EQ
(ic.
GetAddress
(0,1),
Ipv6Address
(
"2001:00aa:0000:0000:0200:00ff:fe00:0001"
),
"Ipv6AddressHelper failure"
);
127
d2addr = n.
Get
(1)->
GetObject
<
Ipv6
> ()->GetAddress (1, 1);
128
// Look at second container
129
NS_TEST_ASSERT_MSG_EQ
(d2addr.GetAddress (),
Ipv6Address
(
"2001:00aa:0000:0000:0200:00ff:fe00:0002"
),
"Ipv6AddressHelper failure"
);
130
// Look also at the interface container (device 0, address 1)
131
NS_TEST_ASSERT_MSG_EQ
(ic.
GetAddress
(1,1),
Ipv6Address
(
"2001:00aa:0000:0000:0200:00ff:fe00:0002"
),
"Ipv6AddressHelper failure"
);
132
}
133
134
void
135
IpAddressHelperTestCasev6::DoTeardown
(
void
)
136
{
137
Ipv6AddressGenerator::Reset
();
138
Simulator::Destroy ();
139
}
140
141
142
class
Ipv6AddressHelperTestSuite
:
public
TestSuite
143
{
144
public
:
145
Ipv6AddressHelperTestSuite
();
146
};
147
148
Ipv6AddressHelperTestSuite::Ipv6AddressHelperTestSuite
()
149
:
TestSuite
(
"ipv6-address-helper"
, UNIT)
150
{
151
AddTestCase
(
new
IpAddressHelperTestCasev6
);
152
}
153
154
// Do not forget to allocate an instance of this TestSuite
155
static
Ipv6AddressHelperTestSuite
ipv6AddressHelperTestSuite
;
src
internet
test
ipv6-address-helper-test-suite.cc
Generated on Fri Dec 21 2012 19:00:38 for ns-3 by
1.8.1.2