Commit 2c9ae239 authored by Robert Ricci's avatar Robert Ricci
Browse files

Add a new option, -N, which prints out the name of the VLAN number

assoicated with the named VLAN..

Output format:
<vlan_name> <stack> <vlan_number>
(This is so the user can, if they want, look for more than one
VLAN on more than one stack at a time.)

This should make some of the control-net firewall code cleaner.

For now, though, it's pretty inefficient, becuase it calls listVlans()
on the whole stack, which is much more than needed. But, a more efficient
implementation will require a change to the switch/stack API.
parent 6ca653cc
......@@ -47,6 +47,7 @@ Usage: $0 [-h] [-v] [-q] [-n] [-i device] [-S stack]
[-T port name]
[-U port]
[-o name]
[ -N name]
[-r pid eid]
[-t pid eid]
[-d ports] [-e ports] [-a ports]
......@@ -78,6 +79,7 @@ VLAN Control:
-z <port> Used with -y and -x, to specify which port is to be used
with the private VLAN
-o <name> Delete the VLAN with name <name>
-N <name> Print out the VLAN number for the named VLAN
-c Delete ALL VLANs, and recreate from the database. ** USE
WITH EXTREME CAUTION **
......@@ -106,8 +108,9 @@ END
my %opt = ();
Getopt::Long::Configure("no_ignore_case");
GetOptions(\%opt, 'a','c','d','e','b','B=s@','g','h','i=s@','l','m=s@','M','n','o=s@',
'p=s','q','r','s', 'S=s@', 't','T=s','u=s','U','v=s','w','y=s','x=s','z=s');
GetOptions(\%opt, 'a','c','d','e','b','B=s@','g','h','i=s@','l','m=s@','M','n',
'N=s@','o=s@','p=s','q','r','s', 'S=s@', 't','T=s','u=s','U','v=s','w',
'y=s','x=s','z=s');
# Unused: f,j
if ($opt{h}) {
......@@ -221,6 +224,12 @@ if ($opt{o}) {
}
}
if ($opt{N}) {
foreach my $name (@{$opt{N}}) {
push @commands, ["vlannumber",$name];
}
}
if ($opt{B}) {
foreach my $statstring (@{$opt{B}}) {
push @commands, ["restorestatus",$statstring];
......@@ -429,7 +438,7 @@ foreach my $command (@commands) {
my @devicenames;
my @vlans;
SWITCH: for ($operation) {
(/listvlans/ || /getstats/ || /make/ || /remove/) && do {
(/listvlans/ || /getstats/ || /make/ || /remove/ || /vlannumber/) && do {
@devicenames = $supplied_switches?
@supplied_switches : getTestSwitches();
last;
......@@ -668,6 +677,11 @@ foreach my $command (@commands) {
$exitval += doPortStatus(\@stacks,@ports);
last;
}; # /portstatus/ && do
/vlannumber/ && do {
my ($vlan_name) = @args;
$exitval += doVlanNumber(\@stacks,$vlan_name);
last;
}; # /portstatus/ && do
/restorestatus/ && do {
$exitval += doRestorePortStatus(\@stacks,@args);
last;
......@@ -1263,6 +1277,44 @@ sub doDeleteVlan($@) {
return $errors;
}
#
# Print the device-dependant VLAN number for a given named VLAN
#
sub doVlanNumber ($$) {
my $stacks = shift;
my $name = shift;
my $found = 0;
#
# Allow the user to give us multiple stacks
#
foreach my $stack (@$stacks) {
#
# TODO: This is horrendously inefficient! But, it allows me to write
# this function without requiring more from the switch/stack modules.
# Once a specialized function has been added to the switch/stack API,
# we should use it here.
#
my @vlanList = $stack->listVlans();
foreach my $vlan (@vlanList) {
my ($id,$ddep,$memberref) = @$vlan;
if ($id eq $name) {
$found = 1;
print "$name $stack->{STACKID} $ddep\n";
}
}
}
if ($found) {
return 0;
} else {
return 1;
}
}
#
# Send $command to @ports.
# TODO: List of commands
......
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