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
34using namespace ns3;
35
41NS_LOG_COMPONENT_DEFINE ("BearerDeactivateExample");
42int
43main (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
53 CommandLine cmd (__FILE__);
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 ("EpcMmeApplication", logLevel);
80 LogComponentEnable ("EpcPgwApplication", logLevel);
81 LogComponentEnable ("EpcSgwApplication", logLevel);
82 LogComponentEnable ("LteEnbRrc", logLevel);
83
84
85 // Create a single RemoteHost
86 NodeContainer remoteHostContainer;
87 remoteHostContainer.Create (1);
88 Ptr<Node> remoteHost = remoteHostContainer.Get (0);
89 InternetStackHelper internet;
90 internet.Install (remoteHostContainer);
91
92 // Create the Internet
94 p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
95 p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
96 p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
97 NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
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 = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
106 remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
107
108 NodeContainer ueNodes;
109 NodeContainer enbNodes;
110 enbNodes.Create (numberOfNodes);
111 ueNodes.Create (numberOfUeNodes);
112
113 // Install Mobility Model
114 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
115 for (uint16_t i = 0; i < numberOfNodes; i++)
116 {
117 positionAlloc->Add (Vector (distance * i, 0, 0));
118 }
120 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
121 mobility.SetPositionAllocator (positionAlloc);
122 mobility.Install (enbNodes);
123 mobility.Install (ueNodes);
124
125 // Install LTE Devices to the nodes
126 NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);
127 NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes);
128
129 // Install the IP stack on the UEs
130 internet.Install (ueNodes);
131 Ipv4InterfaceContainer ueIpIface;
132 ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs));
133 // Assign IP address to UEs, and install applications
134 for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
135 {
136 Ptr<Node> ueNode = ueNodes.Get (u);
137 // Set the default gateway for the UE
138 Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
139 ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
140 }
141
142 // Attach a UE to a eNB
143 lteHelper->Attach (ueLteDevs, enbLteDevs.Get (0));
144
145 // Activate an EPS bearer on all UEs
146
147 for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
148 {
149 Ptr<NetDevice> ueDevice = ueLteDevs.Get (u);
151 qos.gbrDl = 132; // bit/s, considering IP, UDP, RLC, PDCP header size
152 qos.gbrUl = 132;
153 qos.mbrDl = qos.gbrDl;
154 qos.mbrUl = qos.gbrUl;
155
156 enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
157 EpsBearer bearer (q, qos);
158 bearer.arp.priorityLevel = 15 - (u + 1);
159 bearer.arp.preemptionCapability = true;
160 bearer.arp.preemptionVulnerability = true;
161 lteHelper->ActivateDedicatedEpsBearer (ueDevice, bearer, EpcTft::Default ());
162 }
163
164
165 // Install and start applications on UEs and remote host
166 uint16_t dlPort = 1234;
167 uint16_t ulPort = 2000;
168 uint16_t otherPort = 3000;
171 for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
172 {
173 ++ulPort;
174 ++otherPort;
175 PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort));
176 PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort));
177 PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), otherPort));
178 serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get (u)));
179 serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
180 serverApps.Add (packetSinkHelper.Install (ueNodes.Get (u)));
181
182 UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort);
183 dlClient.SetAttribute ("Interval", TimeValue (MilliSeconds (interPacketInterval)));
184 dlClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
185
186 UdpClientHelper ulClient (remoteHostAddr, ulPort);
187 ulClient.SetAttribute ("Interval", TimeValue (MilliSeconds (interPacketInterval)));
188 ulClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
189
190 UdpClientHelper client (ueIpIface.GetAddress (u), otherPort);
191 client.SetAttribute ("Interval", TimeValue (MilliSeconds (interPacketInterval)));
192 client.SetAttribute ("MaxPackets", UintegerValue (1000000));
193
194 clientApps.Add (dlClient.Install (remoteHost));
195 clientApps.Add (ulClient.Install (ueNodes.Get (u)));
196 if (u + 1 < ueNodes.GetN ())
197 {
198 clientApps.Add (client.Install (ueNodes.Get (u + 1)));
199 }
200 else
201 {
202 clientApps.Add (client.Install (ueNodes.Get (0)));
203 }
204 }
205
206 serverApps.Start (Seconds (0.030));
207 clientApps.Start (Seconds (0.030));
208
209 double statsStartTime = 0.04; // need to allow for RRC connection establishment + SRS
210 double statsDuration = 1.0;
211
212 lteHelper->EnableRlcTraces ();
213 Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
214 rlcStats->SetAttribute ("StartTime", TimeValue (Seconds (statsStartTime)));
215 rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (statsDuration)));
216
217 //get ue device pointer for UE-ID 0 IMSI 1 and enb device pointer
218 Ptr<NetDevice> ueDevice = ueLteDevs.Get (0);
219 Ptr<NetDevice> enbDevice = enbLteDevs.Get (0);
220
221 /*
222 * Instantiate De-activation using Simulator::Schedule() method which will initiate bearer de-activation after deActivateTime
223 * Instantiate De-activation in sequence (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3)
224 */
225 Time deActivateTime (Seconds (1.5));
226 Simulator::Schedule (deActivateTime, &LteHelper::DeActivateDedicatedEpsBearer, lteHelper, ueDevice, enbDevice, 2);
227
228 //stop simulation after 3 seconds
229 Simulator::Stop (Seconds (3.0));
230
231 Simulator::Run ();
232 /*GtkConfigStore config;
233 config.ConfigureAttributes();*/
234
235 Simulator::Destroy ();
236 return 0;
237
238}
holds a vector of ns3::Application pointers.
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.
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:92
Qci
QoS Class Indicator.
Definition: eps-bearer.h:107
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
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
Ptr< RadioBearerStatsCalculator > GetRlcStats(void)
Definition: lte-helper.cc:1572
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
void EnableRlcTraces(void)
Enable trace sinks for RLC layer.
Definition: lte-helper.cc:1435
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:489
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:1068
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)
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
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
#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.
LogLevel
Logging severity classes and levels.
Definition: log.h:94
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition: log.h:118
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
Definition: log.h:119
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
cmd
Definition: second.py:35
mobility
Definition: third.py:107
3GPP TS 36.413 9.2.1.18 GBR QoS Information
Definition: eps-bearer.h:36
uint64_t gbrDl
Guaranteed Bit Rate (bit/s) in downlink.
Definition: eps-bearer.h:42
uint64_t gbrUl
Guaranteed Bit Rate (bit/s) in uplink.
Definition: eps-bearer.h:43
uint64_t mbrDl
Maximum Bit Rate (bit/s) in downlink.
Definition: eps-bearer.h:44
uint64_t mbrUl
Maximum Bit Rate (bit/s) in uplink.
Definition: eps-bearer.h:45