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

Open Mash Cross Reference
mash/tcl/net/rlm-mash.tcl

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

  1 # rlm-mash.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1996-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/net/rlm-mash.tcl,v 1.5 2002/02/03 04:28:06 lim Exp $
 32 
 33 
 34 import MMG Layer
 35 
 36 #FIXME
 37 set rlm_debug_flag 1
 38 
 39 Class Layer/mash -superclass Layer
 40 
 41 Layer/mash instproc init {mmg net n} {
 42         $self next $mmg
 43         $self instvar net_ l_ n_
 44         set net_ $net
 45         set n_ $n
 46         set l_ [$net_ set net_($n)]
 47 }
 48 
 49 Layer/mash instproc join-group {} {
 50         $self instvar mmg_ net_
 51         set level [expr [$mmg_ set subscription_] - 1]
 52         $net_ set-subscription-level $level
 53 
 54         $self next
 55 }
 56 
 57 Layer/mash instproc leave-group {} {
 58         $self instvar mmg_ net_
 59         set level [expr [$mmg_ set subscription_] - 1]
 60         $net_ set-subscription-level $level
 61 
 62         $self next
 63 }
 64 
 65 Layer/mash instproc nlost {} {
 66         $self instvar l_
 67         return [$l_ nlost]
 68 }
 69 
 70 Layer/mash instproc npkts {} {
 71         $self instvar l_ n_
 72         return [$l_ npkts $n_]
 73 }
 74 
 75 #
 76 # This class serves as an interface between the MMG class which
 77 # implements the RLM protocol machinery, and the objects in mash
 78 # that are involved in the RLM protocol (i.e., network objects
 79 # join/leave multicast groups, session objects report packet loss,
 80 # etc..).<p>
 81 #
 82 # An application with the <i>useRLM</i> option turned on will run
 83 # the RLM protocol when a NetworkManager is given an AddressBlock
 84 # with multiple multicast groups.  For now, a single global
 85 # instance of the protocol is run across all sources since
 86 # per-source pruning (IGMPv3) has not been deployed.<p>
 87 #
 88 Class MMG/mash -superclass MMG
 89 
 90 MMG/mash instproc init {net caddr} {
 91         $self instvar net_
 92         set net_ $net
 93 
 94         $self next [$net set nchan_]
 95 
 96         #FIXME make ctrl object listening to $caddr
 97         proc ctrl$self {args} { puts "ctrl: $args" }
 98         $self set ctrl_ ctrl$self
 99 }
100 
101 MMG/mash instproc create-layer {layerNo} {
102         $self instvar net_
103         return [new Layer/mash $self $net_ $layerNo]
104 }
105 
106 MMG/mash instproc now {} {
107         return [gettimeofday]
108 }
109 
110 MMG/mash instproc set_timer {which delay} {
111         $self instvar timers_
112         if [info exists timers_($which)] {
113                 puts "timer botched ($which)"
114                 exit 1
115         }
116         set delay [expr int($delay * 1000)]
117         set timers_($which) [after $delay "$self trigger_timer $which"]
118 }
119 
120 MMG/mash instproc trigger_timer {which} {
121         $self instvar timers_
122         unset timers_($which)
123         $self trigger_$which
124 }
125 
126 MMG/mash instproc cancel_timer {which} {
127         $self instvar ns_ timers_
128         if [info exists timers_($which)] {
129                 #FIXME does this cancel the timer?
130                 after cancel $timers_($which)
131                 unset timers_($which)
132         }
133 }
134 
135 
136 
137 MMG/mash instproc debug { msg } {
138         $self instvar debug_
139         if {!$debug_} { return }
140 
141         $self instvar subscription_ state_
142         set time [format %.05f [$self now]]
143         puts stderr "$time layer $subscription_ $state_ $msg"
144 }
145 
146 
147 #FIXME
148 proc uniform01 {} {
149     return [expr double(([random] % 10000000) + 1) / 1e7]
150 }
151 
152 proc uniform { a b } {
153         return [expr ($b - $a) * [uniform01] + $a]
154 }
155 
156 proc exponential mean {
157         return [expr - $mean * log([uniform01])]
158 }
159 
160 proc trunc_exponential lambda {
161         while 1 {
162                 set u [exponential $lambda]
163                 if { $u < [expr 4 * $lambda] } {
164                         return $u
165                 }
166         }
167 }
168 

~ [ 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.