Merge "Fail toggle flow if port is no longer a part of slice"
[controller.git] / opendaylight / topologymanager / implementation / src / main / java / org / opendaylight / controller / topologymanager / TopologyUserLinkConfig.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.topologymanager;
11
12 import java.io.Serializable;
13
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
18
19 import org.opendaylight.controller.sal.core.NodeConnector;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * The Interface provides methods to manipulate user configured link.
25  */
26 @XmlRootElement
27 @XmlAccessorType(XmlAccessType.NONE)
28 public class TopologyUserLinkConfig implements Serializable {
29     private static final long serialVersionUID = 1L;
30     private static final Logger logger = LoggerFactory.getLogger(TopologyUserLinkConfig.class);
31
32     public enum STATUS {
33         SUCCESS("Success"), LINKDOWN("Link Down"), INCORRECT(
34                 "Incorrect Connection");
35         private STATUS(String name) {
36             this.name = name;
37         }
38
39         private String name;
40
41         public String toString() {
42             return name;
43         }
44
45         public static STATUS fromString(String str) {
46             if (str == null)
47                 return LINKDOWN;
48             if (str.equals(SUCCESS.toString()))
49                 return SUCCESS;
50             if (str.equals(LINKDOWN.toString()))
51                 return LINKDOWN;
52             if (str.equals(INCORRECT.toString()))
53                 return INCORRECT;
54             return LINKDOWN;
55         }
56     }
57
58     @XmlElement
59     private String status;
60     @XmlElement
61     private String name;
62     @XmlElement
63     private String srcNodeConnector;
64     @XmlElement
65     private String dstNodeConnector;
66
67     public TopologyUserLinkConfig() {
68         super();
69         status = STATUS.LINKDOWN.toString();
70     }
71
72     public TopologyUserLinkConfig(String name, String srcNodeConnector, String dstNodeConnector) {
73         super();
74         this.name = name;
75         this.srcNodeConnector = srcNodeConnector;
76         this.dstNodeConnector = dstNodeConnector;
77     }
78
79
80     public String getName() {
81         return name;
82     }
83
84     public void setName(String name) {
85         this.name = name;
86     }
87
88
89     public STATUS getStatus() {
90         return STATUS.fromString(status);
91     }
92
93     public void setStatus(STATUS s) {
94         this.status = s.toString();
95     }
96
97     public String getSrcNodeConnector() {
98         return srcNodeConnector;
99     }
100
101     public void setSrcNodeConnector(String srcNodeConnector) {
102         this.srcNodeConnector = srcNodeConnector;
103     }
104
105     public String getDstNodeConnector() {
106         return dstNodeConnector;
107     }
108
109     public void setDstNodeConnector(String dstNodeConnector) {
110         this.dstNodeConnector = dstNodeConnector;
111     }
112
113     public boolean isValidNodeConnector(String nodeConnectorStr) {
114         NodeConnector nc = NodeConnector.fromString(nodeConnectorStr);
115         if (nc == null) return false;
116         return true;
117     }
118
119     public boolean isValid() {
120         if (name == null || srcNodeConnector == null || dstNodeConnector == null) {
121             return false;
122         }
123
124         if (!isValidNodeConnector(srcNodeConnector) ||
125                 !isValidNodeConnector(dstNodeConnector)) {
126             logger.debug("Invalid NodeConnector in user link: {}", this);
127             return false;
128         }
129
130         return true;
131     }
132
133     @Override
134     public int hashCode() {
135         final int prime = 31;
136         int result = 1;
137         result = prime
138                 * result
139                 + ((dstNodeConnector == null) ? 0 : dstNodeConnector.hashCode());
140         result = prime * result + ((name == null) ? 0 : name.hashCode());
141         result = prime
142                 * result
143                 + ((srcNodeConnector == null) ? 0 : srcNodeConnector.hashCode());
144         return result;
145     }
146
147     @Override
148     public boolean equals(Object obj) {
149         if (this == obj)
150             return true;
151         if (obj == null)
152             return false;
153         if (getClass() != obj.getClass())
154             return false;
155         TopologyUserLinkConfig other = (TopologyUserLinkConfig) obj;
156         if (dstNodeConnector == null) {
157             if (other.dstNodeConnector != null)
158                 return false;
159         } else if (!dstNodeConnector.equals(other.dstNodeConnector))
160             return false;
161         if (srcNodeConnector == null) {
162             if (other.srcNodeConnector != null)
163                 return false;
164         } else if (!srcNodeConnector.equals(other.srcNodeConnector))
165             return false;
166         return true;
167     }
168
169     @Override
170     public String toString() {
171         return "TopologyUserLinkConfig [status=" + status + ", name=" + name
172                 + ", srcNodeConnector=" + srcNodeConnector
173                 + ", dstNodeConnector=" + dstNodeConnector + "]";
174     }
175 }