1 # control.tcl --
2 #
3 # FIXME: This file needs a description here.
4 #
5 # Copyright (c) 1998-2002 The Regents of the University of California.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # A. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # B. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # C. Neither the names of the copyright holders nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 import AnnounceListenManager ZTrace MTrace URL_Get_Timer URL_Resp_Timer
32
33 set mtrace [MTrace init {trcWC}]
34 $mtrace toggle_window
35
36 set ztrace [ZTrace init]
37
38 #
39 # A control object for the web cache. It takes care of
40 # communications amoung all caches in a multicast session.
41 #
42 Class WebCacheControl -superclass AnnounceListenManager
43
44 #
45 # The web cache control control. <i>netspec</i> is the multicast
46 # address passed to the announce listen manager, and <i>wc</i> is
47 # the web cache component.
48 #
49 WebCacheControl public init { d1 d2 e1 e2 netspec } {
50 $self next $netspec
51 $self instvar resp_hit_c1_ resp_hit_c2_ resp_hit_d_
52 $self instvar resp_miss_c1_ resp_miss_c2_ resp_miss_d_
53 $self instvar get_c1_ get_c2_ get_d_
54
55 # default random delay values; set to wait a minimum of
56 # two times the estimated rtt (two times the d values below)
57 # to neighbors and choose a delay from an interval that is twice the
58 # "length" of the estimated rtt.
59 set get_c1_ 2.0
60 set get_c2_ 2.0
61 set resp_hit_c1_ $d1
62 set resp_hit_c2_ $d2
63 set resp_miss_c1_ $e1
64 set resp_miss_c2_ $e2
65 set get_d_ .25
66 set resp_hit_d_ .25
67 set resp_miss_d_ .25
68 }
69
70 #
71 # Create URL_Get_Timer for <i>url</i>.
72 #
73 WebCacheControl public create_get_timer { url } {
74 $self instvar gettimer_table_ get_c1_ get_c2_ get_d_ cache_
75
76 # create a URL_Get_Timer
77 if ![info exists gettimer_table($url)] {
78 mtrace trcWC "control: create_get_timer $url"
79 set gettimer [new URL_Get_Timer $url $get_c1_ $get_c2_ $get_d_ $self]
80 set gettimer_table_($url) $gettimer
81 }
82 }
83
84 #
85 # Called when data arrived from the multicast session thereby
86 # the get and response timers associated with the url need to
87 # be canceled.
88 #
89 WebCacheControl public cancel_all_timers { url } {
90 $self instvar cache_ gettimer_table_ resptimer_table_
91
92 mtrace trcWC "control: cancel all timers $url"
93
94 # cancel all timers and pending messages associated with the url
95 if { [info exists gettimer_table_($url)] } {
96 $gettimer_table_($url) destroy
97 unset gettimer_table_($url)
98 }
99 if { [info exists resptimer_table_($url)] } {
100 $resptimer_table_($url) destroy
101 unset resptimer_table_($url)
102 }
103 }
104
105
106 WebCacheControl public win_resp_timer { url } {
107 $self instvar cache_ gettimer_table_ resptimer_table_
108
109 mtrace trcWC "control: win_resp_timer $url"
110
111 # cancel the URL_Resp_Timer
112 if [info exists resptimer_table_($url)] {
113 $resptimer_table_($url) destroy
114 unset resptimer_table_($url)
115 }
116
117 # backoff the URL_Get_Timer
118 if [info exists gettimer_table_($url)] {
119 $gettimer_table_($url) backoff
120 }
121
122 # send a reply pending message if we don't have the
123 # data.
124 if { [$cache_ hit $url] == "" } {
125 $self send_announcement WC_RESP_PEND $url
126 }
127
128 # ask the cache to send data associated with the url
129 $cache_ send_data $url
130 }
131
132 #
133 # Send messages when timers expire. If a get message is
134 # being sent, this method also set a local resp timer. If
135 # a pending message is being sent, this method also cancel
136 # the assocaited resp timer.
137 #
138 WebCacheControl public send_announcement { type url { args "" } } {
139 $self instvar resptimer_table_ resp_miss_c1_ resp_miss_c2_ \
140 resp_miss_d_
141
142 mtrace trcWC "control: send_announcement $type"
143
144 switch -- $type {
145 WC_URL_GET {
146 $self announce "WC_URL_GET $url"
147
148 # should not create multiple get timers for the
149 # same url. this is ok because we forget about
150 # the timer in the array once the srm receiver
151 # all the data.
152 if ![info exists resptimer_table_($url)] {
153 set resptimer_table_($url) \
154 [new URL_Resp_Timer $url \
155 $resp_miss_c1_ $resp_miss_c2_ \
156 $resp_miss_d_ $self]
157 }
158 }
159 WC_RESP_PEND {
160 $self announce "WC_RESP_PEND $url"
161 }
162 }
163 }
164
165 #
166 # Receive messages from other caches. There are currently the
167 # following messages:
168 # WC_URL_GET means that another cache has won the timer war so
169 # this cache should backoff its get timer. At the same time,
170 # it initiates a response timer, which decides which cache will
171 # send the data back to the session.
172 # WC_RESP_PEND means that another cache has won the response
173 # timer war and is currently getting/sending the data. This
174 # cancels the response timer, and backoffs the get timer.
175 #
176 WebCacheControl public recv_announcement { addr port mesg len } {
177 $self instvar gettimer_table_ resptimer_table_ cache_ \
178 resp_hit_c1_ resp_hit_c2_ resp_miss_c1_ resp_miss_c2_ \
179 resp_hit_d_ resp_miss_d_
180
181 mtrace trcWC "control: recv_announcement $mesg"
182
183 set type [lindex $mesg 0]
184 set url [lindex $mesg 1]
185
186 switch -- $type {
187 WC_URL_GET {
188 # backoff its own URL_Get_Timer
189 if [info exists gettimer_table_($url)] {
190 $gettimer_table_($url) backoff
191 }
192
193 # check whether it has data in the local cache
194 if { [$cache_ hit $url] != "" } {
195 set c1 $resp_hit_c1_
196 set c2 $resp_hit_c2_
197 set d $resp_hit_d_
198 } else {
199 set c1 $resp_miss_c1_
200 set c2 $resp_miss_c2_
201 set d $resp_miss_d_
202 }
203
204 # again, do not create multiple timers, because it
205 # confuses the destroy timer operation.
206 if ![info exists resptimer_table_($url)] {
207 set resptimer [new URL_Resp_Timer $url $c1 $c2 $d $self]
208 set resptimer_table_($url) $resptimer
209 }
210 }
211 WC_RESP_PEND {
212
213 # cancel its URL_Resp_Timer if it doesn't have the
214 # data since some other node has requested the data
215 # from the origin server. if it does have the data,
216 # do nothing.
217
218 if { [$cache_ hit $url] == "" } {
219 if [info exists resptimer_table_($url)] {
220 $resptimer_table_($url) destroy
221 unset resptimer_table_($url)
222 }
223
224 # backoff the URL_Get_Timer
225 if [info exists gettimer_table_($url)] {
226 $gettimer_table_($url) backoff
227 }
228 }
229 }
230 }
231 }
232
233
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.