Revoke delegation sent as Pcinitiate message.
[bgpcep.git] / pcep / topology-provider / src / main / java / org / opendaylight / bgpcep / pcep / topology / provider / Stateful07TopologySessionListener.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.Charsets;
11 import com.google.common.base.Function;
12 import com.google.common.base.Optional;
13 import com.google.common.base.Preconditions;
14 import com.google.common.util.concurrent.AsyncFunction;
15 import com.google.common.util.concurrent.Futures;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import java.net.InetAddress;
18 import java.nio.ByteBuffer;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22 import java.util.concurrent.atomic.AtomicLong;
23 import org.opendaylight.protocol.pcep.PCEPSession;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.PcinitiateBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1Builder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.pcinitiate.message.PcinitiateMessageBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.pcinitiate.message.pcinitiate.message.Requests;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.pcinitiate.message.pcinitiate.message.RequestsBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments1;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments2;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments3;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.OperationalStatus;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Path1;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Path1Builder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PcrptMessage;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PcupdBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PlspId;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SrpIdNumber;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.StatefulTlv1;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.StatefulTlv1Builder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.Lsp;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcerr.pcerr.message.error.type.StatefulCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcerr.pcerr.message.error.type.stateful._case.stateful.Srps;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.Reports;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcupd.message.PcupdMessageBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcupd.message.pcupd.message.UpdatesBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcupd.message.pcupd.message.updates.PathBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.SrpBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.Stateful;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcerrMessage;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspArgs;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspArgs;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspArgs;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClientBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLspBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.StatefulTlvBuilder;
71 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
72 import org.slf4j.Logger;
73 import org.slf4j.LoggerFactory;
74
75 final class Stateful07TopologySessionListener extends AbstractTopologySessionListener<SrpIdNumber, PlspId> {
76     private static final Logger LOG = LoggerFactory.getLogger(Stateful07TopologySessionListener.class);
77     private final AtomicLong requestId = new AtomicLong(1L);
78
79     /**
80      * @param serverSessionManager
81      */
82     Stateful07TopologySessionListener(final ServerSessionManager serverSessionManager) {
83         super(serverSessionManager);
84     }
85
86     @Override
87     protected void onSessionUp(final PCEPSession session, final PathComputationClientBuilder pccBuilder) {
88         final InetAddress peerAddress = session.getRemoteAddress();
89
90         final Tlvs tlvs = session.getRemoteTlvs();
91         if (tlvs != null && tlvs.getAugmentation(Tlvs1.class) != null) {
92             final Stateful stateful = tlvs.getAugmentation(Tlvs1.class).getStateful();
93             if (stateful != null) {
94                 pccBuilder.setReportedLsp(Collections.<ReportedLsp> emptyList());
95                 pccBuilder.setStateSync(PccSyncState.InitialResync);
96                 pccBuilder.setStatefulTlv(new StatefulTlvBuilder().addAugmentation(StatefulTlv1.class,
97                     new StatefulTlv1Builder(tlvs.getAugmentation(Tlvs1.class)).build()).build());
98             } else {
99                 LOG.debug("Peer {} does not advertise stateful TLV", peerAddress);
100             }
101         } else {
102             LOG.debug("Peer {} does not advertise stateful TLV", peerAddress);
103         }
104     }
105
106     @Override
107     protected boolean onMessage(final MessageContext ctx, final Message message) {
108         if (message instanceof PcerrMessage) {
109             final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessage errMsg = ((PcerrMessage) message).getPcerrMessage();
110             if (errMsg.getErrorType() instanceof StatefulCase) {
111                 final StatefulCase stat = (StatefulCase)errMsg.getErrorType();
112                 for (final Srps srps : stat.getStateful().getSrps()) {
113                     final SrpIdNumber id = srps.getSrp().getOperationId();
114                     if (id.getValue() != 0) {
115                         final PCEPRequest req = removeRequest(id);
116                         if (req != null) {
117                             req.done(OperationResults.createFailed(errMsg.getErrors()));
118                         } else {
119                             LOG.warn("Request ID {} not found in outstanding DB", id);
120                         }
121                     }
122                 }
123             } else {
124                 LOG.warn("Unhandled PCErr message {}.", errMsg);
125                 return true;
126             }
127             return false;
128         }
129         if (!(message instanceof PcrptMessage)) {
130             return true;
131         }
132
133         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.PcrptMessage rpt = ((PcrptMessage) message).getPcrptMessage();
134         for (final Reports report : rpt.getReports()) {
135             final Lsp lsp = report.getLsp();
136             final PlspId plspid = lsp.getPlspId();
137
138             if (!lsp.isSync() && (lsp.getPlspId() == null || plspid.getValue() == 0)) {
139                 stateSynchronizationAchieved(ctx);
140                 continue;
141             }
142
143             final ReportedLspBuilder rlb = new ReportedLspBuilder();
144
145             boolean solicited = false;
146
147             final Srp srp = report.getSrp();
148             if (srp != null) {
149                 final SrpIdNumber id = srp.getOperationId();
150                 if (id.getValue() != 0) {
151                     solicited = true;
152
153                     switch (lsp.getOperational()) {
154                     case Active:
155                     case Down:
156                     case Up:
157                         final PCEPRequest req = removeRequest(id);
158                         if (req != null) {
159                             LOG.debug("Request {} resulted in LSP operational state {}", id, lsp.getOperational());
160                             rlb.setMetadata(req.getMetadata());
161                             ctx.resolveRequest(req);
162                         } else {
163                             LOG.warn("Request ID {} not found in outstanding DB", id);
164                         }
165                         break;
166                     case GoingDown:
167                     case GoingUp:
168                         // These are transitive states, so we don't have to do anything, as they will be followed
169                         // up...
170                         break;
171                     }
172                     // if remove flag is set in SRP object, remove the tunnel immediately
173                     if (srp.getAugmentation(Srp1.class) != null) {
174                         final Srp1 initiatedSrp = srp.getAugmentation(Srp1.class);
175                         if (initiatedSrp.isRemove()) {
176                             super.removeLsp(ctx, plspid);
177                             return false;
178                         }
179                     }
180                 }
181             }
182             final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.Tlvs tlvs = report.getLsp().getTlvs();
183             final String name;
184             if (tlvs != null && tlvs.getSymbolicPathName() != null) {
185                 name = Charsets.UTF_8.decode(ByteBuffer.wrap(tlvs.getSymbolicPathName().getPathName().getValue())).toString();
186             } else {
187                 name = null;
188             }
189             LspId lspid = null;
190             if (tlvs != null && tlvs.getLspIdentifiers() != null) {
191                 lspid = tlvs.getLspIdentifiers().getLspId();
192             }
193             final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder();
194             if (report.getPath() != null) {
195                 pb.fieldsFrom(report.getPath());
196             }
197             // LSP is mandatory (if there is none, parser will throw an exception)
198             // this is to ensure a path will be created at any rate
199             pb.addAugmentation(Path1.class, new Path1Builder().setLsp(report.getLsp()).build());
200             pb.setLspId(lspid);
201             rlb.setPath(Collections.singletonList(pb.build()));
202             updateLsp(ctx, plspid, name, rlb, solicited, lsp.isRemove());
203             LOG.debug("LSP {} updated", lsp);
204         }
205         return false;
206     }
207
208     private SrpIdNumber nextRequest() {
209         return new SrpIdNumber(this.requestId.getAndIncrement());
210     }
211
212     @Override
213     public synchronized ListenableFuture<OperationResult> addLsp(final AddLspArgs input) {
214         Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
215         LOG.trace("AddLspArgs {}", input);
216         // Make sure there is no such LSP
217         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
218         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
219
220         return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
221             @Override
222             public ListenableFuture<OperationResult> apply(final Optional<ReportedLsp> rep) {
223                 if (rep.isPresent()) {
224                     LOG.debug("Node {} already contains lsp {} at {}", input.getNode(), input.getName(), lsp);
225                     return OperationResults.UNSENT.future();
226                 }
227
228                 // Build the request
229                 final RequestsBuilder rb = new RequestsBuilder();
230                 final Arguments2 args = input.getArguments().getAugmentation(Arguments2.class);
231                 Preconditions.checkArgument(args != null, "Input is missing operational tag.");
232                 final Lsp inputLsp = args.getLsp();
233                 Preconditions.checkArgument(inputLsp != null, "Reported LSP does not contain LSP object.");
234
235                 rb.fieldsFrom(input.getArguments());
236
237                 final TlvsBuilder tlvsBuilder = new TlvsBuilder();
238                 tlvsBuilder.setSymbolicPathName(
239                     new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(input.getName().getBytes(Charsets.UTF_8))).build());
240                 if (inputLsp.getTlvs() != null) {
241                     tlvsBuilder.setVsTlv(inputLsp.getTlvs().getVsTlv());
242                 }
243
244                 rb.setSrp(new SrpBuilder().setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE).build());
245                 rb.setLsp(new LspBuilder().setAdministrative(inputLsp.isAdministrative()).setDelegate(inputLsp.isDelegate()).setPlspId(
246                     new PlspId(0L)).setTlvs(tlvsBuilder.build()).build());
247
248                 final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(MESSAGE_HEADER);
249                 ib.setRequests(Collections.singletonList(rb.build()));
250
251                 // Send the message
252                 return sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(), rb.getSrp().getOperationId(),
253                     input.getArguments().getMetadata());
254             }
255         });
256     }
257
258     @Override
259     public synchronized ListenableFuture<OperationResult> removeLsp(final RemoveLspArgs input) {
260         Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null, "Mandatory XML tags are missing.");
261         LOG.trace("RemoveLspArgs {}", input);
262         // Make sure the LSP exists, we need it for PLSP-ID
263         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
264         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
265
266         return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
267             @Override
268             public ListenableFuture<OperationResult> apply(final Optional<ReportedLsp> rep) {
269                 if (!rep.isPresent()) {
270                     LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
271                     return OperationResults.UNSENT.future();
272                 }
273
274                 // it doesn't matter how many lsps there are in the path list, we only need delegate & plspid that is the same in each path
275                 final Path1 ra = rep.get().getPath().get(0).getAugmentation(Path1.class);
276                 Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
277                 final Lsp reportedLsp = ra.getLsp();
278                 Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
279
280                 // Build the request and send it
281                 final RequestsBuilder rb = new RequestsBuilder();
282                 rb.setSrp(new SrpBuilder().addAugmentation(Srp1.class, new Srp1Builder().setRemove(Boolean.TRUE).build()).setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE).build());
283                 rb.setLsp(new LspBuilder().setRemove(Boolean.FALSE).setPlspId(reportedLsp.getPlspId()).setDelegate(reportedLsp.isDelegate()).build());
284
285                 final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(MESSAGE_HEADER);
286                 ib.setRequests(Collections.singletonList(rb.build()));
287                 return sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(), rb.getSrp().getOperationId(), null);
288             }
289         });
290     }
291
292     @Override
293     public synchronized ListenableFuture<OperationResult> updateLsp(final UpdateLspArgs input) {
294         Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
295         LOG.trace("UpdateLspArgs {}", input);
296         // Make sure the LSP exists
297         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
298         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
299
300         return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
301             @Override
302             public ListenableFuture<OperationResult> apply(final Optional<ReportedLsp> rep) {
303                 if (!rep.isPresent()) {
304                     LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
305                     return OperationResults.UNSENT.future();
306                 }
307
308                 // it doesn't matter how many lsps there are in the path list, we only need plspid that is the same in each path
309                 final Path1 ra = rep.get().getPath().get(0).getAugmentation(Path1.class);
310                 Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
311                 final Lsp reportedLsp = ra.getLsp();
312                 Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
313
314                 // create mandatory objects
315                 final Srp srp = new SrpBuilder().setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE).build();
316
317                 final Lsp inputLsp = input.getArguments().getAugmentation(Arguments3.class).getLsp();
318                 Lsp lsp = null;
319                 if (inputLsp != null) {
320                     lsp = new LspBuilder().setPlspId(reportedLsp.getPlspId()).setDelegate((inputLsp.isDelegate() != null) ? inputLsp.isDelegate() : false).setTlvs(inputLsp.getTlvs()).setAdministrative((inputLsp.isAdministrative() != null) ? inputLsp.isAdministrative() : false).build();
321                 } else {
322                     lsp = new LspBuilder().setPlspId(reportedLsp.getPlspId()).build();
323                 }
324                 Message msg = null;
325                 // the D bit that was reported decides the type of PCE message sent
326                 Preconditions.checkNotNull(reportedLsp.isDelegate());
327                 if (reportedLsp.isDelegate()) {
328                     // we already have delegation, send update
329                     final UpdatesBuilder rb = new UpdatesBuilder();
330                     rb.setSrp(srp);
331                     rb.setLsp(lsp);
332                     final PathBuilder pb = new PathBuilder();
333                     pb.fieldsFrom(input.getArguments());
334                     rb.setPath(pb.build());
335                     final PcupdMessageBuilder ub = new PcupdMessageBuilder(MESSAGE_HEADER);
336                     ub.setUpdates(Collections.singletonList(rb.build()));
337                     msg = new PcupdBuilder().setPcupdMessage(ub.build()).build();
338                 } else {
339                     // we want to revoke delegation, different type of message
340                     // is sent because of specification by Siva
341                     // this message is also sent, when input delegate bit is set to 0
342                     // generating an error in PCC
343                     final List<Requests> reqs = new ArrayList<>();
344                     reqs.add(new RequestsBuilder().setSrp(srp).setLsp(lsp).build());
345                     final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder();
346                     ib.setRequests(reqs);
347                     msg = new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build();
348                 }
349                 return sendMessage(msg, srp.getOperationId(), input.getArguments().getMetadata());
350             }
351         });
352     }
353
354     @Override
355     public synchronized ListenableFuture<OperationResult> ensureLspOperational(final EnsureLspOperationalInput input) {
356         Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
357         final OperationalStatus op;
358         final Arguments1 aa = input.getArguments().getAugmentation(Arguments1.class);
359         if (aa != null) {
360             op = aa.getOperational();
361         } else {
362             op = null;
363         }
364
365         // Make sure the LSP exists
366         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
367         LOG.debug("Checking if LSP {} has operational state {}", lsp, op);
368         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
369
370         return Futures.transform(f, new Function<Optional<ReportedLsp>, OperationResult>() {
371             @Override
372             public OperationResult apply(final Optional<ReportedLsp> rep) {
373                 if (!rep.isPresent()) {
374                     LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
375                     return OperationResults.UNSENT;
376                 }
377
378                 // check if at least one of the paths has the same status as requested
379                 boolean operational = false;
380                 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path p : rep.get().getPath()) {
381                     final Path1 p1 = p.getAugmentation(Path1.class);
382                     if (p1 == null) {
383                         LOG.warn("Node {} LSP {} does not contain data", input.getNode(), input.getName());
384                         return OperationResults.UNSENT;
385                     }
386                     final Lsp l = p1.getLsp();
387                     if (l.getOperational().equals(op)) {
388                         operational = true;
389                     }
390                 }
391
392                 return operational ? OperationResults.SUCCESS : OperationResults.UNSENT;
393             }
394         });
395     }
396 }