Commit 8f0551fc authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Revert all these files to hash 45dfbbcd

Sorry, not the git way, but the git way is baffling, considering I
wanted to undo all of the merges from my portmerge branch, and apply
them on a branch.
parent 2466a91d
......@@ -31,7 +31,6 @@ use lib '@prefix@/lib';
use libdb;
use snmpit_lib;
use libtblog;
use Port;
use English;
use Getopt::Long;
......@@ -208,7 +207,7 @@ my @ports;
if ($opt{s}) {
foreach my $port (@passedPorts) {
if ($port =~ /^[^.]+\.\d+\/\d+$/) {
push @ports, convertPortFromString($port);
push @ports, $port;
} else {
print "'$port' not in correct switch.port syntax, ignoring\n";
}
......@@ -228,12 +227,12 @@ elsif ($opt{p}) {
$port =~ /^([^:]+)(:(\d+))?$/;
my ($hostname,$portnumber) = ($1,$3);
if (defined $portnumber) {
push @ports, convertPortFromString($port);
push @ports, $port;
} else {
my $interfaces = DBQueryFatal("select card, port from interfaces " .
my $interfaces = DBQueryFatal("select card from interfaces " .
"where node_id = '$hostname'");
while (my ($card, $iport) = $interfaces->fetchrow()) {
push @ports, convertPortFromString("$port:$card.$iport");
while (my ($card) = $interfaces->fetchrow()) {
push @ports, "$port:$card";
}
}
}
......@@ -263,10 +262,10 @@ elsif ($opt{p}) {
if (defined($portnumber)) {
# They gave us a specific interface
push @ports, convertPortFromString("$nodeid:$portnumber");
push @ports, "$nodeid:$portnumber";
} else {
# We need to find all experimental ports for this node
push @ports, grep(($nodeid eq $_->node_id()),@experimentPorts);
push @ports, grep(/^$nodeid:(\d+)$/,@experimentPorts);
}
}
......@@ -336,15 +335,18 @@ DEVICE: foreach my $name (keys %portMap) {
#
# Figure out which port on which switch this corresponds to
#
my $switchport = $port->getSwitchPort()?
$port->getSwitchPort():undef;
if (!$switchport) {
warn "WARNING: No switch port found for ".$port->toString()."\n";
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";
} else {
my ($switch_id,$switch_card,$switch_port) =
($switchport->node_id(), $switchport->card(),
$switchport->port());
my ($switch_id,$switch_card,$switch_port) = ($1, $2, $3);
my $dbresult = DBQueryFatal("select * from port_counters where ".
"node_id='$switch_id' and card=$switch_card and ".
"port=$switch_port");
......@@ -428,10 +430,11 @@ DEVICE: foreach my $name (keys %portMap) {
#
# Try to translate the port name to the node's vname
#
if ($port->node_id() && $port->card()) {
my $portnum = $port->card();
$port =~ /^(.+):(\d+)/;
if ($1) {
my $portnum = $2;
my ($junk, $vname);
NodeidToExp($port->node_id(),\$junk,\$junk,\$vname);
NodeidToExp($1,\$junk,\$junk,\$vname);
$port = "$vname:$portnum";
}
}
......@@ -439,7 +442,7 @@ DEVICE: foreach my $name (keys %portMap) {
#
# Throw this onto a list, so that we can sort it
#
push @stats, [Port->isPort($port)?$port->toString():$port,@$result];
push @stats, [$port,@$result];
}
}
......
......@@ -19,7 +19,6 @@ my $ELABINELAB = @ELABINELAB@;
my $NOSTACKMIB = @NOSTACKMIB@;
my $MAINSITE = @TBMAINSITE@;
my $TB = '@prefix@';
my $SWITCH_NODE_STACK = "Switch-Node";
use libdb;
use User;
......@@ -650,8 +649,6 @@ if ($TESTMODE) {
snmpit_lib::init($debug);
my $exitval = 0;
my @pathlinksbyl1 = ();
COMMAND: foreach my $command (@commands) {
#
......@@ -736,18 +733,6 @@ COMMAND: foreach my $command (@commands) {
next COMMAND;
}
} else {
for (my $idx = 0; $idx < scalar(@vlans); $idx++)
{
my %ifaces = ();
if (getPathVlanIfaces($vlans[$idx], \%ifaces) != -1) {
map { print "$_=>$ifaces{$_} " } keys %ifaces;
push @pathlinksbyl1, $vlans[$idx];
print "path: $vlans[$idx] \n";
}
}
@vlans = arraySub(\@vlans, \@pathlinksbyl1);
@devicenames =
getSwitchesInStacks(getPlannedStacksForVlans(@vlans));
debug("Tables: list from database: " . join(",",@devicenames) .
......@@ -1609,10 +1594,8 @@ sub doVlansFromTables($$@) {
my $vlan_number;
if (@$stacks > 1) {
if (!(@$stacks == 2 && @pathlinksbyl1 > 0)) {
die "VLAN creation accross multiple stacks is not yet supported\n" .
"Stacks are " . join(", ",map {$_->{STACKID}} @$stacks) . "\n";
}
die "VLAN creation accross multiple stacks is not yet supported\n" .
"Stacks are " . join(", ",map {$_->{STACKID}} @$stacks) . "\n";
}
#
......@@ -1760,17 +1743,6 @@ sub doVlansFromTables($$@) {
$vlan->Refresh();
}
}
foreach my $vlanid (@pathlinksbyl1) {
my @ports = ();
my %ifaces = ();
if (getPathVlanIfaces($vlanid, \%ifaces) != -1) {
my @ifs = keys %ifaces;
@ports = map { ifacemodport{$_} } @ifs;
$errors += CreateOneVlan($stacks, $vlanid, @ports);
}
}
return $errors;
}
......@@ -1820,7 +1792,7 @@ sub CreateOneVlan($$$@)
# Set the speed and duplex of each interface depending on the
# value in the database
#
if ((!$NOSTACKMIB) && !($stack->{STACKID} eq $SWITCH_NODE_STACK)) {
if (!$NOSTACKMIB) {
foreach my $port (@ports) {
my ($speed,$duplex) = getInterfaceSettings($port);
#
......
......@@ -23,7 +23,6 @@ use libdb;
use libtestbed;
use Expect;
use Lan;
use Port;
# CLI constants
......@@ -184,7 +183,7 @@ sub new($$$;$) {
#
$self->{SESS} = undef;
#$self->readTranslationTable();
$self->readTranslationTable();
return $self;
}
......@@ -224,37 +223,181 @@ sub createExpectObject($)
return $exp;
}
sub toApconPort($$)
#
# Convert port format between switch format and db format
# the original format is auto-detected.
# simply, a switch port starts with A-Z, or A-I on Apcon 2000 series
# while a db port is totally number: card.port.
#
sub convertPortFormat($$)
{
my ($self, $p) = @_;
my $apcport = $p->getEndByNode($self->{NAME});
if (!defined($apcport)) {
return $p;
}
my ($self, $srcport) = @_;
my $card = "";
my $port = "";
if ($srcport =~ /([A-Z])([0-9]{2})/) {
# froms switch to db
$card = ord($1) - ord('A') + 1;
$port = int($2);
my $card = chr(ord('A')+int($apcport->card()) - 1);
my $port = sprintf("%02d", int($apcport->port()));
return "$card.$port";
} elsif ($srcport =~ /(\d+)\.(\d+)/) {
# from db to switch
$card = chr(ord('A') + $1 - 1);
$port = sprintf("%02d", $2);
return "$card"."$port";
} else {
# unknown format, return itself
return $srcport;
}
}
sub fromApconPort($$)
{
my ($self, $ap) = @_;
if ($ap =~ /([A-Z])([0-9]{2})/) {
# froms switch to db
my $card = ord($1) - ord('A') + 1;
my $port = int($2);
##############################################################################
my %Interfaces=();
# Interfaces maps pcX:Y<==>MAC
my %PortIface=();
# Maps pcX:Y<==>pcX:iface
my %Ports=();
# Ports maps pcX:Y.port<==>switch:port
my %OldPorts=();
# Ports maps pcX:Y<==>switch:port
my %MorePortIface=();
# Maps node:card.port <==> node:iface
#
# This function fills in %Interfaces and %Ports
# They hold pcX:Y<==>MAC and pcX:Y.port<==>switch:port respectively
#
# XXX: Temp workround for portnum
#
sub readTranslationTable($) {
my $self = shift;
my $name="";
my $mac="";
my $iface="";
my $switchport="";
print "FILLING %Interfaces\n" if $self->{DEBUG};
my $result =
DBQueryFatal("select node_id,card,port,mac,iface from interfaces");
while ( @_ = $result->fetchrow_array()) {
$name = "$_[0]:$_[1]";
$iface = "$_[0]:$_[4]";
if ($_[2] != 1) {$name .=$_[2]; }
$mac = "$_[3]";
$Interfaces{$name} = $mac;
$Interfaces{$mac} = $name;
$PortIface{$name} = $iface;
$PortIface{$iface} = $name;
return Port->LookupByTriple($self->{NAME}, $card, $port);
$MorePortIface{"$_[0]:$_[1].$_[2]"} = $iface;
$MorePortIface{$iface} = "$_[0]:$_[1].$_[2]";
print "Interfaces: $mac <==> $name\n" if $self->{DEBUG} > 1;
}
print "FILLING %Ports\n" if $self->{DEBUG};
$result = DBQueryFatal("select node_id1,card1,port1,node_id2,card2,port2 ".
"from wires;");
while ( my @row = $result->fetchrow_array()) {
my ($node_id1, $card1, $port1, $node_id2, $card2, $port2) = @row;
my $oldname = "$node_id1:$card1";
$name = "$node_id1:$card1.$port1";
print "Name='$name'\t" if $self->{DEBUG} > 2;
print "Dev='$node_id2'\t" if $self->{DEBUG} > 2;
$switchport = "$node_id2:$card2.$port2";
print "switchport='$switchport'\n" if $self->{DEBUG} > 2;
$Ports{$name} = $switchport;
$Ports{$switchport} = $name;
if (exists($OldPorts{$oldname})) {
if ($OldPorts{$oldname} ne "") {
delete $OldPorts{$OldPorts{$oldname}};
}
$OldPorts{$oldname} = "";
} else {
$OldPorts{$oldname} = $switchport;
$OldPorts{$switchport} = $oldname;
}
return $ap;
print "Ports: '$name' <==> '$switchport'\n" if $self->{DEBUG} > 1;
}
}
#
# More robust version of convertPortFromNode2Dev
#
sub getRealSwitchPortFromPCPort($$) {
my $self = shift;
my $port = shift;
my $realport = "";
$self->debug("get real port on switch from PC port: $port\n");
if (exists($OldPorts{$port})) {
$realport = $OldPorts{$port};
if ($realport ne "") {
return $realport;
}
}
if (exists($Ports{$port})) {
$realport = $Ports{$port};
return $realport;
}
my $fullport = $port.".1";
if (exists($Ports{$fullport})) {
return $Ports{$fullport};
}
return undef;
}
#
# Try to guess if the given ports contains switch ports
# and refine it to be full port format.
#
sub refineVlanPorts($$@) {
my ($self, $vlanid, @givenports) = @_;
my @ifaces = getVlanIfaces($vlanid);
# Now we have to guess...
if ($#givenports == $#ifaces) {
#
# seems like all ports are here
#
my @fullports = ();
foreach my $iface (@ifaces) {
if (exists($MorePortIface{$iface})) {
push @fullports, $MorePortIface{$iface};
} else {
#
# iface doesn't exist, may God bless the givenports
# be new... new enough to be not in DB.
#
$self->debug("refine failed: Iface $iface not found\n");
return @givenports;
}
}
return @fullports;
}
$self->debug("refine failed: ports numbers not equal @givenports, @ifaces\n");
return @givenports;
}
##############################################################################
......@@ -810,6 +953,28 @@ sub setPortRate($$$)
return 0;
}
#
# Internal
# convert port format from pcxx:card to [A-I][0-9]{2}
#
sub convertPortFromNode2Dev($$) {
my $self = shift;
my $pcport = shift;
my $modport;
if ($pcport =~ /(.+):(.+)\.(.+)/) {
$modport = $Ports{"$pcport"};
} else {
$modport = $Ports{"$pcport.1"};
}
if (defined($modport)) {
return $self->convertPortFormat($modport);
}
return $pcport;
}
#
# Set a variable associated with a port. The commands to execute are given
# in the apcon_clilib::portCMDs hash
......@@ -825,13 +990,26 @@ sub portControl ($$@) {
my $cmd = shift;
my @pcports = @_;
$self->debug("portControl: $cmd -> (@pcports)\n");
#my @fullports = $self->refineVlanPorts($vlan_id, @pcports);
#my @ports = map {$self->getRealSwitchPortFromPCPort($_)} @fullports;
my $errors = 0;
foreach my $port (@pcports) {
if (isSwitchPort($port) || ref($self->toApconPort($port->getSwitchPort()))) {
next;
}
foreach my $port (@pcports) {
my $swport = $self->getRealSwitchPortFromPCPort($port);
if (!defined($swport)) {
if (isSwitchPort($port)) {
next;
} else {
$self->debug("No such port: $port\n");
$errors++;
next;
}
}
my $rt = $self->setPortRate($self->toApconPort($port->getSwitchPort()), $cmd);
$swport = $self->convertPortFormat($swport);
my $rt = $self->setPortRate($swport, $cmd);
if ($rt) {
if ($rt =~ /^ERROR: port rate unsupported/) {
#
......@@ -931,7 +1109,7 @@ sub findVlan($$;$) {
if (@$ports) {
return $vlan_id;
} elsif (exists($emptyVlans{$vlan_id})) {
return $vlan_id;
return $vlan_id; #return $emptyVlans{$vlan_id};
}
return undef;
......@@ -991,14 +1169,20 @@ sub setPortVlan($$@) {
my $id = $self->{NAME} . "::setPortVlan";
$self->debug("$id: $vlan_id ");
$self->debug("ports: " . Port->toStrings(@pcports). "\n");
$self->debug("ports: " . join(",",@pcports) . "\n");
if (@pcports != 2) {
warn "$id: supports only two ports in one VLAN.\n";
return 1;
}
my @ports = grep(!ref($_), map( $self->toApconPort($_->getSwitchPort()), @pcports));
#my @ports = map {$self->convertPortFromNode2Dev($_)} @pcports;
my @fullports = $self->refineVlanPorts($vlan_id, @pcports);
my @swports = map {$self->getRealSwitchPortFromPCPort($_)} @fullports;
$self->debug("$id: set ports in vlan: ".join(", ",@swports)."\n");
my @ports = map {$self->convertPortFormat($_)} @swports;
$self->lock();
# Check if ports are free
......@@ -1064,9 +1248,15 @@ sub delPortVlan($$@) {
my @pcports = @_;
$self->debug($self->{NAME} . "::delPortVlan $vlan_id ");
$self->debug("ports: " . Port->toStrings(@pcports) . "\n");
$self->debug("ports: " . join(",",@pcports) . "\n");
#my @ports = map {$self->convertPortFromNode2Dev($_)} @pcports;
my @fullports = $self->refineVlanPorts($vlan_id, @pcports);
my @swports = map {$self->getRealSwitchPortFromPCPort($_)} @fullports;
$self->debug("snmpit_apcon:delPortVlan: set ports in vlan: ".join(", ",@swports)."\n");
my @ports = grep(!ref($_), map($self->toApconPort($_->getSwitchPort()), @pcports));
my @ports = map {$self->convertPortFormat($_)} @swports;
$self->lock();
......@@ -1223,6 +1413,22 @@ sub vlanHasPorts($$) {
}
#
# Internal
# Convert from switch device port to pc node port
#
sub convertPortFromDev2Node($$) {
my ($self, $devport) = @_;
my $pnum = $self->{NAME}.":".$self->convertPortFormat($devport);
if (!exists $Ports{$pnum}) {
return undef;
}
return $Ports{$pnum};
}
#
# List all VLANs on the device
#
......@@ -1236,10 +1442,17 @@ sub listVlans($) {
my $vlans = $self->getAllNamedPorts();
foreach my $vlan_id (keys %$vlans) {
my @swports = @{$vlans->{$vlan_id}};
my @pcports = map($_->getPCPort(),
grep(ref($_),
map($self->fromApconPort($_), @swports)));
my @pcports = ();
foreach my $p (@swports) {
my $pcp = $self->convertPortFromDev2Node($p);
if ($pcp) {
push @pcports, $pcp;
} else {
push @pcports, $p;
}
}
push @list, [$vlan_id, $vlan_id, \@pcports];
}
......@@ -1262,21 +1475,24 @@ sub listPorts($) {
my @arate = @$arateref;
my @strdrate = @{$portRates{$drate}};
my $finalport = $self->fromApconPort($port);
if (!ref($finalport)) {
next;
}
my $pnum = $self->{NAME}.":".$self->convertPortFormat($port);
if (!exists $Ports{$pnum}) {
next;
}
my $finalport = $Ports{$pnum};
#
# if port is actived, use actual rate, otherwise use desired rate
#
if ( $arate[0] eq "00" ) {
push @ports, [$finalport->getPCPort(), "no", "down", $strdrate[2], $strdrate[1]];
push @ports, [$finalport, "no", "down", $strdrate[2], $strdrate[1]];
} else {
#
# Not sure if it is OK to just ignore the desired rate
#
push @ports, [$finalport->getPCPort(), "yes", "up", $arate[3], $arate[2]];
push @ports, [$finalport, "yes", "up", $arate[3], $arate[2]];
}
}
......
......@@ -23,8 +23,6 @@ use SNMP;
use snmpit_lib;
use Socket;
use libtestbed;
use Port;
use Lan;
#
# These are the commands that can be passed to the portControl function
......@@ -57,7 +55,6 @@ my %cmdOIDs =
my $PORT_FORMAT_IFINDEX = 1;
my $PORT_FORMAT_MODPORT = 2;
my $PORT_FORMAT_NODEPORT = 3;
my $PORT_FORMAT_PORT = 4;
#
# used by vlanTrunkUtil()
......@@ -285,7 +282,7 @@ sub portControl ($$@) {
my $cmd = shift;
my @ports = @_;
$self->debug("portControl: $cmd -> (".Port->toStrings(@ports).")\n");
$self->debug("portControl: $cmd -> (@ports)\n");
#
# Find the command in the %cmdOIDs hash (defined at the top of this file)
......@@ -378,7 +375,6 @@ 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;
......@@ -395,65 +391,29 @@ 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 @mps;
}
my @pos = map Port->LookupByStringForced($self->{NAME}.":".(defined($_)? $_:"")), @mps;
if ($output == $PORT_FORMAT_NODEPORT) {
return map $self->{IFINDEX}{$_}, @ports;
} elsif ($output == $PORT_FORMAT_NODEPORT) {