blob: f1458ab456848571ab684b9fe833177cc36ba3d0 [file] [log] [blame]
SureshBR25058b72015-08-13 13:05:06 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
SureshBR25058b72015-08-13 13:05:06 +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.pcep.controller.impl;
17
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053018import java.util.Arrays;
SureshBR25058b72015-08-13 13:05:06 +053019import java.util.Collection;
20import java.util.Collections;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053021import java.util.HashMap;
SureshBR25058b72015-08-13 13:05:06 +053022import java.util.HashSet;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053023import java.util.Iterator;
Priyanka Bd2b28882016-04-04 16:57:04 +053024import java.util.LinkedList;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053025import java.util.List;
26import java.util.ListIterator;
27import java.util.Map;
SureshBR25058b72015-08-13 13:05:06 +053028import java.util.Set;
29import java.util.concurrent.ConcurrentHashMap;
SureshBR25058b72015-08-13 13:05:06 +053030
31import org.apache.felix.scr.annotations.Activate;
32import org.apache.felix.scr.annotations.Component;
33import org.apache.felix.scr.annotations.Deactivate;
Priyanka B94395bf2016-05-21 18:39:46 +053034import org.apache.felix.scr.annotations.Reference;
35import org.apache.felix.scr.annotations.ReferenceCardinality;
SureshBR25058b72015-08-13 13:05:06 +053036import org.apache.felix.scr.annotations.Service;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053037import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
38import org.onosproject.incubator.net.tunnel.Tunnel;
39import org.onosproject.incubator.net.tunnel.TunnelService;
40import org.onosproject.incubator.net.tunnel.Tunnel.State;
Priyanka B94395bf2016-05-21 18:39:46 +053041import org.onosproject.net.device.DeviceService;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053042import org.onosproject.pcep.controller.LspKey;
SureshBR25058b72015-08-13 13:05:06 +053043import org.onosproject.pcep.controller.PccId;
44import org.onosproject.pcep.controller.PcepClient;
45import org.onosproject.pcep.controller.PcepClientController;
46import org.onosproject.pcep.controller.PcepClientListener;
47import org.onosproject.pcep.controller.PcepEventListener;
Priyanka B259847d2016-06-03 21:28:35 +053048import org.onosproject.pcep.controller.PcepLspStatus;
Priyanka B94395bf2016-05-21 18:39:46 +053049import org.onosproject.pcep.controller.PcepNodeListener;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053050import org.onosproject.pcep.controller.PcepPacketListener;
51import org.onosproject.pcep.controller.PcepSyncStatus;
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +053052import org.onosproject.pcep.controller.SrpIdGenerators;
SureshBR25058b72015-08-13 13:05:06 +053053import org.onosproject.pcep.controller.driver.PcepAgent;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053054import org.onosproject.pcepio.exceptions.PcepParseException;
55import org.onosproject.pcepio.protocol.PcInitiatedLspRequest;
Priyanka Bd2b28882016-04-04 16:57:04 +053056import org.onosproject.pcepio.protocol.PcepError;
57import org.onosproject.pcepio.protocol.PcepErrorInfo;
58import org.onosproject.pcepio.protocol.PcepErrorMsg;
59import org.onosproject.pcepio.protocol.PcepErrorObject;
60import org.onosproject.pcepio.protocol.PcepFactory;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053061import org.onosproject.pcepio.protocol.PcepInitiateMsg;
62import org.onosproject.pcepio.protocol.PcepLspObject;
SureshBR25058b72015-08-13 13:05:06 +053063import org.onosproject.pcepio.protocol.PcepMessage;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053064import org.onosproject.pcepio.protocol.PcepReportMsg;
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +053065import org.onosproject.pcepio.protocol.PcepSrpObject;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053066import org.onosproject.pcepio.protocol.PcepStateReport;
67import org.onosproject.pcepio.types.PcepValueType;
68import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
69import org.onosproject.pcepio.types.SymbolicPathNameTlv;
SureshBR25058b72015-08-13 13:05:06 +053070import org.slf4j.Logger;
71import org.slf4j.LoggerFactory;
72
73import com.google.common.collect.Sets;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053074import static com.google.common.base.Preconditions.checkNotNull;
SureshBR25058b72015-08-13 13:05:06 +053075
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053076import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
77import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE;
78import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053079import static org.onosproject.pcep.controller.PcepLspSyncAction.UNSTABLE;
Priyanka Bd2b28882016-04-04 16:57:04 +053080import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_TYPE_19;
81import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5;
82
Phanendra Manda51fb9c22015-09-01 16:17:41 +053083/**
84 * Implementation of PCEP client controller.
85 */
SureshBR25058b72015-08-13 13:05:06 +053086@Component(immediate = true)
87@Service
88public class PcepClientControllerImpl implements PcepClientController {
89
90 private static final Logger log = LoggerFactory.getLogger(PcepClientControllerImpl.class);
91
Priyanka B94395bf2016-05-21 18:39:46 +053092 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
93 protected DeviceService deviceService;
94
SureshBR25058b72015-08-13 13:05:06 +053095 protected ConcurrentHashMap<PccId, PcepClient> connectedClients =
Sho SHIMIZU9b8274c2015-09-04 15:54:24 -070096 new ConcurrentHashMap<>();
SureshBR25058b72015-08-13 13:05:06 +053097
98 protected PcepClientAgent agent = new PcepClientAgent();
99 protected Set<PcepClientListener> pcepClientListener = new HashSet<>();
100
101 protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
Priyanka B94395bf2016-05-21 18:39:46 +0530102 protected Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530103 protected Set<PcepPacketListener> pcepPacketListener = Sets.newHashSet();
SureshBR25058b72015-08-13 13:05:06 +0530104
105 private final Controller ctrl = new Controller();
106
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530107 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
SureshBR25058b72015-08-13 13:05:06 +0530119 @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-Huaweid1e36bd2016-05-26 12:47:16 +0530166 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
SureshBR25058b72015-08-13 13:05:06 +0530176 public void writeMessage(PccId pccId, PcepMessage msg) {
177 this.getClient(pccId).sendMessage(msg);
178 }
179
180 @Override
Priyanka B94395bf2016-05-21 18:39:46 +0530181 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
SureshBR25058b72015-08-13 13:05:06 +0530191 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 Bd2b28882016-04-04 16:57:04 +0530209 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;
SureshBR25058b72015-08-13 13:05:06 +0530227 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 Bd2b28882016-04-04 16:57:04 +0530234 //Only update the listener if respective capability is supported else send PCEP-ERR msg
235 if (pc.capability().statefulPceCapability()) {
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530236
237 ListIterator<PcepStateReport> listIterator = ((PcepReportMsg) msg).getStateReportList().listIterator();
238 while (listIterator.hasNext()) {
239 PcepStateReport stateRpt = listIterator.next();
Avantika-Huawei3524d852016-06-04 20:44:13 +0530240 PcepLspObject lspObj = stateRpt.getLspObject();
241 if (lspObj.getSFlag()) {
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530242 if (pc.lspDbSyncStatus() != PcepSyncStatus.IN_SYNC) {
Avantika-Huawei3524d852016-06-04 20:44:13 +0530243 log.debug("LSP DB sync started for PCC {}", pc.getPccId().id().toString());
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530244 // 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-Huawei3524d852016-06-04 20:44:13 +0530253 } else if (lspObj.getPlspId() == 0) {
254 if (pc.lspDbSyncStatus() == PcepSyncStatus.IN_SYNC
255 || pc.lspDbSyncStatus() == PcepSyncStatus.NOT_SYNCED) {
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530256 // Set end of LSPDB sync.
Avantika-Huawei3524d852016-06-04 20:44:13 +0530257 log.debug("LSP DB sync completed for PCC {}", pc.getPccId().id().toString());
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530258 pc.setLspDbSyncStatus(PcepSyncStatus.SYNCED);
259
260 // Call packet provider to initiate label DB sync (only if PCECC capable).
261 if (pc.capability().pceccCapability()) {
Avantika-Huawei3524d852016-06-04 20:44:13 +0530262 log.debug("Trigger label DB sync for PCC {}", pc.getPccId().id().toString());
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530263 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 Bd2b28882016-04-04 16:57:04 +0530283 }
284 } else {
285 // Send PCEP-ERROR message.
286 pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(),
287 ERROR_TYPE_19, ERROR_VALUE_5)));
SureshBR25058b72015-08-13 13:05:06 +0530288 }
289 break;
Priyanka Bd2b28882016-04-04 16:57:04 +0530290 case LABEL_RANGE_RESERV:
SureshBR25058b72015-08-13 13:05:06 +0530291 break;
Priyanka B94395bf2016-05-21 18:39:46 +0530292 case LS_REPORT: //TODO: need to handle LS report to add or remove node
293 break;
SureshBR25058b72015-08-13 13:05:06 +0530294 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 Bd2b28882016-04-04 16:57:04 +0530313 * 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 /**
SureshBR25058b72015-08-13 13:05:06 +0530341 * 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);
SureshBR25058b72015-08-13 13:05:06 +0530348
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 B94395bf2016-05-21 18:39:46 +0530391
392 @Override
393 public void addNode(PcepClient pc) {
394 for (PcepNodeListener l : pcepNodeListener) {
Avantika-Huaweife44ea62016-05-27 19:21:24 +0530395 l.addDevicePcepConfig(pc);
Priyanka B94395bf2016-05-21 18:39:46 +0530396 }
397 }
398
399 @Override
400 public void deleteNode(PccId pccId) {
401 for (PcepNodeListener l : pcepNodeListener) {
Avantika-Huaweife44ea62016-05-27 19:21:24 +0530402 l.deleteDevicePcepConfig(pccId);
Priyanka B94395bf2016-05-21 18:39:46 +0530403 }
404 }
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530405
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-Huaweifc10dca2016-06-10 16:13:55 +0530438 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-Huaweif849aab2016-06-21 22:29:15 +0530442 log.debug("No LSPs reported from PCC during sync.");
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530443 }
444
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530445 Iterator<PcepStateReport> stateRptListIterator = syncStateRptList.iterator();
446
447 // For every report, fetch PLSP id, local LSP id and symbolic path name from the message.
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530448 while (stateRptListIterator.hasNext()) {
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530449 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-Huawei3c2d3eb2016-06-22 09:34:00 +0530491 PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(SrpIdGenerators.create())
492 .setRFlag(true).build();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530493 PcInitiatedLspRequest releaseLspRequest = pc.factory().buildPcInitiatedLspRequest()
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +0530494 .setLspObject(lspObj).setSrpObject(srpobj).build();
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530495 LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList
496 = new LinkedList<PcInitiatedLspRequest>();
497 llPcInitiatedLspRequestList.add(releaseLspRequest);
498
499 PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg()
500 .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList).build();
501
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +0530502 pc.sendMessage(Collections.singletonList(pcInitiateMsg));
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530503 } catch (PcepParseException e) {
504 log.error("Exception occured while sending initiate delete message {}", e.getMessage());
505 }
Avantika-Huaweif849aab2016-06-21 22:29:15 +0530506 continue;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530507 }
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530508 }
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 }
SureshBR25058b72015-08-13 13:05:06 +0530568 }
569}