*/
package org.opendaylight.bgpcep.pcep.topology.provider;
-import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.ListenableFuture;
import java.net.InetAddress;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.opendaylight.controller.config.yang.pcep.topology.provider.PeerCapabilities;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.protocol.pcep.spi.PSTUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.PathComputationClient1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.PathComputationClient1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.lsp.db.version.tlv.LspDbVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Lsp1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.PcinitiateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1Builder;
final Stateful stateful = tlvs.getAugmentation(Tlvs1.class).getStateful();
if (stateful != null) {
getSessionListenerState().setPeerCapabilities(getCapabilities(stateful));
- pccBuilder.setReportedLsp(Collections.<ReportedLsp> emptyList());
+ pccBuilder.setReportedLsp(Collections.emptyList());
if (isSynchronized()) {
pccBuilder.setStateSync(PccSyncState.Synchronized);
} else if (isTriggeredInitialSynchro()) {
public synchronized ListenableFuture<OperationResult> triggerSync(final TriggerSyncArgs input) {
if (isTriggeredInitialSynchro() && !isSynchronized()) {
return triggerSynchronization(input);
- } else if (isSynchronized() && isTriggeredReSyncEnabled()) {
+ } else if (getSynchronized() && isTriggeredReSyncEnabled()) {
Preconditions.checkArgument(input != null && input.getNode() != null, MISSING_XML_TAG);
if (input.getName() == null) {
return triggerResyncronization(input);
if (f == null) {
return OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future();
}
- return Futures.transform(f, new ResyncLspFunction(input));
+ return Futures.transformAsync(f, new ResyncLspFunction(input));
}
private ListenableFuture<OperationResult> triggerResyncronization(final TriggerSyncArgs input) {
}
private void markAllLspAsStale() {
- for (final PlspId plspId : lsps.keySet()) {
- staleLsps.add(plspId);
+ for (final PlspId plspId : this.lsps.keySet()) {
+ this.staleLsps.add(plspId);
}
}
if (!staleLsp.getPath().isEmpty()) {
final Path1 path1 = staleLsp.getPath().get(0).getAugmentation(Path1.class);
if (path1 != null) {
- staleLsps.add(path1.getLsp().getPlspId());
+ Stateful07TopologySessionListener.this.staleLsps.add(path1.getLsp().getPlspId());
}
}
updatePccState(PccSyncState.PcepTriggeredResync);
case Active:
case Down:
case Up:
- final PCEPRequest req = removeRequest(id);
- if (req != null) {
- LOG.debug("Request {} resulted in LSP operational state {}", id, lsp.getOperational());
- rlb.setMetadata(req.getMetadata());
- ctx.resolveRequest(req);
- } else {
- LOG.warn("Request ID {} not found in outstanding DB", id);
+ if(!isTriggeredSyncInProcess()) {
+ final PCEPRequest req = removeRequest(id);
+ if (req != null) {
+ LOG.debug("Request {} resulted in LSP operational state {}", id, lsp.getOperational());
+ rlb.setMetadata(req.getMetadata());
+ ctx.resolveRequest(req);
+ } else {
+ LOG.warn("Request ID {} not found in outstanding DB", id);
+ }
}
break;
case GoingDown:
if (!lsp.isSync() && (plspid == null || plspid.getValue() == 0)) {
purgeStaleLsps(ctx);
+ if(isTriggeredSyncInProcess()) {
+ if (srp == null) {
+ return false;
+ }
+ final SrpIdNumber id = srp.getOperationId();
+ if (id.getValue() == 0) {
+ return false;
+ }
+ final PCEPRequest req = removeRequest(id);
+ ctx.resolveRequest(req);
+ }
stateSynchronizationAchieved(ctx);
return true;
}
String name = lookupLspName(plspid);
if (lsp.getTlvs() != null && lsp.getTlvs().getSymbolicPathName() != null) {
- name = Charsets.UTF_8.decode(ByteBuffer.wrap(lsp.getTlvs().getSymbolicPathName().getPathName().getValue())).toString();
+ name = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(lsp.getTlvs().getSymbolicPathName().getPathName().getValue())).toString();
}
//get LspDB from LSP and write it to pcc's node
final LspDbVersion lspDbVersion = geLspDbVersionTlv(lsp);
if (tlvs != null) {
if (tlvs.getLspIdentifiers() != null) {
pb.setLspId(tlvs.getLspIdentifiers().getLspId());
- } else if (!isDefaultPST(pst)) {
+ } else if (!PSTUtil.isDefaultPST(pst)) {
pb.setLspId(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId(lsp.getPlspId().getValue()));
}
}
// Build the request
final RequestsBuilder rb = new RequestsBuilder();
final Arguments2 args = this.input.getArguments().getAugmentation(Arguments2.class);
- Preconditions.checkArgument(args != null, "Input is missing operational tag.");
- final Lsp inputLsp = args.getLsp();
- Preconditions.checkArgument(inputLsp != null, "Reported LSP does not contain LSP object.");
+ final Lsp inputLsp = (args != null) ? args.getLsp() : null;
+ if (inputLsp == null) {
+ return OperationResults.createUnsent(PCEPErrors.LSP_MISSING).future();
+ }
rb.fieldsFrom(this.input.getArguments());
tlvsBuilder = new TlvsBuilder();
}
tlvsBuilder.setSymbolicPathName(
- new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(this.input.getName().getBytes(Charsets.UTF_8))).build());
+ new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(this.input.getName().getBytes(StandardCharsets.UTF_8))).build());
final SrpBuilder srpBuilder = new SrpBuilder();
srpBuilder.setOperationId(nextRequest());
srpBuilder.setProcessingRule(Boolean.TRUE);
- if (!isDefaultPST(args.getPathSetupType())) {
+ if (!PSTUtil.isDefaultPST(args.getPathSetupType())) {
srpBuilder.setTlvs(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder()
.setPathSetupType(args.getPathSetupType()).build());
if (f == null) {
return OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future();
}
- return Futures.transform(f, new AddFunction(input, lsp));
+ return Futures.transformAsync(f, new AddFunction(input, lsp));
}
@Override
if (f == null) {
return OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future();
}
- return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
- @Override
- public ListenableFuture<OperationResult> apply(final Optional<ReportedLsp> 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);
+ return 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);
});
}
final SrpBuilder srpBuilder = new SrpBuilder();
srpBuilder.setOperationId(nextRequest());
srpBuilder.setProcessingRule(Boolean.TRUE);
- if (args != null && args.getPathSetupType() != null) {
- if (!isDefaultPST(args.getPathSetupType())) {
+ if ((args != null && args.getPathSetupType() != null)) {
+ if (!PSTUtil.isDefaultPST(args.getPathSetupType())) {
srpBuilder.setTlvs(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder()
.setPathSetupType(args.getPathSetupType()).build());
}
}
final Srp srp = srpBuilder.build();
- final Lsp inputLsp = args.getLsp();
- final Lsp lsp = (inputLsp != null) ?
- new LspBuilder().setPlspId(reportedLsp.getPlspId()).setDelegate((inputLsp.isDelegate() != null) ? inputLsp.isDelegate() : false).setTlvs(inputLsp.getTlvs()).setAdministrative((inputLsp.isAdministrative() != null) ? inputLsp.isAdministrative() : false).build()
- : new LspBuilder().setPlspId(reportedLsp.getPlspId()).build();
- final Message msg = redelegate(reportedLsp.isDelegate(), srp, lsp, this.input);
- return sendMessage(msg, srp.getOperationId(), this.input.getArguments().getMetadata());
+ final Lsp inputLsp = (args != null) ? args.getLsp() : null;
+ final LspBuilder lspBuilder = new LspBuilder().setPlspId(reportedLsp.getPlspId());
+ if (inputLsp != null) {
+ lspBuilder.setDelegate(inputLsp.isDelegate() != null && inputLsp.isDelegate())
+ .setTlvs(inputLsp.getTlvs())
+ .setAdministrative(inputLsp.isAdministrative() != null && inputLsp.isAdministrative());
+ }
+ return redelegate(reportedLsp, srp, lspBuilder.build(), this.input);
}
}
- private Message redelegate(final Boolean isDelegate, final Srp srp, final Lsp lsp, final UpdateLspArgs input) {
+ 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
- Preconditions.checkNotNull(isDelegate);
- if (isDelegate) {
+ Preconditions.checkNotNull(reportedLsp.isDelegate());
+ final Message msg;
+ if (reportedLsp.isDelegate()) {
// we already have delegation, send update
final UpdatesBuilder rb = new UpdatesBuilder();
rb.setSrp(srp);
rb.setPath(pb.build());
final PcupdMessageBuilder ub = new PcupdMessageBuilder(MESSAGE_HEADER);
ub.setUpdates(Collections.singletonList(rb.build()));
- return new PcupdBuilder().setPcupdMessage(ub.build()).build();
+ msg = new PcupdBuilder().setPcupdMessage(ub.build()).build();
+ } else {
+ final Lsp1 lspCreateFlag = reportedLsp.getAugmentation(Lsp1.class);
+ // we only retake delegation for PCE initiated tunnels
+ if (lspCreateFlag != null && !lspCreateFlag.isCreate()) {
+ 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();
}
- // 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);
- return new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build();
+ return sendMessage(msg, srp.getOperationId(), input.getArguments().getMetadata());
}
@Override
if (f == null) {
return OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future();
}
- return Futures.transform(f, new UpdateFunction(input));
+ return Futures.transformAsync(f, new UpdateFunction(input));
}
@Override
}
private ListenableFuture<OperationResult> listenableFuture(final ListenableFuture<Optional<ReportedLsp>> f, final EnsureLspOperationalInput input, final OperationalStatus op) {
- return Futures.transform(f, new Function<Optional<ReportedLsp>, OperationResult>() {
- @Override
- public OperationResult apply(final Optional<ReportedLsp> rep) {
- if (!rep.isPresent()) {
- LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
+ return Futures.transform(f, (Function<Optional<ReportedLsp>, OperationResult>) rep -> {
+ if (!rep.isPresent()) {
+ LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
+ return OperationResults.UNSENT;
+ }
+ // check if at least one of the paths has the same status as requested
+ for (final Path p : rep.get().getPath()) {
+ final Path1 p1 = p.getAugmentation(Path1.class);
+ if (p1 == null) {
+ LOG.warn("Node {} LSP {} does not contain data", input.getNode(), input.getName());
return OperationResults.UNSENT;
}
- // check if at least one of the paths has the same status as requested
- 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()) {
- final Path1 p1 = p.getAugmentation(Path1.class);
- if (p1 == null) {
- LOG.warn("Node {} LSP {} does not contain data", input.getNode(), input.getName());
- return OperationResults.UNSENT;
- }
- if (op.equals(p1.getLsp().getOperational())) {
- return OperationResults.SUCCESS;
- }
+ if (op.equals(p1.getLsp().getOperational())) {
+ return OperationResults.SUCCESS;
}
- return OperationResults.UNSENT;
}
+ return OperationResults.UNSENT;
});
}
final Path1 path1 = rep.get().getPath().get(0).getAugmentation(Path1.class);
if (path1 != null) {
final PathSetupType pst = path1.getPathSetupType();
- if (!isDefaultPST(pst)) {
+ if (!PSTUtil.isDefaultPST(pst)) {
return Optional.of(pst);
}
}
return Optional.absent();
}
- private static boolean isDefaultPST(final PathSetupType pst) {
- if (pst != null && pst.getPst() != null && pst.getPst().shortValue() != 0) {
- return false;
- }
- return true;
- }
-
private static PeerCapabilities getCapabilities(final Stateful stateful) {
final PeerCapabilities capa = new PeerCapabilities();
capa.setStateful(true);
if (path1 != null) {
final PlspId plspId = path1.getLsp().getPlspId();
if (!incrementalSynchro) {
- staleLsps.add(plspId);
+ this.staleLsps.add(plspId);
}
lsps.put(plspId, lspName);
}
* @param plspId
*/
private synchronized void unmarkStaleLsp(final PlspId plspId) {
- staleLsps.remove(plspId);
+ this.staleLsps.remove(plspId);
}
/**
* @param ctx
*/
private synchronized void purgeStaleLsps(final MessageContext ctx) {
- for (final PlspId plspId : staleLsps) {
+ for (final PlspId plspId : this.staleLsps) {
removeLsp(ctx, plspId);
}
- staleLsps.clear();
+ this.staleLsps.clear();
}
}