use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp in project bgpcep by opendaylight.
the class PCEPTopologySessionListener method removeLsp.
@Override
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH", justification = "SB does not grok TYPE_USE")
public synchronized ListenableFuture<OperationResult> removeLsp(final RemoveLspArgs input) {
checkArgument(input != null && input.getName() != null && input.getNode() != null, MISSING_XML_TAG);
LOG.trace("RemoveLspArgs {}", input);
// Make sure the LSP exists, we need it for PLSP-ID
final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
return f == null ? OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future() : Futures.transformAsync(f, rep -> {
final Lsp reportedLsp = validateReportedLsp(rep, input);
if (reportedLsp == null) {
return OperationResults.createUnsent(PCEPErrors.UNKNOWN_PLSP_ID).future();
}
final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(MESSAGE_HEADER);
final Requests rb = buildRequest(rep, reportedLsp);
ib.setRequests(Collections.singletonList(rb));
return sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(), rb.getSrp().getOperationId(), null);
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp in project bgpcep by opendaylight.
the class PCEPTopologySessionListener method buildRequest.
private Requests buildRequest(final Optional<ReportedLsp> rep, final Lsp reportedLsp) {
// Build the request and send it
final RequestsBuilder rb = new RequestsBuilder();
final SrpBuilder srpBuilder = new SrpBuilder().addAugmentation(new Srp1Builder().setRemove(Boolean.TRUE).build()).setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE);
final Optional<PathSetupType> maybePST = getPST(rep);
if (maybePST.isPresent()) {
srpBuilder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.srp.object.srp.TlvsBuilder().setPathSetupType(maybePST.get()).build());
}
rb.setSrp(srpBuilder.build());
rb.setLsp(new LspBuilder().setRemove(Boolean.FALSE).setPlspId(reportedLsp.getPlspId()).setDelegate(reportedLsp.getDelegate()).build());
return rb.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp in project bgpcep by opendaylight.
the class PCEPTopologySessionListener method redelegate.
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private ListenableFuture<OperationResult> redelegate(final Lsp reportedLsp, final Srp srp, final Lsp lsp, final UpdateLspArgs input) {
// the D bit that was reported decides the type of PCE message sent
final boolean isDelegate = requireNonNull(reportedLsp.getDelegate());
final Message msg;
if (isDelegate) {
// we already have delegation, send update
final UpdatesBuilder rb = new UpdatesBuilder();
rb.setSrp(srp);
rb.setLsp(lsp);
final PathBuilder pb = new PathBuilder();
pb.fieldsFrom(input.getArguments());
rb.setPath(pb.build());
final PcupdMessageBuilder ub = new PcupdMessageBuilder(MESSAGE_HEADER);
ub.setUpdates(Collections.singletonList(rb.build()));
msg = new PcupdBuilder().setPcupdMessage(ub.build()).build();
} else {
final Lsp1 lspCreateFlag = reportedLsp.augmentation(Lsp1.class);
// we only retake delegation for PCE initiated tunnels
if (lspCreateFlag != null && !lspCreateFlag.getCreate()) {
LOG.warn("Unable to retake delegation of PCC-initiated tunnel: {}", reportedLsp);
return OperationResults.createUnsent(PCEPErrors.UPDATE_REQ_FOR_NON_LSP).future();
}
// we want to revoke delegation, different type of message
// is sent because of specification by Siva
// this message is also sent, when input delegate bit is set to 0
// generating an error in PCC
final List<Requests> reqs = new ArrayList<>();
reqs.add(new RequestsBuilder().setSrp(srp).setLsp(lsp).build());
final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder();
ib.setRequests(reqs);
msg = new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build();
}
return sendMessage(msg, srp.getOperationId(), input.getArguments().getMetadata());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp in project bgpcep by opendaylight.
the class NodeChangedListener method remove.
private void remove(final ReadWriteTransaction trans, final InstanceIdentifier<ReportedLsp> identifier, final ReportedLsp value) throws ExecutionException, InterruptedException {
final InstanceIdentifier<Link> li = linkForLsp(linkIdForLsp(identifier, value));
final Optional<Link> ol = trans.read(LogicalDatastoreType.OPERATIONAL, li).get();
if (!ol.isPresent()) {
return;
}
final Link l = ol.get();
LOG.debug("Removing link {} (was {})", li, l);
trans.delete(LogicalDatastoreType.OPERATIONAL, li);
LOG.debug("Searching for orphan links/nodes");
final Optional<Topology> ot = trans.read(LogicalDatastoreType.OPERATIONAL, this.target).get();
Preconditions.checkState(ot.isPresent());
final Topology topology = ot.get();
final NodeId srcNode = l.getSource().getSourceNode();
final NodeId dstNode = l.getDestination().getDestNode();
final TpId srcTp = l.getSource().getSourceTp();
final TpId dstTp = l.getDestination().getDestTp();
boolean orphSrcNode = true;
boolean orphDstNode = true;
boolean orphDstTp = true;
boolean orphSrcTp = true;
for (final Link lw : topology.nonnullLink().values()) {
LOG.trace("Checking link {}", lw);
final NodeId sn = lw.getSource().getSourceNode();
final NodeId dn = lw.getDestination().getDestNode();
final TpId st = lw.getSource().getSourceTp();
final TpId dt = lw.getDestination().getDestTp();
// Source node checks
if (srcNode.equals(sn)) {
if (orphSrcNode) {
LOG.debug("Node {} held by source of link {}", srcNode, lw);
orphSrcNode = false;
}
if (orphSrcTp && srcTp.equals(st)) {
LOG.debug("TP {} held by source of link {}", srcTp, lw);
orphSrcTp = false;
}
}
if (srcNode.equals(dn)) {
if (orphSrcNode) {
LOG.debug("Node {} held by destination of link {}", srcNode, lw);
orphSrcNode = false;
}
if (orphSrcTp && srcTp.equals(dt)) {
LOG.debug("TP {} held by destination of link {}", srcTp, lw);
orphSrcTp = false;
}
}
// Destination node checks
if (dstNode.equals(sn)) {
if (orphDstNode) {
LOG.debug("Node {} held by source of link {}", dstNode, lw);
orphDstNode = false;
}
if (orphDstTp && dstTp.equals(st)) {
LOG.debug("TP {} held by source of link {}", dstTp, lw);
orphDstTp = false;
}
}
if (dstNode.equals(dn)) {
if (orphDstNode) {
LOG.debug("Node {} held by destination of link {}", dstNode, lw);
orphDstNode = false;
}
if (orphDstTp && dstTp.equals(dt)) {
LOG.debug("TP {} held by destination of link {}", dstTp, lw);
orphDstTp = false;
}
}
}
if (orphSrcNode && !orphSrcTp) {
LOG.warn("Orphan source node {} but not TP {}, retaining the node", srcNode, srcTp);
orphSrcNode = false;
}
if (orphDstNode && !orphDstTp) {
LOG.warn("Orphan destination node {} but not TP {}, retaining the node", dstNode, dstTp);
orphDstNode = false;
}
if (orphSrcNode) {
LOG.debug("Removing orphan node {}", srcNode);
trans.delete(LogicalDatastoreType.OPERATIONAL, nodeIdentifier(srcNode));
} else if (orphSrcTp) {
LOG.debug("Removing orphan TP {} on node {}", srcTp, srcNode);
trans.delete(LogicalDatastoreType.OPERATIONAL, tpIdentifier(srcNode, srcTp));
}
if (orphDstNode) {
LOG.debug("Removing orphan node {}", dstNode);
trans.delete(LogicalDatastoreType.OPERATIONAL, nodeIdentifier(dstNode));
} else if (orphDstTp) {
LOG.debug("Removing orphan TP {} on node {}", dstTp, dstNode);
trans.delete(LogicalDatastoreType.OPERATIONAL, tpIdentifier(dstNode, dstTp));
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp in project bgpcep by opendaylight.
the class NodeChangedListener method onDataTreeChanged.
@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
final ReadWriteTransaction trans = this.dataProvider.newReadWriteTransaction();
final Set<InstanceIdentifier<ReportedLsp>> lsps = new HashSet<>();
final Set<InstanceIdentifier<Node>> nodes = new HashSet<>();
final Map<InstanceIdentifier<?>, DataObject> original = new HashMap<>();
final Map<InstanceIdentifier<?>, DataObject> updated = new HashMap<>();
final Map<InstanceIdentifier<?>, DataObject> created = new HashMap<>();
for (final DataTreeModification<?> change : changes) {
final InstanceIdentifier<?> iid = change.getRootPath().getRootIdentifier();
final DataObjectModification<?> rootNode = change.getRootNode();
handleChangedNode(rootNode, iid, lsps, nodes, original, updated, created);
}
// Now walk all nodes, check for removals/additions and cascade them to LSPs
for (final InstanceIdentifier<Node> iid : nodes) {
enumerateLsps(iid, (Node) original.get(iid), lsps);
enumerateLsps(iid, (Node) updated.get(iid), lsps);
enumerateLsps(iid, (Node) created.get(iid), lsps);
}
// We now have list of all affected LSPs. Walk them create/remove them
updateTransaction(trans, lsps, original, updated, created);
trans.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Topology change committed successfully");
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Failed to propagate a topology change, target topology became inconsistent", throwable);
}
}, MoreExecutors.directExecutor());
}
Aggregations