A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
25 NS_LOG_COMPONENT_DEFINE ("LteRlcHeader");
26 
27 namespace ns3 {
28 
29 NS_OBJECT_ENSURE_REGISTERED (LteRlcHeader);
30 
32  : m_headerLength (0),
33  m_framingInfo (0xff),
34  m_sequenceNumber (0xfffa)
35 {
36 }
37 
39 {
40  m_headerLength = 0;
41  m_framingInfo = 0xff;
42  m_sequenceNumber = 0xfffb;
43 }
44 
45 void
46 LteRlcHeader::SetFramingInfo (uint8_t framingInfo)
47 {
48  m_framingInfo = framingInfo & 0x03;
49 }
50 
51 void
53 {
54  m_sequenceNumber = sequenceNumber;
55 }
56 
57 uint8_t
59 {
60  return m_framingInfo;
61 }
62 
65 {
66  return m_sequenceNumber;
67 }
68 
69 
70 void
71 LteRlcHeader::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 
88 void
89 LteRlcHeader::PushLengthIndicator (uint16_t lengthIndicator)
90 {
91  m_lengthIndicators.push_back (lengthIndicator);
92 }
93 
94 
95 uint8_t
97 {
98  uint8_t extensionBit = m_extensionBits.front ();
99  m_extensionBits.pop_front ();
100 
101  return extensionBit;
102 }
103 
104 uint16_t
106 {
107  uint16_t lengthIndicator = m_lengthIndicators.front ();
108  m_lengthIndicators.pop_front ();
109 
110  return lengthIndicator;
111 }
112 
113 
114 TypeId
116 {
117  static TypeId tid = TypeId ("ns3::LteRlcHeader")
118  .SetParent<Header> ()
119  .AddConstructor<LteRlcHeader> ()
120  ;
121  return tid;
122 }
123 
124 TypeId
126 {
127  return GetTypeId ();
128 }
129 
130 void LteRlcHeader::Print (std::ostream &os) const
131 {
132  std::list <uint8_t>::const_iterator it1 = m_extensionBits.begin ();
133  std::list <uint16_t>::const_iterator it2 = m_lengthIndicators.begin ();
134 
135  os << "Len=" << m_headerLength;
136  os << " FI=" << (uint16_t)m_framingInfo;
137  os << " E=" << (uint16_t)(*it1);
138  os << " SN=" << m_sequenceNumber;
139 
140  it1++;
141  if (it1 != m_extensionBits.end ())
142  {
143  os << " E=";
144  }
145  while ( it1 != m_extensionBits.end () )
146  {
147  os << (uint16_t)(*it1);
148  it1++;
149  }
150 
151  if (it2 != m_lengthIndicators.end ())
152  {
153  os << " LI=";
154  }
155  while ( it2 != m_lengthIndicators.end () )
156  {
157  os << (uint16_t)(*it2) << " ";
158  it2++;
159  }
160 }
161 
162 uint32_t LteRlcHeader::GetSerializedSize (void) const
163 {
164  return m_headerLength;
165 }
166 
168 {
170 
171  std::list <uint8_t>::const_iterator it1 = m_extensionBits.begin ();
172  std::list <uint16_t>::const_iterator it2 = m_lengthIndicators.begin ();
173 
174  i.WriteU8 ( ((m_framingInfo << 3) & 0x18) |
175  (((*it1) << 2) & 0x04) |
176  ((m_sequenceNumber.GetValue () >> 8) & 0x0003) );
177  i.WriteU8 ( m_sequenceNumber.GetValue () & 0x00FF );
178  it1++;
179 
180  while ( it1 != m_extensionBits.end () &&
181  it2 != m_lengthIndicators.end () )
182  {
183  uint16_t oddLi, evenLi;
184  uint8_t oddE, evenE;
185 
186  oddE = *it1;
187  oddLi = *it2;
188 
189  it1++;
190  it2++;
191 
192  if ( it1 != m_extensionBits.end () &&
193  it2 != m_lengthIndicators.end () )
194  {
195  evenE = *it1;
196  evenLi = *it2;
197 
198  i.WriteU8 ( ((oddE << 7) & 0x80) | ((oddLi >> 4) & 0x007F) );
199  i.WriteU8 ( ((oddLi << 4) & 0x00F0) | ((evenE << 3) & 0x08) | ((evenLi >> 8) & 0x0007) );
200  i.WriteU8 ( evenLi & 0x00FF );
201 
202  it1++;
203  it2++;
204  }
205  else
206  {
207  i.WriteU8 ( ((oddE << 7) & 0x80) | ((oddLi >> 4) & 0x007F) );
208  i.WriteU8 ( ((oddLi << 4) & 0x00F0) ); // Padding is implicit
209  }
210  }
211 }
212 
214 {
216  uint8_t byte_1;
217  uint8_t byte_2;
218  uint8_t byte_3;
219  uint8_t extensionBit;
220 
221  byte_1 = i.ReadU8 ();
222  byte_2 = i.ReadU8 ();
223  m_headerLength = 2;
224  m_framingInfo = (byte_1 & 0x18) >> 3;
225  m_sequenceNumber = ((byte_1 & 0x03) << 8) | byte_2;
226 
227  extensionBit = (byte_1 & 0x04) >> 2;
228  m_extensionBits.push_back (extensionBit);
229 
230  if (extensionBit == DATA_FIELD_FOLLOWS)
231  {
232  return GetSerializedSize ();
233  }
234 
235  uint16_t oddLi, evenLi;
236  uint8_t oddE, evenE;
237  bool moreLiFields = (extensionBit == E_LI_FIELDS_FOLLOWS);
238 
239  while (moreLiFields)
240  {
241  byte_1 = i.ReadU8 ();
242  byte_2 = i.ReadU8 ();
243 
244  oddE = (byte_1 & 0x80) >> 7;
245  oddLi = ((byte_1 & 0x7F) << 4) | ((byte_2 & 0xF0) >> 4);
246  moreLiFields = (oddE == E_LI_FIELDS_FOLLOWS);
247 
248  m_extensionBits.push_back (oddE);
249  m_lengthIndicators.push_back (oddLi);
250  m_headerLength += 2;
251 
252  if (moreLiFields)
253  {
254  byte_3 = i.ReadU8 ();
255 
256  evenE = (byte_2 & 0x08) >> 3;
257  evenLi = ((byte_2 & 0x07) << 8) | (byte_3 & 0xFF);
258  moreLiFields = (evenE == E_LI_FIELDS_FOLLOWS);
259 
260  m_extensionBits.push_back (evenE);
261  m_lengthIndicators.push_back (evenLi);
262 
263  m_headerLength += 1;
264  }
265  }
266 
267  return GetSerializedSize ();
268 }
269 
270 }; // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
std::list< uint16_t > m_lengthIndicators
uint16_t GetValue() const
Extracts the numeric value of the sequence number.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
std::list< uint8_t > m_extensionBits
virtual uint32_t Deserialize(Buffer::Iterator start)
virtual uint32_t GetSerializedSize(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
void PushLengthIndicator(uint16_t lengthIndicator)
uint8_t PopExtensionBit(void)
virtual void Print(std::ostream &os) const
iterator in a Buffer instance
Definition: buffer.h:98
virtual void Serialize(Buffer::Iterator start) const
uint16_t PopLengthIndicator(void)
void SetSequenceNumber(SequenceNumber10 sequenceNumber)
uint16_t m_headerLength
SequenceNumber10 m_sequenceNumber
void PushExtensionBit(uint8_t extensionBit)
virtual TypeId GetInstanceTypeId(void) const
SequenceNumber10 GetSequenceNumber() const
void SetFramingInfo(uint8_t framingInfo)
void WriteU8(uint8_t data)
Definition: buffer.h:876
uint8_t GetFramingInfo() const
uint8_t ReadU8(void)
Definition: buffer.h:1028
LteRlcHeader()
Constructor.
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
static TypeId GetTypeId(void)