#!/usr/bin/perl # # Maintain the global caches for ARP, bridge tables, # and ether details # # $Id: 3cglobalcache,v 1.10 2000/08/17 16:03:28 trockij Exp $ # # Copyright (C) 1998 Jim Trocki # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # use A3Com::BridgeTable; use A3Com::ARP; use A3Com::EtherDetail; use Getopt::Std; sub help; sub read_list; sub update_arp_cache; sub update_bridge_table; sub update_ether_detail; getopts ("hdb:a:D:p:", \%opt); help() if ($opt{"h"}); my %GLOBALPARMS = (); if ($opt{"p"}) { $GLOBALPARMS{"GLOBALCACHEDIR"} = $opt{"p"}; } # # bridge table # update_bridge_table ($opt{"b"}) if ($opt{"b"}); # # ARP table # update_arp_cache ($opt{"a"}) if ($opt{"a"}); # # port details # update_ether_detail ($opt{"D"}) if ($opt{"D"}); exit; sub read_list { my $f = shift; open (IN, $f) || return (); my @l; while () { next if (/^\s*#/ || /^\s*$/); chomp; push (@l, $_); } close (IN); return (@l); } sub help { print < $sw, GLOBALCACHE => 0, CACHE => 0, %GLOBALPARMS, ); if (!defined $n) { # error next; } my %a = $n->arp_table; if ($n->error ne "") { print STDERR "could not get ARP table for $sw: " . $n->error . "\n"; next; } $n->globalcache (1); $n->file_write; if ($n->error ne "") { # error writing print STDERR "error writing global arp cache: " . $n->error . "\n"; next; } my $h = $n->load_history (); if ($n->error ne "") { # error reading } $h = $n->merge_current_with_history (\%a, $h, time); $n->save_history ($h); if ($n->error ne "") { # error writing print STDERR "error writing global arp history for $sw: " . $n->error . "\n"; next; } } } sub update_bridge_table { my $sw = shift; print "BRIDGETABLE $sw\n" if ($opt{"d"}); my $n = new A3Com::BridgeTable ( SWITCH => $sw, GLOBALCACHE => 0, CACHE => 0, %GLOBALPARMS, ); my %bt = $n->btable; if ($n->error ne "") { print STDERR "could not load bridge table for $sw: " . $n->error . "\n"; return undef; } $n->globalcache (1); $n->file_write; if ($n->error ne "") { # error writing print STDERR "error writing global bridge cache for $sw: " . $n->error . "\n"; return undef; } my %h = $n->load_history; if ($n->error ne "") { print STDERR "error reading historical bridge cache for $sw: " . $n->error . "\n"; return undef; } my %merged = $n->merge_current_with_history (\%bt, \%h, scalar (time)); if ($n->hist_start == undef) { $n->hist_start (time); } $n->save_history (\%merged); if ($n->error ne "") { print STDERR "error writing historical bridge cache for $sw: " . $n->error . "\n"; return undef; } } sub update_ether_detail { my $f = shift; @detail_list = read_list ($f); foreach my $sw (@detail_list) { } }