2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.applications.southboundcli.cli;
10 import java.util.Formatter;
11 import java.util.HashSet;
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.commands.Option;
15 import org.apache.karaf.shell.console.OsgiCommandSupport;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.openflowplugin.applications.southboundcli.util.OFNode;
18 import org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil;
20 @Command(scope = "openflow", name = "shownode", description = "shownode -d <NodeID>")
21 public class ShowNodeCommandProvider extends OsgiCommandSupport {
22 public static final String OUTPUT_FORMAT = "%-24s %-20s %-15s";
23 public static final String NEW_LINE = "%-24s %-20s %-15s %n";
24 public static final String HEADER_SEPARATOR = "---------------------------------------------"
25 + "---------------------------------------";
27 @Option(name = "-d", description = "Node Id", required = true, multiValued = false)
30 private DataBroker dataBroker;
32 public void setDataBroker(final DataBroker dataBroker) {
33 this.dataBroker = dataBroker;
37 protected Object doExecute() throws Exception {
39 session.getConsole().println("NodeID not specified");
42 OFNode node = ShellUtil.getNode(Long.parseLong(nodeId), dataBroker);
44 printNodeHeaderOutput();
45 printHeaderSeparator();
46 printNodeOutput(node);
48 session.getConsole().println("No node available for this NodeID");
53 private void printNodeHeaderOutput() {
54 Formatter formatter = new Formatter();
55 String header = formatter.format(OUTPUT_FORMAT, "OFNode", "Name", "Ports").toString();
57 session.getConsole().println(header);
60 private void printHeaderSeparator() {
61 session.getConsole().println(HEADER_SEPARATOR);
64 private void printNodeOutput(final OFNode ofNode) {
65 Set<String> portNames = new HashSet<>();
66 String ofNodeId = ofNode.getNodeId().toString();
67 String ofNodeName = ofNode.getNodeName();
68 for (String port : ofNode.getPorts()) {
70 session.getConsole().println(new Formatter().format(NEW_LINE, ofNodeId, ofNodeName, port).toString());