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