interface 1.79 KB
Newer Older
Alexander Gall's avatar
Alexander Gall committed
1 2 3 4 5 6
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Snabb::SNMP::Agent qw(%persistent_ifIndex %compound_scalar_handlers $sysUpTime);
my %opt = ( 'check-interval' => 5,
7
            'shmem-dir' => '/var/lib/snabb/shmem', );
Alexander Gall's avatar
Alexander Gall committed
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

sub usage() {
  print <<"EOF";
usage: $0 --ifindex=<file>
EOF
  exit(1);
}

sub ifTable_indexer($$$) {
  ## Force persistent ifIndex based on ifDescr
  my ($oid, $table_oid, $segment) = @_;
  my $ifDescr_obj = $segment->{objs}{ifDescr};
  defined $ifDescr_obj or die
    "ifTable IID indexer: no ifDescr present for $segment->{name}";
  tie my $ifDescr, 'Snabb::SNMP::Tie::OCTETSTR', $segment,
    'ifDescr';
  my $ifIndex = $persistent_ifIndex{$ifDescr};
  defined $ifIndex or die
    "ifTable IID indexer: unknown interface $ifDescr";
  return($oid.".".$ifIndex);
}

my %subtrees =
  ( interfaces =>
    { tables =>
      { scalars =>
	{ handlers =>
	  { ifNumber =>
	    { compound_handler => sub {
		return scalar(keys(%persistent_ifIndex));
	      }
	    },
	  },
	},
	ifTable => { indexer => \&ifTable_indexer },
      },
    },

    ifMIB =>
    { tables =>
      { scalars =>
	{ handlers =>
	  { ifTableLastChange =>
	    { compound_handler => sub {
		return $sysUpTime;
	      }
	    },
	  },
	},
	ifXTable => { indexer => \&ifTable_indexer },
      },
    },
  );

GetOptions(\%opt, "check-interval=i",
63
           "ifindex=s", "shmem-dir=s") or usage();
Alexander Gall's avatar
Alexander Gall committed
64
defined $opt{ifindex} or usage();
65
Snabb::SNMP::Agent::start({ name => "interface",
Alexander Gall's avatar
Alexander Gall committed
66 67 68 69 70 71 72 73 74 75 76 77 78
                            subtrees => \%subtrees,
			    check_interval => $opt{'check-interval'},
			    if_index => $opt{ifindex},
                            mibs_dirs => '',
                            mibs => '',
                            shmem_dir => $opt{'shmem-dir'},
			  });

## Not reached

## Local Variables:
## mode: CPerl
## End: