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 org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.commands.Option;
13 import org.apache.karaf.shell.console.OsgiCommandSupport;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.openflowplugin.applications.southboundcli.util.OFNode;
16 import org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil;
18 @Command(scope = "openflow", name = "shownode", description = "shownode -d <NodeID>")
19 public class ShowNodeCommandProvider extends OsgiCommandSupport {
20 public static final String OUTPUT_FORMAT = "%-24s %-20s %-15s";
21 public static final String NEW_LINE = "%-24s %-20s %-15s %n";
22 public static final String HEADER_SEPARATOR = "---------------------------------------------"
23 + "---------------------------------------";
25 @Option(name = "-d", description = "Node Id", required = true, multiValued = false)
28 private DataBroker dataBroker;
30 public void setDataBroker(final DataBroker dataBroker) {
31 this.dataBroker = dataBroker;
35 protected Object doExecute() throws Exception {
37 session.getConsole().println("NodeID not specified");
40 OFNode node = ShellUtil.getNode(Long.parseLong(nodeId), dataBroker);
42 printNodeHeaderOutput();
43 printHeaderSeparator();
44 printNodeOutput(node);
46 session.getConsole().println("No node available for this NodeID");
51 private void printNodeHeaderOutput() {
52 Formatter formatter = new Formatter();
53 String header = formatter.format(OUTPUT_FORMAT, "OFNode", "Name", "Ports").toString();
55 session.getConsole().println(header);
58 private void printHeaderSeparator() {
59 session.getConsole().println(HEADER_SEPARATOR);
62 private void printNodeOutput(final OFNode ofNode) {
63 String ofNodeId = ofNode.getNodeId().toString();
64 String ofNodeName = ofNode.getNodeName();
65 for (String port : ofNode.getPorts()) {
67 session.getConsole().println(new Formatter().format(NEW_LINE, ofNodeId, ofNodeName, port).toString());