5#include "nr-ue-net-device.h"
7#include "bandwidth-part-ue.h"
8#include "bwp-manager-ue.h"
9#include "nr-epc-ue-nas.h"
10#include "nr-gnb-net-device.h"
11#include "nr-initial-association.h"
12#include "nr-ue-component-carrier-manager.h"
17#include "ns3/ipv4-l3-protocol.h"
18#include "ns3/ipv6-l3-protocol.h"
19#include "ns3/object-map.h"
20#include "ns3/pointer.h"
25NS_LOG_COMPONENT_DEFINE(
"NrUeNetDevice");
27NS_OBJECT_ENSURE_REGISTERED(NrUeNetDevice);
33 TypeId(
"ns3::NrUeNetDevice")
35 .AddConstructor<NrUeNetDevice>()
36 .AddAttribute(
"NrEpcUeNas",
37 "The NAS associated to this UeNetDevice",
39 MakePointerAccessor(&NrUeNetDevice::m_nas),
40 MakePointerChecker<NrEpcUeNas>())
41 .AddAttribute(
"nrUeRrc",
42 "The RRC associated to this UeNetDevice",
44 MakePointerAccessor(&NrUeNetDevice::m_rrc),
45 MakePointerChecker<NrUeRrc>())
47 "International Mobile Subscriber Identity assigned to this UE",
50 MakeUintegerChecker<uint64_t>())
53 "The index of DL PHY/MAC that will be used as the primary DL PHY/MAC."
54 "This is needed because UE RRC needs to know which DL PHY/MAC pair is primary.",
56 MakeUintegerAccessor(&NrUeNetDevice::m_primaryDlIndex),
57 MakeUintegerChecker<uint16_t>())
60 "The index of UL PHY/MAC that will be used as the primary UL PHY/MAC."
61 "This is needed because UE RRC needs to know which UL PHY/MAC pair is primary.",
63 MakeUintegerAccessor(&NrUeNetDevice::m_primaryUlIndex),
64 MakeUintegerChecker<uint16_t>())
65 .AddAttribute(
"NrUeRrc",
66 "The RRC layer associated with the gNB",
68 MakePointerAccessor(&NrUeNetDevice::m_rrc),
69 MakePointerChecker<NrUeRrc>())
70 .AddAttribute(
"NrUeComponentCarrierManager",
71 "The ComponentCarrierManager associated to this UeNetDevice",
73 MakePointerAccessor(&NrUeNetDevice::m_componentCarrierManager),
74 MakePointerChecker<NrUeComponentCarrierManager>())
75 .AddAttribute(
"ComponentCarrierMapUe",
76 "List of all component Carrier.",
78 MakeObjectMapAccessor(&NrUeNetDevice::m_ccMap),
79 MakeObjectMapChecker<BandwidthPartUe>())
80 .AddAttribute(
"InitAssoc",
81 "Pointer to nr Initial Accos",
83 MakePointerAccessor(&NrUeNetDevice::m_nrInitAcc),
84 MakePointerChecker<NrInitialAssociation>());
90 NS_LOG_FUNCTION(
this);
98NrUeNetDevice::DoInitialize()
100 NS_LOG_FUNCTION(
this);
104 m_nas->SetImsi(m_imsi);
105 m_rrc->SetImsi(m_imsi);
106 m_nas->SetCsgId(m_csgId);
110NrUeNetDevice::DoDispose()
112 NS_LOG_FUNCTION(
this);
116 m_targetGnb =
nullptr;
119 for (
const auto& it : m_ccMap)
121 it.second->Dispose();
124 m_componentCarrierManager->Dispose();
125 m_componentCarrierManager =
nullptr;
126 m_nrInitAcc =
nullptr;
127 NrNetDevice::DoDispose();
130std::map<uint8_t, Ptr<BandwidthPartUe>>
133 NS_LOG_FUNCTION(
this);
140 NS_LOG_FUNCTION(
this);
141 return m_ccMap.size();
147 NS_LOG_FUNCTION(
this);
149 auto ccManager = DynamicCast<BwpManagerUe>(m_componentCarrierManager);
150 NS_ASSERT(ccManager !=
nullptr);
151 uint8_t index = ccManager->RouteDlHarqFeedback(m);
152 m_ccMap.at(index)->GetPhy()->EnqueueDlHarqFeedback(m);
159 NS_LOG_FUNCTION(
this);
161 for (
const auto& msg : msgList)
163 uint8_t bwpId = DynamicCast<BwpManagerUe>(m_componentCarrierManager)
164 ->RouteIngoingCtrlMsg(msg, sourceBwpId);
165 m_ccMap.at(bwpId)->GetPhy()->PhyCtrlMessagesReceived(msg);
173 NS_LOG_FUNCTION(
this);
175 for (
const auto& msg : msgList)
177 uint8_t bwpId = DynamicCast<BwpManagerUe>(m_componentCarrierManager)
178 ->RouteOutgoingCtrlMsg(msg, sourceBwpId);
179 NS_ASSERT_MSG(m_ccMap.size() > bwpId,
180 "Returned bwp " << +bwpId <<
" is not present. Check your configuration");
182 m_ccMap.at(bwpId)->GetPhy()->HasUlSlot(),
185 <<
" has no UL slot, so the message can't go out. Check your configuration");
186 m_ccMap.at(bwpId)->GetPhy()->EncodeCtrlMsg(msg);
193 NS_LOG_FUNCTION(
this);
194 NS_ABORT_IF(!m_ccMap.empty());
201 NS_LOG_FUNCTION(
this);
208 NS_LOG_FUNCTION(
this << csgId);
212 m_nas->SetCsgId(m_csgId);
219 NS_LOG_FUNCTION(
this);
220 return m_ccMap.at(index)->GetMac();
226 NS_LOG_FUNCTION(
this);
230NrUeNetDevice::DoSend(Ptr<Packet> packet,
const Address& dest, uint16_t protocolNumber)
232 NS_LOG_FUNCTION(
this << packet << dest << protocolNumber);
233 NS_ABORT_MSG_IF(protocolNumber != Ipv4L3Protocol::PROT_NUMBER &&
234 protocolNumber != Ipv6L3Protocol::PROT_NUMBER,
235 "unsupported protocol " << protocolNumber
236 <<
", only IPv4 and IPv6 are supported");
237 return m_nas->Send(packet, protocolNumber);
243 NS_LOG_FUNCTION(
this);
244 return m_ccMap.at(index)->GetPhy();
250 NS_LOG_FUNCTION(
this);
251 return DynamicCast<BwpManagerUe>(m_componentCarrierManager);
257 NS_LOG_FUNCTION(
this);
264 NS_LOG_FUNCTION(
this);
271 NS_LOG_FUNCTION(
this << imsi);
275 m_nas->SetImsi(imsi);
279 m_rrc->SetImsi(imsi);
286 NS_LOG_FUNCTION(
this);
307 NS_LOG_FUNCTION(
this);
308 m_nrInitAcc = initAssoc;
314 NS_LOG_FUNCTION(
this);
318Ptr<const NrGnbNetDevice>
321 NS_LOG_FUNCTION(
this);
void UpdateConfig()
Update the RRC config. Must be called only once.
uint64_t GetImsi() const
Get the Imsi.
Ptr< NrUeRrc > GetRrc() const
Get a Rrc pointer.
uint16_t GetCellId() const
Get the CellId.
std::map< uint8_t, Ptr< BandwidthPartUe > > GetCcMap()
Get the NrComponentCarrier Map for the UE.
void RouteIngoingCtrlMsgs(const std::list< Ptr< NrControlMessage > > &msgList, uint8_t sourceBwpId)
The UE received a CTRL message list.
void SetImsi(uint64_t imsi)
Set the IMSI.
static TypeId GetTypeId()
GetTypeId.
Ptr< NrUeMac > GetMac(uint8_t index) const
Obtain a pointer to the MAC at the index specified.
Ptr< const NrGnbNetDevice > GetTargetGnb() const
Obtain a pointer to the target gnb.
void RouteOutgoingCtrlMsgs(const std::list< Ptr< NrControlMessage > > &msgList, uint8_t sourceBwpId)
Route the outgoing messages to the right BWP.
void SetTargetGnb(Ptr< NrGnbNetDevice > gnb)
Set the GNB to which this UE is attached to.
NrUeNetDevice()
NrUeNetDevice.
void SetCsgId(uint32_t csgId)
SetCsgId ?
Ptr< NrEpcUeNas > GetNas() const
Get a pointer to the Nas.
Ptr< NrUePhy > GetPhy(uint8_t index) const
Obtain a pointer to the PHY at the index specified.
void SetInitAssoc(Ptr< NrInitialAssociation > initAssoc)
Set the Nr Initial Association.
Ptr< BwpManagerUe > GetBwpManager() const
Get the bandwidth part manager.
void EnqueueDlHarqFeedback(const DlHarqInfo &m) const
Spectrum has calculated the HarqFeedback for one DL transmission, and give it to the NetDevice of the...
uint32_t GetCcMapSize() const
Get the size of the component carriers map.
uint32_t GetCsgId() const
GetCsgId ?
~NrUeNetDevice() override
~NrUeNetDevice
void SetCcMap(std::map< uint8_t, Ptr< BandwidthPartUe > > ccm)
Set the NrComponentCarrier Map for the UE.
A struct that contains info for the DL HARQ.