Priyanka B
Committed by Gerrit Code Review

PrefixTed code fix

Change-Id: I857ceb2b04e3af479fed769501c5a6bd5704e4b3
...@@ -17,6 +17,8 @@ package org.onosproject.iptopology.api; ...@@ -17,6 +17,8 @@ package org.onosproject.iptopology.api;
17 17
18 import static com.google.common.base.MoreObjects.toStringHelper; 18 import static com.google.common.base.MoreObjects.toStringHelper;
19 19
20 +import java.util.Iterator;
21 +import java.util.List;
20 import java.util.Objects; 22 import java.util.Objects;
21 23
22 import org.onlab.packet.IpAddress; 24 import org.onlab.packet.IpAddress;
...@@ -26,22 +28,13 @@ import org.onlab.packet.IpAddress; ...@@ -26,22 +28,13 @@ import org.onlab.packet.IpAddress;
26 */ 28 */
27 public class PrefixTed { 29 public class PrefixTed {
28 private final IgpFlags igpFlags; 30 private final IgpFlags igpFlags;
29 - private final RouteTag routeTag; 31 + private final List<RouteTag> routeTag;
30 - private final ExtendedRouteTag extendedRouteTag; 32 + private final List<ExtendedRouteTag> extendedRouteTag;
31 private final Metric metric; 33 private final Metric metric;
32 private final IpAddress fwdingAddress; 34 private final IpAddress fwdingAddress;
33 35
34 /** 36 /**
35 - * Constructor to initialize its parameters. 37 + * Constructor to initialize its fields.
36 - *
37 - * @param igpFlags igp flags
38 - * @param routeTag ospf route tag
39 - * @param extendedRouteTag isis route tag
40 - * @param metric prefix metric
41 - * @param fwdingAddress forwarding address
42 - */
43 - /**
44 - * Constructor to initialize its parameters.
45 * 38 *
46 * @param igpFlags IS-IS and OSPF flags assigned to the prefix 39 * @param igpFlags IS-IS and OSPF flags assigned to the prefix
47 * @param routeTag IGP (ISIS or OSPF) tags of the prefix 40 * @param routeTag IGP (ISIS or OSPF) tags of the prefix
...@@ -49,7 +42,7 @@ public class PrefixTed { ...@@ -49,7 +42,7 @@ public class PrefixTed {
49 * @param metric metric of the prefix 42 * @param metric metric of the prefix
50 * @param fwdingAddress OSPF forwarding address 43 * @param fwdingAddress OSPF forwarding address
51 */ 44 */
52 - public PrefixTed(IgpFlags igpFlags, RouteTag routeTag, ExtendedRouteTag extendedRouteTag, 45 + public PrefixTed(IgpFlags igpFlags, List<RouteTag> routeTag, List<ExtendedRouteTag> extendedRouteTag,
53 Metric metric, IpAddress fwdingAddress) { 46 Metric metric, IpAddress fwdingAddress) {
54 this.igpFlags = igpFlags; 47 this.igpFlags = igpFlags;
55 this.routeTag = routeTag; 48 this.routeTag = routeTag;
...@@ -72,7 +65,7 @@ public class PrefixTed { ...@@ -72,7 +65,7 @@ public class PrefixTed {
72 * 65 *
73 * @return IGP route tag. 66 * @return IGP route tag.
74 */ 67 */
75 - public RouteTag routeTag() { 68 + public List<RouteTag> routeTag() {
76 return routeTag; 69 return routeTag;
77 } 70 }
78 71
...@@ -81,7 +74,7 @@ public class PrefixTed { ...@@ -81,7 +74,7 @@ public class PrefixTed {
81 * 74 *
82 * @return extended IS-IS route tag 75 * @return extended IS-IS route tag
83 */ 76 */
84 - public ExtendedRouteTag extendedRouteTag() { 77 + public List<ExtendedRouteTag> extendedRouteTag() {
85 return extendedRouteTag; 78 return extendedRouteTag;
86 } 79 }
87 80
...@@ -103,7 +96,6 @@ public class PrefixTed { ...@@ -103,7 +96,6 @@ public class PrefixTed {
103 return fwdingAddress; 96 return fwdingAddress;
104 } 97 }
105 98
106 -
107 @Override 99 @Override
108 public int hashCode() { 100 public int hashCode() {
109 return Objects.hash(igpFlags, routeTag, extendedRouteTag, metric, fwdingAddress); 101 return Objects.hash(igpFlags, routeTag, extendedRouteTag, metric, fwdingAddress);
...@@ -117,9 +109,41 @@ public class PrefixTed { ...@@ -117,9 +109,41 @@ public class PrefixTed {
117 109
118 if (obj instanceof PrefixTed) { 110 if (obj instanceof PrefixTed) {
119 PrefixTed other = (PrefixTed) obj; 111 PrefixTed other = (PrefixTed) obj;
120 - return Objects.equals(igpFlags, other.igpFlags) && Objects.equals(extendedRouteTag, other.extendedRouteTag) 112 + Iterator<RouteTag> objListIterator = other.routeTag.iterator();
121 - && Objects.equals(routeTag, other.routeTag) && Objects.equals(metric, other.metric) 113 + int countOtherCommonRouteTag = other.routeTag.size();
122 - && Objects.equals(fwdingAddress, other.fwdingAddress); 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 + }
123 } 147 }
124 return false; 148 return false;
125 } 149 }
......