forked from oslo2015/NS2Tcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prior_new.tcl
262 lines (190 loc) · 5.35 KB
/
prior_new.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
# Creating New Simulator
set ns [new Simulator]
$ns rtproto simple
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the NAM trace file
close $nf
#Execute NAM on the trace file
exec nam out.nam &
exit 0
}
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns color 0 Black
$ns color 1 Blue
$ns color 2 Red
$ns color 3 green
$ns color 4 yellow
$ns color 5 brown
$ns color 6 chocolate
$ns color 7 gold
$ns color 8 tan
#Create links between the nodes
$ns duplex-link $n0 $n1 2Mb 10ms DropTail
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n3 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 2Mb 10ms DropTail
set udp [new Agent/UDP]
$ns attach-agent $n0 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 1
$udp set fid_ 2
puts [$n3 id]
puts [[$null set node_] id]
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
#Schedule events for the CBR and FTP agents
#$ns at 0.1 "$cbr start"
#$ns at 4.5 "$cbr stop"
#$ns at 5.0 "finish"
#$ns run
array set ss ""
set isFlowBased 1
set jobId 1
set flowCnt 0
for {set i 0} {$i < 10} {incr i} {
set ss($i) [expr $jobId * 1000 + $flowCnt]
incr flowCnt
if {0 == $isFlowBased} {
set ss($i) [expr $ss($i) / 1000]
}
}
parray ss
array set tt ""
set ftp [new Application/FTP]
puts $ftp
set tt($ftp) 1
parray tt
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]
set totalNodeNum [expr $hostShift + $k * $hostNumInPod]
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]]
}
proc getFirstNodeByAddr { id } {
global hostShift hostNumInPod eachPodNum coreNum aggNumInPod
return [expr $coreNum + $aggNumInPod + $eachPodNum * [addrToPodId $id] + [addrToSubnetId $id]]
}
# pod aggregation switch
# switch 命名规则:pod(i,type,j)
# i : podNum
# type : a-agg, e-edge
# j : eachPodNum
#$arrftp($jobId,$i,$
#ftpRecord()
#set classifier [$coreSw($i) entry]
set CmdaddFlow 1
set CmdremoveFlow 2
#for {set id $hostShift} {$id < $totalNodeNum} {incr id} {
# puts "$id [addrToPodId $id] -- [addrToSubnetId $id] -- [addrToFirstNode $id]"
#}
for {set id $aggShift} {$id < [expr $hostShift - $aggNumInPod]} {incr id} {
puts "$id [addrToPodId $id 1] -- [addrToSubnetId $id 1]"
}
# 不仅设置路径的flow base
# isFeedBack 用来表示是否是ack路径
proc centrlCtrlFlow { command spid dpid isFeedBack} {
global ftpRecord pod CmdaddFlow CmdremoveFlow
if {$spid != $dpid} {
# 不同pod内, 6hops, 4paths
if {$command == $CmdaddFlow} {
set nextId [$classifier addFlowId $fid $isFeedBack]
if {-1 == $nextId} {
return
}
set sndNode $pod([addrToPodId $nextId],a,[addrToSubnetId $nextId])
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],a,[addrToSubnetId $nextId])
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
}
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]
# 设置发包路径的 flow base
centrlCtrlFlow $command $spid $dpid 0
# 设置ack路径的 flow base
centrlCtrlFlow $command $dpid $spid 1
}
proc ttt {} {
set a 3
set b 4
if {$a == 1} {
puts "-------------"
return
} elseif {$b == 2} {
puts "*************"
return
}
puts "88888888888888"
}