A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wimax-tlv-test.cc
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/abort.h"
24 #include "ns3/test.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/inet-socket-address.h"
27 #include "ns3/point-to-point-helper.h"
28 #include "ns3/internet-stack-helper.h"
29 #include "ns3/ipv4-address-helper.h"
30 #include "ns3/ipv4-header.h"
31 #include "ns3/packet-sink-helper.h"
32 #include "ns3/udp-client-server-helper.h"
33 #include "ns3/udp-header.h"
34 #include "ns3/simulator.h"
35 #include "ns3/wimax-helper.h"
36 #include "ns3/mobility-helper.h"
37 #include "ns3/global-route-manager.h"
38 #include "ns3/wimax-tlv.h"
39 #include "ns3/ipcs-classifier-record.h"
40 #include "ns3/service-flow.h"
41 #include <iostream>
42 
43 using namespace ns3;
44 
45 /*
46  * Test the wimax tlv implementation.
47  */
49 {
50 public:
52  virtual ~Ns3WimaxCsParamTlvTestCase ();
53 
54 private:
55  virtual void DoRun (void);
56 
57 };
58 
59 Ns3WimaxCsParamTlvTestCase::Ns3WimaxCsParamTlvTestCase ()
60  : TestCase ("Test the CS parameters tlv implementation.")
61 {
62 }
63 
64 Ns3WimaxCsParamTlvTestCase::~Ns3WimaxCsParamTlvTestCase ()
65 {
66 }
67 
68 void
70 {
71 
72  IpcsClassifierRecord classifier (Ipv4Address ("10.0.0.0"),
73  Ipv4Mask ("255.0.0.0"),
74  Ipv4Address ("11.0.0.0"),
75  Ipv4Mask ("255.0.0.0"),
76  1000,
77  1100,
78  3000,
79  3100,
80  17,
81  1);
82 
83  classifier.AddSrcAddr (Ipv4Address ("1.0.0.0"), Ipv4Mask ("255.0.0.0"));
84  classifier.AddDstAddr (Ipv4Address ("16.0.0.0"), Ipv4Mask ("255.0.0.0"));
85  classifier.AddProtocol (6);
86  classifier.AddSrcPortRange (1, 2);
87  classifier.AddDstPortRange (4000, 4100);
88  classifier.SetIndex (1);
89 
90  CsParameters csParam (CsParameters::ADD, classifier);
91 
92  SfVectorTlvValue sfVectorTlvValue;
93  sfVectorTlvValue.Add (csParam.ToTlv ());
94 
95  Tlv tlvSent (145, sfVectorTlvValue.GetSerializedSize (), sfVectorTlvValue);
96  Ptr<Packet> packet = Create<Packet> ();
97  packet->AddHeader (tlvSent);
98 
99  Tlv tlvReceived;
100  packet->RemoveHeader (tlvReceived);
101  if (tlvReceived.GetType () == Tlv::UPLINK_SERVICE_FLOW)
102  {
103  SfVectorTlvValue * sfVecValue =
104  (SfVectorTlvValue *) tlvReceived.PeekValue ();
105  for (std::vector<Tlv*>::const_iterator iter = sfVecValue->Begin (); iter
106  != sfVecValue->End (); ++iter)
107  {
108  if ((*iter)->GetType () == SfVectorTlvValue::IPV4_CS_Parameters)
109  {
110  CsParameters csParamsRecv (*(*iter));
111  IpcsClassifierRecord classifier =
112  csParamsRecv.GetPacketClassifierRule ();
113 
114  NS_TEST_ASSERT_MSG_EQ (!classifier.CheckMatch (Ipv4Address ("10.1.1.1"),
115  Ipv4Address ("16.1.1.1"),
116  1050,
117  3050,
118  17), false, "The classifier address did not match.");
119  NS_TEST_ASSERT_MSG_EQ (!classifier.CheckMatch (Ipv4Address ("10.1.5.1"),
120  Ipv4Address ("11.1.1.23"),
121  1070,
122  3040,
123  6), false, "The classifier address did not match.");
124  NS_TEST_ASSERT_MSG_EQ (classifier.CheckMatch (Ipv4Address ("11.1.1.1"),
125  Ipv4Address ("17.1.1.1"),
126  1050,
127  3050,
128  17), false, "The classifier addresses matched.");
129  NS_TEST_ASSERT_MSG_EQ (classifier.CheckMatch (Ipv4Address ("10.1.1.1"),
130  Ipv4Address ("16.1.1.1"),
131  1050,
132  3050,
133  8), false, "The classifier addresses matched.");
134  }
135  }
136  }
137 }
138 // ==============================================================================
139 
140 /*
141  * Test the service flow tlv implementation.
142  */
144 {
145 public:
147  virtual ~Ns3WimaxSfTlvTestCase ();
148 
149 private:
150  virtual void DoRun (void);
151 
152 };
153 
154 Ns3WimaxSfTlvTestCase::Ns3WimaxSfTlvTestCase ()
155  : TestCase ("Test the service flow tlv implementation.")
156 {
157 }
158 
159 Ns3WimaxSfTlvTestCase::~Ns3WimaxSfTlvTestCase ()
160 {
161 }
162 
163 void
165 {
167  CsParameters csParam (CsParameters::ADD, classifier);
168  ServiceFlow sf = ServiceFlow (ServiceFlow::SF_DIRECTION_DOWN);
169 
170  sf.SetSfid (100);
171  sf.SetConvergenceSublayerParam (csParam);
172  sf.SetCsSpecification (ServiceFlow::IPV4);
173  sf.SetServiceSchedulingType (ServiceFlow::SF_TYPE_UGS);
174  sf.SetMaxSustainedTrafficRate (1000000);
175  sf.SetMinReservedTrafficRate (1000000);
176  sf.SetMinTolerableTrafficRate (1000000);
177  sf.SetMaximumLatency (10);
178  sf.SetMaxTrafficBurst (1000);
179  sf.SetTrafficPriority (1);
180 
181  Ptr<Packet> packet = Create<Packet> ();
182  packet->AddHeader (sf.ToTlv ());
183 
184  Tlv tlvReceived;
185  packet->RemoveHeader (tlvReceived);
186 
187  ServiceFlow sfRecv = ServiceFlow (tlvReceived);
188 
189  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetDirection (), ServiceFlow::SF_DIRECTION_DOWN, "The sfRecv had the wrong direction.");
190  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetSfid (), 100, "The sfRecv had the wrong sfid.");
191  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetCsSpecification (), ServiceFlow::IPV4, "The sfRecv had the wrong cs specification.");
192  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetServiceSchedulingType (), ServiceFlow::SF_TYPE_UGS, "The sfRecv had the wrong service scheduling type.");
193  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMaxSustainedTrafficRate (), 1000000, "The sfRecv had the wrong maximum sustained traffic rate.");
194  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMinReservedTrafficRate (), 1000000, "The sfRecv had the wrong minimum reserved traffic rate.");
195  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMinTolerableTrafficRate (), 1000000, "The sfRecv had the wrong minimum tolerable traffic rate.");
196  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMaximumLatency (), 10, "The sfRecv had the wrong maximum latency.");
197  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetMaxTrafficBurst (), 1000, "The sfRecv had the wrong maximum traffic burst.");
198  NS_TEST_ASSERT_MSG_EQ (sfRecv.GetTrafficPriority (), 1, "The sfRecv had the wrong traffic priority.");
199 }
200 
201 // ==============================================================================
203 {
204 public:
206 };
207 
208 Ns3WimaxTlvTestSuite::Ns3WimaxTlvTestSuite ()
209  : TestSuite ("wimax-tlv", UNIT)
210 {
211  AddTestCase (new Ns3WimaxCsParamTlvTestCase, TestCase::QUICK);
212  AddTestCase (new Ns3WimaxSfTlvTestCase, TestCase::QUICK);
213 }
214 
215 static Ns3WimaxTlvTestSuite ns3WimaxTlvTestSuite;
uint32_t RemoveHeader(Header &header)
Definition: packet.cc:285
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:210
A suite of tests to run.
Definition: test.h:962
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
encapsulates test code
Definition: test.h:834
This class implements the Type-Len-Value structure channel encodings as described by "IEEE Standard f...
Definition: wimax-tlv.h:64
virtual void DoRun(void)
Implementation to actually run this test case.
void AddSrcAddr(Ipv4Address srcAddress, Ipv4Mask srcMask)
add a new source ip address to the classifier
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 test case.
Tlv ToTlv(void) const
creates a tlv from the classifier record
void AddDstAddr(Ipv4Address dstAddress, Ipv4Mask dstMask)
add a new destination ip address to the classifier
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
void AddDstPortRange(uint16_t dstPortLow, uint16_t dstPortHigh)
add a range of destination port to the classifier
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
void AddProtocol(uint8_t proto)
add a protocol to the classifier
void SetIndex(uint16_t index)
Set the index of the classifier.
Tlv ToTlv(void) const
creates a TLV from this service flow
IpcsClassifierRecord GetPacketClassifierRule(void) const
void AddHeader(const Header &header)
Definition: packet.cc:270