Commit 811cb82a authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

For elabinelab, snmpit -t (-r) no longer does an individual trunk

enable/disable on each port (one XMLRPC per). Instead, do this as part
of the remotedovlans and remotedestroyvlans.

Some reorg in doVlansFromTables() do deal with vlans that need to be
trunked in dual mode. That vlan must be created first, the ports
trunked, and the rest of the vlans created.
parent c91c8cc1
......@@ -43,10 +43,11 @@ sub doDeleteVlan($@);
sub doVlanNumber($$);
sub doPortControl($$@);
sub doRecreateVlans($);
sub doTrunkEnable($$@);
sub doTrunkEnable($$$@);
sub doTrunkDisable($$);
sub doRestorePortStatus($@);
sub doSynchLeader($);
sub CreateOneVlan($$@);
#
# Defaults
......@@ -77,7 +78,7 @@ Usage: $0 [-h] [-v] [-q] [-n] [-i device] [-S stack]
[-c]
General:
-h Display this help message
-v Verbose mode
-v <level> Verbose mode
-q Quiet mode
-n Test mode - don't actually make any changes
-i <device> Operate on <device>, overriding default device list. Can be
......@@ -770,7 +771,8 @@ COMMAND: foreach my $command (@commands) {
last;
};
/trunkenable/ && do {
$exitval += doTrunkEnable(\@stacks,$ports[0],@vlans);
$exitval += doTrunkEnable(\@stacks,$ports[0],
$equaltrunking,@vlans);
last;
}; # /trunkenable/ && do
/trunkdisable/ && do {
......@@ -1270,31 +1272,70 @@ $port, $inoctets, $inunicast,$innunicast,$indiscards,$inerr, $inunk, $out
#
sub doVlansFromTables($$@) {
my $experiment = shift;
my $stacks = shift;
my @vlans = @_;
my $stacks = shift;
my @vlanids = @_;
my %vlans = ();
my $errors = 0;
my $vlan_number;
my $oEopt = $equaltrunking;
if (@$stacks > 1) {
die "VLAN creation accross multiple stacks is not yet supported\n" .
"Stacks are " . join(",",@$stacks) . "\n";
}
my ($stack) = @$stacks;
my @trunkedPorts = getExperimentTrunks($pid,$eid);
$equaltrunking = 1;
foreach my $port (@trunkedPorts) {
$errors += doTrunkEnable($stacks,$port);
}
$equaltrunking = $oEopt;
#
# Hand over to outer boss.
#
if ($ELABINELAB) {
return RemoteDoVlansFromTables(@vlans);
return RemoteDoVlansFromTables($experiment, @vlanids);
}
my ($stack) = @$stacks;
my @trunkedPorts = getExperimentTrunks($pid,$eid);
my %trunkedPorts = map { $_ => $_ } @trunkedPorts;
#
# Look for a lan that requires dual mode trunking. The ports in that
# lan need to be trunked after the native lan is created, so that we
# can call doTrunkEnable with dual mode instead of equalmode. This is
# not a general solution to this, but I have not found a solution I am
# really happy with.
#
foreach my $id (@vlanids) {
my $vlan = VLan->Lookup($id);
if (!defined($vlan)) {
die("Could not locate vlan $id in the DB\n");
}
$vlans{"$id"} = $vlan;
}
foreach my $vlan (values(%vlans)) {
my $vlanid = $vlan->id();
my $trunk_mode;
$vlan->GetAttribute("trunk_mode", \$trunk_mode);
# This is set in libvtop.
if (defined($trunk_mode) && $trunk_mode eq "dual") {
my @ports = getVlanPorts($vlanid);
# Create this vlan now.
if (CreateOneVlan($stack, $vlanid, @ports)) {
die("Could not create dual trunked $vlan\n");
}
# Trunk these ports, removing from list.
foreach my $port (@ports) {
if (doTrunkEnable($stacks,$port,0,$vlanid)) {
die("Could not put $port ($vlan) into dual trunk mode\n");
}
delete($trunkedPorts{$port});
}
# Delete this vlan from the list that will be created below.
delete($vlans{"$vlanid"});
}
}
# Do the rest of the trunked ports in equalmode.
foreach my $port (keys(%trunkedPorts)) {
$errors += doTrunkEnable($stacks,$port,1);
}
#
......@@ -1315,63 +1356,82 @@ sub doVlansFromTables($$@) {
}
my $vlan_count = $switch_options->{'max_vlan'} -
$switch_options->{'min_vlan'};
my $expt_vlan_count = scalar(@vlans);
my $expt_vlan_count = scalar(keys(%vlans));
if ($expt_vlan_count > $vlan_count) {
tberror "Too many VLANs in experiment: $expt_vlan_count requested, " .
"$vlan_count available";
return 1;
}
foreach my $vlan (@vlans) {
my @ports = getVlanPorts($vlan);
if ($stack->vlanExists($vlan)) {
print " VLAN $vlan already exists\n"
if (!$quiet);
$errors += $stack->setPortVlan($vlan,@ports);
} else {
$vlan_number = $stack->createVlan($vlan,\@ports);
if (!$vlan_number) {
tberror({type => 'secondary', severity => SEV_SECONDARY,
error => ['create_vlan_failed', $vlan]},
"Failed to create VLAN with id $vlan");
#
# Don't try to put ports in a VLAN if it couldn't be created
#
$errors++;
} else {
setVlanTag($vlan, $vlan_number);
VLan->RecordVlanInsertion($experiment, $vlan);
}
}
foreach my $vlan (values(%vlans)) {
my $vlanid = $vlan->id();
my @ports = getVlanPorts($vlanid);
#
# Set the speed and duplex of each interface depending on the
# value in the database
#
foreach my $port (@ports) {
my ($speed,$duplex) = getInterfaceSettings($port);
$errors += CreateOneVlan($stack, $vlanid, @ports);
}
return $errors;
}
#
# Create a single vlan.
#
sub CreateOneVlan($$@)
{
my $stack = shift();
my $vlanid = shift();
my @ports = @_;
my $errors = 0;
if ($stack->vlanExists($vlanid)) {
print " VLAN $vlanid already exists\n"
if (!$quiet);
$errors += $stack->setPortVlan($vlanid,@ports);
}
else {
my $vlan_number = $stack->createVlan($vlanid,\@ports);
if (!$vlan_number) {
tberror({type => 'secondary', severity => SEV_SECONDARY,
error => ['create_vlan_failed', $vlanid]},
"Failed to create VLAN with id $vlanid");
#
# If either is not set, we do nothing. We could make
# a 0 mean 'auto'
# Don't try to put ports in a VLAN if it couldn't be created
#
# For now, we ignore it if the switch doesn't support the commands.
if ($speed) {
my $cmd = $speed . "mbit";
my $rv = $stack->portControl($cmd, $port);
if ($rv > 0) {
$errors += $rv;
}
$errors++;
}
else {
setVlanTag($vlanid, $vlan_number);
VLan->RecordVlanInsertion($experiment, $vlanid);
}
}
return $errors
if ($errors);
#
# 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'
#
# For now, we ignore it if the switch doesn't support the commands.
#
if ($speed) {
my $cmd = $speed . "mbit";
my $rv = $stack->portControl($cmd, $port);
if ($rv > 0) {
$errors += $rv;
}
if ($duplex) {
my $rv = $stack->portControl($duplex, $port);
if ($rv > 0) {
$errors += $rv;
}
}
if ($duplex) {
my $rv = $stack->portControl($duplex, $port);
if ($rv > 0) {
$errors += $rv;
}
}
}
return $errors;
}
......@@ -1384,17 +1444,17 @@ sub doReset($@) {
my $stacks = shift;
my @vlans = @_;
my $errors = 0;
my @trunkedPorts = getExperimentTrunks($pid,$eid);
foreach my $port (@trunkedPorts) {
$errors += doTrunkDisable($stacks,$port);
}
#
# Hand over to outer boss.
#
if ($ELABINELAB) {
return RemoteDoReset(@vlans);
return RemoteDoReset($experiment, scalar(@optvlanids) == 0, @vlans);
}
my $errors = 0;
my @trunkedPorts = getExperimentTrunks($pid,$eid);
foreach my $port (@trunkedPorts) {
$errors += doTrunkDisable($stacks,$port);
}
#
......@@ -1487,6 +1547,7 @@ sub doMakeVlan($$@) {
$target_vlan->MarkManual();
}
$vlan_id = $target_vlan->id();
# This will add the port *only* if not already in the vlan.
foreach my $port (@ports) {
$target_vlan->AddPort($port);
}
......@@ -1498,7 +1559,7 @@ sub doMakeVlan($$@) {
#
if ($ELABINELAB) {
if ($target_vlan) {
return RemoteDoVlansFromTables($target_vlan->id());
return RemoteDoVlansFromTables($experiment, $target_vlan->id());
}
else {
return RemoteMakeVlan($stack, $vlan_id, @ports);
......@@ -1808,9 +1869,10 @@ sub doRecreateVlans($) {
#
# Enable trunking on a port, and enable a set of VLANs on it
#
sub doTrunkEnable($$@) {
sub doTrunkEnable($$$@) {
my $stacks = shift;
my $port = shift;
my $equaltrunking = shift;
my @vlans = @_;
my $errors = 0;
......
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