Commit 06c2f12b authored by Weibin Sun's avatar Weibin Sun
Browse files

Openflow OIDs can be used in snmpit_hp now, so the functions can act...

Openflow OIDs can be used in snmpit_hp now, so the functions can act correctly. Command line options configuration is changed to use only one vlanname for each OF command. The order of OF support checking and finding VLan is changed so that stack module will find vlan first, then check OF support. Thus there will not be an error msg for OF unsupported even if the vlan is not on the switch.
parent be6a40e3
......@@ -82,10 +82,10 @@ Usage: $0 [-h] [-v level] [-q] [-n] [-i device] [-S stack]
[-d ports] [-e ports] [-a ports]
[-p <10|100|1000> ports] [-u <half|full> ports]
[-c]
[--of-disable vlan]
[--of-enable vlan]
[--of-controller vlan tcp:ip:port]
[--of-listener vlan ptcp:ip:port]
[--of-disable name pid eid]
[--of-enable name pid eid]
[--of-controller name pid eid tcp:ip:port]
[--of-listener name pid eid ptcp:ip:port]
General:
-h Display this help message
-v <level> Verbose mode
......@@ -168,7 +168,7 @@ 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','E=s','T=s','u=s','U','v=s','w',
'y=s','x=s','z=s','F','L=s','O', 'D', 'R', 'f', 'X', 'vlan_tag=i',
'of-disable=s@', 'of-enable=s@', 'of-controller=s@', 'of-listener=s@');
'of-disable=s', 'of-enable=s', 'of-controller=s', 'of-listener=s');
# Unused: f,j
if ($opt{h}) {
......@@ -784,13 +784,12 @@ COMMAND: foreach my $command (@commands) {
@vlans = @args;
# Same to 'remove', we find stacks by VLAN
my ($vlan_name) = @args;
my ($vlanobj, $stack);
my ($vlanobj, $stack);
if ($supplied_switches) {
debug("Openflow operations: using supplied switches\n");
@devicenames = @supplied_switches;
} elsif (defined($experiment) &&
defined($vlanobj = VLan->Lookup($experiment,$vlan_name)) &&
defined($vlanobj = VLan->Lookup($experiment,$vlans[0])) &&
defined($stack = $vlanobj->GetStack())) {
debug("Openflow operations: found stack $stack in database\n");
@devicenames = getSwitchesInStack($stack);
......@@ -2531,6 +2530,10 @@ sub doOpenflowEnable($$) {
$errors++;
}
}
if (!$errors) {
print 'Done! \n' if (!$quiet);
}
return $errors;
}
......@@ -2558,6 +2561,10 @@ sub doOpenflowDisable($$) {
#
# TODO:clear controllers/listeners here. Now in HP stack code.
#
if (!$errors) {
print 'Done! \n' if (!$quiet);
}
return $errors;
}
......@@ -2583,6 +2590,10 @@ sub doSetController($$$) {
}
}
if (!$errors) {
print 'Done! \n' if (!$quiet);
}
return $errors;
}
......@@ -2606,6 +2617,10 @@ sub doSetListener($$$) {
$errors++;
}
}
if (!$errors) {
print 'Done! \n' if (!$quiet);
}
return $errors;
}
......@@ -204,78 +204,5 @@ sub UpdateField {
}
}
#
# Enable Openflow
#
sub enableOpenflow($$) {
my $self = shift;
my $vlan = shift;
my $RetVal;
#
# APC switch doesn't support Openflow yet.
#
warn "ERROR: APC swith doesn't support Openflow now";
return 0;
}
#
# Disable Openflow
#
sub disableOpenflow($$) {
my $self = shift;
my $vlan = shift;
my $RetVal;
#
# APC switch doesn't support Openflow yet.
#
warn "ERROR: APC swith doesn't support Openflow now";
return 0;
}
#
# Set controller
#
sub setController($$$) {
my $self = shift;
my $vlan = shift;
my $controller = shift;
my $RetVal;
#
# APC switch doesn't support Openflow yet.
#
warn "ERROR: APC swith doesn't support Openflow now";
return 0;
}
#
# Set listener
#
sub setListener($$$) {
my $self = shift;
my $vlan = shift;
my $listener = shift;
my $RetVal;
#
# APC switch doesn't support Openflow yet.
#
warn "ERROR: APC swith doesn't support Openflow now";
return 0;
}
#
# Check if Openflow is supported on this switch
#
sub isOpenflowSupported($) {
#
# APC switch doesn't support Openflow yet.
#
return 0;
}
# End with true
1;
......@@ -1059,28 +1059,28 @@ sub enableOpenflow($$) {
foreach my $devicename (keys %{$self->{DEVICES}})
{
my $device = $self->{DEVICES}{$devicename};
if ($device->isOpenflowSupported()) {
my $vlan_number = $device->findVlan($vlan_id);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id \n" if $self->{DEBUG};
} else {
my $vlan_number = $device->findVlan($vlan_id, 2);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id, ignore it. \n" if $self->{DEBUG};
} else {
if ($device->isOpenflowSupported()) {
print "Enabling Openflow on $devicename for VLAN $vlan_id".
"\n" if $self->{DEBUG};
"..." if $self->{DEBUG};
my $ok = $device->enableOpenflow($vlan_number);
if (!$ok) { $errors++; }
}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
else {print "Done! \n" if $self->{DEBUG};}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
}
}
......@@ -1101,28 +1101,28 @@ sub disableOpenflow($$) {
foreach my $devicename (keys %{$self->{DEVICES}})
{
my $device = $self->{DEVICES}{$devicename};
if ($device->isOpenflowSupported()) {
my $vlan_number = $device->findVlan($vlan_id);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id \n" if $self->{DEBUG};
} else {
my $vlan_number = $device->findVlan($vlan_id, 2);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id, ignore it. \n" if $self->{DEBUG};
} else {
if ($device->isOpenflowSupported()) {
print "Disabling Openflow on $devicename for VLAN $vlan_id".
"\n" if $self->{DEBUG};
"..." if $self->{DEBUG};
my $ok = $device->disableOpenflow($vlan_number);
if (!$ok) { $errors++; }
}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
else {print "Done! \n" if $self->{DEBUG};}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
}
}
......@@ -1144,28 +1144,28 @@ sub setController($$$) {
foreach my $devicename (keys %{$self->{DEVICES}})
{
my $device = $self->{DEVICES}{$devicename};
if ($device->isOpenflowSupported()) {
my $vlan_number = $device->findVlan($vlan_id);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id \n" if $self->{DEBUG};
} else {
my $vlan_number = $device->findVlan($vlan_id, 2);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id, ignore it. \n" if $self->{DEBUG};
} else {
if ($device->isOpenflowSupported()) {
print "Setting Openflow controller on $devicename for VLAN $vlan_id".
"\n" if $self->{DEBUG};
"..." if $self->{DEBUG};
my $ok = $device->setController($vlan_number, $controller);
if (!$ok) { $errors++; }
}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
else {print "Done! \n" if $self->{DEBUG};}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
}
}
......@@ -1191,29 +1191,29 @@ sub setListener($$$) {
foreach my $devicename (keys %{$self->{DEVICES}})
{
my $device = $self->{DEVICES}{$devicename};
if ($device->isOpenflowSupported()) {
my $vlan_number = $device->findVlan($vlan_id);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id \n" if $self->{DEBUG};
} else {
my $vlan_number = $device->findVlan($vlan_id, 2);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id, ignore it. \n" if $self->{DEBUG};
} else {
if ($device->isOpenflowSupported()) {
print "Setting Openflow listener on $devicename for VLAN $vlan_id".
"\n" if $self->{DEBUG};
"..." if $self->{DEBUG};
my $ok = $device->setListener($vlan_number, $listener);
if (!$ok) { $errors++; }
}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
else {print "Done! \n" if $self->{DEBUG};}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
}
}
return $errors;
......
......@@ -51,7 +51,8 @@ my $createOID = "dot1qVlanStaticRowStatus";
#
# Openflow OIDs, only number format now.
#
my $ofOID = 'iso.org.dod.internet.private.enterprises.11.2.14.11.5.1.7.1.35';
#my $ofOID = 'iso.org.dod.internet.private.enterprises.11.2.14.11.5.1.7.1.35';
my $ofOID = '1.3.6.1.4.1.11.2.14.11.5.1.7.1.35';
my $ofEnableOID = $ofOID.'.1.1.2';
my $ofControllerOID = $ofOID.'.1.1.3';
my $ofListenerOID = $ofOID.'.1.1.4';
......@@ -1854,12 +1855,8 @@ sub setListener($$$) {
sub isOpenflowSupported($) {
my $self = shift;
my $ret;
#
# Still don't know how to detect if Openflow is supported.
# the ofOID is a directory. Maybe walking from it?
#
$ret = $self->get1($ofSupportOID, 1); # not really
$ret = $self->get1($ofSupportOID, 0);
if (defined($ret)) {
return 1;
} else {
......
......@@ -242,28 +242,28 @@ sub enableOpenflow($$) {
foreach my $devicename (keys %{$self->{DEVICES}})
{
my $device = $self->{DEVICES}{$devicename};
if ($device->isOpenflowSupported()) {
my $vlan_number = $device->findVlan($vlan_id);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id \n" if $self->{DEBUG};
} else {
my $vlan_number = $device->findVlan($vlan_id, 2);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id, ignore it. \n" if $self->{DEBUG};
} else {
if ($device->isOpenflowSupported()) {
print "Enabling Openflow on $devicename for VLAN $vlan_id".
"\n" if $self->{DEBUG};
"..." if $self->{DEBUG};
my $ok = $device->enableOpenflow($vlan_number);
if (!$ok) { $errors++; }
}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
else {print "Done! \n" if $self->{DEBUG};}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
}
}
......@@ -284,28 +284,28 @@ sub disableOpenflow($$) {
foreach my $devicename (keys %{$self->{DEVICES}})
{
my $device = $self->{DEVICES}{$devicename};
if ($device->isOpenflowSupported()) {
my $vlan_number = $device->findVlan($vlan_id);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id \n" if $self->{DEBUG};
} else {
my $vlan_number = $device->findVlan($vlan_id, 2);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id, ignore it. \n" if $self->{DEBUG};
} else {
if ($device->isOpenflowSupported()) {
print "Disabling Openflow on $devicename for VLAN $vlan_id".
"\n" if $self->{DEBUG};
"..." if $self->{DEBUG};
my $ok = $device->disableOpenflow($vlan_number);
if (!$ok) { $errors++; }
}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
else {print "Done! \n" if $self->{DEBUG};}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
}
}
......@@ -327,28 +327,28 @@ sub setController($$$) {
foreach my $devicename (keys %{$self->{DEVICES}})
{
my $device = $self->{DEVICES}{$devicename};
if ($device->isOpenflowSupported()) {
my $vlan_number = $device->findVlan($vlan_id);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id \n" if $self->{DEBUG};
} else {
my $vlan_number = $device->findVlan($vlan_id, 2);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id, ignore it. \n" if $self->{DEBUG};
} else {
if ($device->isOpenflowSupported()) {
print "Setting Openflow controller on $devicename for VLAN $vlan_id".
"\n" if $self->{DEBUG};
"..." if $self->{DEBUG};
my $ok = $device->setController($vlan_number, $controller);
if (!$ok) { $errors++; }
}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
else {print "Done! \n" if $self->{DEBUG};}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
}
}
......@@ -374,30 +374,33 @@ sub setListener($$$) {
foreach my $devicename (keys %{$self->{DEVICES}})
{
my $device = $self->{DEVICES}{$devicename};
if ($device->isOpenflowSupported()) {
my $vlan_number = $device->findVlan($vlan_id);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id \n" if $self->{DEBUG};
} else {
my $vlan_number = $device->findVlan($vlan_id, 2);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id, ignore it. \n" if $self->{DEBUG};
} else {
if ($device->isOpenflowSupported()) {
print "Setting Openflow listener on $devicename for VLAN $vlan_id".
"\n" if $self->{DEBUG};
"..." if $self->{DEBUG};
my $ok = $device->setListener($vlan_number, $listener);
if (!$ok) { $errors++; }
}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
else {print "Done! \n" if $self->{DEBUG};}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
}
}
return $errors;
}
# End with true
1;
......@@ -1163,28 +1163,28 @@ sub enableOpenflow($$) {
foreach my $devicename (keys %{$self->{DEVICES}})
{
my $device = $self->{DEVICES}{$devicename};
if ($device->isOpenflowSupported()) {
my $vlan_number = $device->findVlan($vlan_id);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id \n" if $self->{DEBUG};
} else {
my $vlan_number = $device->findVlan($vlan_id, 2);
if (!$vlan_number) {
#
# Not sure if this is an error or not.
# It might be possible that not all devices in a stack have the given VLAN.
#
print "$device has no VLAN $vlan_id, ignore it. \n" if $self->{DEBUG};
} else {
if ($device->isOpenflowSupported()) {
print "Enabling Openflow on $devicename for VLAN $vlan_id".
"\n" if $self->{DEBUG};
"..." if $self->{DEBUG};
my $ok = $device->enableOpenflow($vlan_number);
if (!$ok) { $errors++; }
}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
else {print "Done! \n" if $self->{DEBUG};}
} else {
#
# TODO: Should this be an error?
#
warn "ERROR: Openflow is not supported on $devicename \n";
$errors++;
}
}
}