-
Notifications
You must be signed in to change notification settings - Fork 4
/
ICON.cc
719 lines (609 loc) · 25.3 KB
/
ICON.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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
#include <vector>
#include <iomanip>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/point-to-point-layout-module.h"
#include "ns3/mobility-module.h"
#include "ns3/applications-module.h"
#include "ns3/dcn-module.h"
using namespace ns3;
using namespace std;
// Parameters
double d_LinkSpeed = 10.0;
string LinkSpeed = "10Gbps";
string LinkDelay = "15us";
double linkDelay = 15e-6;
uint32_t MachinesPerRack = 20;
uint32_t NumberofRacks = 20;
uint32_t NumberofSpineSwitches = 10;
uint32_t Scale = 1;
double load = 0.1;
uint32_t threshold = 22.5e3;
uint32_t queueBytes = 225e3; // Number of bytes per queue port
uint32_t initCwnd = 10; // TCP Initial Congestion Window
double minRto = 10000e-6;
uint32_t segmentSize = 1460;
bool LinkUtilization = 0;
string StatsFileName = "dummy1.txt";
double interval = 0.010;
uint32_t incastDegree = 24;
double incastFactor = 0.5;
double longLoadFactor = 0.8;
double longNodeFactor = 0.3;
uint32_t FlowSizeShort = 16*1024;
uint32_t FlowSizeLong = 1024 * 1024;
uint32_t IncastFlowSizeLong = 64*1024;
bool pktspray = 0;
bool dctcp = 1;
double testruntime = 0.25;
// Derived Parameters
uint32_t LongRequestsPerNode;
uint32_t ShortRequestsPerNode;
uint32_t IncastRequestsPerNode;
uint32_t NumberofEndPoints;
uint32_t NumberofEndPointsLong;
uint32_t NumberofIncastPoints;
uint32_t NumberofEndPointsShort;
uint32_t NumberofEndPointsIncast;
double InterArrival_long;
double InterArrival_short;
double InterArrival_incast;
uint32_t NumShortFlows;
uint32_t NumIncastFlows;
uint32_t NumLongFlows;
double shortLoadFactor;
double incastLoadFactor;
uint32_t NumberofIncastSenders;
uint32_t NumberofIncastAggregators;
std::ostringstream oss;
// declare the node pointers
vector < Ptr <Node> > nEnd;
vector < Ptr <Node> > nSpine;
vector < Ptr <Node> > nLeaf;
NS_LOG_COMPONENT_DEFINE ("DataCenterSimulator");
std::map<Ptr<Socket>, Time> sockets;
void QueuedPackets(uint32_t oldValue, uint32_t newValue)
{
NS_LOG_INFO ("Packets in Queue at " << Simulator::Now ().GetSeconds ()<<"are \t"<<newValue);
}
void
QueueStat ()
{
Config::ConnectWithoutContext ("/NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/$ns3::DropTailQueue/PacketsInQueue", MakeCallback (&QueuedPackets));
// Simulator::Schedule (Seconds(0.1), &QueueStat);
}
void
randomShort (void)
{
Ptr<UniformRandomVariable> UniformlyRandomly = CreateObject<UniformRandomVariable> ();
UniformlyRandomly->SetAttribute ("Min", DoubleValue (1));
UniformlyRandomly->SetAttribute ("Max", DoubleValue (99));
if (UniformlyRandomly->GetValue () < 34){
FlowSizeShort = 8 * 1024;
}
else if (33 < UniformlyRandomly->GetValue () && UniformlyRandomly->GetValue () < 67) {
FlowSizeShort = 16 * 1024;
}
else {
FlowSizeShort = 32 * 1024;
}
}
void Configure_Simulator(){
bool status = true;
NS_LOG_INFO ("Configuring the DataCenter Simulator");
Packet::EnablePrinting ();
NumberofRacks = NumberofRacks * Scale;
NumberofSpineSwitches = NumberofSpineSwitches * Scale;
NumberofEndPoints = MachinesPerRack * NumberofRacks;
NumberofEndPointsLong = longNodeFactor * NumberofEndPoints; // each rack has one sender and receiver
NumberofEndPointsShort = (NumberofEndPoints - NumberofEndPointsLong)*(1.0-incastFactor);
NumberofEndPointsIncast = NumberofEndPoints - NumberofEndPointsLong - NumberofEndPointsShort;
cout<<"Number of Long EndPoints :"<<NumberofEndPointsLong<<endl;
cout<<"Number of Short EndPoints :"<<NumberofEndPointsShort<<endl;
cout<<"Number of Incasts EndPoints :"<<NumberofEndPointsIncast<<endl;
shortLoadFactor = (1.0 - longLoadFactor)*(1.0 - incastFactor);
incastLoadFactor = 1.0 - longLoadFactor - shortLoadFactor;
cout<<"Short Load Factor :"<<shortLoadFactor<<endl;
cout<<"Long Load Factor :"<<longLoadFactor<<endl;
cout<<"incast Load Factor :"<<incastLoadFactor<<endl;
// use these instead of delay:
NumberofIncastSenders = NumberofEndPointsIncast - 32;//incastDegree * ((int) (NumberofEndPointsIncast/incastDegree));
if(NumberofIncastSenders == NumberofEndPointsIncast){
NumberofIncastSenders = incastDegree * (((int)(NumberofEndPointsIncast/incastDegree)) - 1 );
}
NumberofIncastAggregators = NumberofEndPointsIncast - NumberofIncastSenders;
cout<<"Incast Senders are :"<<NumberofIncastSenders<<endl;
cout<<"Incast Aggregators are :"<<NumberofIncastAggregators<<endl;
if(longLoadFactor > 0)
{
InterArrival_long = (NumberofEndPointsLong*FlowSizeLong*8) / (load * longLoadFactor * d_LinkSpeed * NumberofSpineSwitches*NumberofRacks *1000000000);
}
else{
InterArrival_long = 0;
}
InterArrival_short = (NumberofEndPointsShort*FlowSizeShort*8) / (load * shortLoadFactor * d_LinkSpeed * NumberofSpineSwitches*NumberofRacks *1000000000);
InterArrival_incast = (NumberofIncastAggregators*FlowSizeShort*8*incastDegree) / (load * incastLoadFactor * d_LinkSpeed * NumberofRacks * NumberofSpineSwitches *1000000000); // TODO: Include incast degree in the formula
cout<<"Short Flow InterArrival Time :"<<InterArrival_short<<endl;
cout<<"Long Flow InterArrival Time :"<<InterArrival_long<<endl;
cout<<"Incast Flow InterArrival Time :"<<InterArrival_incast<<endl;
ShortRequestsPerNode = int ((1/InterArrival_short)*testruntime);
if(InterArrival_long > 0)
{
LongRequestsPerNode = int ((1/InterArrival_long)*testruntime);
}
else{
LongRequestsPerNode = 0;
}
IncastRequestsPerNode = int ((1/InterArrival_incast)*testruntime);
cout<<"Short Requests Per Node :"<<ShortRequestsPerNode<<endl;
cout<<"Long Requests Per Node :"<<LongRequestsPerNode<<endl;
cout<<"Incast Requests Per Node :"<<IncastRequestsPerNode<<endl;
cout<<"Short Flow Size :"<<FlowSizeShort<<endl;
cout<<"Long Flow Size :"<<FlowSizeLong<<endl;
ofstream outfile;
outfile.open(StatsFileName.c_str());
outfile.close();
double minRtt = (8 * linkDelay);
/* Set the simple parameters */
status = Config::SetDefaultFailSafe ("ns3::TcpSocket::SegmentSize", UintegerValue (segmentSize));
status &= Config::SetDefaultFailSafe ("ns3::TcpSocketBase::FCTFileName", StringValue ( StatsFileName));
status &= Config::SetDefaultFailSafe ("ns3::RttEstimator::InitialEstimation", TimeValue ( Seconds (minRtt)));
status &= Config::SetDefaultFailSafe ("ns3::TcpSocket::SndBufSize", UintegerValue (1e9)); //Large value
status &= Config::SetDefaultFailSafe ("ns3::TcpSocket::RcvBufSize", UintegerValue (1e9)); //Large value
status &= Config::SetDefaultFailSafe ("ns3::TcpSocket::InitialCwnd", UintegerValue (initCwnd));
status &= Config::SetDefaultFailSafe ("ns3::TcpSocket::ConnTimeout", TimeValue (Seconds (minRtt)));
status &= Config::SetDefaultFailSafe ("ns3::TcpSocket::ConnCount", UintegerValue (33));
status &= Config::SetDefaultFailSafe ("ns3::TcpSocket::DelAckCount", UintegerValue (1));
status &= Config::SetDefaultFailSafe ("ns3::TcpSocketBase::MultiQueue", BooleanValue(true));
if(!pktspray)
{
status &= Config::SetDefaultFailSafe ("ns3::Ipv4GlobalRouting::FlowEcmpRouting", BooleanValue(true));
}
else
{
status &= Config::SetDefaultFailSafe ("ns3::Ipv4GlobalRouting::RandomEcmpRouting", BooleanValue(true));
status &= Config::SetDefaultFailSafe ("ns3::TcpNewReno::ReTxThreshold", UintegerValue(20));
}
status &= Config::SetDefaultFailSafe ("ns3::RttEstimator::MinRTO", TimeValue ( Seconds (minRto)));
if(!dctcp)
{
status &= Config::SetDefaultFailSafe ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpNewReno::GetTypeId ()));
}
else
{
status &= Config::SetDefaultFailSafe ("ns3::Ipv4L3Protocol::ECN", BooleanValue (true));
status &= Config::SetDefaultFailSafe ("ns3::TcpL4Protocol::SocketType", TypeIdValue (Dctcp::GetTypeId ()));
}
NS_ASSERT(status);
}
void
PrintTime (void)
{
NS_LOG_UNCOND (Simulator::Now ());
Simulator::Schedule (Seconds(0.005), &PrintTime);
}
void Build_Topology()
{
NS_LOG_INFO ("Building the Topology");
for (uint32_t i=0;i<NumberofEndPoints;i++)
nEnd.push_back(CreateObject<Node> ());
NS_LOG_INFO("Allocated " << nEnd.size() << " EndPoint nodes..");
for (uint32_t i=0;i<NumberofSpineSwitches;i++)
{
nSpine.push_back(CreateObject<Node> ());
}
NS_LOG_INFO("Allocated " << nSpine.size() << " Spine switches..");
for (uint32_t i=0;i<NumberofRacks;i++)
nLeaf.push_back(CreateObject<Node> ());
NS_LOG_INFO("Allocated " << nLeaf.size() << " Leaf switches..");
NS_LOG_INFO("Installing IP stack on the nodes ..");
InternetStackHelper internet;
for (uint32_t i=0;i<NumberofRacks;i++)
{
internet.Install (nLeaf[i]);
}
for (uint32_t i=0;i<NumberofSpineSwitches;i++)
internet.Install (nSpine[i]);
NS_LOG_INFO("Installed IP stack on all switches...");
for (uint32_t i=0;i<NumberofEndPoints;i++)
internet.Install(nEnd[i]);
NS_LOG_INFO("Installed TCP/IP stack on all servers...");
NS_LOG_INFO ("Create channels.");
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue (LinkSpeed));
p2p.SetChannelAttribute ("Delay", StringValue (LinkDelay));
std::string queueType = "ns3::DropTailQueue";
std::string n1 = "Mode";
Ptr<AttributeValue> v1 = Create<EnumValue> (DropTailQueue::QUEUE_MODE_BYTES);
std::string n2 = "MaxBytes";
Ptr<AttributeValue> v2 = Create<UintegerValue> (queueBytes);
std::string n3 = "";
Ptr<AttributeValue> v3 = Create<EmptyAttributeValue> ();
if(dctcp) {
n3 = "Th";
queueType = "ns3::SimpleRedEcnQueue";
v3 = Create<UintegerValue> (threshold);
}
p2p.SetQueue (queueType,
n1, *v1,
n2, *v2,
n3, *v3);
PointToPointHelper e2e;
e2e.SetDeviceAttribute ("DataRate", StringValue (LinkSpeed));
e2e.SetChannelAttribute ("Delay", StringValue (LinkDelay));
e2e.SetDevice ("ns3::MQQNetDevice",
"PauseTime", UintegerValue (40));
e2e.SetQueue ("ns3::SimpleRedEcnQueue",
n1, *v1,
n2, *v2,
n3, *v3);
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.0.0.0", "255.255.255.0");
NetDeviceContainer devices;
Ipv4InterfaceContainer interfaces;
for (uint32_t i=0;i<NumberofEndPoints;i++){
devices = e2e.Install (nEnd[i],nLeaf[i/MachinesPerRack]);
interfaces = ipv4.Assign(devices);
ipv4.NewNetwork();
}
for (uint32_t i=0;i<NumberofSpineSwitches;i++){
for (uint32_t j=0;j<NumberofRacks;j++){
devices = p2p.Install(nSpine[i],nLeaf[j]);
interfaces = ipv4.Assign(devices);
ipv4.NewNetwork();
}
}
NS_LOG_INFO ("Populate routing tables.");
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
}
void SetupServerTraffic (Ptr<Node> Nd, uint16_t appPort, Time startTime, uint8_t priority)
{
PacketSinkHelper sink ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), appPort));
sink.SetAttribute ("Priority", UintegerValue (priority));
ApplicationContainer sinkApps = sink.Install (Nd);
sinkApps.Start(startTime);
}
void SetupClientTraffic(Ptr<Node> Nd,Ptr<Node> ServerNode, uint32_t txsize, uint16_t appPort, Time startTime , uint8_t priority){
BulkSendHelper source ("ns3::TcpSocketFactory",InetSocketAddress(ServerNode->GetObject<Ipv4>()->GetAddress(1,0).GetLocal(), appPort));
source.SetAttribute ("MaxBytes", UintegerValue (txsize));
source.SetAttribute ("SendSize", UintegerValue (txsize));
source.SetAttribute ("Priority", UintegerValue (priority));
ApplicationContainer sourceApps = source.Install (Nd);
sourceApps.Start(startTime);
}
void SetDataRate(Ptr<Node> rnode, int DummyID)
{
Ptr<Ipv4L3Protocol> rnodeip = rnode->GetObject<Ipv4L3Protocol>();
//Configure Transmit Data Rate
for(uint32_t i = 0; i < rnodeip->GetNInterfaces(); i++) {
Ptr<NetDevice> netdev = rnodeip->GetNetDevice(i);
Ptr<MQQNetDevice> ptpnetdev = netdev->GetObject<MQQNetDevice>();
if(!ptpnetdev) {
continue;
}
ptpnetdev->SetAttributeFailSafe("ServerNode", BooleanValue(true));
}
}
double AppDelay(){
Ptr<ExponentialRandomVariable> ApplicationDelay = CreateObject<ExponentialRandomVariable> ();
ApplicationDelay->SetAttribute ("Mean", DoubleValue (10));
ApplicationDelay->SetAttribute ("Bound", DoubleValue (120));
double delay = ApplicationDelay->GetValue();
return delay;
}
void Setup_Workload(){
vector <uint32_t> AppIdxLong;
vector <uint32_t> AppIdxShort;
vector <uint32_t> AppIdxIncast;
vector <uint32_t> IncastSenders;
vector <uint32_t> IncastAggregators;
map<uint32_t,vector <uint16_t> > Map_Port;
map<uint32_t,vector <uint32_t> > Map_Client;
Map_Port.clear();
Map_Client.clear();
uint16_t appPort;
AppIdxShort.clear();
AppIdxLong.clear();
AppIdxIncast.clear();
IncastSenders.clear();
IncastAggregators.clear();
Ptr<ExponentialRandomVariable> ApplicationDelay = CreateObject<ExponentialRandomVariable> ();
ApplicationDelay->SetAttribute ("Mean", DoubleValue (0.000082));
ApplicationDelay->SetAttribute ("Bound", DoubleValue (0.0012));
Ptr<UniformRandomVariable> UniformlyRandomly = CreateObject<UniformRandomVariable> ();
UniformlyRandomly->SetAttribute ("Min", DoubleValue (0));
UniformlyRandomly->SetAttribute ("Max", DoubleValue (65535));
uint32_t ServerNodeIdx,ClientNodeIdx;
vector<Time> Prev_Start;
Prev_Start.clear();
Ptr<ExponentialRandomVariable> DelayRandomlyShort = CreateObject<ExponentialRandomVariable> ();
Ptr<ExponentialRandomVariable> DelayRandomlyLong = CreateObject<ExponentialRandomVariable> ();
Ptr<ExponentialRandomVariable> DelayRandomlyIncast = CreateObject<ExponentialRandomVariable> ();
DelayRandomlyShort->SetAttribute ("Mean", DoubleValue(InterArrival_short));
DelayRandomlyLong->SetAttribute ("Mean", DoubleValue(InterArrival_long));
DelayRandomlyIncast->SetAttribute ("Mean", DoubleValue(InterArrival_incast));
Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
uint32_t min = 0.0;
uint32_t max = MachinesPerRack-1;
uint32_t appNode = 0.0;
for(uint32_t i=0;i<NumberofRacks;i++)
{
x->SetAttribute ("Min", DoubleValue (min));
x->SetAttribute ("Max", DoubleValue (max));
for(uint32_t j=0;j<MachinesPerRack*longNodeFactor;j++)
{
do {
appNode = x->GetInteger ();
} while ((find(AppIdxShort.begin(),AppIdxShort.end(),appNode) != AppIdxShort.end()) || (find(AppIdxLong.begin(),AppIdxLong.end(),appNode) != AppIdxLong.end()));
AppIdxLong.push_back(appNode);
}
for(uint32_t j=0;j<MachinesPerRack*(1.0-longNodeFactor)*(1.0 - incastFactor);j++)
{
do {
appNode = x->GetInteger ();
} while ((find(AppIdxShort.begin(),AppIdxShort.end(),appNode) != AppIdxShort.end()) || (find(AppIdxLong.begin(),AppIdxLong.end(),appNode) != AppIdxLong.end()));
AppIdxShort.push_back(appNode);
}
min = min + MachinesPerRack;
max = max + MachinesPerRack;
}
for (uint32_t i=0;i<NumberofEndPoints;i++)
{
bool IncastId = true;
Prev_Start.push_back(Seconds(0.0));
for(uint32_t j=0;j<AppIdxLong.size();j++)
{
if(AppIdxLong[j] == i)
{
IncastId = false;
}
}
for(uint32_t j=0;j<AppIdxShort.size();j++)
{
if(AppIdxShort[j] == i)
{
IncastId = false;
}
}
if(IncastId)
{
AppIdxIncast.push_back(i);
}
}
NS_ASSERT(AppIdxLong.size() == NumberofEndPointsLong);
NS_ASSERT(AppIdxShort.size() == NumberofEndPointsShort);
NS_ASSERT(AppIdxIncast.size() == NumberofEndPointsIncast);
for (uint32_t k=0;k < ShortRequestsPerNode; k++){
random_shuffle(AppIdxShort.begin(),AppIdxShort.end());
for (uint32_t i=0;i<AppIdxShort.size(); i=i+2){
randomShort();
ServerNodeIdx = AppIdxShort[i];
ClientNodeIdx = AppIdxShort[i+1];
do {
appPort = UniformlyRandomly->GetInteger(0,65535);
} while (find(Map_Port[ServerNodeIdx].begin(),Map_Port[ServerNodeIdx].end(),appPort) != Map_Port[ServerNodeIdx].end());
Map_Port[ServerNodeIdx].push_back(appPort);
Time Curr_Start = Prev_Start[ClientNodeIdx] + Seconds (DelayRandomlyShort->GetValue());
Prev_Start[ClientNodeIdx] = Curr_Start;
SetupServerTraffic(nEnd[ServerNodeIdx],appPort,Curr_Start,1);
SetupClientTraffic(nEnd[ClientNodeIdx],nEnd[ServerNodeIdx],FlowSizeShort,appPort,Curr_Start,1);
NumShortFlows++;
Curr_Start = Prev_Start[ServerNodeIdx] + Seconds (DelayRandomlyShort->GetValue());
Prev_Start[ServerNodeIdx] = Curr_Start;
SetupServerTraffic(nEnd[ClientNodeIdx],appPort,Curr_Start,1);
SetupClientTraffic(nEnd[ServerNodeIdx],nEnd[ClientNodeIdx],FlowSizeShort,appPort,Curr_Start,1);
NumShortFlows++;
}
}
cout<<"Short flows Schedueled: " << NumShortFlows<<endl;
for (uint32_t k=0;k < LongRequestsPerNode; k++){
random_shuffle(AppIdxLong.begin(),AppIdxLong.end());
for (uint32_t i=0;i<AppIdxLong.size(); i=i+2){
ServerNodeIdx = AppIdxLong[i];
ClientNodeIdx = AppIdxLong[i+1];
do {
appPort = UniformlyRandomly->GetInteger(0,65535);
} while (find(Map_Port[ServerNodeIdx].begin(),Map_Port[ServerNodeIdx].end(),appPort) != Map_Port[ServerNodeIdx].end());
Map_Port[ServerNodeIdx].push_back(appPort);
Time Curr_Start = Prev_Start[ClientNodeIdx] + Seconds (DelayRandomlyLong->GetValue());
Prev_Start[ClientNodeIdx] = Curr_Start;
SetupServerTraffic(nEnd[ServerNodeIdx],appPort,Curr_Start,1);
SetupClientTraffic(nEnd[ClientNodeIdx],nEnd[ServerNodeIdx],FlowSizeLong,appPort,Curr_Start,1);
NumLongFlows++;
Curr_Start = Prev_Start[ServerNodeIdx] + Seconds (DelayRandomlyLong->GetValue());
Prev_Start[ServerNodeIdx] = Curr_Start;
SetupServerTraffic(nEnd[ClientNodeIdx],appPort,Curr_Start,1);
SetupClientTraffic(nEnd[ServerNodeIdx],nEnd[ClientNodeIdx],FlowSizeLong,appPort,Curr_Start,1);
NumLongFlows++;
}
}
cout<<"long flows Schedueled: " << NumLongFlows<<endl;
random_shuffle(AppIdxIncast.begin(),AppIdxIncast.end());
for(uint32_t i=0; i < AppIdxIncast.size();i++){
if(i < NumberofIncastSenders)
{
IncastSenders.push_back(AppIdxIncast[i]);
}
else{
IncastAggregators.push_back(AppIdxIncast[i]);
}
}
NS_ASSERT(IncastSenders.size() == NumberofIncastSenders);
NS_ASSERT(IncastAggregators.size() == NumberofIncastAggregators);
for(uint32_t i=0; i <IncastAggregators.size();i++){
random_shuffle(IncastSenders.begin(),IncastSenders.end());
for(uint32_t j=0;j<incastDegree;j++)
{
Map_Client[IncastAggregators[i]].push_back(IncastSenders[j]);
}
}
for (uint32_t k=0;k < IncastRequestsPerNode; k++){
for (uint32_t i=0;i<IncastAggregators.size(); i++){
ServerNodeIdx = IncastAggregators[i];
randomShort();
do {
appPort = UniformlyRandomly->GetInteger(0,65535);
} while (find(Map_Port[ServerNodeIdx].begin(),Map_Port[ServerNodeIdx].end(),appPort) != Map_Port[ServerNodeIdx].end());
Map_Port[ServerNodeIdx].push_back(appPort);
Time Curr_Start = Prev_Start[ServerNodeIdx] + Seconds (DelayRandomlyIncast->GetValue());
Prev_Start[ServerNodeIdx] = Curr_Start;
SetupServerTraffic(nEnd[ServerNodeIdx],appPort,Curr_Start,1);
vector<uint32_t> ClientIdx = Map_Client[ServerNodeIdx];
for(uint32_t j=0;j<ClientIdx.size();j++)
{
ClientNodeIdx = ClientIdx[j];
if (j==0){ //j % incastDegree == 0;
SetupClientTraffic(nEnd[ClientNodeIdx],nEnd[ServerNodeIdx],IncastFlowSizeLong,appPort,Curr_Start,1);
}
else {
SetupClientTraffic(nEnd[ClientNodeIdx],nEnd[ServerNodeIdx],FlowSizeShort,appPort,Curr_Start+Seconds (0.000080 + AppDelay()/1000000),1);
}
}
NumIncastFlows++;
}
}
cout<<"Incast flows Schedueled: " << NumIncastFlows<<endl;
}
void SetupServer(Ptr<Node> rnode)
{
bool set_successful = true;
Ptr<Ipv4L3Protocol> rnodeip = rnode->GetObject<Ipv4L3Protocol>();
//Configure output queues
for(uint32_t i = 0; i < rnodeip->GetNInterfaces(); i++) {
Ptr<NetDevice> netdev = rnodeip->GetNetDevice(i);
Ptr<MQQNetDevice> ptpnetdev = netdev->GetObject<MQQNetDevice>();
if(!ptpnetdev) {
continue;
}
Ptr<Queue> queue = ptpnetdev->GetQueue();
if(!dctcp){
Ptr<DropTailQueue> dtqueue = queue->GetObject<DropTailQueue>();
set_successful &= dtqueue->SetAttributeFailSafe("Mode", EnumValue(DropTailQueue::QUEUE_MODE_BYTES));
set_successful &= dtqueue->SetAttributeFailSafe("MaxBytes", UintegerValue(4 * 1024 * 1024)); //4 MB typical to accomodate
}
else{
Ptr<SimpleRedEcnQueue> dtqueue = queue->GetObject<SimpleRedEcnQueue>();
set_successful &= dtqueue->SetAttributeFailSafe("Mode", EnumValue(DropTailQueue::QUEUE_MODE_BYTES));
set_successful &= dtqueue->SetAttributeFailSafe("MaxBytes", UintegerValue(4 * 1024 * 1024)); //4 MB typical to accomodate
set_successful &= dtqueue->SetAttributeFailSafe("Th", UintegerValue(4 * 1024 * 1024));
}
}
NS_ASSERT(set_successful);
}
void Setup_Servers()
{
for (uint32_t i=0;i<NumberofEndPoints;i++)
{
SetDataRate(nEnd[i],i);
}
}
void MeasureLink (Ptr<OutputStreamWrapper> stream, Ptr<Node> rnode)
{
double link_utilization;
Ptr<Ipv4L3Protocol> rnodeip = rnode->GetObject<Ipv4L3Protocol>();
NS_ASSERT(rnodeip);
for(uint32_t j = 0; j < rnodeip->GetNInterfaces(); j++)
{
Ptr<NetDevice> netdev = rnodeip->GetNetDevice(j);
Ptr<PointToPointNetDevice> ptpnetdev = netdev->GetObject<PointToPointNetDevice>();
if(!ptpnetdev) {
continue;
}
NS_ASSERT(ptpnetdev);
link_utilization = (double) (ptpnetdev->m_bytes_transmitted * 8)/ interval;
ptpnetdev->m_bytes_transmitted = 0;
*stream->GetStream ()<<"Node: "<< rnode->GetId()<<"\tInterface:"<< j <<"\tlink utilization:"<<link_utilization<<endl;
}
}
void MeasureLinkUtilization(Ptr<OutputStreamWrapper> stream)
{
for (uint32_t i=0;i<NumberofSpineSwitches;i++)
{
MeasureLink(stream, nSpine[i]);
}
Simulator::Schedule(Seconds(interval),&MeasureLinkUtilization,stream);
}
void ProbeApps(uint32_t junk)
{
bool stopnow = true;
int total = 0;
uint32_t count = 0;
for (uint32_t i=0;i<NumberofEndPoints;i++)
{
for (uint32_t j=0;j<nEnd[i]->GetNApplications();j++)
{
Ptr <Application> Traceapp = nEnd[i]->GetApplication(j);
if (Traceapp)
{
Ptr <BulkSendApplication> Tracebulk = Traceapp->GetObject<BulkSendApplication>();
if (Tracebulk)
{
total++;
if (Tracebulk->m_application_ended == false)
{
stopnow = false;
}
else
{
count++;
}
}
}
}
}
if (stopnow)
{
NS_ASSERT(count == (NumShortFlows + NumLongFlows + NumIncastFlows));
Simulator::Stop();
}
else
{
Simulator::Schedule(Seconds(interval),&ProbeApps,0);
}
}
int
main (int argc, char *argv[])
{
CommandLine cmd;
cmd.AddValue ("load", "Controls the n/w load", load);
cmd.AddValue ("dctcp", "Enable DCTCP", dctcp);
cmd.AddValue ("runtime", "Test Runtime in Seconds", testruntime);
cmd.AddValue ("random", "Load Balancing : Random ECMP", pktspray);
cmd.AddValue ("incastdegree", "Degree of Incast", incastDegree);
cmd.AddValue ("filename", "FileName to Dump Stats", StatsFileName);
cmd.AddValue ("linkutilization", "Measure Link Utilization", LinkUtilization);
cmd.Parse (argc, argv);
if(!dctcp)
{
cout<<"TCPNEWRENO"<<endl;
}
else
{
cout<<"DCTCP"<<endl;
}
cout<<"Load "<<load<<endl;
Time::SetResolution (Time::NS);
LogComponentEnable ("DataCenterSimulator", LOG_ALL);
NS_LOG_INFO ("DataCenter Simulation");
Configure_Simulator();
Build_Topology();
Setup_Servers();
NS_LOG_INFO ("Setting Up Workload");
Setup_Workload();
NS_LOG_INFO ("Starting Simulation");
//Simulator::Schedule (Seconds(0.1), &QueueStat);
if(LinkUtilization)
{
oss << "Util." <<StatsFileName ;
AsciiTraceHelper asciiTraceHelper;
Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream (oss.str ());
Simulator::Schedule(Seconds(interval),&MeasureLinkUtilization,stream);
Simulator::Schedule(Seconds(interval),&ProbeApps,0);
}
Simulator::Run();
Simulator::Destroy ();
NS_LOG_INFO ("Simulation Finished");
return 0;
}