Jian Li | 6b77dc0 | 2016-07-14 16:04:25 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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.lisp.msg.types; |
| 17 | |
| 18 | import org.onlab.packet.IpAddress; |
| 19 | |
Jian Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 20 | import java.util.Objects; |
| 21 | |
Jian Li | 6b77dc0 | 2016-07-14 16:04:25 +0900 | [diff] [blame] | 22 | import static com.google.common.base.Preconditions.checkArgument; |
| 23 | |
| 24 | /** |
| 25 | * IPv4 address that is used by LISP Locator. |
| 26 | */ |
| 27 | public class LispIpv4Address extends LispIpAddress { |
| 28 | |
| 29 | /** |
| 30 | * Initializes LISP locator's IPv4 address. |
| 31 | * |
| 32 | * @param address IP address |
| 33 | */ |
| 34 | public LispIpv4Address(IpAddress address) { |
| 35 | super(address, AddressFamilyIdentifierEnum.IP); |
| 36 | checkArgument(address.isIp4()); |
| 37 | } |
Jian Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 38 | |
| 39 | @Override |
| 40 | public boolean equals(Object obj) { |
| 41 | if (this == obj) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | if (obj instanceof LispIpv4Address) { |
| 46 | final LispIpv4Address other = (LispIpv4Address) obj; |
| 47 | return Objects.equals(this.address, other.address) && |
| 48 | Objects.equals(this.getAfi(), other.getAfi()); |
| 49 | } |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public int hashCode() { |
| 55 | return Objects.hash(address, getAfi()); |
| 56 | } |
Jian Li | 6b77dc0 | 2016-07-14 16:04:25 +0900 | [diff] [blame] | 57 | } |