-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_page.tcl
245 lines (169 loc) · 5.15 KB
/
http_page.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
# Session emulation
Agent/TCP/FullTcp/Sack set segsize_ 1500
ns-random 0
set num_idle_conn 0
set req_size 320
set objnum 42 ;# total number
set no_serv [expr [ns-random]%6+1] ;# serv_tot = main + no_serv = 1 + no_serv
set objnum_server [expr ($objnum+$no_serv+2)/($no_serv+1)]
set num_conn 6
set dns_size 62
set is_delay 0.01
set http_debug 1
set obj_size [new RandomVariable/Pareto]
$obj_size set shape_ 1.2
$obj_size set avg_ 7187
Agent/UDP instproc process_data {from data} {
global ns dns_size http_debug
$self instvar peer_ isserver_ id_ n1_ n2_
set query_type [lindex $data 0]
set server [lindex $data 1]
if {$http_debug} {
puts "DNS [format "%.4lf" [$ns now]] $query_type $server"
}
if { $query_type == "DNS_query" } {
$self send $dns_size "DNS_response $server"
}
if { $query_type == "DNS_response" } {
# open all the connections
$ns at [$ns now] "new-http-session $id_ $n1_ $n2_ $server"
}
}
proc start-http-session {id n1 n2 {server 0}} {
global ns http_start_time page_req_time
set page_req_time($id,$server) [$ns now]
#start DNS
set dnsc [new Agent/UDP]
set dnss [new Agent/UDP]
$dnsc set peer_ $dnss
$dnss set peer_ $dnsc
$dnss set id_ $id
$dnss set n1_ $n1
$dnss set n2_ $n2
$dnsc set id_ $id
$dnsc set n1_ $n1
$dnsc set n2_ $n2
$ns attach-agent $n1 $dnsc
$ns attach-agent $n2 $dnss
$ns connect $dnsc $dnss
if { $server == "0" } {
set http_start_time($id) [$ns now]
}
$ns at [$ns now] "$dnsc send 62 \"DNS_query $server\""
}
Application/TcpApp instproc http-send-req-index {server} {
global ns req_size objnum obj_num duration
global page_req_time page_time num_conn http_debug
$self instvar apps tcp id
if {$server == "0" } {
# first server download index.html first
if { $http_debug == "1" } {
puts "i $id $server [format "%.4lf" [$ns now]]"
}
$ns at [$ns now] "$self send $req_size \"$apps http-req-recv-index\""
} else {
# other servers download objects only
$ns at [$ns now] "$self new-http-session"
$ns at [$ns now] "$self http-send-req NULL"
}
}
Application/TcpApp instproc http-req-recv-index {} {
global ns obj_size id
$self instvar appc
set size [expr int([$obj_size value])]
$ns at [$ns now] "$self send $size \"$appc http-recv-index\""
}
Application/TcpApp instproc http-recv-index {} {
global ns http_debug is_delay no_serv
$self instvar id n1 n2 server
# create sessions to other servers
if { $http_debug == "1" } {
puts "r $id $server [format "%.4lf" [$ns now]]"
}
$ns at [$ns now] "$self new-http-session"
$ns at [$ns now] "$self http-send-req NULL"
set dd [$ns now]
for {set i 1} { $i <= $no_serv} {incr i} {
set dd [expr $dd + $is_delay]
$ns at $dd "start-http-session $id $n1 $n2 $i"
}
}
Application/TcpApp instproc http-send-req {objid} {
global ns req_size objnum obj_num duration http_start_time
global http_duration page_req_time page_time num_conn http_debug
$self instvar apps tcp id server
if { $objid != "NULL" && $http_debug == "1" } {
puts "- $id $server [format "%.4lf" [$ns now]] $objid"
}
incr obj_num($id,$server) -1
if { $obj_num($id,$server) >= 0} {
if { $http_debug == "1" } {
puts "+ $id $server [format "%.4lf" [$ns now]] $obj_num($id,$server)"
}
$ns at [$ns now] "$self send $req_size \"$apps http-req-recv $obj_num($id,$server)\""
return
}
[$self set tcp] close
if { $obj_num($id,$server) == [expr -$num_conn-1]} {
set duration($id,$server) [expr [$ns now] - $page_req_time($id,$server)]
set http_duration($id) [expr [$ns now] - $http_start_time($id)]
if { $http_debug == "1" } {
puts "S $id $server [format "%.4lf" $duration($id,$server)]"
}
}
}
Application/TcpApp instproc http-req-recv {obj_id} {
global ns obj_size obj_num
$self instvar appc id
set size [expr int([$obj_size value])]
$ns at [$ns now] "$self send $size \"$appc http-send-req $obj_id\""
}
Application/TcpApp instproc new-http-session { } {
global ns objnum_server tcp num_conn obj_num
global page_req_time
$self instvar id n1 n2 server
set now [$ns now]
for {set i 0} {$i< $num_conn} {incr i} {
set tcpc [new Agent/TCP/FullTcp/Sack]
set tcps [new Agent/TCP/FullTcp/Sack]
set appc [new Application/TcpApp $tcpc]
set apps [new Application/TcpApp $tcps]
$ns attach-agent $n1 $tcpc
$ns attach-agent $n2 $tcps
$ns connect $tcpc $tcps
$tcps listen
$appc connect $apps
$appc set apps $apps
$apps set appc $appc
$appc set tcp $tcpc
$appc set server $server
$appc set id $id
$apps set id $id
$apps set server $server
$ns at $now "$appc http-send-req NULL"
}
set obj_num($id,$server) $objnum_server
}
proc new-http-session { id n1 n2 {server 0}} {
global ns
set now [$ns now]
set tcpc [new Agent/TCP/FullTcp/Sack]
set tcps [new Agent/TCP/FullTcp/Sack]
set appc [new Application/TcpApp $tcpc]
set apps [new Application/TcpApp $tcps]
$ns attach-agent $n1 $tcpc
$ns attach-agent $n2 $tcps
$ns connect $tcpc $tcps
$tcps listen
$appc connect $apps
$appc set apps $apps
$apps set appc $appc
$appc set tcp $tcpc
$appc set id $id
$appc set n1 $n1
$appc set server $server
$appc set n2 $n2
$apps set id $id
$apps set server $server
$ns at $now "$appc http-send-req-index $server"
}