A Discrete-Event Network Simulator
API
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 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: Manuel Requena <manuel.requena@cttc.es>
19 */
20
21#include "ns3/log.h"
22
23#include "ns3/lte-rlc-header.h"
24
25namespace ns3 {
26
27NS_LOG_COMPONENT_DEFINE ("LteRlcHeader");
28
29NS_OBJECT_ENSURE_REGISTERED (LteRlcHeader);
30
32 : m_headerLength (0),
33 m_framingInfo (0xff),
34 m_sequenceNumber (0xfffa)
35{
36}
37
39{
41 m_framingInfo = 0xff;
42 m_sequenceNumber = 0xfffb;
43}
44
45void
46LteRlcHeader::SetFramingInfo (uint8_t framingInfo)
47{
48 m_framingInfo = framingInfo & 0x03;
49}
50
51void
53{
54 m_sequenceNumber = sequenceNumber;
55}
56
57uint8_t
59{
60 return m_framingInfo;
61}
62
65{
66 return m_sequenceNumber;
67}
68
69
70void
71LteRlcHeader::PushExtensionBit (uint8_t extensionBit)
72{
73 m_extensionBits.push_back (extensionBit);
74 if (m_extensionBits.size() == 1)
75 {
76 m_headerLength = 2; // Only fixed part
77 }
78 else if (m_extensionBits.size() % 2)
79 {
80 m_headerLength += 1;
81 }
82 else
83 {
84 m_headerLength += 2;
85 }
86}
87
88void
89LteRlcHeader::PushLengthIndicator (uint16_t lengthIndicator)
90{
91 m_lengthIndicators.push_back (lengthIndicator);
92}
93
94
95uint8_t
97{
98 uint8_t extensionBit = m_extensionBits.front ();
99 m_extensionBits.pop_front ();
100
101 return extensionBit;
102}
103
104uint16_t
106{
107 uint16_t lengthIndicator = m_lengthIndicators.front ();
108 m_lengthIndicators.pop_front ();
109
110 return lengthIndicator;
111}
112
113
114TypeId
116{
117 static TypeId tid = TypeId ("ns3::LteRlcHeader")
118 .SetParent<Header> ()
119 .SetGroupName("Lte")
120 .AddConstructor<LteRlcHeader> ()
121 ;
122 return tid;
123}
124
125TypeId
127{
128 return GetTypeId ();
129}
130
131void LteRlcHeader::Print (std::ostream &os) const
132{
133 std::list <uint8_t>::const_iterator it1 = m_extensionBits.begin ();
134 std::list <uint16_t>::const_iterator it2 = m_lengthIndicators.begin ();
135
136 os << "Len=" << m_headerLength;
137 os << " FI=" << (uint16_t)m_framingInfo;
138 os << " E=" << (uint16_t)(*it1);
139 os << " SN=" << m_sequenceNumber;
140
141 it1++;
142 if (it1 != m_extensionBits.end ())
143 {
144 os << " E=";
145 }
146 while ( it1 != m_extensionBits.end () )
147 {
148 os << (uint16_t)(*it1);
149 it1++;
150 }
151
152 if (it2 != m_lengthIndicators.end ())
153 {
154 os << " LI=";
155 }
156 while ( it2 != m_lengthIndicators.end () )
157 {
158 os << (uint16_t)(*it2) << " ";
159 it2++;
160 }
161}
162
164{
165 return m_headerLength;
166}
167
169{
171
172 std::list <uint8_t>::const_iterator it1 = m_extensionBits.begin ();
173 std::list <uint16_t>::const_iterator it2 = m_lengthIndicators.begin ();
174
175 i.WriteU8 ( ((m_framingInfo << 3) & 0x18) |
176 (((*it1) << 2) & 0x04) |
177 ((m_sequenceNumber.GetValue () >> 8) & 0x0003) );
178 i.WriteU8 ( m_sequenceNumber.GetValue () & 0x00FF );
179 it1++;
180
181 while ( it1 != m_extensionBits.end () &&
182 it2 != m_lengthIndicators.end () )
183 {
184 uint16_t oddLi, evenLi;
185 uint8_t oddE, evenE;
186
187 oddE = *it1;
188 oddLi = *it2;
189
190 it1++;
191 it2++;
192
193 if ( it1 != m_extensionBits.end () &&
194 it2 != m_lengthIndicators.end () )
195 {
196 evenE = *it1;
197 evenLi = *it2;
198
199 i.WriteU8 ( ((oddE << 7) & 0x80) | ((oddLi >> 4) & 0x007F) );
200 i.WriteU8 ( ((oddLi << 4) & 0x00F0) | ((evenE << 3) & 0x08) | ((evenLi >> 8) & 0x0007) );
201 i.WriteU8 ( evenLi & 0x00FF );
202
203 it1++;
204 it2++;
205 }
206 else
207 {
208 i.WriteU8 ( ((oddE << 7) & 0x80) | ((oddLi >> 4) & 0x007F) );
209 i.WriteU8 ( ((oddLi << 4) & 0x00F0) ); // Padding is implicit
210 }
211 }
212}
213
215{
217 uint8_t byte_1;
218 uint8_t byte_2;
219 uint8_t byte_3;
220 uint8_t extensionBit;
221
222 byte_1 = i.ReadU8 ();
223 byte_2 = i.ReadU8 ();
224 m_headerLength = 2;
225 m_framingInfo = (byte_1 & 0x18) >> 3;
226 m_sequenceNumber = ((byte_1 & 0x03) << 8) | byte_2;
227
228 extensionBit = (byte_1 & 0x04) >> 2;
229 m_extensionBits.push_back (extensionBit);
230
231 if (extensionBit == DATA_FIELD_FOLLOWS)
232 {
233 return GetSerializedSize ();
234 }
235
236 uint16_t oddLi, evenLi;
237 uint8_t oddE, evenE;
238 bool moreLiFields = (extensionBit == E_LI_FIELDS_FOLLOWS);
239
240 while (moreLiFields)
241 {
242 byte_1 = i.ReadU8 ();
243 byte_2 = i.ReadU8 ();
244
245 oddE = (byte_1 & 0x80) >> 7;
246 oddLi = ((byte_1 & 0x7F) << 4) | ((byte_2 & 0xF0) >> 4);
247 moreLiFields = (oddE == E_LI_FIELDS_FOLLOWS);
248
249 m_extensionBits.push_back (oddE);
250 m_lengthIndicators.push_back (oddLi);
251 m_headerLength += 2;
252
253 if (moreLiFields)
254 {
255 byte_3 = i.ReadU8 ();
256
257 evenE = (byte_2 & 0x08) >> 3;
258 evenLi = ((byte_2 & 0x07) << 8) | (byte_3 & 0xFF);
259 moreLiFields = (evenE == E_LI_FIELDS_FOLLOWS);
260
261 m_extensionBits.push_back (evenE);
262 m_lengthIndicators.push_back (evenLi);
263
264 m_headerLength += 1;
265 }
266 }
267
268 return GetSerializedSize ();
269}
270
271}; // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint8_t ReadU8(void)
Definition: buffer.h:1021
Protocol header serialization and deserialization.
Definition: header.h:43
The packet header for the Radio Link Control (RLC) protocol packets.
uint8_t m_framingInfo
2 bits
std::list< uint8_t > m_extensionBits
Includes extensionBit of the fixed part.
void PushExtensionBit(uint8_t extensionBit)
Push extension bit.
SequenceNumber10 m_sequenceNumber
sequence number
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
SequenceNumber10 GetSequenceNumber() const
Get sequence number.
static TypeId GetTypeId(void)
Get the type ID.
uint8_t PopExtensionBit(void)
Pop extension bit.
uint16_t m_headerLength
header length
void SetSequenceNumber(SequenceNumber10 sequenceNumber)
Set sequence number.
virtual uint32_t Deserialize(Buffer::Iterator start)
void SetFramingInfo(uint8_t framingInfo)
Set framing info.
std::list< uint16_t > m_lengthIndicators
length indicators
uint16_t PopLengthIndicator(void)
Pop length indicator.
virtual void Serialize(Buffer::Iterator start) const
LteRlcHeader()
Constructor.
virtual uint32_t GetSerializedSize(void) const
virtual void Print(std::ostream &os) const
uint8_t GetFramingInfo() const
Get framing info.
void PushLengthIndicator(uint16_t lengthIndicator)
Push length indicator.
SequenceNumber10 class.
uint16_t GetValue() const
Extracts the numeric value of the sequence number.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1852