-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw.cc
613 lines (502 loc) · 20.5 KB
/
cw.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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#include "ns3/core-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/opengym-module.h"
//#include "ns3/csma-module.h"
#include "ns3/propagation-module.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/ipv4-flow-classifier.h"
#include "ns3/yans-wifi-channel.h"
#include <fstream>
#include <string>
#include <math.h>
#include <ctime> //timestampi
#include <iomanip> // put_time
#include <deque>
#include <algorithm>
#include <csignal>
#include "scenario.h"
using namespace std;
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("OpenGym");
void installTrafficGenerator(Ptr<ns3::Node> fromNode, Ptr<ns3::Node> toNode, int port, string offeredLoad, double startTime);
void PopulateARPcache();
void recordHistory();
double envStepTime = 0.1;
double simulationTime = 10; //seconds
double current_time = 0.0;
bool verbose = false;
int end_delay = 0;
bool dry_run = false;
Ptr<FlowMonitor> monitor;
FlowMonitorHelper flowmon;
ofstream outfile ("scratch/RLinWiFi-master-original-avg-queue-level/CW_data.csv", fstream::out);
uint32_t CW = 0;
// Our data structure for the scenario needs to be a vector of [history_length, 2]
uint32_t history_length = 20;
deque<float> history;
string type = "discrete";
bool non_zero_start = false;
Scenario *wifiScenario;
/*
Define observation space
*/
Ptr<OpenGymSpace> MyGetObservationSpace(void)
{
float low = 0.0;
float high = 10.0;
std::vector<uint32_t> shape = {
history_length,
};
std::string dtype = TypeNameGet<float>();
Ptr<OpenGymBoxSpace> space = CreateObject<OpenGymBoxSpace>(low, high, shape, dtype);
if (verbose)
NS_LOG_UNCOND("MyGetObservationSpace: " << space);
return space;
}
/*
Define action space
*/
Ptr<OpenGymSpace> MyGetActionSpace(void)
{
float low = 0.0;
float high = 10.0;
std::vector<uint32_t> shape = {
1,
};
std::string dtype = TypeNameGet<float>();
Ptr<OpenGymBoxSpace> space = CreateObject<OpenGymBoxSpace>(low, high, shape, dtype);
if (verbose)
NS_LOG_UNCOND("MyGetActionSpace: " << space);
return space;
}
/*
Define extra info. Optional
*/
uint64_t g_rxPktNum = 0;
uint64_t g_txPktNum = 0;
double jain_index(void)
{
double flowThr;
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
double nominator;
double denominator;
double n=0;
double station_id = 0;
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin(); i != stats.end(); ++i)
{
flowThr = i->second.rxBytes;
flowThr /= wifiScenario->getStationUptime(station_id, current_time);
if(flowThr>0){
nominator += flowThr;
denominator += flowThr*flowThr;
n++;
}
station_id++;
}
nominator *= nominator;
denominator *= n;
return nominator/denominator;
}
Ptr<WifiMacQueue> GetQueue(Ptr<Node> node)
{
Ptr<NetDevice> dev = node->GetDevice (0);
Ptr<WifiNetDevice> wifi_dev = DynamicCast<WifiNetDevice> (dev);
Ptr<WifiMac> wifi_mac = wifi_dev->GetMac ();
Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (wifi_mac);
PointerValue ptr;
rmac->GetAttribute ("BE_Txop", ptr);
Ptr<Txop> txop = ptr.Get<Txop> ();
Ptr<WifiMacQueue> queue = txop->GetWifiMacQueue ();
return queue;
}
std::string MyGetExtraInfo(void)
{
static float ticks = 0.0;
static float lastValue = 0.0;
float obs = g_rxPktNum - lastValue;
lastValue = g_rxPktNum;
ticks += envStepTime;
float sentMbytes = obs * (1500 - 20 - 8 - 8) * 8.0 / 1024 / 1024;
std::string myInfo = std::to_string(sentMbytes);
myInfo = myInfo + "|" + to_string(CW) + "|";
myInfo = myInfo + to_string(wifiScenario->getActiveStationCount(ticks)) + "|";
myInfo = myInfo + to_string(jain_index());
if (verbose)
NS_LOG_UNCOND("MyGetExtraInfo: " << myInfo);
return myInfo;
}
/*
Execute received actions
*/
bool MyExecuteActions(Ptr<OpenGymDataContainer> action)
{
if (verbose)
NS_LOG_UNCOND("MyExecuteActions: " << action);
Ptr<OpenGymBoxContainer<float>> box = DynamicCast<OpenGymBoxContainer<float>>(action);
std::vector<float> actionVector = box->GetData();
if (type == "discrete")
{
CW = pow(2, 4+actionVector.at(0));
}
else if (type == "continuous")
{
CW = pow(2, actionVector.at(0) + 4);
}
else if (type == "direct_continuous")
{
CW = actionVector.at(0);
}
else
{
std::cout << "Unsupported agent type!" << endl;
exit(0);
}
uint32_t min_cw = 16;
uint32_t max_cw = 1024;
CW = min(max_cw, max(CW, min_cw));
outfile << current_time << "," << CW << endl;
if(!dry_run){
Config::Set("/$ns3::NodeListPriv/NodeList/*/$ns3::Node/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BE_Txop/$ns3::QosTxop/MinCw", UintegerValue(CW));
Config::Set("/$ns3::NodeListPriv/NodeList/*/$ns3::Node/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BE_Txop/$ns3::QosTxop/MaxCw", UintegerValue(CW));
}
return true;
}
float MyGetReward(void)
{
static float ticks = 0.0;
static uint32_t last_packets = 0;
static float last_reward = 0.0;
ticks += envStepTime;
float res = g_rxPktNum - last_packets;
float reward = res * (1500 - 20 - 8 - 8) * 8.0 / 1024 / 1024 / (5 * 150 * envStepTime) * 10;
last_packets = g_rxPktNum;
if (ticks <= 2 * envStepTime)
return 0.0;
if (verbose)
NS_LOG_UNCOND("MyGetReward: " << reward);
if(reward>1.0f || reward<0.0f)
reward = last_reward;
last_reward = reward;
return last_reward;
}
/*
Collect observations 2
*/
Ptr<OpenGymDataContainer> MyGetObservation()
{
recordHistory();
std::vector<uint32_t> shape = {
history_length,
};
Ptr<OpenGymBoxContainer<float>> box = CreateObject<OpenGymBoxContainer<float>>(shape);
for (uint32_t i = 0; i < history.size(); i++)
{
if (history[i] >= -100 && history[i] <= 100)
box->AddValue(history[i]);
else
box->AddValue(0);
}
for (uint32_t i = history.size(); i < history_length; i++)
{
box->AddValue(0);
}
if (verbose)
NS_LOG_UNCOND("MyGetObservation: " << box);
return box;
}
bool MyGetGameOver(void)
{
// bool isGameOver = (ns3::Simulator::Now().GetSeconds() > simulationTime + end_delay + 1.0);
return false;
}
void ScheduleNextStateRead(double envStepTime, Ptr<OpenGymInterface> openGymInterface)
{
Simulator::Schedule(Seconds(envStepTime), &ScheduleNextStateRead, envStepTime, openGymInterface);
openGymInterface->NotifyCurrentState();
}
void recordHistory()
{
// Keep track of the observations
// We will define them as the error rate of the last `envStepTime` seconds
static uint32_t calls = 0; // Number of calls to this function
calls++;
current_time += envStepTime;
uint32_t nWifi = NodeList::GetNNodes (); // num de stations ou nodes
double norm_value = 0;
double soma_norm_value= 0;
//int max_queue = 500; //1000; 1500; 2000
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) {
Ptr<Node> node = *i;
Ptr<WifiMacQueue> queue = GetQueue (node);
uint32_t value = queue->GetNPackets();
//1) Case: MaxSize Default = 100p
queue->GetMaxSize().GetValue();
//2) Case: Other MaxSize = 500p; 1000p; 1500p; 2000p.
// std::string queuelen = std::to_string(max_queue)+"p"; // the queue size is of type string
//QueueSize size(queuelen);
//queue->SetMaxSize(size);
norm_value = ((double)value)/((double)queue->GetMaxSize().GetValue());
//SOMATORIO
soma_norm_value = soma_norm_value + norm_value;
}
//MEDIA
double mediaTxBuffer = (soma_norm_value)/(nWifi);
history.push_front(mediaTxBuffer);
// Remove the oldest observation if we have filled the history
if (history.size() > history_length)
{
history.pop_back();
}
if (calls < history_length && non_zero_start)
{
// Schedule the next observation if we are not at the end of the simulation
Simulator::Schedule(Seconds(envStepTime), &recordHistory);
}
else if (calls == history_length && non_zero_start)
{
g_rxPktNum = 0;
g_txPktNum = 0;
}
}
void packetReceived(Ptr<const Packet> packet)
{
NS_LOG_DEBUG("Client received a packet of " << packet->GetSize() << " bytes");
g_rxPktNum++;
}
void packetSent(Ptr<const Packet> packet)
{
g_txPktNum++;
}
void set_phy(int nWifi, int guardInterval, NodeContainer &wifiStaNode, NodeContainer &wifiApNode, YansWifiPhyHelper &phy)
{
Ptr<MatrixPropagationLossModel> lossModel = CreateObject<MatrixPropagationLossModel>();
lossModel->SetDefaultLoss(50);
// Define o numero de Stations (nWifi= 5) e numero de Aps (1)
wifiStaNode.Create(nWifi);
wifiApNode.Create(1);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
Ptr<YansWifiChannel> chan = channel.Create();
chan->SetPropagationLossModel(lossModel);
chan->SetPropagationDelayModel(CreateObject<ConstantSpeedPropagationDelayModel>());
phy = YansWifiPhyHelper::Default();
phy.SetChannel(chan);
// Set guard interval
phy.Set("GuardInterval", TimeValue(NanoSeconds(guardInterval)));
}
void set_nodes(int channelWidth, int rng, int32_t simSeed, NodeContainer wifiStaNode, NodeContainer wifiApNode, YansWifiPhyHelper phy, WifiMacHelper mac, WifiHelper wifi, NetDeviceContainer &apDevice)
{
// Set the access point details
Ssid ssid = Ssid("ns3-80211ax");
mac.SetType("ns3::StaWifiMac",
"Ssid", SsidValue(ssid),
"ActiveProbing", BooleanValue(false),
"BE_MaxAmpduSize", UintegerValue(0));
NetDeviceContainer staDevice;
staDevice = wifi.Install(phy, mac, wifiStaNode);
mac.SetType("ns3::ApWifiMac",
"EnableBeaconJitter", BooleanValue(false),
"Ssid", SsidValue(ssid));
apDevice = wifi.Install(phy, mac, wifiApNode);
// Set channel width
Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue(channelWidth));
// mobility.
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
positionAlloc->Add(Vector(0.0, 0.0, 0.0));
positionAlloc->Add(Vector(1.0, 0.0, 0.0));
mobility.SetPositionAllocator(positionAlloc);
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(wifiApNode);
mobility.Install(wifiStaNode);
/* Internet stack*/
InternetStackHelper stack;
stack.Install(wifiApNode);
stack.Install(wifiStaNode);
//Random
if(simSeed!=-1)
RngSeedManager::SetSeed(simSeed);
RngSeedManager::SetRun(rng);
Ipv4AddressHelper address;
address.SetBase("192.168.1.0", "255.255.255.0");
Ipv4InterfaceContainer staNodeInterface;
Ipv4InterfaceContainer apNodeInterface;
staNodeInterface = address.Assign(staDevice);
apNodeInterface = address.Assign(apDevice);
if (!dry_run)
{
Config::Set("/$ns3::NodeListPriv/NodeList/*/$ns3::Node/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BE_Txop/$ns3::QosTxop/MinCw", UintegerValue(CW));
Config::Set("/$ns3::NodeListPriv/NodeList/*/$ns3::Node/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BE_Txop/$ns3::QosTxop/MaxCw", UintegerValue(CW));
}
else
{
NS_LOG_UNCOND("Default CW");
Config::Set("/$ns3::NodeListPriv/NodeList/*/$ns3::Node/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BE_Txop/$ns3::QosTxop/MinCw", UintegerValue(16));
Config::Set("/$ns3::NodeListPriv/NodeList/*/$ns3::Node/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BE_Txop/$ns3::QosTxop/MaxCw", UintegerValue(1024));
}
}
void set_sim(bool tracing, bool dry_run, int warmup, uint32_t openGymPort, YansWifiPhyHelper phy, NetDeviceContainer apDevice, int end_delay, Ptr<FlowMonitor> &monitor, FlowMonitorHelper &flowmon)
{
monitor = flowmon.InstallAll();
monitor->SetAttribute("StartTime", TimeValue(Seconds(warmup)));
if (tracing)
{
phy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
phy.EnablePcap("cw", apDevice.Get(0));
}
Ptr<OpenGymInterface> openGymInterface = CreateObject<OpenGymInterface>(openGymPort);
openGymInterface->SetGetActionSpaceCb(MakeCallback(&MyGetActionSpace));
openGymInterface->SetGetObservationSpaceCb(MakeCallback(&MyGetObservationSpace));
openGymInterface->SetGetGameOverCb(MakeCallback(&MyGetGameOver));
openGymInterface->SetGetObservationCb(MakeCallback(&MyGetObservation));
openGymInterface->SetGetRewardCb(MakeCallback(&MyGetReward));
openGymInterface->SetGetExtraInfoCb(MakeCallback(&MyGetExtraInfo));
openGymInterface->SetExecuteActionsCb(MakeCallback(&MyExecuteActions));
// if (!dry_run)
// {
if (non_zero_start)
{
Simulator::Schedule(Seconds(1.0), &recordHistory);
Simulator::Schedule(Seconds(envStepTime * history_length + 1.0), &ScheduleNextStateRead, envStepTime, openGymInterface);
}
else
Simulator::Schedule(Seconds(1.0), &ScheduleNextStateRead, envStepTime, openGymInterface);
// }
Simulator::Stop(Seconds(simulationTime + end_delay + 1.0 + envStepTime*(history_length+1)));
NS_LOG_UNCOND("Simulation started");
Simulator::Run();
}
void signalHandler(int signum)
{
cout << "Interrupt signal " << signum << " received.\n";
exit(signum);
}
int main(int argc, char *argv[])
{
int nWifi = 5;
bool tracing = false;
bool useRts = false;
int mcs = 11;
int channelWidth = 20;
int guardInterval = 800;
string offeredLoad = "150";
int port = 1025;
string outputCsv = "cw.csv";
string scenario = "basic";
dry_run = false;
int rng = 1;
int warmup = 1;
uint32_t openGymPort = 0; //5555;
int32_t simSeed = 42; //changed the, before it was seed = -1
signal(SIGTERM, signalHandler);
outfile << "SimulationTime,CW" << endl;
CommandLine cmd;
cmd.AddValue("openGymPort", "Specify port number. Default: 5555", openGymPort);
cmd.AddValue("CW", "Value of Contention Window", CW);
cmd.AddValue("historyLength", "Length of history window", history_length);
cmd.AddValue("nWifi", "Number of wifi 802.11ax STA devices", nWifi);
cmd.AddValue("verbose", "Tell echo applications to log if true", verbose);
cmd.AddValue("tracing", "Enable pcap tracing", tracing);
cmd.AddValue("rng", "Number of RngRun", rng);
cmd.AddValue("simTime", "Simulation time in seconds. Default: 10s", simulationTime);
cmd.AddValue("envStepTime", "Step time in seconds. Default: 0.1s", envStepTime);
cmd.AddValue("agentType", "Type of agent actions: discrete, continuous", type);
cmd.AddValue("nonZeroStart", "Start only after history buffer is filled", non_zero_start);
cmd.AddValue("scenario", "Scenario for analysis: basic, convergence, reaction", scenario);
cmd.AddValue("dryRun", "Execute scenario with BEB and no agent interaction", dry_run);
cmd.AddValue("seed", "Random seed", simSeed);
cmd.Parse(argc, argv);
// history_length*=2;
NS_LOG_UNCOND("Ns3Env parameters:");
NS_LOG_UNCOND("--nWifi: " << nWifi);
NS_LOG_UNCOND("--simulationTime: " << simulationTime);
NS_LOG_UNCOND("--openGymPort: " << openGymPort);
NS_LOG_UNCOND("--envStepTime: " << envStepTime);
NS_LOG_UNCOND("--seed: " << simSeed);
NS_LOG_UNCOND("--agentType: " << type);
NS_LOG_UNCOND("--scenario: " << scenario);
NS_LOG_UNCOND("--dryRun: " << dry_run);
if (verbose)
{
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
if (useRts)
{
Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("0"));
}
// Cria(instancia) objeto da classe NodeContainer para criar os dois tipos de Nodes (Sta e Ap)
NodeContainer wifiStaNode;
NodeContainer wifiApNode;
YansWifiPhyHelper phy;
set_phy(nWifi, guardInterval, wifiStaNode, wifiApNode, phy);
WifiMacHelper mac;
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211ax_5GHZ);
std::ostringstream oss;
oss << "HeMcs" << mcs;
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode", StringValue(oss.str()),
"ControlMode", StringValue(oss.str()));
//802.11ac PHY
/*
phy.Set ("ShortGuardEnabled", BooleanValue (0));
wifi.SetStandard (WIFI_PHY_STANDARD_80211ac);
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("VhtMcs8"),
"ControlMode", StringValue ("VhtMcs8"));
*/
//802.11n PHY
//phy.Set ("ShortGuardEnabled", BooleanValue (1));
//wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
//wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
// "DataMode", StringValue ("HtMcs7"),
// "ControlMode", StringValue ("HtMcs7"));
NetDeviceContainer apDevice;
set_nodes(channelWidth, rng, simSeed, wifiStaNode, wifiApNode, phy, mac, wifi, apDevice);
ScenarioFactory helper = ScenarioFactory(nWifi, wifiStaNode, wifiApNode, port, offeredLoad, history_length);
wifiScenario = helper.getScenario(scenario);
// if (!dry_run)
// {
if (non_zero_start)
end_delay = envStepTime * history_length + 1.0;
else
end_delay = 0.0;
// }
wifiScenario->installScenario(simulationTime + end_delay + envStepTime, envStepTime, MakeCallback(&packetReceived));
// Config::ConnectWithoutContext("/NodeList/0/ApplicationList/*/$ns3::OnOffApplication/Tx", MakeCallback(&packetSent));
Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin", MakeCallback(&packetSent));
//Config::SetDefault ("ns3::QueueBase::MaxSize", StringValue ("80p"));
wifiScenario->PopulateARPcache();
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
set_sim(tracing, dry_run, warmup, openGymPort, phy, apDevice, end_delay, monitor, flowmon);
double flowThr;
float res = g_rxPktNum * (1500 - 20 - 8 - 8) * 8.0 / 1024 / 1024;
printf("Sent mbytes: %.2f\tThroughput: %.3f", res, res/simulationTime);
ofstream myfile;
myfile.open(outputCsv, ios::app);
//std::ofstream file( file_name, std::ios::app ) ;
//fout.open("name_age.dat",ios::app);
/* Contents of CSV output file
Timestamp, CW, nWifi, RngRun, SourceIP, DestinationIP, Throughput
*/
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin(); i != stats.end(); ++i)
{
auto time = std::time(nullptr); //Get timestamp
auto tm = *std::localtime(&time);
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(i->first);
flowThr = i->second.rxBytes * 8.0 / simulationTime / 1000 / 1000;
NS_LOG_UNCOND("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\tThroughput: " << flowThr << " Mbps\tTime: " << i->second.timeLastRxPacket.GetSeconds() - i->second.timeFirstTxPacket.GetSeconds() << " s\tRx packets " << i->second.rxPackets);
myfile << std::put_time(&tm, "%Y-%m-%d %H:%M") << "," << CW << "," << nWifi << "," << RngSeedManager::GetRun() << "," << t.sourceAddress << "," << t.destinationAddress << "," << flowThr;
myfile << std::endl;
}
myfile.close();
Simulator::Destroy();
NS_LOG_UNCOND("Packets registered by handler: " << g_rxPktNum << " Packets" << endl);
return 0;
}