Checkstyle enforcer
[controller.git] / opendaylight / samples / loadbalancer / src / main / java / org / opendaylight / controller / samples / loadbalancer / entities / VIP.java
1 /*
2  * Copyright IBM Corporation, 2013.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.samples.loadbalancer.entities;
9
10 import javax.xml.bind.annotation.XmlAccessType;
11 import javax.xml.bind.annotation.XmlAccessorType;
12 import javax.xml.bind.annotation.XmlElement;
13 import javax.xml.bind.annotation.XmlRootElement;
14
15 /**
16  * This class represents the Virtual IP  (VIP) address exposed by the load balancer application.
17  * Load balancer service differentiates one VIP from the other, using the following three properties:
18  * 1. IP address of the VIP exposed by the application
19  * 2. Protocol of the network traffic (TCP/UDP)
20  * 3. Port to which incoming traffic is destined
21  *
22  * User is allowed to create mutliple VIPs with the same IP, but all such VIPs (with the same IP)
23  * should differ at least in the protocol or port or both.
24  *
25  * NOTE: Each VIP should have a unique name.
26  */
27 @XmlRootElement(name="vip")
28 @XmlAccessorType(XmlAccessType.NONE)
29
30 public class VIP {
31
32     /*
33      * Unique name of the VIP
34      */
35     @XmlElement
36     private String name;
37
38     /*
39      * Virtual IP address of the VIP
40      */
41     @XmlElement
42     private String ip;
43
44     /*
45      *  Network traffic protocol
46      */
47     @XmlElement
48     private String protocol;
49
50     /*
51      * Port where network traffic is destined (destination port)
52      */
53     @XmlElement
54     private short port;
55
56     /*
57      * Name of the pool attached to the VIP for load balancing its traffic
58      */
59     @XmlElement(name="poolname")
60     private String poolName;
61
62     /*
63      * Status (Active/inactive)
64      */
65     @XmlElement
66     private String status;
67
68     /**
69      * Private constructor used for JAXB mapping
70      */
71     @SuppressWarnings("unused")
72     private VIP() {}
73
74     public VIP(String name,
75                 String ip,
76                 String protocol,
77                 short port,
78                 String poolName){
79         this.name = name;
80         this.ip=ip;
81         this.protocol=protocol;
82         this.port = port;
83         this.poolName = poolName;
84     }
85
86     public String getName() {
87         return name;
88     }
89
90     public void setName(String name) {
91         this.name = name;
92     }
93
94     public String getIp() {
95         return ip;
96     }
97
98     public void setIp(String ip) {
99         this.ip = ip;
100     }
101
102     public String getProtocol() {
103         return protocol;
104     }
105
106     public void setProtocol(String protocol) {
107         this.protocol = protocol;
108     }
109
110     public short getPort() {
111         return port;
112     }
113
114     public void setPort(short port) {
115         this.port = port;
116     }
117
118     public String getPoolName() {
119         return poolName;
120     }
121
122     public void setPoolName(String poolName) {
123         this.poolName = poolName;
124     }
125
126     /**
127      * @return the status
128      */
129     public String getStatus() {
130         return status;
131     }
132
133     /**
134      * @param status the status to set
135      */
136     public void setStatus(String status) {
137         this.status = status;
138     }
139
140     /* (non-Javadoc)
141      * @see java.lang.Object#hashCode()
142      */
143     @Override
144     public int hashCode() {
145         final int prime = 31;
146         int result = 1;
147         result = prime * result + ((ip == null) ? 0 : ip.hashCode());
148         result = prime * result + port;
149         result = prime * result
150                 + ((protocol == null) ? 0 : protocol.hashCode());
151         return result;
152     }
153
154     /* (non-Javadoc)
155      * @see java.lang.Object#equals(java.lang.Object)
156      */
157     @Override
158     public boolean equals(Object obj) {
159         if (this == obj) {
160             return true;
161
162         }
163         if (obj == null) {
164             return false;
165         }
166         if (!(obj instanceof VIP)) {
167             return false;
168         }
169
170         VIP other = (VIP) obj;
171         if (ip == null) {
172             if (other.ip != null) {
173                 return false;
174             }
175         }else if (!ip.equals(other.ip)) {
176             return false;
177         }
178         if (port != other.port) {
179             return false;
180         }
181         if (protocol == null) {
182             if (other.protocol != null) {
183                 return false;
184             }
185         }else if (!protocol.equalsIgnoreCase(other.protocol)) {
186             return false;
187         }
188         return true;
189     }
190
191     /* (non-Javadoc)
192      * @see java.lang.Object#toString()
193      */
194     @Override
195     public String toString() {
196         return "VIP [name=" + name + ", ip=" + ip + ", protocol=" + protocol
197                             + ", port=" + port + ", poolName=" + poolName + ", status="
198                             + status + "]";
199     }
200 }