X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Ftopologymanager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Ftopologymanager%2FTopologyUserLinkConfig.java;h=1b1e6f49d153d3b57ccfeb8e120bf2c3d6c7581d;hp=1bd9ac6baca666abd2456712e172000fde2f071b;hb=fa52e9399f9687c7290ed98b22b00cdce4a6aacd;hpb=29f7cfb54b580928c7feac63abce028a7014b0d5 diff --git a/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/TopologyUserLinkConfig.java b/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/TopologyUserLinkConfig.java index 1bd9ac6bac..1b1e6f49d1 100644 --- a/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/TopologyUserLinkConfig.java +++ b/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/TopologyUserLinkConfig.java @@ -10,22 +10,24 @@ package org.opendaylight.controller.topologymanager; import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import org.opendaylight.controller.sal.utils.GUIField; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.opendaylight.controller.sal.core.NodeConnector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * Interface class that provides methods to manipulate user configured link + * The Interface provides methods to manipulate user configured link. */ +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) public class TopologyUserLinkConfig implements Serializable { private static final long serialVersionUID = 1L; - private static final String regexDatapathID = "^([0-9a-fA-F]{1,2}[:-]){7}[0-9a-fA-F]{1,2}$"; - private static final String regexDatapathIDLong = "^[0-9a-fA-F]{1,16}$"; - private static final String guiFields[] = { GUIField.STATUS.toString(), - GUIField.NAME.toString(), GUIField.SRCNODE.toString(), - GUIField.SRCPORT.toString(), GUIField.DSTNODE.toString(), - GUIField.DSTPORT.toString() }; + private static final Logger logger = LoggerFactory.getLogger(TopologyUserLinkConfig.class); public enum STATUS { SUCCESS("Success"), LINKDOWN("Link Down"), INCORRECT( @@ -53,28 +55,28 @@ public class TopologyUserLinkConfig implements Serializable { } } + @XmlElement private String status; + @XmlElement private String name; - private String srcSwitchId; - private String srcPort; - private String dstSwitchId; - private String dstPort; + @XmlElement + private String srcNodeConnector; + @XmlElement + private String dstNodeConnector; public TopologyUserLinkConfig() { super(); status = STATUS.LINKDOWN.toString(); } - public TopologyUserLinkConfig(String name, String srcSwitchId, - String srcPort, String dstSwitchId, String dstPort) { + public TopologyUserLinkConfig(String name, String srcNodeConnector, String dstNodeConnector) { super(); this.name = name; - this.srcSwitchId = srcSwitchId; - this.dstSwitchId = dstSwitchId; - this.srcPort = srcPort; - this.dstPort = dstPort; + this.srcNodeConnector = srcNodeConnector; + this.dstNodeConnector = dstNodeConnector; } + public String getName() { return name; } @@ -83,45 +85,6 @@ public class TopologyUserLinkConfig implements Serializable { this.name = name; } - public String getSrcSwitchId() { - return srcSwitchId; - } - - public long getSrcSwitchIDLong() { - return getSwitchIDLong(srcSwitchId); - } - - public void setSrcSwitchId(String srcSwitchId) { - this.srcSwitchId = srcSwitchId; - } - - public String getDstSwitchId() { - return dstSwitchId; - } - - public long getDstSwitchIDLong() { - return getSwitchIDLong(dstSwitchId); - } - - public void setDstSwitchId(String dstSwitchId) { - this.dstSwitchId = dstSwitchId; - } - - public String getSrcPort() { - return srcPort; - } - - public void setSrcPort(String srcPort) { - this.srcPort = srcPort; - } - - public String getDstPort() { - return dstPort; - } - - public void setDstPort(String dstPort) { - this.dstPort = dstPort; - } public STATUS getStatus() { return STATUS.fromString(status); @@ -131,96 +94,56 @@ public class TopologyUserLinkConfig implements Serializable { this.status = s.toString(); } - private boolean isValidSwitchId(String switchId) { - return (switchId != null && (switchId.matches(regexDatapathID) || switchId - .matches(regexDatapathIDLong))); + public String getSrcNodeConnector() { + return srcNodeConnector; } - private long getSwitchIDLong(String switchId) { - int radix = 16; - String switchString = "0"; + public void setSrcNodeConnector(String srcNodeConnector) { + this.srcNodeConnector = srcNodeConnector; + } - if (isValidSwitchId(switchId)) { - if (switchId.contains(":")) { - // Handle the 00:00:AA:BB:CC:DD:EE:FF notation - switchString = switchId.replace(":", ""); - } else if (switchId.contains("-")) { - // Handle the 00-00-AA-BB-CC-DD-EE-FF notation - switchString = switchId.replace("-", ""); - } else { - // Handle the 0123456789ABCDEF notation - switchString = switchId; - } - } - return Long.parseLong(switchString, radix); + public String getDstNodeConnector() { + return dstNodeConnector; } - public boolean isValid() { - if (name == null || srcSwitchId == null || dstSwitchId == null - || srcPort == null || dstPort == null) - return false; - if (!isValidSwitchId(srcSwitchId) || !isValidSwitchId(dstSwitchId)) - return false; - return true; + public void setDstNodeConnector(String dstNodeConnector) { + this.dstNodeConnector = dstNodeConnector; } - public boolean isSrcPortByName() { - try { - Short.parseShort(srcPort); - } catch (Exception e) { - return true; - } - return false; + public boolean isValidNodeConnector(String nodeConnectorStr) { + NodeConnector nc = NodeConnector.fromString(nodeConnectorStr); + if (nc == null) return false; + return true; } - public boolean isDstPortByName() { - try { - Short.parseShort(dstPort); - } catch (Exception e) { - return true; + public boolean isValid() { + if (name == null || srcNodeConnector == null || dstNodeConnector == null) { + return false; } - return false; - } - public static List getGuiFieldsNames() { - List fieldList = new ArrayList(); - for (String str : guiFields) { - fieldList.add(str); + if (!isValidNodeConnector(srcNodeConnector) || + !isValidNodeConnector(dstNodeConnector)) { + logger.debug("Invalid NodeConnector in user link: {}", this); + return false; } - return fieldList; - } - @Override - public String toString() { - return "ITopologyUserLinkConfig [status=" + status + ", name=" + name - + ", srcSwitchId=" + srcSwitchId + ", srcPort=" + srcPort - + ", dstSwitchId=" + dstSwitchId + ", dstPort=" + dstPort + "]"; + return true; } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((dstPort == null) ? 0 : dstPort.hashCode()); - result = prime * result - + ((dstSwitchId == null) ? 0 : dstSwitchId.hashCode()); - result = prime * result + ((srcPort == null) ? 0 : srcPort.hashCode()); - result = prime * result - + ((srcSwitchId == null) ? 0 : srcSwitchId.hashCode()); + result = prime + * result + + ((dstNodeConnector == null) ? 0 : dstNodeConnector.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime + * result + + ((srcNodeConnector == null) ? 0 : srcNodeConnector.hashCode()); return result; } - public boolean equals(Long srcNid, String srcPortName, Long dstNid, - String dstPortName) { - if (srcNid.equals(getSrcSwitchIDLong()) - && dstNid.equals(getDstSwitchIDLong()) - && srcPortName.equals(getSrcPort()) - && dstPortName.equals(getDstPort())) { - return true; - } - return false; - } - @Override public boolean equals(Object obj) { if (this == obj) @@ -230,26 +153,23 @@ public class TopologyUserLinkConfig implements Serializable { if (getClass() != obj.getClass()) return false; TopologyUserLinkConfig other = (TopologyUserLinkConfig) obj; - if (dstPort == null) { - if (other.dstPort != null) - return false; - } else if (!dstPort.equals(other.dstPort)) - return false; - if (dstSwitchId == null) { - if (other.dstSwitchId != null) + if (dstNodeConnector == null) { + if (other.dstNodeConnector != null) return false; - } else if (!dstSwitchId.equals(other.dstSwitchId)) + } else if (!dstNodeConnector.equals(other.dstNodeConnector)) return false; - if (srcPort == null) { - if (other.srcPort != null) + if (srcNodeConnector == null) { + if (other.srcNodeConnector != null) return false; - } else if (!srcPort.equals(other.srcPort)) - return false; - if (srcSwitchId == null) { - if (other.srcSwitchId != null) - return false; - } else if (!srcSwitchId.equals(other.srcSwitchId)) + } else if (!srcNodeConnector.equals(other.srcNodeConnector)) return false; return true; } + + @Override + public String toString() { + return "TopologyUserLinkConfig [status=" + status + ", name=" + name + + ", srcNodeConnector=" + srcNodeConnector + + ", dstNodeConnector=" + dstNodeConnector + "]"; + } }