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
42{
43 public:
49 static std::string sprintPacketContentsHex(Ptr<Packet> pkt)
50 {
51 uint32_t psize = pkt->GetSize();
52 uint8_t buffer[psize];
53 std::ostringstream oss(std::ostringstream::out);
54 pkt->CopyData(buffer, psize);
55 for (uint32_t i = 0; i < psize; i++)
56 {
57 oss << std::setfill('0') << std::setw(2) << std::hex << (uint32_t)buffer[i];
58 }
59 return oss.str();
60 }
61
67 static std::string sprintPacketContentsBin(Ptr<Packet> pkt)
68 {
69 uint32_t psize = pkt->GetSize();
70 uint8_t buffer[psize];
71 std::ostringstream oss(std::ostringstream::out);
72 pkt->CopyData(buffer, psize);
73 for (uint32_t i = 0; i < psize; i++)
74 {
75 oss << (std::bitset<8>(buffer[i]));
76 }
77 return std::string(oss.str() + "\n");
78 }
79
85 {
86 NS_LOG_DEBUG("---- SERIALIZED PACKET CONTENTS (HEX): -------");
89 }
90
96 template <class T>
97 static void LogPacketInfo(T source, std::string s)
98 {
99 NS_LOG_DEBUG("--------- " << s.data() << " INFO: -------");
100 std::ostringstream oss(std::ostringstream::out);
101 source.Print(oss);
102 NS_LOG_DEBUG(oss.str());
103 }
104};
105
112{
113 public:
122 std::list<SequenceNumber10> nackSnList,
123 std::string hex);
124
125 protected:
126 void DoRun() override;
127
129 std::list<SequenceNumber10> m_nackSnList;
130 std::string m_hex;
131};
132
134 std::list<SequenceNumber10> nackSnList,
135 std::string hex)
136 : TestCase(hex),
137 m_ackSn(ackSn),
138 m_nackSnList(nackSnList),
139 m_hex(hex)
140{
141 NS_LOG_FUNCTION(this << hex);
142}
143
144void
145
147{
148 NS_LOG_FUNCTION(this);
149
150 Ptr<Packet> p = Create<Packet>();
153 h.SetAckSn(m_ackSn);
154 for (std::list<SequenceNumber10>::iterator it = m_nackSnList.begin(); it != m_nackSnList.end();
155 ++it)
156 {
157 h.PushNack(it->GetValue());
158 }
159 p->AddHeader(h);
160
162 std::string hex = TestUtils::sprintPacketContentsHex(p);
164 hex,
165 "serialized packet content " << hex << " differs from test vector "
166 << m_hex);
167
169 p->RemoveHeader(h2);
170 SequenceNumber10 ackSn = h2.GetAckSn();
171 NS_TEST_ASSERT_MSG_EQ(ackSn, m_ackSn, "deserialized ACK SN differs from test vector");
172
173 for (std::list<SequenceNumber10>::iterator it = m_nackSnList.begin(); it != m_nackSnList.end();
174 ++it)
175 {
176 int nackSn = h2.PopNack();
177 NS_TEST_ASSERT_MSG_GT(nackSn, -1, "not enough elements in deserialized NACK list");
179 it->GetValue(),
180 "deserialized NACK SN differs from test vector");
181 }
182 int retVal = h2.PopNack();
183 NS_TEST_ASSERT_MSG_LT(retVal, 0, "too many elements in deserialized NACK list");
184}
185
192{
193 public:
196
198 : TestSuite("lte-rlc-header", UNIT)
199{
200 NS_LOG_FUNCTION(this);
201
202 {
203 SequenceNumber10 ackSn(8);
204 std::list<SequenceNumber10> nackSnList;
205 std::string hex("0020");
206 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
207 }
208
209 {
210 SequenceNumber10 ackSn(873);
211 std::list<SequenceNumber10> nackSnList;
212 std::string hex("0da4");
213 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
214 }
215
216 {
217 SequenceNumber10 ackSn(2);
218 const std::list<SequenceNumber10> nackSnList{
219 SequenceNumber10(873),
220 };
221 std::string hex("000bb480");
222 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
223 }
224
225 {
226 SequenceNumber10 ackSn(2);
227 const std::list<SequenceNumber10> nackSnList{
228 SequenceNumber10(1021),
229 SequenceNumber10(754),
230 };
231 std::string hex("000bfed790");
232 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
233 }
234
235 {
236 SequenceNumber10 ackSn(2);
237 const std::list<SequenceNumber10> nackSnList{
238 SequenceNumber10(1021),
239 SequenceNumber10(754),
240 SequenceNumber10(947),
241 };
242 std::string hex("000bfed795d980");
243 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
244 }
245
246 {
247 SequenceNumber10 ackSn(2);
248 const std::list<SequenceNumber10> nackSnList{
249 SequenceNumber10(1021),
250 SequenceNumber10(754),
251 SequenceNumber10(947),
252 SequenceNumber10(347),
253 };
254 std::string hex("000bfed795d9cad8");
255 AddTestCase(new RlcAmStatusPduTestCase(ackSn, nackSnList, hex), TestCase::QUICK);
256 }
257}
258
259} // 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:862
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 ",...
ns3::LteRlcHeaderTestSuite staticLteRlcHeaderTestSuiteInstance
the test suite
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.