3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.topologymanager;
12 import java.io.Serializable;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.opendaylight.controller.sal.utils.GUIField;
19 * Interface class that provides methods to manipulate user configured link
21 public class TopologyUserLinkConfig implements Serializable {
22 private static final long serialVersionUID = 1L;
23 private static final String regexDatapathID = "^([0-9a-fA-F]{1,2}[:-]){7}[0-9a-fA-F]{1,2}$";
24 private static final String regexDatapathIDLong = "^[0-9a-fA-F]{1,16}$";
25 private static final String guiFields[] = { GUIField.STATUS.toString(),
26 GUIField.NAME.toString(), GUIField.SRCNODE.toString(),
27 GUIField.SRCPORT.toString(), GUIField.DSTNODE.toString(),
28 GUIField.DSTPORT.toString() };
31 SUCCESS("Success"), LINKDOWN("Link Down"), INCORRECT(
32 "Incorrect Connection");
33 private STATUS(String name) {
39 public String toString() {
43 public static STATUS fromString(String str) {
46 if (str.equals(SUCCESS.toString()))
48 if (str.equals(LINKDOWN.toString()))
50 if (str.equals(INCORRECT.toString()))
56 private String status;
58 private String srcSwitchId;
59 private String srcPort;
60 private String dstSwitchId;
61 private String dstPort;
63 public TopologyUserLinkConfig() {
65 status = STATUS.LINKDOWN.toString();
68 public TopologyUserLinkConfig(String name, String srcSwitchId,
69 String srcPort, String dstSwitchId, String dstPort) {
72 this.srcSwitchId = srcSwitchId;
73 this.dstSwitchId = dstSwitchId;
74 this.srcPort = srcPort;
75 this.dstPort = dstPort;
78 public String getName() {
82 public void setName(String name) {
86 public String getSrcSwitchId() {
90 public long getSrcSwitchIDLong() {
91 return getSwitchIDLong(srcSwitchId);
94 public void setSrcSwitchId(String srcSwitchId) {
95 this.srcSwitchId = srcSwitchId;
98 public String getDstSwitchId() {
102 public long getDstSwitchIDLong() {
103 return getSwitchIDLong(dstSwitchId);
106 public void setDstSwitchId(String dstSwitchId) {
107 this.dstSwitchId = dstSwitchId;
110 public String getSrcPort() {
114 public void setSrcPort(String srcPort) {
115 this.srcPort = srcPort;
118 public String getDstPort() {
122 public void setDstPort(String dstPort) {
123 this.dstPort = dstPort;
126 public STATUS getStatus() {
127 return STATUS.fromString(status);
130 public void setStatus(STATUS s) {
131 this.status = s.toString();
134 private boolean isValidSwitchId(String switchId) {
135 return (switchId != null && (switchId.matches(regexDatapathID) || switchId
136 .matches(regexDatapathIDLong)));
139 private long getSwitchIDLong(String switchId) {
141 String switchString = "0";
143 if (isValidSwitchId(switchId)) {
144 if (switchId.contains(":")) {
145 // Handle the 00:00:AA:BB:CC:DD:EE:FF notation
146 switchString = switchId.replace(":", "");
147 } else if (switchId.contains("-")) {
148 // Handle the 00-00-AA-BB-CC-DD-EE-FF notation
149 switchString = switchId.replace("-", "");
151 // Handle the 0123456789ABCDEF notation
152 switchString = switchId;
155 return Long.parseLong(switchString, radix);
158 public boolean isValid() {
159 if (name == null || srcSwitchId == null || dstSwitchId == null
160 || srcPort == null || dstPort == null)
162 if (!isValidSwitchId(srcSwitchId) || !isValidSwitchId(dstSwitchId))
167 public boolean isSrcPortByName() {
169 Short.parseShort(srcPort);
170 } catch (Exception e) {
176 public boolean isDstPortByName() {
178 Short.parseShort(dstPort);
179 } catch (Exception e) {
185 public static List<String> getGuiFieldsNames() {
186 List<String> fieldList = new ArrayList<String>();
187 for (String str : guiFields) {
194 public String toString() {
195 return "ITopologyUserLinkConfig [status=" + status + ", name=" + name
196 + ", srcSwitchId=" + srcSwitchId + ", srcPort=" + srcPort
197 + ", dstSwitchId=" + dstSwitchId + ", dstPort=" + dstPort + "]";
201 public int hashCode() {
202 final int prime = 31;
204 result = prime * result + ((dstPort == null) ? 0 : dstPort.hashCode());
205 result = prime * result
206 + ((dstSwitchId == null) ? 0 : dstSwitchId.hashCode());
207 result = prime * result + ((srcPort == null) ? 0 : srcPort.hashCode());
208 result = prime * result
209 + ((srcSwitchId == null) ? 0 : srcSwitchId.hashCode());
213 public boolean equals(Long srcNid, String srcPortName, Long dstNid,
214 String dstPortName) {
215 if (srcNid.equals(getSrcSwitchIDLong())
216 && dstNid.equals(getDstSwitchIDLong())
217 && srcPortName.equals(getSrcPort())
218 && dstPortName.equals(getDstPort())) {
225 public boolean equals(Object obj) {
230 if (getClass() != obj.getClass())
232 TopologyUserLinkConfig other = (TopologyUserLinkConfig) obj;
233 if (dstPort == null) {
234 if (other.dstPort != null)
236 } else if (!dstPort.equals(other.dstPort))
238 if (dstSwitchId == null) {
239 if (other.dstSwitchId != null)
241 } else if (!dstSwitchId.equals(other.dstSwitchId))
243 if (srcPort == null) {
244 if (other.srcPort != null)
246 } else if (!srcPort.equals(other.srcPort))
248 if (srcSwitchId == null) {
249 if (other.srcSwitchId != null)
251 } else if (!srcSwitchId.equals(other.srcSwitchId))