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 | |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | |
| 26 | /** |
| 27 | * Represents a evpn next hop. |
| 28 | */ |
| 29 | public final class EvpnNextHop { |
| 30 | |
| 31 | private final IpAddress nextHop; |
| 32 | private final List<VpnRouteTarget> importRtList; |
| 33 | private final List<VpnRouteTarget> exportRtList; |
| 34 | private final Label label; |
| 35 | |
| 36 | /** |
| 37 | * Constructor to initialize the parameters. |
| 38 | * |
| 39 | * @param nextHop evpn next hop |
| 40 | * @param importRtList import route targets |
| 41 | * @param importRtList export route targets |
| 42 | * @param label label |
| 43 | */ |
| 44 | private EvpnNextHop(IpAddress nextHop, List<VpnRouteTarget> importRtList, List<VpnRouteTarget> exportRtList, |
| 45 | Label label) { |
| 46 | this.nextHop = nextHop; |
| 47 | this.importRtList = importRtList; |
| 48 | this.exportRtList = exportRtList; |
| 49 | this.label = label; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Creates the Evpn Next hop with given parameters. |
| 54 | * |
| 55 | * @param nextHop Next hop of the route |
| 56 | * @param importRtList route target import list |
| 57 | * @param exportRtList route target export list |
| 58 | * @param label label of evpn route |
| 59 | * @return EvpnNextHop |
| 60 | */ |
| 61 | public static EvpnNextHop evpnNextHop(IpAddress nextHop, List<VpnRouteTarget> importRtList, |
| 62 | List<VpnRouteTarget> exportRtList, |
| 63 | Label label) { |
| 64 | return new EvpnNextHop(nextHop, importRtList, exportRtList, label); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns the next hop IP address. |
| 69 | * |
| 70 | * @return next hop |
| 71 | */ |
| 72 | public IpAddress nextHop() { |
| 73 | return nextHop; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the Route targets. |
| 78 | * |
| 79 | * @return RouteTarget List |
| 80 | */ |
| 81 | |
| 82 | public List<VpnRouteTarget> importRouteTarget() { |
| 83 | return importRtList; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Returns the Route targets. |
| 88 | * |
| 89 | * @return RouteTarget List |
| 90 | */ |
| 91 | public List<VpnRouteTarget> exportRouteTarget() { |
| 92 | return exportRtList; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns the label of evpn route. |
| 97 | * |
| 98 | * @return Label |
| 99 | */ |
| 100 | public Label label() { |
| 101 | return label; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public int hashCode() { |
| 106 | return Objects.hash(nextHop, importRtList, exportRtList, label); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public boolean equals(Object other) { |
| 111 | if (this == other) { |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | if (!(other instanceof EvpnNextHop)) { |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | EvpnNextHop that = (EvpnNextHop) other; |
| 120 | |
| 121 | return Objects.equals(this.nextHop(), that.nextHop()) |
| 122 | && Objects.equals(this.importRtList, that.importRtList) |
| 123 | && Objects.equals(this.exportRtList, that.exportRtList) |
| 124 | && Objects.equals(this.label, that.label); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public String toString() { |
| 129 | return toStringHelper(this).add("nextHop", this.nextHop()) |
| 130 | .add("import rt list", this.importRtList).add("export rt list", this.exportRtList) |
| 131 | .add("label", this.label).toString(); |
| 132 | } |
| 133 | } |