blob: 7c5247a985276d539d3e3e33ab9bea37205307f7 [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
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040021import com.google.common.annotations.Beta;
jcc4a20a5f2015-04-30 15:43:39 +080022import org.onlab.packet.IpAddress;
23
24import com.google.common.base.MoreObjects;
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040025
jcc4a20a5f2015-04-30 15:43:39 +080026/**
27 * Represent for a tunnel point using ip address.
28 */
Brian O'Connor2bed5ce2015-06-25 15:10:28 -040029@Beta
jcc4a20a5f2015-04-30 15:43:39 +080030public final class IpTunnelEndPoint implements TunnelEndPoint {
31
32 private final IpAddress ip;
33
34 /**
35 * Public construction is prohibited.
36 * @param ip ip address
37 */
38 private IpTunnelEndPoint(IpAddress ip) {
39 this.ip = ip;
40 }
41
42 /**
43 * Create a IP tunnel end point.
44 * @param ip IP address
45 * @return IpTunnelEndPoint
46 */
47 public static IpTunnelEndPoint ipTunnelPoint(IpAddress ip) {
48 return new IpTunnelEndPoint(ip);
49 }
50
51 @Override
52 public int hashCode() {
53 return Objects.hash(ip);
54 }
55
56 @Override
57 public boolean equals(Object obj) {
58 if (this == obj) {
59 return true;
60 }
61 if (obj instanceof IpTunnelEndPoint) {
62 final IpTunnelEndPoint other = (IpTunnelEndPoint) obj;
63 return Objects.equals(this.ip, other.ip);
64 }
65 return false;
66 }
67
68 @Override
69 public String toString() {
70 return MoreObjects.toStringHelper(getClass()).add("ip", ip).toString();
71 }
72}