Search in sources :

Example 1 with Metric

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.Metric in project bgpcep by opendaylight.

the class PCEPRequestMessageParser method insertObject.

private static State insertObject(final State state, final List<Object> objects, final List<VendorInformationObject> viObjects, final P2pBuilder builder, final List<Metrics> metrics, final List<Message> errors, final Rp rp) {
    final Object obj = objects.get(0);
    switch(state) {
        case INIT:
            if (obj instanceof Rro) {
                builder.setRro((Rro) obj);
                objects.remove(0);
                final Object nextObj = objects.get(0);
                if (nextObj instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) {
                    builder.setReoptimizationBandwidth((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) nextObj);
                }
                return State.REPORTED_IN;
            }
        case REPORTED_IN:
            if (obj instanceof VendorInformationObject) {
                viObjects.add((VendorInformationObject) obj);
                return State.REPORTED_IN;
            }
        case VENDOR_INFO_LIST:
            if (obj instanceof LoadBalancing) {
                builder.setLoadBalancing((LoadBalancing) obj);
                return State.LOAD_BIN;
            }
        case LOAD_BIN:
            if (obj instanceof Lspa) {
                builder.setLspa((Lspa) obj);
                return State.LSPA_IN;
            }
        case LSPA_IN:
            if (obj instanceof Bandwidth) {
                builder.setBandwidth((Bandwidth) obj);
                return State.BANDWIDTH_IN;
            }
        case BANDWIDTH_IN:
            if (obj instanceof Metric) {
                metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
                return State.BANDWIDTH_IN;
            }
        case METRIC_IN:
            if (obj instanceof Iro) {
                builder.setIro((Iro) obj);
                return State.IRO_IN;
            }
        case IRO_IN:
            if (obj instanceof Rro) {
                builder.setRro((Rro) obj);
                return State.RRO_IN;
            }
        case RRO_IN:
            if (obj instanceof Xro) {
                builder.setXro((Xro) obj);
                return State.XRO_IN;
            }
        case XRO_IN:
            if (obj instanceof Of) {
                builder.setOf((Of) obj);
                return State.OF_IN;
            }
        case OF_IN:
            if (obj instanceof ClassType) {
                final ClassType classType = (ClassType) obj;
                if (!classType.isProcessingRule()) {
                    errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
                } else {
                    builder.setClassType(classType);
                }
                return State.CT_IN;
            }
        case CT_IN:
        case END:
            return State.END;
        default:
            return state;
    }
}
Also used : Preconditions(com.google.common.base.Preconditions) Iro(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.Iro) Rro(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Rro) MetricsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.MetricsBuilder) Xro(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro) Bandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject) ClassType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType) LoadBalancing(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancing) Of(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object) Metric(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric) Lspa(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa)

Example 2 with Metric

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.Metric in project bgpcep by opendaylight.

the class AbstractPathComputation method pruneEdge.

/**
 * Check if Edge need to be prune regarding all constraints including
 * address family.
 *
 * @return True if Edge must be prune, False if Edge must be keep
 */
protected boolean pruneEdge(final ConnectedEdge edge, final CspfPath path) {
    /* Check that Constraints are initialized */
    if (constraints == null) {
        LOG.warn("Constraints not set");
        return true;
    }
    /* Edge could point to an unknown Vertex e.g. with inter-domain link */
    if (edge.getDestination() == null || edge.getDestination().getVertex() == null) {
        LOG.debug("No Destination");
        return true;
    }
    /* Check that Edge have attributes */
    EdgeAttributes attributes = edge.getEdge() != null ? edge.getEdge().getEdgeAttributes() : null;
    if (attributes == null) {
        LOG.debug("No attributes");
        return true;
    }
    /* Check that Edge belongs to the requested address family */
    switch(constraints.getAddressFamily()) {
        case Ipv4:
            if (attributes.getRemoteAddress() == null || attributes.getRemoteAddress().getIpv4Address() == null) {
                LOG.debug("No Ipv4 address");
                return true;
            }
            break;
        case Ipv6:
            if (attributes.getRemoteAddress() == null || attributes.getRemoteAddress().getIpv6Address() == null) {
                LOG.debug("No Ipv6 address");
                return true;
            }
            break;
        case SrIpv4:
            if (getIpv4NodeSid(edge.getDestination()) == null) {
                LOG.debug("No Node-SID for IPv4");
                return true;
            }
            if (attributes.getAdjSid() == null) {
                LOG.debug("No Adjacency-SID");
                return true;
            }
            break;
        case SrIpv6:
            if (getIpv6NodeSid(edge.getDestination()) == null) {
                LOG.debug("No Node-SID for IPv6");
                return true;
            }
            if (attributes.getAdjSid() == null) {
                LOG.debug("No SR Adjacency-SID");
                return true;
            }
            break;
        default:
            return true;
    }
    /* Skip checking other Constraints for simple SPF algorithm */
    if (this instanceof ShortestPathFirst) {
        LOG.trace("Edge {} is valid for Simple Path Computation", edge);
        return false;
    }
    /*
         * If specified, check that total TE Metric up to this edge respects the
         * initial constraints
         */
    if (constraints.getTeMetric() != null) {
        if (attributes.getTeMetric() == null) {
            return true;
        } else {
            int totalCost = attributes.getTeMetric().intValue() + path.getCost();
            if (totalCost > constraints.getTeMetric().intValue()) {
                LOG.debug("TeMetric {} exceed constraint {}", totalCost, constraints.getTeMetric().intValue());
                return true;
            }
        }
    }
    /*
         * If specified, check that total Delay up to this edge respects the
         * initial constraints
         */
    if (constraints.getDelay() != null) {
        if (attributes.getDelay() == null) {
            return true;
        } else {
            int totalDelay = attributes.getDelay().getValue().intValue() + path.getDelay();
            if (totalDelay > constraints.getDelay().getValue().intValue()) {
                LOG.debug("Delay {} exceed constraint {}", totalDelay, constraints.getDelay().getValue().intValue());
                return true;
            }
        }
    }
    /* Check that Edge respect Loss constraint */
    if (constraints.getLoss() != null) {
        if (attributes.getLoss() == null || attributes.getLoss().getValue().intValue() > constraints.getLoss().getValue().intValue()) {
            return true;
        }
    }
    /* Check that Edge meet Bandwidth constraint */
    int cos = 0;
    if (constraints.getClassType() != null) {
        cos = constraints.getClassType().intValue();
    }
    if (constraints.getBandwidth() != null) {
        if (attributes.getMaxLinkBandwidth() == null || attributes.getMaxResvLinkBandwidth() == null || attributes.getUnreservedBandwidth() == null || attributes.getUnreservedBandwidth().get(cos) == null) {
            return true;
        } else {
            Long bandwidth = constraints.getBandwidth().getValue().longValue();
            Long unrsv = 0L;
            for (UnreservedBandwidth unResBw : attributes.getUnreservedBandwidth()) {
                if (unResBw.getClassType().intValue() == cos) {
                    unrsv = unResBw.getBandwidth().getValue().longValue();
                    break;
                }
            }
            if (unrsv < bandwidth || attributes.getMaxLinkBandwidth().getValue().longValue() < bandwidth || attributes.getMaxResvLinkBandwidth().getValue().longValue() < bandwidth) {
                LOG.debug("Bandwidth constraint is not met");
                return true;
            }
        }
    }
    /* Check that Edge belongs to admin group */
    if (constraints.getAdminGroup() != null && !constraints.getAdminGroup().equals(attributes.getAdminGroup())) {
        LOG.debug("Not in the requested admin-group");
        return true;
    }
    /*
         * OK. All is fine. We can consider this Edge valid, so not to be prune
         */
    LOG.trace("Edge {} is valid for Constrained Path Computation", edge);
    return false;
}
Also used : UnreservedBandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.edge.attributes.UnreservedBandwidth) EdgeAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.edge.EdgeAttributes)

Example 3 with Metric

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.Metric in project bgpcep by opendaylight.

the class ConstrainedShortestPathFirst method computeP2pPath.

@Override
public ConstrainedPath computeP2pPath(final VertexKey src, final VertexKey dst, final PathConstraints cts) {
    LOG.info("Start CSPF Path Computation from {} to {} with constraints {}", src, dst, cts);
    /* Initialize algorithm */
    this.constraints = cts;
    ConstrainedPathBuilder cpathBuilder = initializePathComputation(src, dst);
    if (cpathBuilder.getStatus() == ComputationStatus.Failed) {
        return cpathBuilder.build();
    }
    cpathBuilder.setBandwidth(cts.getBandwidth()).setClassType(cts.getClassType());
    visitedVertices.clear();
    /* Process all Connected Vertex until priority queue becomes empty. Connected Vertices are added into the
         * priority queue when processing the next Connected Vertex: see relaxMC() method */
    int currentCost = Integer.MAX_VALUE;
    while (priorityQueue.size() != 0) {
        CspfPath currentPath = priorityQueue.poll();
        visitedVertices.put(currentPath.getVertexKey(), currentPath);
        LOG.debug("Got path to Vertex {} from Priority Queue", currentPath.getVertex());
        List<ConnectedEdge> edges = currentPath.getVertex().getOutputConnectedEdges();
        for (ConnectedEdge edge : edges) {
            /* Skip Connected Edges that must be prune i.e. Edges that not satisfy the given constraints,
                 * in particular the Bandwidth, TE Metric and Delay. */
            if (pruneEdge(edge, currentPath)) {
                LOG.trace("  Prune Edge {}", edge);
                continue;
            }
            if (relaxMultiConstraints(edge, currentPath) && pathDestination.getCost() < currentCost) {
                currentCost = pathDestination.getCost();
                cpathBuilder.setPathDescription(getPathDescription(pathDestination.getPath())).setMetric(Uint32.valueOf(pathDestination.getCost())).setStatus(ComputationStatus.Active);
                LOG.debug("  Found a valid path up to destination {}", cpathBuilder.getPathDescription());
            }
        }
    }
    /* The priority queue is empty => all the possible (vertex, path) elements have been explored
         * The "ConstrainedPathBuilder" object contains the optimal path if it exists
         * Otherwise an empty path with status failed is returned
         */
    if (cpathBuilder.getStatus() == ComputationStatus.InProgress || cpathBuilder.getPathDescription().size() == 0) {
        cpathBuilder.setStatus(ComputationStatus.Failed);
    } else {
        cpathBuilder.setStatus(ComputationStatus.Completed);
    }
    return cpathBuilder.build();
}
Also used : ConstrainedPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPathBuilder) ConnectedEdge(org.opendaylight.graph.ConnectedEdge)

Example 4 with Metric

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.Metric in project bgpcep by opendaylight.

the class Samcra method computeP2pPath.

/* Samcra Algo:
     *
     * To limit the modification outside the Samcra method the same set of parameters as
     * the CSPF method is used (related to pseudo code, the path length is computed inside
     * the method based on the individual constraint parameters).
     *
     * On contrast to a simple CSPF algo, with Samcra a connected vertex might be associated to several
     * metric vectors from which different path lengths are computed. However a connected vertex is only
     * present once in the priority queue, associated to the minimal path weight, which is used as key
     * to address the priority queue.
     *
     * For a given metric the path weight is an integer value computed as the entire part of
     * the quantity:
     *      100 * (vector_path_metric/target_metric)
     * The path weight correspond to the maximum length computed from either the delay or TE metric.
     *
     * To maintain the priority queue behavior unchanged, a "SamcraPath" classes is created to manage
     * the set of possible paths associated to a given vertex (see above).
     *
     */
@Override
public ConstrainedPath computeP2pPath(final VertexKey src, final VertexKey dst, final PathConstraints cts) {
    ConstrainedPathBuilder cpathBuilder;
    List<ConnectedEdge> edges;
    CspfPath currentPath;
    LOG.info("Start SAMCRA Path Computation from {} to {} with constraints {}", src, dst, cts);
    /* Initialize SAMCRA variables */
    this.constraints = cts;
    cpathBuilder = initializePathComputation(src, dst);
    if (cpathBuilder.getStatus() == ComputationStatus.Failed) {
        return cpathBuilder.build();
    }
    cpathBuilder.setBandwidth(cts.getBandwidth()).setClassType(cts.getClassType());
    samcraPaths.clear();
    samcraPaths.put(pathSource.getVertexKey(), new SamcraPath(pathSource.getVertex()));
    samcraPaths.put(pathDestination.getVertexKey(), new SamcraPath(pathDestination.getVertex()));
    /* Exploration of the priority queue:
         * Each connected vertex is represented only once in the priority queue associated to the path
         * with the minimal length (other path are stored in the SamcraPath object).
         * The top of the queue, i.e. the element with the minimal key( path weight), is processed at each loop
         */
    while (priorityQueue.size() != 0) {
        currentPath = priorityQueue.poll();
        LOG.debug(" - Process path up to Vertex {} from Priority Queue", currentPath.getVertex());
        /* Prepare Samcra Path from current CSP Path except for the source */
        if (!currentPath.equals(pathSource)) {
            SamcraPath currentSamcraPath = samcraPaths.get(currentPath.getVertexKey());
            CspfPath currentCspfPath = currentSamcraPath.getCurrentPath();
            float queuePathLength = currentCspfPath.getPathLength();
            LOG.trace(" - Priority Queue output SamcraPaths {} CurrentPath {} with PathLength {}", currentSamcraPath.currentPath, currentCspfPath, queuePathLength);
        }
        edges = currentPath.getVertex().getOutputConnectedEdges();
        float currentPathLength = 1.0F;
        for (ConnectedEdge edge : edges) {
            /* Connected Vertex's edges processing:
                 * Prune the connected edges that do not satisfy the constraints (Bandwidth, TE Metric, Delay, Loss)
                 * For each remaining edge process the path to the remote vertex using the "relaxSamcra" procedure
                 *
                 * If the return path length is positive, the destination is reached and the
                 * obtained route satisfies the requested constraints.
                 * The path length is checked to record only the optimal route (i.e. the route with
                 * the minimal path length) info obtained from the destination vertex
                 */
            if (pruneEdge(edge, currentPath)) {
                LOG.trace(" - Prune Edge {}", edge);
                continue;
            }
            float pathLength = relaxSamcra(edge, currentPath, pathSource);
            /* Check if we found a valid and better path */
            if (pathLength > 0F && pathLength <= currentPathLength) {
                final SamcraPath finalPath = samcraPaths.get(pathDestination.getVertexKey());
                cpathBuilder.setPathDescription(getPathDescription(finalPath.getCurrentPath().getPath())).setMetric(Uint32.valueOf(finalPath.getCurrentPath().getCost())).setDelay(new Delay(Uint32.valueOf(finalPath.getCurrentPath().getDelay()))).setStatus(ComputationStatus.Active);
                LOG.debug(" - Path to destination found and registered {}", cpathBuilder.getPathDescription());
                currentPathLength = pathLength;
            }
        }
        /* The connected vertex that has been removed from the priority queue may have to be re-inserted with
             * the minimal length non-dominated path associated to the connected vertex if it exists (to be done
             * except for the source). Otherwise, the current path associated to the connected vertex is reset to
             * null to allow the connected vertex addition to the priority queue later on with a new path
             * (refer to "relaxSamcra" for addition of a connected vertex to the priority queue).
             */
        float previousLength = 1.0F;
        CspfPath selectedPath = null;
        if (!currentPath.equals(pathSource)) {
            LOG.debug(" - Processing current path {} up to {} from Priority Queue", currentPath, currentPath.getVertex());
            SamcraPath currentSamcraPath = samcraPaths.get(currentPath.getVertexKey());
            currentSamcraPath.decrementPathCount();
            /*
                 * The list of paths associated to the connected vertex is retrieved
                 * The path used to represent the connected vertex in the Priority Queue is marked from "selected"
                 * to "processed". The list of paths is analyzed to check if other "active" path(s) exist(s).
                 * If it is the case the shortest length is used to re-inject the connected vertex in the Priority Queue
                 */
            for (CspfPath testedPath : currentSamcraPath.getPathList()) {
                LOG.debug(" - Testing path {} with status {} ", testedPath, testedPath.getPathStatus());
                if (testedPath.getPathStatus() == CspfPath.SELECTED) {
                    testedPath.setPathStatus(CspfPath.PROCESSED);
                } else if (testedPath.getPathStatus() == CspfPath.ACTIVE && testedPath.getPathLength() < previousLength) {
                    selectedPath = testedPath;
                    previousLength = testedPath.getPathLength();
                }
            }
            /* If a path is found it is marked as "selected", used as "current path" for the connected vertex
                 * and added to the priority queue
                 */
            if (selectedPath != null) {
                selectedPath.setPathStatus(CspfPath.SELECTED);
                currentSamcraPath.setCurrentPath(selectedPath);
                priorityQueue.add(selectedPath);
                LOG.debug(" - Add path {} to Priority Queue. New path count {} ", selectedPath, currentSamcraPath.getPathCount());
            } else {
                currentSamcraPath.setCurrentPath(null);
            }
        }
    }
    /* The priority queue is empty => all the possible (vertex, path) elements have been explored
         * The "ConstrainedPathBuilder" object contains the optimal path if it exists
         * Otherwise an empty path with status failed is returned
         */
    if (cpathBuilder.getStatus() == ComputationStatus.InProgress || cpathBuilder.getPathDescription().size() == 0) {
        cpathBuilder.setStatus(ComputationStatus.Failed);
    } else {
        cpathBuilder.setStatus(ComputationStatus.Completed);
    }
    return cpathBuilder.build();
}
Also used : ConstrainedPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPathBuilder) ConnectedEdge(org.opendaylight.graph.ConnectedEdge) Delay(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.Delay)

Example 5 with Metric

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.Metric in project bgpcep by opendaylight.

the class LinkAttributesParser method parseLinkAttributes.

/**
 * Parse Link Attributes.
 *
 * @param attributes key is the tlv type and value is the value of the tlv
 * @param protocolId to differentiate parsing methods
 * @return {@link LinkStateAttribute}
 */
static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes, final ProtocolId protocolId) {
    final LinkAttributesBuilder builder = new LinkAttributesBuilder();
    final List<SrAdjIds> srAdjIds = new ArrayList<>();
    final List<SrLanAdjIds> srLanAdjIds = new ArrayList<>();
    final List<PeerSetSids> peerSetSids = new ArrayList<>();
    for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
        LOG.trace("Link attribute TLV {}", entry.getKey());
        final int key = entry.getKey();
        final ByteBuf value = entry.getValue();
        switch(key) {
            case TlvUtil.LOCAL_IPV4_ROUTER_ID:
                builder.setLocalIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
                LOG.debug("Parsed IPv4 Router-ID of local node: {}", builder.getLocalIpv4RouterId());
                break;
            case TlvUtil.LOCAL_IPV6_ROUTER_ID:
                builder.setLocalIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
                LOG.debug("Parsed IPv6 Router-ID of local node: {}", builder.getLocalIpv6RouterId());
                break;
            case REMOTE_IPV4_ROUTER_ID:
                builder.setRemoteIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
                LOG.debug("Parsed IPv4 Router-ID of remote node: {}", builder.getRemoteIpv4RouterId());
                break;
            case REMOTE_IPV6_ROUTER_ID:
                builder.setRemoteIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
                LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId());
                break;
            case ADMIN_GROUP:
                builder.setAdminGroup(new AdministrativeGroup(readUint32(value)));
                LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
                break;
            case EXTENDED_ADMIN_GROUP:
                // FIXME: BGPCEP-895: add proper implementation
                LOG.info("Support for Extended Administrative Group not implemented, ignoring it");
                break;
            case MAX_BANDWIDTH:
                builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
                LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
                break;
            case MAX_RESERVABLE_BANDWIDTH:
                builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
                LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
                break;
            case UNRESERVED_BANDWIDTH:
                parseUnreservedBandwidth(value, builder);
                break;
            case TE_METRIC:
                builder.setTeMetric(new TeMetric(readUint32(value)));
                LOG.debug("Parsed Metric {}", builder.getTeMetric());
                break;
            case LINK_PROTECTION_TYPE:
                builder.setLinkProtection(LinkProtectionType.forValue(value.readShort()));
                LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection());
                break;
            case MPLS_PROTOCOL:
                final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE);
                builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
                LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
                break;
            case METRIC:
                // length can 3, 2 or 1
                builder.setMetric(new Metric(Uint32.valueOf(ByteArray.bytesToLong(ByteArray.readAllBytes(value)))));
                LOG.debug("Parsed Metric {}", builder.getMetric());
                break;
            case SHARED_RISK_LINK_GROUP:
                parseSrlg(value, builder);
                break;
            case LINK_OPAQUE:
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
                }
                break;
            case LINK_NAME:
                builder.setLinkName(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII));
                LOG.debug("Parsed Link Name : {}", builder.getLinkName());
                break;
            case SR_ADJ_ID:
                srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId));
                LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1));
                break;
            case SR_LAN_ADJ_ID:
                srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId));
                LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1));
                break;
            case PEER_NODE_SID_CODE:
                builder.setPeerNodeSid(new PeerNodeSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
                LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid());
                break;
            case PEER_ADJ_SID_CODE:
                builder.setPeerAdjSid(new PeerAdjSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
                LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid());
                break;
            case PEER_SET_SID_CODE:
                peerSetSids.add(new PeerSetSidsBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
                LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1));
                break;
            // Performance Metrics
            case LINK_DELAY:
                builder.setLinkDelay(new Delay(readUint32(value)));
                LOG.debug("Parsed Link Delay {}", builder.getLinkDelay());
                break;
            case LINK_MIN_MAX_DELAY:
                builder.setLinkMinMaxDelay(new LinkMinMaxDelayBuilder().setMinDelay(new Delay(readUint32(value))).setMaxDelay(new Delay(readUint32(value))).build());
                LOG.debug("Parsed Link Min/Max Delay {}", builder.getLinkMinMaxDelay());
                break;
            case DELAY_VARIATION:
                builder.setDelayVariation(new Delay(readUint32(value)));
                LOG.debug("Parsed Delay Variation {}", builder.getDelayVariation());
                break;
            case LINK_LOSS:
                builder.setLinkLoss(new Loss(readUint32(value)));
                LOG.debug("Parsed Link Loss {}", builder.getLinkLoss());
                break;
            case RESIDUAL_BANDWIDTH:
                builder.setResidualBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
                LOG.debug("Parsed Residual Bandwidth {}", builder.getResidualBandwidth());
                break;
            case AVAILABLE_BANDWIDTH:
                builder.setAvailableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
                LOG.debug("Parsed Available Bandwidth {}", builder.getAvailableBandwidth());
                break;
            case UTILIZED_BANDWIDTH:
                builder.setUtilizedBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
                LOG.debug("Parsed Utilized Bandwidth {}", builder.getUtilizedBandwidth());
                break;
            default:
                LOG.warn("TLV {} is not a recognized link attribute, ignoring it", key);
        }
    }
    if (!srAdjIds.isEmpty()) {
        builder.setSrAdjIds(srAdjIds);
    }
    if (!srLanAdjIds.isEmpty()) {
        builder.setSrLanAdjIds(srLanAdjIds);
    }
    if (!peerSetSids.isEmpty()) {
        builder.setPeerSetSids(peerSetSids);
    }
    LOG.trace("Finished parsing Link Attributes.");
    return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
}
Also used : SrLanAdjIds(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.SrLanAdjIds) TeMetric(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric) PeerNodeSidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerNodeSidBuilder) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) PeerSetSidsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerSetSidsBuilder) Delay(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Delay) LinkMinMaxDelay(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.LinkMinMaxDelay) SrAdjIds(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.SrAdjIds) Bandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth) UnreservedBandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.UnreservedBandwidth) LinkAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder) BitArray(org.opendaylight.protocol.util.BitArray) Ipv6RouterIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv6RouterIdentifier) MplsProtocolMask(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.MplsProtocolMask) Ipv4RouterIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv4RouterIdentifier) Loss(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Loss) AdministrativeGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.AdministrativeGroup) LinkAttributesCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder) PeerAdjSidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerAdjSidBuilder) LinkMinMaxDelayBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.LinkMinMaxDelayBuilder) PeerSetSids(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerSetSids) Metric(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric) TeMetric(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 BitArray (org.opendaylight.protocol.util.BitArray)4 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object)4 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)3 Metric (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.Metric)3 List (java.util.List)2 ConnectedEdge (org.opendaylight.graph.ConnectedEdge)2 AdministrativeGroup (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.AdministrativeGroup)2 Delay (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Delay)2 Loss (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Loss)2 LinkMinMaxDelay (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.LinkMinMaxDelay)2 LinkAttributesCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder)2 Metric (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric)2 ConstrainedPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPathBuilder)2 Bandwidth (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.Bandwidth)2 Iro (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.Iro)2 LoadBalancing (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.load.balancing.object.LoadBalancing)2 Lspa (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lspa.object.Lspa)2