Commit a522409a authored by Leigh Stoller's avatar Leigh Stoller

Changes to support new syntax for program objects.

parent 53955f50
......@@ -9,7 +9,7 @@ SUBDIR = tbsetup/ns2ir
include $(OBJDIR)/Makeconf
LIB_STUFF = lanlink.tcl node.tcl sim.tcl tb_compat.tcl null.tcl \
nsobject.tcl traffic.tcl vtype.tcl parse.tcl
nsobject.tcl traffic.tcl vtype.tcl parse.tcl program.tcl
LIBEXEC_STUFF = parse-ns
#
......
......@@ -183,6 +183,7 @@ source ${GLOBALS::libdir}/node.tcl
source ${GLOBALS::libdir}/null.tcl
source ${GLOBALS::libdir}/traffic.tcl
source ${GLOBALS::libdir}/vtype.tcl
source ${GLOBALS::libdir}/program.tcl
##################################################
# Redifing Assignment
......@@ -267,11 +268,17 @@ proc new {class args} {
NullClass $id
return $id
}
if {$args != {}} {
punsup "args for $class"
}
set id $class[incr new_counter]
eval $class $id
# XXX Hack!
if {[llength $args] > 1} {
punsup "arguments for $class"
} elseif {[llength $args] == 1} {
eval $class $id [lindex $args 0]
} else {
eval $class $id
}
return $id
}
......
######################################################################
# program.tcl
#
# This defines the local program agent.
#
######################################################################
Class Program -superclass NSObject
namespace eval GLOBALS {
set new_classes(Program) {}
}
Program instproc init {s} {
global ::GLOBALS::last_class
$self set sim $s
$self set node {}
$self set command {}
# Link simulator to this new object.
$s add_program $self
set ::GLOBALS::last_class $self
}
Program instproc rename {old new} {
$self instvar sim
$sim rename_program $old $new
}
# updatedb DB
# This adds rows to the virt_trafgens table corresponding to this agent.
Program instproc updatedb {DB} {
var_import ::GLOBALS::pid
var_import ::GLOBALS::eid
var_import ::GLOBALS::objtypes
$self instvar node
$self instvar command
if {$node == {}} {
perror "\[updatedb] $self has no node."
return
}
if {$command == {}} {
perror "\[updatedb] $self has no command."
return
}
sql exec $DB "insert into virt_agents (pid,eid,vnode,vname,objecttype) values ('$pid','$eid','$node','$self','$objtypes(PROGRAM)')";
}
......@@ -582,49 +582,10 @@ Simulator instproc use_subnet {subnet} {
set subnets($subnet) {}
}
# program
Simulator instproc program {} {
var_import ::GLOBALS::last_class
$self instvar id_counter
# add_program
# Link to a new program object.
Simulator instproc add_program {prog} {
$self instvar prog_list
set id n[incr id_counter]
Program $id $self
set prog_list($id) {}
set last_class $id
return $id
}
Program instproc init {s} {
$self set sim $s
$self set node {}
$self set command {}
}
Program instproc rename {old new} {
[$self set sim] rename_program $old $new
}
# updatedb DB
# This adds rows to the virt_trafgens table corresponding to this agent.
Program instproc updatedb {DB} {
var_import ::GLOBALS::pid
var_import ::GLOBALS::eid
var_import ::GLOBALS::objtypes
$self instvar node
$self instvar command
if {$node == {}} {
perror "\[updatedb] $self has no node."
return
}
if {$command == {}} {
perror "\[updatedb] $self has no command."
return
}
sql exec $DB "insert into virt_agents (pid,eid,vnode,vname,objecttype) values ('$pid','$eid','$node','$self','$objtypes(PROGRAM)')";
set prog_list($prog) {}
}
......@@ -46,11 +46,11 @@ $ns connect $udp0 $null0
$ns connect $tcp0 $null1
# Create a program object and attach it to nodeA
set prog0 [$ns program]
set prog0 [new Program $ns]
$prog0 set node $n3
$prog0 set command "/bin/ls -lt >& /tmp/foo"
set prog1 [$ns program]
set prog1 [new Program $ns]
$prog1 set node $n3
$prog1 set command "/bin/sleep 60 >& /tmp/bar"
......
......@@ -385,15 +385,15 @@ to be started and stopped with NS <tt>at</tt> statements. To define a
program object:
<code><pre>
set prog0 [$ns program]
set prog0 [new Program $ns]
$prog0 set node $nodeA
$prog0 set command "/bin/ls -lt >& /users/joe/logs/prog0"
set prog1 [$ns program]
set prog1 [new Program $ns]
$prog1 set node $nodeB
$prog1 set command "/bin/sleep 60 >& /tmp/sleep.debug"</pre></code>
Then in your NS files a set of static events to run these commands:
Then in your NS file a set of static events to run these commands:
<code><pre>
$ns at 10 "$prog0 start"
......@@ -410,9 +410,6 @@ If you want to schedule starts and stops using dynamic events:
Some points worth mentioning:
<ul>
<li> The term "program" generally refers to the object by which you
control the command line you have specifed.
<li> A program must be "stopped" before it is started; if the program
is currently running on the node, the start event will be
silently ignored.
......@@ -426,7 +423,7 @@ Some points worth mentioning:
process group leader (the csh process). If the SIGTERM fails, a
SIGKILL is sent.
<li> When issuing dynamic events using <tt>tevc</tt?, you must specify
<li> When issuing dynamic events using <tt>tevc</tt>, you must specify
the command line to invoke. This is intended to make program
objects more flexible.
</ul>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment