5G-LENA nr-v4.0
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-ue-net-device.cc
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#include "nr-ue-net-device.h"
6
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"
13#include "nr-ue-mac.h"
14#include "nr-ue-phy.h"
15#include "nr-ue-rrc.h"
16
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"
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("NrUeNetDevice");
26
27NS_OBJECT_ENSURE_REGISTERED(NrUeNetDevice);
28
29TypeId
31{
32 static TypeId tid =
33 TypeId("ns3::NrUeNetDevice")
34 .SetParent<NrNetDevice>()
35 .AddConstructor<NrUeNetDevice>()
36 .AddAttribute("NrEpcUeNas",
37 "The NAS associated to this UeNetDevice",
38 PointerValue(),
39 MakePointerAccessor(&NrUeNetDevice::m_nas),
40 MakePointerChecker<NrEpcUeNas>())
41 .AddAttribute("nrUeRrc",
42 "The RRC associated to this UeNetDevice",
43 PointerValue(),
44 MakePointerAccessor(&NrUeNetDevice::m_rrc),
45 MakePointerChecker<NrUeRrc>())
46 .AddAttribute("Imsi",
47 "International Mobile Subscriber Identity assigned to this UE",
48 UintegerValue(0),
49 MakeUintegerAccessor(&NrUeNetDevice::SetImsi, &NrUeNetDevice::GetImsi),
50 MakeUintegerChecker<uint64_t>())
51 .AddAttribute(
52 "PrimaryDlIndex",
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.",
55 UintegerValue(0),
56 MakeUintegerAccessor(&NrUeNetDevice::m_primaryDlIndex),
57 MakeUintegerChecker<uint16_t>())
58 .AddAttribute(
59 "PrimaryUlIndex",
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.",
62 UintegerValue(0),
63 MakeUintegerAccessor(&NrUeNetDevice::m_primaryUlIndex),
64 MakeUintegerChecker<uint16_t>())
65 .AddAttribute("NrUeRrc",
66 "The RRC layer associated with the gNB",
67 PointerValue(),
68 MakePointerAccessor(&NrUeNetDevice::m_rrc),
69 MakePointerChecker<NrUeRrc>())
70 .AddAttribute("NrUeComponentCarrierManager",
71 "The ComponentCarrierManager associated to this UeNetDevice",
72 PointerValue(),
73 MakePointerAccessor(&NrUeNetDevice::m_componentCarrierManager),
74 MakePointerChecker<NrUeComponentCarrierManager>())
75 .AddAttribute("ComponentCarrierMapUe",
76 "List of all component Carrier.",
77 ObjectMapValue(),
78 MakeObjectMapAccessor(&NrUeNetDevice::m_ccMap),
79 MakeObjectMapChecker<BandwidthPartUe>())
80 .AddAttribute("InitAssoc",
81 "Pointer to nr Initial Accos",
82 PointerValue(),
83 MakePointerAccessor(&NrUeNetDevice::m_nrInitAcc),
84 MakePointerChecker<NrInitialAssociation>());
85 return tid;
86}
87
89{
90 NS_LOG_FUNCTION(this);
91}
92
96
97void
98NrUeNetDevice::DoInitialize()
99{
100 NS_LOG_FUNCTION(this);
101 // While these may have been previously set, the values may not
102 // have propagated to the other objects depending on whether they
103 // had been created upon the previous setting time.
104 m_nas->SetImsi(m_imsi);
105 m_rrc->SetImsi(m_imsi);
106 m_nas->SetCsgId(m_csgId); // this also handles propagation to RRC
107}
108
109void
110NrUeNetDevice::DoDispose()
111{
112 NS_LOG_FUNCTION(this);
113 m_rrc->Dispose();
114 m_rrc = nullptr;
115
116 m_targetGnb = nullptr;
117 m_nas->Dispose();
118 m_nas = nullptr;
119 for (const auto& it : m_ccMap)
120 {
121 it.second->Dispose();
122 }
123 m_ccMap.clear();
124 m_componentCarrierManager->Dispose();
125 m_componentCarrierManager = nullptr;
126 m_nrInitAcc = nullptr;
127 NrNetDevice::DoDispose();
128}
129
130std::map<uint8_t, Ptr<BandwidthPartUe>>
132{
133 NS_LOG_FUNCTION(this);
134 return m_ccMap;
135}
136
137uint32_t
139{
140 NS_LOG_FUNCTION(this);
141 return m_ccMap.size();
142}
143
144void
146{
147 NS_LOG_FUNCTION(this);
148
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);
153}
154
155void
156NrUeNetDevice::RouteIngoingCtrlMsgs(const std::list<Ptr<NrControlMessage>>& msgList,
157 uint8_t sourceBwpId)
158{
159 NS_LOG_FUNCTION(this);
160
161 for (const auto& msg : msgList)
162 {
163 uint8_t bwpId = DynamicCast<BwpManagerUe>(m_componentCarrierManager)
164 ->RouteIngoingCtrlMsg(msg, sourceBwpId);
165 m_ccMap.at(bwpId)->GetPhy()->PhyCtrlMessagesReceived(msg);
166 }
167}
168
169void
170NrUeNetDevice::RouteOutgoingCtrlMsgs(const std::list<Ptr<NrControlMessage>>& msgList,
171 uint8_t sourceBwpId)
172{
173 NS_LOG_FUNCTION(this);
174
175 for (const auto& msg : msgList)
176 {
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");
181 NS_ASSERT_MSG(
182 m_ccMap.at(bwpId)->GetPhy()->HasUlSlot(),
183 "Returned bwp "
184 << +bwpId
185 << " has no UL slot, so the message can't go out. Check your configuration");
186 m_ccMap.at(bwpId)->GetPhy()->EncodeCtrlMsg(msg);
187 }
188}
189
190void
191NrUeNetDevice::SetCcMap(std::map<uint8_t, Ptr<BandwidthPartUe>> ccm)
192{
193 NS_LOG_FUNCTION(this);
194 NS_ABORT_IF(!m_ccMap.empty());
195 m_ccMap = ccm;
196}
197
198uint32_t
200{
201 NS_LOG_FUNCTION(this);
202 return m_csgId;
203}
204
205void
207{
208 NS_LOG_FUNCTION(this << csgId);
209 m_csgId = csgId;
210 if (m_nas)
211 {
212 m_nas->SetCsgId(m_csgId); // this also handles propagation to RRC
213 }
214}
215
216Ptr<NrUeMac>
217NrUeNetDevice::GetMac(uint8_t index) const
218{
219 NS_LOG_FUNCTION(this);
220 return m_ccMap.at(index)->GetMac();
221}
222
223void
225{
226 NS_LOG_FUNCTION(this);
227}
228
229bool
230NrUeNetDevice::DoSend(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
231{
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);
238}
239
240Ptr<NrUePhy>
241NrUeNetDevice::GetPhy(uint8_t index) const
242{
243 NS_LOG_FUNCTION(this);
244 return m_ccMap.at(index)->GetPhy();
245}
246
247Ptr<BwpManagerUe>
249{
250 NS_LOG_FUNCTION(this);
251 return DynamicCast<BwpManagerUe>(m_componentCarrierManager);
252}
253
254Ptr<NrEpcUeNas>
256{
257 NS_LOG_FUNCTION(this);
258 return m_nas;
259}
260
261Ptr<NrUeRrc>
263{
264 NS_LOG_FUNCTION(this);
265 return m_rrc;
266}
267
268void
270{
271 NS_LOG_FUNCTION(this << imsi);
272 m_imsi = imsi;
273 if (m_nas)
274 {
275 m_nas->SetImsi(imsi);
276 }
277 if (m_rrc)
278 {
279 m_rrc->SetImsi(imsi);
280 }
281}
282
283uint64_t
285{
286 NS_LOG_FUNCTION(this);
287 return m_imsi;
288}
289
290uint16_t
292{
293 auto gnb = GetTargetGnb();
294 if (gnb)
295 {
296 return GetTargetGnb()->GetCellId();
297 }
298 else
299 {
300 return UINT16_MAX;
301 }
302}
303
304void
305NrUeNetDevice::SetInitAssoc(Ptr<NrInitialAssociation> initAssoc)
306{
307 NS_LOG_FUNCTION(this);
308 m_nrInitAcc = initAssoc;
309}
310
311void
312NrUeNetDevice::SetTargetGnb(Ptr<NrGnbNetDevice> gnb)
313{
314 NS_LOG_FUNCTION(this);
315 m_targetGnb = gnb;
316}
317
318Ptr<const NrGnbNetDevice>
320{
321 NS_LOG_FUNCTION(this);
322 return m_targetGnb;
323}
324
325} // namespace ns3
The NrNetDevice class.
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.