A Discrete-Event Network Simulator
API
test-lte-rlc-header.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011, 2012, 2013 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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  * Author: Lluis Parcerisa <lparcerisa@cttc.cat> (TestUtils from test-asn1-encoding.cc)
19  * Nicola Baldo <nbaldo@cttc.es> (actual test)
20  */
21 
22 #include "ns3/log.h"
23 #include "ns3/test.h"
24 #include "ns3/ptr.h"
25 #include "ns3/packet.h"
26 
27 #include "ns3/lte-rlc-am-header.h"
28 
29 #include <list>
30 #include <bitset>
31 #include <iomanip>
32 
33 
34 NS_LOG_COMPONENT_DEFINE ("TestLteRlcHeader");
35 
36 namespace ns3 {
37 
44 class TestUtils
45 {
46 public:
52  static std::string sprintPacketContentsHex (Ptr<Packet> pkt)
53  {
54  uint32_t psize = pkt->GetSize ();
55  uint8_t buffer[psize];
56  std::ostringstream oss (std::ostringstream::out);
57  pkt->CopyData (buffer, psize);
58  for (uint32_t i = 0; i < psize; i++)
59  {
60  oss << std::setfill ('0') << std::setw (2) << std::hex << (uint32_t) buffer[i];
61  }
62  return oss.str ();
63  }
64 
70  static std::string sprintPacketContentsBin (Ptr<Packet> pkt)
71  {
72  uint32_t psize = pkt->GetSize ();
73  uint8_t buffer[psize];
74  std::ostringstream oss (std::ostringstream::out);
75  pkt->CopyData (buffer, psize);
76  for (uint32_t i = 0; i < psize; i++)
77  {
78  oss << (std::bitset<8> (buffer[i]));
79  }
80  return std::string (oss.str () + "\n");
81  }
82 
87  static void LogPacketContents (Ptr<Packet> pkt)
88  {
89  NS_LOG_DEBUG ("---- SERIALIZED PACKET CONTENTS (HEX): -------");
92  }
93 
99  template <class T>
100  static void LogPacketInfo (T source,std::string s)
101  {
102  NS_LOG_DEBUG ("--------- " << s.data () << " INFO: -------");
103  std::ostringstream oss (std::ostringstream::out);
104  source.Print (oss);
105  NS_LOG_DEBUG (oss.str ());
106  }
107 };
108 
109 
117 {
118 public:
127  std::list<SequenceNumber10> nackSnList,
128  std::string hex);
129 
130 protected:
131  virtual void DoRun (void);
132 
134  std::list<SequenceNumber10> m_nackSnList;
135  std::string m_hex;
136 
137 };
138 
139 
141  std::list<SequenceNumber10> nackSnList ,
142  std::string hex)
143  : TestCase (hex),
144  m_ackSn (ackSn),
145  m_nackSnList (nackSnList),
146  m_hex (hex)
147 {
148  NS_LOG_FUNCTION (this << hex);
149 }
150 
151 void
152 
154 {
155  NS_LOG_FUNCTION (this);
156 
157  Ptr<Packet> p = Create<Packet> ();
158  LteRlcAmHeader h;
160  h.SetAckSn (m_ackSn);
161  for (std::list<SequenceNumber10>::iterator it = m_nackSnList.begin ();
162  it != m_nackSnList.end ();
163  ++it)
164  {
165  h.PushNack (it->GetValue ());
166  }
167  p->AddHeader (h);
168 
170  std::string hex = TestUtils::sprintPacketContentsHex (p);
171  NS_TEST_ASSERT_MSG_EQ (m_hex, hex, "serialized packet content " << hex << " differs from test vector " << m_hex);
172 
173  LteRlcAmHeader h2;
174  p->RemoveHeader (h2);
175  SequenceNumber10 ackSn = h2.GetAckSn ();
176  NS_TEST_ASSERT_MSG_EQ (ackSn, m_ackSn, "deserialized ACK SN differs from test vector");
177 
178  for (std::list<SequenceNumber10>::iterator it = m_nackSnList.begin ();
179  it != m_nackSnList.end ();
180  ++it)
181  {
182  int nackSn = h2.PopNack ();
183  NS_TEST_ASSERT_MSG_GT (nackSn, -1, "not enough elements in deserialized NACK list");
184  NS_TEST_ASSERT_MSG_EQ (nackSn, it->GetValue (), "deserialized NACK SN differs from test vector");
185  }
186  int retVal = h2.PopNack ();
187  NS_TEST_ASSERT_MSG_LT (retVal, 0, "too many elements in deserialized NACK list");
188 }
189 
190 
198 {
199 public:
202 
204  : TestSuite ("lte-rlc-header", UNIT)
205 {
206  NS_LOG_FUNCTION (this);
207 
208  {
209  SequenceNumber10 ackSn (8);
210  std::list<SequenceNumber10> nackSnList;
211  std::string hex ("0020");
212  AddTestCase (new RlcAmStatusPduTestCase (ackSn, nackSnList, hex), TestCase::QUICK);
213  }
214 
215  {
216  SequenceNumber10 ackSn (873);
217  std::list<SequenceNumber10> nackSnList;
218  std::string hex ("0da4");
219  AddTestCase (new RlcAmStatusPduTestCase (ackSn, nackSnList, hex), TestCase::QUICK);
220  }
221 
222  {
223  SequenceNumber10 ackSn (2);
224  std::list<SequenceNumber10> nackSnList;
225  nackSnList.push_back (SequenceNumber10 (873));
226  std::string hex ("000bb480");
227  AddTestCase (new RlcAmStatusPduTestCase (ackSn, nackSnList, hex), TestCase::QUICK);
228  }
229 
230 
231  {
232  SequenceNumber10 ackSn (2);
233  std::list<SequenceNumber10> nackSnList;
234  nackSnList.push_back (SequenceNumber10 (1021));
235  nackSnList.push_back (SequenceNumber10 (754));
236  std::string hex ("000bfed790");
237  AddTestCase (new RlcAmStatusPduTestCase (ackSn, nackSnList, hex), TestCase::QUICK);
238  }
239 
240 
241  {
242  SequenceNumber10 ackSn (2);
243  std::list<SequenceNumber10> nackSnList;
244  nackSnList.push_back (SequenceNumber10 (1021));
245  nackSnList.push_back (SequenceNumber10 (754));
246  nackSnList.push_back (SequenceNumber10 (947));
247  std::string hex ("000bfed795d980");
248  AddTestCase (new RlcAmStatusPduTestCase (ackSn, nackSnList, hex), TestCase::QUICK);
249  }
250 
251 
252  {
253  SequenceNumber10 ackSn (2);
254  std::list<SequenceNumber10> nackSnList;
255  nackSnList.push_back (SequenceNumber10 (1021));
256  nackSnList.push_back (SequenceNumber10 (754));
257  nackSnList.push_back (SequenceNumber10 (947));
258  nackSnList.push_back (SequenceNumber10 (347));
259  std::string hex ("000bfed795d9cad8");
260  AddTestCase (new RlcAmStatusPduTestCase (ackSn, nackSnList, hex), TestCase::QUICK);
261  }
262 
263 }
264 
265 
266 } // namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Rlc Am Status Pdu Test Case.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
Lte Rlc Header Test Suite.
ns3::LteRlcHeaderTestSuite staticLteRlcHeaderTestSuiteInstance
the test suite
A suite of tests to run.
Definition: test.h:1343
static void LogPacketContents(Ptr< Packet > pkt)
Function to log packet contents.
static void LogPacketInfo(T source, std::string s)
Log packet info function.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
encapsulates test code
Definition: test.h:1153
static std::string sprintPacketContentsHex(Ptr< Packet > pkt)
Function to convert packet contents in hex format.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
#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
void SetControlPdu(uint8_t controlPduType)
Set control PDU function.
The packet header for the AM Radio Link Control (RLC) protocol packets.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
RlcAmStatusPduTestCase(SequenceNumber10 ackSn, std::list< SequenceNumber10 > nackSnList, std::string hex)
Constructor.
SequenceNumber10 m_ackSn
ack sequence number
Fast test.
Definition: test.h:1159
SequenceNumber10 GetAckSn() const
Get ack sn function.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
int PopNack(void)
Retrieve one NACK from the CONTROL PDU.
virtual void DoRun(void)
Implementation to actually run this TestCase.
SequenceNumber10 class.
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition: test.h:995
static std::string sprintPacketContentsBin(Ptr< Packet > pkt)
Function to convert packet contents in binary format.
std::list< SequenceNumber10 > m_nackSnList
list of nack sequence numbers
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
Definition: test.h:809
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
std::string m_hex
hex string