Sho SHIMIZU | b2b2d98 | 2015-09-11 15:35:06 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | b2b2d98 | 2015-09-11 15:35:06 -0700 | [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.vtnrsc; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.packet.MacAddress; |
| 25 | |
| 26 | /** |
| 27 | * Immutable representation of a allowed address pair. |
| 28 | */ |
| 29 | public final class AllowedAddressPair { |
| 30 | private final IpAddress ip; |
| 31 | private final MacAddress mac; |
| 32 | // Public construction is prohibited |
| 33 | private AllowedAddressPair(IpAddress ip, MacAddress mac) { |
| 34 | checkNotNull(ip, "IpAddress cannot be null"); |
| 35 | checkNotNull(mac, "MacAddress cannot be null"); |
| 36 | this.ip = ip; |
| 37 | this.mac = mac; |
| 38 | } |
| 39 | /** |
| 40 | * Returns the AllowedAddressPair ip address. |
| 41 | * |
| 42 | * @return ip address |
| 43 | */ |
| 44 | public IpAddress ip() { |
| 45 | return ip; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns the AllowedAddressPair MAC address. |
| 50 | * |
| 51 | * @return MAC address |
| 52 | */ |
| 53 | public MacAddress mac() { |
| 54 | return mac; |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /** |
| 59 | * Creates a allowedAddressPair using the supplied ipAddress & |
| 60 | * macAddress. |
| 61 | * |
| 62 | * @param ip IP address |
| 63 | * @param mac MAC address |
| 64 | * @return AllowedAddressPair |
| 65 | */ |
| 66 | public static AllowedAddressPair allowedAddressPair(IpAddress ip, |
| 67 | MacAddress mac) { |
| 68 | return new AllowedAddressPair(ip, mac); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public int hashCode() { |
| 73 | return Objects.hash(ip, mac); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public boolean equals(Object obj) { |
| 78 | if (this == obj) { |
| 79 | return true; |
| 80 | } |
| 81 | if (obj instanceof AllowedAddressPair) { |
| 82 | final AllowedAddressPair that = (AllowedAddressPair) obj; |
| 83 | return Objects.equals(this.ip, that.ip) |
| 84 | && Objects.equals(this.mac, that.mac); |
| 85 | } |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public String toString() { |
| 91 | return toStringHelper(this).add("ip", ip).add("mac", mac).toString(); |
| 92 | } |
| 93 | |
| 94 | } |