Commit 044b23aa authored by Weibin Sun's avatar Weibin Sun
Browse files

merge with master and do clean up of the code

parent 04627336
......@@ -3150,7 +3150,7 @@ sub IsNodeInAVlan($$)
return $query_result->numrows;
}
sub FindVlanByPort_OLD($$$) #@@@@ deprecated
sub FindVlanByPort_OLD($$$)
{
my ($class, $experiment, $port) = @_;
my ($node_id, $card) = split(":", $port);
......
......@@ -458,8 +458,7 @@ if ($opt{B}) {
tbdie "No port given in status string";
}
if ($args{port}) {
push @ports, convertPortsFromStrings($args{port}, $optdev);
# @@@@ !!!! #push @ports, convertPortsFromIfaces($args{port});
push @ports, convertPortsFromStrings($args{port}, $optdev);
}
}
}
......@@ -612,14 +611,6 @@ if ($opt{y}) {
"argument has been given";
}
}
# if ($opt{z} =~ /^\d+\/\d+?$/) { #@@@@ whole block refactored
# if ($opt{i} && @{$opt{i}} == 1) {
# $opt{z} = $opt{i}->[0] . "." . $opt{z};
# } else {
# tbdie "The module/port format is only legal if exactly one -i " .
# "argument has been given";
# }
# }
push @pvlanArgs,$opt{x},$opt{z};
}
}
......@@ -637,8 +628,7 @@ if ($opt{y}) {
#
# Convert ports into the correct format
if (@ports) {
@ports = convertPortsFromStrings(@ports, $optdev);
# @@@@ #@ports = convertPortsFromIfaces(@ports);
@ports = convertPortsFromStrings(@ports, $optdev);
if (scalar(@optports) != scalar(@ports)) {
die "Bad format for ports: ".join(" ", @optports)."\n";
}
......@@ -650,7 +640,6 @@ if (@ports) {
# Only admins can do the latter, of course...
#
# @@@@ large change
my @pcports = grep {!$_->is_switch_side()} @ports;
my @nodes = map {$_->node_id()} @pcports;
my @switchports = grep {$_->is_switch_side()} @ports;
......@@ -888,7 +877,7 @@ COMMAND: foreach my $command (@commands) {
if (!$args{port}) {
tbdie "No port given in status string";
}
@ports = Port->converPortsFromStrings($args{port}); #@@@@ @ports = convertPortsFromIfaces($args{port});
@ports = Port->converPortsFromStrings($args{port});
if ($args{vlan}) {
@vlans = ($args{vlan});
}
......@@ -1542,7 +1531,6 @@ sub doRestorePortStatus($@) {
tbdie "No port passed to -B option";
}
#@@@@ tentatively add this:
if (!ref($port)) {
my $tport = convertPortFromString($port);
if ($tport) {
......@@ -3112,9 +3100,7 @@ sub doPortControl($$@) {
if ($ELABINELAB) {
# As below, only one stack.
my ($stack) = @$stacks;
#@@@@ not sure about the port format:
$errors = RemoteDoPortControl($stack,$command, @optports);
#$errors = RemoteDoPortControl($stack,$command, map($_->toIfaceString(), @ports));
goto finish;
}
......@@ -3224,10 +3210,8 @@ sub doTrunkEnable($$$@) {
if ($ELABINELAB) {
my $mode = $equaltrunking ? "-E" : "-T";
# As below, only one stack.
my ($stack) = @$stacks;
# not sure about the port format:
my ($stack) = @$stacks;
$errors = RemoteDoTrunking($stack,$mode,$optports[0],@vlans);
#$errors = RemoteDoTrunking($stack,$mode,$port->toIfaceString(),@vlans);
goto finish;
}
#
......
......@@ -224,16 +224,6 @@ sub createExpectObject($)
return $exp;
}
#
# 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($$) #@@@@ deprecated
{
return undef;
}
sub toApconPort($$)
{
......@@ -265,21 +255,6 @@ sub fromApconPort($$)
}
#
# More robust version of convertPortFromNode2Dev
#
sub getRealSwitchPortFromPCPort($$) { #@@@@ deprecated
return undef;
}
#
# Try to guess if the given ports contains switch ports
# and refine it to be full port format.
#
sub refineVlanPorts($$@) { #@@@@ deprecated
return undef;
}
##############################################################################
......@@ -834,14 +809,6 @@ sub setPortRate($$$)
return 0;
}
#
# Internal
# convert port format from pcxx:card to [A-I][0-9]{2}
#
sub convertPortFromNode2Dev($$) { #@@@@ deprecated
return undef;
}
#
# Set a variable associated with a port. The commands to execute are given
# in the apcon_clilib::portCMDs hash
......@@ -1255,15 +1222,6 @@ sub vlanHasPorts($$) {
}
#
# Internal
# Convert from switch device port to pc node port
#
sub convertPortFromDev2Node($$) { #@@@@ deprecated
return undef;
}
#
# List all VLANs on the device
#
......
......@@ -1575,12 +1575,6 @@ sub listVlans($) {
# XXX: This should really print out something more useful, like the
# other end of the trunk
my $node = $self->{NAME} . ".trunk$ifIndex";
#my ($node) = $self->convertPortFormat($PORT_FORMAT_NODEPORT,$ifIndex);
#if (!$node) {
# my ($modport) = $self->convertPortFormat($PORT_FORMAT_MODPORT,$ifIndex);
# $modport =~ s/\./\//;
# $node = $self->{NAME} . ".$modport";
#}
# Get the allowed VLANs on this trunk
my @trunklans = $self->vlanTrunkUtil($VOP_CHECK, $ifIndex, keys %Names);
......
......@@ -354,7 +354,7 @@ sub portControl ($$@) {
my $cmd = shift;
my @ports = @_;
#$self->debug("portControl: $cmd -> (@ports)\n");
$self->debug("portControl: $cmd -> (".Port->toStrings(@ports).")\n");
#
# Find the command in the %cmdOIDs hash (defined at the top of this file).
......@@ -877,7 +877,6 @@ sub setPortVlan($$@) {
return 0 unless(@ports);
my @portlist = $self->convertPortFormat($PORT_FORMAT_IFINDEX, @ports);
#@@@@$self->debug("ports: " . join(",",@ports) . "\n");
$self->debug("as ifIndexes: " . join(",",@portlist) . "\n");
#
......@@ -960,7 +959,6 @@ sub setPortVlan($$@) {
}
my $onoroff = ($vlan_number ne "1") ? "enable" : "disable";
#@@@@$self->debug("$id; will $onoroff" . join(',',@ports) . "...\n");
if ( $rv = $self->portControl($onoroff, @ports) ) {
warn "$id: Port enable had $rv failures.\n";
$errors += $rv;
......@@ -1006,7 +1004,6 @@ sub updateOneVlan($$$$$@)
$self->lock();
my @portlist = $self->convertPortFormat($PORT_FORMAT_IFINDEX, @ports);
#$self->debug("ports: " . join(",",@ports) . "\n");
$self->debug("as ifIndexes: " . join(",",@portlist) . "\n");
my $vlist = $self->getVlanLists($vlan_number);
......@@ -1152,7 +1149,6 @@ sub removeVlan($@) {
sub UpdateField($$$@) {
my ($self, $OID, $val, @ports)= @_;
my $id = $self->{NAME} . "::UpdateField OID $OID value $val";
#@@@@$self->debug("$id: ports @ports\n");
my $result = 0;
my $oidval = $val;
......@@ -1164,10 +1160,10 @@ sub UpdateField($$$@) {
$self->debug("checking row $row for $val ...\n");
$Status = $self->get1($OID,$row);
if (!defined($Status)) {
print STDERR "id: Port $portname No answer from device\n"; #!@@@@
print STDERR "id: Port $portname No answer from device\n";
next;
}
$self->debug("Port $portname, row $row was $Status\n"); #!@@@@
$self->debug("Port $portname, row $row was $Status\n");
if ($OID eq "hpSwitchPortFastEtherMode") {
#
# Procurves use the same mib variable to set both
......@@ -1202,7 +1198,7 @@ sub UpdateField($$$@) {
}
}
if ($Status ne $oidval) {
$self->debug("Setting $portname (r $row) to $oidval..."); #!@@@@
$self->debug("Setting $portname (r $row) to $oidval...");
$Status = $self->set([[$OID,$row,$oidval,"INTEGER"]]);
$result = (defined($Status)) ? 0 : -1;
$self->debug($result ? "failed.\n" : "succeeded.\n");
......@@ -1274,7 +1270,7 @@ sub listVlans($) {
@portlist = $self->portSetToList($value);
$self->debug("Got $oid $vlan_number @portlist\n",3);
foreach $ifIndex (@portlist) { #@@@@
foreach $ifIndex (@portlist) {
($node) = $self->convertPortFormat($PORT_FORMAT_PORT,$ifIndex);
if (!$node) {
($modport) = $self->convertPortFormat
......@@ -1298,7 +1294,6 @@ sub listVlans($) {
push @list, [$Names{$vlan_id},$vlan_id,$Members{$vlan_id}];
}
#$self->debug($self->{NAME} .":". join("\n",(map {join ",", @$_} @list))."\n");
return @list;
}
......@@ -1365,10 +1360,9 @@ sub listPorts($) {
#
my @rv = ();
foreach my $id ( keys %Able ) {
#@@@@ change here:
$modport = $self->{IFINDEX}{$id};
$portname = $self->{NAME} . ":$modport";
my $port = Port->LookupByTriple($portname); #@@@@ portnum($portname);
my $port = Port->LookupByTriple($portname);
if (defined($port)) {
$port = $port->getPCPort();
}
......@@ -1424,7 +1418,6 @@ sub getStats() {
# See comments in walkTable above.
#@@@@: change here:
if (! defined $self->{IFINDEX}{$ifindex}) { next; }
my $po = convertPortFromString("$self->{NAME}:$ifindex")
|| convertPortFromString("$self->{NAME}:".$self->{IFINDEX}{$ifindex});
......@@ -1444,11 +1437,9 @@ sub getStats() {
#
# usage: resetVlanIfOnTrunk(self, modport, vlan)
#
sub resetVlanIfOnTrunk($$$) {#@@@done
sub resetVlanIfOnTrunk($$$) {
my ($self, $modport, $vlan) = @_;
my ($ifIndex) = $self->convertPortFormat($PORT_FORMAT_IFINDEX,$modport);
#@@@@ $self->debug($self->{NAME} . "::resetVlanIfOnTrunk m $modport "
#@@@@ . "vlan $vlan ifIndex $ifIndex\n",1);
my $vlan_ports = $self->get1($egressOID, $vlan);
if (testPortSet($vlan_ports, $ifIndex - 1)) {
$self->setVlansOnTrunk($modport,0,$vlan);
......@@ -1521,7 +1512,7 @@ sub setVlansOnTrunk($$$$) {
warn "VLAN 1 passed to setVlansOnTrunk\n";
return 0;
}
#@@@@$self->debug("$id: m $modport v $value nums @vlan_numbers\n");
my ($ifIndex) = $self->convertPortFormat($PORT_FORMAT_IFINDEX,$modport);
#
......
......@@ -16,7 +16,7 @@ use Exporter;
@EXPORT = qw( macport portnum portiface Dev vlanmemb vlanid
getTestSwitches getControlSwitches getSwitchesInStack
getSwitchesInStacks getVlanIfaces
getVlanPorts convertPortsFromIfaces convertPortFromIface
getVlanPorts
getExperimentTrunks setVlanTag setVlanStack
getExperimentVlans getDeviceNames getDeviceType
getInterfaceSettings mapPortsToDevices getSwitchPrimaryStack
......@@ -60,7 +60,7 @@ my $SNMPIT_SET = 1;
my $SNMPIT_BULKWALK = 2;
##################################################
#@@@@ deprecated:
# deprecated:
my %Devices=();
# Devices maps device names to device IPs
......@@ -77,7 +77,6 @@ my %IfaceModPorts=();
my %Ports=();
# Ports maps pcX:Y<==>switch:port
#@@@@ deprecated!
##################################################
my %vlanmembers=();
......@@ -95,8 +94,7 @@ sub getTrunkPath($$$$);
# Initialize the library
#
sub init($) {
$debug = shift || $debug;
&ReadTranslationTable;
$debug = shift || $debug;
return 0;
}
......@@ -141,125 +139,43 @@ sub convertPortsFromStrings(@;$)
}
#
# Deprecated
# Map between interfaces and mac addresses
#
sub macport { #@@@@ deprecated
#my $val = shift || "";
#return $Interfaces{$val};
sub macport {
return undef;
}
#
# Deprecated
# Map between node:iface and port numbers
#
sub portiface { #@@@@ deprecated
#my $val = shift || "";
#return $PortIface{$val};
sub portiface {
return undef;
}
#
# Deprecated
# Map between switch interfaces and port numbers
#
sub portnum { #@@@@ deprecated
#my $val = shift || "";
#return $Ports{$val};
sub portnum {
return undef;
}
#
# Deprecated
# Map between interfaces and the devices they are attached to
#
sub Dev { #@@@@ deprecated
#my $val = shift || "";
#return $Devices{$val};
sub Dev {
return undef;
}
#
# Deprecated
# Map between ifaces and switch port
#
sub ifacemodport { #@@@@ deprecated
#my $val = shift || "";
#return $IfaceModPorts{$val};
return undef;
}
#
# This function fills in %Interfaces and %Ports
# They hold pcX:Y<==>MAC and pcX:Y<==>switch:port respectively
#
sub ReadTranslationTable { #@@@@ deprecated
#my $name="";
#my $mac="";
#my $iface="";
#my $switchport="";
#print "FILLING %Interfaces\n" if $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;
#$IfaceModPorts{$iface} = $name.".$_[2]";
#$IfaceModPorts{$name.".$_[2]"} = $iface;
#print "Interfaces: $mac <==> $name\n" if $debug > 1;
#}
#print "FILLING %Ports\n" if $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;
#$name = "$node_id1:$card1";
#print "Name='$name'\t" if $debug > 2;
#print "Dev='$node_id2'\t" if $debug > 2;
#$switchport = "$node_id2:$card2.$port2";
#print "switchport='$switchport'\n" if $debug > 2;
#$Ports{$name} = $switchport;
#$Ports{$switchport} = $name;
#print "Ports: '$name' <==> '$switchport'\n" if $debug > 1;
#}
}
#
# Return an array of ifaces belonging to the VLAN
#
sub getVlanIfaces($) { #@@@@ deprecated
#my $vlanid = shift;
#my @ports = ();
#my $vlan = VLan->Lookup($vlanid);
#if (!defined($vlan)) {
#die("*** $0:\n".
#" No vlanid $vlanid in the DB!\n");
#}
#my @members;
#if ($vlan->MemberList(\@members) != 0) {
#die("*** $0:\n".
#" Unable to load members for $vlan\n");
#}
#foreach my $member (@members) {
#my $nodeid;
#my $iface;
#if ($member->GetAttribute("node_id", \$nodeid) != 0 ||
#$member->GetAttribute("iface", \$iface) != 0) {
#die("*** $0:\n".
#" Missing attributes for $member in $vlan\n");
#}
#push(@ports, "$nodeid:$iface");
#}
#return @ports;
sub ifacemodport {
return undef;
}
......@@ -268,7 +184,7 @@ sub getVlanIfaces($) { #@@@@ deprecated
# that consists of two layer 1 connections and also has a switch as
# the middle node.
#
sub getPathVlanIfaces($$) { #@@@@ OK
sub getPathVlanIfaces($$) {
my $vlanid = shift;
my $ifaces = shift;
......@@ -336,8 +252,7 @@ sub getPathVlanIfaces($$) { #@@@@ OK
warn "Vlan ".$myvlan->id()." doesnot have exact two ports.\n";
return -1;
}
# #@@@@ should use Port's class functions:
if ($pref[0] eq "$node:$iface") {
$ifacesonswitchnode{"$node:$iface"} = $pref[1];
} else {
......@@ -357,7 +272,7 @@ sub getPathVlanIfaces($$) { #@@@@ OK
#
# Returns an array of ports (in node:card form) used by the given VLANs
#
sub getVlanPorts (@) { #@@@@ large change
sub getVlanPorts (@) {
my @vlans = @_;
# Silently exit if they passed us no VLANs
if (!@vlans) {
......@@ -396,11 +311,10 @@ sub getVlanPorts (@) { #@@@@ large change
# Returns an an array of trunked ports (in node:card form) used by an
# experiment
#
sub getExperimentTrunks($$) { #@@@@ OK
sub getExperimentTrunks($$) {
my ($pid, $eid) = @_;
my @ports;
#@@@@ this function should not be aware of the seperated fields of a port
my $query_result =
DBQueryFatal("select distinct r.node_id,i.iface from reserved as r " .
"left join interfaces as i on i.node_id=r.node_id " .
......@@ -409,11 +323,9 @@ sub getExperimentTrunks($$) { #@@@@ OK
while (my ($node, $iface) = $query_result->fetchrow()) {
$node = Port->LookupByIface($node, $iface);
#$node = $node . ":" . $iface;
push @ports, $node;
}
return @ports;
#return convertPortsFromIfaces(@ports);
}
#
......@@ -421,11 +333,10 @@ sub getExperimentTrunks($$) { #@@@@ OK
# experiment. These are the ports that are actually in trunk mode,
# rather then the ports we want to be in trunk mode (above function).
#
sub getExperimentCurrentTrunks($$) { #@@@@ OK
sub getExperimentCurrentTrunks($$) {
my ($pid, $eid) = @_;
my @ports;
#@@@@ this function should not be aware of the seperated fields of a port
my $query_result =
DBQueryFatal("select distinct r.node_id,i.iface from reserved as r " .
"left join interface_state as i on i.node_id=r.node_id " .
......@@ -434,18 +345,16 @@ sub getExperimentCurrentTrunks($$) { #@@@@ OK
while (my ($node, $iface) = $query_result->fetchrow()) {
$node = Port->LookupByIface($node, $iface);
#$node = $node . ":" . $iface;
push @ports, $node;
}
return @ports;
#return convertPortsFromIfaces(@ports);
}
#
# Returns an an array of ports (in node:card form) that currently in
# Returns an an array of ports that currently in
# the given vlan.
#
sub getExperimentVlanPorts($) { #@@@@ OK
sub getExperimentVlanPorts($) {
my ($vlanid) = @_;
my $query_result =
......@@ -457,14 +366,14 @@ sub getExperimentVlanPorts($) { #@@@@ OK
my ($members) = $query_result->fetchrow_array();
my @members = split(/\s+/, $members);
return Port->LookupByIfaces(@members); #convertPortsFromIfaces(@members);
return Port->LookupByIfaces(@members);
}
#
# Get the list of stacks that the given set of VLANs *will* or *should* exist
# on
#
sub getPlannedStacksForVlans(@) { #@@@@ OK
sub getPlannedStacksForVlans(@) {
my @vlans = @_;
# Get VLAN members, then go from there to devices, then from there to
......@@ -627,7 +536,7 @@ sub filterPlannedVlans(@) {
#
# Update database to mark port as enabled or disabled.
#
sub setPortEnabled($$) { #@@@@ OK
sub setPortEnabled($$) {
my ($port, $enabled) = @_;
my ($node, $card) = ($port->node_id(), $port->card());
......@@ -638,8 +547,9 @@ sub setPortEnabled($$) { #@@@@ OK
return 0;
}
# Ditto for trunked.
sub setPortTagged($$) { #@@@@ OK
sub setPortTagged($$) {
my ($port, $tagged) = @_;
my ($node, $card) = ($port->node_id(), $port->card());
......@@ -649,71 +559,11 @@ sub setPortTagged($$) { #@@@@ OK
"where node_id='$node' and card='$card'");
}
#
# Convert an entire list of ports in port:iface format to into port:card -
# returns other port forms unchanged.
#
sub convertPortsFromIfaces(@) { #@@@@ deprecated
my @ports = @_;
return map {
if (/(.+):([A-Za-z].*)/) {
# Seems to be a node:iface line
convertPortFromIface($_);
} else {
$_;
}
} @ports;
}
#
# Convert a port in port:iface format to port:card
#
sub convertPortFromIface($) { #@@@@ deprecated
my ($port) = $_;
if ($port =~ /(.+):(.+)/) {
my ($node,$iface) = ($1,$2);
my $result = DBQueryFatal("SELECT card, port FROM interfaces " .
"WHERE node_id='$node' AND iface='$iface'");
if (!$result->num_rows()) {
warn "WARNING: convertPortFromIface($port) - Unable to get card\n";
return $port;
}
my @row = $result->fetchrow();
my $card = $row[0];
my $cport = $row[1];
$result = DBQueryFatal("SELECT isswitch FROM node_types WHERE type IN ".
"(SELECT type FROM nodes WHERE node_id='$node')");
if (!$result->num_rows()) {
warn "WARNING: convertPortFromIface($port) -".
" Uable to decide if $node is a switch or not\n";
return $port;
}
if (($result->fetchrow())[0] == 1) {
#
# Should return the later one, but many places in snmpit
# and this file depend on the old format...
#
return "$node:$card";
#return "$node:$card.$cport";
}
return "$node:$card";
} else {
warn "WARNING: convertPortFromIface($port) - Bad port format\n";
return $port;
}