A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lte-pdcp.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011-2012 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 #include "ns3/simulator.h"
23 
24 #include "ns3/lte-pdcp.h"
25 #include "ns3/lte-pdcp-header.h"
26 #include "ns3/lte-pdcp-sap.h"
27 #include "ns3/lte-pdcp-tag.h"
28 
29 NS_LOG_COMPONENT_DEFINE ("LtePdcp");
30 
31 namespace ns3 {
32 
33 
35 {
36 public:
38 
39  // Interface provided to lower RLC entity (implemented from LteRlcSapUser)
40  virtual void ReceivePdcpPdu (Ptr<Packet> p);
41 
42 private:
44  LtePdcp* m_pdcp;
45 };
46 
47 LtePdcpSpecificLteRlcSapUser::LtePdcpSpecificLteRlcSapUser (LtePdcp* pdcp)
48  : m_pdcp (pdcp)
49 {
50 }
51 
52 LtePdcpSpecificLteRlcSapUser::LtePdcpSpecificLteRlcSapUser ()
53 {
54 }
55 
56 void
58 {
59  m_pdcp->DoReceivePdu (p);
60 }
61 
63 
64 NS_OBJECT_ENSURE_REGISTERED (LtePdcp);
65 
66 LtePdcp::LtePdcp ()
67  : m_pdcpSapUser (0),
68  m_rlcSapProvider (0),
69  m_rnti (0),
70  m_lcid (0),
71  m_txSequenceNumber (0),
72  m_rxSequenceNumber (0)
73 {
74  NS_LOG_FUNCTION (this);
75  m_pdcpSapProvider = new LtePdcpSpecificLtePdcpSapProvider<LtePdcp> (this);
76  m_rlcSapUser = new LtePdcpSpecificLteRlcSapUser (this);
77 }
78 
79 LtePdcp::~LtePdcp ()
80 {
81  NS_LOG_FUNCTION (this);
82 }
83 
84 TypeId
85 LtePdcp::GetTypeId (void)
86 {
87  static TypeId tid = TypeId ("ns3::LtePdcp")
88  .SetParent<Object> ()
89  .AddTraceSource ("TxPDU",
90  "PDU transmission notified to the RLC.",
92  .AddTraceSource ("RxPDU",
93  "PDU received.",
95  ;
96  return tid;
97 }
98 
99 void
101 {
102  NS_LOG_FUNCTION (this);
103  delete (m_pdcpSapProvider);
104  delete (m_rlcSapUser);
105 }
106 
107 
108 void
109 LtePdcp::SetRnti (uint16_t rnti)
110 {
111  NS_LOG_FUNCTION (this << (uint32_t) rnti);
112  m_rnti = rnti;
113 }
114 
115 void
116 LtePdcp::SetLcId (uint8_t lcId)
117 {
118  NS_LOG_FUNCTION (this << (uint32_t) lcId);
119  m_lcid = lcId;
120 }
121 
122 void
124 {
125  NS_LOG_FUNCTION (this << s);
126  m_pdcpSapUser = s;
127 }
128 
131 {
132  NS_LOG_FUNCTION (this);
133  return m_pdcpSapProvider;
134 }
135 
136 void
138 {
139  NS_LOG_FUNCTION (this << s);
140  m_rlcSapProvider = s;
141 }
142 
145 {
146  NS_LOG_FUNCTION (this);
147  return m_rlcSapUser;
148 }
149 
152 {
153  Status s;
155  s.rxSn = m_rxSequenceNumber;
156  return s;
157 }
158 
159 void
161 {
163  m_rxSequenceNumber = s.rxSn;
164 }
165 
167 
168 void
169 LtePdcp::DoTransmitPdcpSdu (Ptr<Packet> p)
170 {
171  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
172 
173  LtePdcpHeader pdcpHeader;
174  pdcpHeader.SetSequenceNumber (m_txSequenceNumber);
175 
178  {
179  m_txSequenceNumber = 0;
180  }
181 
182  pdcpHeader.SetDcBit (LtePdcpHeader::DATA_PDU);
183 
184  NS_LOG_LOGIC ("PDCP header: " << pdcpHeader);
185  p->AddHeader (pdcpHeader);
186 
187  // Sender timestamp
188  PdcpTag pdcpTag (Simulator::Now ());
189  p->AddByteTag (pdcpTag);
190  m_txPdu (m_rnti, m_lcid, p->GetSize ());
191 
192  LteRlcSapProvider::TransmitPdcpPduParameters params;
193  params.rnti = m_rnti;
194  params.lcid = m_lcid;
195  params.pdcpPdu = p;
196 
197  m_rlcSapProvider->TransmitPdcpPdu (params);
198 }
199 
200 void
201 LtePdcp::DoReceivePdu (Ptr<Packet> p)
202 {
203  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
204 
205  // Receiver timestamp
206  PdcpTag pdcpTag;
207  Time delay;
208  if (p->FindFirstMatchingByteTag (pdcpTag))
209  {
210  delay = Simulator::Now() - pdcpTag.GetSenderTimestamp ();
211  }
212  m_rxPdu(m_rnti, m_lcid, p->GetSize (), delay.GetNanoSeconds ());
213 
214  LtePdcpHeader pdcpHeader;
215  p->RemoveHeader (pdcpHeader);
216  NS_LOG_LOGIC ("PDCP header: " << pdcpHeader);
217 
218  m_rxSequenceNumber = pdcpHeader.GetSequenceNumber () + 1;
219  if (m_rxSequenceNumber > m_maxPdcpSn)
220  {
221  m_rxSequenceNumber = 0;
222  }
223 
224  LtePdcpSapUser::ReceivePdcpSduParameters params;
225  params.pdcpSdu = p;
226  params.rnti = m_rnti;
227  params.lcid = m_lcid;
228  m_pdcpSapUser->ReceivePdcpSdu (params);
229 }
230 
231 
232 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
LteRlcSapUser * GetLteRlcSapUser()
Definition: lte-pdcp.cc:144
void SetLtePdcpSapUser(LtePdcpSapUser *s)
Definition: lte-pdcp.cc:123
uint16_t txSn
TX sequence number.
Definition: lte-pdcp.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
uint32_t GetSize(void) const
Definition: packet.h:620
uint16_t m_txSequenceNumber
Definition: lte-pdcp.h:145
virtual void TransmitPdcpPdu(TransmitPdcpPduParameters params)=0
void SetStatus(Status s)
Definition: lte-pdcp.cc:160
TracedCallback< uint16_t, uint8_t, uint32_t > m_txPdu
Definition: lte-pdcp.h:134
LtePdcpSapProvider * GetLtePdcpSapProvider()
Definition: lte-pdcp.cc:130
void SetLteRlcSapProvider(LteRlcSapProvider *s)
Definition: lte-pdcp.cc:137
uint16_t rxSn
RX sequence number.
Definition: lte-pdcp.h:98
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
void SetLcId(uint8_t lcId)
Definition: lte-pdcp.cc:116
void SetRnti(uint16_t rnti)
Definition: lte-pdcp.cc:109
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual void DoDispose()
Definition: lte-pdcp.cc:100
static Time Now(void)
Definition: simulator.cc:179
virtual void ReceivePdcpSdu(ReceivePdcpSduParameters params)=0
Status GetStatus()
Definition: lte-pdcp.cc:151
virtual void ReceivePdcpPdu(Ptr< Packet > p)
Definition: lte-pdcp.cc:57
TracedCallback< uint16_t, uint8_t, uint32_t, uint64_t > m_rxPdu
Definition: lte-pdcp.h:139
static const uint16_t m_maxPdcpSn
Definition: lte-pdcp.h:151
The packet header for the Packet Data Convergence Protocol (PDCP) packets.
void AddHeader(const Header &header)
Definition: packet.cc:270
void AddByteTag(const Tag &tag) const
Definition: packet.cc:833