@@ -1228,6 +1228,9 @@ sub _getLLDPInfo {
12281228 my $logger = $params {logger };
12291229
12301230 my $results ;
1231+ my $lldpLocPortIdType = $device -> walk(' .1.0.8802.1.1.2.1.3.7.1.2' );
1232+ my $lldpLocPortId = $device -> walk(' .1.0.8802.1.1.2.1.3.7.1.3' );
1233+ my $lldpLocPortDesc = $device -> walk(' .1.0.8802.1.1.2.1.3.7.1.4' );
12311234 my $ChassisIdSubType = $device -> walk(' .1.0.8802.1.1.2.1.4.1.1.4' );
12321235 my $lldpRemChassisId = $device -> walk(' .1.0.8802.1.1.2.1.4.1.1.5' );
12331236 my $lldpRemPortIdSubtype = $device -> walk(' .1.0.8802.1.1.2.1.4.1.1.6' );
@@ -1241,6 +1244,55 @@ sub _getLLDPInfo {
12411244 $device -> walk(' .1.3.6.1.4.1.9.5.1.4.1.1.11.1' ) || # Cisco portIfIndex
12421245 $device -> walk(' .1.3.6.1.2.1.17.1.4.1.2' ); # dot1dBasePortIfIndex
12431246
1247+ # Update/fix port to interface mapping
1248+ if ($lldpLocPortIdType && $lldpLocPortId && $lldpLocPortDesc && $params {ports }) {
1249+ my %portId ;
1250+ my %portDesc ;
1251+ my %ignore ;
1252+ # Firstly index know ports IFNAME and MAC as portid and IFDESCR as port description
1253+ # Always ignore duplicated values
1254+ foreach my $port (keys (%{$params {ports }})) {
1255+ next if empty($params {ports }-> {$port }-> {IFNAME });
1256+ my $name = $params {ports }-> {$port }-> {IFNAME };
1257+ $portId {$name } = $port ;
1258+ unless (empty($params {ports }-> {$port }-> {MAC })) {
1259+ my $mac = getCanonicalMacAddress($params {ports }-> {$port }-> {MAC });
1260+ if ($mac ) {
1261+ if (defined ($portId {$mac })) {
1262+ delete $portId {$mac };
1263+ $ignore {$mac } = 1;
1264+ }
1265+ $portId {$mac } = $port unless $ignore {$mac };
1266+ }
1267+ }
1268+ unless (empty($params {ports }-> {$port }-> {IFDESCR })) {
1269+ my $descr = $params {ports }-> {$port }-> {IFDESCR };
1270+ if (defined ($portDesc {$descr })) {
1271+ delete $portDesc {$descr };
1272+ $ignore {$descr } = 1;
1273+ }
1274+ $portDesc {$descr } = $port unless $ignore {$descr };
1275+ }
1276+ }
1277+ # Then update port2interface with expected interface
1278+ foreach my $port (keys (%{$lldpLocPortIdType })) {
1279+ my $type = $lldpLocPortIdType -> {$port };
1280+ my $portid = $type == 3 ? getCanonicalMacAddress($lldpLocPortId -> {$port })
1281+ : getCanonicalString($lldpLocPortId -> {$port });
1282+ # First try to match on portid
1283+ if ($portid && $portId {$portid }) {
1284+ $port2interface -> {$port } = $portId {$portid };
1285+ next ;
1286+ }
1287+ # Fallback on IFDESCR matching
1288+ my $descr = getCanonicalString($lldpLocPortDesc -> {$port });
1289+ if ($descr && $portDesc {$descr }) {
1290+ $port2interface -> {$port } = $portDesc {$descr };
1291+ next ;
1292+ }
1293+ }
1294+ }
1295+
12441296 # each lldp variable matches the following scheme:
12451297 # $prefix.x.y.z = $value
12461298 # whereas y is either a port or an interface id
0 commit comments