Jian Li | 0e09eaa | 2017-02-14 02:01:18 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | 0e09eaa | 2017-02-14 02:01:18 +0900 | [diff] [blame] | 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.mapping.addresses; |
| 17 | |
| 18 | import org.onlab.packet.MacAddress; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | /** |
| 23 | * Implementation of MAC mapping address. |
| 24 | */ |
| 25 | public final class EthMappingAddress implements MappingAddress { |
| 26 | private final MacAddress mac; |
| 27 | |
| 28 | /** |
| 29 | * Default constructor of EthMappingAddress. |
| 30 | * |
| 31 | * @param mac the MAC address to look up |
| 32 | */ |
| 33 | EthMappingAddress(MacAddress mac) { |
| 34 | this.mac = mac; |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public Type type() { |
| 39 | return Type.ETH; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Obtains the MAC address to look up. |
| 44 | * |
| 45 | * @return the MAC address to look up |
| 46 | */ |
| 47 | public MacAddress mac() { |
| 48 | return this.mac; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public String toString() { |
| 53 | return type().toString() + TYPE_SEPARATOR + mac; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public int hashCode() { |
| 58 | return Objects.hash(Type.ETH, mac); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public boolean equals(Object obj) { |
| 63 | if (this == obj) { |
| 64 | return true; |
| 65 | } |
| 66 | if (obj instanceof EthMappingAddress) { |
| 67 | EthMappingAddress that = (EthMappingAddress) obj; |
| 68 | return Objects.equals(mac, that.mac); |
| 69 | } |
| 70 | return false; |
| 71 | } |
| 72 | } |