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

Open Mash Cross Reference
mash/tcl/nsdr/scope.tcl

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

  1 # scope.tcl --
  2 #
  3 #       A ScopeZone object describes a range of multicast addresses that make
  4 #       up an administratively scoped zone.
  5 #
  6 # Copyright (c) 1998-2002 The Regents of the University of California.
  7 # All rights reserved.
  8 #
  9 # Redistribution and use in source and binary forms, with or without
 10 # modification, are permitted provided that the following conditions are met:
 11 #
 12 # A. Redistributions of source code must retain the above copyright notice,
 13 #    this list of conditions and the following disclaimer.
 14 # B. Redistributions in binary form must reproduce the above copyright notice,
 15 #    this list of conditions and the following disclaimer in the documentation
 16 #    and/or other materials provided with the distribution.
 17 # C. Neither the names of the copyright holders nor the names of its
 18 #    contributors may be used to endorse or promote products derived from this
 19 #    software without specific prior written permission.
 20 #
 21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 24 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31 
 32 # A ScopeZone object describes a range of multicast addresses that
 33 # make up an administratively scoped zone (as described in the
 34 # Internet Draft draft-ietf-mboned-admin-ip-space).
 35 Class ScopeZone
 36 
 37 # Creates a new ScopeZone object for the address block <i>range</i>.
 38 # <i>range</i> should be in CIDR format -- a base address followed
 39 # by the number of bits that are significant.  For example, the
 40 # block <tt>239.255.255.0/24</tt> describes the block of address
 41 # from <tt>239.255.255.0</tt> through <tt>239.255.255.255</tt>.
 42 # The optional parameters <i>bw</i> and <i>name</i> contain the
 43 # bandwidth for SAP announcements in this zone and a name that
 44 # describes how the region (e.g., "CAIRN")
 45 ScopeZone public init {range {bw 200} {name ""}} {
 46     $self instvar range_ bw_
 47 
 48     set range_ $range
 49     set bw_ $bw
 50 
 51     # global is handled differently...
 52     if {$range == "224.2.128.0/17"} {
 53         set o [$self options]
 54         set addr [$o get_option SAPaddress]
 55         set port [$o get_option SAPport]
 56         $self set sapAddr_ "$addr/$port"
 57         $self set name_ "Global"
 58         return
 59     }
 60 
 61     if {$name != ""} {
 62         $self set name_ $name
 63     } else {
 64         $self set name_ "Admin Zone $range"
 65     }
 66 
 67     $self set sapAddr_ [$self addr $range]
 68 }
 69 
 70 # Determines the address and port on which SAP announcements are
 71 # broadcast in this scope zone.  In general, this is the highest
 72 # address in the zone and udp port 9875.
 73 ScopeZone private addr {spec} {
 74 
 75     # global sap doesn't use the same convention as admin scoped zones.
 76     if {$spec == "224.2.128.0/17"} {
 77         set o [$self options]
 78         set addr [$o get_option SAPaddress]
 79         set port [$o get_option SAPport]
 80         puts "returning $addr/$port"
 81         return "$addr/$port"
 82     }
 83 
 84     set l [split $spec /]
 85     set len [llength $l]
 86     if { $len < 2 || $len > 3} {
 87         $self warn "Bogus scope zone spec $spec"
 88         exit 1
 89     }
 90 
 91     set base [lindex $l 0]
 92     set mask [lindex $l 1]
 93     set comps [split $base .]
 94     if {[llength $comps] != 4 || $mask > 24} {
 95         $self warn "Bogus scope zone spec $spec"
 96         exit 1
 97     }
 98     set a [lindex $comps 0]
 99     set b [lindex $comps 1]
100     set c [lindex $comps 2]
101     set d [lindex $comps 3]
102     if {$a<224 || $a>239 || $b<0 || $b>255 || $c<0 || $c>255 || $d<0 || $d>255} {
103         $self warn "Bogus scope zone spec $spec"
104         exit 1
105     }
106 
107     if {$mask < 16} {
108         set b [expr $b | ~((-1)<<(16-$mask))]
109         set mask 16
110     }
111     if {$mask < 24} {
112         set c [expr $c | ~((-1)<<(24-$mask))]
113         set mask 24
114     }
115     set d [expr $d | ~((-1)<<(32-$mask))]
116 
117     if {$len == 3} {
118         set port [lindex $l 2]
119     } else {
120         set port 9875
121     }
122 
123     set addr "$a.$b.$c.$d/$port"
124     #puts "$spec -> $addr"
125     return $addr
126 }
127 
128 # Returns a string that describes this range.
129 ScopeZone public name {} {
130     return [$self set name_]
131 }
132 
133 # Returns the total bandwidth for SAP announcements in this region
134 ScopeZone public bw {} {
135     return [$self set bw_]
136 }
137 
138 
139 # Returns a string in CIDR format (i.e., baseaddress/bits) indicating
140 # the range of addresses in this zone.
141 ScopeZone public range {} {
142     return [$self set range_]
143 }
144 
145 # Returns the address and port on which SAP announcements are transmitted
146 # in this zone, as calculated by the <i>addr</i> method.
147 ScopeZone public sapAddr {} {
148     return [$self set sapAddr_]
149 }
150 
151 # FIXME duplicated in alloc.tcl
152 ScopeZone private inet_addr {a} {
153     set l [split $a .]
154     set addr [expr [lindex $l 0] <<24]
155     incr addr [expr [lindex $l 1] <<16]
156     incr addr [expr [lindex $l 2] <<8]
157     incr addr [lindex $l 3]
158     return $addr
159 }
160 
161 #
162 ScopeZone public contains {addr} {
163 
164     $self instvar range_
165     set l [split $range_ /]
166     set base [$self inet_addr [lindex $l 0]]
167     set mask [lindex $l 1]
168     set addr [$self inet_addr $addr]
169     if {$base == [expr $addr & ((-1)<<(32-$mask))]} {
170         return 1
171     }
172     return 0
173 }
174 

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