A Discrete-Event Network Simulator
API
lena-simple-epc.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2018 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors:
18  * Jaume Nin <jaume.nin@cttc.cat>
19  * Manuel Requena <manuel.requena@cttc.es>
20  */
21 
22 #include "ns3/applications-module.h"
23 #include "ns3/config-store-module.h"
24 #include "ns3/core-module.h"
25 #include "ns3/internet-module.h"
26 #include "ns3/lte-module.h"
27 #include "ns3/mobility-module.h"
28 #include "ns3/point-to-point-module.h"
29 // #include "ns3/gtk-config-store.h"
30 
31 using namespace ns3;
32 
39 NS_LOG_COMPONENT_DEFINE("LenaSimpleEpc");
40 
41 int
42 main(int argc, char* argv[])
43 {
44  uint16_t numNodePairs = 2;
45  Time simTime = MilliSeconds(1100);
46  double distance = 60.0;
47  Time interPacketInterval = MilliSeconds(100);
48  bool useCa = false;
49  bool disableDl = false;
50  bool disableUl = false;
51  bool disablePl = false;
52 
53  // Command line arguments
54  CommandLine cmd(__FILE__);
55  cmd.AddValue("numNodePairs", "Number of eNodeBs + UE pairs", numNodePairs);
56  cmd.AddValue("simTime", "Total duration of the simulation", simTime);
57  cmd.AddValue("distance", "Distance between eNBs [m]", distance);
58  cmd.AddValue("interPacketInterval", "Inter packet interval", interPacketInterval);
59  cmd.AddValue("useCa", "Whether to use carrier aggregation.", useCa);
60  cmd.AddValue("disableDl", "Disable downlink data flows", disableDl);
61  cmd.AddValue("disableUl", "Disable uplink data flows", disableUl);
62  cmd.AddValue("disablePl", "Disable data flows between peer UEs", disablePl);
63  cmd.Parse(argc, argv);
64 
65  ConfigStore inputConfig;
66  inputConfig.ConfigureDefaults();
67 
68  // parse again so you can override default values from the command line
69  cmd.Parse(argc, argv);
70 
71  if (useCa)
72  {
73  Config::SetDefault("ns3::LteHelper::UseCa", BooleanValue(useCa));
74  Config::SetDefault("ns3::LteHelper::NumberOfComponentCarriers", UintegerValue(2));
75  Config::SetDefault("ns3::LteHelper::EnbComponentCarrierManager",
76  StringValue("ns3::RrComponentCarrierManager"));
77  }
78 
79  Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
80  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper>();
81  lteHelper->SetEpcHelper(epcHelper);
82 
83  Ptr<Node> pgw = epcHelper->GetPgwNode();
84 
85  // Create a single RemoteHost
86  NodeContainer remoteHostContainer;
87  remoteHostContainer.Create(1);
88  Ptr<Node> remoteHost = remoteHostContainer.Get(0);
90  internet.Install(remoteHostContainer);
91 
92  // Create the Internet
93  PointToPointHelper p2ph;
94  p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
95  p2ph.SetDeviceAttribute("Mtu", UintegerValue(1500));
96  p2ph.SetChannelAttribute("Delay", TimeValue(MilliSeconds(10)));
97  NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
98  Ipv4AddressHelper ipv4h;
99  ipv4h.SetBase("1.0.0.0", "255.0.0.0");
100  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign(internetDevices);
101  // interface 0 is localhost, 1 is the p2p device
102  Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress(1);
103 
104  Ipv4StaticRoutingHelper ipv4RoutingHelper;
105  Ptr<Ipv4StaticRouting> remoteHostStaticRouting =
106  ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv4>());
107  remoteHostStaticRouting->AddNetworkRouteTo(Ipv4Address("7.0.0.0"), Ipv4Mask("255.0.0.0"), 1);
108 
109  NodeContainer ueNodes;
110  NodeContainer enbNodes;
111  enbNodes.Create(numNodePairs);
112  ueNodes.Create(numNodePairs);
113 
114  // Install Mobility Model
115  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
116  for (uint16_t i = 0; i < numNodePairs; i++)
117  {
118  positionAlloc->Add(Vector(distance * i, 0, 0));
119  }
121  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
122  mobility.SetPositionAllocator(positionAlloc);
123  mobility.Install(enbNodes);
124  mobility.Install(ueNodes);
125 
126  // Install LTE Devices to the nodes
127  NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice(enbNodes);
128  NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice(ueNodes);
129 
130  // Install the IP stack on the UEs
131  internet.Install(ueNodes);
132  Ipv4InterfaceContainer ueIpIface;
133  ueIpIface = epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueLteDevs));
134  // Assign IP address to UEs, and install applications
135  for (uint32_t u = 0; u < ueNodes.GetN(); ++u)
136  {
137  Ptr<Node> ueNode = ueNodes.Get(u);
138  // Set the default gateway for the UE
139  Ptr<Ipv4StaticRouting> ueStaticRouting =
140  ipv4RoutingHelper.GetStaticRouting(ueNode->GetObject<Ipv4>());
141  ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress(), 1);
142  }
143 
144  // Attach one UE per eNodeB
145  for (uint16_t i = 0; i < numNodePairs; i++)
146  {
147  lteHelper->Attach(ueLteDevs.Get(i), enbLteDevs.Get(i));
148  // side effect: the default EPS bearer will be activated
149  }
150 
151  // Install and start applications on UEs and remote host
152  uint16_t dlPort = 1100;
153  uint16_t ulPort = 2000;
154  uint16_t otherPort = 3000;
157  for (uint32_t u = 0; u < ueNodes.GetN(); ++u)
158  {
159  if (!disableDl)
160  {
161  PacketSinkHelper dlPacketSinkHelper("ns3::UdpSocketFactory",
163  serverApps.Add(dlPacketSinkHelper.Install(ueNodes.Get(u)));
164 
165  UdpClientHelper dlClient(ueIpIface.GetAddress(u), dlPort);
166  dlClient.SetAttribute("Interval", TimeValue(interPacketInterval));
167  dlClient.SetAttribute("MaxPackets", UintegerValue(1000000));
168  clientApps.Add(dlClient.Install(remoteHost));
169  }
170 
171  if (!disableUl)
172  {
173  ++ulPort;
174  PacketSinkHelper ulPacketSinkHelper("ns3::UdpSocketFactory",
176  serverApps.Add(ulPacketSinkHelper.Install(remoteHost));
177 
178  UdpClientHelper ulClient(remoteHostAddr, ulPort);
179  ulClient.SetAttribute("Interval", TimeValue(interPacketInterval));
180  ulClient.SetAttribute("MaxPackets", UintegerValue(1000000));
181  clientApps.Add(ulClient.Install(ueNodes.Get(u)));
182  }
183 
184  if (!disablePl && numNodePairs > 1)
185  {
186  ++otherPort;
187  PacketSinkHelper packetSinkHelper("ns3::UdpSocketFactory",
188  InetSocketAddress(Ipv4Address::GetAny(), otherPort));
189  serverApps.Add(packetSinkHelper.Install(ueNodes.Get(u)));
190 
191  UdpClientHelper client(ueIpIface.GetAddress(u), otherPort);
192  client.SetAttribute("Interval", TimeValue(interPacketInterval));
193  client.SetAttribute("MaxPackets", UintegerValue(1000000));
194  clientApps.Add(client.Install(ueNodes.Get((u + 1) % numNodePairs)));
195  }
196  }
197 
198  serverApps.Start(MilliSeconds(500));
199  clientApps.Start(MilliSeconds(500));
200  lteHelper->EnableTraces();
201  // Uncomment to enable PCAP tracing
202  // p2ph.EnablePcapAll("lena-simple-epc");
203 
204  Simulator::Stop(simTime);
205  Simulator::Run();
206 
207  /*GtkConfigStore config;
208  config.ConfigureAttributes();*/
209 
211  return 0;
212 }
holds a vector of ns3::Application pointers.
Parse command-line arguments.
Definition: command-line.h:232
void ConfigureDefaults()
Configure the default values.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
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:42
static Ipv4Address GetAny()
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:80
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:257
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:285
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:485
void EnableTraces()
Enables trace sinks for PHY, MAC, RLC and PDCP.
Definition: lte-helper.cc:1549
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:1039
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:500
Helper class used to assign positions and mobility models to nodes.
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.
Ptr< Node > GetPgwNode() const override
Get the PGW node.
Ipv4Address GetUeDefaultGatewayAddress() override
Ipv4InterfaceContainer AssignUeIpv4Address(NetDeviceContainer ueDevices) override
Assign IPv4 addresses to UE devices.
keep track of a set of node pointers.
uint32_t GetN() 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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
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 Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
Hold variables of type string.
Definition: string.h:56
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
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:45
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:890
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:327
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
serverApps
Definition: first.py:54
clientApps
Definition: first.py:64
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:40
mobility
Definition: third.py:105