~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/megafor/al-megafor.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # al-megafor.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1997-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 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/megafor/al-megafor.tcl,v 1.16 2002/02/03 04:27:42 lim Exp $
 32 
 33 import AnnounceListenManager/AS Timer/Adaptive/ConstBW
 34 
 35 # AnnounceListenManager for soft state gateway, a generic forwarder for
 36 # announce/listen traffic, used in AS1 so that clients without multicast can
 37 # connect to the system.
 38 # Author: Elan Amir
 39 # Status: alpha
 40 Class AnnounceListenManager/AS/SSG -superclass AnnounceListenManager/AS
 41 
 42 # An agent creates a manager and passes itself as "agent"
 43 AnnounceListenManager/AS/SSG instproc init { agent spec bw {srv_inst {}}} {
 44         $self next $spec $bw ssg
 45         $self set agent_ $agent
 46         $self instvar srv_inst_ newtb_ oldtb_
 47 
 48         set f [$self get_option newTBFrac]
 49         set newtb_ [new TokenBucket/SSG $self [expr $bw*$f]]
 50         $newtb_ start
 51         set oldtb_ [new TokenBucket/SSG $self [expr $bw*(1-$f)]]
 52         $oldtb_ start
 53         set srv_inst_ $srv_inst
 54 }
 55 
 56 AnnounceListenManager/AS/SSG public destroy {} {
 57         $self instvar newtb_ oldtb_
 58 
 59         delete $newtb_
 60         delete $oldtb_
 61         $self next
 62 }
 63 
 64 # If a death message arrives, throw it out.  Otherwise, pass the message to the agent
 65 AnnounceListenManager/AS/SSG instproc recv_msg { atype aspec addr srv_name srv_loc srv_inst ssg_port msg } {
 66         if { $srv_name == "DEATH" } {
 67                 return
 68         }
 69         $self instvar agent_
 70         $agent_ recv_msg $self $atype $aspec $addr $srv_name $srv_loc $srv_inst $ssg_port "$msg"
 71 }
 72 
 73 AnnounceListenManager/AS/SSG instproc register args {
 74 }
 75 
 76 AnnounceListenManager/AS/SSG instproc unregister { atype aspec addr srv_name srv_inst msg } {
 77         $self instvar agent_
 78         eval $agent_ unregister $aspec
 79 }
 80 
 81 #
 82 # We enqueue messages from the gateways here.  Since the gateway messages
 83 # never change, a unique identifier for the message is the agent specification
 84 # (aspec).  Thus we can identify if we have seen a given message easily by
 85 # keying on aspec.
 86 #
 87 AnnounceListenManager/AS/SSG instproc enqueue { aspec msgtext } {
 88         $self instvar newtb_ oldtb_ q_
 89 
 90         if {![info exists q_($aspec)] || $q_($aspec) != $msgtext} {
 91                 # new message
 92                 $newtb_ add $msgtext
 93         } else {
 94                 $oldtb_ add $msgtext
 95         }
 96         set q_($aspec) $msgtext
 97 }
 98 
 99 AnnounceListenManager/AS/SSG instproc remove_agent { aspec } {
100         $self instvar q_
101         if [info exists q_($aspec)] {
102                 unset q_($aspec)
103         }
104 }
105 
106 # A TokenBucket for use with a soft state gateway
107 # Author: Elan Amir
108 Class TokenBucket/SSG -superclass Timer/Adaptive/ConstBW
109 
110 TokenBucket/SSG public init { al bw } {
111         $self next $bw
112 
113         $self instvar bw_ q_ qlen_ al_ nsrcs_
114         set q_ {}
115         set qlen_ 8
116         set al_ $al
117         $self update_nsrcs 1
118 }
119 
120 TokenBucket/SSG private timeout {} {
121         $self instvar al_ q_
122         if { $q_ != "" } {
123                 set len [$al_ announce [lindex $q_ 0]]
124                 $self sample_size $len
125                 set q_ [lrange $q_ 1 end]
126         }
127 }
128 
129 TokenBucket/SSG public add { msg } {
130         $self instvar q_ qlen_
131         if { [llength $q_] > $qlen_ } {
132                 return
133         }
134         # FIXME Do we want the aspec as well?
135         lappend q_ $msg
136 }
137 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.