A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
emu-epc-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors:
7 * Jaume Nin <jnin@cttc.es>
8 * Nicola Baldo <nbaldo@cttc.es>
9 * Manuel Requena <manuel.requena@cttc.es>
10 */
11
12#include "emu-epc-helper.h"
13
14#include "ns3/emu-fd-net-device-helper.h"
15#include "ns3/epc-x2.h"
16#include "ns3/log.h"
17#include "ns3/lte-enb-net-device.h"
18#include "ns3/lte-enb-rrc.h"
19#include "ns3/string.h"
20
21#include <iomanip>
22
23namespace ns3
24{
25
26NS_LOG_COMPONENT_DEFINE("EmuEpcHelper");
27
28NS_OBJECT_ENSURE_REGISTERED(EmuEpcHelper);
29
32{
33 NS_LOG_FUNCTION(this);
34 // To access the attribute value within the constructor
36
37 // Create EmuFdNetDevice for SGW
39 NS_LOG_LOGIC("SGW device: " << m_sgwDeviceName);
41
42 Ptr<Node> sgw = GetSgwNode();
43 NetDeviceContainer sgwDevices = emu.Install(sgw);
44 Ptr<NetDevice> sgwDevice = sgwDevices.Get(0);
45 NS_LOG_LOGIC("SGW MAC address: " << m_sgwMacAddress);
46 sgwDevice->SetAttribute("Address", Mac48AddressValue(m_sgwMacAddress.c_str()));
47
48 // Address of the SGW: 10.0.0.1
49 m_epcIpv4AddressHelper.SetBase("10.0.0.0", "255.255.255.0", "0.0.0.1");
51
52 // Address of the first eNB: 10.0.0.101
53 m_epcIpv4AddressHelper.SetBase("10.0.0.0", "255.255.255.0", "0.0.0.101");
54}
55
60
63{
64 static TypeId tid =
65 TypeId("ns3::EmuEpcHelper")
67 .SetGroupName("Lte")
68 .AddConstructor<EmuEpcHelper>()
69 .AddAttribute("SgwDeviceName",
70 "The name of the device used for the S1-U interface of the SGW",
71 StringValue("veth0"),
74 .AddAttribute("EnbDeviceName",
75 "The name of the device used for the S1-U interface of the eNB",
76 StringValue("veth1"),
79 .AddAttribute("SgwMacAddress",
80 "MAC address used for the SGW",
81 StringValue("00:00:00:59:00:aa"),
84 .AddAttribute("EnbMacAddressBase",
85 "First 5 bytes of the eNB MAC address base",
86 StringValue("00:00:00:eb:00"),
89 return tid;
90}
91
94{
95 return GetTypeId();
96}
97
98void
104
105void
106EmuEpcHelper::AddEnb(Ptr<Node> enb, Ptr<NetDevice> lteEnbNetDevice, std::vector<uint16_t> cellIds)
107{
108 NS_LOG_FUNCTION(this << enb << lteEnbNetDevice << cellIds.size());
109
110 NoBackhaulEpcHelper::AddEnb(enb, lteEnbNetDevice, cellIds);
111
112 // Create an EmuFdNetDevice for the eNB to connect with the SGW and other eNBs
114 NS_LOG_LOGIC("eNB cellId: " << cellIds.at(0));
115 NS_LOG_LOGIC("eNB device: " << m_enbDeviceName);
117 NetDeviceContainer enbDevices = emu.Install(enb);
118
119 std::ostringstream enbMacAddress;
120 enbMacAddress << m_enbMacAddressBase << ":" << std::hex << std::setfill('0') << std::setw(2)
121 << cellIds.at(0);
122 NS_LOG_LOGIC("eNB MAC address: " << enbMacAddress.str());
123 Ptr<NetDevice> enbDev = enbDevices.Get(0);
124 enbDev->SetAttribute("Address", Mac48AddressValue(enbMacAddress.str().c_str()));
125
126 // emu.EnablePcap ("enbDevice", enbDev);
127
128 NS_LOG_LOGIC("number of Ipv4 ifaces of the eNB after installing emu dev: "
129 << enb->GetObject<Ipv4>()->GetNInterfaces());
130 Ipv4InterfaceContainer enbIpIfaces = m_epcIpv4AddressHelper.Assign(enbDevices);
131 NS_LOG_LOGIC("number of Ipv4 ifaces of the eNB after assigning Ipv4 addr to S1 dev: "
132 << enb->GetObject<Ipv4>()->GetNInterfaces());
133
134 Ipv4Address enbAddress = enbIpIfaces.GetAddress(0);
135 Ipv4Address sgwAddress = m_sgwIpIfaces.GetAddress(0);
136
137 NoBackhaulEpcHelper::AddS1Interface(enb, enbAddress, sgwAddress, cellIds);
138}
139
140void
142{
143 NS_LOG_FUNCTION(this << enb1 << enb2);
144
145 NS_LOG_WARN("X2 support still untested");
146
147 // for X2, we reuse the same device and IP address of the S1-U interface
148 Ptr<Ipv4> enb1Ipv4 = enb1->GetObject<Ipv4>();
149 Ptr<Ipv4> enb2Ipv4 = enb2->GetObject<Ipv4>();
150 NS_LOG_LOGIC("number of Ipv4 ifaces of the eNB #1: " << enb1Ipv4->GetNInterfaces());
151 NS_LOG_LOGIC("number of Ipv4 ifaces of the eNB #2: " << enb2Ipv4->GetNInterfaces());
152 NS_LOG_LOGIC("number of NetDevices of the eNB #1: " << enb1->GetNDevices());
153 NS_LOG_LOGIC("number of NetDevices of the eNB #2: " << enb2->GetNDevices());
154
155 // 0 is the LTE device, 1 is localhost, 2 is the EPC NetDevice
156 Ptr<NetDevice> enb1EpcDev = enb1->GetDevice(2);
157 Ptr<NetDevice> enb2EpcDev = enb2->GetDevice(2);
158
159 int32_t enb1Interface = enb1Ipv4->GetInterfaceForDevice(enb1EpcDev);
160 int32_t enb2Interface = enb2Ipv4->GetInterfaceForDevice(enb2EpcDev);
161 NS_ASSERT(enb1Interface >= 0);
162 NS_ASSERT(enb2Interface >= 0);
163 NS_ASSERT(enb1Ipv4->GetNAddresses(enb1Interface) == 1);
164 NS_ASSERT(enb2Ipv4->GetNAddresses(enb2Interface) == 1);
165 Ipv4Address enb1Addr = enb1Ipv4->GetAddress(enb1Interface, 0).GetLocal();
166 Ipv4Address enb2Addr = enb2Ipv4->GetAddress(enb2Interface, 0).GetLocal();
167 NS_LOG_LOGIC(" eNB 1 IP address: " << enb1Addr);
168 NS_LOG_LOGIC(" eNB 2 IP address: " << enb2Addr);
169
170 // Add X2 interface to both eNBs' X2 entities
171 Ptr<EpcX2> enb1X2 = enb1->GetObject<EpcX2>();
172 Ptr<LteEnbNetDevice> enb1LteDev = enb1->GetDevice(0)->GetObject<LteEnbNetDevice>();
173 std::vector<uint16_t> enb1CellIds = enb1LteDev->GetCellIds();
174 uint16_t enb1CellId = enb1CellIds.at(0);
175 NS_LOG_LOGIC("LteEnbNetDevice #1 = " << enb1LteDev << " - CellId = " << enb1CellId);
176
177 Ptr<EpcX2> enb2X2 = enb2->GetObject<EpcX2>();
178 Ptr<LteEnbNetDevice> enb2LteDev = enb2->GetDevice(0)->GetObject<LteEnbNetDevice>();
179 std::vector<uint16_t> enb2CellIds = enb2LteDev->GetCellIds();
180 uint16_t enb2CellId = enb2CellIds.at(0);
181 NS_LOG_LOGIC("LteEnbNetDevice #2 = " << enb2LteDev << " - CellId = " << enb2CellId);
182
183 enb1X2->AddX2Interface(enb1CellId, enb1Addr, enb2CellIds, enb2Addr);
184 enb2X2->AddX2Interface(enb2CellId, enb2Addr, enb1CellIds, enb1Addr);
185
186 enb1LteDev->GetRrc()->AddX2Neighbour(enb2LteDev->GetCellId());
187 enb2LteDev->GetRrc()->AddX2Neighbour(enb1LteDev->GetCellId());
188}
189
190} // namespace ns3
List of Attribute name, value and checker triples used to construct Objects.
Create an EPC network using EmuFdNetDevice.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
EmuEpcHelper()
Constructor.
static TypeId GetTypeId()
Register this type.
~EmuEpcHelper() override
Destructor.
Ipv4AddressHelper m_epcIpv4AddressHelper
helper to assign addresses to S1-U NetDevices
std::string m_enbMacAddressBase
First 5 bytes of the Enb MAC address base.
void DoDispose() override
Destructor implementation.
std::string m_enbDeviceName
The name of the device used for the S1-U interface of the eNB.
std::string m_sgwDeviceName
The name of the device used for the S1-U interface of the SGW.
std::string m_sgwMacAddress
MAC address used for the SGW.
void AddX2Interface(Ptr< Node > enbNode1, Ptr< Node > enbNode2) override
Add an X2 interface between two eNB.
Ipv4InterfaceContainer m_sgwIpIfaces
Container for Ipv4Interfaces of the SGW.
void AddEnb(Ptr< Node > enbNode, Ptr< NetDevice > lteEnbNetDevice, std::vector< uint16_t > cellIds) override
Add an eNB to the EPC.
build a set of FdNetDevice objects attached to a physical network interface
void SetDeviceName(std::string deviceName)
Set the device name of this device.
Base helper class to handle the creation of the EPC entities.
Definition epc-helper.h:40
This entity is installed inside an eNB and provides the functionality for the X2 interface.
Definition epc-x2.h:88
virtual NetDeviceContainer Install(Ptr< Node > node) const
This method creates a FdNetDevice and associates it to a node.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
virtual uint32_t GetNInterfaces() const =0
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
The eNodeB device implementation.
std::vector< uint16_t > GetCellIds() const
AttributeValue implementation for Mac48Address.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Create an EPC network with PointToPoint links between the core network nodes.
Ptr< Node > GetSgwNode() const override
Get the SGW node.
void DoDispose() override
Destructor implementation.
void AddS1Interface(Ptr< Node > enb, Ipv4Address enbAddress, Ipv4Address sgwAddress, std::vector< uint16_t > cellIds) override
Add an S1 interface between an eNB and a SGW.
void AddEnb(Ptr< Node > enbNode, Ptr< NetDevice > lteEnbNetDevice, std::vector< uint16_t > cellIds) override
Add an eNB to the EPC.
void ConstructSelf(const AttributeConstructionList &attributes)
Complete construction of ObjectBase; invoked by derived classes.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Definition string.h:45
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Ptr< const AttributeChecker > MakeStringChecker()
Definition string.cc:19
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition string.h:46
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:250
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.