A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lte-simple-helper.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 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> (Based on lte-helper.cc)
19  */
20 
21 
22 #include "ns3/log.h"
23 #include "ns3/callback.h"
24 #include "ns3/config.h"
25 #include "ns3/simple-channel.h"
26 #include "ns3/error-model.h"
27 
28 #include "lte-simple-helper.h"
29 #include "lte-simple-net-device.h"
30 #include "lte-test-entities.h"
31 
32 
33 NS_LOG_COMPONENT_DEFINE ("LteSimpleHelper");
34 
35 namespace ns3 {
36 
37 
38 NS_OBJECT_ENSURE_REGISTERED (LteSimpleHelper);
39 
40 LteSimpleHelper::LteSimpleHelper (void)
41 {
42  NS_LOG_FUNCTION (this);
43  m_enbDeviceFactory.SetTypeId (LteSimpleNetDevice::GetTypeId ());
44  m_ueDeviceFactory.SetTypeId (LteSimpleNetDevice::GetTypeId ());
45 }
46 
47 void
49 {
50  NS_LOG_FUNCTION (this);
51 
52  m_phyChannel = CreateObject<SimpleChannel> ();
53 
55 }
56 
57 LteSimpleHelper::~LteSimpleHelper (void)
58 {
59  NS_LOG_FUNCTION (this);
60 }
61 
62 TypeId LteSimpleHelper::GetTypeId (void)
63 {
64  static TypeId
65  tid =
66  TypeId ("ns3::LteSimpleHelper")
67  .SetParent<Object> ()
68  .AddConstructor<LteSimpleHelper> ()
69  .AddAttribute ("RlcEntity",
70  "Specify which type of RLC will be used. ",
71  EnumValue (RLC_UM),
72  MakeEnumAccessor (&LteSimpleHelper::m_lteRlcEntityType),
73  MakeEnumChecker (RLC_UM, "RlcUm",
74  RLC_AM, "RlcAm"))
75  ;
76  return tid;
77 }
78 
79 void
81 {
82  NS_LOG_FUNCTION (this);
83  m_phyChannel = 0;
84 
85  m_enbMac->Dispose ();
86  m_enbMac = 0;
87  m_ueMac->Dispose ();
88  m_ueMac = 0;
89 
91 }
92 
93 
96 {
97  NS_LOG_FUNCTION (this);
98  Initialize (); // will run DoInitialize () if necessary
99  NetDeviceContainer devices;
100  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
101  {
102  Ptr<Node> node = *i;
103  Ptr<NetDevice> device = InstallSingleEnbDevice (node);
104  devices.Add (device);
105  }
106  return devices;
107 }
108 
111 {
112  NS_LOG_FUNCTION (this);
113  NetDeviceContainer devices;
114  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
115  {
116  Ptr<Node> node = *i;
117  Ptr<NetDevice> device = InstallSingleUeDevice (node);
118  devices.Add (device);
119  }
120  return devices;
121 }
122 
123 
125 LteSimpleHelper::InstallSingleEnbDevice (Ptr<Node> n)
126 {
127  NS_LOG_FUNCTION (this);
128 
129  m_enbRrc = CreateObject<LteTestRrc> ();
130  m_enbPdcp = CreateObject<LtePdcp> ();
131 
132  if (m_lteRlcEntityType == RLC_UM)
133  {
134  m_enbRlc = CreateObject<LteRlcUm> ();
135  }
136  else // m_lteRlcEntityType == RLC_AM
137  {
138  m_enbRlc = CreateObject<LteRlcAm> ();
139  }
140 
141  m_enbRlc->SetRnti (11);
142  m_enbRlc->SetLcId (12);
143 
144  Ptr<LteSimpleNetDevice> enbDev = m_enbDeviceFactory.Create<LteSimpleNetDevice> ();
145  enbDev->SetAddress (Mac48Address::Allocate ());
146  enbDev->SetChannel (m_phyChannel);
147 
148  n->AddDevice (enbDev);
149 
150  m_enbMac = CreateObject<LteTestMac> ();
151  m_enbMac->SetDevice (enbDev);
152 
153  enbDev->SetReceiveCallback (MakeCallback (&LteTestMac::Receive, m_enbMac));
154 
155  // Connect SAPs: RRC <-> PDCP <-> RLC <-> MAC
156 
157  m_enbRrc->SetLtePdcpSapProvider (m_enbPdcp->GetLtePdcpSapProvider ());
158  m_enbPdcp->SetLtePdcpSapUser (m_enbRrc->GetLtePdcpSapUser ());
159 
160  m_enbPdcp->SetLteRlcSapProvider (m_enbRlc->GetLteRlcSapProvider ());
161  m_enbRlc->SetLteRlcSapUser (m_enbPdcp->GetLteRlcSapUser ());
162 
163  m_enbRlc->SetLteMacSapProvider (m_enbMac->GetLteMacSapProvider ());
164  m_enbMac->SetLteMacSapUser (m_enbRlc->GetLteMacSapUser ());
165 
166  return enbDev;
167 }
168 
169 Ptr<NetDevice>
170 LteSimpleHelper::InstallSingleUeDevice (Ptr<Node> n)
171 {
172  NS_LOG_FUNCTION (this);
173 
174  m_ueRrc = CreateObject<LteTestRrc> ();
175  m_uePdcp = CreateObject<LtePdcp> ();
176 
177  if (m_lteRlcEntityType == RLC_UM)
178  {
179  m_ueRlc = CreateObject<LteRlcUm> ();
180  }
181  else // m_lteRlcEntityType == RLC_AM
182  {
183  m_ueRlc = CreateObject<LteRlcAm> ();
184  }
185 
186  m_ueRlc->SetRnti (21);
187  m_ueRlc->SetLcId (22);
188 
189  Ptr<LteSimpleNetDevice> ueDev = m_ueDeviceFactory.Create<LteSimpleNetDevice> ();
190  ueDev->SetAddress (Mac48Address::Allocate ());
191  ueDev->SetChannel (m_phyChannel);
192 
193  n->AddDevice (ueDev);
194 
195  m_ueMac = CreateObject<LteTestMac> ();
196  m_ueMac->SetDevice (ueDev);
197 
198  ueDev->SetReceiveCallback (MakeCallback (&LteTestMac::Receive, m_ueMac));
199 
200  // Connect SAPs: RRC <-> PDCP <-> RLC <-> MAC
201 
202  m_ueRrc->SetLtePdcpSapProvider (m_uePdcp->GetLtePdcpSapProvider ());
203  m_uePdcp->SetLtePdcpSapUser (m_ueRrc->GetLtePdcpSapUser ());
204 
205  m_uePdcp->SetLteRlcSapProvider (m_ueRlc->GetLteRlcSapProvider ());
206  m_ueRlc->SetLteRlcSapUser (m_uePdcp->GetLteRlcSapUser ());
207 
208  m_ueRlc->SetLteMacSapProvider (m_ueMac->GetLteMacSapProvider ());
209  m_ueMac->SetLteMacSapUser (m_ueRlc->GetLteMacSapUser ());
210 
211  return ueDev;
212 }
213 
214 
215 void
217 {
218  LogLevel level = (LogLevel) (LOG_LEVEL_ALL | LOG_PREFIX_TIME | LOG_PREFIX_NODE | LOG_PREFIX_FUNC);
219 
220  LogComponentEnable ("Config", level);
221  LogComponentEnable ("LteSimpleHelper", level);
222  LogComponentEnable ("LteTestEntities", level);
223  LogComponentEnable ("LtePdcp", level);
224  LogComponentEnable ("LteRlc", level);
225  LogComponentEnable ("LteRlcUm", level);
226  LogComponentEnable ("LteRlcAm", level);
227  LogComponentEnable ("LteSimpleNetDevice", level);
228  LogComponentEnable ("SimpleNetDevice", level);
229  LogComponentEnable ("SimpleChannel", level);
230 }
231 
232 void
234 {
235 // EnableMacTraces ();
236  EnableRlcTraces ();
237  EnablePdcpTraces ();
238 }
239 
240 void
242 {
245 }
246 
247 
248 void
249 LteSimpleHelperDlTxPduCallback (Ptr<RadioBearerStatsCalculator> rlcStats, std::string path,
250  uint16_t rnti, uint8_t lcid, uint32_t packetSize)
251 {
252  NS_LOG_FUNCTION (rlcStats << path << rnti << (uint16_t)lcid << packetSize);
253  uint64_t imsi = 111;
254  uint16_t cellId = 222;
255  rlcStats->DlTxPdu (cellId, imsi, rnti, lcid, packetSize);
256 }
257 
258 void
259 LteSimpleHelperDlRxPduCallback (Ptr<RadioBearerStatsCalculator> rlcStats, std::string path,
260  uint16_t rnti, uint8_t lcid, uint32_t packetSize, uint64_t delay)
261 {
262  NS_LOG_FUNCTION (rlcStats << path << rnti << (uint16_t)lcid << packetSize << delay);
263  uint64_t imsi = 333;
264  uint16_t cellId = 555;
265  rlcStats->DlRxPdu (cellId, imsi, rnti, lcid, packetSize, delay);
266 }
267 
268 void
270 {
272 
273  // Config::Connect ("/NodeList/*/DeviceList/*/LteRlc/TxPDU",
274  // MakeBoundCallback (&LteSimpleHelperDlTxPduCallback, m_rlcStats));
275  // Config::Connect ("/NodeList/*/DeviceList/*/LteRlc/RxPDU",
276  // MakeBoundCallback (&LteSimpleHelperDlRxPduCallback, m_rlcStats));
277 }
278 
279 void
280 LteSimpleHelperUlTxPduCallback (Ptr<RadioBearerStatsCalculator> rlcStats, std::string path,
281  uint16_t rnti, uint8_t lcid, uint32_t packetSize)
282 {
283  NS_LOG_FUNCTION (rlcStats << path << rnti << (uint16_t)lcid << packetSize);
284  uint64_t imsi = 1111;
285  uint16_t cellId = 555;
286  rlcStats->UlTxPdu (cellId, imsi, rnti, lcid, packetSize);
287 }
288 
289 void
290 LteSimpleHelperUlRxPduCallback (Ptr<RadioBearerStatsCalculator> rlcStats, std::string path,
291  uint16_t rnti, uint8_t lcid, uint32_t packetSize, uint64_t delay)
292 {
293  NS_LOG_FUNCTION (rlcStats << path << rnti << (uint16_t)lcid << packetSize << delay);
294  uint64_t imsi = 444;
295  uint16_t cellId = 555;
296  rlcStats->UlRxPdu (cellId, imsi, rnti, lcid, packetSize, delay);
297 }
298 
299 
300 void
302 {
304 
305  // Config::Connect ("/NodeList/*/DeviceList/*/LteRlc/TxPDU",
306  // MakeBoundCallback (&LteSimpleHelperUlTxPduCallback, m_rlcStats));
307  // Config::Connect ("/NodeList/*/DeviceList/*/LteRlc/RxPDU",
308  // MakeBoundCallback (&LteSimpleHelperUlRxPduCallback, m_rlcStats));
309 }
310 
311 
312 void
314 {
317 }
318 
319 void
321 {
323 
324  // Config::Connect ("/NodeList/*/DeviceList/*/LtePdcp/TxPDU",
325  // MakeBoundCallback (&LteSimpleHelperDlTxPduCallback, m_pdcpStats));
326  // Config::Connect ("/NodeList/*/DeviceList/*/LtePdcp/RxPDU",
327  // MakeBoundCallback (&LteSimpleHelperDlRxPduCallback, m_pdcpStats));
328 }
329 
330 void
332 {
334 
335  // Config::Connect ("/NodeList/*/DeviceList/*/LtePdcp/TxPDU",
336  // MakeBoundCallback (&LteSimpleHelperUlTxPduCallback, m_pdcpStats));
337  // Config::Connect ("/NodeList/*/DeviceList/*/LtePdcp/RxPDU",
338  // MakeBoundCallback (&LteSimpleHelperUlRxPduCallback, m_pdcpStats));
339 }
340 
341 
342 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
void SetTypeId(TypeId tid)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
virtual void DoDispose(void)
Definition: object.cc:335
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
static Mac48Address Allocate(void)
Ptr< Object > Create(void) const
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
holds a vector of ns3::NetDevice pointers
NetDeviceContainer InstallEnbDevice(NodeContainer c)
void UlTxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:502
virtual void DoDispose(void)
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
NetDeviceContainer InstallUeDevice(NodeContainer c)
void DlTxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize)
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:119
void Initialize(void)
Definition: object.cc:179
virtual void DoInitialize(void)
virtual void DoInitialize(void)
Definition: object.cc:342
void LogComponentEnable(char const *name, enum LogLevel level)
Definition: log.cc:311