Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [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.iptopology.api; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
Priyanka B | 7947549 | 2015-12-05 21:42:15 +0530 | [diff] [blame] | 20 | import java.util.Iterator; |
| 21 | import java.util.List; |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 22 | import java.util.Objects; |
| 23 | |
| 24 | import org.onlab.packet.IpAddress; |
| 25 | |
| 26 | /** |
| 27 | * This class provides implementation of prefix traffic engineering data. |
| 28 | */ |
| 29 | public class PrefixTed { |
| 30 | private final IgpFlags igpFlags; |
Priyanka B | 7947549 | 2015-12-05 21:42:15 +0530 | [diff] [blame] | 31 | private final List<RouteTag> routeTag; |
| 32 | private final List<ExtendedRouteTag> extendedRouteTag; |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 33 | private final Metric metric; |
| 34 | private final IpAddress fwdingAddress; |
| 35 | |
| 36 | /** |
Priyanka B | 7947549 | 2015-12-05 21:42:15 +0530 | [diff] [blame] | 37 | * Constructor to initialize its fields. |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 38 | * |
| 39 | * @param igpFlags IS-IS and OSPF flags assigned to the prefix |
| 40 | * @param routeTag IGP (ISIS or OSPF) tags of the prefix |
| 41 | * @param extendedRouteTag extended ISIS route tags of the prefix |
| 42 | * @param metric metric of the prefix |
| 43 | * @param fwdingAddress OSPF forwarding address |
| 44 | */ |
Priyanka B | 7947549 | 2015-12-05 21:42:15 +0530 | [diff] [blame] | 45 | public PrefixTed(IgpFlags igpFlags, List<RouteTag> routeTag, List<ExtendedRouteTag> extendedRouteTag, |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 46 | Metric metric, IpAddress fwdingAddress) { |
| 47 | this.igpFlags = igpFlags; |
| 48 | this.routeTag = routeTag; |
| 49 | this.extendedRouteTag = extendedRouteTag; |
| 50 | this.metric = metric; |
| 51 | this.fwdingAddress = fwdingAddress; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Provides IS-IS and OSPF flags assigned to the prefix. |
| 56 | * |
| 57 | * @return IGP flags |
| 58 | */ |
| 59 | public IgpFlags igpFlags() { |
| 60 | return igpFlags; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Provides IGP (ISIS or OSPF) tags of the prefix. |
| 65 | * |
| 66 | * @return IGP route tag. |
| 67 | */ |
Priyanka B | 7947549 | 2015-12-05 21:42:15 +0530 | [diff] [blame] | 68 | public List<RouteTag> routeTag() { |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 69 | return routeTag; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Provides extended ISIS route tags of the prefix. |
| 74 | * |
| 75 | * @return extended IS-IS route tag |
| 76 | */ |
Priyanka B | 7947549 | 2015-12-05 21:42:15 +0530 | [diff] [blame] | 77 | public List<ExtendedRouteTag> extendedRouteTag() { |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 78 | return extendedRouteTag; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Provides metric of the prefix. |
| 83 | * |
| 84 | * @return prefix metric |
| 85 | */ |
| 86 | public Metric metric() { |
| 87 | return metric; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Provides OSPF forwarding address. |
| 92 | * |
| 93 | * @return forwarding address |
| 94 | */ |
| 95 | public IpAddress fwdingAddress() { |
| 96 | return fwdingAddress; |
| 97 | } |
| 98 | |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 99 | @Override |
| 100 | public int hashCode() { |
| 101 | return Objects.hash(igpFlags, routeTag, extendedRouteTag, metric, fwdingAddress); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public boolean equals(Object obj) { |
| 106 | if (this == obj) { |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | if (obj instanceof PrefixTed) { |
| 111 | PrefixTed other = (PrefixTed) obj; |
Priyanka B | 7947549 | 2015-12-05 21:42:15 +0530 | [diff] [blame] | 112 | Iterator<RouteTag> objListIterator = other.routeTag.iterator(); |
| 113 | int countOtherCommonRouteTag = other.routeTag.size(); |
| 114 | int countCommonRouteTag = routeTag.size(); |
| 115 | |
| 116 | Iterator<ExtendedRouteTag> objListIterator1 = other.extendedRouteTag.iterator(); |
| 117 | int countOtherCommonExtRouteTag = other.extendedRouteTag.size(); |
| 118 | int countCommonExtRouteTag = extendedRouteTag.size(); |
| 119 | |
| 120 | boolean isCommonRouteType = true; |
| 121 | boolean isCommonExtRouteType = true; |
| 122 | if (countOtherCommonRouteTag != countCommonRouteTag |
| 123 | || countOtherCommonExtRouteTag != countCommonExtRouteTag) { |
| 124 | return false; |
| 125 | } else { |
| 126 | while (objListIterator.hasNext() && isCommonRouteType) { |
| 127 | RouteTag subTlv = objListIterator.next(); |
| 128 | if (routeTag.contains(subTlv) && other.routeTag.contains(subTlv)) { |
| 129 | isCommonRouteType = Objects.equals(routeTag.get(routeTag.indexOf(subTlv)), |
| 130 | other.routeTag.get(other.routeTag.indexOf(subTlv))); |
| 131 | } else { |
| 132 | isCommonRouteType = false; |
| 133 | } |
| 134 | } |
| 135 | while (objListIterator1.hasNext() && isCommonExtRouteType) { |
| 136 | ExtendedRouteTag subTlv = objListIterator1.next(); |
| 137 | if (extendedRouteTag.contains(subTlv) && other.extendedRouteTag.contains(subTlv)) { |
| 138 | isCommonExtRouteType = Objects.equals(extendedRouteTag.get(extendedRouteTag.indexOf(subTlv)), |
| 139 | other.extendedRouteTag.get(other.extendedRouteTag.indexOf(subTlv))); |
| 140 | } else { |
| 141 | isCommonExtRouteType = false; |
| 142 | } |
| 143 | } |
| 144 | return isCommonRouteType && isCommonExtRouteType && Objects.equals(igpFlags, other.igpFlags) |
| 145 | && Objects.equals(metric, other.metric) && Objects.equals(fwdingAddress, other.fwdingAddress); |
| 146 | } |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 147 | } |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public String toString() { |
| 153 | return toStringHelper(this) |
| 154 | .omitNullValues() |
| 155 | .add("igpFlags", igpFlags) |
| 156 | .add("extendedRouteTag", extendedRouteTag) |
| 157 | .add("routeTag", routeTag) |
| 158 | .add("metric", metric) |
| 159 | .add("fwdingAddress", fwdingAddress) |
| 160 | .toString(); |
| 161 | } |
Priyanka B | 7947549 | 2015-12-05 21:42:15 +0530 | [diff] [blame] | 162 | } |