Commit 174776a7 authored by Robert Ricci's avatar Robert Ricci

Contributed patch from Keith Slower @ Berkeley adding a Nortel module

for snmpit.
parent 204c7c10
......@@ -119,6 +119,11 @@ foreach my $name (keys %portMap) {
$device = new snmpit_foundry($name,0);
last;
};
/nortel/ && do {
require snmpit_nortel;
$device = new snmpit_nortel($name,0);
last;
};
# 'default' case
die "Unknown switch type ($type) for $name\n";
......
......@@ -257,6 +257,11 @@ foreach my $name (keys %portMap) {
$device = new snmpit_foundry($name);
last;
};
/nortel/ && do {
require snmpit_nortel;
$device = new snmpit_nortel($name);
last;
};
# 'default' case
die "Unknown switch type ($type) for $name\n";
......
......@@ -975,6 +975,117 @@ sub setVlansOnTrunk($$$$) {
}
return !$errors;
}
#
# Clear the list of allowed VLANs from a trunk
#
# usage: clearAllVlansOnTrunk(self, modport)
# modport: module.port of the trunk to operate on
# Returns 1 on success, 0 otherwise
#
sub clearAllVlansOnTrunk($$) {
my $self = shift;
my ($modport) = @_;
my ($ifIndex) = $self->convertPortFormat($PORT_FORMAT_IFINDEX,$modport);
my $portIndex = $self->{PORTINDEX}{$ifIndex};
my $tag_obj = ["snSwPortInfoTagMode",$portIndex];
my $tag_state = snmpGet($self->{SESS}, $tag_obj);
if ($tag_state == 1 ) {
snmpSet(["snSwPortVlanId",$portIndex,0,"INTEGER"]);
}
my @vlaninfo = $self->listVlans();
while ((scalar @vlaninfo)) {
my ($name, $number, @members) = pop @vlaninfo;
if (grep {$_ eq $modport} @members) {
$self->debug("removing port $portIndex from VLAN $number\n",1);
my $obj = "snVLanByPortMemberRowStatus.$number.$portIndex";
my $RetVal = $self->{SESS}->set( $obj, 3);
if (!defined($RetVal) || ! $RetVal ) {
print STDERR "Couldn't remove $modport from VLAN $number\n";
}
}
}
}
#
# Enable trunking on a port
#
# usage: enablePortTrunking(self, modport, nativevlan)
# modport: module.port of the trunk to operate on
# nativevlan: VLAN number of the native VLAN for this trunk
# Returns 1 on success, 0 otherwise
#
sub enablePortTrunking($$$) {
my $self = shift;
my ($port,$native_vlan) = @_;
my ($ifIndex) = $self->convertPortFormat($PORT_FORMAT_IFINDEX,$port);
my $portIndex = $self->{PORTINDEX}{$ifIndex};
#
# Clear out the list of allowed VLANs for this trunk port, so that when it
# comes up, there is not some race condition
#
my $rv = $self->clearAllVlansOnTrunk($port);
if (!$rv) {
warn "ERROR: Unable to clear VLANs on trunk\n";
return 0;
}
#
# Add this port to the VLAN as a tagged port
#
$rv = $self->setVlansOnTrunk($port, 1, [ $native_vlan] );
if (!$rv) {
warn "ERROR: Unable to add port $port to VLAN $native_vlan\n";
return 0;
}
#
# Set the native VLAN for this trunk
#
my $nativeVlan = ["snSwPortVlanId",$portIndex,$native_vlan,"INTEGER"];
$rv = snmpitSet($self->{SESS},$nativeVlan);
if (!$rv) {
warn "ERROR: Unable to set native VLAN on trunk\n";
return 0;
}
}
#
# Disable trunking on a port
#
# usage: disablePortTrunking(self, modport)
# modport: module.port of the trunk to operate on
# Returns 1 on success, 0 otherwise
#
sub disablePortTrunking($$) {
my $self = shift;
my ($port) = @_;
my ($ifIndex) = $self->convertPortFormat($PORT_FORMAT_IFINDEX,$port);
my $portIndex = $self->{PORTINDEX}{$ifIndex};
my $vlan_obj = ["snSwPortVlanId",$portIndex];
my $tag_obj = ["snSwPortInfoTagMode",$portIndex];
my $tag_state = snmpitGet($self->{SESS},$tag_obj);
my $native_vlan = snmpitGet($self->{SESS},$vlan_obj);
#
# Clear out the list of allowed VLANs for this trunk port
#
my $rv = $self->clearAllVlansOnTrunk($port);
if (!$rv) {
warn "ERROR: Unable to clear VLANs on trunk\n";
return 0;
}
if ($native_vlan != 0) {
$self->setPortVlan($native_vlan, [$port]);
}
return 1;
}
#
# Reads the IfIndex table from the switch, for SNMP functions that use
......
This diff is collapsed.
......@@ -92,7 +92,7 @@ sub new($$$@) {
# we weren't given devicenames for devices that aren't switches.
#
SWITCH: for ($type) {
(/cisco65\d\d/ || /cisco40\d\d/ || /cisco29\d\d/ || /cisco55\d\d/)
(/cisco65\d\d/ || /cisco40\d\d/ || /cisco45\d\d/ || /cisco29\d\d/ || /cisco55\d\d/)
&& do {
use snmpit_cisco;
$device = new snmpit_cisco($devicename,$self->{DEBUG});
......@@ -104,6 +104,12 @@ sub new($$$@) {
$device = new snmpit_foundry($devicename,$self->{DEBUG});
last;
}; # /foundry.*/
(/nortel1100/ || /nortel5510/)
&& do {
use snmpit_nortel;
$device = new snmpit_nortel($devicename,$self->{DEBUG});
last;
}; # /nortel.*/
die "Device $devicename is not of a known type, skipping\n";
}
unless ($device) {
......@@ -559,6 +565,115 @@ sub getStats($) {
}
return map $stats{$_}, sort {tbsort($a,$b)} keys %stats;
}
#
# Turns on trunking on a given port, allowing only the given VLANs on it
#
# usage: enableTrunking(self, port, vlan identifier list)
#
# returns: 1 on success
# returns: 0 on failure
#
sub enableTrunking($$@) {
my $self = shift;
my $port = shift;
my @vlan_ids = @_;
#
# On a Cisco, the first VLAN given becomes the native VLAN for the trunk
#
my $native_vlan_id = shift @vlan_ids;
if (!$native_vlan_id) {
print STDERR "ERROR: No native VLAN passed to enableTrunking()!\n";
return 0;
}
#
# Grab the VLAN number for the native VLAN
#
my $vlan_number = $self->{LEADER}->findVlan($native_vlan_id);
if (!$vlan_number) {
print STDERR "ERROR: Native VLAN $native_vlan_id does not exist!\n";
return 0;
}
#
# Split up the ports among the devices involved
#
my %map = mapPortsToDevices($port);
my ($devicename) = keys %map;
my $device = $self->{DEVICES}{$devicename};
if (!defined($device)) {
warn "ERROR: Unable to find device entry for $devicename\n";
return 0;
}
#
# Simply make the appropriate call on the device
#
print "Enable trunking: Port is $port, native VLAN is $native_vlan_id\n"
if ($self->{DEBUG});
my $rv = $device->enablePortTrunking($port, $vlan_number);
#
# If other VLANs were given, add them to the port too
#
if (@vlan_ids) {
my %vlan_numbers = $self->{LEADER}->findVlans(@vlan_ids);
my @vlan_numbers;
foreach my $vlan_id (@vlan_ids) {
#
# First, make sure that the VLAN really does exist
#
my $vlan_number = $vlan_numbers{$vlan_id};
if (!$vlan_number) {
warn "ERROR: VLAN $vlan_id not found on switch!";
next;
}
push @vlan_numbers, $vlan_number;
}
print " add VLANs " . join(",",@vlan_numbers) . " to trunk\n"
if ($self->{DEBUG});
if (!$device->setVlansOnTrunk($port,1,@vlan_numbers)) {
warn "ERROR: could not add VLANs " .
join(",",@vlan_numbers) . " to trunk";
}
}
return $rv;
}
#
# Turns off trunking for a given port
#
# usage: disableTrunking(self, ports)
#
# returns: 1 on success
# returns: 0 on failure
#
sub disableTrunking($$) {
my $self = shift;
my $port = shift;
#
# Split up the ports among the devices involved
#
my %map = mapPortsToDevices($port);
my ($devicename) = keys %map;
my $device = $self->{DEVICES}{$devicename};
if (!defined($device)) {
warn "ERROR: Unable to find device entry for $devicename\n";
return 0;
}
#
# Simply make the appropriate call on the device
#
my $rv = $device->disablePortTrunking($port);
return $rv;
}
#
# Not a 'public' function - only needs to get called by other functions in
......
......@@ -29,6 +29,7 @@ use libxmlrpc;
use snmpit_lib;
use snmpit_cisco;
use snmpit_foundry;
use snmpit_nortel;
use SNMP;
use strict;
......@@ -330,15 +331,8 @@ SWITCH:
my $bridgeport = $bridgeports{$index};
my $ifIndex = $ifIndexMap{$bridgeport};
if (!$ifIndex) {
if ($switchtype eq "nortel") {
#
# Bad hack for Nortel switches
#
$ifIndex = $bridgeport - 47;
} else {
DEBUG "ifIndex conversion failed for $bridgeport!\n";
next;
}
}
#
......@@ -347,7 +341,8 @@ SWITCH:
# have only one module, and require no ifindex conversion.
#
my $modport;
if (($switchtype eq "cisco") || ($switchtype eq "foundry")) {
if (($switchtype eq "cisco") || ($switchtype eq "foundry") ||
($switchtype eq "nortel" ) {
($modport) = $device->convertPortFormat(2, $ifIndex);
} else {
$modport = "1.$ifIndex";
......
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