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 
34 /*
35  * Test the wimax tlv implementation.
36  */
38 {
39 public:
41  virtual ~Ns3WimaxCsParamTlvTestCase ();
42 
43 private:
44  virtual void DoRun (void);
45 
46 };
47 
49  : TestCase ("Test the CS parameters tlv implementation.")
50 {
51 }
52 
54 {
55 }
56 
57 void
59 {
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 =
93  (SfVectorTlvValue *) tlvReceived.PeekValue ();
94  for (std::vector<Tlv*>::const_iterator iter = sfVecValue->Begin (); iter
95  != sfVecValue->End (); ++iter)
96  {
97  if ((*iter)->GetType () == SfVectorTlvValue::IPV4_CS_Parameters)
98  {
99  CsParameters csParamsRecv (*(*iter));
100  IpcsClassifierRecord classifier =
101  csParamsRecv.GetPacketClassifierRule ();
102 
103  NS_TEST_ASSERT_MSG_EQ (!classifier.CheckMatch (Ipv4Address ("10.1.1.1"),
104  Ipv4Address ("16.1.1.1"),
105  1050,
106  3050,
107  17), false, "The classifier address did not match.");
108  NS_TEST_ASSERT_MSG_EQ (!classifier.CheckMatch (Ipv4Address ("10.1.5.1"),
109  Ipv4Address ("11.1.1.23"),
110  1070,
111  3040,
112  6), false, "The classifier address did not match.");
113  NS_TEST_ASSERT_MSG_EQ (classifier.CheckMatch (Ipv4Address ("11.1.1.1"),
114  Ipv4Address ("17.1.1.1"),
115  1050,
116  3050,
117  17), false, "The classifier addresses matched.");
118  NS_TEST_ASSERT_MSG_EQ (classifier.CheckMatch (Ipv4Address ("10.1.1.1"),
119  Ipv4Address ("16.1.1.1"),
120  1050,
121  3050,
122  8), false, "The classifier addresses matched.");
123  }
124  }
125  }
126 }
127 // ==============================================================================
128 
129 /*
130  * Test the service flow tlv implementation.
131  */
133 {
134 public:
136  virtual ~Ns3WimaxSfTlvTestCase ();
137 
138 private:
139  virtual void DoRun (void);
140 
141 };
142 
144  : TestCase ("Test the service flow tlv implementation.")
145 {
146 }
147 
149 {
150 }
151 
152 void
154 {
156  CsParameters csParam (CsParameters::ADD, classifier);
157  ServiceFlow sf = ServiceFlow (ServiceFlow::SF_DIRECTION_DOWN);
158 
159  sf.SetSfid (100);
160  sf.SetConvergenceSublayerParam (csParam);
162  sf.SetServiceSchedulingType (ServiceFlow::SF_TYPE_UGS);
163  sf.SetMaxSustainedTrafficRate (1000000);
164  sf.SetMinReservedTrafficRate (1000000);
165  sf.SetMinTolerableTrafficRate (1000000);
166  sf.SetMaximumLatency (10);
167  sf.SetMaxTrafficBurst (1000);
168  sf.SetTrafficPriority (1);
169 
170  Ptr<Packet> packet = Create<Packet> ();
171  packet->AddHeader (sf.ToTlv ());
172 
173  Tlv tlvReceived;
174  packet->RemoveHeader (tlvReceived);
175 
176  ServiceFlow sfRecv = ServiceFlow (tlvReceived);
177 
178  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetDirection (), ServiceFlow::SF_DIRECTION_DOWN, "The sfRecv had the wrong direction.");
179  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetSfid (), 100, "The sfRecv had the wrong sfid.");
180  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetCsSpecification (), ServiceFlow::IPV4, "The sfRecv had the wrong cs specification.");
181  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetServiceSchedulingType (), ServiceFlow::SF_TYPE_UGS, "The sfRecv had the wrong service scheduling type.");
182  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMaxSustainedTrafficRate (), 1000000, "The sfRecv had the wrong maximum sustained traffic rate.");
183  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMinReservedTrafficRate (), 1000000, "The sfRecv had the wrong minimum reserved traffic rate.");
184  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMinTolerableTrafficRate (), 1000000, "The sfRecv had the wrong minimum tolerable traffic rate.");
185  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMaximumLatency (), 10, "The sfRecv had the wrong maximum latency.");
186  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMaxTrafficBurst (), 1000, "The sfRecv had the wrong maximum traffic burst.");
187  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetTrafficPriority (), 1, "The sfRecv had the wrong traffic priority.");
188 }
189 
190 // ==============================================================================
192 {
193 public:
195 };
196 
198  : TestSuite ("wimax-tlv", UNIT)
199 {
200  AddTestCase (new Ns3WimaxCsParamTlvTestCase, TestCase::QUICK);
201  AddTestCase (new Ns3WimaxSfTlvTestCase, TestCase::QUICK);
202 }
203 
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
uint32_t GetMinTolerableTrafficRate(void) const
void SetMaxSustainedTrafficRate(uint32_t)
uint32_t GetMaxTrafficBurst(void) const
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
A suite of tests to run.
Definition: test.h:1333
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
uint32_t GetSfid(void) const
virtual uint32_t GetSerializedSize(void) const
Definition: wimax-tlv.cc:251
static Ns3WimaxTlvTestSuite ns3WimaxTlvTestSuite
encapsulates test code
Definition: test.h:1147
void SetMinReservedTrafficRate(uint32_t)
This class implements the Type-Len-Value structure channel encodings as described by "IEEE Standard f...
Definition: wimax-tlv.h:64
void SetServiceSchedulingType(enum ServiceFlow::SchedulingType)
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t GetMinReservedTrafficRate(void) const
void Add(const Tlv &val)
Definition: wimax-tlv.cc:284
void SetMaxTrafficBurst(uint32_t)
void AddSrcAddr(Ipv4Address srcAddress, Ipv4Mask srcMask)
add a new source ip address to the classifier
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
#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:161
void AddSrcPortRange(uint16_t srcPortLow, uint16_t srcPortHigh)
add a range of source port to the classifier
virtual void DoRun(void)
Implementation to actually run this TestCase.
Tlv ToTlv(void) const
creates a tlv from the classifier record
enum CsSpecification GetCsSpecification(void) const
void AddDstAddr(Ipv4Address dstAddress, Ipv4Mask dstMask)
add a new destination ip address to the classifier
uint8_t GetType(void) const
Definition: wimax-tlv.cc:214
uint32_t GetMaximumLatency(void) const
void SetTrafficPriority(uint8_t)
void SetConvergenceSublayerParam(CsParameters)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t GetTrafficPriority(void) const
TlvValue * PeekValue(void)
Definition: wimax-tlv.cc:224
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:39
void SetMaximumLatency(uint32_t)
void AddDstPortRange(uint16_t dstPortLow, uint16_t dstPortHigh)
add a range of destination port to the classifier
virtual ~Ns3WimaxSfTlvTestCase()
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
enum Direction GetDirection(void) const
void SetMinTolerableTrafficRate(uint32_t)
void AddProtocol(uint8_t proto)
add a protocol to the classifier
Iterator Begin() const
Definition: wimax-tlv.cc:272
void SetIndex(uint16_t index)
Set the index of the classifier.
uint32_t GetMaxSustainedTrafficRate(void) const
void SetSfid(uint32_t)
Tlv ToTlv(void) const
creates a TLV from this service flow
void SetCsSpecification(enum CsSpecification)
IpcsClassifierRecord GetPacketClassifierRule(void) const
enum ServiceFlow::SchedulingType GetServiceSchedulingType(void) const
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:257
Iterator End() const
Definition: wimax-tlv.cc:278