File: webbench.tcl

package info (click to toggle)
ns2 2.35%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,796 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (90 lines) | stat: -rw-r--r-- 2,436 bytes parent folder | download | duplicates (8)
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
proc webworkload { ns server stcp ssink client ctcp csink reqsz replsz numpll tcptrace sinktrace numreq } { 
	for {set i 0} {$i < $numreq} {incr i 1} {
		set wb($i) [new Webbench]
		set randtime [uniform 0 2]
		$ns at $randtime "$wb($i) webbench $ns $server $stcp $ssink $client $ctcp $csink $reqsz $replsz $numpll $tcptrace $sinktrace"
	}  
}

proc setuptcp { ns src stcp dst dtcp tcptrace sinktrace } {
	set tcp1 [new Agent/$stcp]
	$tcp1 trace $tcptrace

	set sink1 [new Agent/$dtcp]
	$sink1 trace $sinktrace

	$ns attach-agent $src $tcp1
	$ns attach-agent $dst $sink1
	$ns connect $tcp1 $sink1
	
	return $tcp1
}

proc setupsource { tcp1 stype } {
	set src1 [new Source/$stype]
	$src1 set agent_ $tcp1

	return $src1
}

Class Webbench

Webbench instproc init { } {
	$self instvar ns_ tcp_cs_ ftp_cs_ tcp_sc_ ftp_sc_ reqsz_ replsz_ numpll_
	$self instvar replycount_ starttime_ endtime_
}

Webbench instproc webbench { ns server stcp ssink client ctcp csink reqsz replsz numpll tcptrace sinktrace }  {
	$self instvar ns_ tcp_cs_ ftp_cs_ tcp_sc_ ftp_sc_ reqsz_ replsz_ numpll_
	$self instvar replycount_ starttime_ endtime_

	# save values from arguments
	set ns_ $ns 
	set reqsz_ $reqsz
	set replsz_ $replsz
	set numpll_ $numpll
	set replycount_ 0

	# start time
	set starttime_ [$ns now]

	# attach TCP agents and FTP sources to the server and client nodes

	# client to server
	set tcp_cs_ [setuptcp $ns_ $client $ctcp $server $ssink $tcptrace $sinktrace] 
	$tcp_cs_ set packetSize_ $reqsz
	$tcp_cs_ proc done {} {$self sendreply}
	set ftp_cs_ [setupsource $tcp_cs_ "FTP"]
	
	# server to client
	for {set i 0} {$i < $numpll} {incr i 1} {
		set tcp_sc_($i) [setuptcp $ns_ $server $stcp $client $csink $tcptrace $sinktrace]
		$tcp_sc_($i) proc done {} {$self recdreply}
		set ftp_sc_($i) [setupsource $tcp_sc_($i) "FTP"]
	}
	
	# send a 1-pkt request from client to server
	$ftp_cs_ produce 1 
	
}


Webbench instproc sendreply { } {
	$self instvar ns_ tcp_cs_ ftp_cs_ tcp_sc_ ftp_sc_ numpll_ reqsz_ replsz_ numpll_
	
	for {set i 0} {$i < $numpll_} {incr i 1} {
		$ftp_sc_($i) produce $replsz_
	}
}

Webbench instproc recdreply { } {
	$self instvar ns_ tcp_cs_ ftp_cs_ tcp_sc_ ftp_sc_ numpll_ reqsz_ replsz_ numpll_
	$self instvar replycount_ starttime_ endtime_
	
	incr replycount_ 1
	if { $replycount_ == $numpll_ } {
		set endtime_ [$ns_ now]
		puts [format "Time taken for Web transaction: %g" [expr $endtime_ - $starttime_]]
	}
}