tbreport.in 2.2 KB
Newer Older
1
2
3
4
5
#!/usr/bin/perl -w

# tbreport
# This just provides the necessary information from the IR file.

6
7
my $TBROOT = "@prefix@";
my $DBNAME = "tbdb";
8
9
10
11

push(@INC,"$TBROOT/lib/ir");
require libir;

12
13
14
15
16
use DBI;
$dbh = DBI->connect("DBI:mysql:database=$DBNAME;host=localhost") 
    || die "Could not connect to DB.\n";


17
18
19
20
21
22
23
24
25
26
27
28
29
if ($#ARGV == 3) {
    ($v,$pid,$eid,$irfile) = @ARGV;
    if ($v ne "-v") {
	print STDERR "Syntax: $0 [-v] pid eid irfile\n";
	exit(1);
    }
} elsif ($#ARGV == 2) {
    ($pid,$eid,$irfile) = @ARGV;
} else {
    print STDERR "Syntax: $0 [-v] pid eid irfile\n";
    exit(1);
}

30
31


32
33
34
35
36
37
38
39
40
41
42
43
44
eval {&ir_read($irfile)};
if ($@) {
    print STDERR "Could not read $irfile: $@\n";
    exit(1);
}

# Display node map
$raw = eval {&ir_get("/virtual/nodes")};
if ($@) {
    print STDERR "Could not read /virtual/nodes from IR file!\n";
    exit(1);
}
print "Node Mapping:\n";
45
46
printf "%-15s %-15s %s\n", "Virtual", "Physical", "Qualified Name";
print "--------------- --------------- --------------------\n";
47
48
foreach (split("\n",$raw)) {
    ($v,$p) = split;
49
    printf "%-15s %-15s %s\n", $v, $p, "$v.$eid.$pid.emulab.net";
50
51
52
53
54
55
56
57
58
59
60
61
62
}

# Display IP addresses
#  $raw = eval {&ir_get("/topology/lans")};
#  if ($@) {
#      print STDERR "Could not read /topology/lans from IR file!\n";
#      exit(1);
#  }
#  foreach (split("\n",$raw)) {
#      @info = split;
#      $lan = @info[0];
#      $lans{$lan} = 1;
#  }
63
64
65
66
67
68
69
70
71
72
$raw = eval {&ir_get("/ip/mac")};
if ($@) {
    print STDERR "Could not read /ip/mac from IR file!\n";
    exit(1);
}
foreach (split("\n",$raw)) {
    ($mac,$ip) = split;
    $ipmac{$ip} = $mac;
}

73
74
75
76
77
78
79
$raw = eval {&ir_get("/ip/map")};
if ($@) {
    print STDERR "Could not read /ip/map from IR file!\n";
    exit(1);
}
print "\n";
print "IP Addresses:\n";
80
81
printf "%-15s %-5s %-20s %-20s\n", "Node", "IFC", "Destination", "IP";
print "--------------- -------------------- --------------------\n";
82
83
foreach (split("\n",$raw)) {
    ($src,$dst,$ip) = split;
84
85
86
87
88
89
90
91
92
93
    if (defined($ipmac{$ip})) {
	$mac = $ipmac{$ip};
	$sth = $dbh->prepare("SELECT card FROM interfaces WHERE mac = \"$mac\"");
	if ($sth->execute != 0) {
	    ($ifc) = $sth->fetchrow_array;
	}
	$sth->finish;
    } else {
	$ifc = "?";
    }
94
    printf "%-15s eth%-2s %-20s %-20s\n", $src, $ifc, $dst, $ip;
95
96
97
98
}

0;