Enhancement to switchmanager CLI commands to display all the properties of node and... 09/1109/1
authorPramila Singh <pramisin@cisco.com>
Fri, 6 Sep 2013 05:55:38 +0000 (22:55 -0700)
committerPramila Singh <pramisin@cisco.com>
Fri, 6 Sep 2013 05:58:29 +0000 (22:58 -0700)
Change-Id: I87ee445168e64cc74a7538593503cb43f4e1f50a
Signed-off-by: Pramila Singh <pramisin@cisco.com>
17 files changed:
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Bandwidth.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Buffers.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Capabilities.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Config.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Description.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ForwardingMode.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Latency.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/MacAddress.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Name.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Property.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/State.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Tables.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Tier.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/TimeStamp.java
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerCLI.java

index c26800890bb933d4dd5702dda513bcdec4b37e5f..7b934edfa78df7ad08cf427545c8d1b3f6f502ff 100644 (file)
@@ -105,4 +105,9 @@ public class Actions extends Property {
     public String toString() {
         return "Actions[" + actionsValue + "]";
     }
+
+    @Override
+    public String getStringValue() {
+        return Integer.toHexString(actionsValue);
+    }
 }
index 1282d5ef9c2c18259077390a32a4d6840c8ac068..8c3a97751804215414c9ae9aaa0c3206482921a1 100644 (file)
@@ -105,24 +105,25 @@ public class Bandwidth extends Property {
 
     @Override
     public String toString() {
-        StringBuffer sb = new StringBuffer();
+        return "BandWidth[" + getStringValue() + "]";
+    }
 
-        sb.append("BandWidth[");
+    @Override
+    public String getStringValue() {
         if (this.bandwidthValue == 0) {
-            sb.append("UnKnown");
+            return("UnKnown");
         } else if (this.bandwidthValue < BW1Kbps) {
-            sb.append(this.bandwidthValue + "bps");
+            return(this.bandwidthValue + "bps");
         } else if (this.bandwidthValue < BW1Mbps) {
-            sb.append(Long.toString(this.bandwidthValue / BW1Kbps) + "Kbps");
+            return(Long.toString(this.bandwidthValue / BW1Kbps) + "Kbps");
         } else if (this.bandwidthValue < BW1Gbps) {
-            sb.append(Long.toString(this.bandwidthValue / BW1Mbps) + "Mbps");
+            return(Long.toString(this.bandwidthValue / BW1Mbps) + "Mbps");
         } else if (this.bandwidthValue < BW1Tbps) {
-            sb.append(Long.toString(this.bandwidthValue / BW1Gbps) + "Gbps");
+            return(Long.toString(this.bandwidthValue / BW1Gbps) + "Gbps");
         } else if (this.bandwidthValue < BW1Pbps) {
-            sb.append(Long.toString(this.bandwidthValue / BW1Tbps) + "Tbps");
+            return(Long.toString(this.bandwidthValue / BW1Tbps) + "Tbps");
+        } else {
+            return(this.bandwidthValue + "bps");
         }
-
-        sb.append("]");
-        return sb.toString();
     }
 }
index 6d7369d72bb6f25480cc2d40f359b240eeaed8f8..4c6e08102b214341f237e01d6280d375aaf30eeb 100644 (file)
@@ -81,4 +81,9 @@ public class Buffers extends Property {
     public String toString() {
         return "Buffers[" + buffersValue + "]";
     }
+
+    @Override
+    public String getStringValue() {
+        return Integer.toHexString(buffersValue);
+    }
 }
index 7867b93a683d48f565b65cf03ba3a710b7fe3e5c..b2005913d0dc214d5f2ef9d496969d1452020fde 100644 (file)
@@ -98,4 +98,9 @@ public class Capabilities extends Property {
     public String toString() {
         return "Capabilities[" + capabilitiesValue + "]";
     }
+
+    @Override
+    public String getStringValue() {
+        return Integer.toHexString(capabilitiesValue);
+    }
 }
index ef6efc58211577fb9799509c1d998949a44364dc..651c2f44e12ac8f3a93612b6dda5c3e8ca820e1c 100644 (file)
@@ -75,4 +75,17 @@ public class Config extends Property {
     public String toString() {
         return "Config["+ configValue +"]";
     }
+
+    @Override
+    public String getStringValue() {
+        if (configValue == 0) {
+            return "ADMIN_DOWN";
+        } else if (configValue == 1) {
+            return "ADMIN_UP";
+        } else if (configValue == 0x7fff) {
+            return "ADMIN_UNDEF";
+        } else {
+            return String.valueOf(configValue);
+        }
+    }
 }
index 6915404e24ab43af15299c1469695101b53a6984..ebc12cdbf7a28d86cdafce135e0e98881846806b 100644 (file)
@@ -65,4 +65,9 @@ public class Description extends Property {
     public String toString() {
         return "Description[" + descriptionValue + "]";
     }
+
+    @Override
+    public String getStringValue() {
+        return descriptionValue;
+    }
 }
index a1d4ff9db735476fa593f0fe2f2c577b13b9d473..1b19f19778ddba6c21ae8437d5e06be44b7d3898 100644 (file)
@@ -71,4 +71,9 @@ public class ForwardingMode extends Property {
     public String toString() {
         return "Mode[" + modeValue + "]";
     }
+
+    @Override
+    public String getStringValue() {
+        return (modeValue == ForwardingMode.PROACTIVE_FORWARDING) ? "Proactive" : "Reactive";
+    }
 }
\ No newline at end of file
index a0ba47b29d2458aadcffa90e115f0c1a218602e6..a64ee105cf0efab3f7f6559a89f85deb6639872b 100644 (file)
@@ -112,4 +112,21 @@ public class Latency extends Property {
         sb.append("]");
         return sb.toString();
     }
+
+    @Override
+    public String getStringValue() {
+        if (this.latencyValue == 0) {
+            return("UnKnown");
+        } else if (this.latencyValue < LATENCY1ns) {
+            return(this.latencyValue + "psec");
+        } else if (this.latencyValue < LATENCY1us) {
+            return(Long.toString(this.latencyValue / LATENCY1ns) + "nsec");
+        } else if (this.latencyValue < LATENCY1ms) {
+            return(Long.toString(this.latencyValue / LATENCY1us) + "usec");
+        } else if (this.latencyValue < LATENCY1s) {
+            return(Long.toString(this.latencyValue / LATENCY1ms) + "msec");
+        } else {
+            return Long.toString(this.latencyValue) + "sec";
+        }
+    }
 }
index 27e74e08008094759bda6bc5c6c846f40eef262c..2dfa9168fe91905b52a2312e6f493692fe6d6172 100644 (file)
@@ -109,4 +109,9 @@ public class MacAddress extends Property implements Cloneable {
     public String toString() {
         return "MacAddress[" + address + "]";
     }
+
+    @Override
+    public String getStringValue() {
+        return address;
+    }
 }
index d35610add0f6b2df7101dd6e3422f6252d272e4e..92c8454a4d6d77d92bb1b669883a252fe7237087 100644 (file)
@@ -74,4 +74,9 @@ public class Name extends Property {
     public String toString() {
         return "Name[" + nameValue + "]";
     }
+
+    @Override
+    public String getStringValue() {
+        return nameValue;
+    }
 }
index 574f6d02381303afba11f827aed6bbd972cd00fd..a5deb547e351c1f154fd0eade864173aa82c011b 100644 (file)
@@ -53,6 +53,8 @@ abstract public class Property implements Serializable, Cloneable {
         return this.name;
     }
 
+    public abstract String getStringValue();
+
     /**
      * Used to copy the Property in a polymorphic way
      *
index 058adb63e2156172879dbf7b6d512f7258d2a725..e47542a7bef9f259bfab5ca21bbca82fc528e980 100644 (file)
@@ -76,4 +76,17 @@ public class State extends Property {
     public String toString() {
         return "State[" + stateValue + "]";
     }
+
+    @Override
+    public String getStringValue() {
+        if (stateValue == 0) {
+            return ("EDGE_DOWN");
+        } else if (stateValue == 1) {
+            return ("EDGE_UP");
+        } else if (stateValue == 0x7fff) {
+            return ("EDGE_UNK");
+        } else {
+            return String.valueOf(stateValue);
+        }
+    }
 }
index bd50cf9be067aea6b842e7c9d1e3d8da1b9c746b..b92c4b693c063bb6e9a093b84ee32c62de19f8fa 100644 (file)
@@ -80,4 +80,9 @@ public class Tables extends Property {
     public String toString() {
         return "Tables[" + tablesValue + "]";
     }
+
+    @Override
+    public String getStringValue() {
+        return String.format("%02x", tablesValue);
+    }
 }
index 6756a8213547b1851c1457432827f8934e8b1979..d1af778526bce58b9a1e8841a3cb8d2d64aa5712 100644 (file)
@@ -72,4 +72,9 @@ public class Tier extends Property {
     public String toString() {
         return "Tier[" + tierValue + "]";
     }
+
+    @Override
+    public String getStringValue() {
+        return String.valueOf(tierValue);
+    }
 }
index b38ec8582b17db2d765a35c9df4d3b888ed96228..a2d3d36c6f044a286e37e8eaf7674f72c5f7950e 100644 (file)
@@ -9,6 +9,8 @@
 
 package org.opendaylight.controller.sal.core;
 
+import java.util.Date;
+
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
@@ -103,4 +105,9 @@ public class TimeStamp extends Property {
     public String toString() {
         return "TimeStamp[" + timestampName + ": " + timestamp +"]";
     }
+
+    @Override
+    public String getStringValue() {
+        return timestampName + ": " + new Date(timestamp);
+    }
 }
index d3d41be19f8d6061d2f5f9502c0678fe71cf332e..60330c1ad46b4709c56267578b411ccba2d4aefa 100644 (file)
@@ -772,6 +772,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
                         propMap.put(Description.propertyName, desc);
                     }
                     continue;
+                } else if (prop.equals(ForwardingMode.name)) {
+                    Property defaultMode = new ForwardingMode(ForwardingMode.REACTIVE_FORWARDING);
+                    propMap.put(ForwardingMode.name, defaultMode);
+                    continue;
                 }
                 propMap.remove(prop);
             }
@@ -911,8 +915,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
             }
         }
 
-        // copy node properties from config
         boolean proactiveForwarding = false;
+        // copy node properties from config
         if (nodeConfigList != null) {
             String nodeId = node.toString();
             SwitchConfig conf = nodeConfigList.get(nodeId);
@@ -926,6 +930,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
             }
         }
 
+        if (!propMap.containsKey(ForwardingMode.name)) {
+            Property defaultMode = new ForwardingMode(ForwardingMode.REACTIVE_FORWARDING);
+            propMap.put(ForwardingMode.name, defaultMode);
+        }
         boolean result = false;
         if (propMapCurr == null) {
             if (nodeProps.putIfAbsent(node, propMap) == null) {
@@ -1758,8 +1766,6 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
     public String getHelp() {
         StringBuffer help = new StringBuffer();
         help.append("---Switch Manager---\n");
-        help.append("\t pns                    - Print connected nodes\n");
-        help.append("\t pncs <node id>         - Print node connectors for a given node\n");
         help.append("\t pencs <node id>        - Print enabled node connectors for a given node\n");
         help.append("\t pdm <node id>          - Print switch ports in device map\n");
         help.append("\t snt <node id> <tier>   - Set node tier number\n");
@@ -1768,37 +1774,6 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         return help.toString();
     }
 
-    public void _pns(CommandInterpreter ci) {
-        ci.println("           Node               Type           MAC            Name      Tier");
-        if (nodeProps == null) {
-            return;
-        }
-        Set<Node> nodeSet = nodeProps.keySet();
-        if (nodeSet == null) {
-            return;
-        }
-        List<String> nodeArray = new ArrayList<String>();
-        for (Node node : nodeSet) {
-            nodeArray.add(node.toString());
-        }
-        Collections.sort(nodeArray);
-        for (String str: nodeArray) {
-            Node node = Node.fromString(str);
-            Description desc = ((Description) getNodeProp(node,
-                    Description.propertyName));
-            Tier tier = ((Tier) getNodeProp(node, Tier.TierPropName));
-            String nodeName = (desc == null) ? "" : desc.getValue();
-            MacAddress mac = (MacAddress) getNodeProp(node,
-                    MacAddress.name);
-            String macAddr = (mac == null) ? "" : HexEncode
-                    .bytesToHexStringFormat(mac.getMacAddress());
-            int tierNum = (tier == null) ? 0 : tier.getValue();
-            ci.println(node + "     " + node.getType() + "     " + macAddr
-                    + "     " + nodeName + "     " + tierNum);
-        }
-        ci.println("Total number of Nodes: " + nodeSet.size());
-    }
-
     public void _pencs(CommandInterpreter ci) {
         String st = ci.nextArgument();
         if (st == null) {
@@ -1825,43 +1800,6 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         ci.println("Total number of NodeConnectors: " + nodeConnectorSet.size());
     }
 
-    public void _pncs(CommandInterpreter ci) {
-        String st = ci.nextArgument();
-        if (st == null) {
-            ci.println("Please enter node id");
-            return;
-        }
-
-        Node node = Node.fromString(st);
-        if (node == null) {
-            ci.println("Please enter node id");
-            return;
-        }
-
-        ci.println("          NodeConnector               BandWidth(Gbps)     Admin     State");
-        Set<NodeConnector> nodeConnectorSet = getNodeConnectors(node);
-        if (nodeConnectorSet == null) {
-            return;
-        }
-        for (NodeConnector nodeConnector : nodeConnectorSet) {
-            if (nodeConnector == null) {
-                continue;
-            }
-            Map<String, Property> propMap = 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() : " ";
-            ci.println(out);
-        }
-        ci.println("Total number of NodeConnectors: " + nodeConnectorSet.size());
-    }
-
     public void _pdm(CommandInterpreter ci) {
         String st = ci.nextArgument();
         if (st == null) {
index bcf9fd6d0b33e47da103e5646a86be8566b78176..268e45ad85891f0c1d274447dfca0e66520bb1c7 100644 (file)
@@ -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<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());
     }
@@ -113,26 +113,34 @@ public class SwitchManagerCLI {
             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());
     }