Mailing List Archive

code to determine IfIndex
If you build your own internal management tools, you may have found the
following page lacking in useful details:
https://www.force10networks.com/CSPortal20/KnowledgeBase/SNMPFAQ.aspx

Well, using that information and snmpwalk output, I found the following
code to determine the IfIndex.

The only gotcha is that you really need to know the card type to get the
interface index, which I think blows chunks. So to use this script you
may need to modify the cardtype value to match your environment. The
script as published below assumings slot 0-1 contains 24-port SFP cards,
and all other slots contain 48-port copper cards.

#!/usr/local/bin/perl
my $slot = $ARGV[0];
my $port = $ARGV[1];

my $cardtype = 49209; # bits 1-18
if( $slot < 2 ) {
$cardtype = 49208; # sfp cards in slot 0-1
}
my $portmultiply = 262144; # bits 19-25
my $slotmultiply = 33554432; # bits 26-30

my $ifindex = ( ($slot + 1) * $slotmultiply) + ( ($port + 1) *
$portmultiply) + $cardtype;

print "Ifindex for gi${slot}/${port} = $ifindex\n";

exit 0;

--
Jo Rhett
senior geek
Silicon Valley Colocation
code to determine IfIndex [ In reply to ]
On 6/19/07, Jo Rhett <jrhett at svcolo.com> wrote:
> If you build your own internal management tools, you may have found the
> following page lacking in useful details:
> https://www.force10networks.com/CSPortal20/KnowledgeBase/SNMPFAQ.aspx
>
> Well, using that information and snmpwalk output, I found the following
> code to determine the IfIndex.
>
> The only gotcha is that you really need to know the card type to get the
> interface index, which I think blows chunks. So to use this script you
> may need to modify the cardtype value to match your environment. The
> script as published below assumings slot 0-1 contains 24-port SFP cards,
> and all other slots contain 48-port copper cards.

I apologize if I'm having a major brain fart and just not realizing it
-- but wouldn't one rather work the other way. Meaning, lets
discover/poll the device, get the ifIndexes, and then calculate
everything?

aaron
code to determine IfIndex [ In reply to ]
> On 6/19/07, Jo Rhett <jrhett at svcolo.com> wrote:
>> If you build your own internal management tools, you may have
>> found the
>> following page lacking in useful details:
>> https://www.force10networks.com/CSPortal20/KnowledgeBase/
>> SNMPFAQ.aspx
>>
>> Well, using that information and snmpwalk output, I found the
>> following
>> code to determine the IfIndex.
>>
>> The only gotcha is that you really need to know the card type to
>> get the
>> interface index, which I think blows chunks. So to use this
>> script you
>> may need to modify the cardtype value to match your environment. The
>> script as published below assumings slot 0-1 contains 24-port SFP
>> cards,
>> and all other slots contain 48-port copper cards.

On Aug 1, 2007, at 10:46 AM, Aaron Glenn wrote:
> I apologize if I'm having a major brain fart and just not realizing it
> -- but wouldn't one rather work the other way. Meaning, lets
> discover/poll the device, get the ifIndexes, and then calculate
> everything?

Yes. Poll the device and get the card types, then adjust the script.

The issue is when you want to do random/ad-hoc queries, you don't
want to do a full discovery every time. In my experience a full pull
of all switch ports takes 20 seconds to finish. This allows you to
determine the right thing to query quickly, when you want an instant
direct query of something on the switch.

--
Jo Rhett
senior geek

Silicon Valley Colocation
Support Phone: 408-400-0550