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