HotFix Bug 1581 - DroptestRPC doesn't work with Cbench 06/10106/2
authorVaclav Demcak <vdemcak@cisco.com>
Wed, 20 Aug 2014 15:57:38 +0000 (17:57 +0200)
committerPrasanna Huddar <prasanna.k.huddar@gmail.com>
Thu, 21 Aug 2014 08:40:05 +0000 (08:40 +0000)
* DroptestRpcSender is initialized for command on only, but check
command has to be case insesitive in DropTestCommandProvider (fixed)
* add input validation

Change-Id: Ia7131442d22b436290058082ed8a374a90ea35f8
Signed-off-by: Vaclav Demcak <vdemcak@cisco.com>
drop-test/src/main/java/org/opendaylight/openflowplugin/droptest/DropTestCommandProvider.java

index 07f8fcb5cc387a57885c28615be43545f29f241c..846997d80155a16181777a5a38d4a3a3db6350c0 100644 (file)
@@ -10,39 +10,36 @@ package org.opendaylight.openflowplugin.droptest;
 
 import org.eclipse.osgi.framework.console.CommandInterpreter;
 import org.eclipse.osgi.framework.console.CommandProvider;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.osgi.framework.BundleContext;
 
+import com.google.common.base.Preconditions;
+
 public class DropTestCommandProvider implements CommandProvider {
 
-    private DataBroker dataBroker;
-    private ProviderContext pc;
-    private BundleContext ctx;
-    private DropTestProvider provider;
-    private DropTestRpcProvider rpcProvider;
+    private final BundleContext ctx;
+    private final DropTestProvider provider;
+    private final DropTestRpcProvider rpcProvider;
     private boolean on = false;
     private boolean sessionInitiated = false;
 
-
-    public DropTestCommandProvider(BundleContext ctx, DropTestProvider provider, DropTestRpcProvider rpcProvider) {
-        this.ctx = ctx;
-        this.provider = provider;
-        this.rpcProvider = rpcProvider;
+    public DropTestCommandProvider(final BundleContext ctx, final DropTestProvider provider,
+            final DropTestRpcProvider rpcProvider) {
+        this.ctx = Preconditions.checkNotNull(ctx, "BundleContext can not be null!");
+        this.provider = Preconditions.checkNotNull(provider, "DropTestProvider can't be null!");
+        this.rpcProvider = Preconditions.checkNotNull(rpcProvider, "DropTestRpcProvider can't be null!");
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        pc = session;
-        dataBroker = session.getSALService(DataBroker.class);
+    public void onSessionInitiated(final ProviderContext session) {
+        Preconditions.checkNotNull(session, "ProviderContext can not be null!");
         ctx.registerService(CommandProvider.class.getName(), this, null);
         this.sessionInitiated = true;
-
     }
 
-    public void _dropAllPackets(CommandInterpreter ci) {
+    public void _dropAllPackets(final CommandInterpreter ci) {
         if (sessionInitiated) {
             String onoff = ci.nextArgument();
-            if (onoff.equals("on")) {
+            if (onoff.equalsIgnoreCase("on")) {
                 if (on == false) {
                     provider.start();
                     ci.println("DropAllFlows transitions to on");
@@ -50,7 +47,7 @@ public class DropTestCommandProvider implements CommandProvider {
                     ci.println("DropAllFlows is already on");
                 }
                 on = true;
-            } else if (onoff.equals("off")) {
+            } else if (onoff.equalsIgnoreCase("off")) {
                 if (on == true) {
                     provider.close();
                     ci.println("DropAllFlows transitions to off");
@@ -64,10 +61,10 @@ public class DropTestCommandProvider implements CommandProvider {
         }
     }
 
-    public void _dropAllPacketsRpc(CommandInterpreter ci) {
+    public void _dropAllPacketsRpc(final CommandInterpreter ci) {
         if (sessionInitiated) {
             String onoff = ci.nextArgument();
-            if (onoff.equals("on")) {
+            if (onoff.equalsIgnoreCase("on")) {
                 if (on == false) {
                     rpcProvider.start();
                     ci.println("DropAllFlows transitions to on");
@@ -75,7 +72,7 @@ public class DropTestCommandProvider implements CommandProvider {
                     ci.println("DropAllFlows is already on");
                 }
                 on = true;
-            } else if (onoff.equals("off")) {
+            } else if (onoff.equalsIgnoreCase("off")) {
                 if (on == true) {
                     rpcProvider.close();
                     ci.println("DropAllFlows transitions to off");
@@ -89,7 +86,7 @@ public class DropTestCommandProvider implements CommandProvider {
         }
     }
 
-    public void _showDropStats(CommandInterpreter ci) {
+    public void _showDropStats(final CommandInterpreter ci) {
         if (sessionInitiated) {
             ci.println("RPC Test Statistics: " + this.rpcProvider.getStats().toString());
             ci.println("FRM Test Statistics: " + this.provider.getStats().toString());
@@ -98,7 +95,7 @@ public class DropTestCommandProvider implements CommandProvider {
         }
     }
 
-    public void _clearDropStats(CommandInterpreter ci) {
+    public void _clearDropStats(final CommandInterpreter ci) {
         if (sessionInitiated) {
             ci.print("Clearing drop statistics... ");
             this.rpcProvider.clearStats();