Search in sources :

Example 1 with GeneralMetricsListBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder in project bgpcep by opendaylight.

the class PCEPMonitoringReplyMessageParser method validateSpecificMetrics.

private static void validateSpecificMetrics(final List<Object> objects, final PcmonrepMessageBuilder builder) throws PCEPDeserializerException {
    final List<SpecificMetrics> specificMetrics = new ArrayList<>();
    while (!objects.isEmpty()) {
        final SpecificMetricsBuilder smb = new SpecificMetricsBuilder();
        final List<MetricPce> metricPceList = new ArrayList<>();
        if (objects.get(0) instanceof Rp) {
            smb.setRp((Rp) objects.get(0));
            objects.remove(0);
        }
        while (!objects.isEmpty() && !(objects.get(0) instanceof Rp)) {
            metricPceList.add(Util.validateMonitoringMetrics(objects));
        }
        if (smb.getRp() != null) {
            smb.setMetricPce(metricPceList);
            specificMetrics.add(smb.build());
        } else if (!metricPceList.isEmpty()) {
            builder.setMonitoringMetricsList(new GeneralMetricsListBuilder().setMetricPce(metricPceList).build());
        }
    }
    if (!specificMetrics.isEmpty()) {
        builder.setMonitoringMetricsList(new SpecificMetricsListBuilder().setSpecificMetrics(specificMetrics).build());
    }
}
Also used : SpecificMetricsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.SpecificMetricsListBuilder) GeneralMetricsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder) SpecificMetricsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetricsBuilder) SpecificMetrics(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetrics) ArrayList(java.util.ArrayList) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp) MetricPce(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce)

Example 2 with GeneralMetricsListBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder in project bgpcep by opendaylight.

the class PCEPMonitoringReplyMessageParser method validateSpecificMetrics.

private static void validateSpecificMetrics(final Queue<Object> objects, final PcmonrepMessageBuilder builder) throws PCEPDeserializerException {
    final List<SpecificMetrics> specificMetrics = new ArrayList<>();
    for (Object obj = objects.peek(); obj != null; obj = objects.peek()) {
        final SpecificMetricsBuilder smb = new SpecificMetricsBuilder();
        if (obj instanceof Rp) {
            smb.setRp((Rp) obj);
            objects.remove();
        }
        final List<MetricPce> metricPceList = new ArrayList<>();
        for (obj = objects.peek(); obj != null && !(obj instanceof Rp); obj = objects.peek()) {
            metricPceList.add(Util.validateMonitoringMetrics(objects));
        }
        if (smb.getRp() != null) {
            specificMetrics.add(smb.setMetricPce(metricPceList).build());
        } else if (!metricPceList.isEmpty()) {
            builder.setMonitoringMetricsList(new GeneralMetricsListBuilder().setMetricPce(metricPceList).build());
        }
    }
    if (!specificMetrics.isEmpty()) {
        builder.setMonitoringMetricsList(new SpecificMetricsListBuilder().setSpecificMetrics(specificMetrics).build());
    }
}
Also used : SpecificMetricsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.SpecificMetricsListBuilder) GeneralMetricsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder) SpecificMetricsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetricsBuilder) SpecificMetrics(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetrics) ArrayList(java.util.ArrayList) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp) MetricPce(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPce)

Example 3 with GeneralMetricsListBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder in project bgpcep by opendaylight.

the class PCEPValidatorTest method testMonRepMsg.

@Test
public void testMonRepMsg() throws PCEPDeserializerException, IOException {
    final PCEPMonitoringReplyMessageParser parser = new PCEPMonitoringReplyMessageParser(this.objectRegistry);
    final PcmonrepMessageBuilder builder = new PcmonrepMessageBuilder();
    builder.setMonitoring(this.monitoring).setMonitoringMetricsList(new GeneralMetricsListBuilder().setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build())).build());
    final byte[] msgBytes = { 0x20, 0x09, 0x00, 0x18, /* monitoring object */
    0x13, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, /* pce-id object */
    0x19, 0x10, 0x00, 0x08, 0x7f, 0x00, 0x00, 0x02 };
    ByteBuf result = Unpooled.wrappedBuffer(msgBytes);
    assertEquals(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
    ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
    builder.setMonitoring(this.monitoring);
    builder.setPccIdReq(this.pccIdReq);
    final SpecificMetricsBuilder smBuilder = new SpecificMetricsBuilder();
    smBuilder.setRp(this.rpTrue);
    final List<MetricPce> metricPces = new ArrayList<>();
    metricPces.add(new MetricPceBuilder().setOverload(this.overload).setPceId(this.pceId).setProcTime(this.procTime).build());
    metricPces.add(new MetricPceBuilder().setPceId(this.pceId).setProcTime(this.procTime).build());
    smBuilder.setMetricPce(metricPces);
    final SpecificMetricsBuilder smBuilder2 = new SpecificMetricsBuilder();
    final List<MetricPce> metricPces2 = new ArrayList<>();
    smBuilder2.setRp(this.rpTrue);
    metricPces2.add(new MetricPceBuilder().setOverload(this.overload).setPceId(this.pceId).build());
    smBuilder2.setMetricPce(metricPces2);
    builder.setMonitoringMetricsList(new SpecificMetricsListBuilder().setSpecificMetrics(Lists.newArrayList(smBuilder.build(), smBuilder2.build())).build());
    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCMonRep.bin"));
    assertEquals(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
    buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
}
Also used : PcmonrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcmonrep.message.PcmonrepMessageBuilder) SpecificMetricsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.SpecificMetricsListBuilder) GeneralMetricsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder) SpecificMetricsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetricsBuilder) PcmonrepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcmonrepBuilder) ArrayList(java.util.ArrayList) PCEPMonitoringReplyMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPMonitoringReplyMessageParser) ByteBuf(io.netty.buffer.ByteBuf) MetricPceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPceBuilder) MetricPce(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPce) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 MetricPce (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPce)2 GeneralMetricsListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder)2 SpecificMetricsListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.SpecificMetricsListBuilder)2 SpecificMetricsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetricsBuilder)2 ByteBuf (io.netty.buffer.ByteBuf)1 Test (org.junit.Test)1 PCEPMonitoringReplyMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPMonitoringReplyMessageParser)1 PcmonrepBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcmonrepBuilder)1 MetricPce (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce)1 GeneralMetricsListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder)1 SpecificMetricsListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.SpecificMetricsListBuilder)1 SpecificMetrics (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetrics)1 SpecificMetricsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetricsBuilder)1 Rp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp)1 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object)1 MetricPceBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPceBuilder)1 SpecificMetrics (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetrics)1 PcmonrepMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcmonrep.message.PcmonrepMessageBuilder)1 Rp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp)1