X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fadsal%2Fforwardingrulesmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwardingrulesmanager%2Finternal%2FForwardingRulesManagerCLI.java;fp=opendaylight%2Fadsal%2Fforwardingrulesmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwardingrulesmanager%2Finternal%2FForwardingRulesManagerCLI.java;h=320561b5de92b9cf756899f89e0d6e8009e27957;hb=42c32160bfd41de57189bb246fec5ffb48ed8e9e;hp=0000000000000000000000000000000000000000;hpb=edf5bfcee83c750853253ccfd991ba7000f5f65b;p=controller.git diff --git a/opendaylight/adsal/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManagerCLI.java b/opendaylight/adsal/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManagerCLI.java new file mode 100644 index 0000000000..320561b5de --- /dev/null +++ b/opendaylight/adsal/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManagerCLI.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.forwardingrulesmanager.internal; + +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.List; + +import org.apache.felix.service.command.Descriptor; +import org.opendaylight.controller.forwardingrulesmanager.FlowEntry; +import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager; +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.utils.ServiceHelper; +import org.osgi.framework.ServiceRegistration; + +/** + * This class provides osgi cli commands for developers to debug + * ForwardingRulesManager functionality + */ +public class ForwardingRulesManagerCLI { + @SuppressWarnings("rawtypes") + private ServiceRegistration sr = null; + + public void init() { + } + + public void destroy() { + } + + public void start() { + final Dictionary props = new Hashtable(); + props.put("osgi.command.scope", "odpcontroller"); + props.put("osgi.command.function", new String[] { "showRequestedGroupFlows", "showInstalledGroupFlows", + "showRequestedNodeFlows", "showInstalledNodeFlows" }); + this.sr = ServiceHelper.registerGlobalServiceWReg(ForwardingRulesManagerCLI.class, this, props); + } + + public void stop() { + if (this.sr != null) { + this.sr.unregister(); + this.sr = null; + } + } + + @Descriptor("Displays all the flow entries in a given group") + public void showRequestedGroupFlows(@Descriptor("Container in which to query FRM") String container, + @Descriptor("Group name") String group, @Descriptor("True for verbose else false") Boolean verbose) { + IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance( + IForwardingRulesManager.class, container, this); + if (frm == null) { + System.out.println("Cannot find the FRM instance on container: " + container); + return; + } + List groupFlows = frm.getFlowEntriesForGroup(group); + System.out.println("Group " + group); + for (FlowEntry flowEntry : groupFlows) { + if (!verbose) { + System.out.println(flowEntry.getNode() + " " + flowEntry.getFlowName()); + } else { + System.out.println(flowEntry.getNode() + " " + flowEntry.toString()); + } + } + } + + @Descriptor("Displays all the installed flow entries in a given group") + public void showInstalledGroupFlows(@Descriptor("Container in which to query FRM") String container, + @Descriptor("Group name") String group, @Descriptor("True for verbose else false") Boolean verbose) { + IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance( + IForwardingRulesManager.class, container, this); + if (frm == null) { + System.out.println("Cannot find the FRM instance on container: " + container); + return; + } + List groupFlows = frm.getInstalledFlowEntriesForGroup(group); + System.out.println("Group " + group); + for (FlowEntry flowEntry : groupFlows) { + if (!verbose) { + System.out.println(flowEntry.getNode() + " " + flowEntry.getFlowName()); + } else { + System.out.println(flowEntry.getNode() + " " + flowEntry.toString()); + } + } + } + + @Descriptor("Displays all the flow entries for a network node") + public void showRequestedNodeFlows( + @Descriptor("Container in which to query FRM") String container, + @Descriptor("String representation of the Node, this need to be consumable from Node.fromString()") String nodeId, + @Descriptor("True for verbose else false") Boolean verbose) { + IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance( + IForwardingRulesManager.class, container, this); + if (frm == null) { + System.out.println("Cannot find the FRM instance on container: " + container); + return; + } + Node node = Node.fromString(nodeId); + if (node == null) { + System.out.println("Please enter a valid node id"); + return; + } + List groupFlows = frm.getFlowEntriesForNode(node); + System.out.println("Node " + nodeId); + for (FlowEntry flowEntry : groupFlows) { + if (!verbose) { + System.out.println(flowEntry.getNode() + " " + flowEntry.getFlowName()); + } else { + System.out.println(flowEntry.getNode() + " " + flowEntry.toString()); + } + } + } + + @Descriptor("Displays all the flow entries installed in a network node") + public void showInstalledNodeFlows( + @Descriptor("Container in which to query FRM") String container, + @Descriptor("String representation of the Node, this need to be consumable from Node.fromString()") String nodeId, + @Descriptor("True for verbose else false") Boolean verbose) { + IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance( + IForwardingRulesManager.class, container, this); + if (frm == null) { + System.out.println("Cannot find the FRM instance on container: " + container); + return; + } + Node node = Node.fromString(nodeId); + if (node == null) { + System.out.println("Please enter a valid node id"); + return; + } + List groupFlows = frm.getInstalledFlowEntriesForNode(node); + System.out.println("Node " + nodeId); + for (FlowEntry flowEntry : groupFlows) { + if (!verbose) { + System.out.println(flowEntry.getNode() + " " + flowEntry.getFlowName()); + } else { + System.out.println(flowEntry.getNode() + " " + flowEntry.toString()); + } + } + } +}