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 prefix. |
| 29 | */ |
| 30 | public final class EvpnPrefix { |
| 31 | |
| 32 | private final RouteDistinguisher rd; |
| 33 | private final MacAddress macAddress; |
| 34 | private final IpPrefix ipAddress; |
| 35 | |
| 36 | /** |
| 37 | * Constructor to initialize the parameters. |
| 38 | * |
| 39 | * @param rd route distinguisher |
| 40 | * @param macAddress mac address |
| 41 | * @param ipAddress IP address |
| 42 | */ |
| 43 | public EvpnPrefix(RouteDistinguisher rd, MacAddress macAddress, |
| 44 | IpPrefix ipAddress) { |
| 45 | checkNotNull(rd); |
| 46 | checkNotNull(macAddress); |
| 47 | checkNotNull(ipAddress); |
| 48 | this.rd = rd; |
| 49 | this.macAddress = macAddress; |
| 50 | this.ipAddress = ipAddress; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Creates the evpn prefix by given parameters. |
| 55 | * |
| 56 | * @param rd route distinguisher |
| 57 | * @param macAddress mac address |
| 58 | * @param ipAddress ip address |
| 59 | * @return EvpnPrefix |
| 60 | */ |
| 61 | public static EvpnPrefix evpnPrefix(RouteDistinguisher rd, |
| 62 | MacAddress macAddress, |
| 63 | IpPrefix ipAddress) { |
| 64 | return new EvpnPrefix(rd, macAddress, ipAddress); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns the route distinguisher. |
| 69 | * |
| 70 | * @return RouteDistinguisher |
| 71 | */ |
| 72 | public RouteDistinguisher routeDistinguisher() { |
| 73 | return rd; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the mac address. |
| 78 | * |
| 79 | * @return MacAddress |
| 80 | */ |
| 81 | public MacAddress macAddress() { |
| 82 | return macAddress; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns the IP address. |
| 87 | * |
| 88 | * @return Ip4Address |
| 89 | */ |
| 90 | public IpPrefix ipAddress() { |
| 91 | return ipAddress; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public int hashCode() { |
| 96 | return Objects.hash(rd, macAddress, ipAddress); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public boolean equals(Object other) { |
| 101 | if (this == other) { |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | if (!(other instanceof EvpnPrefix)) { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | EvpnPrefix that = (EvpnPrefix) other; |
| 110 | |
| 111 | return Objects.equals(this.macAddress(), that.macAddress()) |
| 112 | && Objects.equals(this.ipAddress, that.ipAddress) |
| 113 | && Objects.equals(this.rd, that.rd); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public String toString() { |
| 118 | return toStringHelper(this).add("macAddress", this.macAddress()) |
| 119 | .add("ipAddress", this.ipAddress()).add("rd", this.rd) |
| 120 | .toString(); |
| 121 | } |
| 122 | } |