A Discrete-Event Network Simulator
API
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 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("LteTestEntities");
33 
35 
36 TypeId
38 {
39  static TypeId tid = TypeId ("ns3::LteTestRrc")
40  .SetParent<Object> ()
41  .AddConstructor<LteTestRrc> ()
42  ;
43 
44  return tid;
45 }
46 
48 {
49  NS_LOG_FUNCTION (this);
50 
51  m_txPdus = 0;
52  m_txBytes = 0;
53  m_rxPdus = 0;
54  m_rxBytes = 0;
55  m_txLastTime = Time (0);
56  m_rxLastTime = Time (0);;
57 
59 // Simulator::ScheduleNow (&LteTestRrc::Start, this);
60 }
61 
63 {
64  NS_LOG_FUNCTION (this);
65 }
66 
67 void
69 {
70  NS_LOG_FUNCTION (this);
71  delete m_pdcpSapUser;
72 }
73 
74 void
76 {
78 }
79 
82 {
83  return m_pdcpSapUser;
84 }
85 
86 
87 std::string
89 {
90  NS_LOG_FUNCTION (this);
91  return m_receivedData;
92 }
93 
94 // Stats
95 uint32_t
97 {
98  NS_LOG_FUNCTION (this << m_txPdus);
99  return m_txPdus;
100 }
101 
102 uint32_t
104 {
105  NS_LOG_FUNCTION (this << m_txBytes);
106  return m_txBytes;
107 }
108 
109 uint32_t
111 {
112  NS_LOG_FUNCTION (this << m_rxPdus);
113  return m_rxPdus;
114 }
115 
116 uint32_t
118 {
119  NS_LOG_FUNCTION (this << m_rxBytes);
120  return m_rxBytes;
121 }
122 
123 Time
125 {
126  NS_LOG_FUNCTION (this << m_txLastTime);
127  return m_txLastTime;
128 }
129 
130 Time
132 {
133  NS_LOG_FUNCTION (this << m_rxLastTime);
134  return m_rxLastTime;
135 }
136 
137 
138 void
140 {
141  NS_LOG_FUNCTION (this << arrivalTime);
142  m_arrivalTime = arrivalTime;
143 }
144 
145 void
146 LteTestRrc::SetPduSize (uint32_t pduSize)
147 {
148  NS_LOG_FUNCTION (this << pduSize);
149  m_pduSize = pduSize;
150 }
151 
152 
157 void
159 {
160  NS_LOG_FUNCTION (this << params.pdcpSdu->GetSize ());
161  Ptr<Packet> p = params.pdcpSdu;
162 // NS_LOG_LOGIC ("PDU received = " << (*p));
163 
164  uint32_t dataLen = p->GetSize ();
165  uint8_t *buf = new uint8_t[dataLen];
166 
167  // Stats
168  m_rxPdus++;
169  m_rxBytes += dataLen;
171 
172  p->CopyData (buf, dataLen);
173  m_receivedData = std::string ((char *)buf, dataLen);
174 
175 // NS_LOG_LOGIC (m_receivedData);
176 
177  delete [] buf;
178 }
179 
184 void
186 {
187  NS_LOG_FUNCTION (this);
188  NS_ASSERT_MSG (m_arrivalTime != Time (0), "Arrival time must be different from 0");
189 
190  // Stats
191  m_txPdus++;
192  m_txBytes += m_pduSize;
194 
196  p.rnti = 1111;
197  p.lcid = 222;
198  p.pdcpSdu = Create<Packet> (m_pduSize);
199 
202 // Simulator::Run ();
203 }
204 
205 void
207 {
208  NS_LOG_FUNCTION (this);
209  m_nextPdu.Cancel ();
210 }
211 
212 void
213 LteTestRrc::SendData (Time at, std::string dataToSend)
214 {
215  NS_LOG_FUNCTION (this << at << dataToSend.length () << dataToSend);
216 
217  // Stats
218  m_txPdus++;
219  m_txBytes += dataToSend.length ();
220 
222  p.rnti = 1111;
223  p.lcid = 222;
224 
225  NS_LOG_LOGIC ("Data(" << dataToSend.length () << ") = " << dataToSend.data ());
226  p.pdcpSdu = Create<Packet> ((uint8_t *) dataToSend.data (), dataToSend.length ());
227 
228  NS_LOG_LOGIC ("Packet(" << p.pdcpSdu->GetSize () << ")");
230 }
231 
233 
234 TypeId
236 {
237  static TypeId tid = TypeId ("ns3::LteTestPdcp")
238  .SetParent<Object> ()
239  .AddConstructor<LteTestPdcp> ()
240  ;
241 
242  return tid;
243 }
244 
246 {
247  NS_LOG_FUNCTION (this);
250 }
251 
253 {
254  NS_LOG_FUNCTION (this);
255 }
256 
257 void
259 {
260  NS_LOG_FUNCTION (this);
261  delete m_rlcSapUser;
262 }
263 
264 void
266 {
268 }
269 
272 {
273  return m_rlcSapUser;
274 }
275 
276 
277 std::string
279 {
280  NS_LOG_FUNCTION (this);
281 
282  return m_receivedData;
283 }
284 
285 
290 void
292 {
293  NS_LOG_FUNCTION (this << p->GetSize ());
294  NS_LOG_LOGIC ("Data = " << (*p));
295 
296  uint32_t dataLen = p->GetSize ();
297  uint8_t *buf = new uint8_t[dataLen];
298  p->CopyData (buf, dataLen);
299  m_receivedData = std::string ((char *)buf, dataLen);
300 
302 
303  delete [] buf;
304 }
305 
310 void
312 {
313  NS_LOG_FUNCTION (this);
314 }
315 
316 void
317 LteTestPdcp::SendData (Time time, std::string dataToSend)
318 {
319  NS_LOG_FUNCTION (this << time << dataToSend.length () << dataToSend);
320 
322  p.rnti = 1111;
323  p.lcid = 222;
324 
325  NS_LOG_LOGIC ("Data(" << dataToSend.length () << ") = " << dataToSend.data ());
326  p.pdcpPdu = Create<Packet> ((uint8_t *) dataToSend.data (), dataToSend.length ());
327 
328  NS_LOG_LOGIC ("Packet(" << p.pdcpPdu->GetSize () << ")");
330 }
331 
333 
334 TypeId
336 {
337  static TypeId tid = TypeId ("ns3::LteTestMac")
338  .SetParent<Object> ()
339  .AddConstructor<LteTestMac> ()
340  ;
341 
342  return tid;
343 }
344 
346 {
347  NS_LOG_FUNCTION (this);
348  m_device = 0;
350  m_macSapUser = 0;
351  m_macLoopback = 0;
352  m_pdcpHeaderPresent = false;
355  m_txOppTime = Seconds (0.001);
356  m_txOppSize = 0;
357 
358  m_txPdus = 0;
359  m_txBytes = 0;
360  m_rxPdus = 0;
361  m_rxBytes = 0;
362 
363 // m_cmacSapProvider = new EnbMacMemberLteEnbCmacSapProvider (this);
364 // m_schedSapUser = new EnbMacMemberFfMacSchedSapUser (this);
365 // m_cschedSapUser = new EnbMacMemberFfMacCschedSapUser (this);
366 // m_enbPhySapUser = new EnbMacMemberLteEnbPhySapUser (this);
367 }
368 
370 {
371  NS_LOG_FUNCTION (this);
372 }
373 
374 void
376 {
377  NS_LOG_FUNCTION (this);
378  delete m_macSapProvider;
379 // delete m_cmacSapProvider;
380 // delete m_schedSapUser;
381 // delete m_cschedSapUser;
382 // delete m_enbPhySapUser;
383 
384  m_device = 0;
385 }
386 
387 void
389 {
390  m_device = device;
391 }
392 
393 void
395 {
396  m_macSapUser = s;
397 }
398 
401 {
402  return m_macSapProvider;
403 }
404 
405 void
407 {
408  m_macLoopback = s;
409 }
410 
411 std::string
413 {
414  NS_LOG_FUNCTION (this);
415  return m_receivedData;
416 }
417 
418 // Stats
419 uint32_t
421 {
422  NS_LOG_FUNCTION (this << m_txPdus);
423  return m_txPdus;
424 }
425 
426 uint32_t
428 {
429  NS_LOG_FUNCTION (this << m_txBytes);
430  return m_txBytes;
431 }
432 
433 uint32_t
435 {
436  NS_LOG_FUNCTION (this << m_rxPdus);
437  return m_rxPdus;
438 }
439 
440 uint32_t
442 {
443  NS_LOG_FUNCTION (this << m_rxBytes);
444  return m_rxBytes;
445 }
446 
447 
448 void
449 LteTestMac::SendTxOpportunity (Time time, uint32_t bytes)
450 {
451  NS_LOG_FUNCTION (this << time << bytes);
454  {
455  if (m_txOppTime != Seconds (0))
456  {
458  }
459  }
460 }
461 
462 void
464 {
465  NS_LOG_FUNCTION (this << present);
466  m_pdcpHeaderPresent = present;
467 }
468 
469 void
470 LteTestMac::SetRlcHeaderType (uint8_t rlcHeaderType)
471 {
472  NS_LOG_FUNCTION (this << rlcHeaderType);
473  m_rlcHeaderType = rlcHeaderType;
474 }
475 
476 void
478 {
479  NS_LOG_FUNCTION (this << (uint32_t)mode);
480  m_txOpportunityMode = mode;
481 
483  {
484  if (m_txOppTime != Seconds (0.0))
485  {
487  }
488  }
489 }
490 
491 void
493 {
494  NS_LOG_FUNCTION (this << txOppTime);
495  m_txOppTime = txOppTime;
496 }
497 
498 void
499 LteTestMac::SetTxOppSize (uint32_t txOppSize)
500 {
501  NS_LOG_FUNCTION (this << txOppSize);
502  m_txOppSize = txOppSize;
503 }
504 
505 
510 void
512 {
513  NS_LOG_FUNCTION (this << params.pdu->GetSize ());
514 
515  m_txPdus++;
516  m_txBytes += params.pdu->GetSize ();
517 
518  if (m_device)
519  {
520  m_device->Send (params.pdu, m_device->GetBroadcast (), 0);
521  }
522  else if (m_macLoopback)
523  {
525  m_macLoopback->m_macSapUser, params.pdu);
526  }
527  else
528  {
529  LtePdcpHeader pdcpHeader;
530 
532  {
533  // Remove AM RLC header
534  LteRlcAmHeader rlcAmHeader;
535  params.pdu->RemoveHeader (rlcAmHeader);
536  NS_LOG_LOGIC ("AM RLC header: " << rlcAmHeader);
537  }
538  else // if (m_rlcHeaderType == UM_RLC_HEADER)
539  {
540  // Remove UM RLC header
541  LteRlcHeader rlcHeader;
542  params.pdu->RemoveHeader (rlcHeader);
543  NS_LOG_LOGIC ("UM RLC header: " << rlcHeader);
544  }
545 
546  // Remove PDCP header, if present
548  {
549  params.pdu->RemoveHeader (pdcpHeader);
550  NS_LOG_LOGIC ("PDCP header: " << pdcpHeader);
551  }
552 
553  // Copy data to a string
554  uint32_t dataLen = params.pdu->GetSize ();
555  uint8_t *buf = new uint8_t[dataLen];
556  params.pdu->CopyData (buf, dataLen);
557  m_receivedData = std::string ((char *)buf, dataLen);
558 
559  NS_LOG_LOGIC ("Data (" << dataLen << ") = " << m_receivedData);
560  delete [] buf;
561  }
562 }
563 
564 void
566 {
567  NS_LOG_FUNCTION (this << params.txQueueSize << params.retxQueueSize << params.statusPduSize);
568 
570  {
571  if (params.statusPduSize)
572  {
574  m_macSapUser, params.statusPduSize + 2, 0, 0);
575  }
576  else if (params.txQueueSize)
577  {
579  m_macSapUser, params.txQueueSize + 2, 0, 0);
580  }
581  else if (params.retxQueueSize)
582  {
584  m_macSapUser, params.retxQueueSize + 2, 0, 0);
585  }
586  }
587 }
588 
589 
590 bool
591 LteTestMac::Receive (Ptr<NetDevice> nd, Ptr<const Packet> p, uint16_t protocol, const Address& addr)
592 {
593  NS_LOG_FUNCTION (this << addr << protocol << p->GetSize ());
594 
595  m_rxPdus++;
596  m_rxBytes += p->GetSize ();
597 
598  Ptr<Packet> packet = p->Copy ();
599  m_macSapUser->ReceivePdu (packet);
600  return true;
601 }
602 
603 
604 
605 
606 
607 
608 
609 
611 
613  : m_s1SapProvider (0)
614 {
615  NS_LOG_FUNCTION (this);
617 }
618 
619 
621 {
622  NS_LOG_FUNCTION (this);
623 }
624 
625 
626 void
628 {
629  NS_LOG_FUNCTION (this);
630  delete m_s1SapUser;
631 }
632 
633 TypeId
635 {
636  NS_LOG_FUNCTION ("EpcTestRrc::GetTypeId");
637  static TypeId tid = TypeId ("ns3::EpcTestRrc")
638  .SetParent<Object> ()
639  .AddConstructor<EpcTestRrc> ()
640  ;
641  return tid;
642 }
643 void
645 {
646  m_s1SapProvider = s;
647 }
648 
649 
652 {
653  return m_s1SapUser;
654 }
655 
656 void
658 {
659 
660 }
661 
662 void
664 {
665 
666 }
667 
668 
669 } // namespace ns3
670 
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:95
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 an Object subclass with the TypeId system.
Definition: object-base.h:44
void DoReportBufferStatus(LteMacSapProvider::ReportBufferStatusParameters)
virtual void DoDispose(void)
Destructor implementation.
LteMacSapProvider * m_macSapProvider
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
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:766
virtual void DoDispose(void)
Destructor implementation.
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:819
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:90
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:252
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)
Destructor implementation.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:980
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 virtual time.
Definition: simulator.cc:223
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)
Destructor implementation.
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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
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:53
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:368
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:87
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:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
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