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.controller.sal.binding.api.data.DataBrokerService;
15 import org.osgi.framework.BundleContext;
17 public class DropTestCommandProvider implements CommandProvider {
19 private DataBrokerService dataBrokerService;
20 private ProviderContext pc;
21 private BundleContext ctx;
22 private DropTestProvider provider;
23 private DropTestRpcProvider rpcProvider;
24 private boolean on = false;
25 private boolean sessionInitiated = false;
28 public DropTestCommandProvider(BundleContext ctx,DropTestProvider provider,DropTestRpcProvider rpcProvider) {
30 this.provider = provider;
31 this.rpcProvider = rpcProvider;
34 public void onSessionInitiated(ProviderContext session) {
36 dataBrokerService = session.getSALService(DataBrokerService.class);
37 ctx.registerService(CommandProvider.class.getName(), this, null);
38 this.sessionInitiated = true;
42 public void _dropAllPackets(CommandInterpreter ci) {
43 if(sessionInitiated) {
44 String onoff = ci.nextArgument();
45 if(onoff.equals("on")) {
48 ci.println("DropAllFlows transitions to on");
50 ci.println("DropAllFlows is already on");
53 } else if (onoff.equals("off")) {
56 ci.println("DropAllFlows transitions to off");
58 ci.println("DropAllFlows is already off");
63 ci.println("Session not initiated, try again in a few seconds");
67 public void _dropAllPacketsRpc(CommandInterpreter ci) {
68 if(sessionInitiated) {
69 String onoff = ci.nextArgument();
70 if(onoff.equals("on")) {
73 ci.println("DropAllFlows transitions to on");
75 ci.println("DropAllFlows is already on");
78 } else if (onoff.equals("off")) {
81 ci.println("DropAllFlows transitions to off");
83 ci.println("DropAllFlows is already off");
88 ci.println("Session not initiated, try again in a few seconds");
92 public void _showDropStats(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(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();