Commit 9bd1dded authored by Robert Ricci's avatar Robert Ricci

Some minor API changes to increase effieciency for Intels.

First, the stack-level createVlan() function no longer takes as an
argument a list of devices the VLAN exists on, since it looks like
this will never be needed.

In it's place, createVlan() now takes a list of ports, so that it can
(if so desired) put the ports in the VLAN without a seperate lock and
unlock.

The snmpit_intel module now uses its 'nested locking' feature to avoid
additional locking in these cases. Note though, that the way that this
is done is not safe for multiple switches in a stack. If we ever have
to support multiple Intels (looks doubtful), this will have to be
removed, or locking will need to be moved a level up to
snmpit_intel_stack . Yuck.

For Intels, the removeVlan() function calls removePortsFromVlan()
itself, again to save locking overhead. The Cisco behavior, however,
is unchanged, as locking is not expensive, and this would be too
messy.
parent c8addf8d
......@@ -591,36 +591,31 @@ sub doVlansFromTables($@) {
print " VLAN $vlan already exists\n";
$errors += $stack->setPortVlan($vlan,@ports);
} else {
if (!$stack->createVlan($vlan)) {
if (!$stack->createVlan($vlan,@ports)) {
warn "ERROR: Failed to create VLAN with id $vlan\n";
#
# Don't try to put ports in a VLAN if it couldn't be created
#
$errors++;
} else {
my $setErrors = $stack->setPortVlan($vlan,@ports);
$errors += $setErrors;
}
}
#
# Set the speed and duplex of each interface depending on the
# value in the database
#
if (!$setErrors) {
foreach my $port (@ports) {
my ($speed,$duplex) = getInterfaceSettings($port);
#
# If either is not set, we do nothing. We could make
# a 0 mean 'auto'
#
if ($speed) {
my $cmd = $speed . "mbit";
$errors += $stack->portControl($cmd, $port);
}
if ($duplex) {
$errors += $stack->portControl($duplex, $port);
}
}
}
#
# Set the speed and duplex of each interface depending on the
# value in the database
#
foreach my $port (@ports) {
my ($speed,$duplex) = getInterfaceSettings($port);
#
# If either is not set, we do nothing. We could make
# a 0 mean 'auto'
#
if ($speed) {
my $cmd = $speed . "mbit";
$errors += $stack->portControl($cmd, $port);
}
if ($duplex) {
$errors += $stack->portControl($duplex, $port);
}
}
}
......@@ -676,9 +671,20 @@ sub doMakeVlan($$@) {
#
if ($stack->vlanExists($vlan_name)) {
print "VLAN $vlan_name already exists\n";
#
# Put requested ports into the VLAN
#
if (@ports) {
print "Putting ports in VLAN ...\n";
my $perrors = $stack->setPortVlan($vlan_name,@ports);
print "VLAN change ";
print $perrors? "failed":"succeeded",".\n";
$errors += $perrors;
}
} else {
print "Creating VLAN $vlan_name ...\n";
my $ok = $stack->createVlan($vlan_name);
my $ok = $stack->createVlan($vlan_name,@ports);
print "VLAN creation ";
print $ok? "succeeded":"failed",".\n";
if (!$ok) {
......@@ -686,18 +692,6 @@ sub doMakeVlan($$@) {
}
}
#
# Put requested ports into the VLAN
#
if (@ports) {
print "Putting ports in VLAN ...\n";
my $perrors = $stack->setPortVlan($vlan_name,@ports);
print "VLAN change ";
print $perrors? "failed":"succeeded",".\n";
$errors += $perrors;
}
return $errors;
}
......
......@@ -230,25 +230,34 @@ sub setPortVlan($$@) {
}
#
# Creates a VLAN with the given VLAN identifier on the stack. A device list
# is given to indicate which devices the VLAN must span. It is an error to
# create a VLAN that already exists.
# Creates a VLAN with the given VLAN identifier on the stack. If ports are
# given, puts them into the newly created VLAN. It is an error to create a
# VLAN that already exists.
#
# usage: createVlan(self, vlan identfier, device list)
# usage: createVlan(self, vlan identfier, port list)
#
# returns: 1 on success
# returns: 0 on failure
#
sub createVlan($$@) {
sub createVlan($$;@) {
my $self = shift;
my $vlan_id = shift;
my @devicenames = @_; # Note: This is not used for Cisco switches
my @ports = @_;
#
# We just need to create the VLAN on the stack leader
#
return $self->{LEADER}->createVlan($vlan_id);
my $okay = $self->{LEADER}->createVlan($vlan_id);
#
# We need to add the ports to VLANs at the stack level, since they are
# not necessarily on the leader
#
if ($okay && @ports) {
if ($self->setPortVlan($vlan_id,@ports)) {
$okay = 0;
}
}
}
#
......
......@@ -399,15 +399,17 @@ sub findVlan($$;$) {
#
# Create a VLAN on this switch, with the given identifier (which comes from
# the database.) Picks its own switch-specific VLAN number to use.
# the database.) Picks its own switch-specific VLAN number to use. If ports
# are given, puts them in the newly-created VLAN.
#
# usage: createVlan($self, $vlan_id)
# usage: createVlan($self, $vlan_id,@ports)
# returns 1 on success
# returns 0 on failure
#
sub createVlan($$) {
sub createVlan($$;@) {
my $self = shift;
my $vlan_id = shift;
my @ports = shift;
my $okay = 0;
......@@ -442,6 +444,16 @@ sub createVlan($$) {
$okay = 0;
}
#
# If we wre given any ports, put them into the VLAN now, so that
# we can do this without unlocking/relocking.
#
if ($okay && @ports) {
if ($self->setPortVlan($vlan_id,@ports)) {
$okay = 0;
}
}
$self->vlanUnlock();
return $okay;
......@@ -659,7 +671,7 @@ sub removePortsFromVlan($$) {
$self->debug("Removing $port from vlan $vlan\n");
my $RetVal = $self->{SESS}->set(["policyPortRuleDeleteObj",
$index,1,"INTEGER"]);
if ($RetVal) {
if (!$RetVal) {
$errors++;
}
......@@ -684,8 +696,8 @@ sub removePortsFromVlan($$) {
}
#
# Remove the given VLAN from this switch. This presupposes that all of its
# ports have already been removed with removePortsFromVlan(). The VLAN is
# Remove the given VLAN from this switch. Removes all ports from the VLAN,
# so it's not necessary to call removePortsFromVlan() first. The VLAN is
# given as a VLAN identifier from the database.
#
# usage: removeVlan(self,int vlan)
......@@ -714,6 +726,17 @@ sub removeVlan($$) {
return 0;
}
#
# First, remove all ports from this VLAN
#
if ($self->removePortsFromVlan($vlan_id)) {
#
# Uh oh, something went wrong. Unlock and bail
#
$self->vlanUnlock();
return 0;
}
#
# Perform the actual removal
#
......
......@@ -108,12 +108,12 @@ sub setPortVlan($$@) {
return $self->{LEADER}->setPortVlan($vlan_id,@ports);
}
sub createVlan($$@) {
sub createVlan($$;@) {
my $self = shift;
my $vlan_id = shift;
my @devicenames = @_; # Note: This is not used for Intel switches
my @ports = @_;
return $self->{LEADER}->createVlan($vlan_id);
return $self->{LEADER}->createVlan($vlan_id,@ports);
}
......@@ -147,7 +147,6 @@ sub vlanExists($$) {
sub removeVlan($$) {
my $self = shift;
my $vlan_id = shift;
my $errors = 0;
#
# First, make sure that the VLAN really does exist
......@@ -158,7 +157,6 @@ sub removeVlan($$) {
return 0;
}
$errors += $self->{LEADER}->removePortsFromVlan($vlan_id);
my $ok = $self->{LEADER}->removeVlan($vlan_id);
return $ok;
......
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