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 org.eclipse.osgi.framework.console.CommandInterpreter;
12 import org.eclipse.osgi.framework.console.CommandProvider;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
14 import org.opendaylight.openflowplugin.testcommon.DropTestDsProvider;
15 import org.opendaylight.openflowplugin.testcommon.DropTestRpcProvider;
16 import org.osgi.framework.BundleContext;
18 import com.google.common.base.Preconditions;
20 public class DropTestCommandProvider implements CommandProvider {
22 private final BundleContext ctx;
23 private final DropTestDsProvider provider;
24 private final DropTestRpcProvider rpcProvider;
25 private boolean sessionInitiated = false;
27 public DropTestCommandProvider(final BundleContext ctx, final DropTestDsProvider provider,
28 final DropTestRpcProvider rpcProvider) {
29 this.ctx = Preconditions.checkNotNull(ctx, "BundleContext can not be null!");
30 this.provider = Preconditions.checkNotNull(provider, "DropTestProvider can't be null!");
31 this.rpcProvider = Preconditions.checkNotNull(rpcProvider, "DropTestRpcProvider can't be null!");
34 public void onSessionInitiated(final ProviderContext session) {
35 Preconditions.checkNotNull(session, "ProviderContext can not be null!");
36 ctx.registerService(CommandProvider.class.getName(), this, null);
37 this.sessionInitiated = true;
40 public void _dropAllPackets(final CommandInterpreter ci) {
41 if (sessionInitiated) {
42 String onoff = ci.nextArgument();
43 if (onoff.equalsIgnoreCase("on")) {
44 if (! provider.isActive()) {
46 ci.println("DropAllFlows transitions to on");
48 ci.println("DropAllFlows is already on");
50 } else if (onoff.equalsIgnoreCase("off")) {
51 if (provider.isActive()) {
53 ci.println("DropAllFlows transitions to off");
55 ci.println("DropAllFlows is already off");
59 ci.println("Session not initiated, try again in a few seconds");
63 public void _dropAllPacketsRpc(final CommandInterpreter ci) {
64 if (sessionInitiated) {
65 String onoff = ci.nextArgument();
66 if (onoff.equalsIgnoreCase("on")) {
67 if (! rpcProvider.isActive()) {
69 ci.println("DropAllFlows transitions to on");
71 ci.println("DropAllFlows is already on");
73 } else if (onoff.equalsIgnoreCase("off")) {
74 if (rpcProvider.isActive()) {
76 ci.println("DropAllFlows transitions to off");
78 ci.println("DropAllFlows is already off");
82 ci.println("Session not initiated, try again in a few seconds");
86 public void _showDropStats(final CommandInterpreter ci) {
87 if (sessionInitiated) {
88 ci.println("RPC Test Statistics: " + this.rpcProvider.getStats().toString());
89 ci.println("FRM Test Statistics: " + this.provider.getStats().toString());
91 ci.println("Session not initiated, try again in a few seconds");
95 public void _clearDropStats(final CommandInterpreter ci) {
96 if (sessionInitiated) {
97 ci.print("Clearing drop statistics... ");
98 this.rpcProvider.clearStats();
99 this.provider.clearStats();
103 ci.println("Session not initiated, try again in a few seconds");
108 public String getHelp() {
109 StringBuffer help = new StringBuffer();
110 help.append("---dropAllPackets---\n");
111 help.append("\t dropAllPackets on - Start dropping all packets\n");
112 help.append("\t dropAllPackets off - Stop dropping all packets\n");
113 help.append("\t dropAllPacketsRpc on - Start dropping all packets but bypassing dataStore\n");
114 help.append("\t - add flow goes directly to RPC provided OFPlugin\n");
115 help.append("\t dropAllPacketsRpc off - Stop dropping all packets but bypassing dataStore\n");
116 return help.toString();