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 
ns3::IpcsClassifierRecord::AddDstAddr
void AddDstAddr(Ipv4Address dstAddress, Ipv4Mask dstMask)
add a new destination ip address to the classifier
Definition: ipcs-classifier-record.cc:161
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Ns3WimaxTlvTestSuite::Ns3WimaxTlvTestSuite
Ns3WimaxTlvTestSuite()
Definition: wimax-tlv-test.cc:207
Ns3WimaxCsParamTlvTestCase::Ns3WimaxCsParamTlvTestCase
Ns3WimaxCsParamTlvTestCase()
Definition: wimax-tlv-test.cc:51
ns3::ServiceFlow::GetMinReservedTrafficRate
uint32_t GetMinReservedTrafficRate(void) const
Get minimum reserved traffic rate.
Definition: service-flow.cc:359
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ServiceFlow::GetMaxTrafficBurst
uint32_t GetMaxTrafficBurst(void) const
Get max traffic burst.
Definition: service-flow.cc:354
ns3::VectorTlvValue::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Get serialized size in bytes.
Definition: wimax-tlv.cc:251
ns3::IpcsClassifierRecord::AddSrcAddr
void AddSrcAddr(Ipv4Address srcAddress, Ipv4Mask srcMask)
add a new source ip address to the classifier
Definition: ipcs-classifier-record.cc:153
ns3::ServiceFlow::SetServiceSchedulingType
void SetServiceSchedulingType(enum ServiceFlow::SchedulingType schedType)
Set service scheduling type.
Definition: service-flow.cc:525
ns3::IpcsClassifierRecord::AddSrcPortRange
void AddSrcPortRange(uint16_t srcPortLow, uint16_t srcPortHigh)
add a range of source port to the classifier
Definition: ipcs-classifier-record.cc:169
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::ServiceFlow::SetMaxSustainedTrafficRate
void SetMaxSustainedTrafficRate(uint32_t maxSustainedRate)
Set max sustained traffic rate.
Definition: service-flow.cc:505
ns3::ServiceFlow::SetMaximumLatency
void SetMaximumLatency(uint32_t MaximumLatency)
Set maximum latency.
Definition: service-flow.cc:540
Ns3WimaxSfTlvTestCase
Test the service flow tlv implementation.
Definition: wimax-tlv-test.cc:138
ns3::Tlv::GetType
uint8_t GetType(void) const
Get type value.
Definition: wimax-tlv.cc:214
ns3::CsParameters
CsParameters class.
Definition: cs-parameters.h:36
Ns3WimaxCsParamTlvTestCase
Test the wimax tlv implementation.
Definition: wimax-tlv-test.cc:41
ns3::TestCase
encapsulates test code
Definition: test.h:1154
ns3::ServiceFlow::GetMaxSustainedTrafficRate
uint32_t GetMaxSustainedTrafficRate(void) const
Get max sustained traffic rate.
Definition: service-flow.cc:349
ns3::Ptr< Packet >
ns3::VectorTlvValue::Begin
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:272
Ns3WimaxSfTlvTestCase::Ns3WimaxSfTlvTestCase
Ns3WimaxSfTlvTestCase()
Definition: wimax-tlv-test.cc:148
Ns3WimaxCsParamTlvTestCase::~Ns3WimaxCsParamTlvTestCase
virtual ~Ns3WimaxCsParamTlvTestCase()
Definition: wimax-tlv-test.cc:56
ns3::ServiceFlow::SetConvergenceSublayerParam
void SetConvergenceSublayerParam(CsParameters csparam)
Set convergence sublayer parameters.
Definition: service-flow.cc:610
ns3::CsParameters::ToTlv
Tlv ToTlv(void) const
creates a tlv from the classifier record
Definition: cs-parameters.cc:88
ns3::IpcsClassifierRecord::SetIndex
void SetIndex(uint16_t index)
Set the index of the classifier.
Definition: ipcs-classifier-record.cc:201
Ns3WimaxSfTlvTestCase::~Ns3WimaxSfTlvTestCase
virtual ~Ns3WimaxSfTlvTestCase()
Definition: wimax-tlv-test.cc:153
ns3::IPV4
@ IPV4
Definition: packetbb.h:46
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
ns3::ServiceFlow::GetMaximumLatency
uint32_t GetMaximumLatency(void) const
Get maximum latency.
Definition: service-flow.cc:384
Ns3WimaxSfTlvTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: wimax-tlv-test.cc:158
ns3WimaxTlvTestSuite
static Ns3WimaxTlvTestSuite ns3WimaxTlvTestSuite
the test suite
Definition: wimax-tlv-test.cc:214
ns3::ServiceFlow::ToTlv
Tlv ToTlv(void) const
creates a TLV from this service flow
Definition: service-flow.cc:804
ns3::VectorTlvValue::Add
void Add(const Tlv &val)
Add a TLV.
Definition: wimax-tlv.cc:284
ns3::IpcsClassifierRecord::CheckMatch
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
Definition: ipcs-classifier-record.cc:296
ns3::Tlv
This class implements the Type-Len-Value structure channel encodings as described by "IEEE Standard f...
Definition: wimax-tlv.h:84
ns3::SfVectorTlvValue
SfVectorTlvValue class.
Definition: wimax-tlv.h:329
ns3::ServiceFlow::SetMinReservedTrafficRate
void SetMinReservedTrafficRate(uint32_t minResvRate)
Set minimum reserved traffic rate.
Definition: service-flow.cc:515
ns3::ServiceFlow::GetDirection
enum Direction GetDirection(void) const
Get direction.
Definition: service-flow.cc:197
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
ns3::ServiceFlow::SetSfid
void SetSfid(uint32_t sfid)
Set SFID.
Definition: service-flow.cc:485
Ns3WimaxTlvTestSuite
Ns3 Wimax Tlv Test Suite.
Definition: wimax-tlv-test.cc:202
NS_TEST_ASSERT_MSG_EQ
#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:166
ns3::CsParameters::GetPacketClassifierRule
IpcsClassifierRecord GetPacketClassifierRule(void) const
Definition: cs-parameters.cc:83
ns3::ServiceFlow::SetMinTolerableTrafficRate
void SetMinTolerableTrafficRate(uint32_t minJitter)
Set minimum tolerable traffic rate.
Definition: service-flow.cc:520
ns3::ServiceFlow::SetTrafficPriority
void SetTrafficPriority(uint8_t priority)
Set traffic priority.
Definition: service-flow.cc:500
ns3::ServiceFlow::SetCsSpecification
void SetCsSpecification(enum CsSpecification spec)
Set CS specification.
Definition: service-flow.cc:605
ns3::ServiceFlow::GetTrafficPriority
uint8_t GetTrafficPriority(void) const
Get traffic priority.
Definition: service-flow.cc:344
ns3::Tlv::PeekValue
TlvValue * PeekValue(void)
Peek value.
Definition: wimax-tlv.cc:224
ns3::ServiceFlow::GetCsSpecification
enum CsSpecification GetCsSpecification(void) const
Get CS specification.
Definition: service-flow.cc:450
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:256
ns3::IpcsClassifierRecord::AddProtocol
void AddProtocol(uint8_t proto)
add a protocol to the classifier
Definition: ipcs-classifier-record.cc:186
ns3::ServiceFlow
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:40
ns3::ServiceFlow::GetMinTolerableTrafficRate
uint32_t GetMinTolerableTrafficRate(void) const
Get minimum tolerable traffic rate.
Definition: service-flow.cc:364
ns3::ServiceFlow::GetSfid
uint32_t GetSfid(void) const
Get SFID.
Definition: service-flow.cc:320
ns3::IpcsClassifierRecord::AddDstPortRange
void AddDstPortRange(uint16_t dstPortLow, uint16_t dstPortHigh)
add a range of destination port to the classifier
Definition: ipcs-classifier-record.cc:178
ns3::VectorTlvValue::End
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:278
ns3::ServiceFlow::SetMaxTrafficBurst
void SetMaxTrafficBurst(uint32_t maxTrafficBurst)
Set maximum traffic burst.
Definition: service-flow.cc:510
ns3::ServiceFlow::GetServiceSchedulingType
enum ServiceFlow::SchedulingType GetServiceSchedulingType(void) const
Get service scheduling type.
Definition: service-flow.cc:369
Ns3WimaxCsParamTlvTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: wimax-tlv-test.cc:61
ns3::IpcsClassifierRecord
IpcsClassifierRecord class.
Definition: ipcs-classifier-record.h:36