blob: 9d747ad4e4866fac6195a0b04dc527e39f9035e2 [file] [log] [blame]
Kalyankumar Asangi27728f22016-02-17 15:46:28 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Kalyankumar Asangi27728f22016-02-17 15:46:28 +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.ospf.controller.lsdb;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.base.Objects;
20import org.onosproject.ospf.controller.LsaWrapper;
21import org.onosproject.ospf.controller.LsdbAge;
22import org.onosproject.ospf.controller.OspfInterface;
23import org.onosproject.ospf.controller.OspfLsa;
24import org.onosproject.ospf.controller.OspfLsaType;
25import org.onosproject.ospf.protocol.lsa.LsaHeader;
26import org.onosproject.ospf.protocol.util.OspfParameters;
27import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
29
30/**
31 * Wrapper object to store LSA and associated metadata information.
32 */
33public class LsaWrapperImpl implements LsaWrapper {
34 private static final Logger log = LoggerFactory.getLogger(LsaWrapperImpl.class);
35 private LsaHeader lsaHeader;
36 private int lsaAgeReceived;
37 private int ageCounterWhenReceived;
38 private boolean isSelfOriginated;
39 private OspfLsaType lsaType;
40 private OspfLsa ospfLsa;
41 private int noReTransmissionLists;
42 private boolean inAnAgeBin;
43 private boolean changedSinceLastFlood;
44 private boolean isSequenceRollOver;
45 private boolean sentReplyForOlderLsa;
46 private boolean checkAge; // Queued for check sum verification
47 private boolean isAging;
48 private String lsaProcessing; //for LSAQueueConsumer processing
49 private int binNumber = -1;
50 private OspfInterface ospfInterface;
51 private LsdbAge lsdbAge;
sunishvkf7c56552016-07-18 16:02:39 +053052 private int ageCounterRollOverWhenAdded;
53
54 public int getAgeCounterRollOverWhenAdded() {
55 return ageCounterRollOverWhenAdded;
56 }
57
58 public void setAgeCounterRollOverWhenAdded(int ageCounterRollOverWhenAdded) {
59 this.ageCounterRollOverWhenAdded = ageCounterRollOverWhenAdded;
60 }
Kalyankumar Asangi27728f22016-02-17 15:46:28 +053061
62 /**
63 * Gets the LSA type.
64 *
65 * @return LSA type
66 */
67 public OspfLsaType lsaType() {
68 return lsaType;
69 }
70
71 /**
72 * Sets the LSA type.
73 *
74 * @param lsaType LSA type
75 */
76 public void setLsaType(OspfLsaType lsaType) {
77 this.lsaType = lsaType;
78 }
79
80 /**
81 * Gets if self originated or not.
82 *
83 * @return true if self originated else false
84 */
85 public boolean isSelfOriginated() {
86 return isSelfOriginated;
87 }
88
89 /**
90 * Sets if self originated or not.
91 *
92 * @param isSelfOriginated true if self originated else false
93 */
94 public void setIsSelfOriginated(boolean isSelfOriginated) {
95 this.isSelfOriginated = isSelfOriginated;
96 }
97
98 /**
99 * Adds the LSA in the wrapper.
100 *
101 * @param lsaType LSA type
102 * @param ospfLsa LSA instance
103 */
104 public void addLsa(OspfLsaType lsaType, OspfLsa ospfLsa) {
105 this.lsaType = lsaType;
106 this.lsaHeader = (LsaHeader) ospfLsa.lsaHeader();
107 this.ospfLsa = ospfLsa;
108 }
109
110 /**
111 * Age of LSA when received.
112 *
113 * @return Age of LSA when received
114 */
115 public int lsaAgeReceived() {
116 return lsaAgeReceived;
117 }
118
119 /**
120 * Sets the Age of LSA when received.
121 *
122 * @param lsaAgeReceived Age of LSA when received
123 */
124 public void setLsaAgeReceived(int lsaAgeReceived) {
125 this.lsaAgeReceived = lsaAgeReceived;
126 }
127
128 /**
129 * Gets the LSA header.
130 *
131 * @return LSA header instance
132 */
133 public LsaHeader lsaHeader() {
134 lsaHeader.setAge(currentAge());
135 return lsaHeader;
136 }
137
138 /**
139 * Sets LSA header.
140 *
141 * @param lsaHeader LSA header
142 */
143 public void setLsaHeader(LsaHeader lsaHeader) {
144 this.lsaHeader = lsaHeader;
145 }
146
147 /**
148 * Gets the LSA.
149 *
150 * @return LSA instance
151 */
152 public OspfLsa ospfLsa() {
153 LsaHeader lsaHeader = (LsaHeader) ospfLsa;
154 lsaHeader.setAge(currentAge());
155
156 return lsaHeader;
157 }
158
159 /**
160 * Sets the LSA.
161 *
162 * @param ospfLsa LSA instance
163 */
164 public void setOspfLsa(OspfLsa ospfLsa) {
165 this.ospfLsa = ospfLsa;
166 }
167
168 /**
169 * Gets number of LSAs in retransmission list.
170 *
171 * @return number of LSAs in retransmission list
172 */
173 public int noReTransmissionLists() {
174 return noReTransmissionLists;
175 }
176
177 /**
178 * Sets number of LSAs in retransmission list.
179 *
180 * @param noReTransmissionLists number of LSAs in retransmission list
181 */
182 public void setNoReTransmissionLists(int noReTransmissionLists) {
183 this.noReTransmissionLists = noReTransmissionLists;
184 }
185
186 /**
187 * whether LSA in age bin or not.
188 *
189 * @return true if LSA in age bin else false
190 */
191 public boolean isInAnAgeBin() {
192 return inAnAgeBin;
193 }
194
195 /**
196 * Sets whether LSA in age bin or not.
197 *
198 * @param inAnAgeBin whether LSA in age bin or not
199 */
200 public void setInAnAgeBin(boolean inAnAgeBin) {
201 this.inAnAgeBin = inAnAgeBin;
202 }
203
204 /**
205 * Gets if LSA is changed since last flood.
206 *
207 * @return true if LSA is changed since last flood else false
208 */
209 public boolean isChangedSinceLastFlood() {
210 return changedSinceLastFlood;
211 }
212
213 /**
214 * Sets if LSA is changed since last flood.
215 *
216 * @param changedSinceLastFlood true if LSA is changed since last flood else false
217 */
218 public void setChangedSinceLastFlood(boolean changedSinceLastFlood) {
219 this.changedSinceLastFlood = changedSinceLastFlood;
220 }
221
222 /**
223 * Gets if sequence number rolled over.
224 *
225 * @return true if sequence rolled over else false.
226 */
227 public boolean isSequenceRollOver() {
228 return isSequenceRollOver;
229 }
230
231 /**
232 * Sets if sequence number rolled over.
233 *
234 * @param isSequenceRollOver true if sequence rolled over else false
235 */
236 public void setIsSequenceRollOver(boolean isSequenceRollOver) {
237 this.isSequenceRollOver = isSequenceRollOver;
238 }
239
240 /**
241 * Gets is sent reply for older LSA.
242 *
243 * @return true if sent reply for old LSA else false
244 */
245 public boolean isSentReplyForOlderLsa() {
246 return sentReplyForOlderLsa;
247 }
248
249 /**
250 * Sets is sent reply for older lsa.
251 *
252 * @param sentReplyForOlderLsa true if sent reply for older lsa else false
253 */
254 public void setSentReplyForOlderLsa(boolean sentReplyForOlderLsa) {
255 this.sentReplyForOlderLsa = sentReplyForOlderLsa;
256 }
257
258 /**
259 * Gets check age flag.
260 *
261 * @return true check age flag is set else false
262 */
263 public boolean isCheckAge() {
264 return checkAge;
265 }
266
267 /**
268 * Sets check age flag.
269 *
270 * @param checkAge check age flag.
271 */
272 public void setCheckAge(boolean checkAge) {
273 this.checkAge = checkAge;
274 }
275
276 /**
277 * Gets value of aging flag.
278 *
279 * @return is aging flag
280 */
281 public boolean isAging() {
282 return isAging;
283 }
284
285 /**
286 * Sets aging flag.
287 *
288 * @param isAging is aging flag
289 */
290 public void setIsAging(boolean isAging) {
291 this.isAging = isAging;
292 }
293
294 /**
295 * Gets the LSDB age.
296 *
297 * @return LSDB age
298 */
299 public LsdbAge getLsdbAge() {
300 return lsdbAge;
301 }
302
303 /**
304 * Sets the LSDB age.
305 *
306 * @param lsdbAge LSDB age
307 */
308 public void setLsdbAge(LsdbAge lsdbAge) {
309 this.lsdbAge = lsdbAge;
310 }
311
312 /**
313 * Gets the current LSA Age.
314 *
315 * @return LSA age
316 */
317 public int currentAge() {
318
319 int currentAge = 0;
320 //ls age received
321 if (lsdbAge.getAgeCounter() >= ageCounterWhenReceived) {
322 currentAge = lsaAgeReceived + (lsdbAge.getAgeCounter() - ageCounterWhenReceived);
323 } else {
324 currentAge = lsaAgeReceived + ((OspfParameters.MAXAGE + lsdbAge.getAgeCounter())
325 - ageCounterWhenReceived);
326 }
327
328 if (currentAge >= OspfParameters.MAXAGE) {
329 return OspfParameters.MAXAGE;
sunishvkf7c56552016-07-18 16:02:39 +0530330 } else if ((currentAge == lsaAgeReceived) && ageCounterRollOverWhenAdded != lsdbAge.getAgeCounterRollOver()) {
331 return OspfParameters.MAXAGE;
Kalyankumar Asangi27728f22016-02-17 15:46:28 +0530332 }
333
334 return currentAge;
335 }
336
337 /**
338 * Gets the age counter when received.
339 *
340 * @return the age counter when received
341 */
342 public int ageCounterWhenReceived() {
343 return ageCounterWhenReceived;
344 }
345
346 /**
347 * Sets the age counter when received.
348 *
349 * @param ageCounterWhenReceived the age counter when received
350 */
351 public void setAgeCounterWhenReceived(int ageCounterWhenReceived) {
352 this.ageCounterWhenReceived = ageCounterWhenReceived;
353 }
354
355 /**
356 * Gets the LSA process command.
357 *
358 * @return LSA process command
359 */
360 public String lsaProcessing() {
361 return lsaProcessing;
362 }
363
364 /**
365 * Sets the LSA process command.
366 *
367 * @param lsaProcessing LSA process command
368 */
369 public void setLsaProcessing(String lsaProcessing) {
370 this.lsaProcessing = lsaProcessing;
371 }
372
373 /**
374 * Gets bin number.
375 *
376 * @return bin number
377 */
378 public int binNumber() {
379 return binNumber;
380 }
381
382 /**
383 * Sets bin number.
384 *
385 * @param binNumber bin number
386 */
387 public void setBinNumber(int binNumber) {
388 this.binNumber = binNumber;
389 }
390
391
392 /**
393 * Get the OSPF interface.
394 *
395 * @return the OSPF interface.
396 */
397 public OspfInterface ospfInterface() {
398 return ospfInterface;
399 }
400
401 /**
402 * Sets the OSPF interface.
403 *
404 * @param ospfInterface OSPF interface instance
405 */
406 @Override
407 public void setOspfInterface(OspfInterface ospfInterface) {
408 this.ospfInterface = ospfInterface;
409 }
410
411 @Override
412 public String toString() {
413 return MoreObjects.toStringHelper(getClass())
414 .omitNullValues()
415 .add("lsaAgeReceived", lsaAgeReceived)
416 .add("ageCounterWhenReceived", ageCounterWhenReceived)
417 .add("isSelfOriginated", isSelfOriginated)
418 .add("lsaHeader", lsaHeader)
419 .add("lsaType", lsaType)
420 .add("ospflsa", ospfLsa)
421 .add("noReTransmissionLists", noReTransmissionLists)
422 .add("inAnAgeBin", inAnAgeBin)
423 .add("changedSinceLasFlood", changedSinceLastFlood)
424 .add("isSequenceRollOver", isSequenceRollOver)
425 .add("sentReplyForOlderLSA", sentReplyForOlderLsa)
426 .add("checkAge", checkAge)
427 .add("isAging", isAging)
428 .add("lsaProcessing", lsaProcessing)
429 .toString();
430 }
431
432 @Override
433 public boolean equals(Object o) {
434 if (this == o) {
435 return true;
436 }
437 if (o == null || getClass() != o.getClass()) {
438 return false;
439 }
440 LsaWrapperImpl that = (LsaWrapperImpl) o;
441 return Objects.equal(lsaAgeReceived, that.lsaAgeReceived) &&
442 Objects.equal(ageCounterWhenReceived, that.ageCounterWhenReceived) &&
443 Objects.equal(isSelfOriginated, that.isSelfOriginated) &&
444 Objects.equal(lsaHeader, that.lsaHeader) &&
445 Objects.equal(ospfLsa, that.ospfLsa) &&
446 Objects.equal(noReTransmissionLists, that.noReTransmissionLists) &&
447 Objects.equal(inAnAgeBin, that.inAnAgeBin) &&
448 Objects.equal(changedSinceLastFlood, that.changedSinceLastFlood) &&
449 Objects.equal(isSequenceRollOver, that.isSequenceRollOver) &&
450 Objects.equal(sentReplyForOlderLsa, that.sentReplyForOlderLsa) &&
451 Objects.equal(checkAge, that.checkAge) &&
452 Objects.equal(isAging, that.isAging) &&
453 Objects.equal(lsaProcessing, that.lsaProcessing);
454 }
455
456 @Override
457 public int hashCode() {
458 return Objects.hashCode(lsaAgeReceived, lsaAgeReceived, ageCounterWhenReceived, isSelfOriginated,
459 lsaHeader, lsaType, ospfLsa, noReTransmissionLists, inAnAgeBin,
460 changedSinceLastFlood, isSequenceRollOver, sentReplyForOlderLsa,
461 checkAge, isAging, lsaProcessing);
462 }
463}