public String toString() {
return "Actions[" + actionsValue + "]";
}
+
+ @Override
+ public String getStringValue() {
+ return Integer.toHexString(actionsValue);
+ }
}
@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();
}
}
public String toString() {
return "Buffers[" + buffersValue + "]";
}
+
+ @Override
+ public String getStringValue() {
+ return Integer.toHexString(buffersValue);
+ }
}
public String toString() {
return "Capabilities[" + capabilitiesValue + "]";
}
+
+ @Override
+ public String getStringValue() {
+ return Integer.toHexString(capabilitiesValue);
+ }
}
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);
+ }
+ }
}
public String toString() {
return "Description[" + descriptionValue + "]";
}
+
+ @Override
+ public String getStringValue() {
+ return descriptionValue;
+ }
}
public String toString() {
return "Mode[" + modeValue + "]";
}
+
+ @Override
+ public String getStringValue() {
+ return (modeValue == ForwardingMode.PROACTIVE_FORWARDING) ? "Proactive" : "Reactive";
+ }
}
\ No newline at end of file
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";
+ }
+ }
}
public String toString() {
return "MacAddress[" + address + "]";
}
+
+ @Override
+ public String getStringValue() {
+ return address;
+ }
}
public String toString() {
return "Name[" + nameValue + "]";
}
+
+ @Override
+ public String getStringValue() {
+ return nameValue;
+ }
}
return this.name;
}
+ public abstract String getStringValue();
+
/**
* Used to copy the Property in a polymorphic way
*
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);
+ }
+ }
}
public String toString() {
return "Tables[" + tablesValue + "]";
}
+
+ @Override
+ public String getStringValue() {
+ return String.format("%02x", tablesValue);
+ }
}
public String toString() {
return "Tier[" + tierValue + "]";
}
+
+ @Override
+ public String getStringValue() {
+ return String.valueOf(tierValue);
+ }
}
package org.opendaylight.controller.sal.core;
+import java.util.Date;
+
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
public String toString() {
return "TimeStamp[" + timestampName + ": " + timestamp +"]";
}
+
+ @Override
+ public String getStringValue() {
+ return timestampName + ": " + new Date(timestamp);
+ }
}
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);
}
}
}
- // 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);
}
}
+ 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) {
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");
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) {
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) {
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());
}