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

Open Mash Cross Reference
mash/tcl/dc/snap_sds/application-snap_sds.tcl

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

  1 # application-snap_sds.tcl --
  2 #
  3 #       The SDS server implementation.  SDS services register their attributes
  4 #       with the server and others query it later.
  5 #
  6 # Copyright (c) 2000-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 import Timer/Periodic Application SRMv2_Session SRMv2_Source CServiceTableEntry
 33 
 34 #
 35 # Code for SdsApplication
 36 #
 37 Class SdsApplication -superclass Application
 38 
 39 #
 40 # SdsApplication instproc init { vargs }
 41 #
 42 # Input: vargs - list of strings - the command line arguments
 43 #
 44 
 45 SdsApplication instproc init { argv } {
 46     $self next "snap_sds"
 47 
 48     # deal the command line arguments
 49     set options [$self options]
 50     $self InitArguments $options
 51     $self InitResources $options
 52 
 53     # parse the arguments
 54     set argv [$options parse_args $argv]
 55 
 56     # now deal with the snap session stuff
 57     $self instvar m_snapSession
 58 
 59     set inetAddr [$self get_option optServiceAddress]
 60     set iSPort [$self get_option optServicePort]
 61     set iRPort [$self get_option optServicePort]
 62     set iTTL [$self get_option optServiceTTL]
 63 
 64     set m_snapSession [new CSDSSession $inetAddr $iSPort $iRPort $iTTL]
 65 }
 66 
 67 SdsApplication instproc InitArguments { options } {
 68     $options register_option -sa optServiceAddress
 69     $options register_option -sp optServicePort
 70     $options register_option -st optServiceTTL
 71 }
 72 
 73 SdsApplication instproc InitResources { options } {
 74     $options add_default optServiceAddress "224.4.6.8"
 75     $options add_default optServicePort "12344"
 76     $options add_default optServiceTTL "16"
 77 }
 78 
 79 #
 80 # Code for CSDSSession
 81 #
 82 # this object pretty much does the bulk of the work in the application
 83 # the purpose of this object is to keep a simple table with containers ids
 84 # the containers will be created when a service in the network periodically
 85 # announces that it has a service to offer.  The service will have a path
 86 # from the root.  This path will serve as the path of the containers.
 87 #
 88 Class CSDSSession -superclass {SRMv2_Session Timer/Periodic}
 89 
 90 #
 91 # CSDSSession constructor
 92 #
 93 # input: inetAddr - a string with the internet address
 94 #        iSPort - sending port
 95 #        iRPort - receiving port
 96 #
 97 
 98 CSDSSession instproc init {inetAddr iSPort iRPort iTTL} {
 99     $self next $inetAddr $iSPort $iRPort $iTTL
100 
101     # initialize this array
102     $self instvar m_aServiceTable
103     set m_aServiceTable("") ""
104 
105     # create the one and only source object
106     $self instvar m_SDSSource
107     $self instvar m_cidQueryRequest
108 
109     set m_SDSSource [new SRMv2_Source $self ]
110 
111     # set the source info
112     $m_SDSSource app_info { "Service Discover Service Source" }
113 
114     # create some default containers
115     set m_cidQueryRequest [$m_SDSSource calloc 0 "Query Response"]
116 
117     # Ok now let's set the timer to go off periodically
118     # when the timer goes off it will call timeout
119     $self start
120 }
121 
122 #
123 # CSDSSession instproc srm_recv { src cid seqno data }
124 #
125 # this is a call back function that is overloaded from SRMv2_Session object
126 #
127 # input: same as the srm_rec of SRMv2_Session object
128 #
129 CSDSSession instproc srm_recv { src cid seqno data } {
130     $self instvar m_aServiceTable
131 
132     # ok so far there are only two types of messages that should
133     # arrive, query requests and update messages
134     if {[lindex $data 0] == "UPDATE:"} {
135 
136         set index [concat [$src source_id] $cid]
137 
138         # if there's an entry already then create it, else
139         # just update the time on the one that's already existing
140         if {![info exists m_aServiceTable($index)]} {
141             set tableEntry [new CServiceTableEntry $src $cid \
142                     [lindex $data 1] [lindex $data 2]]
143             set m_aServiceTable($index) $tableEntry
144         } else {
145             set tableEntry $m_aServiceTable($index)
146 
147             # update the with new info
148             $tableEntry ContactInfo [lindex $data 1]
149             $tableEntry ServiceProperty [lindex $data 2]
150         }
151 
152         $tableEntry UpdateTime
153     }
154 
155     # ok if it's not an UPDATE, then it can be a QUERY
156     # for now just return everything
157     # FIXME this is really basic and need to be improved
158     if {[lindex $data 0] == "QUERY_REQUEST:"} {
159         set lSendData "QUERY_RESPONSE:"
160 
161         foreach {index tableEntry} [array get m_aServiceTable] {
162             if {$tableEntry != {}} {
163                 # collect all the info into the lSendData list
164                 lappend lSendData [$tableEntry ContactInfo]
165                 lappend lSendData [$tableEntry ServiceProperty]
166             }
167         }
168 
169         # send the data out to the querier
170         $self instvar m_SDSSource m_cidQueryRequest
171         $m_SDSSource send $m_cidQueryRequest $lSendData
172     }
173 }
174 
175 #
176 # CSDSSession instproc srm_read_adu { src cid seqno } {
177 #
178 # don't repair anything
179 #
180 # input: same as the srm_rec of SRMv2_Session object
181 #
182 CSDSSession instproc srm_read_adu { src cid seqno } {
183     # no recovery mechanism
184 }
185 
186 #
187 # CSDSSession public srm_should_recover { src cid sseq eseq } {
188 #
189 # don't repair any losses
190 #
191 # input: same as the srm_rec of SRMv2_Session object
192 #
193 CSDSSession instproc srm_should_recover { src cid sseq eseq } {
194     return 0
195 }
196 
197 
198 #
199 # CSDSSession instproc timeout {} {
200 #
201 # time out functions.  debug output to print out the table entries
202 # periodically.  Also decrement the time entry and if it reaches zero
203 # then remove it
204 #
205 # input: same as the srm_rec of SRMv2_Session object
206 #
207 CSDSSession instproc timeout {} {
208     $self instvar m_aServiceTable
209 
210     foreach {index tableEntry} [array get m_aServiceTable] {
211         if {$tableEntry != {}} {
212             # decrement the time for table entry
213             $tableEntry Time [expr [$tableEntry Time] - 1]
214             if {[$tableEntry Time] <= 0} {
215                 unset m_aServiceTable($index)
216                 delete $tableEntry 
217             }
218         }
219     }
220 
221     # this is debug outputs
222 #    foreach {index tableEntry} [array get m_aServiceTable] {
223 #       if {$tableEntry != {}} {
224 #           puts -nonewline "src=[$tableEntry Source];"
225 #           puts -nonewline "cid=[$tableEntry Cid];"
226 #           puts -nonewline "time=[$tableEntry Time];"
227 #           puts -nonewline "contact=[$tableEntry ContactInfo];"
228 #           puts "prop=[$tableEntry ServiceProperty];"
229 #       }
230 #    }
231 }
232 

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