-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrun.cc
1389 lines (1224 loc) · 56.1 KB
/
mrun.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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* 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
*/
#include <type_traits>
#include "ns3/mrun.h"
using namespace std;
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("RunningModule");
typedef multimap<uint32_t, uint32_t>::iterator mmap_iter;
double controlInterval = 0.02;
double rateUpInterval = 0.002;
// for debug
fstream tokenOut;
void FirstBucketTrace (uint32_t oldV, uint32_t newV)
{
double time = Simulator::Now().GetSeconds();
tokenOut << time << " " << newV << endl;
cout << time << ": first bucket " << newV << endl;
}
void SecondBucketTrace (uint32_t oldV, uint32_t newV)
{
double time = Simulator::Now().GetSeconds();
tokenOut << time << " " << newV << endl;
}
/* ------------- Begin: implementation of CapabilityHelper ------------- */
CapabilityHelper::CapabilityHelper(uint32_t flow_id, Ptr<Node> node, Ptr<NetDevice> device, Address addr)
{
install(flow_id, node, device, addr);
}
vector<int> CapabilityHelper::GetNumFromTag(Ptr<const Packet> p)
{
Ptr<const Packet> pcp = p->Copy();
MyTag tag;
if (!pcp->PeekPacketTag(tag)) return {-1, -1};
MyApp temp;
uint32_t tagScale = temp.tagScale;
int index = tag.GetSimpleValue() / tagScale - 1; // tag should include cnt, even not in debug mode
int cnt = tag.GetSimpleValue() % tagScale;
return {index, cnt};
}
void CapabilityHelper::SendAck(Ptr<const Packet> p)
{
vector<int> vec = GetNumFromTag(p);
if(vec[1] < 0)
{
// cout << " - CapabilityHelper:: ACK not sent! " << vec[0] << ". " << vec[1] << endl;
return;
}
uint32_t ackNo = vec[1];
curAckNo = ackNo;
ackApp->SendAck(ackNo);
// cout << " - CapabilityHelper:: ACK " << ackNo << " of flow " << flow_id << " sent!" << endl;
}
void CapabilityHelper::install(uint32_t flow_id, Ptr<Node> node, Ptr<NetDevice> device, Address addr)
{
this->flow_id = flow_id;
curAckNo = 9999;
Ptr<PointToPointNetDevice> p2pDev = DynamicCast<PointToPointNetDevice> (device);
this->device = p2pDev;
// set socket
TypeId tpid = UdpSocketFactory::GetTypeId(); // currently only for UDP
Ptr<Socket> skt = Socket::CreateSocket(node, tpid);
// set application
ackApp = CreateObject<MyApp> ();
ackApp->isTrackPkt = true; // seems doesn't matter
ackApp->SetTagValue(flow_id + 1); // begin from 1
ackApp->Setup(skt, addr, 15, DataRate('1Mbps')); // pkt size and rate aren't necessary
// node->AddApplication(ackApp);
ackApp->StartAck();
cout << " - CapabilityHelper is installed on RX node " << flow_id << ": tag scale = " << ackApp->tagScale << endl;
}
uint32_t CapabilityHelper::getFlowId()
{
return flow_id;
}
vector<uint32_t> CapabilityHelper::getCurAck()
{
return {flow_id, curAckNo};
}
/* ------------- Begin: implementation of RunningModule ------------- */
uint32_t RunningModule::SetNode(uint32_t i, uint32_t id)
{
Group g = groups.at(i);
nodes.Create(1);
id2nodeIndex[id] = nodes.GetN() - 1;
return nodes.GetN() - 1;
}
uint32_t RunningModule::SetRouter(Ptr<Node> pt, uint32_t i, uint32_t id)
{
Group g = groups[i];
nodes.Add(pt);
id2nodeIndex[id] = nodes.GetN() - 1;
return nodes.GetN() - 1;
}
uint32_t RunningModule::SetNode(uint32_t type, uint32_t i, uint32_t n)
{
Group g = groups.at(i);
uint32_t id;
switch(type)
{
case 0:
id = g.txId[n];
break;
case 1:
id = g.rxId[n];
break;
case 2:
id = g.routerId[n];
break;
default: ;
}
return SetNode(i, id);
}
Ptr<Node> RunningModule::GetNode(uint32_t i, uint32_t id)
{
// use the mapping from node id to index in NodeContainer
if(id2nodeIndex.find(id) == id2nodeIndex.end())
return 0;
return nodes.Get(id2nodeIndex[id]);
}
Ipv4Address RunningModule::GetIpv4Addr(uint32_t i, uint32_t id, uint32_t k)
{
pair<uint32_t, uint32_t> pr = make_pair(id, k);
if(id2ipv4Index.find(pr) == id2ipv4Index.end())
return 0;
return ifc.GetAddress(id2ipv4Index[pr]);
}
uint32_t RunningModule::GetId()
{ return ID; }
RunningModule::RunningModule(vector<double> t, vector<Group> grp, ProtocolType pt, vector<string> bnBw, vector<string> bnDelay, vector<string> delay, vector<bool> fls, uint32_t size)
{
// constant setting
ID = rand() % 10000;
nSender = 0;
nReceiver = 0;
groups = grp;
for(Group g:groups)
{
nSender += g.txId.size();
nReceiver += g.rxId.size();
}
pktSize = size;
rtStart = t.at(0);
rtStop = t.at(1);
for(uint32_t i = 0; i < nSender; i ++)
{
txStart.push_back(t.at(i + 2));
txEnd.push_back(t.at(i + nSender + 2));
}
protocol = pt;
bottleneckBw = bnBw;
bottleneckDelay = bnDelay;
this->delay = delay;
isTrackPkt = fls.at(0);
bypassMacRx = fls.at(1);
// routers.Create(3); // left, right, mbox (link order: mbox-> left-> right)
}
RunningModule::~RunningModule(){}
void RunningModule::buildTopology(vector<Group> grp)
{
PointToPointHelper leaf, cross;
leaf.SetDeviceAttribute("DataRate", StringValue(normalBw));
leaf.SetChannelAttribute("Delay", StringValue(delay[0]));
cross.SetDeviceAttribute("DataRate", StringValue(normalBw));
cross.SetChannelAttribute("Delay", StringValue(delay[1]));
NodeContainer rt_ptr;
NodeContainer leaf_ptr;
stringstream ss;
for(uint32_t i = 0; i < grp.size(); i ++)
{
Group g = grp[i];
bottleneck.SetDeviceAttribute("DataRate", StringValue(bottleneckBw[i]));
bottleneck.SetChannelAttribute("Delay", StringValue(bottleneckDelay[i]));
bottleneck.SetDeviceAttribute("Mtu", StringValue(mtu));
InternetStackHelper stack;
// add mbox node
vector<uint32_t> rt_id(3); // mbox --> tx router --> rx router
for(auto j:{0, 1, 2}) // unique for mbox (UFM)
{
rt_id[j] = SetNode(2, i, j);
if(!i) rt_ptr.Add(nodes.Get(rt_id[j]));
}
Ptr<Node> mb_router = nodes.Get(rt_id[0]);
Ptr<Node> tx_router = nodes.Get(rt_id[1]);
Ptr<Node> rx_router = nodes.Get(rt_id[2]);
routerDevice.Add( leaf.Install(mb_router, tx_router) ); // UFM
routerDevice.Add( bottleneck.Install(tx_router, rx_router) );
for(uint32_t j = 0; j < g.txId.size(); j ++) // left leaf nodes --> mbox
{
uint32_t idx = SetNode(0, i, j);
NetDeviceContainer ndc1;
if(j < g.N_ctrl) ndc1 = leaf.Install(nodes.Get(idx), mb_router);
else ndc1 = cross.Install(nodes.Get(idx), mb_router);
txDevice.Add(ndc1.Get(0));
txRouterDevice.Add(ndc1.Get(1));
if(!i && !j) leaf_ptr.Add(nodes.Get(idx));
}
for(uint32_t j = 0; j < g.rxId.size(); j ++) // rx router --> right leaf nodes
{
uint32_t idx = SetNode(1, i, j);
NetDeviceContainer ndc2;
if(j < g.N_ctrl) ndc2 = leaf.Install(rx_router, nodes.Get(idx));
else ndc2 = cross.Install(rx_router, nodes.Get(idx));
rxRouterDevice.Add(ndc2.Get(0));
rxDevice.Add(ndc2.Get(1));
if(!i && !j) leaf_ptr.Add(nodes.Get(idx));
}
stack.Install(nodes);
}
/*
// tested: no mbox at first, only tx and rx router
vector<uint32_t> rt_id(2);
for(auto j:{0, 1})
{
rt_id[j] = SetNode(2, i, j);
if(!i) rt_ptr.Add(nodes.Get(rt_id[j])); // test
}
Ptr<Node> tx_router = nodes.Get(rt_id[0]);
Ptr<Node> rx_router = nodes.Get(rt_id[1]);
routerDevice.Add( bottleneck.Install(tx_router, rx_router) );
for(uint32_t j = 0; j < g.txId.size(); j ++) // left leaf nodes --> tx router
{
uint32_t idx = SetNode(0, i, j);
NetDeviceContainer ndc1 = leaf.Install(nodes.Get(idx), tx_router);
txDevice.Add(ndc1.Get(0));
txRouterDevice.Add(ndc1.Get(1));
if(!i && !j) leaf_ptr.Add(nodes.Get(idx)); // test
}
for(uint32_t j = 0; j < g.rxId.size(); j ++) // rx router --> right leaf nodes
{
uint32_t idx = SetNode(1, i, j);
NetDeviceContainer ndc2 = leaf.Install(rx_router, nodes.Get(idx));
rxRouterDevice.Add(ndc2.Get(0));
rxDevice.Add(ndc2.Get(1));
if(!i && !j) leaf_ptr.Add(nodes.Get(idx)); // test
}
stack.Install(nodes); // install the stack at last
}
*/
// verify the node id and state
NodeContainer TmpNode;
TmpNode.Add( GetNode(0, grp[0].txId[0]) );
TmpNode.Add( GetNode(0, grp[0].routerId[0]) ); // mbox router
TmpNode.Add( GetNode(0, grp[0].routerId[1]) ); // tx router
TmpNode.Add( GetNode(0, grp[0].routerId[2]) ); // rx router
TmpNode.Add( GetNode(0, grp[0].rxId[0]) );
NS_ASSERT_MSG(TmpNode.Get(0) == leaf_ptr.Get(0), "Ptr<Node> for TX leaf (0,0) is incorrect!");
NS_ASSERT_MSG(TmpNode.Get(1) == rt_ptr.Get(0), "Ptr<Node> for mbox router is incorrect!");
NS_ASSERT_MSG(TmpNode.Get(2) == rt_ptr.Get(1), "Ptr<Node> for TX router is incorrect!");
NS_ASSERT_MSG(TmpNode.Get(3) == rt_ptr.Get(2), "Ptr<Node> for RX router is incorrect!");
NS_ASSERT_MSG(TmpNode.Get(4) == leaf_ptr.Get(1), "Ptr<Node> for RX leaf (0,0) is incorrect!");
NS_LOG_INFO("Ptr<Node> check passed.");
// debug: address verification
ss << "Node verification: # dev MAC addresses MTU" << endl;
for(auto i: {0,1,2,3,4})
{
ss << " " << TmpNode.Get(i)->GetNDevices() << " ";
for(uint32_t j = 0; j < TmpNode.Get(i)->GetNDevices(); j ++)
ss << TmpNode.Get(i)->GetDevice(j)->GetAddress() << " " << TmpNode.Get(i)->GetDevice(j)->GetMtu() << endl << " ";
ss << endl;
}
NS_LOG_INFO(ss.str());
}
void RunningModule::configure(double stopTime, ProtocolType pt, vector<string> bw, vector<string> delay, vector<MiddlePoliceBox>& mboxes, vector<double> Th)
{
NS_LOG_FUNCTION("Begin.");
NS_LOG_INFO("Starting running module ... ");
protocol = pt;
bottleneckBw = bw;
bottleneckDelay = delay;
qc = setQueue(groups, bottleneckBw, bottleneckDelay, Th);
ifc = setAddress();
sinkApp = setSink(groups, protocol);
if(pt == UDP)
{
setCapabilityHelper(groups);
for(uint32_t i = 0; i < chelpers.size(); i ++) // for debug only
{
cout << " -- After installation: flow " << chelpers[i].getFlowId() << " has ptr " << &chelpers.at(i) << endl;
}
}
senderApp = setSender(groups, protocol);
this->mboxes = mboxes;
connectMboxCtrl(groups, controlInterval, 0.2, rateUpInterval);
// connectMbox(groups, controlInterval, 0.2, rateUpInterval); // not work either
// connectMbox(groups, controlInterval, 1, rateUpInterval);
start();
}
QueueDiscContainer RunningModule::setQueue(vector<Group> grp, vector<string> bnBw, vector<string> bnDelay, vector<double> Th)
{
NS_LOG_FUNCTION("Begin.");
// set RED queue and TBFQ
// string token_rate = "50Mbps";
// string peak_rate = "50Mbps";
string token_rate = "10Gbps";
string peak_rate = "10Gbps";
QueueDiscContainer qc;
for(uint32_t i = 0; i < grp.size(); i ++)
{
TrafficControlHelper fq_tch;
fq_tch.SetRootQueueDisc ("ns3::FqTbfQueueDisc",
"MaxSize", QueueSizeValue (QueueSize ("1000p")),
"Burst", UintegerValue (100000),
"Rate", StringValue (token_rate),
"PeakRate", StringValue (peak_rate));
// fq_tch.SetRootQueueDisc("ns3::RedQueueDisc",
// "MinTh", DoubleValue(5),
// "MaxTh", DoubleValue(15),
// "LinkBandwidth", StringValue(token_rate),
// "LinkDelay", StringValue("1ms"));
TrafficControlHelper red_tch;
if(Th.empty()) red_tch.SetRootQueueDisc("ns3::RedQueueDisc",
"MinTh", DoubleValue(5),
"MaxTh", DoubleValue(15),
"LinkBandwidth", StringValue(bnBw.at(i)),
"LinkDelay", StringValue(bnDelay.at(i)));
else red_tch.SetRootQueueDisc("ns3::RedQueueDisc",
"MinTh", DoubleValue(Th.at(0)),
"MaxTh", DoubleValue(Th.at(1)),
"LinkBandwidth", StringValue(bnBw.at(i)),
"LinkDelay", StringValue(bnDelay.at(i)));
// qc.Add(tch.Install(GetNode(i, grp.at(i).routerId[0])->GetDevice(0)));
// Ptr<NetDevice> mbRouter = GetNode(i, grp[i].routerId[0])->GetDevice(0);
// Ptr<NetDevice> txRouter = GetNode(i, grp[i].routerId[1])->GetDevice(0); // should word, but complicated
Ptr<NetDevice> mbRouter = routerDevice.Get(0);
Ptr<NetDevice> txRouter = routerDevice.Get(2);
qc.Add(fq_tch.Install(mbRouter));
qc.Add(red_tch.Install(txRouter));
cout << "type id of queue: " << qc.Get(0)->GetInstanceTypeId() << ", " <<
qc.Get(1)->GetInstanceTypeId() << endl;
}
return qc;
}
Ipv4InterfaceContainer RunningModule::setAddress()
{
// assign Ipv4 addresses: carefully record the index before, because we cannot push back one by one
Ipv4AddressHelper ih("10.1.0.0", "255.255.255.0");
NetDeviceContainer ndc;
Ipv4InterfaceContainer ifc;
uint32_t index = 0;
map<uint32_t, string> type2name; // for debug
type2name[1] = "TX";
type2name[2] = "RX";
type2name[3] = "Router";
stringstream ss;
vector<uint32_t> pt = {0, 0, 0, 0, 0}; // router, tx, tx-rt, rx, rx-rt,
for(uint32_t i = 0; i < groups.size(); i ++)
{
Group g = groups[i];
// mbox router and tx router
NetDeviceContainer ndc0;
ndc0.Add(routerDevice.Get(pt[0] ++));
ndc0.Add(routerDevice.Get(pt[0] ++));
ifc.Add( ih.Assign(ndc0) );
id2ipv4Index[make_pair(g.routerId[0], 0)] = index ++; // mbox MacTx
id2ipv4Index[make_pair(g.routerId[1], 0)] = index ++; // tx router MacRx
ih.SetBase ("11.1.0.0", "255.255.255.0");
// tx router and rx router
NetDeviceContainer ndc1;
ndc1.Add(routerDevice.Get(pt[0] ++));
ndc1.Add(routerDevice.Get(pt[0] ++));
ifc.Add( ih.Assign(ndc1) );
id2ipv4Index[make_pair(g.routerId[1], 1)] = index ++; // tx router MacTx (late created)
id2ipv4Index[make_pair(g.routerId[2], 0)] = index ++; // rx router MacRx
ih.SetBase ("12.1.0.0", "255.255.255.0");
for(uint32_t j = 0; j < g.txId.size(); j ++)
{
// mbox and left router address
NetDeviceContainer ndc2;
ndc2.Add(txDevice.Get(pt[1] ++));
ndc2.Add(txRouterDevice.Get(pt[2] ++));
ifc.Add( ih.Assign(ndc2) );
id2ipv4Index[make_pair(g.txId[j], 0)] = index ++;
id2ipv4Index[make_pair(g.routerId[0], j + 1)] = index ++; // note: mbox is leftmost
ih.NewNetwork();
}
ih.SetBase ("13.1.0.0", "255.255.255.0");
for(uint32_t j = 0; j < g.rxId.size(); j ++)
{
// rx and right router address
NetDeviceContainer ndc3;
ndc3.Add(rxRouterDevice.Get(pt[4] ++));
ndc3.Add(rxDevice.Get(pt[3] ++));
ifc.Add( ih.Assign(ndc3) );
id2ipv4Index[make_pair(g.routerId[2], j + 1)] = index ++;
id2ipv4Index[make_pair(g.rxId[j], 0)] = index ++;
ih.NewNetwork();
}
}
// IP verification
for(uint32_t i = 0; i < groups.size(); i ++)
for(auto t:{1,2,3})
{
vector<uint32_t> ids = t == 1? groups[i].txId:
t == 2? groups[i].rxId: groups[i].routerId;
ss << type2name[t] << ": " << endl;
for(uint32_t j = 0; j < ids.size(); j ++)
{
for(uint32_t k = 0; k < GetNode(i, ids[j])->GetNDevices() - 1; k ++)
{
ss << " ";
ifc.GetAddress( id2ipv4Index[make_pair(ids[j], k)] ).Print(ss);
ss << endl;
}
ss << " --------------- " << endl;
}
}
/* // original address assignment
for(uint32_t i = 0; i < groups.size(); i ++)
for(auto t:{1, 2, 3})
{
vector<uint32_t> ids = t == 1? groups[i].txId:
t == 2? groups[i].rxId: groups[i].routerId;
for(uint32_t j = 0; j < ids.size(); j ++)
{
Ptr<Node> node = GetNode(i, ids[j]);
for(uint32_t k = 0; k < node->GetNDevices() - 1; k ++) // how about discarding loop back device
ndc.Add( node->GetDevice(k) );
}
}
// assign Ipv4 addresses and set the index map
ifc.Add(ih.Assign(ndc));
for(uint32_t i = 0; i < groups.size(); i ++)
for(auto t:{1,2,3})
{
vector<uint32_t> ids = t == 1? groups[i].txId:
t == 2? groups[i].rxId: groups[i].routerId;
ss << type2name[t] << ": " << endl;
for(uint32_t j = 0; j < ids.size(); j ++)
for(uint32_t k = 0; k < GetNode(i, ids[j])->GetNDevices() - 1; k ++)
{
id2ipv4Index[make_pair(ids[j], k)] = index;
ss << " "; // for debug
ifc.GetAddress(index).Print(ss);
ss << endl;
index ++;
}
}
*/
NS_LOG_INFO(ss.str());
return ifc;
}
ApplicationContainer RunningModule::setSink(vector<Group> grp, ProtocolType pt)
{
NS_LOG_FUNCTION("Begin.");
// string ptStr = pt == TCP? "ns3::TcpSocketFactory":"ns3::UdpSocketFactory";
for(uint32_t i = 0; i < grp.size(); i ++)
{
Group g = grp.at(i);
for(uint32_t j = 0; j < g.txId.size(); j ++)
{
uint32_t tid = g.txId.at(j);
string ptStr = g.tx2prot[tid] == TCP? "ns3::TcpSocketFactory":"ns3::UdpSocketFactory";
uint32_t port = g.rate2port[ g.tx2rate[tid] ];
Address sinkLocalAddr (InetSocketAddress(Ipv4Address::GetAny(), port));
PacketSinkHelper psk(ptStr, sinkLocalAddr);
// find RX corresponding to the txId: equal_range, need testing
pair<mmap_iter, mmap_iter> res = g.tx2rx.equal_range(tid);
stringstream ss;
ss << "TX ID: " << tid << "; RX ID: ";
for(mmap_iter it = res.first; it != res.second; it ++)
{
Ptr<Node> pn = GetNode(i, it->second);
sinkApp.Add(psk.Install(pn)); // it->second: rx ids
ss << it->second << " . Addr: " << pn->GetDevice(0)->GetAddress();
}
NS_LOG_INFO(ss.str());
}
}
return sinkApp;
}
vector< CapabilityHelper > RunningModule::setCapabilityHelper(vector<Group> grp)
{
NS_LOG_FUNCTION("Begin.");
int idx = 0;
stringstream ss;
for (uint32_t i = 0; i < grp.size(); i ++)
{
Group g = grp.at(i);
uint32_t n = g.rxId.size();
for (uint32_t j = 0; j < g.txId.size(); j ++)
{
uint32_t tId = g.txId[j];
// uint32_t rx_id = g.tx2rx.equal_range(tId);
uint32_t rx_id = g.rxId[j]; // short cut, not flexible for the case that TX are not equal to RX!!!
uint32_t ri = find(g.rxId.begin(), g.rxId.end(), rx_id) - g.rxId.begin();
string rate = g.tx2rate.at(tId);
uint32_t port = g.rate2port.at(rate);
Ipv4Address addr = GetIpv4Addr(i, tId);
Address sourceAddr(InetSocketAddress(addr, port));
Ptr<Node> rx_node = GetNode(i, rx_id);
Ptr<NetDevice> rx_device = rx_node->GetDevice(0);
if (g.tx2prot[tId] == UDP) // flow oriented
{
CapabilityHelper tmp;
chelpers.push_back(tmp);
chelpers.at(idx ++).install(ri, rx_node, rx_device, sourceAddr);
}
// by the way, set ipv4 -> protocol mapping
ip2prot[addr] = g.tx2prot[tId];
}
}
NS_LOG_INFO(ss.str());
// set tracing in another part to avoid coupling
idx = 0;
for (uint32_t i = 0; i < grp.size(); i ++)
{
Group g = grp.at(i);
for (uint32_t j = 0; j < g.txId.size(); j ++)
{
if (g.tx2prot[g.txId[j]] != UDP) continue;
uint32_t rId = g.rxId[j];
uint32_t ri = j;
Ptr<Node> rx_node = GetNode(i, rId);
Ptr<NetDevice> rx_device = rx_node->GetDevice(0);
rx_device->TraceConnectWithoutContext("MacRx", MakeCallback(&CapabilityHelper::SendAck, &chelpers.at(idx)));
cout << " - f " << j << " 's addr in set chelper: " << &chelpers.at(idx) << endl;
idx ++;
}
}
return chelpers;
}
vector< Ptr<MyApp> > RunningModule::setSender(vector<Group> grp, ProtocolType pt)
{
NS_LOG_FUNCTION("Begin.");
vector<Ptr<MyApp>> appc;
stringstream ss;
for(uint32_t i = 0; i < grp.size(); i ++)
{
ss << "Set sender " << i << " ... " << endl;
Group g = grp.at(i);
for(auto tId:g.txId)
{
pair<mmap_iter, mmap_iter> res = g.tx2rx.equal_range(tId);
for(mmap_iter it = res.first; it != res.second; it ++)
{
vector<uint32_t>::iterator it2 = find(g.txId.begin(), g.txId.end(), tId);
// uint32_t tag = i*u + (uint32_t)(it2 - g.txId.begin()) + 1; // tag: index in sender
uint32_t tag = (uint32_t)(it2 - g.txId.begin()) + 1;
cout << "RX id: " << it->second << "; Tag : " << tag << "; " << tId << " -> " << it->second << endl;
appc.push_back(netFlow(i, tId, it->second, tag));
}
}
}
NS_LOG_INFO(ss.str());
return appc;
}
Ptr<MyApp> RunningModule::netFlow(uint32_t i, uint32_t tId, uint32_t rId, uint32_t tag)
{
// parse rate and port
Group g = groups.at(i);
string rate = g.tx2rate.at(tId);
TypeId tpid = g.tx2prot[tId] == TCP? TcpSocketFactory::GetTypeId():UdpSocketFactory::GetTypeId();
uint32_t port = g.rate2port.at(rate);
uint32_t ri = find(g.rxId.begin(), g.rxId.end(), rId) - g.rxId.begin();
uint32_t ti = find(g.txId.begin(), g.txId.end(), tId) - g.txId.begin();
// set socket
Ptr<Socket> skt = Socket::CreateSocket(GetNode(i, tId), tpid);
if(g.tx2prot[tId] == TCP) skt->SetAttribute ("Sack", BooleanValue (false));
Address sinkAddr(InetSocketAddress(GetIpv4Addr(i, rId), port));
Ptr<MyApp> app = CreateObject<MyApp> ();
app->isTrackPkt = isTrackPkt;
app->SetTagValue(tag);
app->Setup(skt, sinkAddr, pktSize, DataRate(rate));
GetNode(i, tId)->AddApplication(app);
// logging
stringstream ss;
ss << "Group " << i << ": " << tId << "->" << rId << " ; port: " << port << endl;
ss << GetNode(i, tId)->GetDevice(0)->GetAddress() << " -> " << GetNode(i, rId)->GetDevice(0)->GetAddress() << "; RX IP: ";
GetIpv4Addr(i, rId).Print(ss);
ss << " ; # dev: " << GetNode(i, tId)->GetNDevices();
NS_LOG_INFO(ss.str());
return app;
}
void RunningModule::connectMbox(vector<Group> grp, double interval, double logInterval, double ruInterval)
{
NS_LOG_FUNCTION("Connect Mbox ... ");
for(uint32_t i = 0; i < grp.size(); i ++)
{
// MiddlePoliceBox& mb = mboxes.at(i); // not sure
Ptr<NetDevice> txRouter = GetNode(i, grp[i].routerId[0])->GetDevice(0); // 3 router scenario: txRouter is the 1st one
Ptr<NetDevice> rxRouter = GetNode(i, grp[i].routerId[2])->GetDevice(0);
Ptr<Node> txNode = GetNode(i, grp[i].routerId[0]);
Ptr<Node> rxNode = GetNode(i, grp[i].routerId[2]);
NetDeviceContainer nc;
for(uint32_t j = 1; j <= grp[i].txId.size(); j ++)
nc.Add(txNode->GetDevice(j)); // add rx side devices, this line will add the loop back
// install mbox
if(bypassMacRx) mboxes.at(i).install(txRouter); // install only the router net dev for bottleneck link
else mboxes.at(i).install(nc); // install probes for all tx router's mac rx side
NS_LOG_FUNCTION("Mbox installed on router " + to_string(i));
// given flow type infomation
mboxes.at(i).ip2prot = ip2prot;
// set weight, rtt, rto & start mbox
vector<double> rtts;
for(uint32_t j = 0; j < grp.at(i).txId.size(); j ++)
{
double bnDelay = (bottleneckDelay.at(i).c_str()[0] - '0') / 1000.0;
double dely = (delay[0].c_str()[0] - '0') / 1000.0;
double nRouter = 3;
NS_LOG_INFO("rtt[" + to_string(j) + "]: " + to_string(2 *(bnDelay + nRouter * dely))); // router is 3 now
rtts.push_back(2 * (bnDelay + 2 * dely) );
}
mboxes.at(i).SetWeight(grp.at(i).weight);
mboxes.at(i).SetRttRto(rtts);
mboxes.at(i).start();
// tracing
stringstream ss1;
if(bypassMacRx) // by pass the wierd bug of rwnd update: function of MacTx moved to onMacRx
txRouter->TraceConnectWithoutContext("MacTx", MakeCallback(&MiddlePoliceBox::onMacRx, &mboxes.at(i)));
else
{
// for(uint32_t j = 0; j < groups.at(i).txId.size(); j ++) // I think index error is the main cause of mac rx error!!!!
for(uint32_t j = 1; j <= grp[i].txId.size(); j ++)
// for(uint32_t j = 1; j < txNode->GetNDevices(); j ++)
{
bottleneck.EnablePcapAll("router");
bool res = txNode->GetDevice(j)->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMacRx, &mboxes.at(i)));
ss1 << " - onMacRx install: " << res << "; addr: " << txNode->GetDevice(j)->GetAddress() << endl;
}
txRouter->TraceConnectWithoutContext("MacTx", MakeCallback(&MiddlePoliceBox::onMacTx, &mboxes.at(i))); // necessary for TCP loss detection
}
rxRouter->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onPktRx, &mboxes.at(i)));
qc.Get(2 * i)->TraceConnectWithoutContext("Drop", MakeCallback(&MiddlePoliceBox::onQueueDrop, &mboxes.at(i)));
txRouter->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMboxAck, &mboxes.at(i))); // test passeds
// debug packet path
for (uint32_t j = 1; j <= grp[i].rxId.size(); j ++)
{
bool rxRes = rxNode->GetDevice(j)->TraceConnectWithoutContext("MacTx", MakeCallback(&MiddlePoliceBox::onRouterTx, &mboxes.at(i)));
ss1 << " - trace on rx router TX: " << rxRes << endl;
}
NS_LOG_DEBUG(ss1.str());
// debug queue size
qc.Get(2 * i)->TraceConnectWithoutContext("PacketsInQueue", MakeCallback(&MiddlePoliceBox::TcPktInQ, &mboxes.at(i)));
qc.Get(2 * i + 1)->TraceConnectWithoutContext("PacketsInQueue", MakeCallback(&MiddlePoliceBox::TcPktInRed, &mboxes.at(i)));
Ptr<FqTbfQueueDisc> fqp = DynamicCast<FqTbfQueueDisc> (qc.Get(2 * i)); // trial of the interval TBF queue tracing
Config::ConnectWithoutContext ("/NodeList/*/$ns3::TrafficControlLayer/RootQueueDiscList/*/InternalQueueList/0/TokensInFirstBucket", MakeCallback (&FirstBucketTrace));
// qc.Get(2 * i)->TraceConnectWithoutContext("TokensInFirstBucket", MakeCallback (&FirstBucketTrace));
// qc.Get(2 * i)->TraceConnectWithoutContext("TokensInSecondBucket", MakeCallback (&SecondBucketTrace));
Ptr<Queue<Packet>> qp = DynamicCast<PointToPointNetDevice> (txRouter) -> GetQueue();
qp->TraceConnectWithoutContext("PacketsInQueue", MakeCallback(&MiddlePoliceBox::DevPktInQ, &mboxes.at(i)));
// trace TCP congestion window and RTT: tested
for(uint32_t j = 0; j < groups.at(i).txId.size(); j ++)
{
string context1 = "/NodeList/0/$ns3::TcpL4Protocol/SocketList/" + to_string(j) + "/CongestionWindow";
string context2 = "/NodeList/0/$ns3::TcpL4Protocol/SocketList/" + to_string(j) + "/RTT";
Ptr<Socket> skt = senderApp.at(i * groups[0].N + j)->GetSocket(); // maybe limited for different groups
skt->TraceConnect("CongestionWindow", context1, MakeCallback(&MiddlePoliceBox::onCwndChange, &mboxes.at(i)));
skt->TraceConnect("RTT", context2, MakeCallback(&MiddlePoliceBox::onRttChange, &mboxes.at(i)));
}
// test the rx side device index
Ptr<Node> rtNode = GetNode(i, grp[i].routerId[2]);
cout << " rx0: # dev: " << rtNode->GetNDevices() << "; # rx: " << grp.at(i).rxId.size() << endl;
for(uint32_t k = 0; k < rtNode->GetNDevices() - 2; k ++)
{
cout << " -- rx[" << k << "] addr: " << rtNode->GetDevice(k + 1)->GetAddress() << endl;
cout << " -- rx end[" << k << "] addr: " << GetNode(i, grp.at(i).rxId[k])->GetDevice(0)->GetAddress() << endl;
}
// for debug chain 1
for(uint32_t k = 0; k < grp.at(i).txId.size(); k ++)
{
Ptr<NetDevice> senderDev = GetNode(i, grp[i].txId[k])->GetDevice(0);
bool b1 = senderDev->TraceConnectWithoutContext("MacTx", MakeCallback(&MiddlePoliceBox::onSenderTx, &mboxes.at(i)));
// bool b2 = senderDev->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onAckRx, &mboxes.at(i)));
NS_LOG_DEBUG(" -- Sender debug: MacTx: " << b1 << endl);
}
// flow control
Ptr<QueueDisc> tbfq = qc.Get(2 * i);
mboxes.at(i).flowControl(mboxes.at(i).GetFairness(), interval, logInterval, ruInterval, tbfq);
}
}
void RunningModule::disconnectMbox(vector<Group> grp)
{
NS_LOG_INFO("Disconnect Mbox ... ");
for(uint32_t i = 0; i < grp.size(); i ++)
{
Ptr<NetDevice> txRouter = GetNode(i, grp[i].routerId[0])->GetDevice(0);
Ptr<NetDevice> rxRouter = GetNode(i, grp[i].routerId[1])->GetDevice(0);
Ptr<Node> txNode = GetNode(i, grp[i].routerId[0]);
// stop the mbox and tracing
mboxes.at(i).stop(); // stop flow control and logging
for(uint32_t j = 1; j <= grp[i].txId.size(); j ++)
txNode->GetDevice(j)->TraceDisconnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMacRx, &mboxes.at(i)));
if(!rxRouter->TraceDisconnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onPktRx, &mboxes[i])))
NS_LOG_INFO("Failed to disconnect onPktRx!");
// if(!qc.Get(i)->TraceDisconnectWithoutContext("Drop", MakeCallback(&MiddlePoliceBox::onQueueDrop, &mboxes.at(i))))
// NS_LOG_INFO("Failed to disconnect onQueueDrop!");
NS_LOG_FUNCTION("Mbox " + to_string(i) + " stops.");
}
}
void RunningModule::pauseMbox(vector<Group> grp)
{
NS_LOG_INFO("Pause Mbox: stop early drop ... ");
for(uint32_t i = 0; i < grp.size(); i ++)
{
Ptr<Node> txNode = GetNode(i, grp[i].routerId[0]);
Ptr<NetDevice> txRouter = txNode->GetDevice(0);
txRouter->TraceDisconnectWithoutContext("MacTx", MakeCallback(&MiddlePoliceBox::onMacRx, &mboxes.at(i)));
txRouter->TraceConnectWithoutContext("MacTx", MakeCallback(&MiddlePoliceBox::onMacRxWoDrop, &mboxes.at(i)));
// for(uint32_t j = 0; j < txNode->GetNDevices(); j ++)
// {
// txNode->GetDevice(j)->TraceDisconnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMacRx, &mboxes.at(i)));
// txNode->GetDevice(j)->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMacRxWoDrop, &mboxes.at(i)));
// }
}
}
void RunningModule::resumeMbox(vector<Group> grp)
{
NS_LOG_INFO("Resume Mbox: restart early drop ... ");
for(uint32_t i = 0; i < grp.size(); i ++)
{
Ptr<Node> txNode = GetNode(i, grp[i].routerId[0]);
// txRouter->TraceDisconnectWithoutContext("MacTx", MakeCallback(&MiddlePoliceBox::onMacTx, &mb));
// txRouter->TraceConnectWithoutContext("MacTx", MakeCallback(&MiddlePoliceBox::onMacRxWoDrop, &mb));
for(uint32_t j = 1; j <= grp[i].txId.size(); j ++)
{
txNode->GetDevice(j)->TraceDisconnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMacRxWoDrop, &mboxes.at(i)));
txNode->GetDevice(j)->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMacRx, &mboxes.at(i)));
}
}
}
void RunningModule::connectMboxCtrl(vector<Group> grp, double interval, double logInterval, double ruInterval)
{
NS_LOG_FUNCTION("Connect Mbox ... ");
for(uint32_t i = 0; i < grp.size(); i ++)
{
uint32_t nTrace = grp[i].N_ctrl;
Ptr<NetDevice> txRouter = GetNode(i, grp[i].routerId[0])->GetDevice(0); // 3 router scenario: txRouter is the 1st one
Ptr<NetDevice> rxRouter = GetNode(i, grp[i].routerId[2])->GetDevice(0);
Ptr<Node> txNode = GetNode(i, grp[i].routerId[0]);
Ptr<Node> rxNode = GetNode(i, grp[i].routerId[2]);
NetDeviceContainer nc;
for(uint32_t j = 1; j <= nTrace; j ++)
nc.Add(txNode->GetDevice(j)); // add rx side devices, this line will add the loop back
mboxes[i].install(nc);
NS_LOG_FUNCTION("Mbox installed on router " + to_string(i));
// given flow type infomation
mboxes.at(i).ip2prot = ip2prot;
// set weight, rtt, rto & start mbox
vector<double> rtts;
for(uint32_t j = 0; j < nTrace; j ++)
{
double bnDelay = (bottleneckDelay.at(i).c_str()[0] - '0') / 1000.0;
double dely = (delay[0].c_str()[0] - '0') / 1000.0;
double nRouter = 3;
NS_LOG_INFO("rtt[" + to_string(j) + "]: " + to_string(2 *(bnDelay + nRouter * dely))); // router is 3 now
rtts.push_back(2 * (bnDelay + 2 * dely) );
}
mboxes.at(i).SetWeight(grp.at(i).weight);
mboxes.at(i).SetRttRto(rtts);
mboxes.at(i).start();
// tracing
stringstream ss1;
for(uint32_t j = 1; j <= nTrace; j ++)
// for(uint32_t j = 1; j < txNode->GetNDevices(); j ++)
{
bottleneck.EnablePcapAll("router");
bool res = txNode->GetDevice(j)->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMacRx, &mboxes.at(i)));
ss1 << " - onMacRx install: " << res << "; addr: " << txNode->GetDevice(j)->GetAddress() << endl;
}
txRouter->TraceConnectWithoutContext("MacTx", MakeCallback(&MiddlePoliceBox::onMacTx, &mboxes.at(i))); // necessary for TCP loss detection
rxRouter->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onPktRx, &mboxes.at(i)));
qc.Get(2 * i)->TraceConnectWithoutContext("Drop", MakeCallback(&MiddlePoliceBox::onQueueDrop, &mboxes.at(i)));
qc.Get(2 * i + 1)->TraceConnectWithoutContext("Drop", MakeCallback(&MiddlePoliceBox::onRedDrop, &mboxes.at(i)));
txRouter->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMboxAck, &mboxes.at(i))); // test passeds
qc.Get(2 * i)->TraceConnectWithoutContext("PacketsInQueue", MakeCallback(&MiddlePoliceBox::TcPktInQ, &mboxes.at(i)));
qc.Get(2 * i + 1)->TraceConnectWithoutContext("PacketsInQueue", MakeCallback(&MiddlePoliceBox::TcPktInRed, &mboxes.at(i)));
// trace TCP congestion window and RTT: tested
for(uint32_t j = 0; j < nTrace; j ++)
{
string context1 = "/NodeList/0/$ns3::TcpL4Protocol/SocketList/" + to_string(j) + "/CongestionWindow";
string context2 = "/NodeList/0/$ns3::TcpL4Protocol/SocketList/" + to_string(j) + "/RTT";
Ptr<Socket> skt = senderApp.at(i * groups[0].N + j)->GetSocket(); // maybe limited for different groups
skt->TraceConnect("CongestionWindow", context1, MakeCallback(&MiddlePoliceBox::onCwndChange, &mboxes.at(i)));
skt->TraceConnect("RTT", context2, MakeCallback(&MiddlePoliceBox::onRttChange, &mboxes.at(i)));
}
// flow control
Ptr<QueueDisc> tbfq = qc.Get(2 * i);
mboxes.at(i).flowControl(mboxes.at(i).GetFairness(), interval, logInterval, ruInterval, tbfq);
}
// NS_LOG_FUNCTION("Connect Mbox Ctrl...");
// for(uint32_t i = 0; i < grp.size(); i ++)
// {
// Ptr<NetDevice> mbRouter = GetNode(i, grp[i].routerId[0])->GetDevice(0);
// Ptr<NetDevice> rxRouter = GetNode(i, grp[i].routerId[2])->GetDevice(0);
// Ptr<Node> mbNode = GetNode(i, grp[i].routerId[0]);
// NetDeviceContainer nc;
// for(uint32_t j = 1; j <= grp[i].N_ctrl; j ++)
// nc.Add(mbNode->GetDevice(j));
// mboxes[i].install(nc);
// mboxes[i].ip2prot = ip2prot;
// vector<double> rtts;
// for(uint32_t j = 0; j < grp[i].N_ctrl; j ++)
// {
// double bnDelay = (bottleneckDelay[i].c_str()[0] - '0') / 1000.0;
// double dely = (delay.c_str()[0] - '0') / 1000.0;
// double nRouter = 3;
// rtts.push_back(2 * (bnDelay + 2 * dely));
// }
// mboxes[i].SetWeight(grp[i].weight);
// mboxes[i].SetRttRto(rtts);
// mboxes[i].start();
// // tracing
// cout << "connect: N_ctrl = " << grp[i].N_ctrl << endl;
// for(uint32_t j = 1; j <= grp[i].N_ctrl; j ++)
// {
// bottleneck.EnablePcapAll("router");
// bool res = mbNode->GetDevice(j)->TraceDisconnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMacRx, &mboxes[i]));
// NS_ASSERT_MSG(res, "MacRx installation failed at " + to_string(j) + "!");
// }
// // debug MacRx tracing
// cout << "mb dev num: " << mbNode->GetNDevices() << endl;
// for(uint32_t j = 1; j <= grp[i].N_ctrl; j ++)
// {
// cout << mbNode->GetDevice(j)->GetMtu() << ", " << mbNode->GetDevice(j)->GetAddress() << ", ip: ";
// GetIpv4Addr(i, grp[i].routerId[0], j).Print(cout);
// cout << endl;
// }
// mbRouter->TraceConnectWithoutContext("MacTx", MakeCallback(&MiddlePoliceBox::onMacTx, &mboxes[i]));
// rxRouter->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onPktRx, &mboxes[i]));
// qc.Get(2 * i)->TraceConnectWithoutContext("Drop", MakeCallback(&MiddlePoliceBox::onQueueDrop, &mboxes[i]));
// mbRouter->TraceConnectWithoutContext("MacRx", MakeCallback(&MiddlePoliceBox::onMboxAck, &mboxes[i]));
// qc.Get(2 * i)->TraceConnectWithoutContext("PacketsInQueue", MakeCallback(&MiddlePoliceBox::TcPktInQ, &mboxes[i])); // debug queue size
// qc.Get(2 * i + 1)->TraceConnectWithoutContext("PacketsInQueue", MakeCallback(&MiddlePoliceBox::TcPktInRed, &mboxes[i]));
// for(uint32_t j = 0; j < groups[i].N_ctrl; j ++) // trace TCP congestion window and RTT: tested
// {
// string context1 = "/NodeList/0/$ns3::TcpL4Protocol/SocketList/" + to_string(j) + "/CongestionWindow";
// string context2 = "/NodeList/0/$ns3::TcpL4Protocol/SocketList/" + to_string(j) + "/RTT";
// Ptr<Socket> skt = senderApp.at(i * groups[0].N + j)->GetSocket(); // maybe limited for different groups
// skt->TraceConnect("CongestionWindow", context1, MakeCallback(&MiddlePoliceBox::onCwndChange, &mboxes[i]));
// skt->TraceConnect("RTT", context2, MakeCallback(&MiddlePoliceBox::onRttChange, &mboxes[i]));
// }
// Ptr<QueueDisc> tbfq = qc.Get(2 * i);
// mboxes[i].flowControl(mboxes[i].GetFairness(), interval, logInterval, ruInterval, tbfq);
// }
}
void RunningModule::start()
{
NS_LOG_FUNCTION("Start.");
sinkApp.Start(Seconds(rtStart));
sinkApp.Stop(Seconds(rtStop));
for(uint32_t j = 0; j < senderApp.size(); j ++)
{
// senderApp.at(j)->SetStartTime(Seconds(rtStart));
// senderApp.at(j)->SetStopTime(Seconds(rtStop));
senderApp.at(j)->SetStartTime(Seconds(txStart.at(j)));
cout << j << ": start at " << txStart.at(j) << endl;
senderApp.at(j)->SetStopTime(Seconds(txEnd.at(j)));
}
}
void RunningModule::stop()
{
NS_LOG_FUNCTION("Stop.");
for(uint32_t j = 0; j < senderApp.size(); j ++)
senderApp.at(j)->SetStopTime(Seconds(0.0)); // stop now
sinkApp.Stop(Seconds(0.0));
}
int main (int argc, char *argv[])