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

Open Mash Cross Reference
mash/tcl/psvp/fx_forward/back_end.tcl

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

  1 # back_end.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1999-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 RTPApplication
 32 import GraphComm
 33 import FAgent
 34 
 35 Class FXForwardBackEnd -superclass RTPApplication
 36 
 37 FXForwardBackEnd instproc init {args} {
 38     $self next fx_forw_back_end
 39 
 40     $self init_resources
 41 
 42     puts "Args = $args"
 43     eval [$self options] parse_args $args;
 44 
 45     if {[$self get_option subprogram] == ""} {
 46         puts stderr "Must specify subprogram";
 47         exit;
 48     }
 49 
 50     $self instvar my_addr_ node_spec_ ts_pid_ ti_pid_ proc_pids_ my_port_
 51 
 52     set my_addr_ [string trim [exec hostname]];
 53     set habbr [lindex [split $my_addr_ .] 0];
 54     set my_port_ [$self get_option glurun_client_port];
 55 
 56     set server_fd_ [socket -server "$self handle_client_registration" $my_port_];
 57     set my_port_ [lindex [fconfigure $server_fd_ -sockname] 2];
 58 
 59     set node_spec_ all-${habbr}-clump0-clump1-clump2-clump3
 60     global env
 61     set env(GLUNIX_NODES) $node_spec_
 62 
 63     set ts_pid_ [$self StartProc [$self get_option ts_prog] -cntrl_spec [$self get_option to_cntrl]]
 64     set ti_pid_ [$self StartProc [$self get_option ti_prog] -cntrl_spec [$self get_option to_cntrl]]
 65 
 66     for {set p 0} {$p < [$self get_option num_nodes]} {incr p} {
 67         set proc_pids_($p) [$self StartProc [$self get_option proc_prog] -subprogram [$self get_option subprogram] -reg_comm_spec [$self get_option to_cntrl]];
 68     }
 69 
 70     $self instvar from_cntrl_obj_
 71     $self instvar to_cntrl_obj_
 72 
 73     set from_cntrl_spec [split [$self get_option from_cntrl] "/"]
 74     set from_addr [lindex $from_cntrl_spec 0];
 75     set from_port [lindex $from_cntrl_spec 1];
 76     set from_ttl [lindex $from_cntrl_spec 2];
 77 
 78     set from_cntrl_obj_ [new GraphComm/Back/From $self [$self get_option comm_id] $from_addr $from_port $from_ttl];
 79 
 80     set to_cntrl_spec [split [$self get_option to_cntrl] "/"]
 81     set to_addr [lindex $to_cntrl_spec 0];
 82     set to_port [lindex $to_cntrl_spec 1];
 83     set to_ttl [lindex $to_cntrl_spec 2];
 84 
 85     set to_cntrl_obj_ [new GraphComm/Back/To $self [$self get_option comm_id] $to_addr $to_port $to_ttl];
 86 
 87     $from_cntrl_obj_ install $to_cntrl_obj_
 88     $to_cntrl_obj_ install $from_cntrl_obj_
 89 
 90     $from_cntrl_obj_ send_misc "set_back_host [exec hostname]"
 91 
 92 }
 93 
 94 FXForwardBackEnd instproc init_resources {} {
 95     $self add_option num_nodes 4
 96     $self add_option subprogram ""
 97     $self add_option to_cntrl [$self GenerateNewTunnelSpec];
 98     $self add_option network ip
 99     $self add_option mtu 1024
100     $self add_option defaultTTL 32
101     $self add_option sessionType rtpv2
102     $self add_option maxVideoSessionBW 30000000
103     $self add_option glurun_client_port 0
104     $self add_option ts_prog /home/cs/kpatel/mash-code/production/tcl/psvp/test2/fx_tselect.tcl
105     $self add_option ti_prog /home/cs/kpatel/mash-code/production/tcl/psvp/test2/fx_tinter.tcl
106     $self add_option proc_prog /home/cs/kpatel/mash-code/production/tcl/psvp/test2/fx_proc.tcl
107     $self add_option smash_bin /home/cs/kpatel/mash-code/production/smash
108     $self add_option glurun_client /home/cs/kpatel/mash-code/production/tcl/psvp/demos/glurun-client.tcl
109 
110     set hname [exec hostname];
111     set pid [pid];
112 
113     $self add_option comm_id ${hname}.${pid};
114 
115     [$self options] register_option -from_cntrl from_cntrl
116     [$self options] register_option -to_cntrl to_cntrl
117     [$self options] register_option -num_nodes num_nodes
118     [$self options] register_option -subprogram subprogram
119 }
120 
121 FXForwardBackEnd instproc handle_client_registration {sfd addr port} {
122     $self instvar client_sock_fd_;
123 
124     set client_sock_fd_ $sfd;
125 }
126 
127 FXForwardBackEnd instproc StartProc {cmd args} {
128     $self instvar client_sock_fd_ my_addr_ my_port_
129 
130     set client_sock_fd_ "";
131 
132     global env
133     set env(TCL_LIBRARY) /home/cs/kpatel/mash-code/tcl8.0/library
134     cd /home/cs/kpatel/mash-code/production
135 
136     set pid [eval exec glurun [$self get_option smash_bin] [$self get_option glurun_client] $my_addr_ $my_port_ $cmd $args >& /dev/null &];
137 
138     while {$client_sock_fd_ == ""} {
139         update;
140     }
141 
142     set client_host [gets $client_sock_fd_]
143 
144     $self instvar node_spec_
145 
146     set node_spec_ "$node_spec_-${client_host}"
147     global env
148     set env(GLUNIX_NODES) $node_spec_
149 
150     $self instvar pid_map_
151 
152     set pid_map_($pid) $client_sock_fd_;
153 
154     return $pid;
155 }
156 
157 FXForwardBackEnd instproc GenerateNewTunnelSpec {} {
158     $self instvar used_ports_;
159 
160     set new_port [expr (int(rand() * 10000)*2) + 5000];
161     while {[info exists used_ports_($new_port)]} {
162         set new_port [expr (int(rand() * 10000)*2) + 5000];
163     }
164     set used_ports_($new_port) 1;
165 
166     set q1 228
167     set q2 [expr int(rand() * 200) + 10]
168     set q3 [expr int(rand() * 200) + 10]
169     set q4 [expr int(rand() * 200) + 10]
170 
171     return "$q1.$q2.$q3.$q4/$new_port/16"
172 }
173 
174 Class GraphComm/Back -superclass GraphComm
175 
176 GraphComm/Back instproc init {app id addr port ttl} {
177     $self next $id $addr $port
178 
179     $self instvar app_
180 
181     set app_ $app;
182 
183     $self instvar dest_;
184 
185     set dest_ ""
186 }
187 
188 GraphComm/Back instproc install {dest} {
189     $self instvar dest_;
190 
191     set dest_ $dest;
192 }
193 
194 GraphComm/Back instproc recv_trigger_command {cmd} {
195     $self instvar dest_;
196 
197     if {$dest_ == ""} {
198         return;
199     }
200 
201     $dest_ send_trigger_command $cmd
202 }
203 
204 GraphComm/Back instproc recv_misc {cmd} {
205     $self instvar dest_;
206 
207     if {$dest_ == ""} {
208         return;
209     }
210 
211     $dest_ send_misc $cmd
212 }
213 
214 GraphComm/Back instproc recv_debug {data} {
215     $self instvar dest_;
216 
217     if {$dest_ == ""} {
218         return;
219     }
220 
221     $dest_ send_debug $data
222 }
223 
224 GraphComm/Back instproc new_input {new_name} {
225     $self instvar dest_;
226 
227     if {$dest_ == ""} {
228         return;
229     }
230     $self next $new_name
231 
232     $dest_ create_input $new_name
233 }
234 
235 GraphComm/Back instproc new_output {new_name} {
236     $self instvar dest_;
237 
238     if {$dest_ == ""} {
239         return;
240     }
241     $self next $new_name
242 
243     $dest_ create_output $new_name
244 }
245 
246 GraphComm/Back instproc new_parameter {new_name} {
247     $self instvar dest_;
248 
249     if {$dest_ == ""} {
250         return;
251     }
252     $self next $new_name
253 
254     $dest_ create_parameter $new_name
255 }
256 
257 GraphComm/Back instproc new_input_attribute {input_name attr_name} {
258     $self instvar dest_;
259 
260     if {$dest_ == ""} {
261         return;
262     }
263     $self next $input_name $attr_name
264 
265     $dest_ create_input_attr $input_name $attr_name
266 }
267 
268 GraphComm/Back instproc new_output_attribute {output_name attr_name} {
269     $self instvar dest_;
270 
271     if {$dest_ == ""} {
272         return;
273     }
274     $self next $output_name $attr_name
275 
276     $dest_ create_output_attr $output_name $attr_name
277 }
278 
279 GraphComm/Back instproc new_parameter_attribute {parameter_name attr_name} {
280     $self instvar dest_;
281 
282     if {$dest_ == ""} {
283         return;
284     }
285     $self next $parameter_name $attr_name
286 
287     $dest_ create_parameter_attr $parameter_name $attr_name
288 }
289 
290 GraphComm/Back instproc update_input_attr_value {input_name attr_name value} {
291     $self instvar dest_;
292 
293     if {$dest_ == ""} {
294         return;
295     }
296     $self next $input_name $attr_name $value
297 
298     $dest_ set_input_attr $input_name $attr_name $value
299 }
300 
301 GraphComm/Back instproc update_output_attr_value {output_name attr_name value} {
302     $self instvar dest_;
303 
304     if {$dest_ == ""} {
305         return;
306     }
307     $self next $output_name $attr_name $value
308 
309     $dest_ set_output_attr $output_name $attr_name $value
310 }
311 
312 GraphComm/Back instproc update_parameter_attr_value {parameter_name attr_name value} {
313     $self instvar dest_;
314 
315     if {$dest_ == ""} {
316         return;
317     }
318     $self next $parameter_name $attr_name $value
319 
320     $dest_ set_parameter_attr $parameter_name $attr_name $value
321 }
322 
323 GraphComm/Back instproc set_input_attr {input_name attr_name value} {
324     $self create_input $input_name
325     $self create_input_attr $input_name $attr_name
326     $self next $input_name $attr_name $value
327 }
328 
329 GraphComm/Back instproc set_output_attr {output_name attr_name value} {
330     $self create_output $output_name
331     $self create_output_attr $output_name $attr_name
332     $self next $output_name $attr_name $value
333 }
334 
335 GraphComm/Back instproc set_parameter_attr {parameter_name attr_name value} {
336     $self create_parameter $parameter_name
337     $self create_parameter_attr $parameter_name $attr_name
338     $self next $parameter_name $attr_name $value
339 }
340 
341 Class GraphComm/Back/From -superclass GraphComm/Back
342 
343 GraphComm/Back/From instproc update_input_attr_value {input_name attr_name value} {
344     $self instvar dest_;
345 
346     if {$dest_ == ""} {
347         return;
348     }
349 
350     $self instvar app_
351 
352     if {$attr_name == "spec"} {
353         set split_spec [split $value "/"];
354         set addr [lindex $split_spec 0];
355         set port [lindex $split_spec 1];
356         set srcid [lindex $split_spec 2];
357 
358         $self instvar tunnels_
359         if {[info exists tunnels_($addr,$port)]} {
360             set fagent $tunnels_($addr,$port);
361             set tunnel_spec $tunnel_specs_($addr,$port);
362         } else {
363             set tunnel_spec [$app_ GenerateNewTunnelSpec];
364             set fagent [new FAgent $app_ "${addr}/${port}" $tunnel_spec];
365             set tunnels_($addr,$port) $fagent;
366             set tunnel_specs_($addr,$port) $tunnel_spec;
367         }
368         if {$srcid != "*"} {
369             $fagent install_src_callback $srcid "$self complete_input_setup $srcid $fagent $input_name $tunnel_spec"
370             return;
371         } else {
372             set value "${tunnel_spec}/*";
373         }
374     }
375     $self next $input_name $attr_name $value;
376 }
377 
378 GraphComm/Back/From instproc complete_input_setup {srcid fagent input_name tunnel_spec} {
379     set new_id [$fagent translate_srcid $srcid];
380 
381     $self instvar dest_;
382 
383     $dest_ set_input_attr $input_name spec "${tunnel_spec}/${new_id}"
384 }
385 
386 Class GraphComm/Back/To -superclass GraphComm/Back
387 
388 set app [new FXForwardBackEnd $argv];
389 
390 puts "Started"
391 
392 if {![info exists tk_version]} {
393     vwait forever;
394 }
395 
396 

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