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  SfVectorTlvValue* sfVecValue = (SfVectorTlvValue*)tlvReceived.PeekValue();
93  for (std::vector<Tlv*>::const_iterator iter = sfVecValue->Begin();
94  iter != sfVecValue->End();
95  ++iter)
96  {
97  if ((*iter)->GetType() == SfVectorTlvValue::IPV4_CS_Parameters)
98  {
99  CsParameters csParamsRecv(*(*iter));
100  IpcsClassifierRecord classifier = csParamsRecv.GetPacketClassifierRule();
101 
102  NS_TEST_ASSERT_MSG_EQ(!classifier.CheckMatch(Ipv4Address("10.1.1.1"),
103  Ipv4Address("16.1.1.1"),
104  1050,
105  3050,
106  17),
107  false,
108  "The classifier address did not match.");
109  NS_TEST_ASSERT_MSG_EQ(!classifier.CheckMatch(Ipv4Address("10.1.5.1"),
110  Ipv4Address("11.1.1.23"),
111  1070,
112  3040,
113  6),
114  false,
115  "The classifier address did not match.");
116  NS_TEST_ASSERT_MSG_EQ(classifier.CheckMatch(Ipv4Address("11.1.1.1"),
117  Ipv4Address("17.1.1.1"),
118  1050,
119  3050,
120  17),
121  false,
122  "The classifier addresses matched.");
123  NS_TEST_ASSERT_MSG_EQ(classifier.CheckMatch(Ipv4Address("10.1.1.1"),
124  Ipv4Address("16.1.1.1"),
125  1050,
126  3050,
127  8),
128  false,
129  "The classifier addresses matched.");
130  }
131  }
132  }
133 }
134 
142 {
143  public:
145  ~Ns3WimaxSfTlvTestCase() override;
146 
147  private:
148  void DoRun() override;
149 };
150 
152  : TestCase("Test the service flow tlv implementation.")
153 {
154 }
155 
157 {
158 }
159 
160 void
162 {
164  CsParameters csParam(CsParameters::ADD, classifier);
165  ServiceFlow sf = ServiceFlow(ServiceFlow::SF_DIRECTION_DOWN);
166 
167  sf.SetSfid(100);
168  sf.SetConvergenceSublayerParam(csParam);
170  sf.SetServiceSchedulingType(ServiceFlow::SF_TYPE_UGS);
171  sf.SetMaxSustainedTrafficRate(1000000);
172  sf.SetMinReservedTrafficRate(1000000);
173  sf.SetMinTolerableTrafficRate(1000000);
174  sf.SetMaximumLatency(10);
175  sf.SetMaxTrafficBurst(1000);
176  sf.SetTrafficPriority(1);
177 
178  Ptr<Packet> packet = Create<Packet>();
179  packet->AddHeader(sf.ToTlv());
180 
181  Tlv tlvReceived;
182  packet->RemoveHeader(tlvReceived);
183 
184  ServiceFlow sfRecv = ServiceFlow(tlvReceived);
185 
187  ServiceFlow::SF_DIRECTION_DOWN,
188  "The sfRecv had the wrong direction.");
189  NS_TEST_ASSERT_MSG_EQ(sfRecv.GetSfid(), 100, "The sfRecv had the wrong sfid.");
192  "The sfRecv had the wrong cs specification.");
194  ServiceFlow::SF_TYPE_UGS,
195  "The sfRecv had the wrong service scheduling type.");
197  1000000,
198  "The sfRecv had the wrong maximum sustained traffic rate.");
200  1000000,
201  "The sfRecv had the wrong minimum reserved traffic rate.");
203  1000000,
204  "The sfRecv had the wrong minimum tolerable traffic rate.");
206  10,
207  "The sfRecv had the wrong maximum latency.");
209  1000,
210  "The sfRecv had the wrong maximum traffic burst.");
212  1,
213  "The sfRecv had the wrong traffic priority.");
214 }
215 
223 {
224  public:
226 };
227 
229  : TestSuite("wimax-tlv", UNIT)
230 {
231  AddTestCase(new Ns3WimaxCsParamTlvTestCase, TestCase::QUICK);
232  AddTestCase(new Ns3WimaxSfTlvTestCase, TestCase::QUICK);
233 }
234 
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:43
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
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.
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.
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.
enum ServiceFlow::SchedulingType GetServiceSchedulingType() const
Get service scheduling type.
void SetTrafficPriority(uint8_t priority)
Set traffic priority.
void SetMinTolerableTrafficRate(uint32_t minJitter)
Set minimum tolerable traffic rate.
uint32_t GetMinTolerableTrafficRate() const
Get minimum tolerable traffic rate.
void SetServiceSchedulingType(enum ServiceFlow::SchedulingType schedType)
Set service scheduling type.
void SetMinReservedTrafficRate(uint32_t minResvRate)
Set minimum reserved traffic rate.
CsSpecification GetCsSpecification() const
Get CS specification.
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:305
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:252
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:281
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:275
void Add(const Tlv &val)
Add a TLV.
Definition: wimax-tlv.cc:287
#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