Eliminate blueprint for drop-test-karaf commands
[openflowplugin.git] / drop-test-karaf / src / main / java / org / opendaylight / openflowplugin / droptestkaraf / DropAllPacketsCommandProvider.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 package org.opendaylight.openflowplugin.droptestkaraf;
9
10 import org.apache.karaf.shell.api.action.Action;
11 import org.apache.karaf.shell.api.action.Argument;
12 import org.apache.karaf.shell.api.action.Command;
13 import org.apache.karaf.shell.api.action.Completion;
14 import org.apache.karaf.shell.api.action.lifecycle.Reference;
15 import org.apache.karaf.shell.api.action.lifecycle.Service;
16 import org.apache.karaf.shell.api.console.Session;
17 import org.opendaylight.openflowplugin.testcommon.DropTestCommiter;
18
19 @Command(scope = "drop-test", name = "dropAllPackets",
20          description = "drop packet responder involving dataStore and FRM")
21 @Service
22 public class DropAllPacketsCommandProvider implements Action {
23     @Reference
24     DropTestCommiter provider;
25     @Reference
26     Session session;
27
28     @Argument(index = 0, name = "on-off",
29             description = "target state of drop responder",
30             required = true, multiValued = false)
31     @Completion(DropAllPacketsCompleter.class)
32     String targetStateArg;
33
34     @Override
35     public Object execute() {
36         final var out = session.getConsole();
37
38         if ("on".equalsIgnoreCase(targetStateArg)) {
39             if (provider.start()) {
40                 out.println("DropAllFlows transitions to on");
41             } else {
42                 out.println("DropAllFlows is already on");
43             }
44         } else if ("off".equalsIgnoreCase(targetStateArg)) {
45             if (provider.stop()) {
46                 out.println("DropAllFlows transitions to off");
47             } else {
48                 out.println("DropAllFlows is already off");
49             }
50         }
51         return null;
52     }
53 }