blob: af97763c67f22d929a8d6673e955d1c7e13ddafb [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
Madan Jampaniab6d3112014-10-02 16:30:14 -070016package org.onlab.netty;
17
Madan Jampani2e5f87b2015-02-22 10:37:15 -080018import static com.google.common.base.Preconditions.*;
19
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070020import java.util.Objects;
21
Madan Jampani2e5f87b2015-02-22 10:37:15 -080022import org.onlab.packet.IpAddress;
23
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070024import com.google.common.base.MoreObjects;
25
Madan Jampaniab6d3112014-10-02 16:30:14 -070026/**
27 * Representation of a TCP/UDP communication end point.
28 */
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080029public final class Endpoint {
Madan Jampaniab6d3112014-10-02 16:30:14 -070030
31 private final int port;
Madan Jampani2e5f87b2015-02-22 10:37:15 -080032 private final IpAddress ip;
Madan Jampaniab6d3112014-10-02 16:30:14 -070033
Madan Jampani2e5f87b2015-02-22 10:37:15 -080034 public Endpoint(IpAddress host, int port) {
35 this.ip = checkNotNull(host);
Madan Jampaniab6d3112014-10-02 16:30:14 -070036 this.port = port;
37 }
38
Madan Jampani2e5f87b2015-02-22 10:37:15 -080039 public IpAddress host() {
40 return ip;
Madan Jampaniab6d3112014-10-02 16:30:14 -070041 }
42
43 public int port() {
44 return port;
45 }
46
47 @Override
48 public String toString() {
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070049 return MoreObjects.toStringHelper(getClass())
Madan Jampani2e5f87b2015-02-22 10:37:15 -080050 .add("ip", ip)
Madan Jampani15cd0b82014-10-28 08:40:23 -070051 .add("port", port)
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070052 .toString();
Madan Jampaniab6d3112014-10-02 16:30:14 -070053 }
54
55 @Override
56 public int hashCode() {
Madan Jampani2e5f87b2015-02-22 10:37:15 -080057 return Objects.hash(ip, port);
Madan Jampaniab6d3112014-10-02 16:30:14 -070058 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (this == obj) {
63 return true;
64 }
65 if (obj == null) {
66 return false;
67 }
68 if (getClass() != obj.getClass()) {
69 return false;
70 }
Yuta HIGUCHI97b81672014-10-06 23:07:56 -070071 Endpoint that = (Endpoint) obj;
72 return Objects.equals(this.port, that.port) &&
Madan Jampani2e5f87b2015-02-22 10:37:15 -080073 Objects.equals(this.ip, that.ip);
Madan Jampaniab6d3112014-10-02 16:30:14 -070074 }
Yuta HIGUCHI92626c02014-10-06 15:46:18 -070075}