Revert "Checkstyle enforcer"
[controller.git] / opendaylight / samples / loadbalancer / src / main / java / org / opendaylight / controller / samples / loadbalancer / entities / Client.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 /**
11  * This class represents the source host that sends any traffic to any existing virtual IP (VIP).
12  * This source host is referred to as a 'Client'. Clients will be differentiated from each other
13  * based on the following three properties:
14  * 1. IP address of the client.
15  * 2. Protocol of the traffic it is using for sending traffic
16  * 3. Source port from which it is sending traffic.
17  * e.g TCP traffic from two different ports from the same host to a given VIP will be considered
18  * as two different clients by this service. Similarly, traffic using two different protocols
19  * (TCP, UDP) from the same host will be considered as two different clients.
20  * 
21  */
22 public class Client {
23     
24     /*
25      * IP address of the client (source address)
26      */
27     private String ip;
28     
29     /*
30      * Network protocol of the traffic sent by client
31      */
32     private String protocol;
33     
34     /*
35      * Port used to send network traffic (source port)
36      */
37     private short port;
38     
39     public Client(String ip, String protocol, short port){
40         this.ip = ip;
41         this.protocol = protocol;
42         this.port = port;
43     }
44     
45     /**
46      * @return the client IP
47      */
48     public String getIp() {
49         return ip;
50     }
51     
52     /**
53      * @param ip the IP to set
54      */
55     public void setIp(String ip) {
56         this.ip = ip;
57     }
58     
59     /**
60      * @return the client network protocol
61      */
62     public String getProtocol() {
63         return protocol;
64     }
65     
66     /**
67      * @param protocol the protocol to set
68      */
69     public void setProtocol(String protocol) {
70         this.protocol = protocol;
71     }
72     
73     /**
74      * @return the client port
75      */
76     public short getPort() {
77         return port;
78     }
79     
80     /**
81      * @param port the port to set
82      */
83     public void setPort(short port) {
84         this.port = port;
85     }
86     
87     /* (non-Javadoc)
88      * @see java.lang.Object#hashCode()
89      */
90     @Override
91     public int hashCode() {
92         final int prime = 31;
93         int result = 1;
94         result = prime * result + ((ip == null) ? 0 : ip.hashCode());
95         result = prime * result + port;
96         result = prime * result+ ((protocol == null) ? 0 : protocol.hashCode());
97         return result;
98     }
99     
100     /* (non-Javadoc)
101      * @see java.lang.Object#equals(java.lang.Object)
102      */
103     @Override
104     public boolean equals(Object obj) {
105         if (this == obj) {
106             return true;
107         }
108         if (obj == null) {
109             return false;
110         }
111         if (!(obj instanceof Client)) {
112             return false;
113         }
114         Client other = (Client) obj;
115         if (ip == null) {
116             if (other.ip != null) {
117                 return false;
118             }
119         }else if (!ip.equals(other.ip)) {
120             return false;
121         }
122         if (port != other.port) {
123             return false;
124         }
125         if (protocol == null) {
126             if (other.protocol != null) {
127                 return false;
128             }
129         }else if (!protocol.equals(other.protocol)) {
130             return false;
131         }
132         return true;
133     }
134     
135     /* (non-Javadoc)
136      * @see java.lang.Object#toString()
137      */
138     @Override
139     public String toString() {
140         return "Client [ip=" + ip + ", protocol=" + protocol + ", port=" + port+ "]";
141     }
142 }