db2ns.in 2.74 KB
Newer Older
1
#!/usr/bin/perl -w
Leigh Stoller's avatar
Leigh Stoller committed
2 3 4 5 6 7 8

#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#

Leigh Stoller's avatar
Leigh Stoller committed
9
use English;
10 11 12 13 14 15 16 17

# 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;
18
use libdb;
19 20 21 22 23 24 25

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

26
#
Leigh Stoller's avatar
Leigh Stoller committed
27
# Make sure the experiment exists
28
#
Leigh Stoller's avatar
Leigh Stoller committed
29 30
if (!ExpState($pid,$eid)) {
    die "There is no experiment $eid in project $pid\n";
31 32 33
}

#
Leigh Stoller's avatar
Leigh Stoller committed
34
# Make sure they have access to the experiment
35
#
Leigh Stoller's avatar
Leigh Stoller committed
36 37 38
if (!TBAdmin($UID) &&
    !TBExptAccessCheck($UID, $pid, $eid, TB_EXPT_READINFO)) {
    die("*** You do not have permission to access this experiment!\n");
39 40
}

41 42 43
print "source tb_compat.tcl\n";
print "set ns [new Simulator]\n";

44
my $result = DBQueryFatal("select ips,osid,cmd_line,rpms,deltas,startupcmd," .
45 46
		     "tarfiles,vname,type,failureaction " .
		     "from virt_nodes where pid=\"$pid\" and eid=\"$eid\"");
47

48
while (($ips,$osid,$cmdline,$rpms,$deltas,$startupcmd,
49
	$tarfiles,$vname,$type,$failureaction) = $result->fetchrow_array) {
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    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";
}
70
$result->finish;
71

72
$result = DBQueryFatal("select vname,delay,bandwidth,lossrate,member" .
73 74
		     " from virt_lans where pid=\"$pid\" and eid=\"$eid\"");
%lans = ();
75
while (($vname,$delay,$bw,$loss,$member) = $result->fetchrow_array) {
76 77 78 79 80
    if (!defined($lans{$vname})) {
	$lans{$vname} = [];
    } 
    push(@{$lans{$vname}},[$member,$delay,$bw,$loss]);
}
81
$result->finish;
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
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";
100
exit(0);