Commit 1612756f authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Merge branch 'master' into snmpit-mle

parents b5dd2e02 9e0021d3
......@@ -23,10 +23,11 @@ use strict;
use Getopt::Std;
my %opt;
my $optlist = "ltL:evDnrs";
my $optlist = "ltL:evDnrRsa";
if (!getopts($optlist,\%opt)){
warn "Usage: $0 [-r] [-l] [-e] [-t] [-L limit] [-v] [-D] [-n] [-s]\n";
warn "Usage: $0 [-r] [-R] [-l] [-e] [-t] [-L limit] [-v] [-D] [-n] [-s]\n";
warn " -r Remove any files that fail the check\n";
warn " -R Rename any files that fail the check\n";
warn " -l List files that pass the check to stdout\n";
warn " -e Print parse errors from failed files to stderr\n";
warn " -t When finished, dump information about all types and\n";
......@@ -38,6 +39,7 @@ if (!getopts($optlist,\%opt)){
warn " private information\n";
warn " -s Strict checking - only pass files that would be parsed by\n";
warn " latest version of assign\n";
warn " -a Enable anonymization\n";
exit 1;
}
......@@ -68,6 +70,14 @@ my %top_linkflags = (
#
sub is_feature_okay($) {
my ($feature) = @_;
# If we are not anonymizing, all features are considered okay
if (!$opt{a}) {
return 1;
}
# If anyonymizing, don't let through OS features that expose the project
# name
if ($feature =~ /^OS-/) {
# OSes in the emulab-ops project are okay, as are ones that are just
# specified with a numeric ID
......@@ -160,7 +170,7 @@ sub check_node_type($) {
#
sub normalize_ptop($) {
my ($ptop) = @_;
my ($nodes, $links, $limits) = @$ptop;
my ($nodes, $links, $limits,$policies) = @$ptop;
foreach my $node (@$nodes) {
#print "Normalizing $node->{name}\n";
if (!$node->{types}) {
......@@ -209,12 +219,12 @@ sub normalize_ptop($) {
}
}
# Nothing to do for limits, for now
# Nothing to do for limits or policies, for now
}
sub write_normalized_ptop($$) {
my ($outfile, $ptop) = @_;
my ($nodes, $links, $limits) = @$ptop;
my ($nodes, $links, $limits, $policies) = @$ptop;
open (OF,">$outfile") or die "Unable to open $outfile for writing";
foreach my $node (@$nodes) {
......@@ -260,6 +270,10 @@ sub write_normalized_ptop($$) {
print OF "set-type-limit $type $count\n";
}
foreach my $policy (@$policies) {
print OF "policy " . join(" ",@$policy) . "\n";
}
close(OF);
}
......@@ -410,7 +424,7 @@ sub parse_ptop($) {
my %local_seen_link_types;
my %local_seen_fds;
my (@nodes, @links, @limits);
my (@nodes, @links, @limits, @policies);
my $line_no = 0;
while (my $line = <PT>) {
......@@ -541,6 +555,11 @@ sub parse_ptop($) {
my %limit = (type => $type, limit => $limit);
push @limits, \%limit;
} elsif ($line_type eq "policy") {
# For now, we are just going to pass the rest of the string
# along rather than parsing it carefully, since we don't support
# fancy policies in any ptop version yet
push @policies, [@tokens];
} else {
die "Unknown line type '$line_type' on $ptop line $line_no\n";
}
......@@ -558,7 +577,7 @@ sub parse_ptop($) {
close PT;
return [\@nodes, \@links, \@limits];
return [\@nodes, \@links, \@limits,\@policies];
}
sub parse_top($) {
......@@ -635,7 +654,14 @@ sub parse_top($) {
check_type("string",$link{dstiface});
$link{bw} = shift @tokens;
check_type("int",$link{bw});
#
# The bandwidth should be either the string '*' (which means
# 'native speed') or an int
#
if ($link{bw} ne "*") {
check_type("int",$link{bw});
}
# This is a bit tricky - figure out if there are delay and
# loss present on the line
......@@ -745,22 +771,9 @@ chomp @dirs;
my $processed_files = 0;
my $passed_files = 0;
foreach my $dir (@dirs) {
#my @ptopfiles = `ls -1 $dir/\*.ptop`;
#my @ptopfiles = ();
#my @topfiles = `ls -1 $dir/\*.top`;
my @topfiles;
my @ptopfiles;
opendir DIR, "$dir" or die "Unable to open $dir: $!\n";
while (my $file = readdir DIR) {
if ($file =~ /\.ptop$/) {
push @ptopfiles, "$dir/$file";
}
if ($file =~ /\.top$/) {
push @topfiles, "$dir/$file";
}
}
my @topfiles = `find $dir/ -name \*.vtop`;
my @ptopfiles = `find $dir/ -name \*.ptop`;
chomp @ptopfiles;
chomp @topfiles;
......@@ -770,19 +783,26 @@ foreach my $dir (@dirs) {
}
$processed_files++;
my $ptop_data = eval { parse_ptop($ptop); };
#if (eval { parse_ptop($ptop); }) {
if (!$@) {
$passed_files++;
if ($opt{l}) {
print "$ptop\n";
}
if ($opt{n}) {
# Grab timestamps so that we can preserve them
my ($atime, $mtime) = (stat($ptop))[8,9];
normalize_ptop($ptop_data);
write_normalized_ptop($ptop,$ptop_data);
# Restore timestamp
utime $atime, $mtime, $ptop;
}
} else {
if ($opt{r}) {
system "rm $ptop";
} elsif ($opt{R}) {
system "mv $ptop $ptop.failed";
}
if ($opt{e}) {
print "*** FAILED: $ptop: $@\n";
......@@ -799,22 +819,28 @@ foreach my $dir (@dirs) {
if ($opt{D}) {
print "Checking top file $top\n";
}
#parse_top($top);
$processed_files++;
my $top_data = eval { parse_top($top); };
#if (eval { parse_top($top); }) {
if (!$@) {
$passed_files++;
if ($opt{l}) {
print "$top\n";
}
if ($opt{n}) {
# Grab timestamps so that we can preserve them
my ($atime, $mtime) = (stat($top))[8,9];
normalize_top($top_data);
write_normalized_top($top,$top_data);
# Restore timestamp
utime $atime, $mtime, $top;
}
} else {
if ($opt{r}) {
system "rm $top";
} elsif ($opt{R}) {
system "mv $top $top.failed";
}
if ($opt{e}) {
print "*** FAILED: $top: $@\n";
......
......@@ -59,7 +59,7 @@ sub LookupAll($$$)
my $query_result =
DBQueryWarn("select * from interfaces ".
"where node_id='$nodeid'");
"where node_id='$nodeid' and logical=0");
return -1
if (!$query_result);
......
......@@ -588,7 +588,8 @@ sub LookupByWireType($$)
my @ports = ();
my $result = DBQueryFatal("SELECT node_id1, card1, port1, " .
"node_id2, card2, port2 FROM wires WHERE type='$wt'");
"node_id2, card2, port2 FROM wires ".
"WHERE type='$wt' and logical=0");
if ($result) {
while (my @row = $result->fetchrow()) {
......@@ -875,7 +876,13 @@ sub getOtherEndIfaceString($) {
# get the other side of a port instance, according to 'wires' DB table
#
sub getOtherEndPort($) {
return Port->LookupByTriple($_[0]->getOtherEndTripleString());
my $self = $_[0];
my $pt = Port->LookupByTriple($self->getOtherEndTripleString());
if (defined($pt)) {
return $pt;
} else {
return $self;
}
}
#
......
......@@ -1777,6 +1777,7 @@ CREATE TABLE `interfaces` (
`whol` tinyint(4) NOT NULL default '0',
`trunk` tinyint(1) NOT NULL default '0',
`uuid` varchar(40) NOT NULL default '',
`logical` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`node_id`,`card`,`port`),
KEY `mac` (`mac`),
KEY `IP` (`IP`),
......@@ -4728,13 +4729,14 @@ DROP TABLE IF EXISTS `wires`;
CREATE TABLE `wires` (
`cable` smallint(3) unsigned default NULL,
`len` tinyint(3) unsigned NOT NULL default '0',
`type` enum('Node','Serial','Power','Dnard','Control','Trunk','OuterControl') NOT NULL default 'Node',
`type` enum('Node','Serial','Power','Dnard','Control','Trunk','OuterControl','Unused') NOT NULL default 'Node',
`node_id1` char(32) NOT NULL default '',
`card1` tinyint(3) unsigned NOT NULL default '0',
`port1` tinyint(3) unsigned NOT NULL default '0',
`node_id2` char(32) NOT NULL default '',
`card2` tinyint(3) unsigned NOT NULL default '0',
`port2` tinyint(3) unsigned NOT NULL default '0',
`logical` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`node_id1`,`card1`,`port1`),
KEY `node_id2` (`node_id2`,`card2`),
KEY `dest` (`node_id2`,`card2`,`port2`),
......
#
# Add "logical" wire support, used for layer one switch support.
#
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
my $slottype = DBSlotType("wires", "type");
if (!$slottype) {
Fatal("No 'type' slot in 'wires' table");
}
if (! ($slottype =~ /Unused/)) {
DBQueryFatal("alter table wires change `type` `type` ".
" enum('Node','Serial','Power','Dnard','Control',".
" 'Trunk','OuterControl','Unused') ".
" NOT NULL default 'Node'");
}
if (!DBSlotExists("wires", "logical")) {
DBQueryFatal("alter table wires add `logical` ".
" tinyint(1) unsigned NOT NULL default '0'");
}
if (!DBSlotExists("interfaces", "logical")) {
DBQueryFatal("alter table interfaces add `logical` ".
" tinyint(1) unsigned NOT NULL default '0'");
}
return 0;
}
1;
......@@ -31,6 +31,7 @@ use lib '@prefix@/lib';
use libdb;
use snmpit_lib;
use libtblog;
use Port;
use English;
use Getopt::Long;
......@@ -207,7 +208,7 @@ my @ports;
if ($opt{s}) {
foreach my $port (@passedPorts) {
if ($port =~ /^[^.]+\.\d+\/\d+$/) {
push @ports, $port;
push @ports, convertPortFromString($port);
} else {
print "'$port' not in correct switch.port syntax, ignoring\n";
}
......@@ -227,12 +228,12 @@ elsif ($opt{p}) {
$port =~ /^([^:]+)(:(\d+))?$/;
my ($hostname,$portnumber) = ($1,$3);
if (defined $portnumber) {
push @ports, $port;
push @ports, convertPortFromString($port);
} else {
my $interfaces = DBQueryFatal("select card from interfaces " .
my $interfaces = DBQueryFatal("select card, port from interfaces " .
"where node_id = '$hostname'");
while (my ($card) = $interfaces->fetchrow()) {
push @ports, "$port:$card";
while (my ($card, $iport) = $interfaces->fetchrow()) {
push @ports, convertPortFromString("$port:$card.$iport");
}
}
}
......@@ -262,10 +263,10 @@ elsif ($opt{p}) {
if (defined($portnumber)) {
# They gave us a specific interface
push @ports, "$nodeid:$portnumber";
push @ports, convertPortFromString("$nodeid:$portnumber");
} else {
# We need to find all experimental ports for this node
push @ports, grep(/^$nodeid:(\d+)$/,@experimentPorts);
push @ports, grep(($nodeid eq $_->node_id()),@experimentPorts);
}
}
......@@ -335,18 +336,15 @@ DEVICE: foreach my $name (keys %portMap) {
#
# Figure out which port on which switch this corresponds to
#
my $switchport;
if ($opt{s}) {
if ($port =~ /^([^.]+)\.(\d+)\/(\d+)$/) {
$switchport = "$1:$2.$3";
}
} else {
$switchport = portnum($port);
}
if (!($switchport && ($switchport =~ /(.+):(\d+)\.(\d+)/))) {
warn "WARNING: No switch port found for $port\n";
my $switchport = $port->getSwitchPort()?
$port->getSwitchPort():undef;
if (!$switchport) {
warn "WARNING: No switch port found for ".$port->toString()."\n";
} else {
my ($switch_id,$switch_card,$switch_port) = ($1, $2, $3);
my ($switch_id,$switch_card,$switch_port) =
($switchport->node_id(), $switchport->card(),
$switchport->port());
my $dbresult = DBQueryFatal("select * from port_counters where ".
"node_id='$switch_id' and card=$switch_card and ".
"port=$switch_port");
......@@ -430,11 +428,10 @@ DEVICE: foreach my $name (keys %portMap) {
#
# Try to translate the port name to the node's vname
#
$port =~ /^(.+):(\d+)/;
if ($1) {
my $portnum = $2;
if ($port->node_id() && $port->card()) {
my $portnum = $port->card();
my ($junk, $vname);
NodeidToExp($1,\$junk,\$junk,\$vname);
NodeidToExp($port->node_id(),\$junk,\$junk,\$vname);
$port = "$vname:$portnum";
}
}
......@@ -442,7 +439,7 @@ DEVICE: foreach my $name (keys %portMap) {
#
# Throw this onto a list, so that we can sort it
#
push @stats, [$port,@$result];
push @stats, [Port->isPort($port)?$port->toString():$port,@$result];
}
}
......
......@@ -250,8 +250,8 @@ my %interfaceips = ();
# Read interfaces
my $result =
DBQueryFatal("SELECT node_id,card,port,iface,interface_type,role,IP" .
" from interfaces " .
($genimode ne $NO_GENI ? "where role!='gw'" : ""));
" from interfaces where logical=0 " .
($genimode ne $NO_GENI ? "and role!='gw'" : ""));
while (($node,$card,$port,$iface,$type,$role,$ip) = $result->fetchrow_array) {
push @{ $nodetointerface{"$node"} }, $iface;
......@@ -719,7 +719,7 @@ while (($node,$type,$physnode,$class,$issubnode,$def_boot_osid,$reserved,
# features
#
$result = DBQueryFatal("SELECT DISTINCT node_id1, node_id2 " .
" FROM wires");
" FROM wires where logical=0");
my %connections = ();
while (my ($node_id1, $node_id2) = $result->fetchrow()) {
foreach my $nodes ([$node_id1, $node_id2], [$node_id2, $node_id1]) {
......@@ -1276,7 +1276,8 @@ while (($type,$capkey,$capval) = $result->fetchrow_array) {
# Read interface switches
$result = DBQueryFatal("SELECT node_id1, iface, node_id2 FROM wires AS w " .
"LEFT JOIN interfaces as i ON w.node_id1=i.node_id AND w.card1=i.card");
"LEFT JOIN interfaces as i ON w.node_id1=i.node_id AND w.card1=i.card ".
"where w.logical=0");
while (($node,$iface,$switch) = $result->fetchrow_array) {
if ($node && $iface) {
......@@ -1286,7 +1287,7 @@ while (($node,$iface,$switch) = $result->fetchrow_array) {
# Read interface cards and ports
$result = DBQueryFatal("SELECT node_id, iface, card, port, IP ".
"FROM interfaces");
"FROM interfaces where logical=0");
while (($node,$iface,$card,$port,$IP) = $result->fetchrow_array) {
next
......@@ -1344,7 +1345,8 @@ if (defined($experiment)) {
}
$result = DBQueryFatal("SELECT node_id1,card1,port1,node_id2,card2,port2" .
" from wires where type=\"Node\" or type=\"Trunk\"");
" from wires where logical=0 and ".
" (type=\"Node\" or type=\"Trunk\")");
while (($node1,$card1,$port1,$node2,$card2,$port2) =
$result->fetchrow_array) {
if ((defined($nodes{$node1}) || defined($switches{$node1})) &&
......
......@@ -405,7 +405,7 @@ sub convertPortFormat($$@) {
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting ifindex to nodeport\n",2);
return map $_->getPCPort()->toTripleString(), @pos;
return map $_->getOtherEndPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
......@@ -419,7 +419,7 @@ sub convertPortFormat($$@) {
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting modport to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @pos;
return map $_->getOtherEndPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
......@@ -452,7 +452,7 @@ sub convertPortFormat($$@) {
)[1] } @ports;
} elsif ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting port to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @ports;
return map $_->getOtherEndPort()->toTripleString(), @ports;
}
}
......@@ -1656,7 +1656,7 @@ sub walkTableIfIndex($$$;$) {
my $po = convertPortFromString("$self->{NAME}:$index")
|| convertPortFromString("$self->{NAME}:".$self->{IFINDEX}{$index});
if (! defined $po) { next; } # Skip if we don't know about it
my $port = $po->getPCPort()->toTripleString();
my $port = $po->getOtherEndPort()->toTripleString();
#
# Apply the user's processing function
......
......@@ -18,6 +18,7 @@ $| = 1; # Turn off line buffering on output
use English;
use SNMP;
use snmpit_lib;
use Port;
#
# These are the commands that can be passed to the portControl function
......@@ -50,6 +51,7 @@ my %cmdOIDs =
my $PORT_FORMAT_IFINDEX = 1;
my $PORT_FORMAT_MODPORT = 2;
my $PORT_FORMAT_NODEPORT = 3;
my $PORT_FORMAT_PORT = 4;
#
# Creates a new object.
......@@ -272,6 +274,7 @@ sub convertPortFormat($$@) {
my $input;
SWITCH: for ($sample) {
(Port->isPort($sample)) && do { $input = $PORT_FORMAT_PORT; last; };
(/^\d+$/) && do { $input = $PORT_FORMAT_IFINDEX; last; };
(/^\d+\.\d+$/) && do { $input = $PORT_FORMAT_MODPORT; last; };
(/^$self->{NAME}\.\d+\/\d+$/) && do { $input = $PORT_FORMAT_MODPORT;
......@@ -288,29 +291,68 @@ sub convertPortFormat($$@) {
}
if ($input == $PORT_FORMAT_IFINDEX) {
my @mps = map $self->{IFINDEX}{$_}, @ports;
if ($output == $PORT_FORMAT_MODPORT) {
$self->debug("Converting ifindex to modport\n",2);
return map $self->{IFINDEX}{$_}, @ports;
} elsif ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting ifindex to nodeport\n",2);
return map portnum($self->{NAME}.":".$self->{IFINDEX}{$_}), @ports;
$self->debug("Converting ifindex to modport\n",3);
return @mps;
}
my @pos = map Port->LookupByStringForced($self->{NAME}.":".$_), @mps;
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting ifindex to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
} elsif ($input == $PORT_FORMAT_MODPORT) {
if ($output == $PORT_FORMAT_IFINDEX) {
$self->debug("Converting modport to ifindex\n",2);
$self->debug("Converting modport to ifindex\n",3);
return map $self->{IFINDEX}{$_}, @ports;
} elsif ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting modport to nodeport\n",2);
return map portnum($self->{NAME} . ":$_"), @ports;
}
my @pos = map Port->LookupByStringForced($self->{NAME}.":".$_), @ports;
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting modport to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
} elsif ($input == $PORT_FORMAT_NODEPORT) {
my @pos = map Port->LookupByStringForced($_)->getSwitchPort(), @ports;
if ($output == $PORT_FORMAT_IFINDEX) {
$self->debug("Converting nodeport to ifindex\n",2);
return map $self->{IFINDEX}{(split /:/,portnum($_))[1]}, @ports;
$self->debug("Converting nodeport to ifindex\n",3);
return map $self->{IFINDEX}{(split /:/, $_->toTripleString())[1]}, @pos;
} elsif ($output == $PORT_FORMAT_MODPORT) {
$self->debug("Converting nodeport to modport\n",2);
return map { (split /:/,portnum($_))[1] } @ports;
}
$self->debug("Converting nodeport to modport\n",3);
return map { (split /:/, $_->toTripleString())[1] } @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
} elsif ($input == $PORT_FORMAT_PORT) {
if ($output == $PORT_FORMAT_IFINDEX) {
$self->debug("Converting port to ifindex\n",3);
return map $self->{IFINDEX}{(split /:/,
($_->node_id() eq $self->{NAME})?
$_->toTripleString():
$_->getOtherEndTripleString()
)[1]}, @ports;
} elsif ($output == $PORT_FORMAT_MODPORT) {
$self->debug("Converting port to modport\n",3);
return map { (split /:/,
($_->node_id() eq $self->{NAME})?
$_->toTripleString():
$_->getOtherEndTripleString()
)[1] } @ports;
} elsif ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting port to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @ports;
}
}
#
......@@ -501,7 +543,7 @@ sub setPortVlan($$@) {
#
my @portlist = $self->convertPortFormat($PORT_FORMAT_IFINDEX, @ports);
$self->debug("foundry::setPortVLan ports: " . join(",",@ports) . "\n");
$self->debug("foundry::setPortVLan ports: " . Port->toStrings(@ports) . "\n");
$self->debug("as ifIndexes: " . join(",",@portlist) . "\n");
foreach my $port (@portlist) {
......@@ -542,7 +584,7 @@ sub setPortVlan($$@) {
# We need to make sure the ports get enabled.
#
$self->debug("Enabling " . join(',',@ports) . "...\n");
$self->debug("Enabling " . Port->toStrings(@ports) . "...\n");
if ( my $rv = $self->portControl("enable",@ports) ) {
print STDERR "Port enable had $rv failures.\n";
$errors += $rv;
......@@ -662,7 +704,7 @@ sub removeSomePortsFromVlan($$@) {
my ($self, $vlan_number, @ports) = @_;
my ($errors, $id, %hports) = (0,$self->{NAME}."::removeSomePortsFromVlan");
$self->debug("$id $vlan_number @ports\n");
$self->debug("$id $vlan_number ".Port->toStrings(@ports)."\n");
@ports = $self->convertPortFormat($PORT_FORMAT_IFINDEX,@ports);
@hports{@ports} = @ports;
......
......@@ -493,7 +493,7 @@ sub convertPortFormat($$@) {
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting ifindex to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @pos;
return map $_->getOtherEndPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
......@@ -507,7 +507,7 @@ sub convertPortFormat($$@) {
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting modport to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @pos;
return map $_->getOtherEndPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;