72b3c08bec45f7fde05e3c593b101054b828955a
[openflowplugin.git] / drop-test-karaf / src / main / java / org / opendaylight / openflowplugin / droptestkaraf / DropAllPacketsRpcCommandProvider.java
1 /*
2  * Copyright (c) 2013 Ericsson , Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.droptestkaraf;
10
11 import java.io.PrintStream;
12 import org.apache.karaf.shell.commands.Argument;
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.console.OsgiCommandSupport;
15 import org.opendaylight.openflowplugin.testcommon.DropTestRpcProvider;
16
17 @Command(scope = "drop-test", name = "dropAllPacketsRpc",
18          description = "drop packet responder involving SalFlowService")
19 public class DropAllPacketsRpcCommandProvider extends OsgiCommandSupport {
20
21     @Argument(index = 0, name = "on-off",
22             description = "target state of drop responder",
23             required = true, multiValued = false)
24     String targetStateArg;
25
26     @Override
27     protected Object doExecute() {
28         PrintStream out = session.getConsole();
29         final DropTestRpcProvider provider = DropTestProviderImpl.getDropRpcProvider();
30
31         if ("on".equalsIgnoreCase(targetStateArg)) {
32             if (! provider.isActive()) {
33                 provider.start();
34                 out.println("DropAllFlows transitions to on");
35             } else {
36                 out.println("DropAllFlows is already on");
37             }
38         } else if ("off".equalsIgnoreCase(targetStateArg)) {
39             if (provider.isActive()) {
40                 provider.close();
41                 out.println("DropAllFlows transitions to off");
42             } else {
43                 out.println("DropAllFlows is already off");
44             }
45         }
46         return null;
47     }
48
49     //TODO: create commands
50 //    public void _showDropStats(final CommandInterpreter ci) {
51 //        if (sessionInitiated) {
52 //            ci.println("RPC Test Statistics: " + this.rpcProvider.getStats().toString());
53 //            ci.println("FRM Test Statistics: " + this.provider.getStats().toString());
54 //        } else {
55 //            ci.println("Session not initiated, try again in a few seconds");
56 //        }
57 //    }
58 //
59 //    public void _clearDropStats(final CommandInterpreter ci) {
60 //        if (sessionInitiated) {
61 //            ci.print("Clearing drop statistics... ");
62 //            this.rpcProvider.clearStats();
63 //            this.provider.clearStats();
64 //            ci.println("Done.");
65 //
66 //        } else {
67 //            ci.println("Session not initiated, try again in a few seconds");
68 //        }
69 //    }
70
71 }