SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +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.pcep.controller.impl; |
| 17 | |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 18 | import java.util.Arrays; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 19 | import java.util.Collection; |
| 20 | import java.util.Collections; |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 21 | import java.util.HashMap; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 22 | import java.util.HashSet; |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 23 | import java.util.Iterator; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 24 | import java.util.LinkedList; |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 25 | import java.util.List; |
| 26 | import java.util.ListIterator; |
| 27 | import java.util.Map; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 28 | import java.util.Set; |
| 29 | import java.util.concurrent.ConcurrentHashMap; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 30 | |
| 31 | import org.apache.felix.scr.annotations.Activate; |
| 32 | import org.apache.felix.scr.annotations.Component; |
| 33 | import org.apache.felix.scr.annotations.Deactivate; |
Priyanka B | 94395bf | 2016-05-21 18:39:46 +0530 | [diff] [blame] | 34 | import org.apache.felix.scr.annotations.Reference; |
| 35 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 36 | import org.apache.felix.scr.annotations.Service; |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 37 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 38 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 39 | import org.onosproject.incubator.net.tunnel.TunnelService; |
| 40 | import org.onosproject.incubator.net.tunnel.Tunnel.State; |
Priyanka B | 94395bf | 2016-05-21 18:39:46 +0530 | [diff] [blame] | 41 | import org.onosproject.net.device.DeviceService; |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 42 | import org.onosproject.pcep.controller.LspKey; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 43 | import org.onosproject.pcep.controller.PccId; |
| 44 | import org.onosproject.pcep.controller.PcepClient; |
| 45 | import org.onosproject.pcep.controller.PcepClientController; |
| 46 | import org.onosproject.pcep.controller.PcepClientListener; |
| 47 | import org.onosproject.pcep.controller.PcepEventListener; |
Priyanka B | 94395bf | 2016-05-21 18:39:46 +0530 | [diff] [blame] | 48 | import org.onosproject.pcep.controller.PcepNodeListener; |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 49 | import org.onosproject.pcep.controller.PcepPacketListener; |
| 50 | import org.onosproject.pcep.controller.PcepSyncStatus; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 51 | import org.onosproject.pcep.controller.driver.PcepAgent; |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 52 | import org.onosproject.pcepio.exceptions.PcepParseException; |
| 53 | import org.onosproject.pcepio.protocol.PcInitiatedLspRequest; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 54 | import org.onosproject.pcepio.protocol.PcepError; |
| 55 | import org.onosproject.pcepio.protocol.PcepErrorInfo; |
| 56 | import org.onosproject.pcepio.protocol.PcepErrorMsg; |
| 57 | import org.onosproject.pcepio.protocol.PcepErrorObject; |
| 58 | import org.onosproject.pcepio.protocol.PcepFactory; |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 59 | import org.onosproject.pcepio.protocol.PcepInitiateMsg; |
| 60 | import org.onosproject.pcepio.protocol.PcepLspObject; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 61 | import org.onosproject.pcepio.protocol.PcepMessage; |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 62 | import org.onosproject.pcepio.protocol.PcepReportMsg; |
| 63 | import org.onosproject.pcepio.protocol.PcepStateReport; |
| 64 | import org.onosproject.pcepio.types.PcepValueType; |
| 65 | import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; |
| 66 | import org.onosproject.pcepio.types.SymbolicPathNameTlv; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 67 | import org.slf4j.Logger; |
| 68 | import org.slf4j.LoggerFactory; |
| 69 | |
| 70 | import com.google.common.collect.Sets; |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 71 | import static com.google.common.base.Preconditions.checkNotNull; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 72 | |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 73 | import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC; |
| 74 | import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE; |
| 75 | import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE; |
| 76 | import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_DELETE; |
| 77 | import static org.onosproject.pcep.controller.PcepLspSyncAction.UNSTABLE; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 78 | import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_TYPE_19; |
| 79 | import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5; |
| 80 | |
Phanendra Manda | 51fb9c2 | 2015-09-01 16:17:41 +0530 | [diff] [blame] | 81 | /** |
| 82 | * Implementation of PCEP client controller. |
| 83 | */ |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 84 | @Component(immediate = true) |
| 85 | @Service |
| 86 | public class PcepClientControllerImpl implements PcepClientController { |
| 87 | |
| 88 | private static final Logger log = LoggerFactory.getLogger(PcepClientControllerImpl.class); |
| 89 | |
Priyanka B | 94395bf | 2016-05-21 18:39:46 +0530 | [diff] [blame] | 90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 91 | protected DeviceService deviceService; |
| 92 | |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 93 | protected ConcurrentHashMap<PccId, PcepClient> connectedClients = |
Sho SHIMIZU | 9b8274c | 2015-09-04 15:54:24 -0700 | [diff] [blame] | 94 | new ConcurrentHashMap<>(); |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 95 | |
| 96 | protected PcepClientAgent agent = new PcepClientAgent(); |
| 97 | protected Set<PcepClientListener> pcepClientListener = new HashSet<>(); |
| 98 | |
| 99 | protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); |
Priyanka B | 94395bf | 2016-05-21 18:39:46 +0530 | [diff] [blame] | 100 | protected Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet(); |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 101 | protected Set<PcepPacketListener> pcepPacketListener = Sets.newHashSet(); |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 102 | |
| 103 | private final Controller ctrl = new Controller(); |
| 104 | |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 105 | public static final String BANDWIDTH = "bandwidth"; |
| 106 | public static final String LSP_SIG_TYPE = "lspSigType"; |
| 107 | public static final String PCC_TUNNEL_ID = "PccTunnelId"; |
| 108 | public static final String PLSP_ID = "PLspId"; |
| 109 | public static final String LOCAL_LSP_ID = "localLspId"; |
| 110 | public static final String PCE_INIT = "pceInit"; |
| 111 | public static final String COST_TYPE = "costType"; |
| 112 | public static final String DELEGATE = "delegation"; |
| 113 | |
| 114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 115 | protected TunnelService tunnelService; |
| 116 | |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 117 | @Activate |
| 118 | public void activate() { |
| 119 | ctrl.start(agent); |
| 120 | log.info("Started"); |
| 121 | } |
| 122 | |
| 123 | @Deactivate |
| 124 | public void deactivate() { |
| 125 | // Close all connected clients |
| 126 | closeConnectedClients(); |
| 127 | ctrl.stop(); |
| 128 | log.info("Stopped"); |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public Collection<PcepClient> getClients() { |
| 133 | return connectedClients.values(); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public PcepClient getClient(PccId pccId) { |
| 138 | return connectedClients.get(pccId); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public void addListener(PcepClientListener listener) { |
| 143 | if (!pcepClientListener.contains(listener)) { |
| 144 | this.pcepClientListener.add(listener); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void removeListener(PcepClientListener listener) { |
| 150 | this.pcepClientListener.remove(listener); |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public void addEventListener(PcepEventListener listener) { |
| 155 | pcepEventListener.add(listener); |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public void removeEventListener(PcepEventListener listener) { |
| 160 | pcepEventListener.remove(listener); |
| 161 | } |
| 162 | |
| 163 | @Override |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 164 | public void addPacketListener(PcepPacketListener listener) { |
| 165 | pcepPacketListener.add(listener); |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void removePacketListener(PcepPacketListener listener) { |
| 170 | pcepPacketListener.remove(listener); |
| 171 | } |
| 172 | |
| 173 | @Override |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 174 | public void writeMessage(PccId pccId, PcepMessage msg) { |
| 175 | this.getClient(pccId).sendMessage(msg); |
| 176 | } |
| 177 | |
| 178 | @Override |
Priyanka B | 94395bf | 2016-05-21 18:39:46 +0530 | [diff] [blame] | 179 | public void addNodeListener(PcepNodeListener listener) { |
| 180 | pcepNodeListener.add(listener); |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public void removeNodeListener(PcepNodeListener listener) { |
| 185 | pcepNodeListener.remove(listener); |
| 186 | } |
| 187 | |
| 188 | @Override |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 189 | public void processClientMessage(PccId pccId, PcepMessage msg) { |
| 190 | PcepClient pc = getClient(pccId); |
| 191 | |
| 192 | switch (msg.getType()) { |
| 193 | case NONE: |
| 194 | break; |
| 195 | case OPEN: |
| 196 | break; |
| 197 | case KEEP_ALIVE: |
| 198 | break; |
| 199 | case PATH_COMPUTATION_REQUEST: |
| 200 | break; |
| 201 | case PATH_COMPUTATION_REPLY: |
| 202 | break; |
| 203 | case NOTIFICATION: |
| 204 | break; |
| 205 | case ERROR: |
| 206 | break; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 207 | case INITIATE: |
| 208 | if (!pc.capability().pcInstantiationCapability()) { |
| 209 | pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(), ERROR_TYPE_19, |
| 210 | ERROR_VALUE_5))); |
| 211 | } |
| 212 | break; |
| 213 | case UPDATE: |
| 214 | if (!pc.capability().statefulPceCapability()) { |
| 215 | pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(), ERROR_TYPE_19, |
| 216 | ERROR_VALUE_5))); |
| 217 | } |
| 218 | break; |
| 219 | case LABEL_UPDATE: |
| 220 | if (!pc.capability().pceccCapability()) { |
| 221 | pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(), ERROR_TYPE_19, |
| 222 | ERROR_VALUE_5))); |
| 223 | } |
| 224 | break; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 225 | case CLOSE: |
| 226 | log.info("Sending Close Message to {" + pccId.toString() + "}"); |
| 227 | pc.sendMessage(Collections.singletonList(pc.factory().buildCloseMsg().build())); |
| 228 | //now disconnect client |
| 229 | pc.disconnectClient(); |
| 230 | break; |
| 231 | case REPORT: |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 232 | //Only update the listener if respective capability is supported else send PCEP-ERR msg |
| 233 | if (pc.capability().statefulPceCapability()) { |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 234 | |
| 235 | ListIterator<PcepStateReport> listIterator = ((PcepReportMsg) msg).getStateReportList().listIterator(); |
| 236 | while (listIterator.hasNext()) { |
| 237 | PcepStateReport stateRpt = listIterator.next(); |
| 238 | if (stateRpt.getLspObject().getSFlag()) { |
| 239 | if (pc.lspDbSyncStatus() != PcepSyncStatus.IN_SYNC) { |
| 240 | // Initialize LSP DB sync and temporary cache. |
| 241 | pc.setLspDbSyncStatus(PcepSyncStatus.IN_SYNC); |
| 242 | pc.initializeSyncMsgList(pccId); |
| 243 | } |
| 244 | // Store stateRpt in temporary cache. |
| 245 | pc.addSyncMsgToList(pccId, stateRpt); |
| 246 | |
| 247 | // Don't send to provider as of now. |
| 248 | continue; |
| 249 | } else { |
| 250 | if (pc.lspDbSyncStatus() == PcepSyncStatus.IN_SYNC) { |
| 251 | // Set end of LSPDB sync. |
| 252 | pc.setLspDbSyncStatus(PcepSyncStatus.SYNCED); |
| 253 | |
| 254 | // Call packet provider to initiate label DB sync (only if PCECC capable). |
| 255 | if (pc.capability().pceccCapability()) { |
| 256 | pc.setLabelDbSyncStatus(IN_SYNC); |
| 257 | for (PcepPacketListener l : pcepPacketListener) { |
| 258 | l.sendPacketIn(pccId); |
| 259 | } |
| 260 | } else { |
| 261 | // If label db sync is not to be done, handle end of LSPDB sync actions. |
| 262 | agent.analyzeSyncMsgList(pccId); |
| 263 | } |
| 264 | continue; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // It's a usual report message while sync is not undergoing. So process it immediately. |
| 269 | LinkedList<PcepStateReport> llPcRptList = new LinkedList<>(); |
| 270 | llPcRptList.add(stateRpt); |
| 271 | PcepMessage pcReportMsg = pc.factory().buildReportMsg().setStateReportList((llPcRptList)) |
| 272 | .build(); |
| 273 | for (PcepEventListener l : pcepEventListener) { |
| 274 | l.handleMessage(pccId, pcReportMsg); |
| 275 | } |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 276 | } |
| 277 | } else { |
| 278 | // Send PCEP-ERROR message. |
| 279 | pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(), |
| 280 | ERROR_TYPE_19, ERROR_VALUE_5))); |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 281 | } |
| 282 | break; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 283 | case LABEL_RANGE_RESERV: |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 284 | break; |
Priyanka B | 94395bf | 2016-05-21 18:39:46 +0530 | [diff] [blame] | 285 | case LS_REPORT: //TODO: need to handle LS report to add or remove node |
| 286 | break; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 287 | case MAX: |
| 288 | break; |
| 289 | case END: |
| 290 | break; |
| 291 | default: |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public void closeConnectedClients() { |
| 298 | PcepClient pc; |
| 299 | for (PccId id : connectedClients.keySet()) { |
| 300 | pc = getClient(id); |
| 301 | pc.disconnectClient(); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | /** |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 306 | * Returns pcep error message with specific error type and value. |
| 307 | * |
| 308 | * @param factory represents pcep factory |
| 309 | * @param errorType pcep error type |
| 310 | * @param errorValue pcep error value |
| 311 | * @return pcep error message |
| 312 | */ |
| 313 | public PcepErrorMsg getErrMsg(PcepFactory factory, byte errorType, byte errorValue) { |
| 314 | LinkedList<PcepError> llPcepErr = new LinkedList<>(); |
| 315 | |
| 316 | LinkedList<PcepErrorObject> llerrObj = new LinkedList<>(); |
| 317 | PcepErrorMsg errMsg; |
| 318 | |
| 319 | PcepErrorObject errObj = factory.buildPcepErrorObject().setErrorValue(errorValue).setErrorType(errorType) |
| 320 | .build(); |
| 321 | |
| 322 | llerrObj.add(errObj); |
| 323 | PcepError pcepErr = factory.buildPcepError().setErrorObjList(llerrObj).build(); |
| 324 | |
| 325 | llPcepErr.add(pcepErr); |
| 326 | |
| 327 | PcepErrorInfo errInfo = factory.buildPcepErrorInfo().setPcepErrorList(llPcepErr).build(); |
| 328 | |
| 329 | errMsg = factory.buildPcepErrorMsg().setPcepErrorInfo(errInfo).build(); |
| 330 | return errMsg; |
| 331 | } |
| 332 | |
| 333 | /** |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 334 | * Implementation of an Pcep Agent which is responsible for |
| 335 | * keeping track of connected clients and the state in which |
| 336 | * they are. |
| 337 | */ |
| 338 | public class PcepClientAgent implements PcepAgent { |
| 339 | |
| 340 | private final Logger log = LoggerFactory.getLogger(PcepClientAgent.class); |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 341 | |
| 342 | @Override |
| 343 | public boolean addConnectedClient(PccId pccId, PcepClient pc) { |
| 344 | |
| 345 | if (connectedClients.get(pccId) != null) { |
| 346 | log.error("Trying to add connectedClient but found a previous " |
| 347 | + "value for pcc ip: {}", pccId.toString()); |
| 348 | return false; |
| 349 | } else { |
| 350 | log.debug("Added Client {}", pccId.toString()); |
| 351 | connectedClients.put(pccId, pc); |
| 352 | for (PcepClientListener l : pcepClientListener) { |
| 353 | l.clientConnected(pccId); |
| 354 | } |
| 355 | return true; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | @Override |
| 360 | public boolean validActivation(PccId pccId) { |
| 361 | if (connectedClients.get(pccId) == null) { |
| 362 | log.error("Trying to activate client but is not in " |
| 363 | + "connected client: pccIp {}. Aborting ..", pccId.toString()); |
| 364 | return false; |
| 365 | } |
| 366 | |
| 367 | return true; |
| 368 | } |
| 369 | |
| 370 | @Override |
| 371 | public void removeConnectedClient(PccId pccId) { |
| 372 | |
| 373 | connectedClients.remove(pccId); |
| 374 | for (PcepClientListener l : pcepClientListener) { |
| 375 | log.warn("removal for {}", pccId.toString()); |
| 376 | l.clientDisconnected(pccId); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | @Override |
| 381 | public void processPcepMessage(PccId pccId, PcepMessage m) { |
| 382 | processClientMessage(pccId, m); |
| 383 | } |
Priyanka B | 94395bf | 2016-05-21 18:39:46 +0530 | [diff] [blame] | 384 | |
| 385 | @Override |
| 386 | public void addNode(PcepClient pc) { |
| 387 | for (PcepNodeListener l : pcepNodeListener) { |
| 388 | l.addNode(pc); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public void deleteNode(PccId pccId) { |
| 394 | for (PcepNodeListener l : pcepNodeListener) { |
| 395 | l.deleteNode(pccId); |
| 396 | } |
| 397 | } |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 398 | |
| 399 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
| 400 | @Override |
| 401 | public boolean analyzeSyncMsgList(PccId pccId) { |
| 402 | PcepClient pc = getClient(pccId); |
| 403 | /* |
| 404 | * PLSP_ID is null while tunnel is created at PCE and PCInit msg carries it as 0. It is allocated by PCC and |
| 405 | * in that case it becomes the first PCRpt msg from PCC for this LSP, and hence symbolic path name must be |
| 406 | * carried in the PCRpt msg. Draft says: The SYMBOLIC-PATH-NAME TLV "MUST" be included in the LSP object in |
| 407 | * the LSP State Report (PCRpt) message when during a given PCEP session an LSP is "first" reported to a |
| 408 | * PCE. So two separate lists with separate keys are maintained. |
| 409 | */ |
| 410 | Map<LspKey, Tunnel> preSyncLspDbByKey = new HashMap<>(); |
| 411 | Map<String, Tunnel> preSyncLspDbByName = new HashMap<>(); |
| 412 | |
| 413 | // Query tunnel service and fetch all the tunnels with this PCC as ingress. |
| 414 | // Organize into two maps, with LSP key if known otherwise with symbolic path name, for quick search. |
| 415 | Collection<Tunnel> queriedTunnels = tunnelService.queryTunnel(Tunnel.Type.MPLS); |
| 416 | for (Tunnel tunnel : queriedTunnels) { |
| 417 | if (((IpTunnelEndPoint) tunnel.src()).ip().equals(pccId.ipAddress())) { |
| 418 | String pLspId = tunnel.annotations().value(PLSP_ID); |
| 419 | if (pLspId != null) { |
| 420 | String localLspId = tunnel.annotations().value(LOCAL_LSP_ID); |
| 421 | checkNotNull(localLspId); |
| 422 | LspKey lspKey = new LspKey(Integer.valueOf(pLspId), Short.valueOf(localLspId)); |
| 423 | preSyncLspDbByKey.put(lspKey, tunnel); |
| 424 | } else { |
| 425 | preSyncLspDbByName.put(tunnel.tunnelName().value(), tunnel); |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | List<PcepStateReport> syncStateRptList = pc.getSyncMsgList(pccId); |
| 431 | Iterator<PcepStateReport> stateRptListIterator = syncStateRptList.iterator(); |
| 432 | |
| 433 | // For every report, fetch PLSP id, local LSP id and symbolic path name from the message. |
| 434 | while (syncStateRptList.iterator().hasNext()) { |
| 435 | PcepStateReport stateRpt = stateRptListIterator.next(); |
| 436 | Tunnel tunnel = null; |
| 437 | |
| 438 | PcepLspObject lspObj = stateRpt.getLspObject(); |
| 439 | ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator(); |
| 440 | StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv = null; |
| 441 | SymbolicPathNameTlv pathNameTlv = null; |
| 442 | |
| 443 | while (listTlvIterator.hasNext()) { |
| 444 | PcepValueType tlv = listTlvIterator.next(); |
| 445 | switch (tlv.getType()) { |
| 446 | case StatefulIPv4LspIdentifiersTlv.TYPE: |
| 447 | ipv4LspIdenTlv = (StatefulIPv4LspIdentifiersTlv) tlv; |
| 448 | break; |
| 449 | |
| 450 | case SymbolicPathNameTlv.TYPE: |
| 451 | pathNameTlv = (SymbolicPathNameTlv) tlv; |
| 452 | break; |
| 453 | |
| 454 | default: |
| 455 | break; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | LspKey lspKeyOfRpt = new LspKey(lspObj.getPlspId(), ipv4LspIdenTlv.getLspId()); |
| 460 | tunnel = preSyncLspDbByKey.get(lspKeyOfRpt); |
| 461 | // PCE tunnel is matched with PCRpt LSP. Now delete it from the preSyncLspDb list as the residual |
| 462 | // non-matching list will be processed at the end. |
| 463 | if (tunnel != null) { |
| 464 | preSyncLspDbByKey.remove(lspKeyOfRpt); |
| 465 | } else if (pathNameTlv != null) { |
| 466 | tunnel = preSyncLspDbByName.get(Arrays.toString(pathNameTlv.getValue())); |
| 467 | if (tunnel != null) { |
| 468 | preSyncLspDbByName.remove(tunnel.tunnelName()); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | if (tunnel == null) { |
| 473 | // If remove flag is set, and tunnel is not known to PCE, ignore it. |
| 474 | if (lspObj.getCFlag() && !lspObj.getRFlag()) { |
| 475 | // For initiated LSP, need to send PCInit delete msg. |
| 476 | try { |
| 477 | PcInitiatedLspRequest releaseLspRequest = pc.factory().buildPcInitiatedLspRequest() |
| 478 | .setLspObject(lspObj).build(); |
| 479 | LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList |
| 480 | = new LinkedList<PcInitiatedLspRequest>(); |
| 481 | llPcInitiatedLspRequestList.add(releaseLspRequest); |
| 482 | |
| 483 | PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg() |
| 484 | .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList).build(); |
| 485 | |
| 486 | for (PcepEventListener l : pcepEventListener) { |
| 487 | l.handleEndOfSyncAction(pccId, pcInitiateMsg, SEND_DELETE); |
| 488 | } |
| 489 | |
| 490 | } catch (PcepParseException e) { |
| 491 | log.error("Exception occured while sending initiate delete message {}", e.getMessage()); |
| 492 | } |
| 493 | } |
| 494 | continue; |
| 495 | } |
| 496 | |
| 497 | if (!lspObj.getCFlag()) { |
| 498 | // For learned LSP process both add/update PCRpt. |
| 499 | LinkedList<PcepStateReport> llPcRptList = new LinkedList<>(); |
| 500 | llPcRptList.add(stateRpt); |
| 501 | PcepMessage pcReportMsg = pc.factory().buildReportMsg().setStateReportList((llPcRptList)) |
| 502 | .build(); |
| 503 | |
| 504 | for (PcepEventListener l : pcepEventListener) { |
| 505 | l.handleMessage(pccId, pcReportMsg); |
| 506 | } |
| 507 | continue; |
| 508 | } |
| 509 | |
| 510 | // Implied that tunnel != null and lspObj.getCFlag() is set |
| 511 | // State different for PCC sent LSP and PCE known LSP, send PCUpd msg. |
| 512 | State tunnelState = PcepLspStatus |
| 513 | .getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]); |
| 514 | if (tunnelState != tunnel.state()) { |
| 515 | for (PcepEventListener l : pcepEventListener) { |
| 516 | l.handleEndOfSyncAction(tunnel, SEND_UPDATE); |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | // Check which tunnels are extra at PCE that were not reported by PCC. |
| 522 | Map<Object, Tunnel> preSyncLspDb = (Map) preSyncLspDbByKey; |
| 523 | handleResidualTunnels(preSyncLspDb); |
| 524 | preSyncLspDbByKey = null; |
| 525 | |
| 526 | preSyncLspDb = (Map) preSyncLspDbByName; |
| 527 | handleResidualTunnels(preSyncLspDb); |
| 528 | preSyncLspDbByName = null; |
| 529 | preSyncLspDb = null; |
| 530 | |
| 531 | pc.removeSyncMsgList(pccId); |
| 532 | return true; |
| 533 | } |
| 534 | |
| 535 | /* |
| 536 | * Go through the tunnels which are known by PCE but were not reported by PCC during LSP DB sync and take |
| 537 | * appropriate actions. |
| 538 | */ |
| 539 | private void handleResidualTunnels(Map<Object, Tunnel> preSyncLspDb) { |
| 540 | for (Tunnel pceExtraTunnel : preSyncLspDb.values()) { |
| 541 | if (pceExtraTunnel.annotations().value(PCE_INIT) == null |
| 542 | || "false".equalsIgnoreCase(pceExtraTunnel.annotations().value(PCE_INIT))) { |
| 543 | // PCC initiated tunnels should be removed from tunnel store. |
| 544 | for (PcepEventListener l : pcepEventListener) { |
| 545 | l.handleEndOfSyncAction(pceExtraTunnel, REMOVE); |
| 546 | } |
| 547 | } else { |
| 548 | // PCE initiated tunnels should be initiated again. |
| 549 | for (PcepEventListener l : pcepEventListener) { |
| 550 | l.handleEndOfSyncAction(pceExtraTunnel, UNSTABLE); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | } |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 555 | } |
| 556 | } |