#!/usr/bin/perl -w use English; # tbprerun # This is the first program in the # tbprerun/tbswapin/tbswapout/.../tbend sequences. It's main purpose # is to interpret the NS file and create the appropriate entries in # virt_nodes and virt_lans. After this script ends successfully the # NS file is no longer necessary. # # Configure variables # my $TBROOT = "@prefix@"; # Untaint the path $ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" . ":$TBROOT/sbin:$TBROOT/bin"; # # Testbed Support libraries # use lib "@prefix@/lib"; use libdb; use libtestbed; # # Turn off line buffering on output # $| = 1; if ($#ARGV != 2) { print STDERR "Syntax: $0 pid eid ns_file\n"; exit(1); } my ($pid,$eid,$nsfile) = @ARGV; if (! -r $nsfile) { print STDERR "*** NS File '$nsfile' does not exist!\n"; exit(1); } my $state; print "Beginning pre run for $pid/$eid. " . TBTimeStamp() . "\n"; if (! ($state = ExpState($pid, $eid))) { print STDERR "*** No such experiment $pid/$eid\n"; exit(1); } if ($state ne EXPTSTATE_NEW) { print STDERR "*** Experiment is not in the proper state: $state\n"; exit(1); } if (! SetExpState($pid, $eid, EXPTSTATE_PRERUN)) { print STDERR "*** Failed to set intermediate experiment state.\n"; exit(1); } # # Cleanup if something goes wrong. # sub cleanup { print STDERR "Cleaning up after errors.\n"; DBQueryWarn("DELETE from virt_nodes where pid='$pid' and eid='$eid'"); DBQueryWarn("DELETE from virt_lans where pid='$pid' and eid='$eid'"); SetExpState($pid, $eid, EXPTSTATE_NEW); } # This setups virt_nodes, virt_names including all IP address calculation # and tb-* handling. print "Running parser ... " . TBTimeStamp() . "\n"; if (system("parse.tcl $pid $eid $nsfile")) { print STDERR "*** Parsing failed.\n"; cleanup(); exit(1); } print "Parser done! Marking as prerunned. " . TBTimeStamp() . "\n"; if (!SetExpState($pid, $eid, EXPTSTATE_SWAPPED)) { print STDERR "*** Failed to set experiment state!\n"; cleanup(); exit(1); } print "Pre run finished. " . TBTimeStamp() . "\n"; exit(0);