forked from barrattc/NS3-4Gand5GPerformance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmwaveVoIPRandomWalk.cc
274 lines (234 loc) · 10.2 KB
/
mmwaveVoIPRandomWalk.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2011-2018 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Marco Miozzo <[email protected]>
* Nicola Baldo <[email protected]>
*
* Modified by: Marco Mezzavilla < [email protected]>
* Sourjya Dutta <[email protected]>
* Russell Ford <[email protected]>
* Menglei Zhang <[email protected]>
*/
//Import libraries
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store.h"
#include <ns3/buildings-helper.h>
#include "ns3/internet-stack-helper.h"
#include "ns3/point-to-point-helper.h"
#include "ns3/applications-module.h"
#include "ns3/energy-module.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/ipv4-flow-classifier.h"
#include "ns3/voip-client-server-helper.h"
#include "ns3/ipv4-address.h"
#include "ns3/mmwave-helper.h"
//Define namespaces
using namespace ns3;
using namespace mmwave;
//Print remaining energy function
//static void PrintCellInfo (liIonSourceHelper)
//{
// std::cout << "At " << Simulator::Now ().GetSeconds () << " Cell voltage: " << liIonSourceHelper->GetSupplyVoltage () << " V Remaining Capacity: " <<
// liIonSourceHelper->GetRemainingEnergy () / (3.7 * 3600) << " Ah" << std::endl;
//
// if (!Simulator::IsFinished ())
// {
// Simulator::Schedule (Seconds (10),
// &PrintCellInfo,
// liIonSourceHelper);
// }
//}
NS_LOG_COMPONENT_DEFINE ("mmWaveVoIPRandomWalk");
//Checking for lost packets as part of the Flow Monitor
void
FlowMonitor::CheckForLostPackets (Time maxDelay)
{
NS_LOG_FUNCTION (this << maxDelay.GetSeconds ());
Time now = Simulator::Now ();
for (TrackedPacketMap::iterator iter = m_trackedPackets.begin ();
iter != m_trackedPackets.end (); )
{
if (now - iter->second.lastSeenTime >= maxDelay)
{
// packet is considered lost, add it to the loss statistics
FlowStatsContainerI flow = m_flowStats.find (iter->first.first);
NS_ASSERT (flow != m_flowStats.end ());
flow->second.lostPackets++;
// we won't track it anymore
m_trackedPackets.erase (iter++);
}
else
{
iter++;
}
}
}
//Main function
int main (int argc, char *argv[])
{
//Defaults if none given at runtime
double simTime = 5.0;
bool useCa = false;
bool useV6 = false;
Address serverAddress;
Config::SetDefault ("ns3::MmWavePhyMacCommon::ResourceBlockNum", UintegerValue (1));
Config::SetDefault ("ns3::MmWavePhyMacCommon::ChunkPerRB", UintegerValue (72));
//Command line arguments, overrides defaults if given
CommandLine cmd;
cmd.AddValue ("simTime", "Total duration of the simulation", simTime);
cmd.AddValue ("useCa", "Whether to use carrier aggregation.", useCa);
cmd.AddValue ("useV6", "Whether to use IPv6 or not.", useV6);
cmd.Parse (argc, argv);
LogComponentEnable ("mmWaveVoIPRandomWalk", LOG_INFO);
// Parse again so you can override default values from the command line
cmd.Parse (argc, argv);
//If user carrier aggregation is set to true via the command line...
if (useCa)
{
Config::SetDefault ("ns3::MmWaveHelper::UseCa",BooleanValue (useCa));
Config::SetDefault ("ns3::MmWaveHelper::NumberOfComponentCarriers",UintegerValue (2));
Config::SetDefault ("ns3::MmWaveHelper::EnbComponentCarrierManager",StringValue ("ns3::MmWaveRrComponentCarrierManager"));
}
//Creating the mmwavehelper object
Ptr<MmWaveHelper> ptr_mmWave = CreateObject<MmWaveHelper> ();
//and then initialising it
ptr_mmWave->Initialize ();
// Create Nodes: 2eNodeB and 2 UE
NodeContainer enbNodes;
NodeContainer clientServerNodes;
enbNodes.Create (1);
clientServerNodes.Create (2);
// Install Mobility Model
MobilityHelper mobility;
//set non moving enb nodes
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (enbNodes);
BuildingsHelper::Install (enbNodes);
//set randomly walking ue nodes
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (1.0),
"MinY", DoubleValue (1.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (5.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Mode", StringValue ("Time"), //time or distance mode
"Time", StringValue ("2s"), //change current direction and speed after this delay
"Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"), //set constant speed of walk
"Bounds", RectangleValue (Rectangle (-50.0, 50.0, -50.0, 50.0)));
mobility.Install (clientServerNodes.Get(0));
BuildingsHelper::Install (clientServerNodes.Get(0));
// Create Devices and install them in the Nodes (eNB and UE)
NetDeviceContainer enbDevs = ptr_mmWave->InstallEnbDevice (enbNodes);
NetDeviceContainer ueDevs= ptr_mmWave->InstallUeDevice (clientServerNodes.Get (0));
//Attach ue to enb
ptr_mmWave->AttachToClosestEnb (ueDevs, enbDevs.Get (0));
// Activate a data radio bearer
enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
EpsBearer bearer (q);
ptr_mmWave->ActivateDataRadioBearer (ueDevs, bearer);
//Create P2P link
PointToPointHelper pointToPoint;
//Set P2P attributes
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("10Gbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("5ms"));
//install on client/server nodes
NetDeviceContainer clientServerDevs;
clientServerDevs = pointToPoint.Install (clientServerNodes);
//Use the internet stack helper and install on the ue nodes
InternetStackHelper internet;
internet.Install (clientServerNodes);
//Assigning IPv4 addresses onto client/server nodes
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (clientServerDevs);
// Create a UDP Server on the receiver
uint16_t port = 50000;
Time interPacketInterval = Seconds (0.05); //how often to sent packets
VoipServerHelper voipServer (port);
voipServer.SetAttribute ("Interval", TimeValue (interPacketInterval));
ApplicationContainer apps = voipServer.Install (clientServerNodes.Get(1));
apps.Start (Seconds (1.0));
// Create one UdpClient application to send UDP datagrams from node zero to node one.
VoipClientHelper voipClient (i.GetAddress(1), port);
apps = voipClient.Install (clientServerNodes.Get(0));
apps.Start (Seconds (2.0));
/*
// energy source //
BasicEnergySourceHelper basicSourceHelper;
// configure energy source
basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (1.0));
// install source
EnergySourceContainer sources;
sources = basicSourceHelper.Install (clientServerNodes.Get(0));
// device energy model //
LiIonEnergySourceHelper liIonSourceHelper;
liIonSourceHelper.Set("LiIonEnergySourceInitialEnergyJ",
DoubleValue(35000.00));
liIonSourceHelper.Set("InitialCellVoltage",
DoubleValue(3.7));
liIonSourceHelper.Set("PeriodicEnergyUpdateInterval",
TimeValue (Seconds(1.0)));
*/
// DeviceEnergyModelContainer deviceModels = liIonSourceHelper.Install (ueDevs, sources);
//3000 mAh and 3.7V is average mobile phone
// PrintCellInfo (liIonSourceHelper);
//mmwave tracing ALL LAYERS
ptr_mmWave->EnableTraces (); //creates Dl* and Ul* files
//Uncomment for specific mmwave LAYER tracing
//ptr_Helper->EnablePhyTraces ();
//ptr_Helper->EnableMacTraces ();
//ptr_Helper->EnableRlcTraces ();
//ptr_Helper->EnablePdcpTraces ();
//P2P tracing
AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("ASCIImmwaveVoIPRandomWalk.tr")); //ascii
pointToPoint.EnablePcapAll ("PCAPmmwaveVoIPRandomWalk"); //pcap
// Flow monitor
Ptr<FlowMonitor> flowMonitor;
FlowMonitorHelper flowHelper;
flowMonitor = flowHelper.InstallAll();
//Specifying histogram bin widths for delay, jitter and packet size
flowMonitor->SetAttribute("DelayBinWidth", DoubleValue(0.001));
flowMonitor->SetAttribute("JitterBinWidth", DoubleValue(0.001));
flowMonitor->SetAttribute("PacketSizeBinWidth", DoubleValue(20));
//Running and Stopping simulation
Simulator::Stop (Seconds (simTime));
Simulator::Run ();
//Callback to class, checks for packets that appear to be lost
flowMonitor->CheckForLostPackets();
//Only show flow, transferred bytes, received bytes and throughput
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier ());
std::map<FlowId, FlowMonitor::FlowStats> stats = flowMonitor->GetFlowStats ();
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
std::cout << "Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";
std::cout << " Tx Bytes: " << i->second.txBytes << "\n";
std::cout << " Rx Bytes: " << i->second.rxBytes << "\n";
std::cout << " Throughput: " << i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds() - i->second.timeFirstTxPacket.GetSeconds())/1024/1024 << " Mbps\n";
std::cout << " Delay: " << i->second.delaySum << "\n";
std::cout << " Lost Packets: " << i->second.lostPackets << "\n";
}
//Flow monitor file generation
flowMonitor->SerializeToXmlFile("FlowMonitormmwaveVoIPRandomWalk.xml", true, true); //histograms and probes enabled
Simulator::Destroy ();
return 0;
}