Search in sources :

Example 6 with MetricsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.MetricsBuilder 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)

Aggregations

MetricsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.MetricsBuilder)5 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Float32 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32)3 Before (org.junit.Before)2 BaseParserExtensionActivator (org.opendaylight.protocol.pcep.parser.BaseParserExtensionActivator)2 SimplePCEPExtensionProviderContext (org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext)2 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)2 Bandwidth (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth)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 ClassType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassType)2 Ipv4Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv4._case.Ipv4Builder)2 Xro (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.Xro)2 MetricBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.MetricBuilder)2 VendorInformationObject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject)2 Preconditions (com.google.common.base.Preconditions)1 TestEnterpriseSpecificInformation (org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation)1 IpAddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone)1 EnterpriseNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber)1