Bulk-add copyright headers to java files
[controller.git] / opendaylight / forwardingrulesmanager / implementation / src / main / java / org / opendaylight / controller / forwardingrulesmanager / internal / ForwardingRulesManagerCLI.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, 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.controller.forwardingrulesmanager.internal;
9
10 import java.util.Dictionary;
11 import java.util.Hashtable;
12 import java.util.List;
13
14 import org.apache.felix.service.command.Descriptor;
15 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
16 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
17 import org.opendaylight.controller.sal.core.Node;
18 import org.opendaylight.controller.sal.utils.ServiceHelper;
19 import org.osgi.framework.ServiceRegistration;
20
21 /**
22  * This class provides osgi cli commands for developers to debug
23  * ForwardingRulesManager functionality
24  */
25 public class ForwardingRulesManagerCLI {
26     @SuppressWarnings("rawtypes")
27     private ServiceRegistration sr = null;
28
29     public void init() {
30     }
31
32     public void destroy() {
33     }
34
35     public void start() {
36         final Dictionary<String, Object> props = new Hashtable<String, Object>();
37         props.put("osgi.command.scope", "odpcontroller");
38         props.put("osgi.command.function", new String[] { "showRequestedGroupFlows", "showInstalledGroupFlows",
39                 "showRequestedNodeFlows", "showInstalledNodeFlows" });
40         this.sr = ServiceHelper.registerGlobalServiceWReg(ForwardingRulesManagerCLI.class, this, props);
41     }
42
43     public void stop() {
44         if (this.sr != null) {
45             this.sr.unregister();
46             this.sr = null;
47         }
48     }
49
50     @Descriptor("Displays all the flow entries in a given group")
51     public void showRequestedGroupFlows(@Descriptor("Container in which to query FRM") String container,
52             @Descriptor("Group name") String group, @Descriptor("True for verbose else false") Boolean verbose) {
53         IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
54                 IForwardingRulesManager.class, container, this);
55         if (frm == null) {
56             System.out.println("Cannot find the FRM instance on container: " + container);
57             return;
58         }
59         List<FlowEntry> groupFlows = frm.getFlowEntriesForGroup(group);
60         System.out.println("Group " + group);
61         for (FlowEntry flowEntry : groupFlows) {
62             if (!verbose) {
63                 System.out.println(flowEntry.getNode() + " " + flowEntry.getFlowName());
64             } else {
65                 System.out.println(flowEntry.getNode() + " " + flowEntry.toString());
66             }
67         }
68     }
69
70     @Descriptor("Displays all the installed flow entries in a given group")
71     public void showInstalledGroupFlows(@Descriptor("Container in which to query FRM") String container,
72             @Descriptor("Group name") String group, @Descriptor("True for verbose else false") Boolean verbose) {
73         IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
74                 IForwardingRulesManager.class, container, this);
75         if (frm == null) {
76             System.out.println("Cannot find the FRM instance on container: " + container);
77             return;
78         }
79         List<FlowEntry> groupFlows = frm.getInstalledFlowEntriesForGroup(group);
80         System.out.println("Group " + group);
81         for (FlowEntry flowEntry : groupFlows) {
82             if (!verbose) {
83                 System.out.println(flowEntry.getNode() + " " + flowEntry.getFlowName());
84             } else {
85                 System.out.println(flowEntry.getNode() + " " + flowEntry.toString());
86             }
87         }
88     }
89
90     @Descriptor("Displays all the flow entries for a network node")
91     public void showRequestedNodeFlows(
92             @Descriptor("Container in which to query FRM") String container,
93             @Descriptor("String representation of the Node, this need to be consumable from Node.fromString()") String nodeId,
94             @Descriptor("True for verbose else false") Boolean verbose) {
95         IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
96                 IForwardingRulesManager.class, container, this);
97         if (frm == null) {
98             System.out.println("Cannot find the FRM instance on container: " + container);
99             return;
100         }
101         Node node = Node.fromString(nodeId);
102         if (node == null) {
103             System.out.println("Please enter a valid node id");
104             return;
105         }
106         List<FlowEntry> groupFlows = frm.getFlowEntriesForNode(node);
107         System.out.println("Node " + nodeId);
108         for (FlowEntry flowEntry : groupFlows) {
109             if (!verbose) {
110                 System.out.println(flowEntry.getNode() + " " + flowEntry.getFlowName());
111             } else {
112                 System.out.println(flowEntry.getNode() + " " + flowEntry.toString());
113             }
114         }
115     }
116
117     @Descriptor("Displays all the flow entries installed in a network node")
118     public void showInstalledNodeFlows(
119             @Descriptor("Container in which to query FRM") String container,
120             @Descriptor("String representation of the Node, this need to be consumable from Node.fromString()") String nodeId,
121             @Descriptor("True for verbose else false") Boolean verbose) {
122         IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
123                 IForwardingRulesManager.class, container, this);
124         if (frm == null) {
125             System.out.println("Cannot find the FRM instance on container: " + container);
126             return;
127         }
128         Node node = Node.fromString(nodeId);
129         if (node == null) {
130             System.out.println("Please enter a valid node id");
131             return;
132         }
133         List<FlowEntry> groupFlows = frm.getInstalledFlowEntriesForNode(node);
134         System.out.println("Node " + nodeId);
135         for (FlowEntry flowEntry : groupFlows) {
136             if (!verbose) {
137                 System.out.println(flowEntry.getNode() + " " + flowEntry.getFlowName());
138             } else {
139                 System.out.println(flowEntry.getNode() + " " + flowEntry.toString());
140             }
141         }
142     }
143 }