A Discrete-Event Network Simulator
API
emu-epc-helper.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011-2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Jaume Nin <jnin@cttc.es>
19  * Nicola Baldo <nbaldo@cttc.es>
20  * Manuel Requena <manuel.requena@cttc.es>
21  */
22 
23 #include <iomanip>
24 
25 #include "ns3/log.h"
26 #include "ns3/string.h"
27 #include "ns3/lte-enb-net-device.h"
28 #include "ns3/lte-enb-rrc.h"
29 #include "ns3/epc-x2.h"
30 #include "ns3/emu-fd-net-device-helper.h"
31 #include "ns3/emu-epc-helper.h"
32 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("EmuEpcHelper");
36 
37 NS_OBJECT_ENSURE_REGISTERED (EmuEpcHelper);
38 
39 
42 {
43  NS_LOG_FUNCTION (this);
44  // To access the attribute value within the constructor
46 
47  // Create EmuFdNetDevice for SGW
49  NS_LOG_LOGIC ("SGW device: " << m_sgwDeviceName);
51 
52  Ptr<Node> sgw = GetSgwNode ();
53  NetDeviceContainer sgwDevices = emu.Install (sgw);
54  Ptr<NetDevice> sgwDevice = sgwDevices.Get (0);
55  NS_LOG_LOGIC ("SGW MAC address: " << m_sgwMacAddress);
56  sgwDevice->SetAttribute ("Address", Mac48AddressValue (m_sgwMacAddress.c_str ()));
57 
58  // Address of the SGW: 10.0.0.1
59  m_epcIpv4AddressHelper.SetBase ("10.0.0.0", "255.255.255.0", "0.0.0.1");
61 
62  // Address of the first eNB: 10.0.0.101
63  m_epcIpv4AddressHelper.SetBase ("10.0.0.0", "255.255.255.0", "0.0.0.101");
64 }
65 
67 {
68  NS_LOG_FUNCTION (this);
69 }
70 
71 TypeId
73 {
74  static TypeId tid = TypeId ("ns3::EmuEpcHelper")
75  .SetParent<EpcHelper> ()
76  .SetGroupName("Lte")
77  .AddConstructor<EmuEpcHelper> ()
78  .AddAttribute ("SgwDeviceName",
79  "The name of the device used for the S1-U interface of the SGW",
80  StringValue ("veth0"),
83  .AddAttribute ("EnbDeviceName",
84  "The name of the device used for the S1-U interface of the eNB",
85  StringValue ("veth1"),
88  .AddAttribute ("SgwMacAddress",
89  "MAC address used for the SGW",
90  StringValue ("00:00:00:59:00:aa"),
93  .AddAttribute ("EnbMacAddressBase",
94  "First 5 bytes of the eNB MAC address base",
95  StringValue ("00:00:00:eb:00"),
98  ;
99  return tid;
100 }
101 
102 TypeId
104 {
105  return GetTypeId ();
106 }
107 
108 void
110 {
111  NS_LOG_FUNCTION (this);
113 }
114 
115 
116 void
117 EmuEpcHelper::AddEnb (Ptr<Node> enb, Ptr<NetDevice> lteEnbNetDevice, uint16_t cellId)
118 {
119  NS_LOG_FUNCTION (this << enb << lteEnbNetDevice << cellId);
120 
121  NoBackhaulEpcHelper::AddEnb (enb, lteEnbNetDevice, cellId);
122 
123  // Create an EmuFdNetDevice for the eNB to connect with the SGW and other eNBs
125  NS_LOG_LOGIC ("eNB cellId: " << cellId);
126  NS_LOG_LOGIC ("eNB device: " << m_enbDeviceName);
128  NetDeviceContainer enbDevices = emu.Install (enb);
129 
130  NS_ABORT_IF ((cellId == 0) || (cellId > 255));
131  std::ostringstream enbMacAddress;
132  enbMacAddress << m_enbMacAddressBase << ":" << std::hex << std::setfill ('0') << std::setw (2) << cellId;
133  NS_LOG_LOGIC ("eNB MAC address: " << enbMacAddress.str ());
134  Ptr<NetDevice> enbDev = enbDevices.Get (0);
135  enbDev->SetAttribute ("Address", Mac48AddressValue (enbMacAddress.str ().c_str ()));
136 
137  //emu.EnablePcap ("enbDevice", enbDev);
138 
139  NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after installing emu dev: " << enb->GetObject<Ipv4> ()->GetNInterfaces ());
140  Ipv4InterfaceContainer enbIpIfaces = m_epcIpv4AddressHelper.Assign (enbDevices);
141  NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after assigning Ipv4 addr to S1 dev: " << enb->GetObject<Ipv4> ()->GetNInterfaces ());
142 
143  Ipv4Address enbAddress = enbIpIfaces.GetAddress (0);
144  Ipv4Address sgwAddress = m_sgwIpIfaces.GetAddress (0);
145 
146  NoBackhaulEpcHelper::AddS1Interface (enb, enbAddress, sgwAddress, cellId);
147 }
148 
149 
150 void
152 {
153  NS_LOG_FUNCTION (this << enb1 << enb2);
154 
155  NS_LOG_WARN ("X2 support still untested");
156 
157 
158  // for X2, we reuse the same device and IP address of the S1-U interface
159  Ptr<Ipv4> enb1Ipv4 = enb1->GetObject<Ipv4> ();
160  Ptr<Ipv4> enb2Ipv4 = enb2->GetObject<Ipv4> ();
161  NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB #1: " << enb1Ipv4->GetNInterfaces ());
162  NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB #2: " << enb2Ipv4->GetNInterfaces ());
163  NS_LOG_LOGIC ("number of NetDevices of the eNB #1: " << enb1->GetNDevices ());
164  NS_LOG_LOGIC ("number of NetDevices of the eNB #2: " << enb2->GetNDevices ());
165 
166  // 0 is the LTE device, 1 is localhost, 2 is the EPC NetDevice
167  Ptr<NetDevice> enb1EpcDev = enb1->GetDevice (2);
168  Ptr<NetDevice> enb2EpcDev = enb2->GetDevice (2);
169 
170  int32_t enb1Interface = enb1Ipv4->GetInterfaceForDevice (enb1EpcDev);
171  int32_t enb2Interface = enb2Ipv4->GetInterfaceForDevice (enb2EpcDev);
172  NS_ASSERT (enb1Interface >= 0);
173  NS_ASSERT (enb2Interface >= 0);
174  NS_ASSERT (enb1Ipv4->GetNAddresses (enb1Interface) == 1);
175  NS_ASSERT (enb2Ipv4->GetNAddresses (enb2Interface) == 1);
176  Ipv4Address enb1Addr = enb1Ipv4->GetAddress (enb1Interface, 0).GetLocal ();
177  Ipv4Address enb2Addr = enb2Ipv4->GetAddress (enb2Interface, 0).GetLocal ();
178  NS_LOG_LOGIC (" eNB 1 IP address: " << enb1Addr);
179  NS_LOG_LOGIC (" eNB 2 IP address: " << enb2Addr);
180 
181  // Add X2 interface to both eNBs' X2 entities
182  Ptr<EpcX2> enb1X2 = enb1->GetObject<EpcX2> ();
183  Ptr<LteEnbNetDevice> enb1LteDev = enb1->GetDevice (0)->GetObject<LteEnbNetDevice> ();
184  uint16_t enb1CellId = enb1LteDev->GetCellId ();
185  NS_LOG_LOGIC ("LteEnbNetDevice #1 = " << enb1LteDev << " - CellId = " << enb1CellId);
186 
187  Ptr<EpcX2> enb2X2 = enb2->GetObject<EpcX2> ();
188  Ptr<LteEnbNetDevice> enb2LteDev = enb2->GetDevice (0)->GetObject<LteEnbNetDevice> ();
189  uint16_t enb2CellId = enb2LteDev->GetCellId ();
190  NS_LOG_LOGIC ("LteEnbNetDevice #2 = " << enb2LteDev << " - CellId = " << enb2CellId);
191 
192  enb1X2->AddX2Interface (enb1CellId, enb1Addr, enb2CellId, enb2Addr);
193  enb2X2->AddX2Interface (enb2CellId, enb2Addr, enb1CellId, enb1Addr);
194 
195  enb1LteDev->GetRrc ()->AddX2Neighbour (enb2LteDev->GetCellId ());
196  enb2LteDev->GetRrc ()->AddX2Neighbour (enb1LteDev->GetCellId ());
197 }
198 
199 } // namespace ns3
static TypeId GetTypeId(void)
Register this type.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void AddEnb(Ptr< Node > enbNode, Ptr< NetDevice > lteEnbNetDevice, uint16_t cellId)
Add an eNB to the EPC.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Hold variables of type string.
Definition: string.h:41
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
std::string m_sgwDeviceName
The name of the device used for the S1-U interface of the SGW.
Ipv4InterfaceContainer m_sgwIpIfaces
Container for Ipv4Interfaces of the SGW.
EmuEpcHelper()
Constructor.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
virtual NetDeviceContainer Install(Ptr< Node > node) const
This method creates a FdNetDevice and associates it to a node.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
uint16_t GetCellId() const
List of Attribute name, value and checker triples used to construct Objects.
holds a vector of ns3::NetDevice pointers
virtual void AddX2Interface(Ptr< Node > enbNode1, Ptr< Node > enbNode2)
Add an X2 interface between two eNB.
virtual void AddS1Interface(Ptr< Node > enb, Ipv4Address enbAddress, Ipv4Address sgwAddress, uint16_t cellId=0)
Add an S1 interface between an eNB and a SGW.
virtual void AddEnb(Ptr< Node > enbNode, Ptr< NetDevice > lteEnbNetDevice, uint16_t cellId)
Add an eNB to the EPC.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Create an EPC network using EmuFdNetDevice.
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
void SetDeviceName(std::string deviceName)
Set the device name of this device.
Create an EPC network with PointToPoint links between the core network nodes.
std::string m_enbMacAddressBase
First 5 bytes of the Enb MAC address base.
std::string m_sgwMacAddress
MAC address used for the SGW.
Base helper class to handle the creation of the EPC entities.
Definition: epc-helper.h:49
virtual void DoDispose()
Destructor implementation.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
This entity is installed inside an eNB and provides the functionality for the X2 interface.
Definition: epc-x2.h:99
void ConstructSelf(const AttributeConstructionList &attributes)
Complete construction of ObjectBase; invoked by derived classes.
Definition: object-base.cc:80
virtual ~EmuEpcHelper()
Destructor.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
AttributeValue implementation for Mac48Address.
std::string m_enbDeviceName
The name of the device used for the S1-U interface of the eNB.
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:42
Ipv4AddressHelper m_epcIpv4AddressHelper
helper to assign addresses to S1-U NetDevices
virtual void DoDispose()
Destructor implementation.
virtual Ptr< Node > GetSgwNode() const
Get the SGW node.
The eNodeB device implementation.
build a set of FdNetDevice objects attached to a physical network interface
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
virtual uint32_t GetNInterfaces(void) const =0
uint32_t GetNDevices(void) const
Definition: node.cc:152
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.