A Discrete-Event Network Simulator
API
wimax-tlv-test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 INRIA, UDcast
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
18  * <amine.ismail@udcast.com>
19  *
20  */
21 #include "ns3/cs-parameters.h"
22 #include "ns3/ipcs-classifier-record.h"
23 #include "ns3/log.h"
24 #include "ns3/packet.h"
25 #include "ns3/ptr.h"
26 #include "ns3/service-flow.h"
27 #include "ns3/test.h"
28 #include "ns3/wimax-helper.h"
29 #include "ns3/wimax-tlv.h"
30 
31 using namespace ns3;
32 
40 {
41  public:
43  ~Ns3WimaxCsParamTlvTestCase() override;
44 
45  private:
46  void DoRun() override;
47 };
48 
50  : TestCase("Test the CS parameters tlv implementation.")
51 {
52 }
53 
55 {
56 }
57 
58 void
60 {
61  IpcsClassifierRecord classifier(Ipv4Address("10.0.0.0"),
62  Ipv4Mask("255.0.0.0"),
63  Ipv4Address("11.0.0.0"),
64  Ipv4Mask("255.0.0.0"),
65  1000,
66  1100,
67  3000,
68  3100,
69  17,
70  1);
71 
72  classifier.AddSrcAddr(Ipv4Address("1.0.0.0"), Ipv4Mask("255.0.0.0"));
73  classifier.AddDstAddr(Ipv4Address("16.0.0.0"), Ipv4Mask("255.0.0.0"));
74  classifier.AddProtocol(6);
75  classifier.AddSrcPortRange(1, 2);
76  classifier.AddDstPortRange(4000, 4100);
77  classifier.SetIndex(1);
78 
79  CsParameters csParam(CsParameters::ADD, classifier);
80 
81  SfVectorTlvValue sfVectorTlvValue;
82  sfVectorTlvValue.Add(csParam.ToTlv());
83 
84  Tlv tlvSent(145, sfVectorTlvValue.GetSerializedSize(), sfVectorTlvValue);
85  Ptr<Packet> packet = Create<Packet>();
86  packet->AddHeader(tlvSent);
87 
88  Tlv tlvReceived;
89  packet->RemoveHeader(tlvReceived);
90  if (tlvReceived.GetType() == Tlv::UPLINK_SERVICE_FLOW)
91  {
92  auto sfVecValue = (SfVectorTlvValue*)tlvReceived.PeekValue();
93  for (auto iter = sfVecValue->Begin(); iter != sfVecValue->End(); ++iter)
94  {
95  if ((*iter)->GetType() == SfVectorTlvValue::IPV4_CS_Parameters)
96  {
97  CsParameters csParamsRecv(*(*iter));
98  IpcsClassifierRecord classifier = csParamsRecv.GetPacketClassifierRule();
99 
100  NS_TEST_ASSERT_MSG_EQ(!classifier.CheckMatch(Ipv4Address("10.1.1.1"),
101  Ipv4Address("16.1.1.1"),
102  1050,
103  3050,
104  17),
105  false,
106  "The classifier address did not match.");
107  NS_TEST_ASSERT_MSG_EQ(!classifier.CheckMatch(Ipv4Address("10.1.5.1"),
108  Ipv4Address("11.1.1.23"),
109  1070,
110  3040,
111  6),
112  false,
113  "The classifier address did not match.");
114  NS_TEST_ASSERT_MSG_EQ(classifier.CheckMatch(Ipv4Address("11.1.1.1"),
115  Ipv4Address("17.1.1.1"),
116  1050,
117  3050,
118  17),
119  false,
120  "The classifier addresses matched.");
121  NS_TEST_ASSERT_MSG_EQ(classifier.CheckMatch(Ipv4Address("10.1.1.1"),
122  Ipv4Address("16.1.1.1"),
123  1050,
124  3050,
125  8),
126  false,
127  "The classifier addresses matched.");
128  }
129  }
130  }
131 }
132 
140 {
141  public:
143  ~Ns3WimaxSfTlvTestCase() override;
144 
145  private:
146  void DoRun() override;
147 };
148 
150  : TestCase("Test the service flow tlv implementation.")
151 {
152 }
153 
155 {
156 }
157 
158 void
160 {
162  CsParameters csParam(CsParameters::ADD, classifier);
163  ServiceFlow sf = ServiceFlow(ServiceFlow::SF_DIRECTION_DOWN);
164 
165  sf.SetSfid(100);
166  sf.SetConvergenceSublayerParam(csParam);
168  sf.SetServiceSchedulingType(ServiceFlow::SF_TYPE_UGS);
169  sf.SetMaxSustainedTrafficRate(1000000);
170  sf.SetMinReservedTrafficRate(1000000);
171  sf.SetMinTolerableTrafficRate(1000000);
172  sf.SetMaximumLatency(10);
173  sf.SetMaxTrafficBurst(1000);
174  sf.SetTrafficPriority(1);
175 
176  Ptr<Packet> packet = Create<Packet>();
177  packet->AddHeader(sf.ToTlv());
178 
179  Tlv tlvReceived;
180  packet->RemoveHeader(tlvReceived);
181 
182  ServiceFlow sfRecv = ServiceFlow(tlvReceived);
183 
185  ServiceFlow::SF_DIRECTION_DOWN,
186  "The sfRecv had the wrong direction.");
187  NS_TEST_ASSERT_MSG_EQ(sfRecv.GetSfid(), 100, "The sfRecv had the wrong sfid.");
190  "The sfRecv had the wrong cs specification.");
192  ServiceFlow::SF_TYPE_UGS,
193  "The sfRecv had the wrong service scheduling type.");
195  1000000,
196  "The sfRecv had the wrong maximum sustained traffic rate.");
198  1000000,
199  "The sfRecv had the wrong minimum reserved traffic rate.");
201  1000000,
202  "The sfRecv had the wrong minimum tolerable traffic rate.");
204  10,
205  "The sfRecv had the wrong maximum latency.");
207  1000,
208  "The sfRecv had the wrong maximum traffic burst.");
210  1,
211  "The sfRecv had the wrong traffic priority.");
212 }
213 
221 {
222  public:
224 };
225 
227  : TestSuite("wimax-tlv", UNIT)
228 {
229  AddTestCase(new Ns3WimaxCsParamTlvTestCase, TestCase::QUICK);
230  AddTestCase(new Ns3WimaxSfTlvTestCase, TestCase::QUICK);
231 }
232 
Test the wimax tlv implementation.
void DoRun() override
Implementation to actually run this TestCase.
~Ns3WimaxCsParamTlvTestCase() override
Test the service flow tlv implementation.
~Ns3WimaxSfTlvTestCase() override
void DoRun() override
Implementation to actually run this TestCase.
Ns3 Wimax Tlv Test Suite.
CsParameters class.
Definition: cs-parameters.h:36
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.
Definition: ipv4-address.h:42
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:294
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:43
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:337
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
This class implements the Type-Len-Value structure channel encodings as described by "IEEE Standard f...
Definition: wimax-tlv.h:87
uint8_t GetType() const
Get type value.
Definition: wimax-tlv.cc:211
TlvValue * PeekValue()
Peek value.
Definition: wimax-tlv.cc:223
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:251
void Add(const Tlv &val)
Add a TLV.
Definition: wimax-tlv.cc:284
#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:144
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ IPV4
Definition: packetbb.h:47
static Ns3WimaxTlvTestSuite ns3WimaxTlvTestSuite
the test suite