An indication of which Virtual LANs are allowed on this Inter-Switch Link. This is an octet string value with bits set to indicate allowed VLANs. It can be interpreted as a sum of f(x) as x goes from 0 to 1023, where f(x) = 0 for VLAN x not allowed and f(x) = exp(2, x) for VLAN x allowed.
Some genius wrote that documentation, presumably thinking it was wonderfully precise, without specifying the order of bits in the 'octet string'
If we make the flying assumption that the '0xfff...fe' is a 1024 bit number, and not an 'octet string' at all, then we can go to and from a Perl bit-vector string, and use vec to access it, as in the code below.
The result is:
Ranges: 1..1023which looks plausible. But a value with a few more '0' bits in it would be a stronger test.
use strict ; use warnings ; #1234567890123456789012345678901234567890123456789012345 +678901234 my $vlans = '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff +fffffffff' .'fffffffffffffffffffffffffffffffffffffffffffffffffffffff +fffffffff' .'fffffffffffffffffffffffffffffffffffffffffffffffffffffff +fffffffff' .'fffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffe' ; my $vlan_vec = to_vec($vlans) ; # Convert long hex integer to bit-vect +or # VLAN numbers are mapped to/from $vlan_vec by vec($vlan_vec, 1, $vn) # This scans the bit-vector looking for ranges of VLAN numbers. # # Note that we can read one bit beyond the given range, and get 0 my $r = undef ; my @s = () ; for my $vn (0..length($vlan_vec) * 8) { if (vec($vlan_vec, $vn, 1)) { if (!defined($r)) { push @s, "$vn.." ; } ; $r = $vn ; } else { if (defined($r)) { $s[-1] .= "$r" ; $r = undef ; } ; } ; } ; print "Ranges: ", join(', ', @s), "\n" ; # Convert long hex integer to bit-vector. # # Combination of 'h*' and reverse gives bits in right order in the bit +-vector. sub to_vec { my ($hex) = @_ ; $hex =~ s/^0x// ; return pack('h*', scalar reverse $hex) ; } ; # Convert bit-vector to long integer. Again 'h*' and reverse sorts ou +t bit order. sub from_vec { my ($vec) = @_ ; return '0x'. scalar reverse(unpack('h*', $vec)) ; } ;
In reply to Re: Allowed VLANs with SNMP
by gone2015
in thread Allowed VLANs with SNMP
by spivey49
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |