forked from oslo2015/NS2Tcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prior_test10.tcl
998 lines (804 loc) · 25.7 KB
/
prior_test10.tcl
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
#
#
# topo : fat tree k = 4
#
#
# 目的:
# 整体实验
# 多job + 多路径(flow-based scheduling)
#
#
# 已有:
# (1) 输出格式
# t1 t2 t3 ... sceneTime
# !!完成 2015-04-23 16:04:41
#
# (2) 点的读入
# 要完成点的选择,读取文件|随机产生
#
# (3) 当最高优先级完成,次优先级变成最高优先级,即设置最高优先级动态设定。
#
# 新增:
# (1) 实现flow-based 的 多路径
#
#
#
#
# 2015-12-01 15:01:55
# tcl程序接受5个参数
# argv0 jobnum
# argv1 queueNum
# argv2 HowToReadPoint -- 1代表读取文件 -- 2代表随机产生
# argv3 isflowBased -- 1代表flowBased -- 0代表packetBased
# argv4 isSinglePath -- 1代表设置成单路径
# -----------------------------------------------------
# 产生0~Range范围的随机整数
proc randInt { Range } {
return [expr {int (rand()*$Range)}]
}
# 在job 数组中,设置jobId的map个数。
# job($jobId,mapNum) = base + (0 ~ range)
proc setMapNum {job jobId base range} {
upvar $job arr
set arr($jobId,mapNum) [expr $base + [randInt $range]]
}
# 在job 数组中,设置jobId的reduce个数。
# job($jobId,reduceNum) = base + (0 ~ range)
proc setReduceNum {job jobId base range} {
upvar $job arr
set arr($jobId,reduceNum) [expr $base + [randInt $range]]
}
# 给jobId的job中map和reduce随机分配到host中
# 并记录分配结果
proc allocNode {job jobId host {record -1}} {
upvar $job arrj
upvar $host arrl3
global allocInputFile
global HowToReadPoint
set mapn $arrj($jobId,mapNum)
set arraySize [array size arrl3]
for {set i 0} {$i < $mapn} {incr i} {
if { 1 == $HowToReadPoint} {
# 1 代表读取文件
# 2 代表随机产生
gets $allocInputFile line
set seq [expr $line % $arraySize]
} else {
set seq [randInt $arraySize]
puts $allocInputFile $seq
}
set arrj($jobId,m,$i) $arrl3($seq)
if {-1 != $record} {
puts $record "($jobId,m,$i) = [$arrl3($seq) id]"
}
}
set reducen $arrj($jobId,reduceNum)
for {set i 0} {$i < $reducen} {incr i} {
if { 1 == $HowToReadPoint} {
# 1 代表读取文件
# 2 代表随机产生
gets $allocInputFile line
set seq [expr $line % $arraySize]
} else {
set seq [randInt $arraySize]
puts $allocInputFile $seq
}
set arrj($jobId,r,$i) $arrl3($seq)
if {-1 != $record} {
puts $record "($jobId,r,$i) = [$arrl3($seq) id]"
}
}
puts $record ""
}
# 在jobId的map和reduce之间建立ftp链接
# 在tcp_a数组中, tcp_a($jobId,$i,$j) = $tcp
# 在sink_a数组中, sink_a($jobId,$i,$j) = $sink
# 在ftp_a数组中, ftp_a($jobId,$i,$j) = $ftp
# ftp中添加一维,表示 ftp状态
# "r" 代表未开始 "s" 代表正在进行 "d" 代表完成
# job(jobId,ing) 表示job正在运行的流的个数
proc createTcpConnection {job_a jobId tcp_a sink_a ftp_a record {wnd 256} {packetSize 1000}} {
upvar $job_a arrj
upvar $tcp_a arrtcp
upvar $sink_a arrsink
upvar $ftp_a arrftp
global ns isFlowBased ftpRecord
set mapn $arrj($jobId,mapNum)
set reducen $arrj($jobId,reduceNum)
set flowCnt 0
for {set i 0} {$i < $mapn} {incr i} {
for {set j 0} {$j < $reducen} {incr j} {
set tcp [new Agent/TCP/Reno]
set jjobid [expr $jobId * 1000 + $flowCnt]
#puts $jjobid
#set jjobid $jobId
incr flowCnt
if {0 == $isFlowBased} {
set jjobid [expr $jjobid / 1000]
}
#puts $jjobid
$tcp set fid_ $jjobid
$tcp set window_ $wnd
$tcp set packetSize_ $packetSize
$ns attach-agent $arrj($jobId,m,$i) $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $arrj($jobId,r,$j) $sink
$ns connect $tcp $sink
# ftp
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
# 记录ftp的src,dst 节点, fid。 用于flow based scheduling
set ftpRecord($ftp,src) $arrj($jobId,m,$i)
set ftpRecord($ftp,dst) $arrj($jobId,r,$j)
set ftpRecord($ftp,fid) $jjobid
set arrtcp($jobId,$i,$j) $tcp
set arrsink($jobId,$i,$j) $sink
set arrftp($jobId,$i,$j) $ftp
set arrftp($jobId,$i,$j,status) "r"
set arrj($jobId,r$j,started) 0
set arrj($jobId,r$j,fin) 0
set arrj($jobId,ing) 0
#puts $record "($jobId,m$i,r$j) = [$arrj($jobId,m,$i) id].[$tcp port],[$arrj($jobId,r,$j) id].[$tcp dst-port]"
}
}
flush $record
}
# ****************************************
proc setQueueNum { {num 0}} {
global arrLink
foreach i [array names arrLink] {
[$arrLink($i) queue] queue-num $num
}
}
proc setTopPriority { {num 0}} {
# 设置队列中,最高优先级的标号
global arrLink
foreach i [array names arrLink] {
[$arrLink($i) queue] setMaxPriority $num
}
}
proc addrToPodId { id {level 3}} {
global hostShift hostNumInPod aggShift eachPodNum
if {3 == $level} {
return [expr ($id - $hostShift) / $hostNumInPod]
} elseif {1 == $level} {
return [expr ($id - $aggShift) / $eachPodNum]
}
}
proc addrToSubnetId { id {level 3}} {
global hostShift hostNumInPod aggShift eachPodNum
if {3 == $level} {
return [expr (($id - $hostShift) % $hostNumInPod) / $eachPodNum]
} elseif {1 == $level} {
return [expr ($id - $aggShift) % $eachPodNum]
}
}
#proc addrToFirstNode { id } {
# global hostShift hostNumInPod eachPodNum coreNum aggNumInPod
# return [expr $coreNum + $aggNumInPod + $eachPodNum * [addrToPodId $id] + [addrToSubnetId $id]]
#}
# 不仅设置路径的flow base
# isFeedBack 用来表示是否是ack路径
proc centrlCtrlFlow { command fid srcNodeId dstNodeId isFeedBack} {
global pod CmdaddFlow CmdremoveFlow
set spid [addrToPodId $srcNodeId]
set ssubpid [addrToSubnetId $srcNodeId]
set dpid [addrToPodId $dstNodeId]
set dsubpid [addrToSubnetId $dstNodeId]
set firstNode $pod($spid,e,$ssubpid)
set classifier [$firstNode entry]
if {$spid != $dpid} {
# 不同pod内, 6hops, 4paths
if {$command == $CmdaddFlow} {
set nextId [$classifier addFlowId $fid $isFeedBack]
if {-1 == $nextId} {
return
}
set sndNode $pod([addrToPodId $nextId 1],a,[addrToSubnetId $nextId 1])
set classifier2 [$sndNode entry]
$classifier2 addFlowId $fid $isFeedBack
} elseif {$command == $CmdremoveFlow} {
set nextId [$classifier removeFlowId $fid $isFeedBack]
if {-1 == $nextId} {
return
}
set sndNode $pod([addrToPodId $nextId 1],a,[addrToSubnetId $nextId 1])
set classifier2 [$sndNode entry]
$classifier2 removeFlowId $fid $isFeedBack
}
} elseif { $ssubpid != $dsubpid} {
# 同pod, 不同subpod, 4hops, 2path
if {$command == $CmdaddFlow} {
set nextId [$classifier addFlowId $fid $isFeedBack]
} elseif {$command == $CmdremoveFlow} {
set nextId [$classifier removeFlowId $fid $isFeedBack]
}
}
}
# 根据ftp的src,dst,在相应的switch上添加/删除flow信息,
# 达成flow based scheduling
# centrlCtrl ftp {CmdaddFlow/CmdremoveFlow}
proc centrlCtrl { ftp command} {
global ftpRecord pod CmdaddFlow CmdremoveFlow
set srcNodeId [$ftpRecord($ftp,src) id]
set dstNodeId [$ftpRecord($ftp,dst) id]
set fid $ftpRecord($ftp,fid)
if {$srcNodeId == $dstNodeId} {
return
}
# 设置发包路径的 flow base
centrlCtrlFlow $command $fid $srcNodeId $dstNodeId 0
# 设置ack路径的 flow base
centrlCtrlFlow $command $fid $dstNodeId $srcNodeId 1
}
proc printScene { label {channel -1}} {
global totalJobNum tagNum
#global jobTag jobNotTag
global jobDoneNum
global flowVol bandWidth queueLimit queueType
global TAGSEC
puts ""
if {-1 == $channel} {
puts "### $label ###"
puts "--------------"
puts "totalJobNum = $totalJobNum"
#puts "tagNum = $tagNum"
puts "flowVol = $flowVol"
puts "bandWidth = $bandWidth"
puts "queueLimit = $queueLimit"
puts "queueType = $queueType"
puts "TAGSEC = $TAGSEC"
#puts "jobDoneNum = $jobDoneNum"
puts "--------------"
#parray jobTag
#puts "[array size jobTag]"
#puts "--------------"
#parray jobNotTag
#puts "--------------"
} else {
puts $channel "###$label###"
puts $channel "--------------"
puts $channel "totalJobNum = $totalJobNum"
#puts $channel "tagNum = $tagNum"
puts "flowVol = $flowVol"
puts "bandWidth = $bandWidth"
puts "queueLimit = $queueLimit"
puts "queueType = $queueType"
puts "TAGSEC = $TAGSEC"
#puts $channel "jobDoneNum = $jobDoneNum"
puts $channel "--------------"
#foreach {k v} {[array get jobTag *]} {
#puts $channel $k $v
#}
#puts $channel "--------------"
#foreach {k v} {[array get jobNotTag *]} {
#puts $channel $k $v
#}
#puts $channel "--------------"
}
}
# 开始运行jobId的job
# 而且每个reduce最多与5个map传输
proc startJob {job_a jobId ftp_a wtime {numMb 100}} {
upvar $job_a arrj
upvar $ftp_a arrftp
global ns isFlowBased CmdaddFlow CmdremoveFlow
set mapn $arrj($jobId,mapNum)
set reducen $arrj($jobId,reduceNum)
if {$mapn <= 5} {
set mp $mapn
} else {
set mp 5
}
for {set j 0} {$j < $reducen} {incr j} {
for {set i 0} {$i < $mapn} {incr i} {
set arrj($jobId,r$j,started) 0
set arrj($jobId,r$j,fin) 0
}
}
for {set j 0} {$j < $reducen} {incr j} {
for {set i 0} {$i < $mp} {incr i} {
set nbyte [expr 1000*1000*$numMb]
if {1 == $isFlowBased} {
centrlCtrl $arrftp($jobId,$i,$j) $CmdaddFlow
}
$ns at $wtime "$arrftp($jobId,$i,$j) send $nbyte"
set arrftp($jobId,$i,$j,status) "s"
}
set arrj($jobId,r$j,started) $mp
# 设置job正在运行的flow的个数
incr arrj($jobId,ing) $mp
}
}
# 场景开始
# 启动 totalJobNum 个 job
# 每个流大小由numMb决定
# 并在开始后0.1开始 everyDetect
proc sceneStart {startTime {numMb 100}} {
global job ftp
global jobDoneNum totalJobNum
global ns sceneStartT sceneEndT
global jobIng
global sceneNum
incr sceneNum
set sceneStartT $startTime
#puts "SCENE START at $startTime"
set jobDoneNum 0
for {set i 1} {$i <= $totalJobNum} {incr i} {
startJob job $i ftp $startTime $numMb
set jobIng($i) 0
}
#parray jobIng
$ns at [expr $startTime + 0.1] "everyDetect $numMb"
}
# 判断 jodId 中正在执行的ftp是否完成,完成且有未启动的,则启动。
proc jobFtpEndDetect {jobId {numMb 100}} {
global job ftp tcp
global ns fend isFlowBased CmdaddFlow CmdremoveFlow
set now [$ns now]
set mapn $job($jobId,mapNum)
set reducen $job($jobId,reduceNum)
for {set j 0} {$j < $reducen} {incr j} {
for {set k [expr $mapn - 1]} {$k >= 0} {set k [expr $k - 1]} {
if {$ftp($jobId,$k,$j,status) == "s" && yes == [$ftp($jobId,$k,$j) isend]} {
set ftp($jobId,$k,$j,status) "d"
incr job($jobId,r$j,fin)
incr job($jobId,ing) -1
if {1 == $isFlowBased} {
centrlCtrl $ftp($jobId,$k,$j) $CmdremoveFlow
}
puts $fend "$now ftp($jobId,$k,$j) end [$job($jobId,m,$k) id].[$tcp($jobId,$k,$j) port],[$job($jobId,r,$j) id].[$tcp($jobId,$k,$j) dst-port]"
puts $fend "$now job($jobId,r$j,fin) = $job($jobId,r$j,fin)"
puts $fend ""
set started $job($jobId,r$j,started)
if { $started < $mapn} {
set nbyte [expr 1000 * 1000 * $numMb]
set ftp($jobId,$started,$j,status) "s"
if {1 == $isFlowBased} {
centrlCtrl $ftp($jobId,$started,$j) $CmdaddFlow
}
$ns at $now "$ftp($jobId,$started,$j) send $nbyte"
incr job($jobId,r$j,started)
incr job($jobId,ing)
puts $fend "$now ftp($jobId,$started,$j) start"
puts $fend "$now job($jobId,r$j,started) = $job($jobId,r$j,started)"
puts $fend ""
}
}
}
}
}
# 检测jobId 的 job 是否完成
proc jobEndDetect { jobId } {
global job
global ns
set now [$ns now]
set mapn $job($jobId,mapNum)
set reducen $job($jobId,reduceNum)
set flag "yes"
for {set i 0} {$i < $reducen} {incr i} {
if {$job($jobId,r$i,fin) != $mapn} {
set flag "no"
}
#puts "$now : $job($jobId,r$i,fin)"
}
return $flag
}
# 每隔intval检测一次,监测ftp和job的完成情况,并启动新的ftp
proc everyDetect { {numMb 100} } {
global job ftp
global jobTag jobNotTag
global ns fend jobDoneNum totalJobNum
global sceneStartT sceneEndT
global eachPodNum TAGSEC
global qFile qMonitor
global qRecordCount QUEUERECORD
global jobEndTime
global runningTAGSEC
global jobIng
global jobEndTime sceneNum
global TopPriorityNum queueNum
set intval 0.1
set now [$ns now]
#if {0 == [expr {int($now)} % 100]} {
#puts "time : $now"
#}
# 检测每个运行的job的每个运行的流的完成情况
# 如果完成且有未开始的,启动
for {set seq 1} { $seq <= $totalJobNum} {incr seq} {
#proc jobFtpEndDetect {jobId {numMb 100}}
jobFtpEndDetect $seq $numMb
}
# 检测每个job是否完成
for {set seq 1} { $seq <= $totalJobNum} {incr seq} {
#proc jobEndDetect { jobId }
if { yes == [jobEndDetect $seq] && 0 == $jobIng($seq)} {
#puts "$now job($jobTag($seq)) finished."
#puts "#[expr $now - $sceneStartT] job($seq) finished."
incr jobDoneNum
set jobIng($seq) 1
# jobIng($seq) 标记为 完成
set jobEndTime($sceneNum,$seq) [expr $now - $sceneStartT]
# 如果最高优先级job完成
# 次高优先级成为最高优先级
# 2015年06月12日 星期五 09时46分46秒
if {$queueNum > 0 && $seq == $TopPriorityNum} {
set nextTop [expr 1 + $TopPriorityNum]
for {set ii $nextTop} {$ii <= $totalJobNum} {incr ii} {
if {$jobIng($ii) == 0} {
set TopPriorityNum $ii
setTopPriority $TopPriorityNum
break
}
}
}
}
}
#puts "jobDoneNum = $jobDoneNum"
if {1 == $QUEUERECORD} {
foreach i [array names qMonitor] {
puts $qFile($i) "$qRecordCount [$qMonitor($i) set pkts_]"
}
incr qRecordCount
if {0 == [expr $qRecordCount % 10]} {
foreach i [array names qFile] {
flush $qFile($i)
}
}
}
if {$jobDoneNum < $totalJobNum} {
$ns at [expr $now+$intval] "everyDetect $numMb"
} else {
set sceneEndT $now
#puts "scene Done at $now"
#puts "time : [expr $sceneEndT - $sceneStartT]"
set jobEndTime(scene) [expr $sceneEndT - $sceneStartT]
incr qRecordCount 10000
}
}
#**********************************************************
# -----------------------------------------------------
# Creating New Simulator
set ns [new Simulator]
$ns rtproto simple
# Setting up the traces
# trace记录文件,nam动画记录文件
set f [open simu/prior_test8.tr w]
set nf [open simu/prior_test8.nam w]
# 设置nam记录
#$ns namtrace-all $nf
#$ns trace-all $f
proc finish { {isNAM yes} } {
global ns nf f rec fend
global qFile qMonitor
global jobEndTime sceneNum
global jobCmp totalJobNum isSinglePath
#global seqqq
global queueNum
for {set i 1} {$i <= $sceneNum} {incr i} {
#puts "\n####Scene No. $i : #######"
for {set j 1} {$j <= $totalJobNum} {incr j} {
#puts -nonewline "$jobEndTime($i,$j)\t"
puts -nonewline [format "%.4f \t" $jobEndTime($i,$j)]
#puts -nonewline [format "%10.4f" $jobEndTime($i,$j)]
}
puts -nonewline [format "%.4f \t" $jobEndTime(scene)]
#puts -nonewline [format "%10.4f" $jobEndTime($i,$j)]
#puts "\n#####################"
}
puts ""
if {0 == $queueNum && 1 == $isSinglePath} {
puts ""
}
#puts "\n CMP:"
#for {set i 1} {$i <= $totalJobNum} {incr i} {
# set jobCmp($i) [expr $jobEndTime(2,$i) - $jobEndTime(1,$i)]
# puts -nonewline "$jobCmp($i)\t"
#}
#puts ""
#parray jobEndTime
#puts "--------------------"
#parray jobCmp
#if {$jobCmp(1) > 0} {
# puts "\n\[Warn\] This is a bad situation. ----- $seqqq----\n"
#}
#set nodeAllocFile /home/hadoop/nslog/nodeAlloc-log.tr
#set endlogFile /home/hadoop/nslog/end-log.tr
#file copy $nodeAllocFile /home/hadoop/simu/ns2_test/record/nodeAlloc-log-$seqqq.txt
#file copy $endlogFile /home/hadoop/simu/ns2_test/record/endlog-$seqqq.txt
$ns flush-trace
#puts "----------------------------------------"
#puts "Simulation completed."
close $nf
close $f
close $rec
close $fend
foreach i [array names qFile] {
close $qFile($i)
}
if {$isNAM} {
#exec nam simu/prior_test8.nam &
}
exit 0
}
$ns color 0 Black
$ns color 1000 Blue
$ns color 2000 Red
$ns color 3000 green
$ns color 4 yellow
$ns color 5 brown
$ns color 6 chocolate
$ns color 7 gold
$ns color 8 tan
$ns color 1 Blue
$ns color 2 Red
$ns color 3 green
#---------TOPOLOGY-------------
#
#Create Nodes
#
set k 4
set coreNum [expr $k * $k / 4]
set podNum $k
set eachPodNum [expr $k / 2]
set hostNum [expr $k * $k * $k /4]
set TAGSEC 1
set runningTAGSEC 0
set aggShift [expr $k * $k / 4]
set hostShift [expr 5 * $k * $k / 4]
set hostNumInPod [expr $k * $k / 4]
set aggNumInPod [expr $k * $k / 2]
# coreSw 记录core 的switch
# pod 记录agg & edge switch
# pod aggregation switch
# switch 命名规则:pod(i,type,j)asa
# i : podNum
# type : a-agg, e-edge
# j : eachPodNum
# host 记录host
array set coreSw ""
array set pod ""
array set host ""
# core switch
for {set i 0} {$i < $coreNum} {incr i} {
set coreSw($i) [$ns node]
}
for {set i 0} {$i < $podNum} {incr i} {
for {set j 0} {$j < $eachPodNum} {incr j} {
set pod($i,a,$j) [$ns node]
}
}
# pod edge switch
for {set i 0} {$i < $podNum} {incr i} {
for {set j 0} {$j < $eachPodNum} {incr j} {
set pod($i,e,$j) [$ns node]
}
}
# host
for {set i 0} {$i < $hostNum} {incr i} {
set host($i) [$ns node]
}
#
#Create Link
#
# 设置队列记录
set QUEUERECORD 0
#set QUEUERECORD 1
array set qFile ""
array set qMonitor ""
#set fakeFile [open simu/fake.tr w]
set qRecordCount 0
# 链路参数设置
# linkargu
set upLinkNum $eachPodNum
set downLinkNum $eachPodNum
set bandWidth 100Mb
set linkDelay 10ms
set queueLimit 100
#set queueType RED
#set queueType DropTail
set queueType DTPR
# link between Core and Pod
for {set pn 0} {$pn < $podNum} {incr pn} {
set incrBase 0
for {set i 0} {$i < $eachPodNum} {incr i} {
for {set j 0} {$j < $upLinkNum} {incr j} {
set nn [expr $incrBase + $j]
$ns duplex-link $pod($pn,a,$i) $coreSw($nn) $bandWidth $linkDelay $queueType
$ns queue-limit $pod($pn,a,$i) $coreSw($nn) $queueLimit
$ns queue-limit $coreSw($nn) $pod($pn,a,$i) $queueLimit
if {1 == $QUEUERECORD} {
set lsrc $pod($pn,a,$i)
set ldst $coreSw($nn)
set qsrc [$lsrc id]
set qdst [$ldst id]
set qFile($qsrc-$qdst) [open queueFile/$qsrc-$qdst.out w]
set qMonitor($qsrc-$qdst) [$ns monitor-queue $lsrc $ldst $fakeFile 0.1]
set qFile($qdst-$qsrc) [open queueFile/$qdst-$qsrc.out w]
set qMonitor($qdst-$qsrc) [$ns monitor-queue $ldst $lsrc $fakeFile 0.1]
}
}
set incrBase [expr $incrBase + $upLinkNum]
}
}
# link inside pod
for {set pn 0} {$pn < $podNum} {incr pn} {
for {set i 0} {$i < $eachPodNum} {incr i} {
for {set j 0} {$j < $eachPodNum} {incr j} {
$ns duplex-link $pod($pn,a,$i) $pod($pn,e,$j) $bandWidth $linkDelay $queueType
$ns queue-limit $pod($pn,a,$i) $pod($pn,e,$j) $queueLimit
$ns queue-limit $pod($pn,e,$j) $pod($pn,a,$i) $queueLimit
if {1 == $QUEUERECORD} {
set lsrc $pod($pn,a,$i)
set ldst $pod($pn,e,$j)
set qsrc [$lsrc id]
set qdst [$ldst id]
set qFile($qsrc-$qdst) [open queueFile/$qsrc-$qdst.out w]
set qMonitor($qsrc-$qdst) [$ns monitor-queue $lsrc $ldst $fakeFile 0.1]
set qFile($qdst-$qsrc) [open queueFile/$qdst-$qsrc.out w]
set qMonitor($qdst-$qsrc) [$ns monitor-queue $ldst $lsrc $fakeFile 0.1]
}
}
}
}
set incrBase 0
# link between Pod and host
for {set pn 0} {$pn < $podNum} {incr pn} {
for {set i 0} {$i < $eachPodNum} {incr i} {
for {set j 0} {$j < $downLinkNum} {incr j} {
$ns duplex-link $pod($pn,e,$i) $host($incrBase) $bandWidth $linkDelay $queueType
$ns queue-limit $pod($pn,e,$i) $host($incrBase) $queueLimit
$ns queue-limit $host($incrBase) $pod($pn,e,$i) $queueLimit
if {1 == $QUEUERECORD} {
set lsrc $pod($pn,e,$i)
set ldst $host($incrBase)
set qsrc [$lsrc id]
set qdst [$ldst id]
set qFile($qsrc-$qdst) [open queueFile/$qsrc-$qdst.out w]
set qMonitor($qsrc-$qdst) [$ns monitor-queue $lsrc $ldst $fakeFile 0.1]
set qFile($qdst-$qsrc) [open queueFile/$qdst-$qsrc.out w]
set qMonitor($qdst-$qsrc) [$ns monitor-queue $ldst $lsrc $fakeFile 0.1]
}
incr incrBase
}
}
}
#---------TOPOLOGY-------------
#---------Set Switch arguments-------------
# 设置节点类型
# t_host, t_core单路径
# t_agg, t_edge 可多路径
set t_host 1
set t_core 2
set t_agg 3
set t_edge 4
set t_nc -1
set isFlowBased [lindex $argv 3]
set isSinglePath [lindex $argv 4]
# 1 代表flowBased
# 0 代表packetBased
set CmdaddFlow 1
set CmdremoveFlow 2
# core switch
for {set i 0} {$i < $coreNum} {incr i} {
set classifier [$coreSw($i) entry]
$classifier setNodeType $t_core
#$classifier setFlowBased $isFlowBased
}
# host
for {set i 0} {$i < $hostNum} {incr i} {
set classifier [$host($i) entry]
$classifier setNodeType $t_host
#$classifier setFlowBased $isFlowBased
}
# agg switch
for {set pn 0} {$pn < $podNum} {incr pn} {
for {set i 0} {$i < $eachPodNum} {incr i} {
set aggsh [expr $i * $eachPodNum]
set classifier [$pod($pn,a,$i) entry]
$classifier setFatTreeK $k
$classifier setNodeInfo $pn $i $t_agg $aggsh
$classifier setFlowBased $isFlowBased 1
if {1 == $isSinglePath} {
$classifier setNodeType $t_nc
}
}
}
# edge switch
for {set pn 0} {$pn < $podNum} {incr pn} {
set aggsh [$pod($pn,a,0) id]
for {set i 0} {$i < $eachPodNum} {incr i} {
set classifier [$pod($pn,e,$i) entry]
$classifier setFatTreeK $k
$classifier setNodeInfo $pn $i $t_edge $aggsh
$classifier setFlowBased $isFlowBased 1
if {1 == $isSinglePath} {
$classifier setNodeType $t_nc
}
}
}
proc resetAllLast {} {
global pod podNum eachPodNum
for {set pn 0} {$pn < $podNum} {incr pn} {
for {set i 0} {$i < $eachPodNum} {incr i} {
set classifier [$pod($pn,a,$i) entry]
$classifier resetLast
set classifier [$pod($pn,e,$i) entry]
$classifier resetLast
}
}
}
#---------Set Switch arguments-------------
#---------JOB ARGUMENTS---------
# jobargu
#set seqqq [lindex $argv 0]
#set totalJobNum 6
set totalJobNum [lindex $argv 0]
set queueNum [lindex $argv 1]
set HowToReadPoint [lindex $argv 2]
set TopPriorityNum 1
puts [format "queueNum : %d" $queueNum]
#puts $totalJobNum
#puts $queueNum
#puts $HowToReadPoint
if { 1 == $HowToReadPoint} {
# 1 代表读取文件
set allocInputFile [open /home/oslo/simu/alloc.txt r]
} else {
# 2 代表随机产生
set allocInputFile [open /home/oslo/simu/alloc.txt w]
}
set mapNum 10
set reduceNum 4
set mapWive 0
set reduceWive 0
set flowVol 20
set jobDoneNum 0
array set jobIng ""
set sceneStartT 0
set sceneEndT 0
set rec [open /home/oslo/simu/nodeAlloc-log.tr w]
set fend [open /home/oslo/simu/end-log.tr w]
array set jobCmp ""
array set jobEndTime ""
set sceneNum 0
array set ftpRecord ""
#---------JOB ARGUMENTS---------
# 一次实验 ,场景设置,分配节点,建立链接
# jobId 从1开始。
for {set i 1} {$i <= $totalJobNum} {incr i} {
setMapNum job $i $mapNum 0
setReduceNum job $i $reduceNum 0
#proc allocNode {job jobId l3 {record -1}}
allocNode job $i host $rec
#proc createTcpConnection {job_a jobId tcp_a sink_a ftp_a record {wnd 512} {packetSize 5000}}
createTcpConnection job $i tcp sink ftp $rec
}
if { 2 == $HowToReadPoint} {
# 2 代表随机产生
flush $rec
flush $allocInputFile
}
set isNAM yes
if { ![info exists isNAM] } {
set isNAM no
}
set FirstSet 9
set FirstStart [expr 1 + $FirstSet]
set SecondSet 499
set SecondStart [expr 1 + $SecondSet]
# -----------------------------
# 获得队列,可以设置队列中优先级的个数。
set aLink [$ns get-link-arr]
array set arrLink $aLink
if {"DTPR" == $queueType} {
$ns at $FirstSet "setQueueNum $queueNum"
if { $queueNum > 0} {
set TopPriorityNum 1
}
}
#$ns at $FirstSet "printScene Scene_1_QueueFair"
$ns at $FirstSet "sceneStart $FirstStart $flowVol"
$ns at 5000.0 "finish $isNAM"
$ns run