A Discrete-Event Network Simulator
API
test-lte-rlc-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011, 2012, 2013 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Lluis Parcerisa <lparcerisa@cttc.cat> (TestUtils from test-asn1-encoding.cc)
18 * Nicola Baldo <nbaldo@cttc.es> (actual test)
19 */
20
21#include "ns3/log.h"
22#include "ns3/lte-rlc-am-header.h"
23#include "ns3/packet.h"
24#include "ns3/ptr.h"
25#include "ns3/test.h"
26
27#include <bitset>
28#include <iomanip>
29#include <list>
30
31NS_LOG_COMPONENT_DEFINE("TestLteRlcHeader");
32
33namespace ns3
34{
35
43{
44 public:
50 static std::string sprintPacketContentsHex(Ptr<Packet> pkt)
51 {
52 uint32_t psize = pkt->GetSize();
53 uint8_t buffer[psize];
54 std::ostringstream oss(std::ostringstream::out);
55 pkt->CopyData(buffer, psize);
56 for (uint32_t i = 0; i < psize; i++)
57 {
58 oss << std::setfill('0') << std::setw(2) << std::hex << (uint32_t)buffer[i];
59 }
60 return oss.str();
61 }
62
68 static std::string sprintPacketContentsBin(Ptr<Packet> pkt)
69 {
70 uint32_t psize = pkt->GetSize();
71 uint8_t buffer[psize];
72 std::ostringstream oss(std::ostringstream::out);
73 pkt->CopyData(buffer, psize);
74 for (uint32_t i = 0; i < psize; i++)
75 {
76 oss << (std::bitset<8>(buffer[i]));
77 }
78 return std::string(oss.str() + "\n");
79 }
80
86 {
87 NS_LOG_DEBUG("---- SERIALIZED PACKET CONTENTS (HEX): -------");
90 }
91
97 template <class T>
98 static void LogPacketInfo(T source, std::string s)
99 {
100 NS_LOG_DEBUG("--------- " << s.data() << " INFO: -------");
101 std::ostringstream oss(std::ostringstream::out);
102 source.Print(oss);
103 NS_LOG_DEBUG(oss.str());
104 }
105};
106
114{
115 public:
124 std::list<SequenceNumber10> nackSnList,
125 std::string hex);
126
127 protected:
128 void DoRun() override;
129
131 std::list<SequenceNumber10> m_nackSnList;
132 std::string m_hex;
133};
134
136 std::list<SequenceNumber10> nackSnList,
137 std::string hex)
138 : TestCase(hex),
139 m_ackSn(ackSn),
140 m_nackSnList(nackSnList),
141 m_hex(hex)
142{
143 NS_LOG_FUNCTION(this << hex);
144}
145
146void
147
149{
150 NS_LOG_FUNCTION(this);
151
152 Ptr<Packet> p = Create<Packet>();
155 h.SetAckSn(m_ackSn);
156 for (std::list<SequenceNumber10>::iterator it = m_nackSnList.begin(); it != m_nackSnList.end();
157 ++it)
158 {
159 h.PushNack(it->GetValue());
160 }
161 p->AddHeader(h);
162
164 std::string hex = TestUtils::sprintPacketContentsHex(p);
166 hex,
167 "serialized packet content " << hex << " differs from test vector "
168 << m_hex);
169
171 p->RemoveHeader(h2);
172 SequenceNumber10 ackSn = h2.GetAckSn();
173 NS_TEST_ASSERT_MSG_EQ(ackSn, m_ackSn, "deserialized ACK SN differs from test vector");
174
175 for (std::list<SequenceNumber10>::iterator it = m_nackSnList.begin(); it != m_nackSnList.end();
176 ++it)
177 {
178 int nackSn = h2.PopNack();
179 NS_TEST_ASSERT_MSG_GT(nackSn, -1, "not enough elements in deserialized NACK list");
181 it->GetValue(),
182 "deserialized NACK SN differs from test vector");
183 }
184 int retVal = h2.PopNack();
185 NS_TEST_ASSERT_MSG_LT(retVal, 0, "too many elements in deserialized NACK list");
186}
187
195{
196 public:
199
201 : TestSuite("lte-rlc-header", UNIT)
202{
203 NS_LOG_FUNCTION(this);
204
205 {
206 SequenceNumber10 ackSn(8);
207 std::list<SequenceNumber10> nackSnList;
208 std::string hex("0020");
209 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
210 }
211
212 {
213 SequenceNumber10 ackSn(873);
214 std::list<SequenceNumber10> nackSnList;
215 std::string hex("0da4");
216 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
217 }
218
219 {
220 SequenceNumber10 ackSn(2);
221 const std::list<SequenceNumber10> nackSnList{
222 SequenceNumber10(873),
223 };
224 std::string hex("000bb480");
225 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
226 }
227
228 {
229 SequenceNumber10 ackSn(2);
230 const std::list<SequenceNumber10> nackSnList{
231 SequenceNumber10(1021),
232 SequenceNumber10(754),
233 };
234 std::string hex("000bfed790");
235 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
236 }
237
238 {
239 SequenceNumber10 ackSn(2);
240 const std::list<SequenceNumber10> nackSnList{
241 SequenceNumber10(1021),
242 SequenceNumber10(754),
243 SequenceNumber10(947),
244 };
245 std::string hex("000bfed795d980");
246 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
247 }
248
249 {
250 SequenceNumber10 ackSn(2);
251 const std::list<SequenceNumber10> nackSnList{
252 SequenceNumber10(1021),
253 SequenceNumber10(754),
254 SequenceNumber10(947),
255 SequenceNumber10(347),
256 };
257 std::string hex("000bfed795d9cad8");
258 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
259 }
260}
261
262} // namespace ns3
The packet header for the AM Radio Link Control (RLC) protocol packets.
SequenceNumber10 GetAckSn() const
Get ack sn function.
void PushNack(int nack)
Add one more NACK to the CONTROL PDU.
void SetAckSn(SequenceNumber10 ackSn)
Set ack sn function.
int PopNack()
Retrieve one NACK from the CONTROL PDU.
void SetControlPdu(uint8_t controlPduType)
Set control PDU function.
Lte Rlc Header Test Suite.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:294
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:863
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:400
Rlc Am Status Pdu Test Case.
std::list< SequenceNumber10 > m_nackSnList
list of nack sequence numbers
void DoRun() override
Implementation to actually run this TestCase.
RlcAmStatusPduTestCase(SequenceNumber10 ackSn, std::list< SequenceNumber10 > nackSnList, std::string hex)
Constructor.
SequenceNumber10 m_ackSn
ack sequence number
SequenceNumber10 class.
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
static std::string sprintPacketContentsBin(Ptr< Packet > pkt)
Function to convert packet contents in binary format.
static std::string sprintPacketContentsHex(Ptr< Packet > pkt)
Function to convert packet contents in hex format.
static void LogPacketInfo(T source, std::string s)
Log packet info function.
static void LogPacketContents(Ptr< Packet > pkt)
Function to log packet contents.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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:709
#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:144
#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:874
ns3::LteRlcHeaderTestSuite staticLteRlcHeaderTestSuiteInstance
the test suite
Every class exported by the ns3 library is enclosed in the ns3 namespace.