Search in sources :

Example 11 with ClassType

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

the class PCEPRequestMessageParser method insertP2PObject.

// Note: objects is expected to be non-empty and caller will remove the first object if non-empty
private static P2PState insertP2PObject(final P2PState p2PState, final Queue<Object> objects, final List<VendorInformationObject> viObjects, final P2pBuilder builder, final List<Metrics> metrics, final List<Message> errors, final Rp rp) {
    final Object obj = objects.element();
    switch(p2PState) {
        case INIT:
            if (obj instanceof Rro) {
                builder.setRro((Rro) obj);
                objects.remove();
                // FIXME: should we guard against empty objects?
                final Object nextObj = objects.element();
                if (nextObj instanceof ReoptimizationBandwidth) {
                    builder.setReoptimizationBandwidth((ReoptimizationBandwidth) nextObj);
                }
                return P2PState.REPORTED_IN;
            }
        // fallthrough
        case REPORTED_IN:
            if (obj instanceof VendorInformationObject) {
                viObjects.add((VendorInformationObject) obj);
                return P2PState.REPORTED_IN;
            }
        // fallthrough
        case VENDOR_INFO_LIST:
            if (obj instanceof LoadBalancing) {
                builder.setLoadBalancing((LoadBalancing) obj);
                return P2PState.LOAD_BIN;
            }
        // fallthrough
        case LOAD_BIN:
            if (obj instanceof Lspa) {
                builder.setLspa((Lspa) obj);
                return P2PState.LSPA_IN;
            }
        // fallthrough
        case LSPA_IN:
            if (obj instanceof Bandwidth) {
                builder.setBandwidth((Bandwidth) obj);
                return P2PState.BANDWIDTH_IN;
            }
        // fallthrough
        case BANDWIDTH_IN:
            if (obj instanceof Metric) {
                metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
                return P2PState.BANDWIDTH_IN;
            }
        // fallthrough
        case METRIC_IN:
            if (obj instanceof Iro) {
                builder.setIro((Iro) obj);
                return P2PState.IRO_IN;
            }
        // fallthrough
        case IRO_IN:
            if (obj instanceof Rro) {
                builder.setRro((Rro) obj);
                return P2PState.RRO_IN;
            }
        // fallthrough
        case RRO_IN:
            if (obj instanceof Xro) {
                builder.setXro((Xro) obj);
                return P2PState.XRO_IN;
            }
        // fallthrough
        case XRO_IN:
            if (obj instanceof Of) {
                builder.setOf((Of) obj);
                return P2PState.OF_IN;
            }
        // fallthrough
        case OF_IN:
            if (obj instanceof ClassType) {
                final ClassType classType = (ClassType) obj;
                if (!classType.getProcessingRule()) {
                    errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
                } else {
                    builder.setClassType(classType);
                }
                return P2PState.CT_IN;
            }
        // fallthrough
        case CT_IN:
        case END:
            return P2PState.END;
        default:
            return p2PState;
    }
}
Also used : Iro(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.include.route.object.Iro) ClassType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassType) LoadBalancing(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.load.balancing.object.LoadBalancing) Rro(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.Rro) MetricsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.MetricsBuilder) Xro(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.Xro) Bandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.Bandwidth) ReoptimizationBandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reoptimization.bandwidth.object.ReoptimizationBandwidth) Of(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object) Metric(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.Metric) Lspa(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lspa.object.Lspa) ReoptimizationBandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reoptimization.bandwidth.object.ReoptimizationBandwidth)

Example 12 with ClassType

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

the class PCEPClassTypeObjectParser method serializeObject.

@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
    checkArgument(object instanceof ClassType, "Wrong instance of PCEPObject. Passed %s. Needed ClassTypeObject.", object.getClass());
    final ByteBuf body = Unpooled.buffer(SIZE);
    body.writeZero(SIZE - 1);
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType classType = ((ClassType) object).getClassType();
    checkArgument(classType != null, "ClassType is mandatory.");
    ByteBufUtils.write(body, classType.getValue());
    ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);
}
Also used : ClassType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassType) ByteBuf(io.netty.buffer.ByteBuf)

Example 13 with ClassType

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

the class MessagesUtil method buildPath.

private static PathsBuilder buildPath(final ConstrainedPath cpath) {
    final PathsBuilder pathBuilder = new PathsBuilder();
    /* Get ERO from Path Description */
    pathBuilder.setEro(getEro(cpath.getPathDescription()));
    /* Fulfill Computed Metrics if available */
    final ArrayList<Metrics> metrics = new ArrayList<>();
    if (cpath.getMetric() != null) {
        final MetricBuilder metricBuilder = new MetricBuilder().setComputed(true).setMetricType(Uint8.valueOf(IGP_METRIC)).setValue(new Float32(ByteBuffer.allocate(4).putFloat(cpath.getMetric().floatValue()).array()));
        metrics.add(new MetricsBuilder().setMetric(metricBuilder.build()).build());
    }
    if (cpath.getTeMetric() != null) {
        final MetricBuilder metricBuilder = new MetricBuilder().setComputed(true).setMetricType(Uint8.valueOf(TE_METRIC)).setValue(new Float32(ByteBuffer.allocate(4).putFloat(cpath.getTeMetric().floatValue()).array()));
        metrics.add(new MetricsBuilder().setMetric(metricBuilder.build()).build());
    }
    if (cpath.getDelay() != null) {
        final MetricBuilder metricBuilder = new MetricBuilder().setComputed(true).setMetricType(Uint8.valueOf(PATH_DELAY)).setValue(new Float32(ByteBuffer.allocate(4).putFloat(cpath.getDelay().getValue().floatValue()).array()));
        metrics.add(new MetricsBuilder().setMetric(metricBuilder.build()).build());
    }
    if (!metrics.isEmpty()) {
        pathBuilder.setMetrics(metrics);
    }
    /* Fulfill Bandwidth and ClassType if set */
    if (cpath.getBandwidth() != null) {
        final BandwidthBuilder bwBuilder = new BandwidthBuilder();
        bwBuilder.setBandwidth(new Bandwidth(new Float32(ByteBuffer.allocate(4).putFloat(cpath.getBandwidth().getValue().floatValue()).array())));
        pathBuilder.setBandwidth(bwBuilder.build());
    }
    if (cpath.getClassType() != null && !cpath.getClassType().equals(Uint8.ZERO)) {
        pathBuilder.setClassType(new ClassTypeBuilder().setClassType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType(cpath.getClassType())).build());
    }
    return pathBuilder;
}
Also used : Collections(java.util.Collections) ArrayList(java.util.ArrayList) PathsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder) BandwidthBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.BandwidthBuilder) MetricsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.MetricsBuilder) Metrics(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.Metrics) Float32(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32) Bandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth) ClassTypeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassTypeBuilder) MetricBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.MetricBuilder)

Example 14 with ClassType

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

the class PathComputationImpl method getConstraints.

private static PathConstraints getConstraints(final EndpointsObj endpoints, final Bandwidth bandwidth, final ClassType classType, final List<Metrics> metrics, final boolean segmentRouting) {
    ConstraintsBuilder ctsBuilder = new ConstraintsBuilder();
    Float convert;
    /* Set Metrics if any */
    if (metrics != null) {
        for (Metrics metric : metrics) {
            convert = ByteBuffer.wrap(metric.getMetric().getValue().getValue()).getFloat();
            final long value = convert.longValue();
            /* Skip Metric with value equal to 0 */
            if (value == 0) {
                continue;
            }
            switch(metric.getMetric().getMetricType().intValue()) {
                case MessagesUtil.IGP_METRIC:
                    ctsBuilder.setMetric(Uint32.valueOf(value));
                    break;
                case MessagesUtil.TE_METRIC:
                    ctsBuilder.setTeMetric(Uint32.valueOf(value));
                    break;
                case MessagesUtil.PATH_DELAY:
                    ctsBuilder.setDelay(new Delay(Uint32.valueOf(value)));
                    break;
                default:
                    LOG.warn("Metric {} is not handle by Path Computation Constraints", metric);
                    break;
            }
        }
    }
    /* Set Bandwidth and Class Type */
    if (bandwidth != null) {
        convert = ByteBuffer.wrap(bandwidth.getBandwidth().getValue()).getFloat();
        final long value = convert.longValue();
        /* Skip Bandwidth with value equal to 0 */
        if (value != 0) {
            ctsBuilder.setBandwidth(new DecimalBandwidth(BigDecimal.valueOf(value)));
            if (classType != null) {
                ctsBuilder.setClassType(classType.getClassType().getValue());
            }
        }
    }
    /* Set Address Family */
    if (endpoints.getAddressFamily() instanceof Ipv4Case) {
        ctsBuilder.setAddressFamily(segmentRouting ? AddressFamily.SrIpv4 : AddressFamily.Ipv4);
    } else {
        ctsBuilder.setAddressFamily(segmentRouting ? AddressFamily.SrIpv6 : AddressFamily.Ipv6);
    }
    return ctsBuilder.build();
}
Also used : DecimalBandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.DecimalBandwidth) Metrics(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.Metrics) ConstraintsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.get.constrained.path.input.ConstraintsBuilder) Ipv4Case(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4Case) Delay(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.Delay)

Aggregations

ClassType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassType)3 ClassTypeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassTypeBuilder)3 ByteBuf (io.netty.buffer.ByteBuf)2 Test (org.junit.Test)2 BitArray (org.opendaylight.protocol.util.BitArray)2 Bandwidth (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth)2 ClassType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType)2 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object)2 Bandwidth (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.Bandwidth)2 Ipv4Case (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4Case)2 Xro (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.Xro)2 Metrics (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.Metrics)2 MetricsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.MetricsBuilder)2 Preconditions (com.google.common.base.Preconditions)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 PathComputationAlgorithm (org.opendaylight.algo.PathComputationAlgorithm)1 AbstractConcurrentDataBrokerTest (org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest)1 PCEPClassTypeObjectParser (org.opendaylight.protocol.pcep.parser.object.PCEPClassTypeObjectParser)1 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)1