36 : m_gtpuUdpPort(2152),
37 m_s11LinkDataRate(DataRate(
"10Gb/s")),
38 m_s11LinkDelay(Seconds(0)),
41 m_s5LinkDataRate(DataRate(
"10Gb/s")),
42 m_s5LinkDelay(Seconds(0)),
45 NS_LOG_FUNCTION(
this);
47 ObjectBase::ConstructSelf(AttributeConstructionList());
54 m_x2Ipv4AddressHelper.SetBase(
"12.0.0.0",
"255.255.255.252");
55 m_s11Ipv4AddressHelper.SetBase(
"13.0.0.0",
"255.255.255.252");
56 m_s5Ipv4AddressHelper.SetBase(
"14.0.0.0",
"255.255.255.252");
59 m_uePgwAddressHelper.SetBase(
"7.0.0.0",
"255.0.0.0");
62 m_uePgwAddressHelper6.SetBase(
"7777:f00d::", Ipv6Prefix(64));
65 m_pgw = CreateObject<Node>();
66 m_sgw = CreateObject<Node>();
67 m_mme = CreateObject<Node>();
68 InternetStackHelper internet;
69 internet.Install(m_pgw);
70 internet.Install(m_sgw);
71 internet.Install(m_mme);
77 Ipv6StaticRoutingHelper ipv6RoutingHelper;
78 Ptr<Ipv6StaticRouting> pgwStaticRouting =
79 ipv6RoutingHelper.GetStaticRouting(m_pgw->GetObject<Ipv6>());
80 pgwStaticRouting->AddNetworkRouteTo(
"7777:f00d::", Ipv6Prefix(64), Ipv6Address(
"::"), 1, 0);
83 m_tunDevice = CreateObject<VirtualNetDevice>();
86 m_tunDevice->SetAttribute(
"Mtu", UintegerValue(30000));
89 m_tunDevice->SetAddress(Mac48Address::Allocate());
91 m_pgw->AddDevice(m_tunDevice);
92 NetDeviceContainer tunDeviceContainer;
93 tunDeviceContainer.Add(m_tunDevice);
105 tunDeviceIpv6IfContainer.SetForwarding(0,
true);
106 tunDeviceIpv6IfContainer.SetDefaultRouteInAllNodes(0);
109 PointToPointHelper p2ph;
110 p2ph.SetDeviceAttribute(
"DataRate", DataRateValue(m_s5LinkDataRate));
111 p2ph.SetDeviceAttribute(
"Mtu", UintegerValue(m_s5LinkMtu));
112 p2ph.SetChannelAttribute(
"Delay", TimeValue(m_s5LinkDelay));
113 NetDeviceContainer pgwSgwDevices = p2ph.Install(m_pgw, m_sgw);
114 NS_LOG_LOGIC(
"IPv4 ifaces of the PGW after installing p2p dev: "
115 << m_pgw->GetObject<Ipv4>()->GetNInterfaces());
116 NS_LOG_LOGIC(
"IPv4 ifaces of the SGW after installing p2p dev: "
117 << m_sgw->GetObject<Ipv4>()->GetNInterfaces());
118 Ptr<NetDevice> pgwDev = pgwSgwDevices.Get(0);
119 Ptr<NetDevice> sgwDev = pgwSgwDevices.Get(1);
120 m_s5Ipv4AddressHelper.NewNetwork();
121 Ipv4InterfaceContainer pgwSgwIpIfaces = m_s5Ipv4AddressHelper.Assign(pgwSgwDevices);
122 NS_LOG_LOGIC(
"IPv4 ifaces of the PGW after assigning Ipv4 addr to S5 dev: "
123 << m_pgw->GetObject<Ipv4>()->GetNInterfaces());
124 NS_LOG_LOGIC(
"IPv4 ifaces of the SGW after assigning Ipv4 addr to S5 dev: "
125 << m_sgw->GetObject<Ipv4>()->GetNInterfaces());
127 Ipv4Address pgwS5Address = pgwSgwIpIfaces.GetAddress(0);
128 Ipv4Address sgwS5Address = pgwSgwIpIfaces.GetAddress(1);
131 Ptr<Socket> pgwS5uSocket =
132 Socket::CreateSocket(m_pgw, TypeId::LookupByName(
"ns3::UdpSocketFactory"));
133 retval = pgwS5uSocket->Bind(InetSocketAddress(pgwS5Address, m_gtpuUdpPort));
134 NS_ASSERT(retval == 0);
137 Ptr<Socket> pgwS5cSocket =
138 Socket::CreateSocket(m_pgw, TypeId::LookupByName(
"ns3::UdpSocketFactory"));
139 retval = pgwS5cSocket->Bind(InetSocketAddress(pgwS5Address, m_gtpcUdpPort));
140 NS_ASSERT(retval == 0);
144 CreateObject<NrEpcPgwApplication>(m_tunDevice, pgwS5Address, pgwS5uSocket, pgwS5cSocket);
145 m_pgw->AddApplication(m_pgwApp);
151 Ptr<Socket> sgwS5uSocket =
152 Socket::CreateSocket(m_sgw, TypeId::LookupByName(
"ns3::UdpSocketFactory"));
153 retval = sgwS5uSocket->Bind(InetSocketAddress(sgwS5Address, m_gtpuUdpPort));
154 NS_ASSERT(retval == 0);
157 Ptr<Socket> sgwS5cSocket =
158 Socket::CreateSocket(m_sgw, TypeId::LookupByName(
"ns3::UdpSocketFactory"));
159 retval = sgwS5cSocket->Bind(InetSocketAddress(sgwS5Address, m_gtpcUdpPort));
160 NS_ASSERT(retval == 0);
163 Ptr<Socket> sgwS1uSocket =
164 Socket::CreateSocket(m_sgw, TypeId::LookupByName(
"ns3::UdpSocketFactory"));
165 retval = sgwS1uSocket->Bind(InetSocketAddress(Ipv4Address::GetAny(), m_gtpuUdpPort));
166 NS_ASSERT(retval == 0);
170 CreateObject<NrEpcSgwApplication>(sgwS1uSocket, sgwS5Address, sgwS5uSocket, sgwS5cSocket);
171 m_sgw->AddApplication(m_sgwApp);
172 m_sgwApp->AddPgw(pgwS5Address);
173 m_pgwApp->AddSgw(sgwS5Address);
176 PointToPointHelper s11P2ph;
177 s11P2ph.SetDeviceAttribute(
"DataRate", DataRateValue(m_s11LinkDataRate));
178 s11P2ph.SetDeviceAttribute(
"Mtu", UintegerValue(m_s11LinkMtu));
179 s11P2ph.SetChannelAttribute(
"Delay", TimeValue(m_s11LinkDelay));
180 NetDeviceContainer mmeSgwDevices = s11P2ph.Install(m_mme, m_sgw);
181 NS_LOG_LOGIC(
"MME's IPv4 ifaces after installing p2p dev: "
182 << m_mme->GetObject<Ipv4>()->GetNInterfaces());
183 NS_LOG_LOGIC(
"SGW's IPv4 ifaces after installing p2p dev: "
184 << m_sgw->GetObject<Ipv4>()->GetNInterfaces());
185 Ptr<NetDevice> mmeDev = mmeSgwDevices.Get(0);
186 Ptr<NetDevice> sgwS11Dev = mmeSgwDevices.Get(1);
187 m_s11Ipv4AddressHelper.NewNetwork();
188 Ipv4InterfaceContainer mmeSgwIpIfaces = m_s11Ipv4AddressHelper.Assign(mmeSgwDevices);
189 NS_LOG_LOGIC(
"MME's IPv4 ifaces after assigning Ipv4 addr to S11 dev: "
190 << m_mme->GetObject<Ipv4>()->GetNInterfaces());
191 NS_LOG_LOGIC(
"SGW's IPv4 ifaces after assigning Ipv4 addr to S11 dev: "
192 << m_sgw->GetObject<Ipv4>()->GetNInterfaces());
194 Ipv4Address mmeS11Address = mmeSgwIpIfaces.GetAddress(0);
195 Ipv4Address sgwS11Address = mmeSgwIpIfaces.GetAddress(1);
198 Ptr<Socket> mmeS11Socket =
199 Socket::CreateSocket(m_mme, TypeId::LookupByName(
"ns3::UdpSocketFactory"));
200 retval = mmeS11Socket->Bind(InetSocketAddress(mmeS11Address, m_gtpcUdpPort));
201 NS_ASSERT(retval == 0);
204 Ptr<Socket> sgwS11Socket =
205 Socket::CreateSocket(m_sgw, TypeId::LookupByName(
"ns3::UdpSocketFactory"));
206 retval = sgwS11Socket->Bind(InetSocketAddress(sgwS11Address, m_gtpcUdpPort));
207 NS_ASSERT(retval == 0);
210 m_mmeApp = CreateObject<NrEpcMmeApplication>();
211 m_mme->AddApplication(m_mmeApp);
212 m_mmeApp->AddSgw(sgwS11Address, mmeS11Address, mmeS11Socket);
213 m_sgwApp->AddMme(mmeS11Address, sgwS11Socket);
224 NS_LOG_FUNCTION_NOARGS();
226 TypeId(
"ns3::NrNoBackhaulEpcHelper")
230 .AddAttribute(
"S5LinkDataRate",
231 "The data rate to be used for the next S5 link to be created",
232 DataRateValue(DataRate(
"10Gb/s")),
233 MakeDataRateAccessor(&NrNoBackhaulEpcHelper::m_s5LinkDataRate),
234 MakeDataRateChecker())
235 .AddAttribute(
"S5LinkDelay",
236 "The delay to be used for the next S5 link to be created",
237 TimeValue(Seconds(0)),
238 MakeTimeAccessor(&NrNoBackhaulEpcHelper::m_s5LinkDelay),
240 .AddAttribute(
"S5LinkMtu",
241 "The MTU of the next S5 link to be created",
243 MakeUintegerAccessor(&NrNoBackhaulEpcHelper::m_s5LinkMtu),
244 MakeUintegerChecker<uint16_t>())
245 .AddAttribute(
"S11LinkDataRate",
246 "The data rate to be used for the next S11 link to be created",
247 DataRateValue(DataRate(
"10Gb/s")),
248 MakeDataRateAccessor(&NrNoBackhaulEpcHelper::m_s11LinkDataRate),
249 MakeDataRateChecker())
250 .AddAttribute(
"S11LinkDelay",
251 "The delay to be used for the next S11 link to be created",
252 TimeValue(Seconds(0)),
253 MakeTimeAccessor(&NrNoBackhaulEpcHelper::m_s11LinkDelay),
255 .AddAttribute(
"S11LinkMtu",
256 "The MTU of the next S11 link to be created.",
258 MakeUintegerAccessor(&NrNoBackhaulEpcHelper::m_s11LinkMtu),
259 MakeUintegerChecker<uint16_t>())
260 .AddAttribute(
"X2LinkDataRate",
261 "The data rate to be used for the next X2 link to be created",
262 DataRateValue(DataRate(
"10Gb/s")),
263 MakeDataRateAccessor(&NrNoBackhaulEpcHelper::m_x2LinkDataRate),
264 MakeDataRateChecker())
265 .AddAttribute(
"X2LinkDelay",
266 "The delay to be used for the next X2 link to be created",
267 TimeValue(Seconds(0)),
268 MakeTimeAccessor(&NrNoBackhaulEpcHelper::m_x2LinkDelay),
270 .AddAttribute(
"X2LinkMtu",
271 "The MTU of the next X2 link to be created. Note that, because of some "
272 "big X2 messages, you need a big MTU.",
274 MakeUintegerAccessor(&NrNoBackhaulEpcHelper::m_x2LinkMtu),
275 MakeUintegerChecker<uint16_t>())
276 .AddAttribute(
"X2LinkPcapPrefix",
277 "Prefix for Pcap generated by X2 link",
279 MakeStringAccessor(&NrNoBackhaulEpcHelper::m_x2LinkPcapPrefix),
281 .AddAttribute(
"X2LinkEnablePcap",
282 "Enable Pcap for X2 link",
284 MakeBooleanAccessor(&NrNoBackhaulEpcHelper::m_x2LinkEnablePcap),
285 MakeBooleanChecker());
306 Ptr<NetDevice> nrGnbNetDevice,
307 std::vector<uint16_t> cellIds)
309 NS_LOG_FUNCTION(
this << gnb << nrGnbNetDevice << cellIds.size());
310 NS_ASSERT(gnb == nrGnbNetDevice->GetNode());
315 InternetStackHelper internet;
316 internet.Install(gnb);
317 NS_LOG_LOGIC(
"number of Ipv4 ifaces of the gNB after node creation: "
318 << gnb->GetObject<Ipv4>()->GetNInterfaces());
321 Ptr<Socket> nrGnbSocket =
322 Socket::CreateSocket(gnb, TypeId::LookupByName(
"ns3::PacketSocketFactory"));
323 PacketSocketAddress nrGnbSocketBindAddress;
324 nrGnbSocketBindAddress.SetSingleDevice(nrGnbNetDevice->GetIfIndex());
325 nrGnbSocketBindAddress.SetProtocol(Ipv4L3Protocol::PROT_NUMBER);
326 retval = nrGnbSocket->Bind(nrGnbSocketBindAddress);
327 NS_ASSERT(retval == 0);
328 PacketSocketAddress nrGnbSocketConnectAddress;
329 nrGnbSocketConnectAddress.SetPhysicalAddress(Mac48Address::GetBroadcast());
330 nrGnbSocketConnectAddress.SetSingleDevice(nrGnbNetDevice->GetIfIndex());
331 nrGnbSocketConnectAddress.SetProtocol(Ipv4L3Protocol::PROT_NUMBER);
332 retval = nrGnbSocket->Connect(nrGnbSocketConnectAddress);
333 NS_ASSERT(retval == 0);
336 Ptr<Socket> nrGnbSocket6 =
337 Socket::CreateSocket(gnb, TypeId::LookupByName(
"ns3::PacketSocketFactory"));
338 PacketSocketAddress nrGnbSocketBindAddress6;
339 nrGnbSocketBindAddress6.SetSingleDevice(nrGnbNetDevice->GetIfIndex());
340 nrGnbSocketBindAddress6.SetProtocol(Ipv6L3Protocol::PROT_NUMBER);
341 retval = nrGnbSocket6->Bind(nrGnbSocketBindAddress6);
342 NS_ASSERT(retval == 0);
343 PacketSocketAddress nrGnbSocketConnectAddress6;
344 nrGnbSocketConnectAddress6.SetPhysicalAddress(Mac48Address::GetBroadcast());
345 nrGnbSocketConnectAddress6.SetSingleDevice(nrGnbNetDevice->GetIfIndex());
346 nrGnbSocketConnectAddress6.SetProtocol(Ipv6L3Protocol::PROT_NUMBER);
347 retval = nrGnbSocket6->Connect(nrGnbSocketConnectAddress6);
348 NS_ASSERT(retval == 0);
350 NS_LOG_INFO(
"Create NrEpcGnbApplication for cell ID " << cellIds.at(0));
351 Ptr<NrEpcGnbApplication> gnbApp =
352 CreateObject<NrEpcGnbApplication>(nrGnbSocket, nrGnbSocket6, cellIds.at(0));
353 gnb->AddApplication(gnbApp);
354 NS_ASSERT(gnb->GetNApplications() == 1);
356 "cannot retrieve NrEpcGnbApplication");
357 NS_LOG_LOGIC(
"gnb: " << gnb <<
", gnb->GetApplication (0): " << gnb->GetApplication(0));
359 NS_LOG_INFO(
"Create NrEpcX2 entity");
360 Ptr<NrEpcX2> x2 = CreateObject<NrEpcX2>();
361 gnb->AggregateObject(x2);
367 NS_LOG_FUNCTION(
this << gnb1 << gnb2);
371 PointToPointHelper p2ph;
372 p2ph.SetDeviceAttribute(
"DataRate", DataRateValue(m_x2LinkDataRate));
373 p2ph.SetDeviceAttribute(
"Mtu", UintegerValue(m_x2LinkMtu));
374 p2ph.SetChannelAttribute(
"Delay", TimeValue(m_x2LinkDelay));
375 NetDeviceContainer gnbDevices = p2ph.Install(gnb1, gnb2);
376 NS_LOG_LOGIC(
"number of Ipv4 ifaces of the gNB #1 after installing p2p dev: "
377 << gnb1->GetObject<Ipv4>()->GetNInterfaces());
378 NS_LOG_LOGIC(
"number of Ipv4 ifaces of the gNB #2 after installing p2p dev: "
379 << gnb2->GetObject<Ipv4>()->GetNInterfaces());
381 if (m_x2LinkEnablePcap)
383 p2ph.EnablePcapAll(m_x2LinkPcapPrefix);
386 m_x2Ipv4AddressHelper.NewNetwork();
387 Ipv4InterfaceContainer gnbIpIfaces = m_x2Ipv4AddressHelper.Assign(gnbDevices);
388 NS_LOG_LOGIC(
"number of Ipv4 ifaces of the gNB #1 after assigning Ipv4 addr to X2 dev: "
389 << gnb1->GetObject<Ipv4>()->GetNInterfaces());
390 NS_LOG_LOGIC(
"number of Ipv4 ifaces of the gNB #2 after assigning Ipv4 addr to X2 dev: "
391 << gnb2->GetObject<Ipv4>()->GetNInterfaces());
393 Ipv4Address gnb1X2Address = gnbIpIfaces.GetAddress(0);
394 Ipv4Address gnb2X2Address = gnbIpIfaces.GetAddress(1);
397 Ptr<NrEpcX2> gnb1X2 = gnb1->GetObject<
NrEpcX2>();
398 Ptr<NrEpcX2> gnb2X2 = gnb2->GetObject<
NrEpcX2>();
400 Ptr<NetDevice> gnb1NrDev = gnb1->GetDevice(0);
401 Ptr<NetDevice> gnb2NrDev = gnb2->GetDevice(0);
403 DoAddX2Interface(gnb1X2, gnb1NrDev, gnb1X2Address, gnb2X2, gnb2NrDev, gnb2X2Address);
408 const Ptr<NetDevice>& gnb1NrDev,
409 const Ipv4Address& gnb1X2Address,
410 const Ptr<NrEpcX2>& gnb2X2,
411 const Ptr<NetDevice>& gnb2NrDev,
412 const Ipv4Address& gnb2X2Address)
const
414 NS_LOG_FUNCTION(
this);
416 Ptr<NrGnbNetDevice> gnb1NrDevice = gnb1NrDev->GetObject<
NrGnbNetDevice>();
417 Ptr<NrGnbNetDevice> gnb2NrDevice = gnb2NrDev->GetObject<
NrGnbNetDevice>();
419 NS_ABORT_MSG_IF(!gnb1NrDevice,
"Unable to find NrGnbNetDevice for the first gNB");
420 NS_ABORT_MSG_IF(!gnb2NrDevice,
"Unable to find NrGnbNetDevice for the second gNB");
422 std::vector<uint16_t> gnb1CellIds = gnb1NrDevice->GetCellIds();
423 std::vector<uint16_t> gnb2CellIds = gnb2NrDevice->GetCellIds();
425 uint16_t gnb1CellId = gnb1CellIds.at(0);
426 uint16_t gnb2CellId = gnb2CellIds.at(0);
428 NS_LOG_LOGIC(
"NrGnbNetDevice #1 = " << gnb1NrDev <<
" - CellId = " << gnb1CellId);
429 NS_LOG_LOGIC(
"NrGnbNetDevice #2 = " << gnb2NrDev <<
" - CellId = " << gnb2CellId);
431 gnb1X2->AddX2Interface(gnb1CellId, gnb1X2Address, gnb2CellIds, gnb2X2Address);
432 gnb2X2->AddX2Interface(gnb2CellId, gnb2X2Address, gnb1CellIds, gnb1X2Address);
434 gnb1NrDevice->GetRrc()->AddX2Neighbour(gnb2CellId);
435 gnb2NrDevice->GetRrc()->AddX2Neighbour(gnb1CellId);
628 std::optional<uint16_t> mtu,
629 std::optional<Time> delay)
634 NodeContainer remoteHostContainer;
635 remoteHostContainer.Create(1);
636 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
637 InternetStackHelper internet;
638 internet.Install(remoteHostContainer);
641 PointToPointHelper p2ph;
642 if (dataRate.has_value())
644 p2ph.SetDeviceAttribute(
"DataRate", StringValue(dataRate.value()));
648 p2ph.SetDeviceAttribute(
"Mtu", UintegerValue(mtu.value()));
650 if (delay.has_value())
652 p2ph.SetChannelAttribute(
"Delay", TimeValue(delay.value()));
654 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
657 Ipv4AddressHelper ipv4h;
658 Ipv4StaticRoutingHelper ipv4RoutingHelper;
659 ipv4h.SetBase(
"1.0.0.0",
"255.0.0.0");
660 Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign(internetDevices);
661 Ptr<Ipv4StaticRouting> remoteHostStaticRouting4 =
662 ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv4>());
663 remoteHostStaticRouting4->AddNetworkRouteTo(Ipv4Address(
"7.0.0.0"), Ipv4Mask(
"255.0.0.0"), 1);
664 return std::make_pair(remoteHost, internetIpIfaces.GetAddress(0, 0));
669 std::optional<uint16_t> mtu,
670 std::optional<Time> delay)
675 NodeContainer remoteHostContainer;
676 remoteHostContainer.Create(1);
677 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
678 InternetStackHelper internet;
679 internet.Install(remoteHostContainer);
682 PointToPointHelper p2ph;
683 if (dataRate.has_value())
685 p2ph.SetDeviceAttribute(
"DataRate", StringValue(dataRate.value()));
689 p2ph.SetDeviceAttribute(
"Mtu", UintegerValue(mtu.value()));
691 if (delay.has_value())
693 p2ph.SetChannelAttribute(
"Delay", TimeValue(delay.value()));
695 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
698 Ipv6AddressHelper ipv6h;
699 ipv6h.SetBase(Ipv6Address(
"6001:db80::"), Ipv6Prefix(64));
700 Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign(internetDevices);
701 internetIpIfaces.SetForwarding(0,
true);
702 internetIpIfaces.SetDefaultRouteInAllNodes(0);
704 Ipv6StaticRoutingHelper ipv6RoutingHelper;
705 Ptr<Ipv6StaticRouting> remoteHostStaticRouting =
706 ipv6RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv6>());
707 remoteHostStaticRouting
708 ->AddNetworkRouteTo(
"7777:f00d::", Ipv6Prefix(64), internetIpIfaces.GetAddress(0, 1), 1, 0);
709 return std::make_pair(remoteHost, internetIpIfaces.GetAddress(1, 1));