Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | |
Ray Milkey | a95193c | 2017-08-10 15:35:36 -0700 | [diff] [blame] | 17 | package org.onosproject.evpnrouteservice; |
| 18 | |
| 19 | import java.util.Objects; |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 20 | |
| 21 | import org.onlab.packet.IpPrefix; |
| 22 | import org.onlab.packet.MacAddress; |
| 23 | |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Represents a evpn instance prefix. |
| 29 | */ |
| 30 | public final class EvpnInstancePrefix { |
| 31 | |
| 32 | private final MacAddress macAddress; |
| 33 | private final IpPrefix ipPrefix; |
| 34 | |
| 35 | /** |
| 36 | * Constructor to initialize the parameters. |
| 37 | * |
| 38 | * @param macAddress Mac address |
| 39 | * @param ipPrefix IP address |
| 40 | */ |
| 41 | private EvpnInstancePrefix(MacAddress macAddress, |
| 42 | IpPrefix ipPrefix) { |
| 43 | checkNotNull(macAddress); |
| 44 | this.macAddress = macAddress; |
| 45 | this.ipPrefix = ipPrefix; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Creates the instance of EvpnInstancePrefix. |
| 50 | * |
| 51 | * @param macAddress Mac address |
| 52 | * @param ipPrefix IP address |
| 53 | * @return Evpn instance prefix |
| 54 | */ |
| 55 | public static EvpnInstancePrefix evpnPrefix(MacAddress macAddress, |
| 56 | IpPrefix ipPrefix) { |
| 57 | return new EvpnInstancePrefix(macAddress, ipPrefix); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns the MAC of the route. |
| 62 | * |
| 63 | * @return MAC address |
| 64 | */ |
| 65 | public MacAddress macAddress() { |
| 66 | return macAddress; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Returns the IP prefix of the route. |
| 71 | * |
| 72 | * @return IP prefix |
| 73 | */ |
| 74 | public IpPrefix ipPrefix() { |
| 75 | return ipPrefix; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public int hashCode() { |
| 80 | return Objects.hash(macAddress); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public boolean equals(Object other) { |
| 85 | if (this == other) { |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | if (!(other instanceof EvpnInstancePrefix)) { |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | EvpnInstancePrefix that = (EvpnInstancePrefix) other; |
| 94 | |
| 95 | return Objects.equals(this.macAddress, that.macAddress) |
| 96 | && Objects.equals(this.ipPrefix, that.ipPrefix); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String toString() { |
| 101 | return toStringHelper(this).add("macAddress", this.macAddress) |
| 102 | .add("ipAddress", this.ipPrefix).toString(); |
| 103 | } |
| 104 | } |