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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Lluis Parcerisa <lparcerisa@cttc.cat> (TestUtils from test-asn1-encoding.cc)
7 * Nicola Baldo <nbaldo@cttc.es> (actual test)
8 */
9
10#include "ns3/log.h"
11#include "ns3/lte-rlc-am-header.h"
12#include "ns3/packet.h"
13#include "ns3/ptr.h"
14#include "ns3/test.h"
15
16#include <bitset>
17#include <iomanip>
18#include <list>
19#include <vector>
20
21NS_LOG_COMPONENT_DEFINE("TestLteRlcHeader");
22
23namespace ns3
24{
25
26/**
27 * @ingroup lte-test
28 *
29 * @brief Test Utils
30 */
32{
33 public:
34 /**
35 * Function to convert packet contents in hex format
36 * @param pkt the packet
37 * @returns a text string
38 */
39 static std::string sprintPacketContentsHex(Ptr<Packet> pkt)
40 {
41 std::vector<uint8_t> buffer(pkt->GetSize());
42 std::ostringstream oss(std::ostringstream::out);
43 pkt->CopyData(buffer.data(), buffer.size());
44 for (auto b : buffer)
45 {
46 oss << std::setfill('0') << std::setw(2) << std::hex << (uint32_t)b;
47 }
48 return oss.str();
49 }
50
51 /**
52 * Function to convert packet contents in binary format
53 * @param pkt the packet
54 * @returns a text string
55 */
56 static std::string sprintPacketContentsBin(Ptr<Packet> pkt)
57 {
58 std::vector<uint8_t> buffer(pkt->GetSize());
59 std::ostringstream oss(std::ostringstream::out);
60 pkt->CopyData(buffer.data(), buffer.size());
61 for (auto b : buffer)
62 {
64 }
65 return std::string(oss.str() + "\n");
66 }
67
68 /**
69 * Function to log packet contents
70 * @param pkt the packet
71 */
73 {
74 NS_LOG_DEBUG("---- SERIALIZED PACKET CONTENTS (HEX): -------");
77 }
78
79 /**
80 * Log packet info function
81 * @param source T
82 * @param s text string to log
83 */
84 template <class T>
85 static void LogPacketInfo(T source, std::string s)
86 {
87 NS_LOG_DEBUG("--------- " << s.data() << " INFO: -------");
88 std::ostringstream oss(std::ostringstream::out);
89 source.Print(oss);
90 NS_LOG_DEBUG(oss.str());
91 }
92};
93
94/**
95 * @ingroup lte-test
96 *
97 * @brief Rlc Am Status Pdu Test Case
98 */
100{
101 public:
102 /**
103 * Constructor
104 *
105 * @param ackSn the sequence number
106 * @param nackSnList list of nack sequence numbers
107 * @param hex string
108 */
110 std::list<SequenceNumber10> nackSnList,
111 std::string hex);
112
113 protected:
114 void DoRun() override;
115
116 SequenceNumber10 m_ackSn; ///< ack sequence number
117 std::list<SequenceNumber10> m_nackSnList; ///< list of nack sequence numbers
118 std::string m_hex; ///< hex string
119};
120
122 std::list<SequenceNumber10> nackSnList,
123 std::string hex)
124 : TestCase(hex),
125 m_ackSn(ackSn),
126 m_nackSnList(nackSnList),
127 m_hex(hex)
128{
129 NS_LOG_FUNCTION(this << hex);
130}
131
132void
133
135{
136 NS_LOG_FUNCTION(this);
137
141 h.SetAckSn(m_ackSn);
142 for (auto it = m_nackSnList.begin(); it != m_nackSnList.end(); ++it)
143 {
144 h.PushNack(it->GetValue());
145 }
146 p->AddHeader(h);
147
151 hex,
152 "serialized packet content " << hex << " differs from test vector "
153 << m_hex);
154
156 p->RemoveHeader(h2);
157 SequenceNumber10 ackSn = h2.GetAckSn();
158 NS_TEST_ASSERT_MSG_EQ(ackSn, m_ackSn, "deserialized ACK SN differs from test vector");
159
160 for (auto it = m_nackSnList.begin(); it != m_nackSnList.end(); ++it)
161 {
162 int nackSn = h2.PopNack();
163 NS_TEST_ASSERT_MSG_GT(nackSn, -1, "not enough elements in deserialized NACK list");
165 it->GetValue(),
166 "deserialized NACK SN differs from test vector");
167 }
168 int retVal = h2.PopNack();
169 NS_TEST_ASSERT_MSG_LT(retVal, 0, "too many elements in deserialized NACK list");
170}
171
172/**
173 * @ingroup lte-test
174 *
175 * @brief Lte Rlc Header Test Suite
176 */
178{
179 public:
182
184 : TestSuite("lte-rlc-header", Type::UNIT)
185{
186 NS_LOG_FUNCTION(this);
187
188 {
190 std::list<SequenceNumber10> nackSnList;
191 std::string hex("0020");
193 }
194
195 {
197 std::list<SequenceNumber10> nackSnList;
198 std::string hex("0da4");
200 }
201
202 {
204 const std::list<SequenceNumber10> nackSnList{
205 SequenceNumber10(873),
206 };
207 std::string hex("000bb480");
209 }
210
211 {
213 const std::list<SequenceNumber10> nackSnList{
214 SequenceNumber10(1021),
215 SequenceNumber10(754),
216 };
217 std::string hex("000bfed790");
219 }
220
221 {
223 const std::list<SequenceNumber10> nackSnList{
224 SequenceNumber10(1021),
225 SequenceNumber10(754),
226 SequenceNumber10(947),
227 };
228 std::string hex("000bfed795d980");
230 }
231
232 {
234 const std::list<SequenceNumber10> nackSnList{
235 SequenceNumber10(1021),
236 SequenceNumber10(754),
237 SequenceNumber10(947),
238 SequenceNumber10(347),
239 };
240 std::string hex("000bfed795d9cad8");
242 }
243}
244
245} // namespace ns3
The packet header for the AM Radio Link Control (RLC) protocol packets.
static constexpr uint8_t STATUS_PDU
Control PDU type status.
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:66
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:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
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:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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:699
#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:134
#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:864
Every class exported by the ns3 library is enclosed in the ns3 namespace.