db2ns.in 2.63 KB
Newer Older
1
#!/usr/bin/perl -w
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
use English;
3 4 5 6 7 8 9 10

# This is a very simple program that convers the virt_* tables in the DB
# into a NS file.  Not the original NS file, but a NS file that, if parsed
# will create identical virt_* entries.  Well, almost identical.  The virtual
# ports get changed.

use lib "@prefix@/lib";
use exitonwarn;
11
use libdb;
12 13 14 15 16 17 18

if ($#ARGV != 1) {
    print STDERR "Syntax: $0 pid eid\n";
    exit(1);
}
($pid,$eid) = @ARGV;

19
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
20
# Make sure the experiment exists
21
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
22 23
if (!ExpState($pid,$eid)) {
    die "There is no experiment $eid in project $pid\n";
24 25 26
}

#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
27
# Make sure they have access to the experiment
28
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
29 30 31
if (!TBAdmin($UID) &&
    !TBExptAccessCheck($UID, $pid, $eid, TB_EXPT_READINFO)) {
    die("*** You do not have permission to access this experiment!\n");
32 33
}

34 35 36
print "source tb_compat.tcl\n";
print "set ns [new Simulator]\n";

37
my $result = DBQueryFatal("select ips,osid,cmd_line,rpms,deltas,startupcmd," .
38 39
		     "tarfiles,vname,type,failureaction " .
		     "from virt_nodes where pid=\"$pid\" and eid=\"$eid\"");
40

41
while (($ips,$osid,$cmdline,$rpms,$deltas,$startupcmd,
42
	$tarfiles,$vname,$type,$failureaction) = $result->fetchrow_array) {
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    print "set $vname [\$ns node]\n";
    foreach $ippair (split(" ",$ips)) {
	($port,$ip) = split(":",$ippair);
	$ips{"$vname:$port"} = $ip;
    }
    print "tb-set-node-os $vname $osid\n";
    print "tb-set-hardware $vname $type\n";
    print "tb-set-node-cmdline $vname \"$cmdline\"\n";
    if ($rpms ne "") {
	print "tb-set-node-rpms $vname $rpms\n";
    }
    if ($deltas ne "") {
	print "tb-set-node-deltas $vname $deltas\n";
    }
    print "tb-set-node-startup $vname \"$startupcmd\"\n";
    if ($tarfiles ne "") {
	print "tb-set-node-tarfiles $vname $tarfiles\n";
    }
    print "tb-set-node-failure-action $vname $failureaction\n";
}
63
$result->finish;
64

65
$result = DBQueryFatal("select vname,delay,bandwidth,lossrate,member" .
66 67
		     " from virt_lans where pid=\"$pid\" and eid=\"$eid\"");
%lans = ();
68
while (($vname,$delay,$bw,$loss,$member) = $result->fetchrow_array) {
69 70 71 72 73
    if (!defined($lans{$vname})) {
	$lans{$vname} = [];
    } 
    push(@{$lans{$vname}},[$member,$delay,$bw,$loss]);
}
74
$result->finish;
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
foreach $lan (keys(%lans)) {
    $raw = "";
    foreach $member (@{$lans{$lan}}) {
	@info = @$member;
	$nodeport = $info[0];
	$node = (split(":",$nodeport))[0];
	$raw .= "$node ";
    }
    print "set $lan [\$ns make-lan \"$raw\" 100Mb 0ms]\n";
    foreach $member (@{$lans{$lan}}) {
	($nodeport,$delay,$bw,$loss) = @$member;
	($node,$port) = split(":",$nodeport);
	print "tb-set-ip-lan $node $lan " . $ips{$nodeport} . "\n";
	print "tb-set-node-lan-params $node $lan $delay $bw $loss\n";
    }
}

print "\$ns run\n";
93
exit(0);