2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.bgpcep.pcep.topology.provider;
10 import io.netty.util.concurrent.EventExecutor;
11 import io.netty.util.concurrent.FutureListener;
12 import io.netty.util.concurrent.GlobalEventExecutor;
13 import io.netty.util.concurrent.Promise;
15 import java.net.InetAddress;
16 import java.util.HashMap;
18 import java.util.Map.Entry;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.Future;
22 import javax.annotation.concurrent.GuardedBy;
24 import org.opendaylight.bgpcep.programming.spi.ExecutionResult;
25 import org.opendaylight.bgpcep.programming.spi.InstructionExecutor;
26 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
27 import org.opendaylight.bgpcep.programming.spi.SuccessfulRpcResult;
28 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
29 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
30 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
31 import org.opendaylight.protocol.framework.SessionListenerFactory;
32 import org.opendaylight.protocol.pcep.PCEPSession;
33 import org.opendaylight.protocol.pcep.PCEPSessionListener;
34 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
35 import org.opendaylight.protocol.pcep.TerminationReason;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcinitiateBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcupdBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.MessageHeader;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrptMessage;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PlspId;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpObject.Flags;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.TlvsBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.PcinitiateMessageBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.RequestsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.LspBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.SrpBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.Reports;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.reports.Lsp;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.reports.Srp;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.PcupdMessageBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.UpdatesBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.updates.PathBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.Stateful;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.symbolic.path.name.tlv.SymbolicPathName;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.symbolic.path.name.tlv.SymbolicPathNameBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatus;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.status.changed.Details;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.FailureBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.failure.Failure;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutput;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutputBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.NetworkTopologyPcepService;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1Builder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.PccSyncState;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspOutput;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspOutputBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutput;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutputBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClientBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsps;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLspsKey;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.StatefulTlvBuilder;
84 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
85 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
87 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
88 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
89 import org.opendaylight.yangtools.yang.binding.DataContainer;
90 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
91 import org.opendaylight.yangtools.yang.common.RpcResult;
92 import org.slf4j.Logger;
93 import org.slf4j.LoggerFactory;
95 import com.google.common.base.Preconditions;
96 import com.google.common.collect.ImmutableList;
101 final class ServerSessionManager implements SessionListenerFactory<PCEPSessionListener>, NetworkTopologyPcepService {
102 private static String createNodeId(final InetAddress addr) {
103 return "pcc://" + addr.getHostAddress();
106 private final class SessionListener implements PCEPSessionListener {
107 private final Map<SrpIdNumber, Promise<ExecutionResult<Details>>> waitingRequests = new HashMap<>();
108 private final Map<SrpIdNumber, Promise<ExecutionResult<Details>>> sendingRequests = new HashMap<>();
109 private final Map<PlspId, SymbolicPathName> lsps = new HashMap<>();
110 private PathComputationClientBuilder pccBuilder;
111 private InstanceIdentifier<Node1> topologyAugment;
112 private InstanceIdentifier<Node> topologyNode;
113 private Node1Builder topologyAugmentBuilder;
114 private boolean ownsTopology = false;
115 private boolean synced = false;
116 private PCEPSession session;
117 private long requestId = 1;
118 private NodeId nodeId;
120 final Node topologyNode(final DataModificationTransaction trans, final InetAddress address) {
121 final String pccId = createNodeId(address);
122 final Topology topo = (Topology)trans.readOperationalData(topology);
124 for (final Node n : topo.getNode()) {
125 LOG.debug("Matching topology node {} to id {}", n, pccId);
126 if (n.getNodeId().getValue().equals(pccId)) {
132 * We failed to find a matching node. Let's create a dynamic one
133 * and note that we are the owner (so we clean it up afterwards).
135 final NodeId id = new NodeId(pccId);
136 final NodeKey nk = new NodeKey(id);
137 final InstanceIdentifier<Node> nti = InstanceIdentifier.builder(ServerSessionManager.this.topology).node(Node.class, nk).toInstance();
139 final Node ret = new NodeBuilder().setKey(nk).setNodeId(id).build();
141 trans.putRuntimeData(nti, ret);
142 this.ownsTopology = true;
143 this.topologyNode = nti;
149 public synchronized void onSessionUp(final PCEPSession session) {
151 * The session went up. Look up the router in Inventory model,
152 * create it if it is not there (marking that fact for later
153 * deletion), and mark it as synchronizing. Also create it in
154 * the topology model, with empty LSP list.
156 final InetAddress peerAddress = session.getRemoteAddress();
157 final DataModificationTransaction trans = ServerSessionManager.this.dataProvider.beginTransaction();
159 final Node topoNode = topologyNode(trans, peerAddress);
160 LOG.debug("Peer {} resolved to topology node {}", peerAddress, topoNode);
162 // Our augmentation in the topology node
163 this.pccBuilder = new PathComputationClientBuilder();
165 final Tlvs tlvs = session.getRemoteTlvs();
166 final Stateful stateful = tlvs.getStateful();
167 if (stateful != null) {
168 this.pccBuilder.setStatefulTlv(new StatefulTlvBuilder(tlvs).build());
169 this.pccBuilder.setStateSync(PccSyncState.InitialResync);
172 topologyAugmentBuilder = new Node1Builder().setPathComputationClient(pccBuilder.build());
173 topologyAugment = InstanceIdentifier.builder(topologyNode).node(Node1.class).toInstance();
174 trans.putRuntimeData(topologyAugment, topologyAugmentBuilder.build());
176 // All set, commit the modifications
177 final Future<RpcResult<TransactionStatus>> s = trans.commit();
180 * FIXME: once this Future is listenable, attach to it so we can
181 * do cleanup if the commit fails. For now we force a commit.
185 } catch (InterruptedException | ExecutionException e) {
186 LOG.error("Failed to update internal state for session {}, terminating it", session, e);
187 session.close(TerminationReason.Unknown);
191 nodes.put(nodeId, this);
192 this.session = session;
193 LOG.info("Session with {} attached to topology node {}", session.getRemoteAddress(), topoNode.getNodeId());
197 private void tearDown(final PCEPSession session) {
199 nodes.remove(nodeId);
201 final DataModificationTransaction trans = ServerSessionManager.this.dataProvider.beginTransaction();
203 // The session went down. Undo all the Topology changes we have done.
204 trans.removeRuntimeData(topologyAugment);
206 trans.removeRuntimeData(topologyNode);
210 * FIXME: once this Future is listenable, attach to it so we can
211 * do cleanup if the commit fails. For now we force a commit.
213 final Future<RpcResult<TransactionStatus>> s = trans.commit();
216 } catch (InterruptedException | ExecutionException e) {
217 LOG.error("Failed to cleanup internal state for session {}", session, e);
220 // Clear all requests which have not been sent to the peer: they result in cancellation
221 for (Entry<SrpIdNumber, Promise<ExecutionResult<Details>>> e : sendingRequests.entrySet()) {
222 LOG.debug("Request {} was not sent when session went down, cancelling the instruction", e.getKey());
223 e.getValue().setSuccess(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
225 sendingRequests.clear();
227 // CLear all requests which have not been acked by the peer: they result in failure
228 for (Entry<SrpIdNumber, Promise<ExecutionResult<Details>>> e : waitingRequests.entrySet()) {
229 LOG.info("Request {} was incomplete when session went down, failing the instruction", e.getKey());
230 e.getValue().setSuccess(new ExecutionResult<Details>(InstructionStatus.Failed, null));
232 waitingRequests.clear();
236 public synchronized void onSessionDown(final PCEPSession session, final Exception e) {
237 LOG.warn("Session {} went down unexpectedly", e);
242 public synchronized void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason reason) {
243 LOG.info("Session {} terminated by peer with reason {}", session, reason);
247 private InstanceIdentifier<ReportedLsps> lspIdentifier(final SymbolicPathName name) {
248 return InstanceIdentifier.builder(topologyAugment).
249 node(ReportedLsps.class, new ReportedLspsKey(name.getPathName())).toInstance();
253 public synchronized void onMessage(final PCEPSession session, final Message message) {
254 if (!(message instanceof PcrptMessage)) {
255 LOG.info("Unhandled message {} on session {}", message, session);
256 session.sendMessage(unhandledMessageError);
259 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.PcrptMessage rpt = ((PcrptMessage) message).getPcrptMessage();
261 final DataModificationTransaction trans = ServerSessionManager.this.dataProvider.beginTransaction();
263 for (final Reports r : rpt.getReports()) {
264 final Lsp lsp = r.getLsp();
266 if (lsp.isSync() && !this.synced) {
267 // Update synchronization flag
269 topologyAugmentBuilder.setPathComputationClient(pccBuilder.setStateSync(PccSyncState.Synchronized).build());
270 trans.putRuntimeData(topologyAugment, topologyAugmentBuilder.build());
271 LOG.debug("Session {} achieved synchronized state", session);
274 final Srp srp = r.getSrp();
276 final SrpIdNumber id = srp.getOperationId();
277 if (id.getValue() != 0) {
278 switch (lsp.getOperational()) {
282 final Promise<ExecutionResult<Details>> p = waitingRequests.remove(id);
284 LOG.debug("Request {} resulted in LSP operational state {}", id, lsp.getOperational());
285 p.setSuccess(new ExecutionResult<Details>(InstructionStatus.Successful, null));
287 LOG.warn("Request ID {} not found in outstanding DB", id);
292 // These are transitive states, so
298 final PlspId id = lsp.getPlspId();
299 if (lsp.isRemove()) {
300 final SymbolicPathName name = this.lsps.remove(id);
302 trans.removeRuntimeData(lspIdentifier(name));
305 LOG.debug("LSP {} removed", lsp);
307 if (!this.lsps.containsKey(id)) {
308 LOG.debug("PLSPID {} not known yet, looking for a symbolic name", id);
310 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.Tlvs tlvs = r.getLsp().getTlvs();
311 final SymbolicPathName name = tlvs.getSymbolicPathName();
313 LOG.error("PLSPID {} seen for the first time, not reporting the LSP");
314 // TODO: what should we do here?
319 final SymbolicPathName name = this.lsps.get(id);
320 trans.putRuntimeData(lspIdentifier(name), lsp);
322 LOG.debug("LSP {} updated");
327 * FIXME: once this Future is listenable, attach to it so we can
328 * do cleanup if the commit fails. For now we force a commit.
330 final Future<RpcResult<TransactionStatus>> s = trans.commit();
333 } catch (InterruptedException | ExecutionException e) {
334 LOG.error("Failed to update internal state for session {}, closing it", session, e);
335 session.close(TerminationReason.Unknown);
339 private synchronized SrpIdNumber nextRequest() {
340 return new SrpIdNumber(requestId++);
343 private synchronized void messageSendingComplete(final SrpIdNumber requestId, final io.netty.util.concurrent.Future<Void> future) {
344 final Promise<ExecutionResult<Details>> promise = sendingRequests.remove(requestId);
346 if (future.isSuccess()) {
347 waitingRequests.put(requestId, promise);
349 LOG.info("Failed to send request {}, instruction cancelled", requestId, future.cause());
350 promise.setSuccess(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
354 private synchronized io.netty.util.concurrent.Future<ExecutionResult<Details>> sendMessage(final Message message, final SrpIdNumber requestId) {
355 final io.netty.util.concurrent.Future<Void> f = session.sendMessage(message);
356 final Promise<ExecutionResult<Details>> ret = exec.newPromise();
358 sendingRequests.put(requestId, ret);
360 f.addListener(new FutureListener<Void>() {
362 public void operationComplete(final io.netty.util.concurrent.Future<Void> future) {
363 messageSendingComplete(requestId, future);
371 private static final Logger LOG = LoggerFactory.getLogger(ServerSessionManager.class);
372 private static final Pcerr unhandledMessageError = new PcerrBuilder().setPcerrMessage(
373 new PcerrMessageBuilder().setErrorType(null).build()).build();
374 private static final MessageHeader messageHeader = new MessageHeader() {
375 private final ProtocolVersion version = new ProtocolVersion((short)1);
378 public Class<? extends DataContainer> getImplementedInterface() {
379 return MessageHeader.class;
383 public ProtocolVersion getVersion() {
387 private static final EventExecutor exec = GlobalEventExecutor.INSTANCE;
388 private final Map<NodeId, SessionListener> nodes = new HashMap<>();
389 private final InstanceIdentifier<Topology> topology;
390 private final DataProviderService dataProvider;
391 private final InstructionScheduler scheduler;
393 public ServerSessionManager(final InstructionScheduler scheduler, final DataProviderService dataProvider,
394 final InstanceIdentifier<Topology> topology) {
395 this.dataProvider = Preconditions.checkNotNull(dataProvider);
396 this.topology = Preconditions.checkNotNull(topology);
397 this.scheduler = Preconditions.checkNotNull(scheduler);
401 public PCEPSessionListener getSessionListener() {
402 return new SessionListener();
405 private synchronized io.netty.util.concurrent.Future<ExecutionResult<Details>> realAddLsp(final AddLspInput input) {
406 // Get the listener corresponding to the node
407 final SessionListener l = nodes.get(input.getNode());
409 LOG.debug("Session for node {} not found", input.getNode());
410 return exec.newSucceededFuture(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
413 final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).node(ReportedLsps.class, new ReportedLspsKey(input.getName())).toInstance();
414 if (dataProvider.readOperationalData(lsp) != null) {
415 LOG.debug("Node {} already contains lsp {} at {}", input.getNode(), input.getName(), lsp);
416 return exec.newSucceededFuture(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
419 final RequestsBuilder rb = new RequestsBuilder(input.getArguments());
420 rb.setSrp(new SrpBuilder().setOperationId(l.nextRequest()).setProcessingRule(Boolean.TRUE).build());
422 new LspBuilder().setAdministrative(input.getArguments().isAdministrative()).setTlvs(
423 new TlvsBuilder().setSymbolicPathName(
424 new SymbolicPathNameBuilder().setPathName(input.getName()).build()).build()).build());
426 final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(messageHeader);
427 ib.setRequests(ImmutableList.of(rb.build()));
429 return l.sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(), rb.getSrp().getOperationId());
432 private synchronized io.netty.util.concurrent.Future<ExecutionResult<Details>> realRemoveLsp(final RemoveLspInput input) {
433 // Get the listener corresponding to the node
434 final SessionListener l = nodes.get(input.getNode());
436 LOG.debug("Session for node {} not found", input.getNode());
437 return exec.newSucceededFuture(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
440 final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).node(ReportedLsps.class, new ReportedLspsKey(input.getName())).toInstance();
441 final ReportedLsps rep = (ReportedLsps) dataProvider.readOperationalData(lsp);
443 LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
444 return exec.newSucceededFuture(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
447 final RequestsBuilder rb = new RequestsBuilder();
448 rb.setSrp(new SrpBuilder().setOperationId(l.nextRequest()).setProcessingRule(Boolean.TRUE).setFlags(new Flags(Boolean.TRUE)).build());
449 rb.setLsp(new LspBuilder().setRemove(Boolean.TRUE).setPlspId(rep.getLsp().getPlspId()).setDelegate(Boolean.TRUE).build());
451 final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(messageHeader);
452 ib.setRequests(ImmutableList.of(rb.build()));
453 return l.sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(), rb.getSrp().getOperationId());
456 private synchronized io.netty.util.concurrent.Future<ExecutionResult<Details>> realUpdateLsp(final UpdateLspInput input) {
457 // Get the listener corresponding to the node
458 final SessionListener l = nodes.get(input.getNode());
460 LOG.debug("Session for node {} not found", input.getNode());
461 return exec.newSucceededFuture(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
464 final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).node(ReportedLsps.class, new ReportedLspsKey(input.getName())).toInstance();
465 final ReportedLsps rep = (ReportedLsps) dataProvider.readOperationalData(lsp);
467 LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
468 return exec.newSucceededFuture(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
471 final UpdatesBuilder rb = new UpdatesBuilder();
472 rb.setSrp(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.updates.SrpBuilder().setOperationId(l.nextRequest()).setProcessingRule(Boolean.TRUE).build());
473 rb.setLsp(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.updates.LspBuilder().
474 setPlspId(rep.getLsp().getPlspId()).setDelegate(Boolean.TRUE).build());
475 rb.setPath(new PathBuilder(input.getArguments()).build());
477 final PcupdMessageBuilder ub = new PcupdMessageBuilder(messageHeader);
478 ub.setUpdates(ImmutableList.of(rb.build()));
479 return l.sendMessage(new PcupdBuilder().setPcupdMessage(ub.build()).build(), rb.getSrp().getOperationId());
483 public Future<RpcResult<AddLspOutput>> addLsp(final AddLspInput input) {
484 Preconditions.checkArgument(input.getNode() != null);
485 Preconditions.checkArgument(input.getName() != null);
487 final InstructionExecutor e = new InstructionExecutor() {
489 public io.netty.util.concurrent.Future<ExecutionResult<Details>> execute() {
490 return realAddLsp(input);
494 final Failure f = this.scheduler.submitInstruction(input, e);
495 final AddLspOutputBuilder b = new AddLspOutputBuilder();
497 b.setResult(new FailureBuilder().setFailure(f).build());
500 final RpcResult<AddLspOutput> res = SuccessfulRpcResult.create(b.build());
501 return exec.newSucceededFuture(res);
505 public Future<RpcResult<RemoveLspOutput>> removeLsp(final RemoveLspInput input) {
506 Preconditions.checkArgument(input.getNode() != null);
507 Preconditions.checkArgument(input.getName() != null);
509 final InstructionExecutor e = new InstructionExecutor() {
511 public io.netty.util.concurrent.Future<ExecutionResult<Details>> execute() {
512 return realRemoveLsp(input);
516 final Failure f = this.scheduler.submitInstruction(input, e);
517 final RemoveLspOutputBuilder b = new RemoveLspOutputBuilder();
519 b.setResult(new FailureBuilder().setFailure(f).build());
522 final RpcResult<RemoveLspOutput> res = SuccessfulRpcResult.create(b.build());
523 return exec.newSucceededFuture(res);
527 public Future<RpcResult<UpdateLspOutput>> updateLsp(final UpdateLspInput input) {
528 Preconditions.checkArgument(input.getNode() != null);
529 Preconditions.checkArgument(input.getName() != null);
531 final InstructionExecutor e = new InstructionExecutor() {
533 public io.netty.util.concurrent.Future<ExecutionResult<Details>> execute() {
534 return realUpdateLsp(input);
538 final Failure f = this.scheduler.submitInstruction(input, e);
539 final UpdateLspOutputBuilder b = new UpdateLspOutputBuilder();
541 b.setResult(new FailureBuilder().setFailure(f).build());
544 final RpcResult<UpdateLspOutput> res = SuccessfulRpcResult.create(b.build());
545 return exec.newSucceededFuture(res);