A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-pdcp.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 #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:
45 };
46 
48  : m_pdcp (pdcp)
49 {
50 }
51 
53 {
54 }
55 
56 void
58 {
59  m_pdcp->DoReceivePdu (p);
60 }
61 
63 
65 
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);
77 
79 }
80 
81 TypeId
83 {
84  static TypeId tid = TypeId ("ns3::LtePdcp")
85  .SetParent<Object> ()
86  .AddTraceSource ("TxPDU",
87  "PDU transmission notified to the RLC.",
89  .AddTraceSource ("RxPDU",
90  "PDU received.",
92  ;
93  return tid;
94 }
95 
96 void
97 LtePdcp::SetRnti (uint16_t rnti)
98 {
99  NS_LOG_FUNCTION (this << (uint32_t) rnti);
100  m_rnti = rnti;
101 }
102 
103 void
104 LtePdcp::SetLcId (uint8_t lcId)
105 {
106  NS_LOG_FUNCTION (this << (uint32_t) lcId);
107  m_lcid = lcId;
108 }
109 
111 {
112  NS_LOG_FUNCTION (this);
113  delete (m_pdcpSapProvider);
114  delete (m_rlcSapUser);
115 }
116 
117 void
119 {
120  NS_LOG_FUNCTION (this << s);
121  m_pdcpSapUser = s;
122 }
123 
126 {
127  NS_LOG_FUNCTION (this);
128  return m_pdcpSapProvider;
129 }
130 
131 void
133 {
134  NS_LOG_FUNCTION (this << s);
135  m_rlcSapProvider = s;
136 }
137 
140 {
141  NS_LOG_FUNCTION (this);
142  return m_rlcSapUser;
143 }
144 
146 
147 void
149 {
150  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
151 
152  LtePdcpHeader pdcpHeader;
154 
157  {
158  m_txSequenceNumber = 0;
159  }
160 
161  pdcpHeader.SetDcBit (LtePdcpHeader::DATA_PDU);
162 
163  NS_LOG_LOGIC ("PDCP header: " << pdcpHeader);
164  p->AddHeader (pdcpHeader);
165 
166  // Sender timestamp
167  PdcpTag pdcpTag (Simulator::Now ());
168  p->AddByteTag (pdcpTag);
169  m_txPdu (m_rnti, m_lcid, p->GetSize ());
170 
172  params.rnti = m_rnti;
173  params.lcid = m_lcid;
174  params.pdcpPdu = p;
175 
177 }
178 
179 void
181 {
182  NS_LOG_FUNCTION (this << m_rnti << (uint32_t) m_lcid << p->GetSize ());
183 
184  // Receiver timestamp
185  PdcpTag pdcpTag;
186  Time delay;
187  if (p->FindFirstMatchingByteTag (pdcpTag))
188  {
189  delay = Simulator::Now() - pdcpTag.GetSenderTimestamp ();
190  }
191  m_rxPdu(m_rnti, m_lcid, p->GetSize (), delay.GetNanoSeconds ());
192 
193  LtePdcpHeader pdcpHeader;
194  p->RemoveHeader (pdcpHeader);
195  NS_LOG_LOGIC ("PDCP header: " << pdcpHeader);
196 
197  m_rxSequenceNumber = pdcpHeader.GetSequenceNumber () + 1;
199  {
200  m_rxSequenceNumber = 0;
201  }
202 
204  params.rrcPdu = p;
205  params.rnti = m_rnti;
206  params.lcid = m_lcid;
207  m_pdcpSapUser->ReceiveRrcPdu (params);
208 }
209 
210 void
212 {
213  NS_LOG_FUNCTION (this);
214 }
215 
216 
217 } // namespace ns3