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