Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [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 java.util.Objects;
|
| 19 |
|
| 20 | import org.onlab.packet.Ip4Address;
|
| 21 | import org.onlab.packet.Ip6Address;
|
| 22 |
|
| 23 | import com.google.common.base.MoreObjects;
|
| 24 |
|
| 25 | /**
|
| 26 | * Representation of device interface.
|
| 27 | */
|
| 28 | public class DeviceInterface {
|
| 29 | private final Ip4Address ip4Address;
|
| 30 | private final Ip6Address ip6Address;
|
| 31 | private final InterfaceIdentifier interfaceId;
|
| 32 |
|
| 33 | /**
|
| 34 | * Constructor to initialize its parameter.
|
| 35 | *
|
| 36 | * @param ip4Address ipv4 interface address
|
| 37 | * @param ip6Address ipv6 interface address
|
| 38 | * @param interfaceId interface Identifier
|
| 39 | */
|
| 40 | public DeviceInterface(Ip4Address ip4Address, Ip6Address ip6Address, InterfaceIdentifier interfaceId) {
|
| 41 | this.ip4Address = ip4Address;
|
| 42 | this.ip6Address = ip6Address;
|
| 43 | this.interfaceId = interfaceId;
|
| 44 | }
|
| 45 |
|
| 46 | /**
|
| 47 | * obtains ipv4 address of an interface.
|
| 48 | *
|
| 49 | * @return ipv4 interface address
|
| 50 | */
|
| 51 | public Ip4Address ip4Address() {
|
| 52 | return ip4Address;
|
| 53 | }
|
| 54 |
|
| 55 | /**
|
| 56 | * obtains ipv6 interface address.
|
| 57 | *
|
| 58 | * @return ipv6 interface address
|
| 59 | */
|
| 60 | public Ip6Address ip6Address() {
|
| 61 | return ip6Address;
|
| 62 | }
|
| 63 |
|
| 64 | /**
|
| 65 | * obtains interface identifier.
|
| 66 | *
|
| 67 | * @return interface identifier
|
| 68 | */
|
| 69 | public InterfaceIdentifier interfaceId() {
|
| 70 | return interfaceId;
|
| 71 | }
|
| 72 |
|
| 73 | @Override
|
| 74 | public int hashCode() {
|
| 75 | return Objects.hash(ip4Address, ip6Address, interfaceId);
|
| 76 | }
|
| 77 |
|
| 78 | @Override
|
| 79 | public boolean equals(Object obj) {
|
| 80 | if (this == obj) {
|
| 81 | return true;
|
| 82 | }
|
| 83 | if (obj instanceof DeviceInterface) {
|
| 84 | final DeviceInterface other = (DeviceInterface) obj;
|
| 85 | return Objects.equals(this.ip4Address, other.ip4Address)
|
| 86 | && Objects.equals(this.ip6Address, other.ip6Address)
|
| 87 | && Objects.equals(this.interfaceId, other.interfaceId);
|
| 88 | }
|
| 89 | return false;
|
| 90 | }
|
| 91 |
|
| 92 | @Override
|
| 93 | public String toString() {
|
| 94 | return MoreObjects.toStringHelper(this)
|
| 95 | .add("ip4Address", ip4Address)
|
| 96 | .add("ip6Address", ip6Address)
|
| 97 | .add("interfaceId", interfaceId)
|
| 98 | .toString();
|
| 99 | }
|
| 100 | } |