tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +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.isis.controller.impl.lsdb; |
| 17 | |
| 18 | import org.onosproject.isis.controller.IsisInterface; |
| 19 | import org.onosproject.isis.controller.IsisLsdbAge; |
| 20 | import org.onosproject.isis.controller.IsisPduType; |
| 21 | import org.onosproject.isis.controller.LspWrapper; |
| 22 | import org.onosproject.isis.io.isispacket.pdu.LsPdu; |
| 23 | import org.onosproject.isis.io.util.IsisConstants; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 24 | import org.slf4j.Logger; |
| 25 | import org.slf4j.LoggerFactory; |
tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Representation of LSP wrapper where the LSPs are stored with metadata. |
| 29 | */ |
| 30 | public class DefaultLspWrapper implements LspWrapper { |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 31 | private static final Logger log = LoggerFactory.getLogger(DefaultLspWrapper.class); |
tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 32 | private int binNumber = -1; |
| 33 | private boolean selfOriginated = false; |
| 34 | private IsisPduType lspType; |
| 35 | private int lspAgeReceived; |
| 36 | private int ageCounterWhenReceived; |
| 37 | private LsPdu lsPdu; |
| 38 | private IsisLsdbAge lsdbAge; |
| 39 | private int ageCounterRollOverWhenAdded; |
| 40 | private int remainingLifetime; |
| 41 | private IsisInterface isisInterface; |
| 42 | private String lspProcessing; |
| 43 | |
| 44 | /** |
| 45 | * Returns "refreshLsp" or "maxageLsp" based on LSP to process. |
| 46 | * |
| 47 | * @return LSP processing string |
| 48 | */ |
| 49 | public String lspProcessing() { |
| 50 | return lspProcessing; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Sets LSP processing "refreshLsp" or "maxageLsp" based on LSP to process. |
| 55 | * |
| 56 | * @param lspProcessing "refreshLsp" or "maxageLsp" based on LSP to process |
| 57 | */ |
| 58 | public void setLspProcessing(String lspProcessing) { |
| 59 | this.lspProcessing = lspProcessing; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns LSP age received. |
| 64 | * |
| 65 | * @return LSP age received |
| 66 | */ |
| 67 | public int lspAgeReceived() { |
| 68 | return lspAgeReceived; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Sets LSP age received. |
| 73 | * |
| 74 | * @param lspAgeReceived LSP age received. |
| 75 | */ |
| 76 | public void setLspAgeReceived(int lspAgeReceived) { |
| 77 | this.lspAgeReceived = lspAgeReceived; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns ISIS interface instance. |
| 82 | * |
| 83 | * @return ISIS interface instance |
| 84 | */ |
| 85 | public IsisInterface isisInterface() { |
| 86 | return isisInterface; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Sets ISIS interface. |
| 91 | * |
| 92 | * @param isisInterface ISIS interface instance |
| 93 | */ |
| 94 | public void setIsisInterface(IsisInterface isisInterface) { |
| 95 | this.isisInterface = isisInterface; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Returns age counter when received. |
| 100 | * |
| 101 | * @return age counter when received |
| 102 | */ |
| 103 | public int ageCounterWhenReceived() { |
| 104 | |
| 105 | return ageCounterWhenReceived; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Sets age counter when received. |
| 110 | * |
| 111 | * @param ageCounterWhenReceived age counter when received |
| 112 | */ |
| 113 | public void setAgeCounterWhenReceived(int ageCounterWhenReceived) { |
| 114 | this.ageCounterWhenReceived = ageCounterWhenReceived; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Returns age counter roll over. |
| 119 | * |
| 120 | * @return age counter roll over |
| 121 | */ |
| 122 | public int ageCounterRollOverWhenAdded() { |
| 123 | return ageCounterRollOverWhenAdded; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Sets age counter roll over when added. |
| 128 | * |
| 129 | * @param ageCounterRollOverWhenAdded age counter roll over when added |
| 130 | */ |
| 131 | public void setAgeCounterRollOverWhenAdded(int ageCounterRollOverWhenAdded) { |
| 132 | this.ageCounterRollOverWhenAdded = ageCounterRollOverWhenAdded; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Returns bin number. |
| 137 | * |
| 138 | * @return bin number |
| 139 | */ |
| 140 | public int binNumber() { |
| 141 | return binNumber; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Sets bin number. |
| 146 | * |
| 147 | * @param binNumber bin number |
| 148 | */ |
| 149 | public void setBinNumber(int binNumber) { |
| 150 | this.binNumber = binNumber; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Returns true if self originated. |
| 155 | * |
| 156 | * @return true if self originated. |
| 157 | */ |
| 158 | public boolean isSelfOriginated() { |
| 159 | return selfOriginated; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Sets true if self originated. |
| 164 | * |
| 165 | * @param selfOriginated true if self originated else false |
| 166 | */ |
| 167 | public void setSelfOriginated(boolean selfOriginated) { |
| 168 | this.selfOriginated = selfOriginated; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Returns ISIS PDU type. |
| 173 | * |
| 174 | * @return ISIS PDU type |
| 175 | */ |
| 176 | public IsisPduType lspType() { |
| 177 | return lspType; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Sets ISIS PDU type. |
| 182 | * |
| 183 | * @param lspType ISIS PDU type |
| 184 | */ |
| 185 | public void setLspType(IsisPduType lspType) { |
| 186 | this.lspType = lspType; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Returns LSPDU which the wrapper contains. |
| 191 | * |
| 192 | * @return LSPDU which the wrapper contains |
| 193 | */ |
| 194 | public LsPdu lsPdu() { |
| 195 | return lsPdu; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Sets LSPDU which the wrapper contains. |
| 200 | * |
| 201 | * @param lsPdu LSPDU which the wrapper contains |
| 202 | */ |
| 203 | public void setLsPdu(LsPdu lsPdu) { |
| 204 | this.lsPdu = lsPdu; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Returns ISIS LSDB age. |
| 209 | * |
| 210 | * @return ISIS LSDB age |
| 211 | */ |
| 212 | public IsisLsdbAge lsdbAge() { |
| 213 | return lsdbAge; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Sets LSDB age. |
| 218 | * |
| 219 | * @param lsdbAge LSDB age |
| 220 | */ |
| 221 | public void setLsdbAge(IsisLsdbAge lsdbAge) { |
| 222 | this.lsdbAge = lsdbAge; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Returns the current LSP Age. |
| 227 | * |
| 228 | * @return LSP age |
| 229 | */ |
| 230 | public int currentAge() { |
| 231 | |
| 232 | int currentAge = 0; |
| 233 | //ls age received |
| 234 | if (lsdbAge.ageCounter() >= ageCounterWhenReceived) { |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 235 | if (!selfOriginated) { |
| 236 | if (ageCounterRollOverWhenAdded == lsdbAge.ageCounterRollOver()) { |
tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 237 | currentAge = lspAgeReceived + (lsdbAge.ageCounter() - ageCounterWhenReceived); |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 238 | } else { |
| 239 | return IsisConstants.LSPMAXAGE; |
| 240 | } |
| 241 | } else { |
| 242 | currentAge = lspAgeReceived + (lsdbAge.ageCounter() - ageCounterWhenReceived); |
| 243 | } |
tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 244 | } else { |
| 245 | currentAge = lspAgeReceived + ((IsisConstants.LSPMAXAGE + lsdbAge.ageCounter()) |
| 246 | - ageCounterWhenReceived); |
| 247 | } |
| 248 | |
| 249 | if (currentAge >= IsisConstants.LSPMAXAGE) { |
| 250 | return IsisConstants.LSPMAXAGE; |
| 251 | } else if ((currentAge == lspAgeReceived) && ageCounterRollOverWhenAdded |
| 252 | != lsdbAge.ageCounterRollOver()) { |
| 253 | return IsisConstants.LSPMAXAGE; |
| 254 | } |
| 255 | |
| 256 | return currentAge; |
| 257 | } |
| 258 | |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 259 | |
| 260 | |
tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 261 | /** |
| 262 | * Returns remaining time. |
| 263 | * |
| 264 | * @return remaining time |
| 265 | */ |
| 266 | public int remainingLifetime() { |
| 267 | //Calculate the remaining lifetime |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 268 | remainingLifetime = IsisConstants.LSPMAXAGE - currentAge(); |
tejeshwer degala | 3fe1ed5 | 2016-04-22 17:04:01 +0530 | [diff] [blame] | 269 | return remainingLifetime; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Sets remaining life time. |
| 274 | * |
| 275 | * @param remainingLifetime LSPs remaining life time |
| 276 | */ |
| 277 | public void setRemainingLifetime(int remainingLifetime) { |
| 278 | this.remainingLifetime = remainingLifetime; |
| 279 | } |
| 280 | } |