A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lena-deactivate-bearer.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 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 * Author: Gaurav Sathe <gaurav.sathe@tcs.com>
18 */
19
20#include "ns3/applications-module.h"
21#include "ns3/config-store.h"
22#include "ns3/core-module.h"
23#include "ns3/epc-helper.h"
24#include "ns3/internet-module.h"
25#include "ns3/ipv4-global-routing-helper.h"
26#include "ns3/lte-helper.h"
27#include "ns3/lte-module.h"
28#include "ns3/mobility-module.h"
29#include "ns3/network-module.h"
30#include "ns3/point-to-point-helper.h"
31// #include "ns3/gtk-config-store.h"
32
33using namespace ns3;
34
35/**
36 * Sample simulation script for LTE+EPC. It instantiates one eNodeB,
37 * attaches three UE to eNodeB starts a flow for each UE to and from a remote host.
38 * It also instantiates one dedicated bearer per UE
39 */
40NS_LOG_COMPONENT_DEFINE("BearerDeactivateExample");
41
42int
43main(int argc, char* argv[])
44{
45 uint16_t numberOfNodes = 1;
46 uint16_t numberOfUeNodes = 3;
47 double simTime = 1.1;
48 double distance = 60.0;
49 double interPacketInterval = 100;
50
51 // Command line arguments
52 CommandLine cmd(__FILE__);
53 cmd.AddValue("numberOfNodes", "Number of eNodeBs + UE pairs", numberOfNodes);
54 cmd.AddValue("simTime", "Total duration of the simulation [s])", simTime);
55 cmd.AddValue("distance", "Distance between eNBs [m]", distance);
56 cmd.AddValue("interPacketInterval", "Inter packet interval [ms])", interPacketInterval);
57 cmd.Parse(argc, argv);
58
59 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
60 Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper>();
61 lteHelper->SetEpcHelper(epcHelper);
62
63 ConfigStore inputConfig;
64 inputConfig.ConfigureDefaults();
65
66 // parse again so you can override default values from the command line
67 cmd.Parse(argc, argv);
68
69 Ptr<Node> pgw = epcHelper->GetPgwNode();
70
71 // Enable Logging
73
74 LogComponentEnable("BearerDeactivateExample", LOG_LEVEL_ALL);
75 LogComponentEnable("LteHelper", logLevel);
76 LogComponentEnable("EpcHelper", logLevel);
77 LogComponentEnable("EpcEnbApplication", logLevel);
78 LogComponentEnable("EpcMmeApplication", logLevel);
79 LogComponentEnable("EpcPgwApplication", logLevel);
80 LogComponentEnable("EpcSgwApplication", logLevel);
81 LogComponentEnable("LteEnbRrc", logLevel);
82
83 // Create a single RemoteHost
84 NodeContainer remoteHostContainer;
85 remoteHostContainer.Create(1);
86 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
88 internet.Install(remoteHostContainer);
89
90 // Create the Internet
92 p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
93 p2ph.SetDeviceAttribute("Mtu", UintegerValue(1500));
94 p2ph.SetChannelAttribute("Delay", TimeValue(Seconds(0.010)));
95 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
97 ipv4h.SetBase("1.0.0.0", "255.0.0.0");
98 Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign(internetDevices);
99 // interface 0 is localhost, 1 is the p2p device
100 Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress(1);
101
102 Ipv4StaticRoutingHelper ipv4RoutingHelper;
103 Ptr<Ipv4StaticRouting> remoteHostStaticRouting =
104 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 =
138 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
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 // 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",
176 PacketSinkHelper ulPacketSinkHelper("ns3::UdpSocketFactory",
178 PacketSinkHelper packetSinkHelper("ns3::UdpSocketFactory",
180 serverApps.Add(dlPacketSinkHelper.Install(ueNodes.Get(u)));
181 serverApps.Add(ulPacketSinkHelper.Install(remoteHost));
182 serverApps.Add(packetSinkHelper.Install(ueNodes.Get(u)));
183
184 UdpClientHelper dlClient(ueIpIface.GetAddress(u), dlPort);
185 dlClient.SetAttribute("Interval", TimeValue(MilliSeconds(interPacketInterval)));
186 dlClient.SetAttribute("MaxPackets", UintegerValue(1000000));
187
188 UdpClientHelper ulClient(remoteHostAddr, ulPort);
189 ulClient.SetAttribute("Interval", TimeValue(MilliSeconds(interPacketInterval)));
190 ulClient.SetAttribute("MaxPackets", UintegerValue(1000000));
191
192 UdpClientHelper client(ueIpIface.GetAddress(u), otherPort);
193 client.SetAttribute("Interval", TimeValue(MilliSeconds(interPacketInterval)));
194 client.SetAttribute("MaxPackets", UintegerValue(1000000));
195
196 clientApps.Add(dlClient.Install(remoteHost));
197 clientApps.Add(ulClient.Install(ueNodes.Get(u)));
198 if (u + 1 < ueNodes.GetN())
199 {
200 clientApps.Add(client.Install(ueNodes.Get(u + 1)));
201 }
202 else
203 {
204 clientApps.Add(client.Install(ueNodes.Get(0)));
205 }
206 }
207
208 serverApps.Start(Seconds(0.030));
209 clientApps.Start(Seconds(0.030));
210
211 double statsStartTime = 0.04; // need to allow for RRC connection establishment + SRS
212 double statsDuration = 1.0;
213
214 lteHelper->EnableRlcTraces();
215 Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats();
216 rlcStats->SetAttribute("StartTime", TimeValue(Seconds(statsStartTime)));
217 rlcStats->SetAttribute("EpochDuration", TimeValue(Seconds(statsDuration)));
218
219 // get ue device pointer for UE-ID 0 IMSI 1 and enb device pointer
220 Ptr<NetDevice> ueDevice = ueLteDevs.Get(0);
221 Ptr<NetDevice> enbDevice = enbLteDevs.Get(0);
222
223 /*
224 * Instantiate De-activation using Simulator::Schedule() method which will initiate bearer
225 * de-activation after deActivateTime Instantiate De-activation in sequence (Time const &time,
226 * MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3)
227 */
228 Time deActivateTime(Seconds(1.5));
229 Simulator::Schedule(deActivateTime,
231 lteHelper,
232 ueDevice,
233 enbDevice,
234 2);
235
236 // stop simulation after 3 seconds
238
240 /*GtkConfigStore config;
241 config.ConfigureAttributes();*/
242
244 return 0;
245}
holds a vector of ns3::Application pointers.
Parse command-line arguments.
Definition: command-line.h:232
Introspection did not find any typical Config paths.
Definition: config-store.h:61
void ConfigureDefaults()
Configure the default values.
Class for representing data rates.
Definition: data-rate.h:89
AttributeValue implementation for DataRate.
Definition: data-rate.h:296
static Ptr< EpcTft > Default()
creates a TFT matching any traffic
Definition: epc-tft.cc:229
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:91
Qci
QoS Class Indicator.
Definition: eps-bearer.h:106
@ GBR_CONV_VOICE
GBR Conversational Voice.
Definition: eps-bearer.h:107
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 DeActivateDedicatedEpsBearer(Ptr< NetDevice > ueDevice, Ptr< NetDevice > enbDevice, uint8_t bearerId)
Manually trigger dedicated bearer de-activation at specific simulation time.
Definition: lte-helper.cc:1387
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.
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.
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)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
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
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1406
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
ns serverApps
Definition: first.py:54
ns clientApps
Definition: first.py:64
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:302
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
ns cmd
Definition: second.py:40
ns mobility
Definition: third.py:105
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