1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
|
# SNMP::Info::Layer3::Foundry - SNMP Interface to Foundry devices
# $Id$
#
# Copyright (c) 2008 Max Baker changes from version 0.8 and beyond.
#
# Copyright (c) 2002,2003 Regents of the University of California
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the University of California, Santa Cruz nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer3::Foundry;
use strict;
use Exporter;
use SNMP::Info::Layer3;
use SNMP::Info::FDP;
use SNMP::Info::LLDP;
@SNMP::Info::Layer3::Foundry::ISA = qw/
SNMP::Info::FDP
SNMP::Info::LLDP
SNMP::Info::Layer3
Exporter
/;
@SNMP::Info::Layer3::Foundry::EXPORT_OK = qw//;
use vars qw/$VERSION %GLOBALS %FUNCS %MIBS %MUNGE/;
$VERSION = '3.65';
%MIBS = (
%SNMP::Info::Layer3::MIBS,
%SNMP::Info::LLDP::MIBS,
%SNMP::Info::FDP::MIBS,
'FOUNDRY-SN-ROOT-MIB' => 'foundry',
'FOUNDRY-SN-AGENT-MIB' => 'snChasPwrSupplyDescription',
'FOUNDRY-SN-SWITCH-GROUP-MIB' => 'snSwGroupOperMode',
'FOUNDRY-SN-STACKING-MIB' => 'snStackingOperUnitRole',
'FOUNDRY-POE-MIB' => 'snAgentPoeGblPowerCapacityTotal',
'FOUNDRY-SN-SWITCH-GROUP-MIB' => 'snSwGroupOperMode',
'BROCADE-PRODUCTS-MIB' => 'brocadeProducts',
);
%GLOBALS = (
%SNMP::Info::Layer3::GLOBALS,
%SNMP::Info::LLDP::GLOBALS,
%SNMP::Info::FDP::GLOBALS,
'mac' => 'ifPhysAddress.1',
'chassis' => 'entPhysicalDescr.1',
'temp' => 'snChasActualTemperature',
'ps1_type' => 'snChasPwrSupplyDescription.1',
'ps1_status' => 'snChasPwrSupplyOperStatus.1',
'fan' => 'snChasFanOperStatus.1',
'img_ver' => 'snAgImgVer',
'ch_serial' => 'snChasSerNum',
);
%FUNCS = (
%SNMP::Info::Layer3::FUNCS,
%SNMP::Info::LLDP::FUNCS,
%SNMP::Info::FDP::FUNCS,
# FOUNDRY-SN-SWITCH-GROUP-MIB
# snSwPortInfoTable - Switch Port Information Group
'sw_index' => 'snSwPortIfIndex',
'sw_duplex' => 'snSwPortInfoChnMode',
'sw_type' => 'snSwPortInfoMediaType',
'sw_speed' => 'snSwPortInfoSpeed',
# FOUNDRY-SN-AGENT-MIB::snAgentConfigModule2Table
'ag_mod2_type' => 'snAgentConfigModule2Type',
# FOUNDRY-SN-AGENT-MIB::snAgentConfigModuleTable
'ag_mod_type' => 'snAgentConfigModuleType',
# FOUNDRY-SN-AGENT-MIB::snVLanByPortTable
'stp_i_id' => 'snVLanByPortVLanId',
'stp_i_mac' => 'snVLanByPortBaseBridgeAddress',
'stp_i_time' => 'snVLanByPortStpTimeSinceTopologyChange',
'stp_i_ntop' => 'snVLanByPortStpTopChanges',
'stp_i_root' => 'snVLanByPortStpDesignatedRoot',
'stp_i_root_port' => 'snVLanByPortStpRootPort',
'stp_i_priority' => 'snVLanByPortStpPriority',
# FOUNDRY-SN-AGENT-MIB::snPortStpTable
'stp_p_id' => 'snPortStpPortNum',
'stp_p_stg_id' => 'snPortStpVLanId',
'stp_p_priority' => 'snPortStpPortPriority',
'stp_p_state' => 'snPortStpPortState',
'stp_p_cost' => 'snPortStpPortDesignatedCost',
'stp_p_root' => 'snPortStpPortDesignatedRoot',
'stp_p_bridge' => 'snPortStpPortDesignatedBridge',
'stp_p_port' => 'snPortStpPortDesignatedPort',
);
%MUNGE = (
%SNMP::Info::Layer3::MUNGE,
%SNMP::Info::LLDP::MUNGE,
%SNMP::Info::FDP::MUNGE,
'ag_mod2_type' => \&SNMP::Info::munge_e_type,
'ag_mod_type' => \&SNMP::Info::munge_e_type,
'stp_i_mac' => \&SNMP::Info::munge_mac,
'stp_i_root' => \&SNMP::Info::munge_prio_mac,
'stp_p_root' => \&SNMP::Info::munge_prio_mac,
'stp_p_bridge' => \&SNMP::Info::munge_prio_mac,
'stp_p_port' => \&SNMP::Info::munge_prio_port,
);
sub i_ignore {
my $foundry = shift;
my $partial = shift;
my $interfaces = $foundry->interfaces($partial) || {};
my %i_ignore;
foreach my $if ( keys %$interfaces ) {
if ( $interfaces->{$if} =~ /(tunnel|loopback|\blo\b|lb|null)/i ) {
$i_ignore{$if}++;
}
}
return \%i_ignore;
}
sub i_duplex {
my $foundry = shift;
my $partial = shift;
my $sw_index = $foundry->sw_index($partial);
my $sw_duplex = $foundry->sw_duplex($partial);
unless ( defined $sw_index and defined $sw_duplex ) {
return $foundry->SUPER::i_duplex();
}
my %i_duplex;
foreach my $sw_port ( keys %$sw_duplex ) {
my $iid = $sw_index->{$sw_port};
my $duplex = $sw_duplex->{$sw_port};
next if $duplex =~ /none/i;
$i_duplex{$iid} = 'half' if $duplex =~ /half/i;
$i_duplex{$iid} = 'full' if $duplex =~ /full/i;
}
return \%i_duplex;
}
sub model {
my $foundry = shift;
my $id = $foundry->id();
my $model = &SNMP::translateObj($id);
# EdgeIron
if ( $id =~ /\.1991\.1\.[45]\./ ) {
my $e_name = $foundry->e_name();
# Find entity table entry for "unit.1"
my $unit_iid = undef;
foreach my $e ( keys %$e_name ) {
my $name = $e_name->{$e} || '';
$unit_iid = $e if $name eq 'unit.1';
}
# Find Model Name
my $e_model = $foundry->e_model();
if ( defined $e_model->{$unit_iid} ) {
return $e_model->{$unit_iid};
}
}
return $id unless defined $model;
$model =~ s/^sn//;
$model =~ s/Switch//;
return $model;
}
sub os {
return 'brocade';
}
sub vendor {
return 'brocade';
}
sub os_ver {
my $foundry = shift;
return $foundry->img_ver() if ( defined $foundry->img_ver() );
# Some older ones don't have this value,so we cull it from the description
my $descr = $foundry->description();
if ( $descr =~ m/Version (\d\S*)/ ) {
return $1;
}
# EdgeIron
my $e_name = $foundry->e_name();
# find entity table entry for "stackmanaget.1"
my $unit_iid = undef;
foreach my $e ( keys %$e_name ) {
my $name = $e_name->{$e} || '';
$unit_iid = $e if $name eq 'stackmanaget.1';
}
if ( defined $unit_iid ) {
# Find Model Name
my $e_fwver = $foundry->e_fwver();
if ( defined $e_fwver->{$unit_iid} ) {
return $e_fwver->{$unit_iid};
}
}
# See if we report from Flash if wouldn't report from running above
return $foundry->snAgFlashImgVer() if ( defined $foundry->snAgFlashImgVer() );
# Last resort
return $foundry->SUPER::os_ver();
}
sub serial {
my $foundry = shift;
# Return chassis serial number if available
return $foundry->ch_serial() if ( $foundry->ch_serial() );
# If no chassis serial use first module serial
my $mod_serials = $foundry->snAgentConfigModuleSerialNumber() || {};
foreach my $mod ( sort keys %$mod_serials ) {
my $serial = $mod_serials->{$mod} || '';
next unless defined $serial;
return $serial;
}
# EdgeIron
my $e_name = $foundry->e_name();
# find entity table entry for "unit.1"
my $unit_iid = undef;
foreach my $e ( keys %$e_name ) {
my $name = $e_name->{$e} || '';
$unit_iid = $e if $name eq 'unit.1';
}
if ( defined $unit_iid ) {
# Look up serial of found entry.
my $e_serial = $foundry->e_serial();
return $e_serial->{$unit_iid} if defined $e_serial->{$unit_iid};
}
# Last resort
return $foundry->SUPER::serial();
}
sub interfaces {
my $foundry = shift;
my $partial = shift;
my $i_descr = $foundry->i_description($partial) || {};
my $i_name = $foundry->i_name($partial) || {};
# Use ifName for EdgeIrons else use ifDescr
foreach my $iid ( keys %$i_name ) {
my $name = $i_name->{$iid};
next unless defined $name;
$i_descr->{$iid} = $name
if $name =~ /^port\d+/i;
}
return $i_descr;
}
# Entity MIB is supported on the Brocade NetIron XMR, NetIron MLX, MLXe,
# NetIron CES, NetIron CER, and older EdgeIron series devices.
# Try Entity MIB methods first and fall back to Pseudo ENTITY-MIB methods for
# other devices.
# e_fwver, e_hwver, e_swver not supported in psuedo methods, no need to
# override
sub e_index {
my $foundry = shift;
my $partial = shift;
return $foundry->SUPER::e_index($partial)
|| $foundry->brcd_e_index($partial);
}
sub e_class {
my $foundry = shift;
my $partial = shift;
return $foundry->SUPER::e_class($partial)
|| $foundry->brcd_e_class($partial);
}
sub e_descr {
my $foundry = shift;
my $partial = shift;
return $foundry->SUPER::e_descr($partial)
|| $foundry->brcd_e_descr($partial);
}
sub e_name {
my $foundry = shift;
my $partial = shift;
return $foundry->SUPER::e_name($partial)
|| $foundry->brcd_e_name($partial);
}
sub e_parent {
my $foundry = shift;
my $partial = shift;
return $foundry->SUPER::e_parent($partial)
|| $foundry->brcd_e_parent($partial);
}
sub e_pos {
my $foundry = shift;
my $partial = shift;
return $foundry->SUPER::e_pos($partial) || $foundry->brcd_e_pos($partial);
}
sub e_serial {
my $foundry = shift;
my $partial = shift;
return $foundry->SUPER::e_serial($partial)
|| $foundry->brcd_e_serial($partial);
}
sub e_type {
my $foundry = shift;
my $partial = shift;
return $foundry->SUPER::e_type($partial)
|| $foundry->brcd_e_type($partial);
}
sub e_vendor {
my $foundry = shift;
my $partial = shift;
return $foundry->SUPER::e_vendor($partial)
|| $foundry->brcd_e_vendor($partial);
}
# Pseudo ENTITY-MIB methods
# This class supports both stackable and chassis based switches, identify if
# we have a stackable so that we return appropriate entPhysicalClass
# Identify if the stackable is actually a stack vs. single switch
sub _brcd_stack_master {
my $foundry = shift;
my $roles = $foundry->snStackingOperUnitRole() || {};
foreach my $iid ( keys %$roles ) {
my $role = $roles->{$iid};
next unless $role;
if ( $role eq 'active' ) {
return $iid;
}
}
return;
}
sub brcd_e_index {
my $foundry = shift;
my $partial = shift;
my $stack_master = $foundry->_brcd_stack_master();
my $brcd_e_idx
= $foundry->snAgentConfigModule2Description($partial)
|| $foundry->snAgentConfigModuleDescription($partial)
|| {};
my %brcd_e_index;
if ($stack_master) {
# Stack Entity
$brcd_e_index{0} = 1;
}
foreach my $iid ( keys %$brcd_e_idx ) {
my $index = $iid;
# Format into consistent integer format so that numeric sorting works
if ( $iid =~ /(\d+)\.(\d+)/ ) {
$index = "$1" . sprintf "%02d", $2;
}
$brcd_e_index{$iid} = $index;
}
return \%brcd_e_index;
}
sub brcd_e_class {
my $foundry = shift;
my $partial = shift;
my $e_idx = $foundry->brcd_e_index($partial) || {};
my %e_class;
foreach my $iid ( keys %$e_idx ) {
if ( $iid == 0 ) {
$e_class{$iid} = 'stack';
}
# Were going to assume chassis at slot/index 1
# If this turns out to be false in some cases we can check
# snAgentConfigModuleNumberOfCpus as other modules won't have cpus?
elsif ( $iid =~ /1$/ ) {
$e_class{$iid} = 'chassis';
}
else {
$e_class{$iid} = 'module';
}
}
return \%e_class;
}
sub brcd_e_descr {
my $foundry = shift;
my $partial = shift;
my $brcd_e_idx = $foundry->brcd_e_index($partial) || {};
my $m_descrs
= $foundry->snAgentConfigModule2Description($partial)
|| $foundry->snAgentConfigModuleDescription($partial)
|| {};
my %brcd_e_descr;
foreach my $iid ( keys %$brcd_e_idx ) {
if ( $iid == 0 ) {
$brcd_e_descr{$iid} = $foundry->description();
}
my $descr = $m_descrs->{$iid};
next unless defined $descr;
$brcd_e_descr{$iid} = $descr;
}
return \%brcd_e_descr;
}
sub brcd_e_name {
my $foundry = shift;
my $partial = shift;
my $stack_master = $foundry->_brcd_stack_master();
my $e_idx = $foundry->brcd_e_index($partial) || {};
my %brcd_e_name;
foreach my $iid ( keys %$e_idx ) {
if ( $iid == 0 ) {
$brcd_e_name{$iid} = 'Stack Master Unit';
}
elsif ( $stack_master && $iid =~ /(\d+)\.1$/ ) {
$brcd_e_name{$iid} = "Switch Stack Unit $1";
}
elsif ( $iid =~ /1$/ ) {
$brcd_e_name{$iid} = "Switch";
}
else {
$brcd_e_name{$iid} = 'Module';
}
}
return \%brcd_e_name;
}
sub brcd_e_vendor {
my $foundry = shift;
my $partial = shift;
my $e_idx = $foundry->brcd_e_index($partial) || {};
my %brcd_e_vendor;
foreach my $iid ( keys %$e_idx ) {
my $vendor = 'brocade';
$brcd_e_vendor{$iid} = $vendor;
}
return \%brcd_e_vendor;
}
sub brcd_e_serial {
my $foundry = shift;
my $partial = shift;
my $e_idx = $foundry->brcd_e_index($partial) || {};
my $serials
= $foundry->snAgentConfigModule2SerialNumber($partial)
|| $foundry->snAgentConfigModuleSerialNumber($partial)
|| {};
my %brcd_e_serial;
foreach my $iid ( keys %$e_idx ) {
if ( $iid == 0 ) {
$brcd_e_serial{$iid} = $foundry->serial();
}
my $serial = $serials->{$iid};
next unless defined $serial;
$brcd_e_serial{$iid} = $serial;
}
return \%brcd_e_serial;
}
sub brcd_e_type {
my $foundry = shift;
my $partial = shift;
my $e_idx = $foundry->brcd_e_index($partial) || {};
my $types
= $foundry->ag_mod2_type($partial)
|| $foundry->ag_mod_type($partial)
|| {};
my %brcd_e_type;
foreach my $iid ( keys %$e_idx ) {
if ( $iid == 0 ) {
$brcd_e_type{$iid} = $foundry->model();
}
my $type = $types->{$iid};
next unless defined $type;
$brcd_e_type{$iid} = $type;
}
return \%brcd_e_type;
}
sub brcd_e_pos {
my $foundry = shift;
my $partial = shift;
my $e_idx = $foundry->brcd_e_index($partial) || {};
my %brcd_e_pos;
foreach my $iid ( keys %$e_idx ) {
my $pos;
if ( $iid == 0 ) {
$pos = -1;
}
elsif ( $iid =~ /(\d+)\.1$/ ) {
$pos = $1;
}
elsif ( $iid =~ /(\d+)$/ ) {
$pos = $1;
}
$brcd_e_pos{$iid} = $pos;
}
return \%brcd_e_pos;
}
sub brcd_e_parent {
my $foundry = shift;
my $partial = shift;
my $stack_master = $foundry->_brcd_stack_master();
my $e_idx = $foundry->brcd_e_index($partial) || {};
my %brcd_e_parent;
foreach my $iid ( keys %$e_idx ) {
if ( $iid == 0 ) {
$brcd_e_parent{$iid} = 0;
}
elsif ( $stack_master && $iid =~ /(\d+)\.1$/ ) {
$brcd_e_parent{$iid} = 1;
}
elsif ( $iid =~ /1$/ ) {
$brcd_e_parent{$iid} = 0;
}
elsif ( $iid =~ /(\d+).\d+/ ) {
$brcd_e_parent{$iid} = "$1" . "01";
}
# assume non-stacked and chassis at index 1
else {
$brcd_e_parent{$iid} = 1;
}
}
return \%brcd_e_parent;
}
# The index of snAgentPoePortTable is snAgentPoePortNumber which equals
# ifIndex; however, to emulate POWER-ETHERNET-MIB we need a "module.port"
# index. If ifDescr has the format x/x/x use it to determine the module
# otherwise default to 1. Unfortunately, this means we can't map any
# snAgentPoePortTable leafs directly and partials will not be supported.
sub peth_port_ifindex {
my $foundry = shift;
my $indexes = $foundry->snAgentPoePortNumber();
my $descrs = $foundry->i_description();
my $peth_port_ifindex = {};
foreach my $i ( keys %$indexes ) {
my $descr = $descrs->{$i};
next unless $descr;
my $new_idx = "1.$i";
if ( $descr =~ /(\d+)\/\d+\/\d+/ ) {
$new_idx = "$1.$i";
}
$peth_port_ifindex->{$new_idx} = $i;
}
return $peth_port_ifindex;
}
sub peth_port_admin {
my $foundry = shift;
my $p_index = $foundry->peth_port_ifindex() || {};
my $admin_states = $foundry->snAgentPoePortControl() || {};
my $peth_port_admin = {};
foreach my $i ( keys %$p_index ) {
my ( $module, $port ) = split( /\./, $i );
my $state = $admin_states->{$port};
if ( $state =~ /enable/ ) {
$peth_port_admin->{$i} = 'true';
}
else {
$peth_port_admin->{$i} = 'false';
}
}
return $peth_port_admin;
}
sub peth_port_neg_power {
my $foundry = shift;
my $p_index = $foundry->peth_port_ifindex() || {};
my $peth_port_class = $foundry->snAgentPoePortClass() || {};
my $poemax = {
'0' => 12950,
'1' => 3840,
'2' => 6490,
'3' => 12950,
'4' => 25500
};
my $peth_port_neg_power = {};
foreach my $i ( keys %$p_index ) {
my ( $module, $port ) = split( /\./, $i );
my $power = $poemax->{ $peth_port_class->{$port} };
next unless $power;
$peth_port_neg_power->{$i} = $power;
}
return $peth_port_neg_power;
}
sub peth_port_power {
my $foundry = shift;
my $p_index = $foundry->peth_port_ifindex() || {};
my $port_consumed = $foundry->snAgentPoePortConsumed() || {};
my $peth_port_power = {};
foreach my $i ( keys %$p_index ) {
my ( $module, $port ) = split( /\./, $i );
my $power = $port_consumed->{$port};
next unless $power;
$peth_port_power->{$i} = $power;
}
return $peth_port_power;
}
sub peth_port_class {
my $foundry = shift;
my $p_index = $foundry->peth_port_ifindex() || {};
my $port_class = $foundry->snAgentPoePortClass() || {};
my $peth_port_class = {};
foreach my $i ( keys %$p_index ) {
my ( $module, $port ) = split( /\./, $i );
my $power = $port_class->{$port};
next unless $power;
$peth_port_class->{$i} = "class$power";
}
return $peth_port_class;
}
sub peth_port_status {
my $foundry = shift;
my $p_index = $foundry->peth_port_ifindex() || {};
my $admin_states = $foundry->snAgentPoePortControl() || {};
my $peth_port_status = {};
foreach my $i ( keys %$p_index ) {
my ( $module, $port ) = split( /\./, $i );
my $state = $admin_states->{$port};
if ( $state =~ /enable/ ) {
$peth_port_status->{$i} = 'deliveringPower';
}
else {
$peth_port_status->{$i} = 'disabled';
}
}
return $peth_port_status;
}
sub peth_power_status {
my $foundry = shift;
my $partial = shift;
my $watts = $foundry->snAgentPoeUnitPowerCapacityTotal($partial) || {};
my $peth_power_status = {};
foreach my $i ( keys %$watts ) {
$peth_power_status->{$i} = 'on';
}
return $peth_power_status;
}
sub peth_power_watts {
my $foundry = shift;
my $partial = shift;
my $watts_total = $foundry->snAgentPoeUnitPowerCapacityTotal($partial)
|| {};
my $peth_power_watts = {};
foreach my $i ( keys %$watts_total ) {
my $total = $watts_total->{$i};
next unless $total;
$peth_power_watts->{$i} = $total / 1000;
}
return $peth_power_watts;
}
sub peth_power_consumption {
my $foundry = shift;
my $partial = shift;
my $watts_total = $foundry->snAgentPoeUnitPowerCapacityTotal($partial)
|| {};
my $watts_free = $foundry->snAgentPoeUnitPowerCapacityFree($partial)
|| {};
my $peth_power_consumed = {};
foreach my $i ( keys %$watts_total ) {
my $total = $watts_total->{$i};
next unless $total;
my $free = $watts_free->{$i} || 0;
$peth_power_consumed->{$i} = ( $total - $free ) / 1000;
}
return $peth_power_consumed;
}
sub agg_ports {
my $dev = shift;
# TODO: implement partial
my $trunks = $dev->snMSTrunkPortList;
my $ports = $dev->snSwPortIfIndex; # sw_index()
return {} unless
ref {} eq ref $trunks and scalar keys %$trunks
and ref {} eq ref $ports and scalar keys %$ports;
my $ret = {};
foreach my $m (keys %$trunks) {
my $skip = 0;
while (my $s = unpack("x${skip}n2", $trunks->{$m})) {
$ret->{ $ports->{$s} } = $ports->{$m};
$skip += 2;
}
}
return $ret;
}
sub i_stp_state {
my $foundry = shift;
my $partial = shift;
my $bp_index = $foundry->bp_index($partial);
my $stp_p_state = $foundry->dot1dStpPortState($partial);
my %i_stp_state;
foreach my $index ( keys %$stp_p_state ) {
my $state = $stp_p_state->{$index};
my $iid = $bp_index->{$index};
next unless defined $iid;
next unless defined $state;
$i_stp_state{$iid} = $state;
}
return \%i_stp_state;
}
1;
__END__
=head1 NAME
SNMP::Info::Layer3::Foundry - SNMP Interface to Brocade (Foundry) Network
Devices
=head1 AUTHOR
Max Baker
=head1 SYNOPSIS
# Let SNMP::Info determine the correct subclass for you.
my $foundry = new SNMP::Info(
AutoSpecify => 1,
Debug => 1,
DestHost => 'myswitch',
Community => 'public',
Version => 1
)
or die "Can't connect to DestHost.\n";
my $class = $foundry->class();
print "SNMP::Info determined this device to fall under subclass : $class\n";
=head1 DESCRIPTION
Abstraction subclass for Brocade (Foundry) Networks devices.
For speed or debugging purposes you can call the subclass directly, but not
after determining a more specific class using the method above.
my $foundry = new SNMP::Info::Layer3::Foundry(...);
=head2 Inherited Classes
=over
=item SNMP::Info::Layer3;
=item SNMP::Info::FDP;
=item SNMP::Info::LLDP;
=back
=head2 Required MIBs
=over
=item F<FOUNDRY-SN-ROOT-MIB>
=item F<FOUNDRY-SN-AGENT-MIB>
=item F<FOUNDRY-SN-SWITCH-GROUP-MIB>
=item F<FOUNDRY-SN-STACKING-MIB>
=item F<FOUNDRY-POE-MIB>
=item F<FOUNDRY-SN-SWITCH-GROUP-MIB>
=item Inherited Classes' MIBs
See L<SNMP::Info::Layer3/"Required MIBs"> for its own MIB requirements.
See L<SNMP::Info::FDP/"Required MIBs"> for its own MIB requirements.
See L<SNMP::Info::LLDP/"Required MIBs"> for its own MIB requirements.
=back
=head1 GLOBALS
These are methods that return scalar value from SNMP
=over
=item $foundry->model()
Returns model type. Checks $foundry->id() against the F<FOUNDRY-SN-ROOT-MIB>
and removes 'C<sn>' and 'C<Switch>'. EdgeIron models determined
through F<ENTITY-MIB>.
=item $foundry->vendor()
Returns 'brocade'
=item $foundry->os()
Returns 'brocade'
=item $foundry->os_ver()
Returns the software version
=item $foundry->mac()
Returns MAC Address of root port.
(C<ifPhysAddress.1>)
=item $foundry->chassis()
Returns Chassis type.
(C<entPhysicalDescr.1>)
=item $foundry->serial()
Returns serial number of device.
=item $foundry->temp()
Returns the chassis temperature
(C<snChasActualTemperature>)
=item $foundry->ps1_type()
Returns the Description for the power supply
(C<snChasPwrSupplyDescription.1>)
=item $foundry->ps1_status()
Returns the status of the power supply.
(C<snChasPwrSupplyOperStatus.1>)
=item $foundry->fan()
Returns the status of the chassis fan.
(C<snChasFanOperStatus.1>)
=item $foundry->img_ver()
Returns device image version.
(C<snAgImgVer.0>)
=item $foundry->ch_serial()
Returns chassis serial number.
(C<snChasSerNum.0>)
=back
=head2 Global Methods imported from SNMP::Info::Layer3
See documentation in L<SNMP::Info::Layer3/"GLOBALS"> for details.
=head2 Global Methods imported from SNMP::Info::FDP
See documentation in L<SNMP::Info::FDP/"GLOBALS"> for details.
=head2 Global Methods imported from SNMP::Info::LLDP
See documentation in L<SNMP::Info::LLDP/"GLOBALS"> for details.
=head1 TABLE METHODS
These are methods that return tables of information in the form of a
reference to a hash.
=head2 Overrides
=over
=item $foundry->interfaces()
Returns reference to hash of interface names to iids.
=item $foundry->i_ignore()
Returns reference to hash of interfaces to be ignored.
Ignores interfaces with descriptions of tunnel,loopback,null
=item $foundry->i_duplex()
Returns reference to hash of interface link duplex status.
Crosses $foundry->sw_duplex() with $foundry->sw_index()
=item $foundry->i_stp_state()
Returns the mapping of (C<dot1dStpPortState>) to the interface
index (iid).
=item $foundry->agg_ports()
Returns a HASH reference mapping from slave to master port for each member of
a port bundle on the device. Keys are ifIndex of the slave ports, Values are
ifIndex of the corresponding master ports.
=back
=head2 F<ENTITY-MIB> Information
F<ENTITY-MIB> is supported on the Brocade NetIron XMR, NetIron MLX, MLXe,
NetIron CES, NetIron CER, and older EdgeIron series devices. For other
devices which do not support it, these methods emulate Physical Table methods
using F<FOUNDRY-SN-AGENT-MIB>. See Pseudo F<ENTITY-MIB> information below
for details on brcd_e_* methods.
=over
=item $foundry->e_index()
If the device doesn't support C<entPhysicalDescr>, this will
try brcd_e_index().
Note that this is based on C<entPhysicalDescr> due to implementation
details of SNMP::Info::Entity::e_index().
=item $foundry->e_class()
If the device doesn't support C<entPhysicalClass>, this will try
brcd_e_class().
=item $foundry->e_descr()
If the device doesn't support C<entPhysicalDescr>, this will try
brcd_e_descr().
=item $foundry->e_name()
If the device doesn't support C<entPhysicalName>, this will try
brcd_e_name().
=item $foundry->e_parent()
If the device doesn't support C<entPhysicalContainedIn>, this will try
brcd_e_parent().
=item $foundry->e_pos()
If the device doesn't support C<entPhysicalParentRelPos>, this will try
brcd_e_pos().
=item $foundry->e_serial()
If the device doesn't support C<entPhysicalSerialNum>, this will try
brcd_e_serial().
=item $foundry->e_type()
If the device doesn't support C<entPhysicalVendorType>, this will try
brcd_e_type().
=item $foundry->e_vendor()
If the device doesn't support C<entPhysicalMfgName>, this will try
brcd_e_vendor().
=back
=head2 Pseudo F<ENTITY-MIB> information
These methods emulate F<ENTITY-MIB> Physical Table methods using
F<FOUNDRY-SN-AGENT-MIB>.
=over
=item $foundry->brcd_e_index()
Returns reference to hash. Key: IID, Value: Integer, Indices are combined
into an integer, each index is two digits padded with leading zero if
required.
=item $foundry->brcd_e_class()
Returns reference to hash. Key: IID, Value: General hardware type.
Returns 'stack' for the stack master in an active stack, 'chassis' for
base switches that contain modules, and 'module' for others.
=item $foundry->brcd_e_descr()
Returns reference to hash. Key: IID, Value: Human friendly name
(C<snAgentConfigModule2Description>) or
(C<snAgentConfigModuleDescription>)
=item $foundry->brcd_e_name()
Returns reference to hash. Key: IID, Value: Human friendly name
=item $foundry->brcd_e_vendor()
Returns reference to hash. Key: IID, Value: brocade
=item $foundry->brcd_e_serial()
Returns reference to hash. Key: IID, Value: Serial number
Serial number is $foundry->serial() for a stack master unit and
(C<snAgentConfigModule2SerialNumber>) or
(C<snAgentConfigModuleSerialNumber>) for all others.
=item $foundry->brcd_e_type()
Returns reference to hash. Key: IID, Value: Type of component/sub-component
as defined under C<snAgentConfigModule2Type> or C<snAgentConfigModule2Type>
in F<FOUNDRY-SN-AGENT-MIB>.
=item $foundry->brcd_e_pos()
Returns reference to hash. Key: IID, Value: The relative position among all
entities sharing the same parent.
(C<s5ChasComSubIndx>)
=item $foundry->brcd_e_parent()
Returns reference to hash. Key: IID, Value: The value of brcd_e_index()
for the entity which 'contains' this entity. A value of zero indicates
this entity is not contained in any other entity.
=back
=head2 Foundry Switch Port Information Table (C<snSwPortIfTable>)
=over
=item $foundry->sw_index()
Returns reference to hash. Maps Table to Interface IID.
(C<snSwPortIfIndex>)
=item $foundry->sw_duplex()
Returns reference to hash. Current duplex status for switch ports.
(C<snSwPortInfoChnMode>)
=item $foundry->sw_type()
Returns reference to hash. Current Port Type .
(C<snSwPortInfoMediaType>)
=item $foundry->sw_speed()
Returns reference to hash. Current Port Speed.
(C<snSwPortInfoSpeed>)
=back
=head2 Power Over Ethernet Port Table
These methods emulate the F<POWER-ETHERNET-MIB> Power Source Entity (PSE)
Port Table C<pethPsePortTable> methods using the F<FOUNDRY-POE-MIB> Power
over Ethernet Port Table C<snAgentPoePortTable>.
=over
=item $foundry->peth_port_ifindex()
Creates an index of module.port to align with the indexing of the
C<pethPsePortTable> with a value of C<ifIndex>. The module defaults 1
if otherwise unknown.
=item $foundry->peth_port_admin()
Administrative status: is this port permitted to deliver power?
C<pethPsePortAdminEnable>
=item $foundry->peth_port_status()
Current status: is this port delivering power.
=item $foundry->peth_port_class()
Device class: if status is delivering power, this represents the 802.3af
class of the device being powered.
=item $foundry->peth_port_neg_power()
The power, in milliwatts, that has been committed to this port.
This value is derived from the 802.3af class of the device being
powered.
=item $foundry->peth_port_power()
The power, in milliwatts, that the port is delivering.
=back
=head2 Power Over Ethernet Module Table
These methods emulate the F<POWER-ETHERNET-MIB> Main Power Source Entity
(PSE) Table C<pethMainPseTable> methods using the F<FOUNDRY-POE-MIB> Power
over Ethernet Port Table C<snAgentPoeModuleTable >.
=over
=item $foundry->peth_power_watts()
The power supply's capacity, in watts.
=item $foundry->peth_power_status()
The power supply's operational status.
=item $foundry->peth_power_consumption()
How much power, in watts, this power supply has been committed to
deliver.
=back
=head2 Table Methods imported from SNMP::Info::Layer3
See documentation in L<SNMP::Info::Layer3/"TABLE METHODS"> for details.
=head2 Table Methods imported from SNMP::Info::FDP
See documentation in L<SNMP::Info::FDP/"TABLE METHODS"> for details.
=head2 Table Methods imported from SNMP::Info::LLDP
See documentation in L<SNMP::Info::LLDP/"TABLE METHODS"> for details.
=cut
|