A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-entities.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/simulator.h"
22 #include "ns3/log.h"
23 
24 #include "ns3/lte-rlc-header.h"
25 #include "ns3/lte-rlc-am-header.h"
26 #include "ns3/lte-pdcp-header.h"
27 
28 #include "lte-test-entities.h"
29 
30 NS_LOG_COMPONENT_DEFINE ("LteTestEntities");
31 
32 namespace ns3 {
33 
34 
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::LteTestRrc")
41  .SetParent<Object> ()
42  .AddConstructor<LteTestRrc> ()
43  ;
44 
45  return tid;
46 }
47 
49 {
50  NS_LOG_FUNCTION (this);
51 
52  m_txPdus = 0;
53  m_txBytes = 0;
54  m_rxPdus = 0;
55  m_rxBytes = 0;
56  m_txLastTime = Time (0);
57  m_rxLastTime = Time (0);;
58 
60 // Simulator::ScheduleNow (&LteTestRrc::Start, this);
61 }
62 
64 {
65  NS_LOG_FUNCTION (this);
66 }
67 
68 void
70 {
71  NS_LOG_FUNCTION (this);
72  delete m_pdcpSapUser;
73 }
74 
75 void
77 {
79 }
80 
83 {
84  return m_pdcpSapUser;
85 }
86 
87 
88 std::string
90 {
91  NS_LOG_FUNCTION (this);
92  return m_receivedData;
93 }
94 
95 // Stats
96 uint32_t
98 {
99  NS_LOG_FUNCTION (this << m_txPdus);
100  return m_txPdus;
101 }
102 
103 uint32_t
105 {
106  NS_LOG_FUNCTION (this << m_txBytes);
107  return m_txBytes;
108 }
109 
110 uint32_t
112 {
113  NS_LOG_FUNCTION (this << m_rxPdus);
114  return m_rxPdus;
115 }
116 
117 uint32_t
119 {
120  NS_LOG_FUNCTION (this << m_rxBytes);
121  return m_rxBytes;
122 }
123 
124 Time
126 {
127  NS_LOG_FUNCTION (this << m_txLastTime);
128  return m_txLastTime;
129 }
130 
131 Time
133 {
134  NS_LOG_FUNCTION (this << m_rxLastTime);
135  return m_rxLastTime;
136 }
137 
138 
139 void
141 {
142  NS_LOG_FUNCTION (this << arrivalTime);
143  m_arrivalTime = arrivalTime;
144 }
145 
146 void
147 LteTestRrc::SetPduSize (uint32_t pduSize)
148 {
149  NS_LOG_FUNCTION (this << pduSize);
150  m_pduSize = pduSize;
151 }
152 
153 
158 void
160 {
161  NS_LOG_FUNCTION (this << params.pdcpSdu->GetSize ());
162  Ptr<Packet> p = params.pdcpSdu;
163 // NS_LOG_LOGIC ("PDU received = " << (*p));
164 
165  uint32_t dataLen = p->GetSize ();
166  uint8_t *buf = new uint8_t[dataLen];
167 
168  // Stats
169  m_rxPdus++;
170  m_rxBytes += dataLen;
172 
173  p->CopyData (buf, dataLen);
174  m_receivedData = std::string ((char *)buf, dataLen);
175 
176 // NS_LOG_LOGIC (m_receivedData);
177 
178  delete [] buf;
179 }
180 
185 void
187 {
188  NS_LOG_FUNCTION (this);
189  NS_ASSERT_MSG (m_arrivalTime != Time (0), "Arrival time must be different from 0");
190 
191  // Stats
192  m_txPdus++;
193  m_txBytes += m_pduSize;
195 
197  p.rnti = 1111;
198  p.lcid = 222;
199  p.pdcpSdu = Create<Packet> (m_pduSize);
200 
203 // Simulator::Run ();
204 }
205 
206 void
208 {
209  NS_LOG_FUNCTION (this);
210  m_nextPdu.Cancel ();
211 }
212 
213 void
214 LteTestRrc::SendData (Time at, std::string dataToSend)
215 {
216  NS_LOG_FUNCTION (this << at << dataToSend.length () << dataToSend);
217 
218  // Stats
219  m_txPdus++;
220  m_txBytes += dataToSend.length ();
221 
223  p.rnti = 1111;
224  p.lcid = 222;
225 
226  NS_LOG_LOGIC ("Data(" << dataToSend.length () << ") = " << dataToSend.data ());
227  p.pdcpSdu = Create<Packet> ((uint8_t *) dataToSend.data (), dataToSend.length ());
228 
229  NS_LOG_LOGIC ("Packet(" << p.pdcpSdu->GetSize () << ")");
231 }
232 
234 
235 TypeId
237 {
238  static TypeId tid = TypeId ("ns3::LteTestPdcp")
239  .SetParent<Object> ()
240  .AddConstructor<LteTestPdcp> ()
241  ;
242 
243  return tid;
244 }
245 
247 {
248  NS_LOG_FUNCTION (this);
251 }
252 
254 {
255  NS_LOG_FUNCTION (this);
256 }
257 
258 void
260 {
261  NS_LOG_FUNCTION (this);
262  delete m_rlcSapUser;
263 }
264 
265 void
267 {
269 }
270 
273 {
274  return m_rlcSapUser;
275 }
276 
277 
278 std::string
280 {
281  NS_LOG_FUNCTION (this);
282 
283  return m_receivedData;
284 }
285 
286 
291 void
293 {
294  NS_LOG_FUNCTION (this << p->GetSize ());
295  NS_LOG_LOGIC ("Data = " << (*p));
296 
297  uint32_t dataLen = p->GetSize ();
298  uint8_t *buf = new uint8_t[dataLen];
299  p->CopyData (buf, dataLen);
300  m_receivedData = std::string ((char *)buf, dataLen);
301 
303 
304  delete [] buf;
305 }
306 
311 void
313 {
314  NS_LOG_FUNCTION (this);
315 }
316 
317 void
318 LteTestPdcp::SendData (Time time, std::string dataToSend)
319 {
320  NS_LOG_FUNCTION (this << time << dataToSend.length () << dataToSend);
321 
323  p.rnti = 1111;
324  p.lcid = 222;
325 
326  NS_LOG_LOGIC ("Data(" << dataToSend.length () << ") = " << dataToSend.data ());
327  p.pdcpPdu = Create<Packet> ((uint8_t *) dataToSend.data (), dataToSend.length ());
328 
329  NS_LOG_LOGIC ("Packet(" << p.pdcpPdu->GetSize () << ")");
331 }
332 
334 
335 TypeId
337 {
338  static TypeId tid = TypeId ("ns3::LteTestMac")
339  .SetParent<Object> ()
340  .AddConstructor<LteTestMac> ()
341  ;
342 
343  return tid;
344 }
345 
347 {
348  NS_LOG_FUNCTION (this);
349  m_device = 0;
351  m_macSapUser = 0;
352  m_macLoopback = 0;
353  m_pdcpHeaderPresent = false;
356  m_txOppTime = Seconds (0.001);
357  m_txOppSize = 0;
358 
359  m_txPdus = 0;
360  m_txBytes = 0;
361  m_rxPdus = 0;
362  m_rxBytes = 0;
363 
364 // m_cmacSapProvider = new EnbMacMemberLteEnbCmacSapProvider (this);
365 // m_schedSapUser = new EnbMacMemberFfMacSchedSapUser (this);
366 // m_cschedSapUser = new EnbMacMemberFfMacCschedSapUser (this);
367 // m_enbPhySapUser = new EnbMacMemberLteEnbPhySapUser (this);
368 }
369 
371 {
372  NS_LOG_FUNCTION (this);
373 }
374 
375 void
377 {
378  NS_LOG_FUNCTION (this);
379  delete m_macSapProvider;
380 // delete m_cmacSapProvider;
381 // delete m_schedSapUser;
382 // delete m_cschedSapUser;
383 // delete m_enbPhySapUser;
384 
385  m_device = 0;
386 }
387 
388 void
390 {
391  m_device = device;
392 }
393 
394 void
396 {
397  m_macSapUser = s;
398 }
399 
402 {
403  return m_macSapProvider;
404 }
405 
406 void
408 {
409  m_macLoopback = s;
410 }
411 
412 std::string
414 {
415  NS_LOG_FUNCTION (this);
416  return m_receivedData;
417 }
418 
419 // Stats
420 uint32_t
422 {
423  NS_LOG_FUNCTION (this << m_txPdus);
424  return m_txPdus;
425 }
426 
427 uint32_t
429 {
430  NS_LOG_FUNCTION (this << m_txBytes);
431  return m_txBytes;
432 }
433 
434 uint32_t
436 {
437  NS_LOG_FUNCTION (this << m_rxPdus);
438  return m_rxPdus;
439 }
440 
441 uint32_t
443 {
444  NS_LOG_FUNCTION (this << m_rxBytes);
445  return m_rxBytes;
446 }
447 
448 
449 void
450 LteTestMac::SendTxOpportunity (Time time, uint32_t bytes)
451 {
452  NS_LOG_FUNCTION (this << time << bytes);
455  {
456  if (m_txOppTime != Seconds (0))
457  {
459  }
460  }
461 }
462 
463 void
465 {
466  NS_LOG_FUNCTION (this << present);
467  m_pdcpHeaderPresent = present;
468 }
469 
470 void
471 LteTestMac::SetRlcHeaderType (uint8_t rlcHeaderType)
472 {
473  NS_LOG_FUNCTION (this << rlcHeaderType);
474  m_rlcHeaderType = rlcHeaderType;
475 }
476 
477 void
479 {
480  NS_LOG_FUNCTION (this << (uint32_t)mode);
481  m_txOpportunityMode = mode;
482 
484  {
485  if (m_txOppTime != Seconds (0.0))
486  {
488  }
489  }
490 }
491 
492 void
494 {
495  NS_LOG_FUNCTION (this << txOppTime);
496  m_txOppTime = txOppTime;
497 }
498 
499 void
500 LteTestMac::SetTxOppSize (uint32_t txOppSize)
501 {
502  NS_LOG_FUNCTION (this << txOppSize);
503  m_txOppSize = txOppSize;
504 }
505 
506 
511 void
513 {
514  NS_LOG_FUNCTION (this << params.pdu->GetSize ());
515 
516  m_txPdus++;
517  m_txBytes += params.pdu->GetSize ();
518 
519  if (m_device)
520  {
521  m_device->Send (params.pdu, m_device->GetBroadcast (), 0);
522  }
523  else if (m_macLoopback)
524  {
526  m_macLoopback->m_macSapUser, params.pdu);
527  }
528  else
529  {
530  LtePdcpHeader pdcpHeader;
531 
533  {
534  // Remove AM RLC header
535  LteRlcAmHeader rlcAmHeader;
536  params.pdu->RemoveHeader (rlcAmHeader);
537  NS_LOG_LOGIC ("AM RLC header: " << rlcAmHeader);
538  }
539  else // if (m_rlcHeaderType == UM_RLC_HEADER)
540  {
541  // Remove UM RLC header
542  LteRlcHeader rlcHeader;
543  params.pdu->RemoveHeader (rlcHeader);
544  NS_LOG_LOGIC ("UM RLC header: " << rlcHeader);
545  }
546 
547  // Remove PDCP header, if present
549  {
550  params.pdu->RemoveHeader (pdcpHeader);
551  NS_LOG_LOGIC ("PDCP header: " << pdcpHeader);
552  }
553 
554  // Copy data to a string
555  uint32_t dataLen = params.pdu->GetSize ();
556  uint8_t *buf = new uint8_t[dataLen];
557  params.pdu->CopyData (buf, dataLen);
558  m_receivedData = std::string ((char *)buf, dataLen);
559 
560  NS_LOG_LOGIC ("Data (" << dataLen << ") = " << m_receivedData);
561  delete [] buf;
562  }
563 }
564 
565 void
567 {
568  NS_LOG_FUNCTION (this << params.txQueueSize << params.retxQueueSize << params.statusPduSize);
569 
571  {
572  if (params.statusPduSize)
573  {
575  m_macSapUser, params.statusPduSize + 2, 0, 0);
576  }
577  else if (params.txQueueSize)
578  {
580  m_macSapUser, params.txQueueSize + 2, 0, 0);
581  }
582  else if (params.retxQueueSize)
583  {
585  m_macSapUser, params.retxQueueSize + 2, 0, 0);
586  }
587  }
588 }
589 
590 
591 bool
592 LteTestMac::Receive (Ptr<NetDevice> nd, Ptr<const Packet> p, uint16_t protocol, const Address& addr)
593 {
594  NS_LOG_FUNCTION (this << addr << protocol << p->GetSize ());
595 
596  m_rxPdus++;
597  m_rxBytes += p->GetSize ();
598 
599  Ptr<Packet> packet = p->Copy ();
600  m_macSapUser->ReceivePdu (packet);
601  return true;
602 }
603 
604 
605 
606 
607 
608 
609 
610 
612 
614  : m_s1SapProvider (0)
615 {
616  NS_LOG_FUNCTION (this);
618 }
619 
620 
622 {
623  NS_LOG_FUNCTION (this);
624 }
625 
626 
627 void
629 {
630  NS_LOG_FUNCTION (this);
631  delete m_s1SapUser;
632 }
633 
634 TypeId
636 {
637  NS_LOG_FUNCTION ("EpcTestRrc::GetTypeId");
638  static TypeId tid = TypeId ("ns3::EpcTestRrc")
639  .SetParent<Object> ()
640  .AddConstructor<EpcTestRrc> ()
641  ;
642  return tid;
643 }
644 void
646 {
647  m_s1SapProvider = s;
648 }
649 
650 
653 {
654  return m_s1SapUser;
655 }
656 
657 void
659 {
660 
661 }
662 
663 void
665 {
666 
667 }
668 
669 
670 } // namespace ns3
671 
Time GetTxLastTime(void)
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
Service Access Point (SAP) offered by the UM-RLC and AM-RLC entities to the PDCP entity See 3GPP 36...
Definition: lte-rlc-sap.h:66
Time GetRxLastTime(void)
Parameters passed to DataRadioBearerSetupRequest ()
Template for the implementation of the EpcEnbS1SapUser as a member of an owner class of type C to whi...
This class implements the Service Access Point (SAP) between the LteEnbRrc and the EpcEnbApplication...
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
LteRlcSapUser * m_rlcSapUser
uint32_t GetTxBytes(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetPduSize(uint32_t pduSize)
std::string m_receivedData
static TypeId GetTypeId(void)
This class implements the Service Access Point (SAP) between the LteEnbRrc and the EpcEnbApplication...
Service Access Point (SAP) offered by the UM-RLC and AM-RLC entities to the PDCP entity See 3GPP 36...
Definition: lte-rlc-sap.h:35
static TypeId GetTypeId(void)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
void DoReportBufferStatus(LteMacSapProvider::ReportBufferStatusParameters)
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
LteMacSapProvider * m_macSapProvider
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
virtual void NotifyTxOpportunity(uint32_t bytes, uint8_t layer, uint8_t harqId)=0
Called by the MAC to notify the RLC that the scheduler granted a transmission opportunity to this RLC...
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
uint32_t retxQueueSize
the current size of the RLC retransmission queue in bytes
Definition: lte-mac-sap.h:72
void SetTxOpportunityMode(uint8_t mode)
void SetLteMacLoopback(Ptr< LteTestMac > s)
Set the other side of the MAC Loopback.
virtual void DoReceivePdcpSdu(LtePdcpSapUser::ReceivePdcpSduParameters params)
PDCP SAP.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:825
virtual void TransmitPdcpPdu(TransmitPdcpPduParameters params)=0
Send a PDCP PDU to the RLC for transmission This method is to be called when upper PDCP entity has a ...
EpcEnbS1SapUser * m_s1SapUser
a polymophic address class
Definition: address.h:86
The packet header for the Radio Link Control (RLC) protocol packets.
virtual ~LteTestPdcp(void)
EpcEnbS1SapProvider * m_s1SapProvider
Parameters for LteMacSapProvider::ReportBufferStatus.
Definition: lte-mac-sap.h:66
Parameters for LtePdcpSapUser::ReceivePdcpSdu.
Definition: lte-pdcp-sap.h:76
void SetLteMacSapUser(LteMacSapUser *s)
Set the MAC SAP user.
LtePdcpSapUser * m_pdcpSapUser
LtePdcpSapProvider * m_pdcpSapProvider
static TypeId GetTypeId(void)
LtePdcpSapUser * GetLtePdcpSapUser(void)
Get the PDCP SAP user.
Ptr< SampleEmitter > s
void Start()
START.
void SendData(Time at, std::string dataToSend)
void SetLteRlcSapProvider(LteRlcSapProvider *s)
Set the RLC SAP provider.
uint16_t rnti
the C-RNTI identifying the UE
Definition: lte-pdcp-sap.h:46
Parameters for LtePdcpSapProvider::TransmitPdcpSdu.
Definition: lte-pdcp-sap.h:43
Ptr< NetDevice > m_device
uint32_t GetTxBytes(void)
void SetS1SapProvider(EpcEnbS1SapProvider *s)
Set the S1 SAP Provider.
uint32_t GetRxPdus(void)
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:233
void SetTxOppTime(Time txOppTime)
uint32_t GetRxPdus(void)
EpcEnbS1SapUser * GetS1SapUser()
LteRlcSapProvider * m_rlcSapProvider
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
RRC stub providing a testing S1 SAP user to be used with the EpcEnbApplication.
The packet header for the AM Radio Link Control (RLC) protocol packets.
uint32_t GetTxPdus(void)
virtual ~LteTestRrc(void)
LteMacSapProvider * GetLteMacSapProvider(void)
Get the MAC SAP provider.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
std::string m_receivedData
void SetArrivalTime(Time arrivalTime)
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:986
uint32_t GetTxPdus(void)
uint32_t txQueueSize
the current size of the RLC transmission queue
Definition: lte-mac-sap.h:70
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
std::string m_receivedData
std::string GetDataReceived(void)
virtual void TransmitPdcpSdu(TransmitPdcpSduParameters params)=0
Send a RRC PDU to the RDCP for transmission This method is to be called when upper RRC entity has a R...
void SetTxOppSize(uint32_t txOppSize)
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
void DoPathSwitchRequestAcknowledge(EpcEnbS1SapUser::PathSwitchRequestAcknowledgeParameters params)
Parameters for LteRlcSapProvider::TransmitPdcpPdu.
Definition: lte-rlc-sap.h:43
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:84
void SendTxOpportunity(Time, uint32_t)
Service Access Point (SAP) offered by the PDCP entity to the RRC entity See 3GPP 36.323 Packet Data Convergence Protocol (PDCP) specification.
Definition: lte-pdcp-sap.h:35
uint16_t statusPduSize
the current size of the pending STATUS RLC PDU message in bytes
Definition: lte-mac-sap.h:74
std::string GetDataReceived(void)
Service Access Point (SAP) offered by the MAC to the RLC See Femto Forum MAC Scheduler Interface Spec...
Definition: lte-mac-sap.h:94
Service Access Point (SAP) offered by the PDCP entity to the RRC entity See 3GPP 36.323 Packet Data Convergence Protocol (PDCP) specification.
Definition: lte-pdcp-sap.h:68
void SetDevice(Ptr< NetDevice > device)
void SendData(Time time, std::string dataToSend)
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::cancel method.
Definition: event-id.cc:47
virtual void ReceivePdu(Ptr< Packet > p)=0
Called by the MAC to notify the RLC of the reception of a new PDU.
Service Access Point (SAP) offered by the MAC to the RLC See Femto Forum MAC Scheduler Interface Spec...
Definition: lte-mac-sap.h:36
std::string GetDataReceived(void)
uint32_t GetRxBytes(void)
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:381
uint16_t rnti
the C-RNTI identifying the UE
Definition: lte-rlc-sap.h:46
uint32_t GetRxBytes(void)
void DoTransmitPdu(LteMacSapProvider::TransmitPduParameters)
MAC SAP.
The packet header for the Packet Data Convergence Protocol (PDCP) packets.
a base class which provides memory management and object aggregation
Definition: object.h:64
void DoDataRadioBearerSetupRequest(EpcEnbS1SapUser::DataRadioBearerSetupRequestParameters params)
virtual ~LteTestMac(void)
uint8_t lcid
the logical channel id corresponding to the sending RLC instance
Definition: lte-pdcp-sap.h:47
void SetPdcpHeaderPresent(bool present)
Ptr< LteTestMac > m_macLoopback
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
LteMacSapUser * m_macSapUser
virtual void DoReceivePdcpPdu(Ptr< Packet > p)
RLC SAP.
void SetLtePdcpSapProvider(LtePdcpSapProvider *s)
Set the PDCP SAP provider.
static TypeId GetTypeId(void)
void SetRlcHeaderType(uint8_t rlcHeaderType)
bool Receive(Ptr< NetDevice > nd, Ptr< const Packet > p, uint16_t protocol, const Address &addr)
LteRlcSapUser * GetLteRlcSapUser(void)
Get the RLC SAP user.
Parameters for LteMacSapProvider::TransmitPdu.
Definition: lte-mac-sap.h:45