2 * Copyright (c) 2013 Ericsson , Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.droptest;
11 import com.google.common.base.Preconditions;
12 import org.eclipse.osgi.framework.console.CommandInterpreter;
13 import org.eclipse.osgi.framework.console.CommandProvider;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.openflowplugin.testcommon.DropTestDsProvider;
16 import org.opendaylight.openflowplugin.testcommon.DropTestRpcProvider;
17 import org.osgi.framework.BundleContext;
21 * use the same methods defined via karaf commands (defined in drop-test-karaf artifact)
22 * Can be deleted after patch https://git.opendaylight.org/gerrit/#/c/15660/ for bug 2750 will be merged.
26 public class DropTestCommandProvider implements CommandProvider {
28 private final BundleContext ctx;
29 private final DropTestDsProvider provider;
30 private final DropTestRpcProvider rpcProvider;
31 private boolean sessionInitiated = false;
33 public DropTestCommandProvider(final BundleContext ctx, final DropTestDsProvider provider,
34 final DropTestRpcProvider rpcProvider) {
35 this.ctx = Preconditions.checkNotNull(ctx, "BundleContext can not be null!");
36 this.provider = Preconditions.checkNotNull(provider, "DropTestProvider can't be null!");
37 this.rpcProvider = Preconditions.checkNotNull(rpcProvider, "DropTestRpcProvider can't be null!");
40 public void onSessionInitiated(final ProviderContext session) {
41 Preconditions.checkNotNull(session, "ProviderContext can not be null!");
42 ctx.registerService(CommandProvider.class.getName(), this, null);
43 this.sessionInitiated = true;
46 public void dropAllPackets(final CommandInterpreter ci) {
47 if (sessionInitiated) {
48 String onoff = ci.nextArgument();
49 if (onoff.equalsIgnoreCase("on")) {
50 if (! provider.isActive()) {
52 ci.println("DropAllFlows transitions to on");
54 ci.println("DropAllFlows is already on");
56 } else if (onoff.equalsIgnoreCase("off")) {
57 if (provider.isActive()) {
59 ci.println("DropAllFlows transitions to off");
61 ci.println("DropAllFlows is already off");
65 ci.println("Session not initiated, try again in a few seconds");
69 public void dropAllPacketsRpc(final CommandInterpreter ci) {
70 if (sessionInitiated) {
71 String onoff = ci.nextArgument();
72 if (onoff.equalsIgnoreCase("on")) {
73 if (! rpcProvider.isActive()) {
75 ci.println("DropAllFlows transitions to on");
77 ci.println("DropAllFlows is already on");
79 } else if (onoff.equalsIgnoreCase("off")) {
80 if (rpcProvider.isActive()) {
82 ci.println("DropAllFlows transitions to off");
84 ci.println("DropAllFlows is already off");
88 ci.println("Session not initiated, try again in a few seconds");
92 public void showDropStats(final CommandInterpreter ci) {
93 if (sessionInitiated) {
94 ci.println("RPC Test Statistics: " + this.rpcProvider.getStats().toString());
95 ci.println("FRM Test Statistics: " + this.provider.getStats().toString());
97 ci.println("Session not initiated, try again in a few seconds");
101 public void clearDropStats(final CommandInterpreter ci) {
102 if (sessionInitiated) {
103 ci.print("Clearing drop statistics... ");
104 this.rpcProvider.clearStats();
105 this.provider.clearStats();
109 ci.println("Session not initiated, try again in a few seconds");
114 public String getHelp() {
115 StringBuffer help = new StringBuffer();
116 help.append("---dropAllPackets---\n");
117 help.append("\t dropAllPackets on - Start dropping all packets\n");
118 help.append("\t dropAllPackets off - Stop dropping all packets\n");
119 help.append("\t dropAllPacketsRpc on - Start dropping all packets but bypassing dataStore\n");
120 help.append("\t - add flow goes directly to RPC provided OFPlugin\n");
121 help.append("\t dropAllPacketsRpc off - Stop dropping all packets but bypassing dataStore\n");
122 return help.toString();