#!/usr/bin/perl # # Identify stale (unused) ports on a bridge, based on # bridge table history # # $Id: stale-ports,v 1.2 2000/11/11 16:27:41 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 Getopt::Std; use Date::Manip; sub help; getopts ("hdDp:t:", \%opt); help() if ($opt{"h"}); my %GLOBALPARMS = (); if ($opt{"p"}) { $GLOBALPARMS{"GLOBALCACHEDIR"} = $opt{"p"}; } my $old_date = 0; if ($opt{"t"} ne "") { $old_date = UnixDate (ParseDate ($opt{"t"}), '%s'); } if (!defined $old_date) { die "error parsing date\n"; } my @BRIDGES; foreach my $arg (@ARGV) { if ($arg eq "-") { while () { next if (/^\s*#/); chomp; push (@BRIDGES, $_); } } else { push (@BRIDGES, $arg); } } foreach my $bridge (@BRIDGES) { my $n = new A3Com::BridgeTable ( SWITCH => $bridge, GLOBALCACHE => 0, CACHE => 0, %GLOBALPARMS, ); my %h = $n->load_history; if ($n->error ne "") { print STDERR "error for $bridge: " . $n->error . "\n"; next; } my @unused_ports; # # find "stale" ports # for (my $p = 1; $p < 38; $p++) { # # no address ever learned # if (!defined $h{$p}) { push (@unused_ports, $p); next; } # # look for aged ports # my $old = 1; foreach my $mac (keys %{$h{$p}}) { $old = 0 if ($h{$p}->{$mac} >= $old_date); } push (@unused_ports, $p) if ($old); } my $st = localtime ($n->hist_start); my $port_str; if (@unused_ports == 0) { $port_str = "no free ports"; } else { $port_str = "@unused_ports"; } if ($opt{"D"}) { printf ("%-10s (%s) %s\n", $bridge, $st, $port_str); } else { printf ("%s %s\n", $bridge, $port_str); } } exit; sub help { print <