A Discrete-Event Network Simulator
API
lena-simple-epc.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011-2018 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  * Authors: Jaume Nin <jaume.nin@cttc.cat>
19  * Manuel Requena <manuel.requena@cttc.es>
20  */
21 
22 #include "ns3/core-module.h"
23 #include "ns3/point-to-point-module.h"
24 #include "ns3/internet-module.h"
25 #include "ns3/applications-module.h"
26 #include "ns3/mobility-module.h"
27 #include "ns3/config-store-module.h"
28 #include "ns3/lte-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", StringValue ("ns3::RrComponentCarrierManager"));
76  }
77 
78  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
79  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
80  lteHelper->SetEpcHelper (epcHelper);
81 
82  Ptr<Node> pgw = epcHelper->GetPgwNode ();
83 
84  // Create a single RemoteHost
85  NodeContainer remoteHostContainer;
86  remoteHostContainer.Create (1);
87  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
88  InternetStackHelper internet;
89  internet.Install (remoteHostContainer);
90 
91  // Create the Internet
92  PointToPointHelper p2ph;
93  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
94  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
95  p2ph.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10)));
96  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
97  Ipv4AddressHelper ipv4h;
98  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
99  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
100  // interface 0 is localhost, 1 is the p2p device
101  Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
102 
103  Ipv4StaticRoutingHelper ipv4RoutingHelper;
104  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
105  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
106 
107  NodeContainer ueNodes;
108  NodeContainer enbNodes;
109  enbNodes.Create (numNodePairs);
110  ueNodes.Create (numNodePairs);
111 
112  // Install Mobility Model
113  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
114  for (uint16_t i = 0; i < numNodePairs; i++)
115  {
116  positionAlloc->Add (Vector (distance * i, 0, 0));
117  }
119  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
120  mobility.SetPositionAllocator(positionAlloc);
121  mobility.Install(enbNodes);
122  mobility.Install(ueNodes);
123 
124  // Install LTE Devices to the nodes
125  NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);
126  NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes);
127 
128  // Install the IP stack on the UEs
129  internet.Install (ueNodes);
130  Ipv4InterfaceContainer ueIpIface;
131  ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs));
132  // Assign IP address to UEs, and install applications
133  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
134  {
135  Ptr<Node> ueNode = ueNodes.Get (u);
136  // Set the default gateway for the UE
137  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
138  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
139  }
140 
141  // Attach one UE per eNodeB
142  for (uint16_t i = 0; i < numNodePairs; i++)
143  {
144  lteHelper->Attach (ueLteDevs.Get(i), enbLteDevs.Get(i));
145  // side effect: the default EPS bearer will be activated
146  }
147 
148 
149  // Install and start applications on UEs and remote host
150  uint16_t dlPort = 1100;
151  uint16_t ulPort = 2000;
152  uint16_t otherPort = 3000;
155  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
156  {
157  if (!disableDl)
158  {
159  PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort));
160  serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get (u)));
161 
162  UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort);
163  dlClient.SetAttribute ("Interval", TimeValue (interPacketInterval));
164  dlClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
165  clientApps.Add (dlClient.Install (remoteHost));
166  }
167 
168  if (!disableUl)
169  {
170  ++ulPort;
171  PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort));
172  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
173 
174  UdpClientHelper ulClient (remoteHostAddr, ulPort);
175  ulClient.SetAttribute ("Interval", TimeValue (interPacketInterval));
176  ulClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
177  clientApps.Add (ulClient.Install (ueNodes.Get(u)));
178  }
179 
180  if (!disablePl && numNodePairs > 1)
181  {
182  ++otherPort;
183  PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), otherPort));
184  serverApps.Add (packetSinkHelper.Install (ueNodes.Get (u)));
185 
186  UdpClientHelper client (ueIpIface.GetAddress (u), otherPort);
187  client.SetAttribute ("Interval", TimeValue (interPacketInterval));
188  client.SetAttribute ("MaxPackets", UintegerValue (1000000));
189  clientApps.Add (client.Install (ueNodes.Get ((u + 1) % numNodePairs)));
190  }
191  }
192 
193  serverApps.Start (MilliSeconds (500));
194  clientApps.Start (MilliSeconds (500));
195  lteHelper->EnableTraces ();
196  // Uncomment to enable PCAP tracing
197  //p2ph.EnablePcapAll("lena-simple-epc");
198 
199  Simulator::Stop (simTime);
200  Simulator::Run ();
201 
202  /*GtkConfigStore config;
203  config.ConfigureAttributes();*/
204 
206  return 0;
207 }
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
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
void EnableTraces(void)
Enables trace sinks for PHY, MAC, RLC and PDCP.
Definition: lte-helper.cc:1426
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.
virtual Ipv4Address GetUeDefaultGatewayAddress()
virtual Ptr< Node > GetPgwNode() const
Get the PGW node.
virtual Ipv4InterfaceContainer AssignUeIpv4Address(NetDeviceContainer ueDevices)
Assign IPv4 addresses to UE devices.
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.
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
Hold variables of type string.
Definition: string.h:41
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
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
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 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