Commit 2cf4331e authored by Christopher Alfeld's avatar Christopher Alfeld

Added db2ns, a program that resides in sbin. db2ns takes a pid and eid

and produces a ns file that will produce an identical topology to the one
stored in the DB.  It does not keep virtual ports the same but does map IP
addresses to connections correctly.  I.e. the topology is the same even
though the virt_nodes table differ slightly.
parent 36d7d0ca
......@@ -1039,7 +1039,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/startexp tbsetup/endexp tbsetup/webstartexp tbsetup/webendexp \
tbsetup/snmpit tbsetup/ns2ir/GNUmakefile \
tbsetup/ns2ir/parse.tcl tbsetup/ns2ir/tb_compat.tcl \
tbsetup/ns2ir/sim.tcl tbsetup/savevlans \
tbsetup/ns2ir/sim.tcl tbsetup/savevlans tbsetup/db2ns \
tbsetup/tbprerun tbsetup/tbswapin tbsetup/tbswapout tbsetup/tbend \
tbsetup/tbreport tbsetup/named_setup tbsetup/exports_setup \
tbsetup/checkpass/GNUmakefile tbsetup/assign_wrapper tbsetup/ptopgen \
......
......@@ -161,7 +161,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/startexp tbsetup/endexp tbsetup/webstartexp tbsetup/webendexp \
tbsetup/snmpit tbsetup/ns2ir/GNUmakefile \
tbsetup/ns2ir/parse.tcl tbsetup/ns2ir/tb_compat.tcl \
tbsetup/ns2ir/sim.tcl tbsetup/savevlans \
tbsetup/ns2ir/sim.tcl tbsetup/savevlans tbsetup/db2ns \
tbsetup/tbprerun tbsetup/tbswapin tbsetup/tbswapout tbsetup/tbend \
tbsetup/tbreport tbsetup/named_setup tbsetup/exports_setup \
tbsetup/checkpass/GNUmakefile tbsetup/assign_wrapper tbsetup/ptopgen \
......
......@@ -19,7 +19,7 @@ USERBINS = os_load node_reboot nscheck
SBIN_STUFF = resetvlans console_setup.proxy sched_reload named_setup \
batch_daemon exports_setup reload_daemon sched_reserve \
console_reset
console_reset db2ns
LIBEXEC_STUFF = mkprojdir rmproj mkacct-ctrl rmacct-ctrl \
os_setup mkexpdir console_setup webnscheck \
......
#!/usr/bin/perl -w
# 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 DBI;
use lib "@prefix@/lib";
use exitonwarn;
$TBDB = "@TBDBNAME@";
$dbh = DBI->connect("DBI:mysql:database=$TBDB;host=localhost") ||
die "Could not connect to DB.\n";
if ($#ARGV != 1) {
print STDERR "Syntax: $0 pid eid\n";
exit(1);
}
($pid,$eid) = @ARGV;
print "source tb_compat.tcl\n";
print "set ns [new Simulator]\n";
$sth = $dbh->prepare("select ips,osid,cmd_line,rpms,deltas,startupcmd," .
"tarfiles,vname,type,failureaction " .
"from virt_nodes where pid=\"$pid\" and eid=\"$eid\"");
$sth->execute;
while (($ips,$osid,$cmdline,$rpms,$deltas,$startupcmd,
$tarfiles,$vname,$type,$failureaction) = $sth->fetchrow_array) {
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";
}
$sth->finish;
$sth = $dbh->prepare("select vname,delay,bandwidth,lossrate,member" .
" from virt_lans where pid=\"$pid\" and eid=\"$eid\"");
$sth->execute;
%lans = ();
while (($vname,$delay,$bw,$loss,$member) = $sth->fetchrow_array) {
if (!defined($lans{$vname})) {
$lans{$vname} = [];
}
push(@{$lans{$vname}},[$member,$delay,$bw,$loss]);
}
$sth->finish;
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";
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