jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 1 | package org.onosproject.net.tunnel; |
| 2 | |
| 3 | import java.util.Objects; |
| 4 | |
| 5 | import org.onlab.packet.IpAddress; |
| 6 | |
| 7 | import com.google.common.base.MoreObjects; |
| 8 | /** |
| 9 | * Represent for a tunnel point using ip address. |
| 10 | */ |
| 11 | public final class IpTunnelEndPoint implements TunnelEndPoint { |
| 12 | |
| 13 | private final IpAddress ip; |
| 14 | |
| 15 | /** |
| 16 | * Public construction is prohibited. |
| 17 | * @param ip ip address |
| 18 | */ |
| 19 | private IpTunnelEndPoint(IpAddress ip) { |
| 20 | this.ip = ip; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Create a IP tunnel end point. |
| 25 | * @param ip IP address |
| 26 | * @return IpTunnelEndPoint |
| 27 | */ |
| 28 | public static IpTunnelEndPoint ipTunnelPoint(IpAddress ip) { |
| 29 | return new IpTunnelEndPoint(ip); |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public int hashCode() { |
| 34 | return Objects.hash(ip); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public boolean equals(Object obj) { |
| 39 | if (this == obj) { |
| 40 | return true; |
| 41 | } |
| 42 | if (obj instanceof IpTunnelEndPoint) { |
| 43 | final IpTunnelEndPoint other = (IpTunnelEndPoint) obj; |
| 44 | return Objects.equals(this.ip, other.ip); |
| 45 | } |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public String toString() { |
| 51 | return MoreObjects.toStringHelper(getClass()).add("ip", ip).toString(); |
| 52 | } |
| 53 | } |