A Discrete-Event Network Simulator
API
lena-simple-epc-emu.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011, 2013 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 <jaume.nin@cttc.cat>
19  * Nicola Baldo <nbaldo@cttc.cat>
20  */
21 
22 #include "ns3/lte-helper.h"
23 #include "ns3/epc-helper.h"
24 #include "ns3/core-module.h"
25 #include "ns3/network-module.h"
26 #include "ns3/ipv4-global-routing-helper.h"
27 #include "ns3/internet-module.h"
28 #include "ns3/mobility-module.h"
29 #include "ns3/lte-module.h"
30 #include "ns3/applications-module.h"
31 #include "ns3/point-to-point-helper.h"
32 #include <ns3/config-store-module.h>
33 
34 using namespace ns3;
35 
36 /*
37  * Simple simulation program using the emulated EPC.
38  * For the LTE radio part, it simulates a simple linear topology with
39  * a fixed number of eNBs spaced at equal distance, and a fixed number
40  * of UEs per each eNB, located at the same position of the eNB.
41  * For the EPC, it uses EmuEpcHelper to realize the S1-U connection
42  * via a real link.
43  */
44 
45 NS_LOG_COMPONENT_DEFINE ("EpcFirstExample");
46 
47 int
48 main (int argc, char *argv[])
49 {
50 
51  uint16_t nEnbs = 1;
52  uint16_t nUesPerEnb = 1;
53  double simTime = 10.1;
54  double distance = 1000.0;
55  double interPacketInterval = 1000;
56 
57  // Command line arguments
58  CommandLine cmd (__FILE__);
59  cmd.AddValue("nEnbs", "Number of eNBs", nEnbs);
60  cmd.AddValue("nUesPerEnb", "Number of UEs per eNB", nUesPerEnb);
61  cmd.AddValue("simTime", "Total duration of the simulation [s])", simTime);
62  cmd.AddValue("distance", "Distance between eNBs [m]", distance);
63  cmd.AddValue("interPacketInterval", "Inter packet interval [ms])", interPacketInterval);
64  cmd.Parse(argc, argv);
65 
66  // let's go in real time
67  // NOTE: if you go in real time I strongly advise to use
68  // --ns3::RealtimeSimulatorImpl::SynchronizationMode=HardLimit
69  // I've seen that if BestEffort is used things can break
70  // (even simple stuff such as ARP)
71  //GlobalValue::Bind ("SimulatorImplementationType",
72  // StringValue ("ns3::RealtimeSimulatorImpl"));
73 
74  // let's speed things up, we don't need these details for this scenario
75  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
76  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
77 
78  GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
79 
80  ConfigStore inputConfig;
81  inputConfig.ConfigureDefaults();
82 
83  // parse again so you can override default values from the command line
84  cmd.Parse(argc, argv);
85 
86 
87 
88  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
89  Ptr<EmuEpcHelper> epcHelper = CreateObject<EmuEpcHelper> ();
90  lteHelper->SetEpcHelper (epcHelper);
91  epcHelper->Initialize ();
92 
93  Ptr<Node> pgw = epcHelper->GetPgwNode ();
94 
95  // Create a single RemoteHost
96  NodeContainer remoteHostContainer;
97  remoteHostContainer.Create (1);
98  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
99  InternetStackHelper internet;
100  internet.Install (remoteHostContainer);
101 
102  // Create the Internet
103  PointToPointHelper p2ph;
104  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
105  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
106  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
107  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
108  Ipv4AddressHelper ipv4h;
109  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
110  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
111  // interface 0 is localhost, 1 is the p2p device
112  Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
113 
114  Ipv4StaticRoutingHelper ipv4RoutingHelper;
115  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
116  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
117 
118  NodeContainer ueNodes;
119  NodeContainer enbNodes;
120  enbNodes.Create(nEnbs);
121  ueNodes.Create(nEnbs*nUesPerEnb);
122 
123  // Install Mobility Model
124  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
125  for (uint16_t i = 0; i < nEnbs; i++)
126  {
127  positionAlloc->Add (Vector(distance * i, 0, 0));
128  }
130  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
131  mobility.SetPositionAllocator(positionAlloc);
132  mobility.Install(enbNodes);
133  mobility.Install(ueNodes);
134 
135  // Install LTE Devices to the nodes
136  NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);
137  NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes);
138 
139  // Install the IP stack on the UEs
140  internet.Install (ueNodes);
141  Ipv4InterfaceContainer ueIpIface;
142  ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs));
143  // Assign IP address to UEs, and install applications
144  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
145  {
146  Ptr<Node> ueNode = ueNodes.Get (u);
147  // Set the default gateway for the UE
148  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
149  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
150  }
151 
152  lteHelper->Attach (ueLteDevs);
153  // side effects: 1) use idle mode cell selection, 2) activate default EPS bearer
154 
155  // randomize a bit start times to avoid simulation artifacts
156  // (e.g., buffer overflows due to packet transmissions happening
157  // exactly at the same time)
158  Ptr<UniformRandomVariable> startTimeSeconds = CreateObject<UniformRandomVariable> ();
159  startTimeSeconds->SetAttribute ("Min", DoubleValue (0));
160  startTimeSeconds->SetAttribute ("Max", DoubleValue (interPacketInterval/1000.0));
161 
162  // Install and start applications on UEs and remote host
163  uint16_t dlPort = 1234;
164  uint16_t ulPort = 2000;
165  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
166  {
167  ++ulPort;
170 
171 
172  PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort));
173  PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort));
174  serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get(u)));
175  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
176 
177  UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort);
178  dlClient.SetAttribute ("Interval", TimeValue (MilliSeconds(interPacketInterval)));
179  dlClient.SetAttribute ("MaxPackets", UintegerValue(1000000));
180 
181  UdpClientHelper ulClient (remoteHostAddr, ulPort);
182  ulClient.SetAttribute ("Interval", TimeValue (MilliSeconds(interPacketInterval)));
183  ulClient.SetAttribute ("MaxPackets", UintegerValue(1000000));
184 
185  clientApps.Add (dlClient.Install (remoteHost));
186  clientApps.Add (ulClient.Install (ueNodes.Get(u)));
187 
188  serverApps.Start (Seconds (startTimeSeconds->GetValue ()));
189  clientApps.Start (Seconds (startTimeSeconds->GetValue ()));
190  }
191 
192  Simulator::Stop(Seconds(simTime));
193  Simulator::Run();
194 
196  return 0;
197 }
198 
holds a vector of ns3::Application pointers.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Parse command-line arguments.
Definition: command-line.h:229
Introspection did not find any typical Config paths.
Definition: config-store.h:60
void ConfigureDefaults(void)
Configure the default values.
Class for representing data rates.
Definition: data-rate.h:89
AttributeValue implementation for DataRate.
Definition: data-rate.h:298
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
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.
Definition: ipv4-address.h:41
static Ipv4Address GetAny(void)
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:77
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:256
Helper class that adds ns3::Ipv4StaticRouting objects.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
void SetEpcHelper(Ptr< EpcHelper > h)
Set the EpcHelper to be used to setup the EPC network in conjunction with the setup of the LTE radio ...
Definition: lte-helper.cc:272
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:474
void Attach(NetDeviceContainer ueDevices)
Enables automatic attachment of a set of UE devices to a suitable cell using Idle mode initial cell s...
Definition: lte-helper.cc:959
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:489
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
AttributeValue implementation for Time.
Definition: nstime.h:1308
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Hold an unsigned integer type.
Definition: uinteger.h:44
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
serverApps
Definition: first.py:52
clientApps
Definition: first.py:61
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:35
mobility
Definition: third.py:108