5#include "nr-gnb-net-device.h"
7#include "bandwidth-part-gnb.h"
8#include "bwp-manager-gnb.h"
9#include "nr-gnb-component-carrier-manager.h"
10#include "nr-gnb-mac.h"
11#include "nr-gnb-phy.h"
12#include "nr-gnb-rrc.h"
15#include <ns3/ipv4-l3-protocol.h>
16#include <ns3/ipv6-l3-protocol.h>
18#include <ns3/object-map.h>
19#include <ns3/pointer.h>
24NS_LOG_COMPONENT_DEFINE(
"NrGnbNetDevice");
26NS_OBJECT_ENSURE_REGISTERED(NrGnbNetDevice);
29NrGnbNetDevice::GetTypeId()
32 TypeId(
"ns3::NrGnbNetDevice")
34 .AddConstructor<NrGnbNetDevice>()
35 .AddAttribute(
"NrGnbComponentCarrierManager",
36 "The component carrier manager associated to this GnbNetDevice",
38 MakePointerAccessor(&NrGnbNetDevice::m_componentCarrierManager),
39 MakePointerChecker<NrGnbComponentCarrierManager>())
40 .AddAttribute(
"BandwidthPartMap",
41 "List of Bandwidth Part container.",
43 MakeObjectMapAccessor(&NrGnbNetDevice::m_ccMap),
44 MakeObjectMapChecker<BandwidthPartGnb>())
45 .AddAttribute(
"NrGnbRrc",
46 "The RRC layer associated with the gNB",
48 MakePointerAccessor(&NrGnbNetDevice::m_rrc),
49 MakePointerChecker<NrGnbRrc>());
53NrGnbNetDevice::NrGnbNetDevice()
56 NS_LOG_FUNCTION(
this);
59NrGnbNetDevice::~NrGnbNetDevice()
61 NS_LOG_FUNCTION(
this);
65NrGnbNetDevice::GetScheduler(uint8_t index)
const
67 NS_LOG_FUNCTION(
this);
68 return m_ccMap.at(index)->GetScheduler();
72NrGnbNetDevice::SetCcMap(
const std::map<uint8_t, Ptr<BandwidthPartGnb>>& ccm)
74 NS_ABORT_IF(!m_ccMap.empty());
79NrGnbNetDevice::GetCcMapSize()
const
81 return static_cast<uint32_t
>(m_ccMap.size());
85NrGnbNetDevice::SetNrFhControl(Ptr<NrFhControl> nrFh)
87 NS_LOG_FUNCTION(
this);
92NrGnbNetDevice::GetNrFhControl()
94 NS_LOG_FUNCTION(
this);
99NrGnbNetDevice::RouteIngoingCtrlMsgs(
const std::list<Ptr<NrControlMessage>>& msgList,
102 NS_LOG_FUNCTION(
this);
104 for (
const auto& msg : msgList)
106 uint8_t bwpId = DynamicCast<BwpManagerGnb>(m_componentCarrierManager)
107 ->RouteIngoingCtrlMsgs(msg, sourceBwpId);
108 m_ccMap.at(bwpId)->GetPhy()->PhyCtrlMessagesReceived(msg);
113NrGnbNetDevice::RouteOutgoingCtrlMsgs(
const std::list<Ptr<NrControlMessage>>& msgList,
116 NS_LOG_FUNCTION(
this);
118 for (
const auto& msg : msgList)
120 uint8_t bwpId = DynamicCast<BwpManagerGnb>(m_componentCarrierManager)
121 ->RouteOutgoingCtrlMsg(msg, sourceBwpId);
122 NS_ASSERT_MSG(m_ccMap.size() > bwpId,
123 "Returned bwp " << +bwpId <<
" is not present. Check your configuration");
125 m_ccMap.at(bwpId)->GetPhy()->HasDlSlot(),
128 <<
" has no DL slot, so the message can't go out. Check your configuration");
129 m_ccMap.at(bwpId)->GetPhy()->EncodeCtrlMsg(msg);
134NrGnbNetDevice::DoInitialize()
136 NS_LOG_FUNCTION(
this);
137 if (!m_isCellConfigured)
144NrGnbNetDevice::DoDispose()
146 NS_LOG_FUNCTION(
this);
150 for (
const auto& it : m_ccMap)
152 it.second->Dispose();
155 m_componentCarrierManager->Dispose();
156 m_componentCarrierManager =
nullptr;
157 NrNetDevice::DoDispose();
161NrGnbNetDevice::GetMac(uint8_t index)
const
163 return m_ccMap.at(index)->GetMac();
167NrGnbNetDevice::GetPhy(uint8_t index)
const
169 NS_LOG_FUNCTION(
this);
170 return m_ccMap.at(index)->GetPhy();
174NrGnbNetDevice::GetBwpManager()
const
176 return DynamicCast<BwpManagerGnb>(m_componentCarrierManager);
180NrGnbNetDevice::GetCellId()
const
182 NS_LOG_FUNCTION(
this);
187NrGnbNetDevice::GetCellIds()
const
189 std::vector<uint16_t> cellIds;
191 cellIds.reserve(m_ccMap.size());
192 for (
auto& it : m_ccMap)
194 cellIds.push_back(it.second->GetCellId());
200NrGnbNetDevice::SetCellId(uint16_t cellId)
202 NS_LOG_FUNCTION(
this);
207NrGnbNetDevice::GetBwpId(uint8_t index)
const
209 NS_LOG_FUNCTION(
this);
210 return m_ccMap.at(index)->GetCellId();
214NrGnbNetDevice::GetEarfcn(uint8_t index)
const
216 NS_LOG_FUNCTION(
this);
217 return m_ccMap.at(index)->GetDlEarfcn();
221NrGnbNetDevice::SetRrc(Ptr<NrGnbRrc> rrc)
227NrGnbNetDevice::GetRrc()
233NrGnbNetDevice::DoSend(Ptr<Packet> packet,
const Address& dest, uint16_t protocolNumber)
235 NS_LOG_FUNCTION(
this << packet << dest << protocolNumber);
236 NS_ABORT_MSG_IF(protocolNumber != Ipv4L3Protocol::PROT_NUMBER &&
237 protocolNumber != Ipv6L3Protocol::PROT_NUMBER,
238 "unsupported protocol " << protocolNumber
239 <<
", only IPv4 and IPv6 are supported");
241 NS_LOG_INFO(
"Forward received packet to RRC Layer");
242 m_txTrace(packet, dest);
244 return m_rrc->SendData(packet);
248NrGnbNetDevice::UpdateConfig()
250 NS_LOG_FUNCTION(
this);
255NrGnbNetDevice::ConfigureCell()
257 NS_LOG_FUNCTION(
this);
258 NS_ASSERT_MSG(!m_isCellConfigured,
"ConfigureCell() has already been called");
259 NS_ASSERT_MSG(!m_ccMap.empty(),
"Component carrier map is empty");
260 m_isCellConfigured =
true;
261 m_rrc->ConfigureCell(m_ccMap);
265NrGnbNetDevice::IsCellConfigured()
const
267 return m_isCellConfigured;
271NrGnbNetDevice::GetCellIdDlBandwidth(uint16_t cellId)
const
273 NS_ASSERT_MSG(m_rrc->HasCellId(cellId),
"Unknown cellId");
274 if (m_rrc->HasCellId(cellId))
276 for (
const auto& [key, cc] : m_ccMap)
278 if (cc->GetCellId() == cellId)
280 return cc->GetDlBandwidth();
288NrGnbNetDevice::GetCellIdUlBandwidth(uint16_t cellId)
const
290 NS_ASSERT_MSG(m_rrc->HasCellId(cellId),
"Unknown cellId");
291 if (m_rrc->HasCellId(cellId))
293 for (
const auto& [key, cc] : m_ccMap)
295 if (cc->GetCellId() == cellId)
297 return cc->GetUlBandwidth();
305NrGnbNetDevice::GetCellIdDlEarfcn(uint16_t cellId)
const
307 NS_ASSERT_MSG(m_rrc->HasCellId(cellId),
"Unknown cellId");
308 if (m_rrc->HasCellId(cellId))
310 for (
const auto& [key, cc] : m_ccMap)
312 if (cc->GetCellId() == cellId)
314 return cc->GetDlEarfcn();
322NrGnbNetDevice::GetCellIdUlEarfcn(uint16_t cellId)
const
324 NS_ASSERT_MSG(m_rrc->HasCellId(cellId),
"Unknown cellId");
325 if (m_rrc->HasCellId(cellId))
327 for (
const auto& [key, cc] : m_ccMap)
329 if (cc->GetCellId() == cellId)
331 return cc->GetUlEarfcn();
NrNetDevice()
NrNetDevice.