A Discrete-Event Network Simulator
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
20using namespace ns3;
21
22/**
23 * \ingroup wimax-test
24 * \ingroup tests
25 *
26 * \brief Test the wimax tlv implementation.
27 */
29{
30 public:
33
34 private:
35 void DoRun() override;
36};
37
39 : TestCase("Test the CS parameters tlv implementation.")
40{
41}
42
46
47void
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 */
129{
130 public:
132 ~Ns3WimaxSfTlvTestCase() override;
133
134 private:
135 void DoRun() override;
136};
137
139 : TestCase("Test the service flow tlv implementation.")
140{
141}
142
146
147void
149{
151 CsParameters csParam(CsParameters::ADD, classifier);
153
154 sf.SetSfid(100);
155 sf.SetConvergenceSublayerParam(csParam);
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
175 "The sfRecv had the wrong direction.");
176 NS_TEST_ASSERT_MSG_EQ(sfRecv.GetSfid(), 100, "The sfRecv had the wrong sfid.");
179 "The sfRecv had the wrong cs specification.");
182 "The sfRecv had the wrong service scheduling type.");
184 1000000,
185 "The sfRecv had the wrong maximum sustained traffic rate.");
187 1000000,
188 "The sfRecv had the wrong minimum reserved traffic rate.");
190 1000000,
191 "The sfRecv had the wrong minimum tolerable traffic rate.");
193 10,
194 "The sfRecv had the wrong maximum latency.");
196 1000,
197 "The sfRecv had the wrong maximum traffic burst.");
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 */
210{
211 public:
213};
214
216 : TestSuite("wimax-tlv", Type::UNIT)
217{
218 AddTestCase(new Ns3WimaxCsParamTlvTestCase, TestCase::Duration::QUICK);
219 AddTestCase(new Ns3WimaxSfTlvTestCase, TestCase::Duration::QUICK);
220}
221
Test the wimax tlv implementation.
void DoRun() override
Implementation to actually run this TestCase.
Test the service flow tlv implementation.
~Ns3WimaxSfTlvTestCase() override
void DoRun() override
Implementation to actually run this TestCase.
Ns3 Wimax Tlv Test Suite.
CsParameters class.
Tlv ToTlv() const
creates a tlv from the classifier record
IpcsClassifierRecord GetPacketClassifierRule() const
IpcsClassifierRecord class.
void SetIndex(uint16_t index)
Set the index of the classifier.
void AddDstAddr(Ipv4Address dstAddress, Ipv4Mask dstMask)
add a new destination ip address to the classifier
void AddSrcPortRange(uint16_t srcPortLow, uint16_t srcPortHigh)
add a range of source port to the classifier
bool CheckMatch(Ipv4Address srcAddress, Ipv4Address dstAddress, uint16_t srcPort, uint16_t dstPort, uint8_t proto) const
check if a packets can be used with this classifier
void AddDstPortRange(uint16_t dstPortLow, uint16_t dstPortHigh)
add a range of destination port to the classifier
void AddSrcAddr(Ipv4Address srcAddress, Ipv4Mask srcMask)
add a new source ip address to the classifier
void AddProtocol(uint8_t proto)
add a protocol to the classifier
Ipv4 addresses are stored in host order in this class.
a class to represent an Ipv4 address mask
Smart pointer class similar to boost::intrusive_ptr.
This class implements service flows as described by the IEEE-802.16 standard.
void SetSfid(uint32_t sfid)
Set SFID.
void SetCsSpecification(CsSpecification spec)
Set CS specification.
ServiceFlow::SchedulingType GetServiceSchedulingType() const
Get service scheduling type.
uint32_t GetMaxSustainedTrafficRate() const
Get max sustained traffic rate.
uint32_t GetMaxTrafficBurst() const
Get max traffic burst.
uint32_t GetSfid() const
Get SFID.
uint32_t GetMaximumLatency() const
Get maximum latency.
void SetMaxTrafficBurst(uint32_t maxTrafficBurst)
Set maximum traffic burst.
void SetServiceSchedulingType(ServiceFlow::SchedulingType schedType)
Set service scheduling type.
Tlv ToTlv() const
creates a TLV from this service flow
void SetMaximumLatency(uint32_t MaximumLatency)
Set maximum latency.
void SetConvergenceSublayerParam(CsParameters csparam)
Set convergence sublayer parameters.
uint8_t GetTrafficPriority() const
Get traffic priority.
uint32_t GetMinReservedTrafficRate() const
Get minimum reserved traffic rate.
void SetTrafficPriority(uint8_t priority)
Set traffic priority.
CsSpecification GetCsSpecification() const
Get CS specification.
void SetMinTolerableTrafficRate(uint32_t minJitter)
Set minimum tolerable traffic rate.
uint32_t GetMinTolerableTrafficRate() const
Get minimum tolerable traffic rate.
void SetMinReservedTrafficRate(uint32_t minResvRate)
Set minimum reserved traffic rate.
Direction GetDirection() const
Get direction.
void SetMaxSustainedTrafficRate(uint32_t maxSustainedRate)
Set max sustained traffic rate.
SfVectorTlvValue class.
Definition wimax-tlv.h:326
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
This class implements the Type-Len-Value structure channel encodings as described by "IEEEStandard fo...
Definition wimax-tlv.h:76
uint8_t GetType() const
Get type value.
Definition wimax-tlv.cc:200
TlvValue * PeekValue()
Peek value.
Definition wimax-tlv.cc:212
@ UPLINK_SERVICE_FLOW
Definition wimax-tlv.h:85
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition wimax-tlv.cc:240
void Add(const Tlv &val)
Add a TLV.
Definition wimax-tlv.cc:273
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static Ns3WimaxTlvTestSuite ns3WimaxTlvTestSuite
the test suite