3d50fd03a097a2bfb91b595f3fcf10933ee7e6e8
[bgpcep.git] / pcep / topology-provider / src / main / java / org / opendaylight / bgpcep / pcep / topology / provider / AbstractTopologySessionListener.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.bgpcep.pcep.topology.provider;
9
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import io.netty.util.concurrent.FutureListener;
16 import java.net.InetAddress;
17 import java.util.ArrayList;
18 import java.util.Collection;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Map.Entry;
23 import java.util.Timer;
24 import java.util.TimerTask;
25 import java.util.concurrent.TimeUnit;
26
27 import javax.annotation.concurrent.GuardedBy;
28 import org.opendaylight.controller.config.yang.pcep.topology.provider.ListenerStateRuntimeMXBean;
29 import org.opendaylight.controller.config.yang.pcep.topology.provider.ListenerStateRuntimeRegistration;
30 import org.opendaylight.controller.config.yang.pcep.topology.provider.PeerCapabilities;
31 import org.opendaylight.controller.config.yang.pcep.topology.provider.ReplyTime;
32 import org.opendaylight.controller.config.yang.pcep.topology.provider.SessionState;
33 import org.opendaylight.controller.config.yang.pcep.topology.provider.StatefulMessages;
34 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
35 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
36 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
37 import org.opendaylight.protocol.pcep.PCEPSession;
38 import org.opendaylight.protocol.pcep.PCEPSessionListener;
39 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
40 import org.opendaylight.protocol.pcep.TerminationReason;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.MessageHeader;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.LspId;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1Builder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.lsp.metadata.Metadata;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClientBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLspBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLspKey;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path;
58 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
59 import org.opendaylight.yangtools.yang.binding.DataContainer;
60 import org.opendaylight.yangtools.yang.binding.DataObject;
61 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
62 import org.slf4j.Logger;
63 import org.slf4j.LoggerFactory;
64
65 /**
66  * Base class for PCEP topology providers. It handles the common tasks involved in managing a PCEP server (PCE)
67  * endpoint, and exposing a network topology based on it. It needs to be subclassed to form a fully functional block,
68  * where the subclass provides handling of incoming messages.
69  *
70  * @param <S> identifier type of requests
71  * @param <L> identifier type for LSPs
72  */
73 public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessionListener, TopologySessionListener, ListenerStateRuntimeMXBean {
74     protected static final class MessageContext {
75         private final Collection<PCEPRequest> requests = new ArrayList<>();
76         private final WriteTransaction trans;
77
78         private MessageContext(final WriteTransaction trans) {
79             this.trans = Preconditions.checkNotNull(trans);
80         }
81
82         void resolveRequest(final PCEPRequest req) {
83             this.requests.add(req);
84         }
85
86         private void notifyRequests() {
87             for (final PCEPRequest r : this.requests) {
88                 r.done(OperationResults.SUCCESS);
89             }
90         }
91     }
92
93     protected static final MessageHeader MESSAGE_HEADER = new MessageHeader() {
94         private final ProtocolVersion version = new ProtocolVersion((short) 1);
95
96         @Override
97         public Class<? extends DataContainer> getImplementedInterface() {
98             return MessageHeader.class;
99         }
100
101         @Override
102         public ProtocolVersion getVersion() {
103             return this.version;
104         }
105     };
106
107     private static final Logger LOG = LoggerFactory.getLogger(AbstractTopologySessionListener.class);
108
109     protected static final String MISSING_XML_TAG = "Mandatory XML tags are missing.";
110
111     @GuardedBy("this")
112     private final Map<S, PCEPRequest> requests = new HashMap<>();
113
114     @GuardedBy("this")
115     private final Map<String, ReportedLsp> lspData = new HashMap<>();
116
117     @GuardedBy("this")
118     protected final Map<L, String> lsps = new HashMap<>();
119
120     private final ServerSessionManager serverSessionManager;
121     private InstanceIdentifier<PathComputationClient> pccIdentifier;
122     private TopologyNodeState nodeState;
123     private boolean synced = false;
124     private PCEPSession session;
125     private SyncOptimization syncOptimization;
126     private boolean triggeredResyncInProcess;
127
128     private ListenerStateRuntimeRegistration registration;
129     private final SessionListenerState listenerState;
130
131     protected AbstractTopologySessionListener(final ServerSessionManager serverSessionManager) {
132         this.serverSessionManager = Preconditions.checkNotNull(serverSessionManager);
133         this.listenerState = new SessionListenerState();
134     }
135
136     @Override
137     public final synchronized void onSessionUp(final PCEPSession session) {
138         /*
139          * The session went up. Look up the router in Inventory model,
140          * create it if it is not there (marking that fact for later
141          * deletion), and mark it as synchronizing. Also create it in
142          * the topology model, with empty LSP list.
143          */
144         final InetAddress peerAddress = session.getRemoteAddress();
145
146         syncOptimization  = new SyncOptimization(session);
147
148         final TopologyNodeState state = this.serverSessionManager.takeNodeState(peerAddress, this, isLspDbRetreived());
149
150         this.session = session;
151         this.nodeState = state;
152
153         LOG.trace("Peer {} resolved to topology node {}", peerAddress, state.getNodeId());
154
155         // Our augmentation in the topology node
156         final PathComputationClientBuilder pccBuilder = new PathComputationClientBuilder();
157
158         onSessionUp(session, pccBuilder);
159         this.synced = isSynchronized();
160
161         pccBuilder.setIpAddress(IpAddressBuilder.getDefaultInstance(peerAddress.getHostAddress()));
162         final InstanceIdentifier<Node1> topologyAugment = state.getNodeId().augmentation(Node1.class);
163         this.pccIdentifier = topologyAugment.child(PathComputationClient.class);
164         final Node initialNodeState = state.getInitialNodeState();
165         final boolean isNodePresent = isLspDbRetreived() && initialNodeState != null;
166         if (isNodePresent) {
167             loadLspData(initialNodeState, lspData, lsps, isIncrementalSynchro());
168             pccBuilder.setReportedLsp(initialNodeState.getAugmentation(Node1.class).getPathComputationClient().getReportedLsp());
169         }
170         writeNode(pccBuilder, state, topologyAugment);
171         this.listenerState.init(session);
172         if (this.serverSessionManager.getRuntimeRootRegistration().isPresent()) {
173             this.registration = this.serverSessionManager.getRuntimeRootRegistration().get().register(this);
174         }
175         LOG.info("Session with {} attached to topology node {}", session.getRemoteAddress(), state.getNodeId());
176     }
177
178     private void writeNode(final PathComputationClientBuilder pccBuilder, final TopologyNodeState state,
179             final InstanceIdentifier<Node1> topologyAugment) {
180         final Node1 ta = new Node1Builder().setPathComputationClient(pccBuilder.build()).build();
181
182         final ReadWriteTransaction trans = state.rwTransaction();
183         trans.put(LogicalDatastoreType.OPERATIONAL, topologyAugment, ta);
184         LOG.trace("Peer data {} set to {}", topologyAugment, ta);
185
186         // All set, commit the modifications
187         Futures.addCallback(trans.submit(), new FutureCallback<Void>() {
188             @Override
189             public void onSuccess(final Void result) {
190                 LOG.trace("Internal state for session {} updated successfully", session);
191             }
192
193             @Override
194             public void onFailure(final Throwable t) {
195                 LOG.error("Failed to update internal state for session {}, terminating it", session, t);
196                 session.close(TerminationReason.UNKNOWN);
197             }
198         });
199     }
200
201     protected void updatePccState(final PccSyncState pccSyncState) {
202         final MessageContext ctx = new MessageContext(this.nodeState.beginTransaction());
203         updatePccNode(ctx, new PathComputationClientBuilder().setStateSync(pccSyncState).build());
204         if (pccSyncState != PccSyncState.Synchronized) {
205             this.synced = false;
206             this.triggeredResyncInProcess = true;
207         }
208         // All set, commit the modifications
209         Futures.addCallback(ctx.trans.submit(), new FutureCallback<Void>() {
210             @Override
211             public void onSuccess(final Void result) {
212                 LOG.trace("Internal state for session {} updated successfully", session);
213             }
214
215             @Override
216             public void onFailure(final Throwable t) {
217                 LOG.error("Failed to update internal state for session {}", session, t);
218                 session.close(TerminationReason.UNKNOWN);
219             }
220         });
221     }
222
223     protected boolean isTriggeredSyncInProcess() {
224         return this.triggeredResyncInProcess;
225     }
226
227     @GuardedBy("this")
228     private void tearDown(final PCEPSession session) {
229         this.serverSessionManager.releaseNodeState(this.nodeState, session, isLspDbPersisted());
230         this.nodeState = null;
231         this.session = null;
232         this.syncOptimization = null;
233         unregister();
234
235         // Clear all requests we know about
236         for (final Entry<S, PCEPRequest> e : this.requests.entrySet()) {
237             final PCEPRequest r = e.getValue();
238             switch (r.getState()) {
239             case DONE:
240                 // Done is done, nothing to do
241                 break;
242             case UNACKED:
243                 // Peer has not acked: results in failure
244                 LOG.info("Request {} was incomplete when session went down, failing the instruction", e.getKey());
245                 r.done(OperationResults.NOACK);
246                 break;
247             case UNSENT:
248                 // Peer has not been sent to the peer: results in cancellation
249                 LOG.debug("Request {} was not sent when session went down, cancelling the instruction", e.getKey());
250                 r.done(OperationResults.UNSENT);
251                 break;
252             default:
253                 break;
254             }
255         }
256         this.requests.clear();
257     }
258
259     @Override
260     public final synchronized void onSessionDown(final PCEPSession session, final Exception e) {
261         LOG.warn("Session {} went down unexpectedly", session, e);
262         tearDown(session);
263     }
264
265     @Override
266     public final synchronized void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason reason) {
267         LOG.info("Session {} terminated by peer with reason {}", session, reason);
268         tearDown(session);
269     }
270
271     @Override
272     public final synchronized void onMessage(final PCEPSession session, final Message message) {
273         final MessageContext ctx = new MessageContext(this.nodeState.beginTransaction());
274
275         if (onMessage(ctx, message)) {
276             LOG.info("Unhandled message {} on session {}", message, session);
277             return;
278         }
279
280         Futures.addCallback(ctx.trans.submit(), new FutureCallback<Void>() {
281             @Override
282             public void onSuccess(final Void result) {
283                 LOG.trace("Internal state for session {} updated successfully", session);
284                 ctx.notifyRequests();
285             }
286
287             @Override
288             public void onFailure(final Throwable t) {
289                 LOG.error("Failed to update internal state for session {}, closing it", session, t);
290                 ctx.notifyRequests();
291                 session.close(TerminationReason.UNKNOWN);
292             }
293         });
294     }
295
296     @Override
297     public void close() {
298         unregister();
299         if (this.session != null) {
300             this.session.close(TerminationReason.UNKNOWN);
301         }
302     }
303
304     private synchronized void unregister() {
305         if (this.registration != null) {
306             this.registration.close();
307             this.registration = null;
308         }
309     }
310
311     protected final synchronized PCEPRequest removeRequest(final S id) {
312         final PCEPRequest ret = this.requests.remove(id);
313         if (ret != null) {
314             this.listenerState.processRequestStats(ret.getElapsedMillis());
315         }
316         LOG.trace("Removed request {} object {}", id, ret);
317         return ret;
318     }
319
320     protected final synchronized ListenableFuture<OperationResult> sendMessage(final Message message, final S requestId,
321         final Metadata metadata) {
322         final io.netty.util.concurrent.Future<Void> f = this.session.sendMessage(message);
323         this.listenerState.updateStatefulSentMsg(message);
324         final PCEPRequest req = new PCEPRequest(metadata);
325         this.requests.put(requestId, req);
326         final int rpcTimeout = serverSessionManager.getRpcTimeout();
327         LOG.trace("RPC response timeout value is {} seconds", rpcTimeout);
328         if (rpcTimeout > 0) {
329             setupTimeoutHandler(requestId, req, rpcTimeout);
330         }
331
332         f.addListener(new FutureListener<Void>() {
333             @Override
334             public void operationComplete(final io.netty.util.concurrent.Future<Void> future) {
335                 if (!future.isSuccess()) {
336                     synchronized (AbstractTopologySessionListener.this) {
337                         AbstractTopologySessionListener.this.requests.remove(requestId);
338                     }
339                     req.done(OperationResults.UNSENT);
340                     LOG.info("Failed to send request {}, instruction cancelled", requestId, future.cause());
341                 } else {
342                     req.sent();
343                     LOG.trace("Request {} sent to peer (object {})", requestId, req);
344                 }
345             }
346         });
347
348         return req.getFuture();
349     }
350
351     private void setupTimeoutHandler(final S requestId, final PCEPRequest req, final int timeout) {
352         final Timer timer = req.getTimer();
353         timer.schedule(new TimerTask() {
354             @Override
355             public void run() {
356                 synchronized (AbstractTopologySessionListener.this) {
357                     AbstractTopologySessionListener.this.requests.remove(requestId);
358                 }
359                 req.done();
360                 LOG.info("Request {} timed-out waiting for response", requestId);
361             }
362         }, TimeUnit.SECONDS.toMillis(timeout));
363         LOG.trace("Set up response timeout handler for request {}", requestId);
364     }
365
366     /**
367      * Update an LSP in the data store
368      *
369      * @param ctx Message context
370      * @param id Revision-specific LSP identifier
371      * @param lspName LSP name
372      * @param rlb Reported LSP builder
373      * @param solicited True if the update was solicited
374      * @param remove True if this is an LSP path removal
375      */
376     protected final synchronized void updateLsp(final MessageContext ctx, final L id, final String lspName,
377         final ReportedLspBuilder rlb, final boolean solicited, final boolean remove) {
378
379         final String name;
380         if (lspName == null) {
381             name = this.lsps.get(id);
382             if (name == null) {
383                 LOG.error("PLSPID {} seen for the first time, not reporting the LSP", id);
384                 return;
385             }
386         } else {
387             name = lspName;
388         }
389
390         LOG.debug("Saved LSP {} with name {}", id, name);
391         this.lsps.put(id, name);
392
393
394         final ReportedLsp previous = this.lspData.get(name);
395         // if no previous report about the lsp exist, just proceed
396         if (previous != null) {
397             final List<Path> updatedPaths = makeBeforeBreak(rlb, previous, name, remove);
398             // if all paths or the last path were deleted, delete whole tunnel
399             if (updatedPaths == null || updatedPaths.isEmpty()) {
400                 LOG.debug("All paths were removed, removing LSP with {}.", id);
401                 removeLsp(ctx, id);
402                 return;
403             }
404             rlb.setPath(updatedPaths);
405         }
406         rlb.setKey(new ReportedLspKey(name));
407         rlb.setName(name);
408
409         // If this is an unsolicited update. We need to make sure we retain the metadata already present
410         if (solicited) {
411             this.nodeState.setLspMetadata(name, rlb.getMetadata());
412         } else {
413             rlb.setMetadata(this.nodeState.getLspMetadata(name));
414         }
415
416         final ReportedLsp rl = rlb.build();
417         ctx.trans.put(LogicalDatastoreType.OPERATIONAL, this.pccIdentifier.child(ReportedLsp.class, rlb.getKey()), rl);
418         LOG.debug("LSP {} updated to MD-SAL", name);
419
420         this.lspData.put(name, rl);
421     }
422
423     private List<Path> makeBeforeBreak(final ReportedLspBuilder rlb, final ReportedLsp previous, final String name, final boolean remove) {
424         // just one path should be reported
425         Preconditions.checkState(rlb.getPath().size() == 1);
426         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId reportedLspId = rlb.getPath().get(0).getLspId();
427         final List<Path> updatedPaths;
428         //lspId = 0 and remove = false -> tunnel is down, still exists but no path is signaled
429         //remove existing tunnel's paths now, as explicit path remove will not come
430         if (!remove && reportedLspId.getValue() == 0) {
431             updatedPaths = new ArrayList<>();
432             LOG.debug("Remove previous paths {} to this lsp name {}", previous.getPath(), name);
433         } else {
434             // check previous report for existing paths
435             updatedPaths = new ArrayList<>(previous.getPath());
436             LOG.debug("Found previous paths {} to this lsp name {}", updatedPaths, name);
437             for (final Path path : previous.getPath()) {
438                 //we found reported path in previous reports
439                 if (path.getLspId().getValue() == 0 || path.getLspId().equals(reportedLspId)) {
440                     LOG.debug("Match on lsp-id {}", path.getLspId().getValue() );
441                     // path that was reported previously and does have the same lsp-id, path will be updated
442                     final boolean r = updatedPaths.remove(path);
443                     LOG.trace("Request removed? {}", r);
444                 }
445             }
446         }
447         // if the path does not exist in previous report, add it to path list, it's a new ERO
448         // only one path will be added
449         //lspId is 0 means confirmation message that shouldn't be added (because we have no means of deleting it later)
450         LOG.trace("Adding new path {} to {}", rlb.getPath(), updatedPaths);
451         updatedPaths.addAll(rlb.getPath());
452         if (remove) {
453             if (reportedLspId.getValue() == 0) {
454                 // if lsp-id also 0, remove all paths
455                 LOG.debug("Removing all paths.");
456                 updatedPaths.clear();
457             } else {
458                 // path is marked to be removed
459                 LOG.debug("Removing path {} from {}", rlb.getPath(), updatedPaths);
460                 final boolean r = updatedPaths.removeAll(rlb.getPath());
461                 LOG.trace("Request removed? {}", r);
462             }
463         }
464         LOG.debug("Setting new paths {} to lsp {}", updatedPaths, name);
465         return updatedPaths;
466     }
467
468     /**
469      * Indicate that the peer has completed state synchronization.
470      *
471      * @param ctx Message context
472      */
473     protected final synchronized void stateSynchronizationAchieved(final MessageContext ctx) {
474         if (this.synced) {
475             LOG.debug("State synchronization achieved while synchronized, not updating state");
476             return;
477         }
478
479         // Update synchronization flag
480         this.synced = true;
481         if(this.triggeredResyncInProcess) {
482             this.triggeredResyncInProcess = false;
483         }
484         updatePccNode(ctx, new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).build());
485
486         // The node has completed synchronization, cleanup metadata no longer reported back
487         this.nodeState.cleanupExcept(this.lsps.values());
488         LOG.debug("Session {} achieved synchronized state", this.session);
489     }
490
491     protected final synchronized void updatePccNode(final MessageContext ctx, final PathComputationClient pcc) {
492         ctx.trans.merge(LogicalDatastoreType.OPERATIONAL, this.pccIdentifier, pcc);
493     }
494
495     protected final InstanceIdentifier<ReportedLsp> lspIdentifier(final String name) {
496         return this.pccIdentifier.child(ReportedLsp.class, new ReportedLspKey(name));
497     }
498
499     protected final InstanceIdentifier<PathComputationClient> getPccIdentifier() {
500         return this.pccIdentifier;
501     }
502
503     /**
504      * Remove LSP from the database.
505      *
506      * @param ctx Message Context
507      * @param id Revision-specific LSP identifier
508      */
509     protected final synchronized void removeLsp(final MessageContext ctx, final L id) {
510         final String name = this.lsps.remove(id);
511         LOG.debug("LSP {} removed", name);
512         ctx.trans.delete(LogicalDatastoreType.OPERATIONAL, lspIdentifier(name));
513         this.lspData.remove(name);
514     }
515
516     protected abstract void onSessionUp(PCEPSession session, PathComputationClientBuilder pccBuilder);
517
518     /**
519      * Perform revision-specific message processing when a message arrives.
520      *
521      * @param ctx Message processing context
522      * @param message Protocol message
523      * @return True if the message type is not handle.
524      */
525     protected abstract boolean onMessage(MessageContext ctx, Message message);
526
527     protected final String lookupLspName(final L id) {
528         Preconditions.checkNotNull(id, "ID parameter null.");
529         return this.lsps.get(id);
530     }
531
532     /**
533      * Reads operational data on this node. Doesn't attempt to read the data,
534      * if the node does not exist. In this case returns null.
535      *
536      * @param id InstanceIdentifier of the node
537      * @return null if the node does not exists, or operational data
538      */
539     protected final synchronized <T extends DataObject> ListenableFuture<Optional<T>> readOperationalData(final InstanceIdentifier<T> id) {
540         if (this.nodeState == null) {
541             return null;
542         }
543         return this.nodeState.readOperationalData(id);
544     }
545
546     protected abstract Object validateReportedLsp(final Optional<ReportedLsp> rep, final LspId input);
547
548     protected abstract void loadLspData(final Node node, final Map<String, ReportedLsp> lspData, final Map<L, String> lsps, final boolean incrementalSynchro);
549
550     protected final boolean isLspDbPersisted() {
551         if (syncOptimization != null) {
552             return syncOptimization.isSyncAvoidanceEnabled();
553         }
554         return false;
555     }
556
557     protected final boolean isLspDbRetreived() {
558         if (syncOptimization != null) {
559             return syncOptimization.isDbVersionPresent();
560         }
561         return false;
562     }
563
564     /**
565      * Is Incremental synchronization if LSP-DB-VERSION are included,
566      * LSP-DB-VERSION TLV values doesnt match, and  LSP-SYNC-CAPABILITY is enabled
567      * @return
568      */
569     protected final boolean isIncrementalSynchro() {
570         if (syncOptimization != null) {
571             return syncOptimization.isSyncAvoidanceEnabled() && syncOptimization.isDeltaSyncEnabled();
572         }
573         return false;
574     }
575
576     protected final boolean isTriggeredInitialSynchro() {
577         if (syncOptimization != null) {
578             return syncOptimization.isTriggeredInitSyncEnabled();
579         }
580         return false;
581     }
582
583     protected final boolean isTriggeredReSyncEnabled() {
584         if (syncOptimization != null) {
585             return syncOptimization.isTriggeredReSyncEnabled();
586         }
587         return false;
588     }
589
590     protected final boolean isSynchronized() {
591         if (syncOptimization != null) {
592             return syncOptimization.doesLspDbMatch();
593         }
594         return false;
595     }
596
597     protected SessionListenerState getSessionListenerState() {
598         return this.listenerState;
599     }
600
601     @Override
602     public Integer getDelegatedLspsCount() {
603         return this.lsps.size();
604     }
605
606     @Override
607     public Boolean getSynchronized() {
608         return this.synced;
609     }
610
611     @Override
612     public StatefulMessages getStatefulMessages() {
613         return this.listenerState.getStatefulMessages();
614     }
615
616     @Override
617     public synchronized void resetStats() {
618         this.listenerState.resetStats(this.session);
619     }
620
621     @Override
622     public ReplyTime getReplyTime() {
623         return this.listenerState.getReplyTime();
624     }
625
626     @Override
627     public PeerCapabilities getPeerCapabilities() {
628         return this.listenerState.getPeerCapabilities();
629     }
630
631     @Override
632     public void tearDownSession() {
633         this.close();
634     }
635
636     @Override
637     public synchronized SessionState getSessionState() {
638         return this.listenerState.getSessionState(this.session);
639     }
640
641     @Override
642     public synchronized String getPeerId() {
643         return this.session.getPeerPref().getIpAddress();
644     }
645 }