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; |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 18 | |
| 19 | import java.util.List; |
| 20 | import java.util.Objects; |
| 21 | |
Ray Milkey | a95193c | 2017-08-10 15:35:36 -0700 | [diff] [blame] | 22 | import org.onlab.packet.IpAddress; |
| 23 | import org.onlab.packet.IpPrefix; |
| 24 | |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * Represents a evpn instance route. |
| 30 | */ |
| 31 | public class EvpnInstanceRoute { |
| 32 | |
| 33 | private final EvpnInstanceName evpnName; |
| 34 | private final RouteDistinguisher rd; |
| 35 | private List<VpnRouteTarget> importRtList; |
| 36 | private List<VpnRouteTarget> exportRtList; |
| 37 | private final EvpnInstancePrefix evpnInstancePrefix; |
| 38 | private final EvpnInstanceNextHop evpnInstanceNextHop; |
| 39 | private final IpPrefix prefix; |
| 40 | private final IpAddress nextHop; |
| 41 | private final Label label; |
| 42 | |
| 43 | /** |
| 44 | * Constructor to initialize the parameters. |
| 45 | * |
| 46 | * @param evpnName vpn instance name |
| 47 | * @param rd route distinguisher |
| 48 | * @param importRtList import route targets |
| 49 | * @param exportRtList export route targets |
| 50 | * @param evpnInstancePrefix evpn intance prefix |
| 51 | * @param evpnInstanceNextHop evpn instance nexthop |
| 52 | * @param prefix evpn prefix |
| 53 | * @param nextHop evpn nexthop |
| 54 | * @param label label |
| 55 | */ |
| 56 | public EvpnInstanceRoute(EvpnInstanceName evpnName, |
| 57 | RouteDistinguisher rd, |
| 58 | List<VpnRouteTarget> importRtList, |
| 59 | List<VpnRouteTarget> exportRtList, |
| 60 | EvpnInstancePrefix evpnInstancePrefix, |
| 61 | EvpnInstanceNextHop evpnInstanceNextHop, |
| 62 | IpPrefix prefix, |
| 63 | IpAddress nextHop, |
| 64 | Label label) { |
| 65 | checkNotNull(evpnName); |
| 66 | checkNotNull(prefix); |
| 67 | //checkNotNull(nextHop); //can be NULL in MP un reach |
| 68 | checkNotNull(rd); |
| 69 | |
| 70 | this.evpnName = evpnName; |
| 71 | this.rd = rd; |
| 72 | this.importRtList = importRtList; |
| 73 | this.exportRtList = exportRtList; |
| 74 | this.prefix = prefix; |
| 75 | this.nextHop = nextHop; |
| 76 | this.evpnInstancePrefix = evpnInstancePrefix; |
| 77 | this.evpnInstanceNextHop = evpnInstanceNextHop; |
| 78 | this.label = label; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns the evpnName. |
| 83 | * |
| 84 | * @return EvpnInstanceName |
| 85 | */ |
| 86 | public EvpnInstanceName evpnInstanceName() { |
| 87 | return evpnName; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Returns the route distinguisher. |
| 92 | * |
| 93 | * @return RouteDistinguisher |
| 94 | */ |
| 95 | public RouteDistinguisher routeDistinguisher() { |
| 96 | return rd; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Returns the Route targets. |
| 101 | * |
| 102 | * @return RouteTarget List |
| 103 | */ |
| 104 | |
| 105 | public List<VpnRouteTarget> importRouteTarget() { |
| 106 | return importRtList; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Returns the Route targets. |
| 111 | * |
| 112 | * @return RouteTarget List |
| 113 | */ |
| 114 | public List<VpnRouteTarget> exportRouteTarget() { |
| 115 | return exportRtList; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Set import list. |
| 120 | * |
| 121 | * @param importRtList import list |
| 122 | */ |
| 123 | public void setImportRtList(List<VpnRouteTarget> importRtList) { |
| 124 | this.importRtList = importRtList; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Set export list. |
| 129 | * |
| 130 | * @param exportRtList export list |
| 131 | */ |
| 132 | public void setExportRtList(List<VpnRouteTarget> exportRtList) { |
| 133 | this.exportRtList = exportRtList; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Returns EvpnInstancePrefix of the evpn private route. |
| 138 | * |
| 139 | * @return EvpnInstancePrefix |
| 140 | */ |
| 141 | |
| 142 | public EvpnInstancePrefix getevpnInstancePrefix() { |
| 143 | return evpnInstancePrefix; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Returns EvpnInstanceNextHop of the evpn private route. |
| 148 | * |
| 149 | * @return EvpnInstancePrefix |
| 150 | */ |
| 151 | |
| 152 | public EvpnInstanceNextHop getEvpnInstanceNextHop() { |
| 153 | return evpnInstanceNextHop; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Returns prefix of the evpn private route. |
| 158 | * |
| 159 | * @return EvpnInstancePrefix |
| 160 | */ |
| 161 | public IpPrefix prefix() { |
| 162 | return prefix; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Returns the label. |
| 167 | * |
| 168 | * @return EvpnInstanceName |
| 169 | */ |
| 170 | public Label getLabel() { |
| 171 | return label; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Returns the label. |
| 176 | * |
| 177 | * @return EvpnInstanceName |
| 178 | */ |
| 179 | public IpAddress getNextHopl() { |
| 180 | return nextHop; |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public int hashCode() { |
| 185 | return Objects.hash(evpnName, prefix, nextHop, |
| 186 | rd, importRtList, exportRtList); |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public boolean equals(Object other) { |
| 191 | if (this == other) { |
| 192 | return true; |
| 193 | } |
| 194 | |
| 195 | if (!(other instanceof EvpnInstanceRoute)) { |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | EvpnInstanceRoute that = (EvpnInstanceRoute) other; |
| 200 | |
Yuta HIGUCHI | 488a94c | 2018-01-26 17:24:09 -0800 | [diff] [blame] | 201 | return Objects.equals(prefix, that.prefix) |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 202 | && Objects.equals(nextHop, that.nextHop) |
| 203 | && Objects.equals(evpnName, that.evpnName) |
| 204 | && Objects.equals(rd, that.rd) |
| 205 | && Objects.equals(importRtList, that.importRtList) |
| 206 | && Objects.equals(exportRtList, that.exportRtList); |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public String toString() { |
| 211 | return toStringHelper(this).add("prefix", prefix) |
| 212 | .add("nextHop", nextHop) |
| 213 | .add("rd", rd) |
| 214 | .add("import rt", importRtList) |
| 215 | .add("export rt", exportRtList) |
| 216 | .add("evpnName", evpnName) |
| 217 | .toString(); |
| 218 | } |
| 219 | } |