Commit 53cfe6f1 authored by Robert Ricci's avatar Robert Ricci

Merge tag 'sklower-two-snmpit-changes'

parents 35bd622e d6281dad
......@@ -1683,7 +1683,9 @@ sub readifIndex($) {
}
foreach $j (keys %{$self->{TRUNKS}}) {
$ifindex = $j + $t_off;
$port = "1." . $ifindex;
if (my $lref = $self->{TRUNKS}{$j}) {
$port = $self->{IFINDEX}{@$lref[0]}; #actually modport
} else { $port = "1." . $ifindex; } # the else should never happen
$self->{IFINDEX}{$ifindex} = $port;
$self->{IFINDEX}{$port} = $ifindex;
$self->{TRUNKINDEX}{$ifindex} = 0; # simplifies convertPortIndex
......
......@@ -76,6 +76,9 @@ my %vlanmembers=();
my %vlanids=();
# vlanids maps pid:eid <==> id
my %DeviceOptions=();
# Maps devicename -> hash of options to avoid db call after forking;
my $snmpitErrorString;
# Protos
......@@ -87,6 +90,7 @@ sub getTrunkPath($$$$);
sub init($) {
$debug = shift || $debug;
&ReadTranslationTable;
&ReadDeviceOptions;
return 0;
}
......@@ -985,6 +989,9 @@ sub getDeviceOptions($) {
my $switch = shift;
my %options;
if (my $cached_options = $DeviceOptions{$switch}) {
return $cached_options;
}
my $result = DBQueryFatal("SELECT supports_private, " .
"single_domain, s.snmp_community as device_community, ".
"t.min_vlan, t.max_vlan, " .
......@@ -1010,7 +1017,23 @@ sub getDeviceOptions($) {
$options{'min_vlan'} = $device_min || $min_vlan || 2;
$options{'max_vlan'} = $device_max || $max_vlan || 1000;
$options{'type'} = getDeviceType($switch);
my $type = $options{'type'} = getDeviceType($switch);
my $q = "(select \"default\" source, attrkey, attrvalue from ".
"node_type_attributes where type='$type' ".
"and attrkey like 'snmpit%') union ".
"(select \"override\" source, attrkey, attrvalue from ".
"node_attributes where node_id='$switch' ".
"and attrkey like 'snmpit%') order by source";
$result = DBQuery($q);
if ($result && $result->numrows()) {
while (my ($source, $key, $value) = $result->fetchrow()) {
$key =~ s/^snmpit_//;
$options{$key} = $value;
}
}
$DeviceOptions{$switch} = \%options;
if ($debug) {
print "Options for $switch:\n";
......@@ -1022,6 +1045,13 @@ sub getDeviceOptions($) {
return \%options;
}
sub ReadDeviceOptions() {
my $result = DBQuery("select distinct node_id from switch_stacks");
print STDERR "No switch found in any stack\n"
unless ($result && $result->numrows());
while (my ($switch) = $result->fetchrow()) { getDeviceOptions($switch); }
}
#
# Returns a structure representing all trunk links. It's a hash, keyed by
# switch, that contains hash references. Each of the second level hashes
......
......@@ -1755,7 +1755,9 @@ sub readifIndex($) {
}
foreach $j (keys %{$self->{TRUNKS}}) {
$ifindex = $j + $t_off;
$port = "1." . $ifindex;
if (my $lref = $self->{TRUNKS}{$j}) {
$port = $self->{IFINDEX}{@$lref[0]}; #actually modport
} else { $port = "1." . $ifindex; } # the else should never happen
$self->{IFINDEX}{$ifindex} = $port;
$self->{IFINDEX}{$port} = $ifindex;
$self->{TRUNKINDEX}{$ifindex} = 0; # simplifies convertPortIndex
......
......@@ -89,6 +89,9 @@ my %vlanmembers=();
my %vlanids=();
# vlanids maps pid:eid <==> id
my %DeviceOptions=();
# Maps devicename -> hash of options to avoid db call after forking;
my $snmpitErrorString;
# Protos
......@@ -99,6 +102,7 @@ sub getTrunkPath($$$$);
#
sub init($) {
$debug = shift || $debug;
&readDeviceOptions;
return 0;
}
......@@ -1058,6 +1062,9 @@ sub getDeviceOptions($) {
my $switch = shift;
my %options;
if (my $cached_options = $DeviceOptions{$switch}) {
return $cached_options;
}
my $result = DBQueryFatal("SELECT supports_private, " .
"single_domain, s.snmp_community as device_community, ".
"t.min_vlan, t.max_vlan, " .
......@@ -1083,7 +1090,23 @@ sub getDeviceOptions($) {
$options{'min_vlan'} = $device_min || $min_vlan || 2;
$options{'max_vlan'} = $device_max || $max_vlan || 1000;
$options{'type'} = getDeviceType($switch);
my $type = $options{'type'} = getDeviceType($switch);
my $q = "(select \"default\" source, attrkey, attrvalue from ".
"node_type_attributes where type='$type' ".
"and attrkey like 'snmpit%') union ".
"(select \"override\" source, attrkey, attrvalue from ".
"node_attributes where node_id='$switch' ".
"and attrkey like 'snmpit%') order by source";
$result = DBQuery($q);
if ($result && $result->numrows()) {
while (my ($source, $key, $value) = $result->fetchrow()) {
$key =~ s/^snmpit_//;
$options{$key} = $value;
}
}
$DeviceOptions{$switch} = \%options;
if ($debug) {
print "Options for $switch:\n";
......@@ -1095,6 +1118,13 @@ sub getDeviceOptions($) {
return \%options;
}
sub ReadDeviceOptions() {
my $result = DBQuery("select distinct node_id from switch_stacks");
print STDERR "No switch found in any stack\n"
unless ($result && $result->numrows());
while (my ($switch) = $result->fetchrow()) { getDeviceOptions($switch); }
}
#
# Returns a structure representing all trunk links. It's a hash, keyed by
# switch, that contains hash references. Each of the second level hashes
......
......@@ -192,7 +192,7 @@ SWITCH:
$switchtype = "intel"; last;};
(/^nortel/) && do { $snmpversion = "1"; $useindexing = 0;
$switchtype = "nortel"; last;};
(/^hp/) && do { $snmpversion = "1"; $useindexing = 0;
(/^hp/) && do { $snmpversion = "2c"; $useindexing = 0;
$switchtype = "hp"; last;};
(/^foundry/) && do { $snmpversion = "1"; $useindexing = 0;
$switchtype = "foundry"; last;};
......
......@@ -36,22 +36,20 @@ function find_switch_macs(&$mac_list) {
$class = $exploded[4];
if (!preg_match("/^([\w-]+)\/(\d+)\.(\d+)$/",$switchport,$matches)) {
echo "<h3>Bad line from switchmac: $line</h3>\n";
}
$switch = $matches[1];
$card = $matches[2];
$port = $matches[3];
if (isset($mac_list[$MAC]) &&
(is_null($mac_list[$MAC]["class"]) ||
!isset($mac_list[$MAC]["class"]) ||
($mac_list[$MAC]["class"] == $class))) {
$mac_list[$MAC]["switch"] = $switch;
$mac_list[$MAC]["switch_card"] = $card;
$mac_list[$MAC]["switch_port"] = $port;
if ($ELABINELAB) {
# We let switchmac tell us.
$mac_list[$MAC]["class"] = $class;
# Need this to reorder the interfaces.
$mac_list[$MAC]["iface"] = $iface;
} else {
$switch = $matches[1];
$card = $matches[2];
$port = $matches[3];
if (isset($mac_list[$MAC]) ) {
$mac_list[$MAC]["switch"] = $switch;
$mac_list[$MAC]["switch_card"] = $card;
$mac_list[$MAC]["switch_port"] = $port;
if ($ELABINELAB) {
# We let switchmac tell us.
$mac_list[$MAC]["class"] = $class;
# Need this to reorder the interfaces.
$mac_list[$MAC]["iface"] = $iface;
}
}
}
$line = fgets($macs);
......
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