Search in sources :

Example 16 with Lsp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp in project bgpcep by opendaylight.

the class AbstractTopologySessionListener method onSessionUp.

@Override
public final void onSessionUp(final PCEPSession psession) {
    synchronized (this.serverSessionManager) {
        synchronized (this) {
            /*
                 * The session went up. Look up the router in Inventory model, create it if it
                 * is not there (marking that fact for later deletion), and mark it as
                 * synchronizing. Also create it in the topology model, with empty LSP list.
                 */
            final InetAddress peerAddress = psession.getRemoteAddress();
            this.syncOptimization = new SyncOptimization(psession);
            final TopologyNodeState state = this.serverSessionManager.takeNodeState(peerAddress, this, isLspDbRetreived());
            // due to configuration change
            if (state == null) {
                LOG.error("Unable to fetch topology node state for PCEP session. Closing session {}", psession);
                psession.close(TerminationReason.UNKNOWN);
                this.onSessionTerminated(psession, new PCEPCloseTermination(TerminationReason.UNKNOWN));
                return;
            }
            if (this.session != null || this.nodeState != null) {
                LOG.error("PCEP session is already up with {}. Closing session {}", psession.getRemoteAddress(), psession);
                psession.close(TerminationReason.UNKNOWN);
                this.onSessionTerminated(psession, new PCEPCloseTermination(TerminationReason.UNKNOWN));
                return;
            }
            this.session = psession;
            this.nodeState = state;
            LOG.trace("Peer {} resolved to topology node {}", peerAddress, state.getNodeId());
            // Our augmentation in the topology node
            final PathComputationClientBuilder pccBuilder = new PathComputationClientBuilder();
            onSessionUp(psession, pccBuilder);
            this.synced.set(isSynchronized());
            pccBuilder.setIpAddress(IetfInetUtil.INSTANCE.ipAddressNoZoneFor(peerAddress));
            final InstanceIdentifier<Node1> topologyAugment = state.getNodeId().augmentation(Node1.class);
            this.pccIdentifier = topologyAugment.child(PathComputationClient.class);
            final Node initialNodeState = state.getInitialNodeState();
            final boolean isNodePresent = isLspDbRetreived() && initialNodeState != null;
            if (isNodePresent) {
                loadLspData(initialNodeState, this.lspData, this.lsps, isIncrementalSynchro());
                pccBuilder.setReportedLsp(initialNodeState.augmentation(Node1.class).getPathComputationClient().getReportedLsp());
            }
            state.storeNode(topologyAugment, new Node1Builder().setPathComputationClient(pccBuilder.build()).build(), this.session);
            this.listenerState = new SessionStateImpl(this, psession);
            this.serverSessionManager.bind(this.nodeState.getNodeId(), this.listenerState);
            LOG.info("Session with {} attached to topology node {}", psession.getRemoteAddress(), state.getNodeId());
        }
    }
}
Also used : PCEPCloseTermination(org.opendaylight.protocol.pcep.PCEPCloseTermination) Node1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.Node1) Node1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.Node1Builder) PathComputationClient(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.PathComputationClient) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) PathComputationClientBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.PathComputationClientBuilder) SessionStateImpl(org.opendaylight.bgpcep.pcep.topology.provider.session.stats.SessionStateImpl) InetAddress(java.net.InetAddress)

Example 17 with Lsp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp in project bgpcep by opendaylight.

the class AbstractTopologySessionListener method updateLsp.

/**
 * Update an LSP in the data store.
 *
 * @param ctx       Message context
 * @param id        Revision-specific LSP identifier
 * @param lspName   LSP name
 * @param rlb       Reported LSP builder
 * @param solicited True if the update was solicited
 * @param remove    True if this is an LSP path removal
 */
protected final synchronized void updateLsp(final MessageContext ctx, final L id, final String lspName, final ReportedLspBuilder rlb, final boolean solicited, final boolean remove) {
    final String name;
    if (lspName == null) {
        name = this.lsps.get(id);
        if (name == null) {
            LOG.error("PLSPID {} seen for the first time, not reporting the LSP", id);
            return;
        }
    } else {
        name = lspName;
    }
    LOG.debug("Saved LSP {} with name {}", id, name);
    this.lsps.put(id, name);
    final ReportedLsp previous = this.lspData.get(name);
    // if no previous report about the lsp exist, just proceed
    if (previous != null) {
        final Map<PathKey, Path> updatedPaths = makeBeforeBreak(rlb, previous, name, remove);
        // if all paths or the last path were deleted, delete whole tunnel
        if (updatedPaths.isEmpty()) {
            LOG.debug("All paths were removed, removing LSP with {}.", id);
            removeLsp(ctx, id);
            return;
        }
        rlb.setPath(updatedPaths);
    }
    rlb.withKey(new ReportedLspKey(name));
    rlb.setName(name);
    // If this is an unsolicited update. We need to make sure we retain the metadata already present
    if (solicited) {
        this.nodeState.setLspMetadata(name, rlb.getMetadata());
    } else {
        rlb.setMetadata(this.nodeState.getLspMetadata(name));
    }
    final ReportedLsp rl = rlb.build();
    ctx.trans.put(LogicalDatastoreType.OPERATIONAL, this.pccIdentifier.child(ReportedLsp.class, rlb.key()), rl);
    LOG.debug("LSP {} updated to MD-SAL", name);
    this.lspData.put(name, rl);
}
Also used : Path(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.Path) PathKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.PathKey) ReportedLsp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp) ReportedLspKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLspKey)

Example 18 with Lsp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp in project bgpcep by opendaylight.

the class AbstractTopologySessionListener method makeBeforeBreak.

private static Map<PathKey, Path> makeBeforeBreak(final ReportedLspBuilder rlb, final ReportedLsp previous, final String name, final boolean remove) {
    // just one path should be reported
    final Path path = Iterables.getOnlyElement(rlb.getPath().values());
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId reportedLspId = path.getLspId();
    final List<Path> updatedPaths;
    // remove existing tunnel's paths now, as explicit path remove will not come
    if (!remove && reportedLspId.getValue().toJava() == 0) {
        updatedPaths = new ArrayList<>();
        LOG.debug("Remove previous paths {} to this lsp name {}", previous.getPath(), name);
    } else {
        // check previous report for existing paths
        final Collection<Path> prev = previous.nonnullPath().values();
        updatedPaths = new ArrayList<>(prev);
        LOG.debug("Found previous paths {} to this lsp name {}", updatedPaths, name);
        for (final Path prevPath : prev) {
            // we found reported path in previous reports
            if (prevPath.getLspId().getValue().toJava() == 0 || prevPath.getLspId().equals(reportedLspId)) {
                LOG.debug("Match on lsp-id {}", prevPath.getLspId().getValue());
                // path that was reported previously and does have the same lsp-id, path will be updated
                final boolean r = updatedPaths.remove(prevPath);
                LOG.trace("Request removed? {}", r);
            }
        }
    }
    // if the path does not exist in previous report, add it to path list, it's a new ERO
    // only one path will be added
    // lspId is 0 means confirmation message that shouldn't be added (because we have no means of deleting it later)
    LOG.trace("Adding new path {} to {}", path, updatedPaths);
    updatedPaths.add(path);
    if (remove) {
        if (reportedLspId.getValue().toJava() == 0) {
            // if lsp-id also 0, remove all paths
            LOG.debug("Removing all paths.");
            updatedPaths.clear();
        } else {
            // path is marked to be removed
            LOG.debug("Removing path {} from {}", path, updatedPaths);
            final boolean r = updatedPaths.remove(path);
            LOG.trace("Request removed? {}", r);
        }
    }
    LOG.debug("Setting new paths {} to lsp {}", updatedPaths, name);
    return Maps.uniqueIndex(updatedPaths, Path::key);
}
Also used : Path(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.Path)

Example 19 with Lsp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp in project bgpcep by opendaylight.

the class PCEPTopologySessionListener method manageNextReport.

@Holding("this")
private boolean manageNextReport(final Reports report, final MessageContext ctx) {
    final Lsp lsp = report.getLsp();
    final PlspId plspid = lsp.getPlspId();
    final Srp srp = report.getSrp();
    if (!lsp.getSync() && (plspid == null || plspid.getValue().toJava() == 0)) {
        purgeStaleLsps(ctx);
        if (isTriggeredSyncInProcess()) {
            if (srp == null) {
                return false;
            }
            final SrpIdNumber id = srp.getOperationId();
            if (id.getValue().toJava() == 0) {
                return false;
            }
            final PCEPRequest req = removeRequest(id);
            ctx.resolveRequest(req);
        }
        stateSynchronizationAchieved(ctx);
        return true;
    }
    final ReportedLspBuilder rlb = new ReportedLspBuilder();
    boolean solicited = false;
    solicited = isSolicited(srp, lsp, ctx, rlb);
    // if remove flag is set in SRP object, remove the tunnel immediately
    if (solicited) {
        final Srp1 initiatedSrp = srp.augmentation(Srp1.class);
        if (initiatedSrp != null && initiatedSrp.getRemove()) {
            super.removeLsp(ctx, plspid);
            return false;
        }
    }
    rlb.setPath(BindingMap.of(buildPath(report, srp, lsp)));
    String name = lookupLspName(plspid);
    if (lsp.getTlvs() != null && lsp.getTlvs().getSymbolicPathName() != null) {
        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 (lspDbVersion != null) {
        updatePccNode(ctx, new PathComputationClientBuilder().addAugmentation(new PathComputationClient1Builder().setLspDbVersion(lspDbVersion).build()).build());
    }
    updateLsp(ctx, plspid, name, rlb, solicited, lsp.getRemove());
    unmarkStaleLsp(plspid);
    LOG.debug("LSP {} updated", lsp);
    return true;
}
Also used : Srp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.srp.object.Srp) Srp1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.initiated.rev200720.Srp1) Lsp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp) ReportedLsp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp) SrpIdNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.SrpIdNumber) ReportedLspBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLspBuilder) LspDbVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.lsp.db.version.tlv.LspDbVersion) PathComputationClientBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.PathComputationClientBuilder) PathComputationClient1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.PathComputationClient1Builder) PlspId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.PlspId) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 20 with Lsp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp in project bgpcep by opendaylight.

the class PCEPTopologySessionListener method buildPath.

private static Path buildPath(final Reports report, final Srp srp, final Lsp lsp) {
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder();
    if (report.getPath() != null) {
        pb.fieldsFrom(report.getPath());
    }
    // LSP is mandatory (if there is none, parser will throw an exception)
    // this is to ensure a path will be created at any rate
    final Path1Builder p1Builder = new Path1Builder();
    p1Builder.setLsp(report.getLsp());
    final PathSetupType pst;
    if (srp != null && srp.getTlvs() != null && srp.getTlvs().getPathSetupType() != null) {
        pst = srp.getTlvs().getPathSetupType();
        p1Builder.setPathSetupType(pst);
    } else {
        pst = null;
    }
    pb.addAugmentation(p1Builder.build());
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.lsp.Tlvs tlvs = report.getLsp().getTlvs();
    if (tlvs != null) {
        if (tlvs.getLspIdentifiers() != null) {
            pb.setLspId(tlvs.getLspIdentifiers().getLspId());
        } 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()));
        }
    }
    return pb.build();
}
Also used : LspId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.LspId) Collections(java.util.Collections) PathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcupd.message.pcupd.message.updates.PathBuilder) PathSetupType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupType) Path1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.Path1Builder)

Aggregations

PlspId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.PlspId)18 Test (org.junit.Test)17 LspBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.LspBuilder)16 Lsp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp)15 ByteBuf (io.netty.buffer.ByteBuf)12 Pcrpt (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.Pcrpt)12 Collections (java.util.Collections)10 ReportedLsp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp)10 PlspId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.PlspId)9 Lsp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.object.Lsp)8 LspId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId)8 ArrayList (java.util.ArrayList)7 MsgBuilderUtil.createLspTlvs (org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLspTlvs)7 Srp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.srp.object.Srp)7 ReportedLsp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.path.computation.client.ReportedLsp)7 LspBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.object.LspBuilder)6 SrpIdNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.SrpIdNumber)6 TunnelId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId)6 PCEPSession (org.opendaylight.protocol.pcep.PCEPSession)5 LspDbVersion (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.lsp.db.version.tlv.LspDbVersion)5