A Discrete-Event Network Simulator
API
wimax-tlv-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 INRIA, UDcast
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  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19  * <amine.ismail@udcast.com>
20  *
21  */
22 #include "ns3/log.h"
23 #include "ns3/test.h"
24 #include "ns3/ipcs-classifier-record.h"
25 #include "ns3/ptr.h"
26 #include "ns3/packet.h"
27 #include "ns3/wimax-helper.h"
28 #include "ns3/wimax-tlv.h"
29 #include "ns3/service-flow.h"
30 #include "ns3/cs-parameters.h"
31 
32 using namespace ns3;
33 
41 {
42 public:
44  virtual ~Ns3WimaxCsParamTlvTestCase ();
45 
46 private:
47  virtual void DoRun (void);
48 
49 };
50 
52  : TestCase ("Test the CS parameters tlv implementation.")
53 {
54 }
55 
57 {
58 }
59 
60 void
62 {
63 
64  IpcsClassifierRecord classifier (Ipv4Address ("10.0.0.0"),
65  Ipv4Mask ("255.0.0.0"),
66  Ipv4Address ("11.0.0.0"),
67  Ipv4Mask ("255.0.0.0"),
68  1000,
69  1100,
70  3000,
71  3100,
72  17,
73  1);
74 
75  classifier.AddSrcAddr (Ipv4Address ("1.0.0.0"), Ipv4Mask ("255.0.0.0"));
76  classifier.AddDstAddr (Ipv4Address ("16.0.0.0"), Ipv4Mask ("255.0.0.0"));
77  classifier.AddProtocol (6);
78  classifier.AddSrcPortRange (1, 2);
79  classifier.AddDstPortRange (4000, 4100);
80  classifier.SetIndex (1);
81 
82  CsParameters csParam (CsParameters::ADD, classifier);
83 
84  SfVectorTlvValue sfVectorTlvValue;
85  sfVectorTlvValue.Add (csParam.ToTlv ());
86 
87  Tlv tlvSent (145, sfVectorTlvValue.GetSerializedSize (), sfVectorTlvValue);
88  Ptr<Packet> packet = Create<Packet> ();
89  packet->AddHeader (tlvSent);
90 
91  Tlv tlvReceived;
92  packet->RemoveHeader (tlvReceived);
93  if (tlvReceived.GetType () == Tlv::UPLINK_SERVICE_FLOW)
94  {
95  SfVectorTlvValue * sfVecValue =
96  (SfVectorTlvValue *) tlvReceived.PeekValue ();
97  for (std::vector<Tlv*>::const_iterator iter = sfVecValue->Begin (); iter
98  != sfVecValue->End (); ++iter)
99  {
100  if ((*iter)->GetType () == SfVectorTlvValue::IPV4_CS_Parameters)
101  {
102  CsParameters csParamsRecv (*(*iter));
103  IpcsClassifierRecord classifier =
104  csParamsRecv.GetPacketClassifierRule ();
105 
106  NS_TEST_ASSERT_MSG_EQ (!classifier.CheckMatch (Ipv4Address ("10.1.1.1"),
107  Ipv4Address ("16.1.1.1"),
108  1050,
109  3050,
110  17), false, "The classifier address did not match.");
111  NS_TEST_ASSERT_MSG_EQ (!classifier.CheckMatch (Ipv4Address ("10.1.5.1"),
112  Ipv4Address ("11.1.1.23"),
113  1070,
114  3040,
115  6), false, "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), false, "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), false, "The classifier addresses matched.");
126  }
127  }
128  }
129 }
130 
138 {
139 public:
141  virtual ~Ns3WimaxSfTlvTestCase ();
142 
143 private:
144  virtual void DoRun (void);
145 
146 };
147 
149  : TestCase ("Test the service flow tlv implementation.")
150 {
151 }
152 
154 {
155 }
156 
157 void
159 {
161  CsParameters csParam (CsParameters::ADD, classifier);
162  ServiceFlow sf = ServiceFlow (ServiceFlow::SF_DIRECTION_DOWN);
163 
164  sf.SetSfid (100);
165  sf.SetConvergenceSublayerParam (csParam);
167  sf.SetServiceSchedulingType (ServiceFlow::SF_TYPE_UGS);
168  sf.SetMaxSustainedTrafficRate (1000000);
169  sf.SetMinReservedTrafficRate (1000000);
170  sf.SetMinTolerableTrafficRate (1000000);
171  sf.SetMaximumLatency (10);
172  sf.SetMaxTrafficBurst (1000);
173  sf.SetTrafficPriority (1);
174 
175  Ptr<Packet> packet = Create<Packet> ();
176  packet->AddHeader (sf.ToTlv ());
177 
178  Tlv tlvReceived;
179  packet->RemoveHeader (tlvReceived);
180 
181  ServiceFlow sfRecv = ServiceFlow (tlvReceived);
182 
183  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetDirection (), ServiceFlow::SF_DIRECTION_DOWN, "The sfRecv had the wrong direction.");
184  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetSfid (), 100, "The sfRecv had the wrong sfid.");
185  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetCsSpecification (), ServiceFlow::IPV4, "The sfRecv had the wrong cs specification.");
186  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetServiceSchedulingType (), ServiceFlow::SF_TYPE_UGS, "The sfRecv had the wrong service scheduling type.");
187  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMaxSustainedTrafficRate (), 1000000, "The sfRecv had the wrong maximum sustained traffic rate.");
188  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMinReservedTrafficRate (), 1000000, "The sfRecv had the wrong minimum reserved traffic rate.");
189  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMinTolerableTrafficRate (), 1000000, "The sfRecv had the wrong minimum tolerable traffic rate.");
190  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMaximumLatency (), 10, "The sfRecv had the wrong maximum latency.");
191  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMaxTrafficBurst (), 1000, "The sfRecv had the wrong maximum traffic burst.");
192  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetTrafficPriority (), 1, "The sfRecv had the wrong traffic priority.");
193 }
194 
202 {
203 public:
205 };
206 
208  : TestSuite ("wimax-tlv", UNIT)
209 {
210  AddTestCase (new Ns3WimaxCsParamTlvTestCase, TestCase::QUICK);
211  AddTestCase (new Ns3WimaxSfTlvTestCase, TestCase::QUICK);
212 }
213 
Test the wimax tlv implementation.
uint32_t GetMaxSustainedTrafficRate(void) const
Get max sustained traffic rate.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
Tlv ToTlv(void) const
creates a TLV from this service flow
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:263
A suite of tests to run.
Definition: test.h:1342
SfVectorTlvValue class.
Definition: wimax-tlv.h:328
Test the service flow tlv implementation.
uint32_t GetMinTolerableTrafficRate(void) const
Get minimum tolerable traffic rate.
uint32_t GetMaximumLatency(void) const
Get maximum latency.
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:278
static Ns3WimaxTlvTestSuite ns3WimaxTlvTestSuite
the test suite
encapsulates test code
Definition: test.h:1155
uint8_t GetTrafficPriority(void) const
Get traffic priority.
virtual uint32_t GetSerializedSize(void) const
Get serialized size in bytes.
Definition: wimax-tlv.cc:251
uint32_t GetSfid(void) const
Get SFID.
This class implements the Type-Len-Value structure channel encodings as described by "IEEE Standard f...
Definition: wimax-tlv.h:83
IpcsClassifierRecord class.
void SetMinReservedTrafficRate(uint32_t minResvRate)
Set minimum reserved traffic rate.
enum ServiceFlow::SchedulingType GetServiceSchedulingType(void) const
Get service scheduling type.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Add(const Tlv &val)
Add a TLV.
Definition: wimax-tlv.cc:284
CsParameters class.
Definition: cs-parameters.h:35
void AddSrcAddr(Ipv4Address srcAddress, Ipv4Mask srcMask)
add a new source ip address to the classifier
IpcsClassifierRecord GetPacketClassifierRule(void) const
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:272
#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:168
void AddSrcPortRange(uint16_t srcPortLow, uint16_t srcPortHigh)
add a range of source port to the classifier
uint8_t GetType(void) const
Get type value.
Definition: wimax-tlv.cc:214
virtual void DoRun(void)
Implementation to actually run this TestCase.
void AddDstAddr(Ipv4Address dstAddress, Ipv4Mask dstMask)
add a new destination ip address to the classifier
enum CsSpecification GetCsSpecification(void) const
Get CS specification.
void SetMaximumLatency(uint32_t MaximumLatency)
Set maximum latency.
uint32_t GetMaxTrafficBurst(void) const
Get max traffic burst.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetConvergenceSublayerParam(CsParameters csparam)
Set convergence sublayer parameters.
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
Ns3 Wimax Tlv Test Suite.
TlvValue * PeekValue(void)
Peek value.
Definition: wimax-tlv.cc:224
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:39
uint32_t GetMinReservedTrafficRate(void) const
Get minimum reserved traffic rate.
void AddDstPortRange(uint16_t dstPortLow, uint16_t dstPortHigh)
add a range of destination port to the classifier
virtual ~Ns3WimaxSfTlvTestCase()
void SetMinTolerableTrafficRate(uint32_t minJitter)
Set minimum tolerable traffic rate.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
void AddProtocol(uint8_t proto)
add a protocol to the classifier
void SetIndex(uint16_t index)
Set the index of the classifier.
void SetMaxTrafficBurst(uint32_t maxTrafficBurst)
Set maximum traffic burst.
void SetSfid(uint32_t sfid)
Set SFID.
void SetTrafficPriority(uint8_t priority)
Set traffic priority.
void SetCsSpecification(enum CsSpecification spec)
Set CS specification.
void SetMaxSustainedTrafficRate(uint32_t maxSustainedRate)
Set max sustained traffic rate.
Tlv ToTlv(void) const
creates a tlv from the classifier record
enum Direction GetDirection(void) const
Get direction.
void SetServiceSchedulingType(enum ServiceFlow::SchedulingType schedType)
Set service scheduling type.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256