Commit 22f0f035 authored by Mac Newbold's avatar Mac Newbold

Added -u parameter to allow waiting for switch table to update, and

confirm new setting. Useful for when you cut off your own connection...
parent 418152bd
......@@ -27,6 +27,7 @@ my $l = 0; #List all VLANs on switch
my $m = ""; #Create VLAN - name
my @vlan = (); #VLAN Members - list of MAC Addresses
my @r = (); #VLAN(s) to be removed
my $u = 0; #Wait for Update of VLAN tables
my $b = 0; #Block (bool) (two-way switch)
my $c = 1; #Confirm Changes (bool) (two-way switch)
my $v = 0; #Verbose (bool) !Must default quiet; switch only turns on!
......@@ -39,7 +40,7 @@ my $all=0;
my @outlets=();
my %Interfaces=();
&ParseArgs(*ARGV,*i,*p,*d,*e,*a,*dup,*s,*f,*l,*m,*vlan,*r,*b,*c,*v,
&ParseArgs(*ARGV,*i,*p,*d,*e,*a,*dup,*s,*f,*l,*m,*vlan,*r,*u,*b,*c,*v,
*on,*off,*cyc,*all,*outlets,*Interfaces);
use lib '/n/moab/x/newbold/ucd-snmp-4.1.1/perl/SNMP/blib/lib';
......@@ -123,11 +124,11 @@ if (@vlan) {
#This is to make ONE vlan - for multiple, use -f AutoVLAN from file
&GetToken(\$sess,\$v);
&OneVLAN(\$sess,\$m,\@vlan,\$v);
&ReleaseToken(\$sess,\$v);
&ReleaseToken(\$sess,\$v,\$u);
}
if ($f) {
&AutoVLANConfig(\$sess,\$f,\$v);
&AutoVLANConfig(\$sess,\$f,\$v,\$u);
}
if (@r) {
......@@ -136,7 +137,7 @@ if (@r) {
{
&RemoveVLAN(\$sess,\$x,\$v);
}
&ReleaseToken(\$sess,\$v);
&ReleaseToken(\$sess,\$v,\$u);
}
#List VLANs is always after $f and @vlan, so that changes made are reflected...
......@@ -186,7 +187,7 @@ if ($off || $on || $cyc) {
# SUB PARSEARGS----------------------
#
sub ParseArgs {
local(*CMDS,*i,*p,*d,*e,*a,*dup,*s,*f,*l,*m,*vlan,*r,*b,*c,*v,
local(*CMDS,*i,*p,*d,*e,*a,*dup,*s,*f,*l,*m,*vlan,*r,*u,*b,*c,*v,
*on,*off,*cyc,*all,*outlets,*Interfaces) = @_;
my $help=0;
if (@CMDS < 1) {$help = 2; }
......@@ -222,6 +223,7 @@ sub ParseArgs {
elsif (/^-d(.*)/) {$d = 1;}
elsif (/^-e(.*)/) {$e = 1;}
elsif (/^-l(.*)/) {$l = 1;}
elsif (/^-u(.*)/) {$u = 1;}
elsif (/^-f(.*)/) {$f = ($1 ? $1 : shift(@CMDS));}
elsif (/^-m(.*)/) {$m = ( !(@CMDS==0 || $CMDS[0] =~ /^(-|\+)(.*)/) ?
($1 ? $1 : shift(@CMDS)) : "");}
......@@ -277,6 +279,7 @@ sub ParseArgs {
" -m Make a VLAN\n",
" -vlan Add MAC Address to VLAN\n",
" -r Remove VLAN(s)",
" -u Wait for Update of VLAN tables (takes about 20 seconds)\n",
" -on Turn on outlets\n",
" -off Turn off outlets\n",
" -cyc Power Cycle outlets\n",
......@@ -400,19 +403,46 @@ sub UpdateField {
#
sub ReleaseToken {
local(*sess,*v) = @_;
local(*sess,*v,*u) = @_;
my $TokenRelease = '.1.3.6.1.4.1.343.6.11.4.8';
my $TokenReleaseResult = '.1.3.6.1.4.1.343.6.11.4.9';
$sess->set([[$TokenRelease,0,"save","INTEGER"]]);
my $TokenConfirmState = '.1.3.6.1.4.1.343.6.11.1.18';
my $save = ($u ? "saveWithConfirmOption" : "save");
print "Releasing Token with $save command\n" if ($v);
$sess->set([[$TokenRelease,0,$save,"INTEGER"]]);
$RetVal = $sess->get([[$TokenReleaseResult,0]]);
print "VLAN Configuration Save Result is $RetVal\n" if ($v);
while ($RetVal eq "notReady") {
$RetVal = $sess->get([[$TokenReleaseResult,0]]);
print "VLAN Configuration Save Result is $RetVal\n" if ($v);
select (undef, undef, undef, .25); #wait 1/4 second
}
if ($RetVal ne 'success') {
die("VLAN Reconfiguration Failed. No changes saved.\n");
}
if ($u) {
$RetVal = $sess->get([[$TokenConfirmState,0]]);
print "VLAN Configuration Confirm Result is $RetVal\n" if ($v);
while ($RetVal eq "notReady") {
sleep(2);
$RetVal = $sess->get([[$TokenConfirmState,0]]);
print "VLAN Configuration Confirm Result is $RetVal\n" if ($v);
}
if ($RetVal eq "ready")
{
$RetVal = $sess->set([[$TokenConfirmState,0,"confirm","INTEGER"]]);
print "VLAN Configuration Confirm Result is $RetVal\n" if ($v);
}
while (!($RetVal =~ /Conf/i)) {
$RetVal = $sess->get([[$TokenConfirmState,0]]);
print "VLAN Configuration Confirm Result is $RetVal\n" if ($v);
}
if ($RetVal ne "confirmedNewConf") {
die("VLAN Reconfiguration Failed. No changes saved.\n");
}
} else {
if ($RetVal ne 'success') {
print "VLAN Configuration Save Result is $RetVal\n" if ($v);
die("$RetVal VLAN Reconfiguration Failed. No changes saved.\n");
}
}
}
#
......@@ -428,12 +458,12 @@ sub GetToken {
my $TokenReleaseResult = '.1.3.6.1.4.1.343.6.11.4.9';
my $Num = pack("C*",0,0,0,0,1,1);
#The zeros and ones are a magic number it needs...
my $RetVal = $sess->set([[$TokenReq,0,$Num,"OCTETSTR"]]);
print "VLAN Token Claim Result is $RetVal\n" if ($v);
$RetVal = $sess->get([[$TokenReqResult,0]]);
$sess->set([[$TokenReq,0,$Num,"OCTETSTR"]]);
my $RetVal = $sess->get([[$TokenReqResult,0]]);
while ($RetVal eq "notReady") {
$RetVal = $sess->get([[$TokenReqResult,0]]);
print "VLAN Token Claim Result is $RetVal\n" if ($v);
select (undef, undef, undef, .25); #wait 1/4 second
}
print "VLAN Token Claim Result is $RetVal\n" if ($v);
if ($RetVal ne 'success') {
......@@ -459,7 +489,7 @@ sub OneVLAN {
$RetVal = $sess->set([[$CreateOID,$Vlan,$m,"OCTETSTR"]]);
print "",($RetVal? "Succeeded":"Failed"),".\n";
if (! defined ($RetVal) ) {
&ReleaseToken(*sess,*v);
&ReleaseToken(*sess,*v,1);
die("VLAN name \"$m\" not unique.\n");
}
my @x;
......@@ -485,7 +515,7 @@ sub OneVLAN {
#
sub AutoVLANConfig {
local(*sess,*f,*v) = @_;
local(*sess,*f,*v,*u) = @_;
my @VLANS= ();
&ReadIRFile(*f,\@VLANS);
&GetToken(*sess,*v);
......@@ -494,7 +524,7 @@ sub AutoVLANConfig {
@vlan = @{shift(@VLANS)};
&OneVLAN(*sess,*m,*vlan,*v);
}
&ReleaseToken(*sess,*v);
&ReleaseToken(*sess,*v,\$u);
}
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment