X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2Finternal%2FSwitchManagerCLI.java;h=268e45ad85891f0c1d274447dfca0e66520bb1c7;hb=633fd9012d8ff920283da437131b19d8cd3c2330;hp=bcf9fd6d0b33e47da103e5646a86be8566b78176;hpb=f3bdffc96f0c221111faeef07db2a6b975f56463;p=controller.git diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerCLI.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerCLI.java index bcf9fd6d0b..268e45ad85 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerCLI.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerCLI.java @@ -11,23 +11,17 @@ package org.opendaylight.controller.switchmanager.internal; import java.util.ArrayList; import java.util.Collections; import java.util.Dictionary; +import java.util.HashSet; import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.felix.service.command.Descriptor; -import org.opendaylight.controller.sal.core.Bandwidth; -import org.opendaylight.controller.sal.core.Config; -import org.opendaylight.controller.sal.core.Description; -import org.opendaylight.controller.sal.core.MacAddress; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.State; -import org.opendaylight.controller.sal.core.Tier; import org.opendaylight.controller.sal.utils.GlobalConstants; -import org.opendaylight.controller.sal.utils.HexEncode; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.controller.switchmanager.ISwitchManager; import org.osgi.framework.ServiceRegistration; @@ -70,28 +64,34 @@ public class SwitchManagerCLI { return; } - System.out.println(" Node Type MAC Name Tier"); - Set nodes = sm.getNodes(); if (nodes == null || nodes.isEmpty()) { return; } - List nodeArray = new ArrayList(); + Set propertyList = new HashSet(); for (Node node : nodes) { - nodeArray.add(node.toString()); + Map propList = sm.getNodeProps(node); + propertyList.addAll(propList.keySet()); + } + List sortedProps = new ArrayList(propertyList); + Collections.sort(sortedProps); + String properties = String.format("%-26s ", "Node"); + for (String s : sortedProps) { + properties = properties.concat(String.format("%-18s ", s)); } - Collections.sort(nodeArray); - for (String str : nodeArray) { - Node node = Node.fromString(str); - Description desc = ((Description) sm.getNodeProp(node, Description.propertyName)); - Tier tier = ((Tier) sm.getNodeProp(node, Tier.TierPropName)); - String nodeName = (desc == null) ? "" : desc.getValue(); - MacAddress mac = (MacAddress) sm.getNodeProp(node, MacAddress.name); - String macAddr = (mac == null) ? "" : HexEncode.bytesToHexStringFormat(mac.getMacAddress()); - int tierNum = (tier == null) ? 0 : tier.getValue(); - System.out.println(node + " " + node.getType() + " " + macAddr + " " + nodeName + " " - + tierNum); + System.out.println(properties); + for (Node node : nodes) { + String nodeProp = String.format("%-26s ", node); + Map propList = sm.getNodeProps(node); + for (String s : sortedProps) { + if (propList.containsKey(s)) { + nodeProp = nodeProp.concat(String.format("%-18s ", propList.get(s).getStringValue())); + } else { + nodeProp = nodeProp.concat(String.format("%-18s ", "null")); + } + } + System.out.println(nodeProp); } System.out.println("Total number of Nodes: " + nodes.size()); } @@ -113,26 +113,34 @@ public class SwitchManagerCLI { return; } - System.out.println(" NodeConnector BandWidth(Gbps) Admin State"); Set nodeConnectorSet = sm.getNodeConnectors(target); - if (nodeConnectorSet == null) { + if (nodeConnectorSet == null || nodeConnectorSet.isEmpty()) { return; } + + Set propertyList = new HashSet(); + for (NodeConnector nodeConnector : nodeConnectorSet) { + Map propList = sm.getNodeConnectorProps(nodeConnector); + propertyList.addAll(propList.keySet()); + } + List sortedProps = new ArrayList(propertyList); + Collections.sort(sortedProps); + String properties = String.format("%-33s ", "NodeConnector"); + for (String s : sortedProps) { + properties = properties.concat(String.format("%-18s ", s)); + } + System.out.println(properties); for (NodeConnector nodeConnector : nodeConnectorSet) { - if (nodeConnector == null) { - continue; + String ncProp = String.format("%-33s ", nodeConnector); + Map ncProperties = sm.getNodeConnectorProps(nodeConnector); + for (String s : sortedProps) { + if (ncProperties.containsKey(s)) { + ncProp = ncProp.concat(String.format("%-18s ", ncProperties.get(s).getStringValue())); + } else { + ncProp = ncProp.concat(String.format("%-18s ", "null")); + } } - Map propMap = sm.getNodeConnectorProps(nodeConnector); - Bandwidth bw = (Bandwidth) propMap.get(Bandwidth.BandwidthPropName); - Config config = (Config) propMap.get(Config.ConfigPropName); - State state = (State) propMap.get(State.StatePropName); - String out = nodeConnector + " "; - out += (bw != null) ? bw.getValue() / Math.pow(10, 9) : " "; - out += " "; - out += (config != null) ? config.getValue() : " "; - out += " "; - out += (state != null) ? state.getValue() : " "; - System.out.println(out); + System.out.println(ncProp); } System.out.println("Total number of NodeConnectors: " + nodeConnectorSet.size()); }