blob: bde823d92a07ecb0fb85a1555b46928acf77a73f [file] [log] [blame]
Satish Kf6d87cb2015-11-30 19:59:22 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Satish Kf6d87cb2015-11-30 19:59:22 +05303 *
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 */
16package org.onosproject.iptopology.api;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
Priyanka B79475492015-12-05 21:42:15 +053020import java.util.Iterator;
21import java.util.List;
Satish Kf6d87cb2015-11-30 19:59:22 +053022import java.util.Objects;
23
24import org.onlab.packet.IpAddress;
25
26/**
27 * This class provides implementation of prefix traffic engineering data.
28 */
29public class PrefixTed {
30 private final IgpFlags igpFlags;
Priyanka B79475492015-12-05 21:42:15 +053031 private final List<RouteTag> routeTag;
32 private final List<ExtendedRouteTag> extendedRouteTag;
Satish Kf6d87cb2015-11-30 19:59:22 +053033 private final Metric metric;
34 private final IpAddress fwdingAddress;
35
36 /**
Priyanka B79475492015-12-05 21:42:15 +053037 * Constructor to initialize its fields.
Satish Kf6d87cb2015-11-30 19:59:22 +053038 *
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 B79475492015-12-05 21:42:15 +053045 public PrefixTed(IgpFlags igpFlags, List<RouteTag> routeTag, List<ExtendedRouteTag> extendedRouteTag,
Satish Kf6d87cb2015-11-30 19:59:22 +053046 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 B79475492015-12-05 21:42:15 +053068 public List<RouteTag> routeTag() {
Satish Kf6d87cb2015-11-30 19:59:22 +053069 return routeTag;
70 }
71
72 /**
73 * Provides extended ISIS route tags of the prefix.
74 *
75 * @return extended IS-IS route tag
76 */
Priyanka B79475492015-12-05 21:42:15 +053077 public List<ExtendedRouteTag> extendedRouteTag() {
Satish Kf6d87cb2015-11-30 19:59:22 +053078 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 Kf6d87cb2015-11-30 19:59:22 +053099 @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 B79475492015-12-05 21:42:15 +0530112 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 Kf6d87cb2015-11-30 19:59:22 +0530147 }
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 B79475492015-12-05 21:42:15 +0530162}