blob: 83ad4756d5592625569bfafb307a05e6e22de710 [file] [log] [blame]
samuelbc087c02015-07-23 14:11:58 +08001/*
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.net.behaviour;
18
19import java.util.Objects;
20
21import com.google.common.annotations.Beta;
22import org.onlab.packet.IpAddress;
23
24import com.google.common.base.MoreObjects;
25
26/**
27 * Represent for a tunnel point using ip address.
28 */
29@Beta
30public 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 /**
52 * Returns IP address.
53 * @return IP address
54 */
55 public IpAddress ip() {
56 return ip;
57 }
58
59 @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}