Commit 7e7f5a14 authored by Christopher Alfeld's avatar Christopher Alfeld
Browse files

handle_ip and handle_os now use the tbcmds file. extract_tb is the backwards

compatability script that looks at a ns scripts and puts all the #TB commands
in the tbcmds file in the correct format.
parent 14e1d714
......@@ -9,7 +9,7 @@ SUBDIR = tbsetup/ir
include $(OBJDIR)/Makeconf
LIB_STUFF = libir.tcl libir.pm
LIBEXEC_STUFF = assign_wrapper handle_os handle_ip postassign
LIBEXEC_STUFF = assign_wrapper handle_os handle_ip postassign extract_tb
#
# Force dependencies on the scripts so that they will be rerun through
......
#!/usr/bin/perl -w
# This extracts any old style TB commands from the NS file and appends them
# to the tbcmds file.
if ($#ARGV != 1) {
print STDERR "Syntax: $0 ns_file tbcmd_file\n";
exit 1;
}
($nsfile,$tbcmdfile) = @ARGV;
open(NSFILE,$nsfile) || do {
print STDERR "Could not open $nsfile.\n";
exit(1);
};
open(TBCMD,">> $tbcmdfile") || do {
print STDERR "Could not open $tbcmdfile.\n";
exit(1);
};
while (<NSFILE>) {
chop;
/^\#TB (.+)$/ || next;
print TBCMD "tb-" . $1 . "\n";
}
close(NSFILE);
close(TBCMD);
......@@ -37,11 +37,11 @@ $dbh = DBI->connect("DBI:$driver:database=$DBNAME;host=localhost") || do {
};
if ($#ARGV != 1) {
print STDERR "Syntax: $0 irfile nsfile\n";
print STDERR "Syntax: $0 irfile tbcmdfile\n";
exit(1);
}
($irfile,$nsfile) = @ARGV;
($irfile,$tbcmdfile) = @ARGV;
# read IR file
eval {&ir_read($irfile)};
......@@ -50,9 +50,9 @@ if ($@) {
exit(1);
}
# open NS file
open(NSFILE,$nsfile) || do {
print STDERR "Could not open $nsfile\n";
# open tbcmd file
open(TBCMD,$tbcmdfile) || do {
print STDERR "Could not open $tbcmdfile\n";
exit(1);
};
......@@ -127,57 +127,57 @@ $sth->finish;
# Read NS file
# IP is indexed either by src or by src:dst and contains the IP address.
while (<NSFILE>) {
if (/^#TB/) {
chop;
@line = split;
$_ = $line[1];
SWITCH1: {
/^set-ip$/ && do {
# set-ip <node> <ip>
if ($#line != 3) {
push(@ERRORS,"Syntax: set-ip node ip\n");
last SWITCH1;
}
($node,$ip) = @line[2..3];
if (!defined($vnodemap{$node})) {
push(@ERRORS,"$node is not a valid node.\n");
last SWITCH1;
}
# This actually matches a valid IP address
if (! ($ip =~ /^([0-9]{1,3}\.){3,3}[0-9]{1,3}$/)) {
push(@ERRORS,"$ip is not a valid ip address.\n");
last SWITCH1;
}
$IP{$node} = $ip;
while (<TBCMD>) {
chop;
@line = split;
$_ = $line[0];
SWITCH1: {
/^tb-set-ip$/ && do {
# tb-set-ip <node> <ip>
if ($#line != 2) {
push(@ERRORS,"Syntax: tb-set-ip node ip\n");
last SWITCH1;
};
/^set-ip-interface$/ && do {
# set-ip-interface <node> <dst> <ip>
if ($#line != 4) {
push(@ERRORS,"Syntax: set-ip-interface node dst ip\n");
last SWITCH1;
}
($node,$dst,$ip) = @line[2..4];
if (! defined($vnodemap{$node})) {
push(@ERRORS,"$node is not a valid node.\n");
last SWITCH1;
}
if (! defined($vnodemap{$dst})) {
push(@ERRORS,"$dst is not a valid node.\n");
last SWITCH1;
}
if (! ($ip =~ /^([0-9]{1,3}\.){3,3}[0-9]{1,3}$/)) {
push(@ERRORS,"$ip is not a valid ip address.\n");
last SWITCH1;
}
$IP{"$node:$dst"} = $ip;
}
($node,$ip) = @line[1..2];
if (!defined($vnodemap{$node})) {
push(@ERRORS,"$node is not a valid node.\n");
last SWITCH1;
}
# This actually matches a valid IP address
if (! ($ip =~ /^([0-9]{1,3}\.){3,3}[0-9]{1,3}$/)) {
push(@ERRORS,"$ip is not a valid ip address.\n");
last SWITCH1;
}
$IP{$node} = $ip;
last SWITCH1;
};
/^tb-set-ip-interface$/ && do {
# tb-set-ip-interface <node> <dst> <ip>
if ($#line != 3) {
push(@ERRORS,"Syntax: tb-set-ip-interface node dst ip\n");
last SWITCH1;
}
($node,$dst,$ip) = @line[1..3];
if (! defined($vnodemap{$node})) {
push(@ERRORS,"$node is not a valid node.\n");
last SWITCH1;
}
if (! defined($vnodemap{$dst})) {
push(@ERRORS,"$dst is not a valid node.\n");
last SWITCH1;
}
if (! ($ip =~ /^([0-9]{1,3}\.){3,3}[0-9]{1,3}$/)) {
push(@ERRORS,"$ip is not a valid ip address.\n");
last SWITCH1;
}
$IP{"$node:$dst"} = $ip;
last SWITCH1;
}
}
}
}
close(TBCMD);
# At this point we have most of the data we need. We now loop through all
# the virtual links (/topology/links) assigning them IP addresses. This is
......
......@@ -18,10 +18,10 @@ push(@INC, $IRLIB);
require libir;
if ($#ARGV != 1) {
print STDERR "Syntax: $0 ir_file ns_file\n";
print STDERR "Syntax: $0 ir_file tbcmdfile\n";
exit 1;
}
($irfile,$nsfile) = @ARGV;
($irfile,$tbcmdfile) = @ARGV;
use DBI;
......@@ -39,9 +39,9 @@ if ($@) {
exit(1);
}
# open the ns file
open(NSFILE,$nsfile) || do {
print STDERR "Could not open $nsfile.\n";
# open the tbcmd file
open(TBCMD,$tbcmdfile) || do {
print STDERR "Could not open $tbcmdfile.\n";
exit(1);
};
......@@ -105,30 +105,28 @@ foreach (split("\n",$raw)) {
}
}
}
# Now we parse the NS file
# Now we parse the tbcmd file
# %images is indexed by label and contains "$path $partition"
while (<NSFILE>) {
/^\#TB/ || next;
while (<TBCMD>) {
chop;
@line = split;
$_ = $line[1];
$_ = $line[0];
SWITCH: {
/^create-os$/ && do {
/^tb-create-os$/ && do {
# Should add some checking for partition
if ($#line != 4) {
push(@ERRORS,"Syntax: create-os label path partition");
if ($#line != 3) {
push(@ERRORS,"Syntax: tb-create-os label path partition");
} else {
($label,$path,$partition) = @line[2..4];
($label,$path,$partition) = @line[1..3];
$images{$label} = "$path $partition";
}
last SWITCH;
};
/^set-dnard-os$/ && do {
if ($#line != 4) {
push(@ERRORS,"Syntax: set-dnard-os shelf n os");
/^tb-set-dnard-os$/ && do {
if ($#line != 3) {
push(@ERRORS,"Syntax: tb-set-dnard-os shelf n os");
} else {
($shelf,$n,$label) = @line[2..4];
($shelf,$n,$label) = @line[1..3];
if (! defined($nodemap{$shelf})) {
push(@ERRORS,"Unknown node $shelf\n");
last SWITCH;
......@@ -164,11 +162,11 @@ while (<NSFILE>) {
}
last SWITCH;
};
/^set-node-os$/ && do {
if ($#line != 3) {
push(@ERRORS,"Syntax: set-node-os nodespec os");
/^tb-set-node-os$/ && do {
if ($#line != 2) {
push(@ERRORS,"Syntax: tb-set-node-os nodespec os");
} else {
($nodespec,$label) = @line[2..3];
($nodespec,$label) = @line[1..2];
# Do initial checking on label
# We also get the valid type for this image and store it
# in valid_type;
......@@ -208,16 +206,18 @@ while (<NSFILE>) {
last SWITCH;
};
/^set-dnard-deltas$/ && do {
/^tb-set-dnard-deltas$/ && do {
# PLACE HOLDER
last SWITCH;
};
/^set-node-deltas$/ && do {
/^tb-set-node-deltas$/ && do {
# PLACE HOLDER
last SWITCH;
};
}
}
close(TBCMD);
# Check if we're good so far
if ($#ERRORS != -1) {
......
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