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  ;
31 
33  : m_headerLength (0),
34  m_framingInfo (0xff),
35  m_sequenceNumber (0xfffa)
36 {
37 }
38 
40 {
41  m_headerLength = 0;
42  m_framingInfo = 0xff;
43  m_sequenceNumber = 0xfffb;
44 }
45 
46 void
47 LteRlcHeader::SetFramingInfo (uint8_t framingInfo)
48 {
49  m_framingInfo = framingInfo & 0x03;
50 }
51 
52 void
54 {
55  m_sequenceNumber = sequenceNumber;
56 }
57 
58 uint8_t
60 {
61  return m_framingInfo;
62 }
63 
66 {
67  return m_sequenceNumber;
68 }
69 
70 
71 void
72 LteRlcHeader::PushExtensionBit (uint8_t extensionBit)
73 {
74  m_extensionBits.push_back (extensionBit);
75  if (m_extensionBits.size() == 1)
76  {
77  m_headerLength = 2; // Only fixed part
78  }
79  else if (m_extensionBits.size() % 2)
80  {
81  m_headerLength += 1;
82  }
83  else
84  {
85  m_headerLength += 2;
86  }
87 }
88 
89 void
90 LteRlcHeader::PushLengthIndicator (uint16_t lengthIndicator)
91 {
92  m_lengthIndicators.push_back (lengthIndicator);
93 }
94 
95 
96 uint8_t
98 {
99  uint8_t extensionBit = m_extensionBits.front ();
100  m_extensionBits.pop_front ();
101 
102  return extensionBit;
103 }
104 
105 uint16_t
107 {
108  uint16_t lengthIndicator = m_lengthIndicators.front ();
109  m_lengthIndicators.pop_front ();
110 
111  return lengthIndicator;
112 }
113 
114 
115 TypeId
117 {
118  static TypeId tid = TypeId ("ns3::LteRlcHeader")
119  .SetParent<Header> ()
120  .AddConstructor<LteRlcHeader> ()
121  ;
122  return tid;
123 }
124 
125 TypeId
127 {
128  return GetTypeId ();
129 }
130 
131 void 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 
163 uint32_t LteRlcHeader::GetSerializedSize (void) const
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
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.
std::list< uint8_t > m_extensionBits
virtual uint32_t Deserialize(Buffer::Iterator start)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual uint32_t GetSerializedSize(void) const
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
NS_LOG_COMPONENT_DEFINE("LteRlcHeader")
SequenceNumber10 GetSequenceNumber() const
void SetFramingInfo(uint8_t framingInfo)
void WriteU8(uint8_t data)
Definition: buffer.h:690
uint8_t GetFramingInfo() const
uint8_t ReadU8(void)
Definition: buffer.h:819
LteRlcHeader()
Constructor.
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
static TypeId GetTypeId(void)