A Discrete-Event Network Simulator
API
lena-deactivate-bearer.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 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: Gaurav Sathe <gaurav.sathe@tcs.com>
19  */
20 
21 #include "ns3/lte-helper.h"
22 #include "ns3/epc-helper.h"
23 #include "ns3/core-module.h"
24 #include "ns3/network-module.h"
25 #include "ns3/ipv4-global-routing-helper.h"
26 #include "ns3/internet-module.h"
27 #include "ns3/mobility-module.h"
28 #include "ns3/lte-module.h"
29 #include "ns3/applications-module.h"
30 #include "ns3/point-to-point-helper.h"
31 #include "ns3/config-store.h"
32 //#include "ns3/gtk-config-store.h"
33 
34 using namespace ns3;
35 
41 NS_LOG_COMPONENT_DEFINE ("BearerDeactivateExample");
42 int
43 main (int argc, char *argv[])
44 {
45 
46  uint16_t numberOfNodes = 1;
47  uint16_t numberOfUeNodes = 3;
48  double simTime = 1.1;
49  double distance = 60.0;
50  double interPacketInterval = 100;
51 
52  // Command line arguments
54  cmd.AddValue ("numberOfNodes", "Number of eNodeBs + UE pairs", numberOfNodes);
55  cmd.AddValue ("simTime", "Total duration of the simulation [s])", simTime);
56  cmd.AddValue ("distance", "Distance between eNBs [m]", distance);
57  cmd.AddValue ("interPacketInterval", "Inter packet interval [ms])", interPacketInterval);
58  cmd.Parse (argc, argv);
59 
60  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
61  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
62  lteHelper->SetEpcHelper (epcHelper);
63 
64  ConfigStore inputConfig;
65  inputConfig.ConfigureDefaults ();
66 
67  // parse again so you can override default values from the command line
68  cmd.Parse (argc, argv);
69 
70  Ptr<Node> pgw = epcHelper->GetPgwNode ();
71 
72  // Enable Logging
74 
75  LogComponentEnable ("BearerDeactivateExample", LOG_LEVEL_ALL);
76  LogComponentEnable ("LteHelper", logLevel);
77  LogComponentEnable ("EpcHelper", logLevel);
78  LogComponentEnable ("EpcEnbApplication", logLevel);
79  LogComponentEnable ("EpcSgwPgwApplication", logLevel);
80  LogComponentEnable ("EpcMme", logLevel);
81  LogComponentEnable ("LteEnbRrc", logLevel);
82 
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 (Seconds (0.010)));
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 (numberOfNodes);
110  ueNodes.Create (numberOfUeNodes);
111 
112  // Install Mobility Model
113  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
114  for (uint16_t i = 0; i < numberOfNodes; 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 a UE to a eNB
142  lteHelper->Attach (ueLteDevs, enbLteDevs.Get (0));
143 
144  // Activate an EPS bearer on all UEs
145 
146  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
147  {
148  Ptr<NetDevice> ueDevice = ueLteDevs.Get (u);
149  GbrQosInformation qos;
150  qos.gbrDl = 132; // bit/s, considering IP, UDP, RLC, PDCP header size
151  qos.gbrUl = 132;
152  qos.mbrDl = qos.gbrDl;
153  qos.mbrUl = qos.gbrUl;
154 
156  EpsBearer bearer (q, qos);
157  bearer.arp.priorityLevel = 15 - (u + 1);
158  bearer.arp.preemptionCapability = true;
159  bearer.arp.preemptionVulnerability = true;
160  lteHelper->ActivateDedicatedEpsBearer (ueDevice, bearer, EpcTft::Default ());
161  }
162 
163 
164  // Install and start applications on UEs and remote host
165  uint16_t dlPort = 1234;
166  uint16_t ulPort = 2000;
167  uint16_t otherPort = 3000;
170  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
171  {
172  ++ulPort;
173  ++otherPort;
174  PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort));
175  PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort));
176  PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), otherPort));
177  serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get (u)));
178  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
179  serverApps.Add (packetSinkHelper.Install (ueNodes.Get (u)));
180 
181  UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort);
182  dlClient.SetAttribute ("Interval", TimeValue (MilliSeconds (interPacketInterval)));
183  dlClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
184 
185  UdpClientHelper ulClient (remoteHostAddr, ulPort);
186  ulClient.SetAttribute ("Interval", TimeValue (MilliSeconds (interPacketInterval)));
187  ulClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
188 
189  UdpClientHelper client (ueIpIface.GetAddress (u), otherPort);
190  client.SetAttribute ("Interval", TimeValue (MilliSeconds (interPacketInterval)));
191  client.SetAttribute ("MaxPackets", UintegerValue (1000000));
192 
193  clientApps.Add (dlClient.Install (remoteHost));
194  clientApps.Add (ulClient.Install (ueNodes.Get (u)));
195  if (u + 1 < ueNodes.GetN ())
196  {
197  clientApps.Add (client.Install (ueNodes.Get (u + 1)));
198  }
199  else
200  {
201  clientApps.Add (client.Install (ueNodes.Get (0)));
202  }
203  }
204 
205  serverApps.Start (Seconds (0.030));
206  clientApps.Start (Seconds (0.030));
207 
208  double statsStartTime = 0.04; // need to allow for RRC connection establishment + SRS
209  double statsDuration = 1.0;
210 
211  lteHelper->EnableRlcTraces ();
212  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
213  rlcStats->SetAttribute ("StartTime", TimeValue (Seconds (statsStartTime)));
214  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (statsDuration)));
215 
216  //get ue device pointer for UE-ID 0 IMSI 1 and enb device pointer
217  Ptr<NetDevice> ueDevice = ueLteDevs.Get (0);
218  Ptr<NetDevice> enbDevice = enbLteDevs.Get (0);
219 
220  /*
221  * Instantiate De-activation using Simulator::Schedule() method which will initiate bearer de-activation after deActivateTime
222  * Instantiate De-activation in sequence (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3)
223  */
224  Time deActivateTime (Seconds (1.5));
225  Simulator::Schedule (deActivateTime, &LteHelper::DeActivateDedicatedEpsBearer, lteHelper, ueDevice, enbDevice, 2);
226 
227  //stop simulation after 3 seconds
228  Simulator::Stop (Seconds (3.0));
229 
230  Simulator::Run ();
231  /*GtkConfigStore config;
232  config.ConfigureAttributes();*/
233 
235  return 0;
236 
237 }
238 
holds a vector of ns3::Application pointers.
Introspection did not find any typical Config paths.
Definition: config-store.h:54
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
an Inet address class
static Ipv4Address GetAny(void)
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:382
holds a vector of std::pair of Ptr and interface index.
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:462
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
static Ptr< EpcTft > Default()
creates a TFT matching any traffic
Definition: epc-tft.cc:141
static void Run(void)
Run the simulation.
Definition: simulator.cc:201
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:716
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:903
void EnableRlcTraces(void)
Enable trace sinks for RLC layer.
Definition: lte-helper.cc:1102
aggregate IP/TCP/UDP functionality to existing Nodes.
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.
uint8_t ActivateDedicatedEpsBearer(NetDeviceContainer ueDevices, EpsBearer bearer, Ptr< EpcTft > tft)
Activate a dedicated EPS bearer on a given set of UE devices.
Definition: lte-helper.cc:824
tuple cmd
Definition: second.py:35
tuple clientApps
Definition: first.py:54
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
uint64_t gbrUl
Guaranteed Bit Rate (bit/s) in uplink.
Definition: eps-bearer.h:41
Class for representing data rates.
Definition: data-rate.h:88
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
void DeActivateDedicatedEpsBearer(Ptr< NetDevice > ueDevice, Ptr< NetDevice > enbDevice, uint8_t bearerId)
Manually trigger dedicated bearer de-activation at specific simulation time.
Definition: lte-helper.cc:1020
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:351
tuple mobility
Definition: third.py:101
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1238
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
AttributeValue implementation for Time.
Definition: nstime.h:957
Hold an unsigned integer type.
Definition: uinteger.h:44
holds a vector of ns3::NetDevice pointers
uint64_t gbrDl
Guaranteed Bit Rate (bit/s) in downlink.
Definition: eps-bearer.h:40
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
Definition: command-line.h:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:165
tuple serverApps
Definition: first.py:45
void ConfigureDefaults(void)
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Prefix all trace prints with simulation time.
Definition: log.h:115
uint64_t mbrUl
Maximum Bit Rate (bit/s) in uplink.
Definition: eps-bearer.h:43
Prefix all trace prints with function.
Definition: log.h:114
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
Ptr< RadioBearerStatsCalculator > GetRlcStats(void)
Definition: lte-helper.cc:1233
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:397
Helper class used to assign positions and mobility models to nodes.
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a network route to the static routing table.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
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:218
Helper class that adds ns3::Ipv4StaticRouting objects.
AttributeValue implementation for DataRate.
Definition: data-rate.h:242
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:495
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:209
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
LogLevel
Logging severity classes and levels.
Definition: log.h:90
void Add(Vector v)
Add a position to the list of positions.
Print everything.
Definition: log.h:112
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
uint64_t mbrDl
Maximum Bit Rate (bit/s) in downlink.
Definition: eps-bearer.h:42
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
3GPP TS 36.143 9.2.1.18 GBR QoS Information
Definition: eps-bearer.h:33
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191
Qci
QoS Class Indicator.
Definition: eps-bearer.h:77
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const