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;
return;
}
- System.out.println(" Node Type MAC Name Tier");
-
Set<Node> nodes = sm.getNodes();
if (nodes == null || nodes.isEmpty()) {
return;
}
- List<String> nodeArray = new ArrayList<String>();
+ Set<String> propertyList = new HashSet<String>();
for (Node node : nodes) {
- nodeArray.add(node.toString());
+ Map<String, Property> propList = sm.getNodeProps(node);
+ propertyList.addAll(propList.keySet());
+ }
+ List<String> sortedProps = new ArrayList<String>(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<String, Property> 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());
}
return;
}
- System.out.println(" NodeConnector BandWidth(Gbps) Admin State");
Set<NodeConnector> nodeConnectorSet = sm.getNodeConnectors(target);
- if (nodeConnectorSet == null) {
+ if (nodeConnectorSet == null || nodeConnectorSet.isEmpty()) {
return;
}
+
+ Set<String> propertyList = new HashSet<String>();
+ for (NodeConnector nodeConnector : nodeConnectorSet) {
+ Map<String, Property> propList = sm.getNodeConnectorProps(nodeConnector);
+ propertyList.addAll(propList.keySet());
+ }
+ List<String> sortedProps = new ArrayList<String>(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<String, Property> 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<String, Property> 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());
}