A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
wimax-tlv-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 INRIA, UDcast
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
7
* <amine.ismail@udcast.com>
8
*
9
*/
10
#include "ns3/cs-parameters.h"
11
#include "ns3/ipcs-classifier-record.h"
12
#include "ns3/log.h"
13
#include "ns3/packet.h"
14
#include "ns3/ptr.h"
15
#include "ns3/service-flow.h"
16
#include "ns3/test.h"
17
#include "ns3/wimax-helper.h"
18
#include "ns3/wimax-tlv.h"
19
20
using namespace
ns3
;
21
22
/**
23
* @ingroup wimax-test
24
* @ingroup tests
25
*
26
* @brief Test the wimax tlv implementation.
27
*/
28
class
Ns3WimaxCsParamTlvTestCase
:
public
TestCase
29
{
30
public
:
31
Ns3WimaxCsParamTlvTestCase
();
32
~Ns3WimaxCsParamTlvTestCase
()
override
;
33
34
private
:
35
void
DoRun
()
override
;
36
};
37
38
Ns3WimaxCsParamTlvTestCase::Ns3WimaxCsParamTlvTestCase
()
39
:
TestCase
(
"Test the CS parameters tlv implementation."
)
40
{
41
}
42
43
Ns3WimaxCsParamTlvTestCase::~Ns3WimaxCsParamTlvTestCase
()
44
{
45
}
46
47
void
48
Ns3WimaxCsParamTlvTestCase::DoRun
()
49
{
50
IpcsClassifierRecord
classifier
(
Ipv4Address
(
"10.0.0.0"
),
51
Ipv4Mask
(
"255.0.0.0"
),
52
Ipv4Address
(
"11.0.0.0"
),
53
Ipv4Mask
(
"255.0.0.0"
),
54
1000,
55
1100,
56
3000,
57
3100,
58
17,
59
1);
60
61
classifier
.AddSrcAddr(
Ipv4Address
(
"1.0.0.0"
),
Ipv4Mask
(
"255.0.0.0"
));
62
classifier
.AddDstAddr(
Ipv4Address
(
"16.0.0.0"
),
Ipv4Mask
(
"255.0.0.0"
));
63
classifier
.AddProtocol(6);
64
classifier
.AddSrcPortRange(1, 2);
65
classifier
.AddDstPortRange(4000, 4100);
66
classifier
.SetIndex(1);
67
68
CsParameters
csParam
(
CsParameters::ADD
,
classifier
);
69
70
SfVectorTlvValue
sfVectorTlvValue
;
71
sfVectorTlvValue
.
Add
(
csParam
.ToTlv());
72
73
Tlv
tlvSent
(145,
sfVectorTlvValue
.GetSerializedSize(),
sfVectorTlvValue
);
74
Ptr<Packet>
packet =
Create<Packet>
();
75
packet->AddHeader(
tlvSent
);
76
77
Tlv
tlvReceived
;
78
packet->RemoveHeader(
tlvReceived
);
79
if
(
tlvReceived
.GetType() ==
Tlv::UPLINK_SERVICE_FLOW
)
80
{
81
auto
sfVecValue
= (
SfVectorTlvValue
*)
tlvReceived
.PeekValue();
82
for
(
auto
iter
=
sfVecValue
->Begin();
iter
!=
sfVecValue
->End(); ++
iter
)
83
{
84
if
((*iter)->GetType() ==
SfVectorTlvValue::IPV4_CS_Parameters
)
85
{
86
CsParameters
csParamsRecv
(*(*
iter
));
87
IpcsClassifierRecord
classifier
=
csParamsRecv
.GetPacketClassifierRule();
88
89
NS_TEST_ASSERT_MSG_EQ
(!
classifier
.CheckMatch(
Ipv4Address
(
"10.1.1.1"
),
90
Ipv4Address
(
"16.1.1.1"
),
91
1050,
92
3050,
93
17),
94
false
,
95
"The classifier address did not match."
);
96
NS_TEST_ASSERT_MSG_EQ
(!
classifier
.CheckMatch(
Ipv4Address
(
"10.1.5.1"
),
97
Ipv4Address
(
"11.1.1.23"
),
98
1070,
99
3040,
100
6),
101
false
,
102
"The classifier address did not match."
);
103
NS_TEST_ASSERT_MSG_EQ
(
classifier
.CheckMatch(
Ipv4Address
(
"11.1.1.1"
),
104
Ipv4Address
(
"17.1.1.1"
),
105
1050,
106
3050,
107
17),
108
false
,
109
"The classifier addresses matched."
);
110
NS_TEST_ASSERT_MSG_EQ
(
classifier
.CheckMatch(
Ipv4Address
(
"10.1.1.1"
),
111
Ipv4Address
(
"16.1.1.1"
),
112
1050,
113
3050,
114
8),
115
false
,
116
"The classifier addresses matched."
);
117
}
118
}
119
}
120
}
121
122
/**
123
* @ingroup wimax-test
124
* @ingroup tests
125
*
126
* @brief Test the service flow tlv implementation.
127
*/
128
class
Ns3WimaxSfTlvTestCase
:
public
TestCase
129
{
130
public
:
131
Ns3WimaxSfTlvTestCase
();
132
~Ns3WimaxSfTlvTestCase
()
override
;
133
134
private
:
135
void
DoRun
()
override
;
136
};
137
138
Ns3WimaxSfTlvTestCase::Ns3WimaxSfTlvTestCase
()
139
:
TestCase
(
"Test the service flow tlv implementation."
)
140
{
141
}
142
143
Ns3WimaxSfTlvTestCase::~Ns3WimaxSfTlvTestCase
()
144
{
145
}
146
147
void
148
Ns3WimaxSfTlvTestCase::DoRun
()
149
{
150
IpcsClassifierRecord
classifier
=
IpcsClassifierRecord
();
151
CsParameters
csParam
(
CsParameters::ADD
,
classifier
);
152
ServiceFlow
sf
=
ServiceFlow
(
ServiceFlow::SF_DIRECTION_DOWN
);
153
154
sf
.SetSfid(100);
155
sf
.SetConvergenceSublayerParam(
csParam
);
156
sf
.SetCsSpecification(
ServiceFlow::IPV4
);
157
sf
.SetServiceSchedulingType(
ServiceFlow::SF_TYPE_UGS
);
158
sf
.SetMaxSustainedTrafficRate(1000000);
159
sf
.SetMinReservedTrafficRate(1000000);
160
sf
.SetMinTolerableTrafficRate(1000000);
161
sf
.SetMaximumLatency(10);
162
sf
.SetMaxTrafficBurst(1000);
163
sf
.SetTrafficPriority(1);
164
165
Ptr<Packet>
packet =
Create<Packet>
();
166
packet->AddHeader(
sf
.ToTlv());
167
168
Tlv
tlvReceived
;
169
packet->RemoveHeader(
tlvReceived
);
170
171
ServiceFlow
sfRecv
=
ServiceFlow
(
tlvReceived
);
172
173
NS_TEST_ASSERT_MSG_EQ
(
sfRecv
.GetDirection(),
174
ServiceFlow::SF_DIRECTION_DOWN
,
175
"The sfRecv had the wrong direction."
);
176
NS_TEST_ASSERT_MSG_EQ
(
sfRecv
.GetSfid(), 100,
"The sfRecv had the wrong sfid."
);
177
NS_TEST_ASSERT_MSG_EQ
(
sfRecv
.GetCsSpecification(),
178
ServiceFlow::IPV4
,
179
"The sfRecv had the wrong cs specification."
);
180
NS_TEST_ASSERT_MSG_EQ
(
sfRecv
.GetServiceSchedulingType(),
181
ServiceFlow::SF_TYPE_UGS
,
182
"The sfRecv had the wrong service scheduling type."
);
183
NS_TEST_ASSERT_MSG_EQ
(
sfRecv
.GetMaxSustainedTrafficRate(),
184
1000000,
185
"The sfRecv had the wrong maximum sustained traffic rate."
);
186
NS_TEST_ASSERT_MSG_EQ
(
sfRecv
.GetMinReservedTrafficRate(),
187
1000000,
188
"The sfRecv had the wrong minimum reserved traffic rate."
);
189
NS_TEST_ASSERT_MSG_EQ
(
sfRecv
.GetMinTolerableTrafficRate(),
190
1000000,
191
"The sfRecv had the wrong minimum tolerable traffic rate."
);
192
NS_TEST_ASSERT_MSG_EQ
(
sfRecv
.GetMaximumLatency(),
193
10,
194
"The sfRecv had the wrong maximum latency."
);
195
NS_TEST_ASSERT_MSG_EQ
(
sfRecv
.GetMaxTrafficBurst(),
196
1000,
197
"The sfRecv had the wrong maximum traffic burst."
);
198
NS_TEST_ASSERT_MSG_EQ
(
sfRecv
.GetTrafficPriority(),
199
1,
200
"The sfRecv had the wrong traffic priority."
);
201
}
202
203
/**
204
* @ingroup wimax-test
205
* @ingroup tests
206
*
207
* @brief Ns3 Wimax Tlv Test Suite
208
*/
209
class
Ns3WimaxTlvTestSuite
:
public
TestSuite
210
{
211
public
:
212
Ns3WimaxTlvTestSuite
();
213
};
214
215
Ns3WimaxTlvTestSuite::Ns3WimaxTlvTestSuite
()
216
:
TestSuite
(
"wimax-tlv"
,
Type
::UNIT)
217
{
218
AddTestCase
(
new
Ns3WimaxCsParamTlvTestCase
, TestCase::Duration::QUICK);
219
AddTestCase
(
new
Ns3WimaxSfTlvTestCase
, TestCase::Duration::QUICK);
220
}
221
222
static
Ns3WimaxTlvTestSuite
ns3WimaxTlvTestSuite
;
///< the test suite
Ns3WimaxCsParamTlvTestCase
Test the wimax tlv implementation.
Definition
wimax-tlv-test.cc:29
Ns3WimaxCsParamTlvTestCase::Ns3WimaxCsParamTlvTestCase
Ns3WimaxCsParamTlvTestCase()
Definition
wimax-tlv-test.cc:38
Ns3WimaxCsParamTlvTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
wimax-tlv-test.cc:48
Ns3WimaxCsParamTlvTestCase::~Ns3WimaxCsParamTlvTestCase
~Ns3WimaxCsParamTlvTestCase() override
Definition
wimax-tlv-test.cc:43
Ns3WimaxSfTlvTestCase
Test the service flow tlv implementation.
Definition
wimax-tlv-test.cc:129
Ns3WimaxSfTlvTestCase::~Ns3WimaxSfTlvTestCase
~Ns3WimaxSfTlvTestCase() override
Definition
wimax-tlv-test.cc:143
Ns3WimaxSfTlvTestCase::Ns3WimaxSfTlvTestCase
Ns3WimaxSfTlvTestCase()
Definition
wimax-tlv-test.cc:138
Ns3WimaxSfTlvTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
wimax-tlv-test.cc:148
Ns3WimaxTlvTestSuite
Ns3 Wimax Tlv Test Suite.
Definition
wimax-tlv-test.cc:210
Ns3WimaxTlvTestSuite::Ns3WimaxTlvTestSuite
Ns3WimaxTlvTestSuite()
Definition
wimax-tlv-test.cc:215
ns3::CsParameters
CsParameters class.
Definition
cs-parameters.h:25
ns3::CsParameters::ADD
@ ADD
Definition
cs-parameters.h:30
ns3::IpcsClassifierRecord
IpcsClassifierRecord class.
Definition
ipcs-classifier-record.h:27
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition
ipv4-address.h:246
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::ServiceFlow
This class implements service flows as described by the IEEE-802.16 standard.
Definition
service-flow.h:32
ns3::ServiceFlow::SF_TYPE_UGS
@ SF_TYPE_UGS
Definition
service-flow.h:57
ns3::ServiceFlow::IPV4
@ IPV4
Definition
service-flow.h:65
ns3::ServiceFlow::SF_DIRECTION_DOWN
@ SF_DIRECTION_DOWN
Definition
service-flow.h:37
ns3::SfVectorTlvValue
SfVectorTlvValue class.
Definition
wimax-tlv.h:326
ns3::SfVectorTlvValue::IPV4_CS_Parameters
@ IPV4_CS_Parameters
Definition
wimax-tlv.h:359
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::Tlv
This class implements the Type-Len-Value structure channel encodings as described by "IEEE Standard f...
Definition
wimax-tlv.h:76
ns3::Tlv::UPLINK_SERVICE_FLOW
@ UPLINK_SERVICE_FLOW
Definition
wimax-tlv.h:85
ns3::VectorTlvValue::Add
void Add(const Tlv &val)
Add a TLV.
Definition
wimax-tlv.cc:273
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
NS_TEST_ASSERT_MSG_EQ
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition
test.h:134
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3WimaxTlvTestSuite
static Ns3WimaxTlvTestSuite ns3WimaxTlvTestSuite
the test suite
Definition
wimax-tlv-test.cc:222
src
wimax
test
wimax-tlv-test.cc
Generated on Mon Dec 15 2025 15:22:12 for ns-3 by
1.9.8