A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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#include <vector>
31
32NS_LOG_COMPONENT_DEFINE("TestLteRlcHeader");
33
34namespace ns3
35{
36
37/**
38 * \ingroup lte-test
39 *
40 * \brief Test Utils
41 */
43{
44 public:
45 /**
46 * Function to convert packet contents in hex format
47 * \param pkt the packet
48 * \returns a text string
49 */
50 static std::string sprintPacketContentsHex(Ptr<Packet> pkt)
51 {
52 std::vector<uint8_t> buffer(pkt->GetSize());
53 std::ostringstream oss(std::ostringstream::out);
54 pkt->CopyData(buffer.data(), buffer.size());
55 for (auto b : buffer)
56 {
57 oss << std::setfill('0') << std::setw(2) << std::hex << (uint32_t)b;
58 }
59 return oss.str();
60 }
61
62 /**
63 * Function to convert packet contents in binary format
64 * \param pkt the packet
65 * \returns a text string
66 */
67 static std::string sprintPacketContentsBin(Ptr<Packet> pkt)
68 {
69 std::vector<uint8_t> buffer(pkt->GetSize());
70 std::ostringstream oss(std::ostringstream::out);
71 pkt->CopyData(buffer.data(), buffer.size());
72 for (auto b : buffer)
73 {
74 oss << (std::bitset<8>(b));
75 }
76 return std::string(oss.str() + "\n");
77 }
78
79 /**
80 * Function to log packet contents
81 * \param pkt the packet
82 */
84 {
85 NS_LOG_DEBUG("---- SERIALIZED PACKET CONTENTS (HEX): -------");
88 }
89
90 /**
91 * Log packet info function
92 * \param source T
93 * \param s text string to log
94 */
95 template <class T>
96 static void LogPacketInfo(T source, std::string s)
97 {
98 NS_LOG_DEBUG("--------- " << s.data() << " INFO: -------");
99 std::ostringstream oss(std::ostringstream::out);
100 source.Print(oss);
101 NS_LOG_DEBUG(oss.str());
102 }
103};
104
105/**
106 * \ingroup lte-test
107 *
108 * \brief Rlc Am Status Pdu Test Case
109 */
111{
112 public:
113 /**
114 * Constructor
115 *
116 * \param ackSn the sequence number
117 * \param nackSnList list of nack sequence numbers
118 * \param hex string
119 */
121 std::list<SequenceNumber10> nackSnList,
122 std::string hex);
123
124 protected:
125 void DoRun() override;
126
127 SequenceNumber10 m_ackSn; ///< ack sequence number
128 std::list<SequenceNumber10> m_nackSnList; ///< list of nack sequence numbers
129 std::string m_hex; ///< hex string
130};
131
133 std::list<SequenceNumber10> nackSnList,
134 std::string hex)
135 : TestCase(hex),
136 m_ackSn(ackSn),
137 m_nackSnList(nackSnList),
138 m_hex(hex)
139{
140 NS_LOG_FUNCTION(this << hex);
141}
142
143void
144
146{
147 NS_LOG_FUNCTION(this);
148
149 Ptr<Packet> p = Create<Packet>();
152 h.SetAckSn(m_ackSn);
153 for (auto it = m_nackSnList.begin(); it != m_nackSnList.end(); ++it)
154 {
155 h.PushNack(it->GetValue());
156 }
157 p->AddHeader(h);
158
160 std::string hex = TestUtils::sprintPacketContentsHex(p);
162 hex,
163 "serialized packet content " << hex << " differs from test vector "
164 << m_hex);
165
167 p->RemoveHeader(h2);
168 SequenceNumber10 ackSn = h2.GetAckSn();
169 NS_TEST_ASSERT_MSG_EQ(ackSn, m_ackSn, "deserialized ACK SN differs from test vector");
170
171 for (auto it = m_nackSnList.begin(); it != m_nackSnList.end(); ++it)
172 {
173 int nackSn = h2.PopNack();
174 NS_TEST_ASSERT_MSG_GT(nackSn, -1, "not enough elements in deserialized NACK list");
176 it->GetValue(),
177 "deserialized NACK SN differs from test vector");
178 }
179 int retVal = h2.PopNack();
180 NS_TEST_ASSERT_MSG_LT(retVal, 0, "too many elements in deserialized NACK list");
181}
182
183/**
184 * \ingroup lte-test
185 *
186 * \brief Lte Rlc Header Test Suite
187 */
189{
190 public:
193
195 : TestSuite("lte-rlc-header", Type::UNIT)
196{
197 NS_LOG_FUNCTION(this);
198
199 {
200 SequenceNumber10 ackSn(8);
201 std::list<SequenceNumber10> nackSnList;
202 std::string hex("0020");
204 }
205
206 {
207 SequenceNumber10 ackSn(873);
208 std::list<SequenceNumber10> nackSnList;
209 std::string hex("0da4");
211 }
212
213 {
214 SequenceNumber10 ackSn(2);
215 const std::list<SequenceNumber10> nackSnList{
216 SequenceNumber10(873),
217 };
218 std::string hex("000bb480");
220 }
221
222 {
223 SequenceNumber10 ackSn(2);
224 const std::list<SequenceNumber10> nackSnList{
225 SequenceNumber10(1021),
226 SequenceNumber10(754),
227 };
228 std::string hex("000bfed790");
230 }
231
232 {
233 SequenceNumber10 ackSn(2);
234 const std::list<SequenceNumber10> nackSnList{
235 SequenceNumber10(1021),
236 SequenceNumber10(754),
237 SequenceNumber10(947),
238 };
239 std::string hex("000bfed795d980");
241 }
242
243 {
244 SequenceNumber10 ackSn(2);
245 const std::list<SequenceNumber10> nackSnList{
246 SequenceNumber10(1021),
247 SequenceNumber10(754),
248 SequenceNumber10(947),
249 SequenceNumber10(347),
250 };
251 std::string hex("000bfed795d9cad8");
253 }
254}
255
256} // 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.
static constexpr uint8_t STATUS_PDU
Control PDU type status.
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
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:710
#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:145
#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:875
Every class exported by the ns3 library is enclosed in the ns3 namespace.