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");
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");
}
}
- 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");
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");
}
}
- 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());
}
}
- public void _clearDropStats(CommandInterpreter ci) {
+ public void _clearDropStats(final CommandInterpreter ci) {
if (sessionInitiated) {
ci.print("Clearing drop statistics... ");
this.rpcProvider.clearStats();