blob: 5d94d34173df0894d4db9881a5109b4c11e51ac1 [file] [log] [blame]
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuskabf916ea2015-05-20 18:24:34 -07003 *
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
samuel0276a322015-07-13 16:35:17 +080051 /**
52 * Returns IP address.
53 * @return IP address
54 */
55 public IpAddress ip() {
56 return ip;
57 }
58
jcc4a20a5f2015-04-30 15:43:39 +080059 @Override
60 public int hashCode() {
61 return Objects.hash(ip);
62 }
63
64 @Override
65 public boolean equals(Object obj) {
66 if (this == obj) {
67 return true;
68 }
69 if (obj instanceof IpTunnelEndPoint) {
70 final IpTunnelEndPoint other = (IpTunnelEndPoint) obj;
71 return Objects.equals(this.ip, other.ip);
72 }
73 return false;
74 }
75
76 @Override
77 public String toString() {
78 return MoreObjects.toStringHelper(getClass()).add("ip", ip).toString();
79 }
80}