A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-pdcp-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-pdcp-header.h"
24 
25 NS_LOG_COMPONENT_DEFINE ("LtePdcpHeader");
26 
27 namespace ns3 {
28 
29 NS_OBJECT_ENSURE_REGISTERED (LtePdcpHeader)
30  ;
31 
33  : m_dcBit (0xff),
34  m_sequenceNumber (0xfffa)
35 {
36 }
37 
39 {
40  m_dcBit = 0xff;
41  m_sequenceNumber = 0xfffb;
42 }
43 
44 void
45 LtePdcpHeader::SetDcBit (uint8_t dcBit)
46 {
47  m_dcBit = dcBit & 0x01;
48 }
49 
50 void
51 LtePdcpHeader::SetSequenceNumber (uint16_t sequenceNumber)
52 {
53  m_sequenceNumber = sequenceNumber & 0x0FFF;
54 }
55 
56 uint8_t
58 {
59  return m_dcBit;
60 }
61 
62 uint16_t
64 {
65  return m_sequenceNumber;
66 }
67 
68 
69 TypeId
71 {
72  static TypeId tid = TypeId ("ns3::LtePdcpHeader")
73  .SetParent<Header> ()
74  .AddConstructor<LtePdcpHeader> ()
75  ;
76  return tid;
77 }
78 
79 TypeId
81 {
82  return GetTypeId ();
83 }
84 
85 void LtePdcpHeader::Print (std::ostream &os) const
86 {
87  os << "D/C=" << (uint16_t)m_dcBit;
88  os << " SN=" << m_sequenceNumber;
89 }
90 
91 uint32_t LtePdcpHeader::GetSerializedSize (void) const
92 {
93  return 2;
94 }
95 
97 {
99 
100  i.WriteU8 ( (m_dcBit << 7) | (m_sequenceNumber & 0x0F00) >> 8 );
101  i.WriteU8 ( (m_sequenceNumber & 0x00FF) );
102 }
103 
105 {
107  uint8_t byte_1;
108  uint8_t byte_2;
109 
110  byte_1 = i.ReadU8 ();
111  byte_2 = i.ReadU8 ();
112  m_dcBit = (byte_1 & 0x80) > 7;
113  // For now, we just support DATA PDUs
115  m_sequenceNumber = ((byte_1 & 0x0F) << 8) | byte_2;
116 
117  return GetSerializedSize ();
118 }
119 
120 }; // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
virtual uint32_t Deserialize(Buffer::Iterator start)
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
NS_LOG_COMPONENT_DEFINE("LtePdcpHeader")
void SetDcBit(uint8_t dcBit)
uint8_t GetDcBit() const
virtual void Serialize(Buffer::Iterator start) const
iterator in a Buffer instance
Definition: buffer.h:98
static TypeId GetTypeId(void)
virtual TypeId GetInstanceTypeId(void) const
uint16_t GetSequenceNumber() const
void WriteU8(uint8_t data)
Definition: buffer.h:690
LtePdcpHeader()
Constructor.
uint8_t ReadU8(void)
Definition: buffer.h:819
virtual uint32_t GetSerializedSize(void) const
virtual void Print(std::ostream &os) const
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
void SetSequenceNumber(uint16_t sequenceNumber)