-
Notifications
You must be signed in to change notification settings - Fork 13
/
d2dsim.cc
397 lines (344 loc) · 13.8 KB
/
d2dsim.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2016 Gyeongsang N. University
* InfoCom Engineering Dept, South Korea
*
* $Id: d2dsim.cc, 2016-07-05 18:56 +0900 makhtar $
* Advisor: Woonsup Lee
* Author: Makhtar Diouf
*
* *** Proximity-based Services, LTE-Direct (D2D) ***
*
* This program is open source software released under the terms of the
* GNU General Public License version 2 as published by the Free Software Foundation.
* It is distributed 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.
*
* Control LTE-A ProSe D2D/Cellular network simulation.
* Progressively implemented to match the requirements of 3GPP TS 23.303, 24.334, TR 36.843...
*/
#include <string>
#include <ns3/log.h>
#include <ns3/config-store-module.h>
#include <ns3/command-line.h>
#include <ns3/net-device-container.h>
#include <ns3/lte-ue-net-device.h>
#include <ns3/lte-ue-rrc.h>
#include <ns3/rng-seed-manager.h>
#include <ns3/flow-monitor-helper.h>
#include <ns3/flow-monitor.h>
//#include <ns3/gnuplot-helper.h>
#include "ns3/default-simulator-impl.h"
#include "ns3/lte-prose-common.h"
#include "ns3/lte-utils.h"
#include <cstdlib>
#include <csignal>
using namespace std;
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("D2dSimulator");
void
NetanimTrace(Ptr<ProSeHelper> d2dCtrl);
class D2dExperiment
{
public:
struct Input
{
Input()
{
;
}
// Defaults
/*
* As per TR36843 A.2.1.1, macroEnbNum should be 7 with 3 sectors
* 3 sector = 3eNBs with different antenna orientation each
* ueNum should be 150, with 25 active
*/
uint8_t maxEnbs = 2; // 7
uint8_t maxUes = 150;
uint8_t enbNum = 1;
uint8_t ueNum = 5;
uint8_t ueSpeed = 3;
double dUesRatio = 1; // 0.16 3GPP requirements 25/150 active users
double nRB = 50; // 10 MHz
double cellRadius = 250.0; // meters
// Time for one full processing for LTE-D + LTE-infra + WiFi-adhoc
double simuTime = 50.0;
uint8_t debug = 1;
bool useAnimation = false;
};
struct Output
{
uint32_t received;
Ptr<FlowMonitor> flowmon;
};
D2dExperiment()
{
;
}
struct D2dExperiment::Output Run(struct D2dExperiment::Input input);
private:
struct Input m_input;
struct Output m_output;
};
void EnableLogging(struct D2dExperiment::Input input);
/*
* \ingroup ProSe D2D
* \brief Control simulation: Basic scenario with 1 macro eNB, 3 sectors, and a few cellular and hybrid Ues
* Parameters specified here are settable in a configuration file.
*/
int
main(int argc, char* argv[])
{
NS_LOG_INFO("\n\tRunning the D2d simulator...");
D2dExperiment experiment;
struct D2dExperiment::Input input;
// struct D2dExperiment::Output kpi;
EnableLogging(input);
// CLI arguments, currently unused
CommandLine cmd;
cmd.AddValue("enbNum", "Number of eNodeBs", input.enbNum);
cmd.AddValue("ueNum", "Number of Cellular and ProSe D2D Ues", input.ueNum);
cmd.AddValue("cellRadius", "Cell radius [m]", input.cellRadius);
cmd.AddValue("nRB", "Number of resource blocks", input.nRB);
cmd.AddValue("simuTime", "Total duration of the simulation [s]", input.simuTime);
cmd.AddValue("debug", "Enable detailed debugging output [int >= 1]", input.debug);
cmd.AddValue("useAnimation", "Generate Netanim xml file [bool]", input.useAnimation);
cmd.Parse(argc, argv);
Config::SetDefault("ns3::LteEnbRrc::DefaultTransmissionMode", UintegerValue(2));
Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(true));
Config::SetDefault("ns3::LteUePowerControl::ClosedLoop", BooleanValue(true));
Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(true));
Config::SetDefault("ns3::LteUePowerControl::Alpha", DoubleValue(1.0));
Config::SetDefault("ns3::LteUePowerControl::Pcmin", DoubleValue(16.0)); // min Tx power
GlobalValue::Bind("ChecksumEnabled", BooleanValue(true));
ns3::lteUseIpv6 = false;
stringstream ss;
// Randomize experiments
RngSeedManager::SetSeed(2);
RngSeedManager::SetRun(2);
input.ueSpeed = 3; // pedestrian
input.dUesRatio = 1.0; // * 100%
int numberOfRuns = 1; // Multiple Runs
ss << "speed" << (int) input.ueSpeed
<< "seed" << (int) RngSeedManager::GetSeed()
<< "run" << (int) RngSeedManager::GetRun();
string conf = ss.str();
for (int i = 0; i < numberOfRuns; i++)
{
NS_LOG_INFO("\n\n\tRun " << (int) i << " - configuration with "
<< (int) input.ueNum << " Ues"
<< " Ratio: " << input.dUesRatio);
experiment.Run(input);
// @TODO Rewrite this programmatically
// Save generated log, stats files under OUTPUT directory
ss.str("");
ss << "export SIMUOUTPUT=OUTPUT/`date \"+%Y%m%d\"`/"
<< (int) input.ueSpeed << "kmh"
<< "_" << (int) input.ueNum << "Ues"
<< "_Ratio" << (int) input.dUesRatio
<< "; mkdir -p $SIMUOUTPUT ;"
<< "cp *.log $SIMUOUTPUT ;"
<< "mv *txt *mob *plt *xml *tr *pcap $SIMUOUTPUT"
;
system(ss.str().c_str());
input.ueNum += 10;
}
ss << " mv d2d-discovery.txt d2d-discovery`date \"+%Y%m%d\"`_" << conf << ".txt;"
<< "mv d2d-nodes.txt d2d-nodes`date \"+%Y%m%d\"`_" << conf << ".txt";
system(ss.str().c_str());
NS_LOG_INFO("\tStopping the D2d simulator...\n See stats and pcap files under ns3-dev/OUTPUT/ directory");
return 0;
}
struct D2dExperiment::Output
D2dExperiment::Run(struct D2dExperiment::Input input)
{
NS_LOG_INFO("\tConfiguring nodes...");
Ptr<ProSeHelper> d2dCtrl = CreateObject<ProSeHelper>();
/*
d2dCtrl->SetConfig(argv[0], true);
Reference signals periodicity for high number of Ues
Ref g_srsPeriodicity[SRS_ENTRIES] = {0, 2, 5, 10, 20, 40, 80, 160, 320};
*/
uint8_t srsPeriodicity = 80;
while ((input.ueNum > srsPeriodicity) && (srsPeriodicity <= 320))
srsPeriodicity *= 2;
Config::SetDefault("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue(srsPeriodicity));
NS_LOG_INFO("\tSRS periodicity set to: " << (int) srsPeriodicity);
if (input.enbNum > input.maxEnbs)
{
input.enbNum = input.maxEnbs;
NS_LOG_INFO("\tLimiting the number of eNBs to " << (int) input.enbNum);
}
if (input.ueNum > input.maxUes)
{
input.ueNum = input.maxUes;
NS_LOG_INFO("\tLimiting the number of Ues to " << (int) input.ueNum);
}
d2dCtrl->SetNodesDistribution(ProSeHelper::UNIFORM);
d2dCtrl->CreateNodesAndHelpers(input.enbNum, input.ueNum, input.dUesRatio);
d2dCtrl->InstallEpcRanInHexGrid(input.cellRadius);
// Default scheduler is Proportional-Fair, uncomment to use Round-Robin
d2dCtrl->lteH->SetSchedulerType ("ns3::RrFfMacScheduler");
d2dCtrl->InstallUes("ns3::RandomWalk2dMobilityModel");
// d2dCtrl->InstallUes("ns3::ConstantPositionMobilityModel");
// d2dCtrl->InstallUes("ns3::ConstantVelocityMobilityModel");
ns3::PacketMetadata::Enable();
// Note: this cannot track multicast packets
FlowMonitorHelper flowmonH;
struct D2dExperiment::Output output;
output.flowmon = flowmonH.InstallAll();
// For visualizing node movements
if (input.useAnimation)
{
;// Simulator::Schedule(Seconds(6.0), &NetanimTrace, d2dCtrl);
}
d2dCtrl->SetupIpNetwork();
// Attach each Ue to the eNB with the strongest signal or the closest homeEnb
d2dCtrl->lteH->Attach(d2dCtrl->ueD2dDevs);
d2dCtrl->lteH->Attach(d2dCtrl->ueCellDevs);
d2dCtrl->lteH->EnableTraces();
if (input.debug > 2)
d2dCtrl->lteH->EnableLogComponents();
// Output nodes positions and energy consumption
// Reduce the sampling period of DL stats
TrackNodes("d2d-nodes.txt");
/// Simulator::Schedule (Seconds (5.0), &GenRadioMap, d2dCtrl);
output.flowmon->Start(Seconds(0.1));
output.flowmon->Stop(Seconds(input.simuTime));
NS_LOG_INFO("\tInitializing discovery procedures...");
Simulator::Schedule(Seconds(0.5), &ProSeHelper::InitDiscovery, d2dCtrl, NetDeviceContainer());
// Save configuration
// d2dCtrl->SetConfig(argv[0], false);
Simulator::Stop(Seconds(input.simuTime));
//**** Allow threading dubbed unsafe by the default simulator
Ptr<DefaultSimulatorImpl> sim = DynamicCast<DefaultSimulatorImpl>(Simulator::GetImplementation());
sim->RunWithThreads();
stringstream ss;
ss << "d2d-flowmon_" << (int) input.ueNum << "Ues" << "_Ratio" << input.dUesRatio << ".xml";
output.flowmon->SerializeToXmlFile(ss.str().c_str(), true, true);
Simulator::Destroy();
return output;
}
void
EnableLogging(struct D2dExperiment::Input input)
{
LogLevel logAll = (LogLevel) (LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
LogLevel logInfo = (LogLevel) (LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_INFO);
LogComponentEnable("D2dSimulator", logAll);
LogComponentEnable("LteUtils", logAll);
LogComponentEnable("ProSeApp", logAll);
LogComponentEnable("ProSeAppLteD2d", logAll);
LogComponentEnable("ProSeAppWifi", logAll);
LogComponentEnable("ProSeHelper", logAll);
LogComponentEnable("EpcProSeFcnApp", logAll);
LogComponentEnable("PointToPointHelper", logAll);
LogComponentEnable("PointToPointEpcHelper", logAll);
// LogComponentEnable("LteUeNetDevice", logAll);
LogComponentEnable("EpcSgwPgwApplication", logAll);
/// TEMP
//LogComponentEnable ("Ipv4AddressHelper", logAll);
//LogComponentEnable ("LteSpectrumPhy", logAll);
//LogComponentEnable ("MultiModelSpectrumChannel", logAll);
// LogComponentEnable("Ipv4StaticRouting", logAll);
// LogComponentEnable("TcpSocketBase", logAll);
LogComponentEnable("OnOffApplication", logInfo);
LogComponentEnable("UdpClient", logAll);
LogComponentEnable("PacketSink", logInfo);
if (input.debug)
{
// ...
if (input.debug > 1)
{
LogComponentEnable("MobilityHelper", logAll);
LogComponentEnable("PositionAllocator", logAll);
LogComponentEnable("LteHexGridEnbTopologyHelper", logAll);
LogComponentEnable("HttpClient", logAll);
LogComponentEnable("HttpServer", logAll);
LogComponentEnable("EpcSgwPgwApplication", logAll);
LogComponentEnable("EpcEnbApplication", logAll);
LogComponentEnable("YansWifiHelper", logAll);
// LogComponentEnable ("Ipv6Interface", logAll);
// LogComponentEnable ("Ipv6RawSocketImpl", logAll);
// LogComponentEnable("RandomWalk2d", logAll);
// LogComponentEnable ("LteUeMac", logAll);
LogComponentEnable("EpcUeNas", logAll);
LogComponentEnable("LteNetDevice", logAll);
LogComponentEnable("LteEnbNetDevice", logAll);
LogComponentEnable("LteRlcTm", logAll);
LogComponentEnable("Ipv4L3Protocol", logAll);
LogComponentEnable("Ipv6L3Protocol", logAll);
LogComponentEnable("Icmpv6L4Protocol", logAll);
LogComponentEnable("Ipv4StaticRouting", logAll);
LogComponentEnable("Ipv6StaticRouting", logAll);
LogComponentEnable("YansWifiPhy", logAll);
LogComponentEnable("MinstrelWifiManager", logAll);
LogComponentEnable("YansWifiHelper", logAll);
LogComponentEnable("WifiHelper", logAll);
}
}
}
/** Note: there's a compilation issue on OsX */
void
NetanimTrace(Ptr<ProSeHelper> d2dCtrl)
{
NS_LOG_FUNCTION_NOARGS();
char label[10] = "*";
double animPollInterval = 1.0;
string animationFile = string("d2d-anim.xml");
AnimationInterface anim(animationFile);
anim.SetMobilityPollInterval(Seconds(animPollInterval));
anim.EnablePacketMetadata(true);
uint32_t i = 0;
// uint32_t nNodes = NodeList::GetNNodes ();
Ptr<Node> node;
Ptr<MobilityModel> mob;
Ptr<LteUeNetDevice> udev;
Ptr<LteEnbNetDevice> enbdev;
for (NodeList::Iterator it = NodeList::Begin();
it != NodeList::End(); ++it, ++i)
{
node = *it;
int nDevs = node->GetNDevices();
for (int j = 0; j < nDevs; j++)
{
mob = node->GetObject<MobilityModel> ();
if (mob == 0)
{
anim.SetConstantPosition(node, 0, 0);
anim.UpdateNodeSize(i, 10, 10);
anim.UpdateNodeDescription(node, string(label));
continue;
}
udev = node->GetDevice(j)->GetObject <LteUeNetDevice> ();
if (udev)
{
if (i > 1) // TEMP
{
sprintf(label, "dUe%0d", i);
anim.UpdateNodeColor(node, 0, 0, 194); // blue for dUes
}
else
{
sprintf(label, "cUe%0d", i);
anim.UpdateNodeColor(node, 60, 181, 44); // green for cUes
}
anim.UpdateNodeSize(i, 10, 10);
anim.UpdateNodeDescription(node, string(label));
}
else
{
enbdev = node->GetDevice(j)->GetObject <LteEnbNetDevice> ();
if (enbdev)
{
sprintf(label, "eNB%d", i);
}
anim.UpdateNodeSize(i, 20, 20);
anim.UpdateNodeDescription(node, string(label));
}
}
}
anim.UpdateNodeDescription(d2dCtrl->GetPgwNode(), "PGW");
anim.UpdateNodeDescription(d2dCtrl->GetProseFcnNode(), "ProSeFcn");
NS_LOG_INFO("\tNetwork animation trace packets count: " << anim.GetTracePktCount());
}