tbprerun.tcl 2.61 KB
Newer Older
1
2
#!/usr/local/bin/tclsh

Christopher Alfeld's avatar
Christopher Alfeld committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
proc outs {args} {
    global logFp
    if {[llength $args] == 1} {
	set out stdout
	set s [lindex $args 0]
    } else {
	set out [lindex $args 0]
	set s [lindex $args 1]
    }
    
    puts $out $s
    puts $logFp $s
}

17
18
19
20
21
### Bootstrapping code.  The whole purpose of this is to find the
# directory containing the script.
set file [info script]
while {![catch "file readlink $file" newfile]} {
    set file $newfile
22
}
23
24
25
26
27
28
set scriptdir [file dirname $file]
if {$scriptdir == "."} {set scriptdir [pwd]}
###

set updir [file dirname $scriptdir]

29
30
set ns2ir "$updir/ir/ns2ir/parse.tcl"
set assign "$updir/ir/assign.tcl"
31
set handle_ip "$updir/ir/handle_ip.tcl"
32
33
34
35
36
37
38
39
set avail "$updir/db/avail"
set ptopgen "$updir/db/ptopgen"
set ptopfile "$updir/ir/testbed.ptop"
set reserve "$updir/db/nalloc"
set libir "$updir/ir/libir.tcl"

source $libir
namespace import TB_LIBIR::ir
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

if {$argc != 1} {
    puts stderr "Syntax: $argv0 <ns-file>"
    exit 1
}

set nsFile [lindex $argv 0]
set t [split $nsFile .]
set prefix [join [lrange $t 0 [expr [llength $t] - 2]] .]
set irFile "$prefix.ir"
set logFile "$prefix.log"

if {[catch "open $logFile w" logFp]} {
    puts stderr "Could not open $logFile for writing."
    exit 1
}

Christopher Alfeld's avatar
Christopher Alfeld committed
57
58
59
60
61
outs "Input: $nsFile"
outs "Output: $irFile"
outs "Log: $logFile"
outs ""
outs "Beginning Testbed pre run for $nsFile. [clock format [clock seconds]]"
62
63

if {! [file exists $nsFile]} {
Christopher Alfeld's avatar
Christopher Alfeld committed
64
    outs stderr "$nsFile does not exist"
65
66
67
    exit 1
}

Christopher Alfeld's avatar
Christopher Alfeld committed
68
outs "Parsing ns input."
69
if {[catch "exec $ns2ir $nsFile $irFile >@ $logFp 2>@ $logFp" err]} {
Christopher Alfeld's avatar
Christopher Alfeld committed
70
    outs stderr "Error parsing ns input. ($err)"
71
72
73
    exit 1
}
if {! [file exists $irFile]} {
Christopher Alfeld's avatar
Christopher Alfeld committed
74
    outs stderr "$irFile not generated.  Make sure you have a 'run' command in your ns file."
75
76
77
    exit 1
}

78
outs "Determining available resources."
Christopher Alfeld's avatar
Christopher Alfeld committed
79
if {[catch "exec $avail type=pc ver extras | $ptopgen > $ptopfile 2>@ $logFp" err]} {
80
81
82
    outs stderr "Error determining available resources. ($err)"
    exit 1
}
83

Christopher Alfeld's avatar
Christopher Alfeld committed
84
outs "Allocating resources - This may take a while."
85
if {[catch "exec $assign $irFile >@ $logFp 2>@ $logFp" err]} {
Christopher Alfeld's avatar
Christopher Alfeld committed
86
    outs stderr "Error allocating resources. ($err)"
87
88
89
    exit 1
}

90
91
92
93
94
95
96
ir read $irFile
set nodemap [ir get /virtual/nodes]
set machines {}
foreach pair $nodemap {
    lappend machines [lindex $pair 1]
}

Christopher Alfeld's avatar
Christopher Alfeld committed
97
outs "Reserving resources."
98
99
100
101
if {[catch "exec $reserve $prefix $machines >@ $logFp 2>@ $logFp" err]} {
    outs stderr "Error reserving resources. ($err)"
    exit 1
}
102

103
104
105
106
107
108
outs "Allocating IP addresses."
if {[catch "exec $handle_ip $irFile $nsFile >@ $logFp 2>@ $logFp" err]} {
    outs stderr "Error allocating IP addresses. ($err)"
    exit 1
}

Christopher Alfeld's avatar
Christopher Alfeld committed
109
outs "Setup finished - $irFile generated."
110
111