Index: /trunk/klask
===================================================================
--- /trunk/klask	(revision 270)
+++ /trunk/klask	(revision 271)
@@ -527,6 +527,6 @@
          }
 
-      my $swport_num = $result->{$research1};
-      my $swport_hr = snmp_get_switchport_num2hr($session, $swport_num);
+      my $swport_id = $result->{$research1};
+      my $swport_hr = snmp_get_switchport_id2hr($session, $swport_id);
 
       $session->close;
@@ -547,5 +547,5 @@
       $ret{'switch_hostname'}    = $sw->{'hostname'};
       $ret{'switch_description'} = $sw->{'description'};
-      $ret{'switch_port_id'}     = $swport_num;
+      $ret{'switch_port_id'}     = $swport_id;
       $ret{'switch_port_hr'}     = $swport_hr; # human readable
 
@@ -583,6 +583,6 @@
 
       if (defined $result and $result->{$research1} ne 'noSuchInstance') {
-         my $swport_num = $result->{$research1};
-         my $swport_hr = snmp_get_switchport_num2hr($session, $swport_num);
+         my $swport_id = $result->{$research1};
+         my $swport_hr = snmp_get_switchport_id2hr($session, $swport_id);
 
          SWITCH_PORT_IGNORE:
@@ -597,5 +597,5 @@
          $ret->{$sw->{'hostname'}}{'hostname'}    = $sw->{'hostname'};
          $ret->{$sw->{'hostname'}}{'description'} = $sw->{'description'};
-         $ret->{$sw->{'hostname'}}{'port'}        = $swport_num;
+         $ret->{$sw->{'hostname'}}{'port'}        = $swport_id;
          $ret->{$sw->{'hostname'}}{'port_hr'}     = $swport_hr;
          }
@@ -716,31 +716,31 @@
 
 #---------------------------------------------------------------
-sub snmp_get_switchport_num2hr {
-   my ($snmp_session, $swport_num) = @_;
-
-   # On H3C, port number and port index are not the same
+sub snmp_get_switchport_id2hr {
+   my ($snmp_session, $swport_id) = @_;
+
+   # On H3C, port id (port_id) and port index (port_ix) are not the same
    # Double SNMP request to get the name
-   # First get the index, second get the name
-
-   my $research_index = $OID_NUMBER{'ifIndex'} .'.'. $swport_num;
-   my $result_index = $snmp_session->get_request(
-      -varbindlist => [$research_index]
+   # First get the index, second get the name (port_hr)
+
+   my $research_ix = $OID_NUMBER{'ifIndex'} .'.'. $swport_id;
+   my $result_ix = $snmp_session->get_request(
+      -varbindlist => [$research_ix]
       );
 
-   my $swport_index = $swport_num;
-   $swport_index = $result_index->{$research_index} if defined $result_index;
-
-   return snmp_get_switchport_index2hr($snmp_session, $swport_index);
-   }
-
-#---------------------------------------------------------------
-sub snmp_get_switchport_index2hr {
-   my ($snmp_session, $swport_index) = @_;
-
-   my $research_hr = $OID_NUMBER{'ifName'} .'.'. $swport_index;
+   my $swport_ix = $swport_id;
+   $swport_ix = $result_ix->{$research_ix} if defined $result_ix;
+
+   return snmp_get_switchport_ix2hr($snmp_session, $swport_ix);
+   }
+
+#---------------------------------------------------------------
+sub snmp_get_switchport_ix2hr {
+   my ($snmp_session, $swport_ix) = @_;
+
+   my $research_hr = $OID_NUMBER{'ifName'} .'.'. $swport_ix;
    my $result_hr = $snmp_session->get_request(
       -varbindlist => [$research_hr]
       );
-   my $swport_hr = $swport_index;
+   my $swport_hr = $swport_ix;
    $swport_hr = normalize_port_human_readable($result_hr->{$research_hr}) if defined $result_hr;
 
@@ -757,5 +757,5 @@
          # IEEE8023-LAG-MIB::dot3adAggPortAttachedAggID.28 = INTEGER: 337
          my $port_aggregator_index = $snmp_session->var_bind_list->{$oid_current};
-         my ($current_port_index) = reverse split /\./, $oid_current; # last number
+         my ($current_port_ix) = reverse split /\./, $oid_current; # last number
 
          # prepare next loop item
@@ -763,7 +763,7 @@
 
          next LOOP_ON_OID_PORT if $port_aggregator_index == 0;
-         next LOOP_ON_OID_PORT if not $port_aggregator_index == $swport_index;
-
-         my $current_port_name = snmp_get_switchport_index2hr($snmp_session, $current_port_index);
+         next LOOP_ON_OID_PORT if not $port_aggregator_index == $swport_ix;
+
+         my $current_port_name = snmp_get_switchport_ix2hr($snmp_session, $current_port_ix);
          $swport_hr .= "$SEP_AGGREGATOR_PORT$current_port_name";
          }
@@ -774,5 +774,5 @@
 #---------------------------------------------------------------
 # Reverse search port number
-sub snmp_get_switchport_hr2num {
+sub snmp_get_switchport_hr2id {
    my ($snmp_session, $swport_hr, $verbose) = @_;
 
@@ -781,17 +781,17 @@
    ($swport_hr) = split /$SEP_AGGREGATOR_PORT/, $swport_hr;
 
-   my $swport_num = $swport_hr;
+   my $swport_id = $swport_hr;
    # direct return if already numeric (next loop is expensive) / old or simple switch
-   return $swport_num if $swport_num =~ m/^\d+$/;
-
-   my $research_index = $OID_NUMBER{'ifIndex'}; # base OID
-   my @args = ( -varbindlist =>  [$research_index]);
+   return $swport_id if $swport_id =~ m/^\d+$/;
+
+   my $research_ix = $OID_NUMBER{'ifIndex'}; # base OID
+   my @args = ( -varbindlist =>  [$research_ix]);
    LOOP_ON_OID_PORT:
    while ( defined $snmp_session->get_next_request(@args) ) {
       my ($oid_current) = $snmp_session->var_bind_names;
-      last LOOP_ON_OID_PORT if  not Net::SNMP::oid_base_match($research_index, $oid_current);
+      last LOOP_ON_OID_PORT if  not Net::SNMP::oid_base_match($research_ix, $oid_current);
       
       my $port_ifIndex = $snmp_session->var_bind_list->{$oid_current};
-      my ($port_index) = reverse split /\./, $oid_current; # last number
+      my ($port_ix) = reverse split /\./, $oid_current; # last number
       printf "PORT1: %s => %s\n", $oid_current, $port_ifIndex if $verbose;
 
@@ -806,12 +806,12 @@
       printf "PORT2: $oid_ifName => $current_port_hr\n" if $verbose;
       if ($current_port_hr eq $swport_hr) {
-         print "PORT3: $current_port_hr <-> $port_index\n" if $verbose;
+         print "PORT3: $current_port_hr <-> $port_ix\n" if $verbose;
          
          # return port number ifIndex need by OID portUpDown
-         $swport_num = $port_ifIndex; # other possible value could be $port_index
+         $swport_id = $port_ifIndex; # other possible value could be $port_ix
          last LOOP_ON_OID_PORT;
          }
       }
-   return $swport_num;
+   return $swport_id;
    }
 
@@ -2329,8 +2329,8 @@
 
    # Retrieve numeric port value
-   my $port_num = snmp_get_switchport_hr2num($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
-   die "Error : Port $port does not exist on switch $switch_name\n" if not $port_num =~ m/^\d+$/;
-
-   my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_num;
+   my $port_id = snmp_get_switchport_hr2id($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
+   die "Error : Port $port does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/;
+
+   my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
    print "Info: switch $switch_name port $port SNMP OID $search_portstatus\n" if $verbose;
 
@@ -2374,8 +2374,8 @@
 
    # Retrieve numeric port value
-   my $port_num = snmp_get_switchport_hr2num($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
-   die "Error : Port $port does not exist on switch $switch_name\n" if not $port_num =~ m/^\d+$/;
-
-   my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_num;
+   my $port_id = snmp_get_switchport_hr2id($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
+   die "Error : Port $port does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/;
+
+   my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
    print "Info: switch $switch_name port $port SNMP OID $search_portstatus\n" if $verbose;
 
@@ -2417,9 +2417,9 @@
 
    # Retrieve numeric port value
-   my $port_num = snmp_get_switchport_hr2num($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
-   die "Error : Port $port does not exist on switch $switch_name\n" if not $port_num =~ m/^\d+$/;
-
-   my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_num;
-   print "Info: switch $switch_name port $port ($port_num) SNMP OID $search_portstatus\n" if $verbose;
+   my $port_id = snmp_get_switchport_hr2id($session, normalize_port_human_readable($port), $verbose ? 'yes' : '');
+   die "Error : Port $port does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/;
+
+   my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
+   print "Info: switch $switch_name port $port ($port_id) SNMP OID $search_portstatus\n" if $verbose;
 
    my $result = $session->get_request(
@@ -2484,6 +2484,6 @@
 
       if (defined $result and $result->{$research1} ne 'noSuchInstance') {
-         my $swport_num = $result->{$research1};
-         my $swport_hr = snmp_get_switchport_num2hr($session, $swport_num);
+         my $swport_id = $result->{$research1};
+         my $swport_hr = snmp_get_switchport_id2hr($session, $swport_id);
          print "Klask find MAC $mac_address on switch $sw_name port $swport_hr\n";
          }
