9#include "nr-test-entities.h"
13#include "ns3/nr-pdcp-header.h"
14#include "ns3/nr-rlc-am-header.h"
15#include "ns3/nr-rlc-header.h"
16#include "ns3/simulator.h"
21NS_LOG_COMPONENT_DEFINE(
"NrTestEntities");
28 static TypeId tid = TypeId(
"ns3::NrTestRrc").SetParent<Object>().AddConstructor<NrTestRrc>();
35 NS_LOG_FUNCTION(
this);
41 m_txLastTime = Time(0);
42 m_rxLastTime = Time(0);
48NrTestRrc::~NrTestRrc()
50 NS_LOG_FUNCTION(
this);
56 NS_LOG_FUNCTION(
this);
69 m_pdcpSapProvider = s;
81 NS_LOG_FUNCTION(
this);
82 return m_receivedData;
89 NS_LOG_FUNCTION(
this << m_txPdus);
96 NS_LOG_FUNCTION(
this << m_txBytes);
103 NS_LOG_FUNCTION(
this << m_rxPdus);
110 NS_LOG_FUNCTION(
this << m_rxBytes);
117 NS_LOG_FUNCTION(
this << m_txLastTime);
124 NS_LOG_FUNCTION(
this << m_rxLastTime);
131 NS_LOG_FUNCTION(
this << arrivalTime);
132 m_arrivalTime = arrivalTime;
138 NS_LOG_FUNCTION(
this << pduSize);
149 NS_LOG_FUNCTION(
this << params.
pdcpSdu->GetSize());
150 Ptr<Packet> p = params.
pdcpSdu;
153 uint32_t dataLen = p->GetSize();
154 auto buf =
new uint8_t[dataLen];
158 m_rxBytes += dataLen;
159 m_rxLastTime = Simulator::Now();
161 p->CopyData(buf, dataLen);
162 m_receivedData = std::string((
char*)buf, dataLen);
176 NS_LOG_FUNCTION(
this);
177 NS_ASSERT_MSG(m_arrivalTime != Time(0),
"Arrival time must be different from 0");
181 m_txBytes += m_pduSize;
182 m_txLastTime = Simulator::Now();
187 p.
pdcpSdu = Create<Packet>(m_pduSize);
189 bool haveContext =
false;
193 node = m_device->GetNode();
201 Simulator::ScheduleWithContext(node->GetId(),
219 NS_LOG_FUNCTION(
this);
226 NS_LOG_FUNCTION(
this << at << dataToSend.length() << dataToSend);
230 m_txBytes += dataToSend.length();
236 NS_LOG_LOGIC(
"Data(" << dataToSend.length() <<
") = " << dataToSend.data());
237 p.
pdcpSdu = Create<Packet>((uint8_t*)dataToSend.data(), dataToSend.length());
239 NS_LOG_LOGIC(
"Packet(" << p.
pdcpSdu->GetSize() <<
")");
248 static TypeId tid = TypeId(
"ns3::NrTestPdcp").SetParent<Object>().AddConstructor<NrTestPdcp>();
253NrTestPdcp::NrTestPdcp()
255 NS_LOG_FUNCTION(
this);
260NrTestPdcp::~NrTestPdcp()
262 NS_LOG_FUNCTION(
this);
266NrTestPdcp::DoDispose()
268 NS_LOG_FUNCTION(
this);
275 m_rlcSapProvider = s;
287 NS_LOG_FUNCTION(
this);
289 return m_receivedData;
297NrTestPdcp::DoReceivePdcpPdu(Ptr<Packet> p)
299 NS_LOG_FUNCTION(
this << p->GetSize());
300 NS_LOG_LOGIC(
"Data = " << (*p));
302 uint32_t dataLen = p->GetSize();
303 auto buf =
new uint8_t[dataLen];
304 p->CopyData(buf, dataLen);
305 m_receivedData = std::string((
char*)buf, dataLen);
307 NS_LOG_LOGIC(m_receivedData);
319 NS_LOG_FUNCTION(
this);
325 NS_LOG_FUNCTION(
this << time << dataToSend.length() << dataToSend);
331 NS_LOG_LOGIC(
"Data(" << dataToSend.length() <<
") = " << dataToSend.data());
332 p.
pdcpPdu = Create<Packet>((uint8_t*)dataToSend.data(), dataToSend.length());
334 NS_LOG_LOGIC(
"Packet(" << p.
pdcpPdu->GetSize() <<
")");
343 static TypeId tid = TypeId(
"ns3::NrTestMac").SetParent<Object>().AddConstructor<NrTestMac>();
348NrTestMac::NrTestMac()
350 NS_LOG_FUNCTION(
this);
353 m_macSapUser =
nullptr;
354 m_macLoopback =
nullptr;
355 m_pdcpHeaderPresent =
false;
356 m_rlcHeaderType = UM_RLC_HEADER;
357 m_txOpportunityMode = MANUAL_MODE;
358 m_txOppTime = Seconds(0.001);
372NrTestMac::~NrTestMac()
374 NS_LOG_FUNCTION(
this);
378NrTestMac::DoDispose()
380 NS_LOG_FUNCTION(
this);
381 delete m_macSapProvider;
405 return m_macSapProvider;
417 NS_LOG_FUNCTION(
this);
418 return m_receivedData;
425 NS_LOG_FUNCTION(
this << m_txPdus);
432 NS_LOG_FUNCTION(
this << m_txBytes);
439 NS_LOG_FUNCTION(
this << m_rxPdus);
446 NS_LOG_FUNCTION(
this << m_rxBytes);
453 NS_LOG_FUNCTION(
this << time << bytes);
454 bool haveContext =
false;
458 node = m_device->GetNode();
465 txOpParams.
bytes = bytes;
466 txOpParams.
layer = 0;
474 Simulator::ScheduleWithContext(node->GetId(),
485 if (m_txOpportunityMode == RANDOM_MODE)
487 if (m_txOppTime != Seconds(0))
489 Simulator::Schedule(m_txOppTime,
501 NS_LOG_FUNCTION(
this << present);
502 m_pdcpHeaderPresent = present;
508 NS_LOG_FUNCTION(
this << rlcHeaderType);
509 m_rlcHeaderType = rlcHeaderType;
515 NS_LOG_FUNCTION(
this << (uint32_t)mode);
516 m_txOpportunityMode = mode;
518 if (m_txOpportunityMode == RANDOM_MODE)
520 if (m_txOppTime != Seconds(0.0))
530 NS_LOG_FUNCTION(
this << txOppTime);
531 m_txOppTime = txOppTime;
537 NS_LOG_FUNCTION(
this << txOppSize);
538 m_txOppSize = txOppSize;
548 NS_LOG_FUNCTION(
this << params.
pdu->GetSize());
551 m_txBytes += params.
pdu->GetSize();
554 rxPduParams.
p = params.
pdu;
560 m_device->Send(params.
pdu, m_device->GetBroadcast(), 0);
562 else if (m_macLoopback)
564 Simulator::Schedule(Seconds(0.1),
566 m_macLoopback->m_macSapUser,
571 NrPdcpHeader pdcpHeader;
573 if (m_rlcHeaderType == AM_RLC_HEADER)
576 NrRlcAmHeader rlcAmHeader;
577 params.
pdu->RemoveHeader(rlcAmHeader);
578 NS_LOG_LOGIC(
"AM RLC header: " << rlcAmHeader);
583 NrRlcHeader rlcHeader;
584 params.
pdu->RemoveHeader(rlcHeader);
585 NS_LOG_LOGIC(
"UM RLC header: " << rlcHeader);
589 if (m_pdcpHeaderPresent)
591 params.
pdu->RemoveHeader(pdcpHeader);
592 NS_LOG_LOGIC(
"PDCP header: " << pdcpHeader);
596 uint32_t dataLen = params.
pdu->GetSize();
597 auto buf =
new uint8_t[dataLen];
598 params.
pdu->CopyData(buf, dataLen);
599 m_receivedData = std::string((
char*)buf, dataLen);
601 NS_LOG_LOGIC(
"Data (" << dataLen <<
") = " << m_receivedData);
607NrTestMac::DoTransmitBufferStatusReport(NrMacSapProvider::BufferStatusReportParameters params)
609 NS_LOG_FUNCTION(
this << params.txQueueSize << params.retxQueueSize << params.statusPduSize);
611 if (m_txOpportunityMode == AUTOMATIC_MODE)
614 for (
auto it = m_nextTxOppList.begin(); it != m_nextTxOppList.end(); ++it)
618 m_nextTxOppList.clear();
620 int32_t size = params.statusPduSize + params.txQueueSize + params.retxQueueSize;
621 Time time = m_txOppTime;
622 NrMacSapUser::TxOpportunityParameters txOpParams;
623 txOpParams.bytes = m_txOppSize;
624 txOpParams.layer = 0;
625 txOpParams.componentCarrierId = 0;
626 txOpParams.harqId = 0;
627 txOpParams.rnti = params.rnti;
628 txOpParams.lcid = params.lcid;
631 EventId e = Simulator::Schedule(time,
635 m_nextTxOppList.push_back(e);
645 NS_LOG_FUNCTION(
this << addr << protocol << p->GetSize());
648 m_rxBytes += p->GetSize();
650 Ptr<Packet> packet = p->Copy();
652 rxPduParams.
p = packet;
653 rxPduParams.
rnti = 0;
654 rxPduParams.
lcid = 0;
661NrEpcTestRrc::NrEpcTestRrc()
662 : m_s1SapProvider(nullptr)
664 NS_LOG_FUNCTION(
this);
668NrEpcTestRrc::~NrEpcTestRrc()
670 NS_LOG_FUNCTION(
this);
674NrEpcTestRrc::DoDispose()
676 NS_LOG_FUNCTION(
this);
683 NS_LOG_FUNCTION(
"NrEpcTestRrc::GetTypeId");
685 TypeId(
"ns3::NrEpcTestRrc").SetParent<Object>().AddConstructor<NrEpcTestRrc>();
702NrEpcTestRrc::DoInitialContextSetupRequest(
708NrEpcTestRrc::DoDataRadioBearerSetupRequest(
709 NrEpcGnbS1SapUser::DataRadioBearerSetupRequestParameters request)
714NrEpcTestRrc::DoPathSwitchRequestAcknowledge(
715 NrEpcGnbS1SapUser::PathSwitchRequestAcknowledgeParameters params)
RRC stub providing a testing S1 SAP user to be used with the NrEpcGnbApplication.
NrEpcGnbS1SapUser * GetS1SapUser()
static TypeId GetTypeId()
Get the type ID.
void SetS1SapProvider(NrEpcGnbS1SapProvider *s)
virtual void NotifyTxOpportunity(TxOpportunityParameters params)=0
virtual void ReceivePdu(ReceivePduParameters params)=0
virtual void TransmitPdcpSdu(TransmitPdcpSduParameters params)=0
virtual void TransmitPdcpPdu(TransmitPdcpPduParameters params)=0
void SendTxOpportunity(Time time, uint32_t bytes)
Send transmit opportunity function.
void SetTxOppTime(Time txOppTime)
uint32_t GetRxPdus()
Get the receive PDUs.
void SetNrMacLoopback(Ptr< NrTestMac > s)
Set the other side of the MAC Loopback.
NrMacSapProvider * GetNrMacSapProvider()
Get the MAC SAP provider.
void SetNrMacSapUser(NrMacSapUser *s)
Set the MAC SAP user.
void SetPdcpHeaderPresent(bool present)
Set PDCP header present function.
void SetDevice(Ptr< NetDevice > device)
Set the device function.
void SetTxOpportunityMode(uint8_t mode)
static TypeId GetTypeId()
Get the type ID.
void SetTxOppSize(uint32_t txOppSize)
bool Receive(Ptr< NetDevice > nd, Ptr< const Packet > p, uint16_t protocol, const Address &addr)
the Receive function
uint32_t GetRxBytes()
Get the receive bytes.
friend class GnbMacMemberNrMacSapProvider< NrTestMac >
allow GnbMacMemberNrMacSapProvider<NrTestMac> class friend access
std::string GetDataReceived()
Get data received function.
void SetRlcHeaderType(uint8_t rlcHeaderType)
Set RLC header type.
uint32_t GetTxPdus()
Get the transmit PDUs.
uint32_t GetTxBytes()
Get the transmit bytes.
void Start()
Start function.
void SetNrRlcSapProvider(NrRlcSapProvider *s)
Set the RLC SAP provider.
static TypeId GetTypeId()
Get the type ID.
std::string GetDataReceived()
Get data received function.
friend class NrRlcSpecificNrRlcSapUser< NrTestPdcp >
allow NrRlcSpecificNrRlcSapUser<NrTestPdcp> class friend access
NrRlcSapUser * GetNrRlcSapUser()
Get the RLC SAP user.
void SendData(Time time, std::string dataToSend)
Send data function.
void Stop()
Stop function.
static TypeId GetTypeId()
Get the type ID.
void SetPduSize(uint32_t pduSize)
Set the PDU size.
Time GetRxLastTime()
Get the last receive time.
uint32_t GetTxPdus()
Get the transmit PDUs.
uint32_t GetRxPdus()
Get the receive PDUs.
uint32_t GetTxBytes()
Get the transmit bytes.
void SetNrPdcpSapProvider(NrPdcpSapProvider *s)
Set the PDCP SAP provider.
uint32_t GetRxBytes()
Get the receive bytes.
std::string GetDataReceived()
Get data received function.
NrPdcpSapUser * GetNrPdcpSapUser()
Get the PDCP SAP user.
void SetArrivalTime(Time arrivalTime)
Set the arrival time.
void Start()
Start function.
friend class NrPdcpSpecificNrPdcpSapUser< NrTestRrc >
allow NrPdcpSpecificNrPdcpSapUser<NrTestRrc> class friend access
Time GetTxLastTime()
Get the last transmit time.
void SendData(Time at, std::string dataToSend)
Send data function.
void SetDevice(Ptr< NetDevice > device)
Set the device.
uint8_t componentCarrierId