Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 1 | /* |
| 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 | package org.onosproject.iptopology.api; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import org.onlab.packet.Ip4Address; |
| 23 | import org.onlab.packet.Ip6Address; |
| 24 | |
| 25 | /** |
| 26 | * Represents Ip Link Identifier. |
| 27 | */ |
| 28 | public class IpLinkIdentifier { |
| 29 | private final InterfaceIdentifier localIndentifier; |
| 30 | private final InterfaceIdentifier remoteIndentifier; |
| 31 | private final Ip4Address localIpv4Addr; |
| 32 | private final Ip4Address remoteIpv4Addr; |
| 33 | private final Ip6Address localIpv6Addr; |
| 34 | private final Ip6Address remoteIpv6Addr; |
| 35 | private final TopologyId topologyId; |
| 36 | |
| 37 | /** |
| 38 | * Constructor to initialize its parameters. |
| 39 | * |
| 40 | * @param localIndentifier local interface identifier of the link |
| 41 | * @param remoteIndentifier remote interface identifier of the link |
| 42 | * @param localIpv4Addr local IPv4 address of the link |
| 43 | * @param remoteIpv4Addr remote IPv4 address of the link |
| 44 | * @param localIpv6Addr local IPv6 address of the link |
| 45 | * @param remoteIpv6Addr remote IPv6 address of the link |
| 46 | * @param topologyId link topology identifier |
| 47 | */ |
| 48 | public IpLinkIdentifier(InterfaceIdentifier localIndentifier, InterfaceIdentifier remoteIndentifier, |
| 49 | Ip4Address localIpv4Addr, Ip4Address remoteIpv4Addr, Ip6Address localIpv6Addr, |
| 50 | Ip6Address remoteIpv6Addr, TopologyId topologyId) { |
| 51 | this.localIndentifier = localIndentifier; |
| 52 | this.remoteIndentifier = remoteIndentifier; |
| 53 | this.localIpv4Addr = localIpv4Addr; |
| 54 | this.remoteIpv4Addr = remoteIpv4Addr; |
| 55 | this.localIpv6Addr = localIpv6Addr; |
| 56 | this.remoteIpv6Addr = remoteIpv6Addr; |
| 57 | this.topologyId = topologyId; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Obtains link local identifier. |
| 62 | * |
| 63 | * @return link local identifier |
| 64 | */ |
| 65 | public InterfaceIdentifier localIndentifier() { |
| 66 | return localIndentifier; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Obtains link local identifier. |
| 71 | * |
| 72 | * @return link local identifier |
| 73 | */ |
| 74 | public InterfaceIdentifier remoteIndentifier() { |
| 75 | return remoteIndentifier; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Obtains local IPv4 address of the link. |
| 80 | * |
| 81 | * @return local IPv4 address of the link |
| 82 | */ |
| 83 | public Ip4Address localIpv4Addr() { |
| 84 | return localIpv4Addr; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Obtains remote IPv4 address of the link. |
| 89 | * |
| 90 | * @return remote IPv4 address of the link |
| 91 | */ |
| 92 | public Ip4Address remoteIpv4Addr() { |
| 93 | return remoteIpv4Addr; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Obtains local IPv6 address of the link. |
| 98 | * |
| 99 | * @return local IPv6 address of the link |
| 100 | */ |
| 101 | public Ip6Address localIpv6Addr() { |
| 102 | return localIpv6Addr; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Obtains remote IPv6 address of the link. |
| 107 | * |
| 108 | * @return remote IPv6 address of the link |
| 109 | */ |
| 110 | public Ip6Address remoteIpv6Addr() { |
| 111 | return remoteIpv6Addr; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Obtains Topology ID of the link. |
| 116 | * |
| 117 | * @return Topology ID of the link |
| 118 | */ |
| 119 | public TopologyId topologyId() { |
| 120 | return topologyId; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public int hashCode() { |
| 125 | return Objects.hash(localIndentifier, remoteIndentifier, localIpv4Addr, remoteIpv4Addr, |
| 126 | localIpv6Addr, remoteIpv6Addr, topologyId); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public boolean equals(Object obj) { |
| 131 | if (this == obj) { |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | if (obj instanceof IpLinkIdentifier) { |
| 136 | IpLinkIdentifier other = (IpLinkIdentifier) obj; |
| 137 | return Objects.equals(topologyId, other.topologyId) |
| 138 | && Objects.equals(localIndentifier, other.localIndentifier) |
| 139 | && Objects.equals(remoteIndentifier, other.remoteIndentifier) |
| 140 | && Objects.equals(localIpv4Addr, other.localIpv4Addr) |
| 141 | && Objects.equals(remoteIpv4Addr, other.remoteIpv4Addr) |
| 142 | && Objects.equals(localIpv6Addr, other.localIpv6Addr) |
| 143 | && Objects.equals(remoteIpv6Addr, other.remoteIpv6Addr); |
| 144 | } |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public String toString() { |
| 150 | return toStringHelper(this) |
| 151 | .omitNullValues() |
| 152 | .add("localIndentifier", localIndentifier) |
| 153 | .add("remoteIndentifier", remoteIndentifier) |
| 154 | .add("localIpv4Addr", localIpv4Addr) |
| 155 | .add("remoteIpv4Addr", remoteIpv4Addr) |
| 156 | .add("localIpv6Addr", localIpv6Addr) |
| 157 | .add("remoteIpv6Addr", remoteIpv6Addr) |
| 158 | .add("topologyId", topologyId) |
| 159 | .toString(); |
| 160 | } |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 161 | } |