blob: a9278fc637725011742c6d70f8b96f2000c0e7fe [file] [log] [blame]
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * 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
7 *
8 * 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.
15 */
16
17package org.onosproject.incubator.net.tunnel;
jcc4a20a5f2015-04-30 15:43:39 +080018
19import java.util.Objects;
20
21import org.onlab.packet.IpAddress;
22
23import com.google.common.base.MoreObjects;
24/**
25 * Represent for a tunnel point using ip address.
26 */
27public final class IpTunnelEndPoint implements TunnelEndPoint {
28
29 private final IpAddress ip;
30
31 /**
32 * Public construction is prohibited.
33 * @param ip ip address
34 */
35 private IpTunnelEndPoint(IpAddress ip) {
36 this.ip = ip;
37 }
38
39 /**
40 * Create a IP tunnel end point.
41 * @param ip IP address
42 * @return IpTunnelEndPoint
43 */
44 public static IpTunnelEndPoint ipTunnelPoint(IpAddress ip) {
45 return new IpTunnelEndPoint(ip);
46 }
47
48 @Override
49 public int hashCode() {
50 return Objects.hash(ip);
51 }
52
53 @Override
54 public boolean equals(Object obj) {
55 if (this == obj) {
56 return true;
57 }
58 if (obj instanceof IpTunnelEndPoint) {
59 final IpTunnelEndPoint other = (IpTunnelEndPoint) obj;
60 return Objects.equals(this.ip, other.ip);
61 }
62 return false;
63 }
64
65 @Override
66 public String toString() {
67 return MoreObjects.toStringHelper(getClass()).add("ip", ip).toString();
68 }
69}