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.lsp.object.TlvsBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.PcinitiateMessageBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.RequestsBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.LspBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.Reports;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.reports.Lsp;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.PcupdMessageBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.UpdatesBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.updates.PathBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.srp.object.Srp;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.srp.object.Srp.Flags;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.srp.object.SrpBuilder;
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(ServerSessionManager.this.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 this.topologyAugmentBuilder = new Node1Builder().setPathComputationClient(this.pccBuilder.build());
173 this.topologyAugment = InstanceIdentifier.builder(this.topologyNode).node(Node1.class).toInstance();
174 trans.putRuntimeData(this.topologyAugment, this.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 ServerSessionManager.this.nodes.put(this.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 ServerSessionManager.this.nodes.remove(this.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(this.topologyAugment);
205 if (this.ownsTopology) {
206 trans.removeRuntimeData(this.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 (final Entry<SrpIdNumber, Promise<ExecutionResult<Details>>> e : this.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 this.sendingRequests.clear();
227 // CLear all requests which have not been acked by the peer: they result in failure
228 for (final Entry<SrpIdNumber, Promise<ExecutionResult<Details>>> e : this.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 this.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(this.topologyAugment).node(ReportedLsps.class, new ReportedLspsKey(name.getPathName())).toInstance();
252 public synchronized void onMessage(final PCEPSession session, final Message message) {
253 if (!(message instanceof PcrptMessage)) {
254 LOG.info("Unhandled message {} on session {}", message, session);
255 session.sendMessage(unhandledMessageError);
258 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.PcrptMessage rpt = ((PcrptMessage) message).getPcrptMessage();
260 final DataModificationTransaction trans = ServerSessionManager.this.dataProvider.beginTransaction();
262 for (final Reports r : rpt.getReports()) {
263 final Lsp lsp = r.getLsp();
265 if (lsp.isSync() && !this.synced) {
266 // Update synchronization flag
268 this.topologyAugmentBuilder.setPathComputationClient(this.pccBuilder.setStateSync(PccSyncState.Synchronized).build());
269 trans.putRuntimeData(this.topologyAugment, this.topologyAugmentBuilder.build());
270 LOG.debug("Session {} achieved synchronized state", session);
273 final Srp srp = r.getSrp();
275 final SrpIdNumber id = srp.getOperationId();
276 if (id.getValue() != 0) {
277 switch (lsp.getOperational()) {
281 final Promise<ExecutionResult<Details>> p = this.waitingRequests.remove(id);
283 LOG.debug("Request {} resulted in LSP operational state {}", id, lsp.getOperational());
284 p.setSuccess(new ExecutionResult<Details>(InstructionStatus.Successful, null));
286 LOG.warn("Request ID {} not found in outstanding DB", id);
291 // These are transitive states, so
297 final PlspId id = lsp.getPlspId();
298 if (lsp.isRemove()) {
299 final SymbolicPathName name = this.lsps.remove(id);
301 trans.removeRuntimeData(lspIdentifier(name));
304 LOG.debug("LSP {} removed", lsp);
306 if (!this.lsps.containsKey(id)) {
307 LOG.debug("PLSPID {} not known yet, looking for a symbolic name", id);
309 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.Tlvs tlvs = r.getLsp().getTlvs();
310 final SymbolicPathName name = tlvs.getSymbolicPathName();
312 LOG.error("PLSPID {} seen for the first time, not reporting the LSP");
313 // TODO: what should we do here?
318 final SymbolicPathName name = this.lsps.get(id);
319 trans.putRuntimeData(lspIdentifier(name), lsp);
321 LOG.debug("LSP {} updated");
326 * FIXME: once this Future is listenable, attach to it so we can
327 * do cleanup if the commit fails. For now we force a commit.
329 final Future<RpcResult<TransactionStatus>> s = trans.commit();
332 } catch (InterruptedException | ExecutionException e) {
333 LOG.error("Failed to update internal state for session {}, closing it", session, e);
334 session.close(TerminationReason.Unknown);
338 private synchronized SrpIdNumber nextRequest() {
339 return new SrpIdNumber(this.requestId++);
342 private synchronized void messageSendingComplete(final SrpIdNumber requestId, final io.netty.util.concurrent.Future<Void> future) {
343 final Promise<ExecutionResult<Details>> promise = this.sendingRequests.remove(requestId);
345 if (future.isSuccess()) {
346 this.waitingRequests.put(requestId, promise);
348 LOG.info("Failed to send request {}, instruction cancelled", requestId, future.cause());
349 promise.setSuccess(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
353 private synchronized io.netty.util.concurrent.Future<ExecutionResult<Details>> sendMessage(final Message message,
354 final SrpIdNumber requestId) {
355 final io.netty.util.concurrent.Future<Void> f = this.session.sendMessage(message);
356 final Promise<ExecutionResult<Details>> ret = exec.newPromise();
358 this.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 = this.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,
414 new ReportedLspsKey(input.getName())).toInstance();
415 if (this.dataProvider.readOperationalData(lsp) != null) {
416 LOG.debug("Node {} already contains lsp {} at {}", input.getNode(), input.getName(), lsp);
417 return exec.newSucceededFuture(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
420 final RequestsBuilder rb = new RequestsBuilder(input.getArguments());
421 rb.setSrp(new SrpBuilder().setOperationId(l.nextRequest()).setProcessingRule(Boolean.TRUE).build());
422 rb.setLsp(new LspBuilder().setAdministrative(input.getArguments().isAdministrative()).setTlvs(
423 new TlvsBuilder().setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(input.getName()).build()).build()).build());
425 final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(messageHeader);
426 ib.setRequests(ImmutableList.of(rb.build()));
428 return l.sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(), rb.getSrp().getOperationId());
431 private synchronized io.netty.util.concurrent.Future<ExecutionResult<Details>> realRemoveLsp(final RemoveLspInput input) {
432 // Get the listener corresponding to the node
433 final SessionListener l = this.nodes.get(input.getNode());
435 LOG.debug("Session for node {} not found", input.getNode());
436 return exec.newSucceededFuture(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
439 final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).node(ReportedLsps.class,
440 new ReportedLspsKey(input.getName())).toInstance();
441 final ReportedLsps rep = (ReportedLsps) this.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 = this.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,
465 new ReportedLspsKey(input.getName())).toInstance();
466 final ReportedLsps rep = (ReportedLsps) this.dataProvider.readOperationalData(lsp);
468 LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
469 return exec.newSucceededFuture(new ExecutionResult<Details>(InstructionStatus.Cancelled, null));
472 final UpdatesBuilder rb = new UpdatesBuilder();
473 rb.setSrp(new SrpBuilder().setOperationId(l.nextRequest()).setProcessingRule(Boolean.TRUE).build());
474 rb.setLsp(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcupd.message.pcupd.message.updates.LspBuilder().setPlspId(
475 rep.getLsp().getPlspId()).setDelegate(Boolean.TRUE).build());
476 rb.setPath(new PathBuilder(input.getArguments()).build());
478 final PcupdMessageBuilder ub = new PcupdMessageBuilder(messageHeader);
479 ub.setUpdates(ImmutableList.of(rb.build()));
480 return l.sendMessage(new PcupdBuilder().setPcupdMessage(ub.build()).build(), rb.getSrp().getOperationId());
484 public Future<RpcResult<AddLspOutput>> addLsp(final AddLspInput input) {
485 Preconditions.checkArgument(input.getNode() != null);
486 Preconditions.checkArgument(input.getName() != null);
488 final InstructionExecutor e = new InstructionExecutor() {
490 public io.netty.util.concurrent.Future<ExecutionResult<Details>> execute() {
491 return realAddLsp(input);
495 final Failure f = this.scheduler.submitInstruction(input, e);
496 final AddLspOutputBuilder b = new AddLspOutputBuilder();
498 b.setResult(new FailureBuilder().setFailure(f).build());
501 final RpcResult<AddLspOutput> res = SuccessfulRpcResult.create(b.build());
502 return exec.newSucceededFuture(res);
506 public Future<RpcResult<RemoveLspOutput>> removeLsp(final RemoveLspInput input) {
507 Preconditions.checkArgument(input.getNode() != null);
508 Preconditions.checkArgument(input.getName() != null);
510 final InstructionExecutor e = new InstructionExecutor() {
512 public io.netty.util.concurrent.Future<ExecutionResult<Details>> execute() {
513 return realRemoveLsp(input);
517 final Failure f = this.scheduler.submitInstruction(input, e);
518 final RemoveLspOutputBuilder b = new RemoveLspOutputBuilder();
520 b.setResult(new FailureBuilder().setFailure(f).build());
523 final RpcResult<RemoveLspOutput> res = SuccessfulRpcResult.create(b.build());
524 return exec.newSucceededFuture(res);
528 public Future<RpcResult<UpdateLspOutput>> updateLsp(final UpdateLspInput input) {
529 Preconditions.checkArgument(input.getNode() != null);
530 Preconditions.checkArgument(input.getName() != null);
532 final InstructionExecutor e = new InstructionExecutor() {
534 public io.netty.util.concurrent.Future<ExecutionResult<Details>> execute() {
535 return realUpdateLsp(input);
539 final Failure f = this.scheduler.submitInstruction(input, e);
540 final UpdateLspOutputBuilder b = new UpdateLspOutputBuilder();
542 b.setResult(new FailureBuilder().setFailure(f).build());
545 final RpcResult<UpdateLspOutput> res = SuccessfulRpcResult.create(b.build());
546 return exec.newSucceededFuture(res);