Search in sources :

Example 6 with MetricPce

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

the class PCEPReplyMessageParser method getValidReply.

protected Replies getValidReply(final Queue<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
    Object obj = objects.remove();
    if (!(obj instanceof Rp)) {
        errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.empty()));
        return null;
    }
    final RepliesBuilder repliesBuilder = new RepliesBuilder().setRp((Rp) obj);
    obj = objects.peek();
    if (obj instanceof Monitoring) {
        repliesBuilder.setMonitoring((Monitoring) obj);
        objects.remove();
        obj = objects.peek();
    }
    if (obj instanceof PccIdReq) {
        repliesBuilder.setPccIdReq((PccIdReq) obj);
        objects.remove();
    // last option, no need to peek
    }
    // note: this may modify 'objects'
    final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
    if (!vendorInfo.isEmpty()) {
        repliesBuilder.setVendorInformationObject(vendorInfo);
    }
    final Result res;
    obj = objects.peek();
    if (obj instanceof NoPath) {
        objects.remove();
        res = handleNoPath((NoPath) obj, objects);
    } else if (obj instanceof Ero) {
        res = handleEros(objects);
    } else {
        res = null;
    }
    if (objects.peek() instanceof PceId) {
        final List<MetricPce> metricPceList = new ArrayList<>();
        while (!objects.isEmpty()) {
            metricPceList.add(Util.validateMonitoringMetrics(objects));
        }
        if (!metricPceList.isEmpty()) {
            repliesBuilder.setMetricPce(metricPceList);
        }
    }
    return repliesBuilder.setResult(res).build();
}
Also used : RepliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder) Ero(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero) ArrayList(java.util.ArrayList) Result(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.Result) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject) PceId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pce.id.object.PceId) PccIdReq(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcc.id.req.object.PccIdReq) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject) NoPath(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.NoPath) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp) Monitoring(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring) MetricPce(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPce)

Example 7 with MetricPce

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

the class PCEPMonitoringReplyMessageParser method serializeMessage.

@Override
public void serializeMessage(final Message message, final ByteBuf buffer) {
    checkArgument(message instanceof Pcmonrep, "Wrong instance of Message. Passed instance of %s. Need Pcmonrep.", message.getClass());
    final PcmonrepMessage monRepMsg = ((Pcmonrep) message).getPcmonrepMessage();
    checkArgument(monRepMsg.getMonitoring() != null, "MONITORING object is mandatory.");
    final ByteBuf body = Unpooled.buffer();
    serializeObject(monRepMsg.getMonitoring(), body);
    serializeObject(monRepMsg.getPccIdReq(), body);
    if (monRepMsg.getMonitoringMetricsList() instanceof GeneralMetricsList) {
        final GeneralMetricsList gml = (GeneralMetricsList) monRepMsg.getMonitoringMetricsList();
        for (final MetricPce metricPce : gml.nonnullMetricPce()) {
            serializeMetricPce(metricPce, body);
        }
    } else if (monRepMsg.getMonitoringMetricsList() instanceof SpecificMetricsList) {
        final SpecificMetricsList sml = (SpecificMetricsList) monRepMsg.getMonitoringMetricsList();
        for (final SpecificMetrics specificMetrics : sml.nonnullSpecificMetrics()) {
            serializeObject(specificMetrics.getRp(), body);
            for (final MetricPce metricPce : specificMetrics.nonnullMetricPce()) {
                serializeMetricPce(metricPce, body);
            }
        }
    }
    MessageUtil.formatMessage(TYPE, body, buffer);
}
Also used : SpecificMetricsList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.SpecificMetricsList) Pcmonrep(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcmonrep) PcmonrepMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcmonrep.message.PcmonrepMessage) SpecificMetrics(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetrics) ByteBuf(io.netty.buffer.ByteBuf) GeneralMetricsList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.GeneralMetricsList) MetricPce(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPce)

Example 8 with MetricPce

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPce 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)5 MetricPce (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPce)4 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object)3 ByteBuf (io.netty.buffer.ByteBuf)2 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)2 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object)2 MetricPce (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce)2 PceId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId)2 Rp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp)2 MetricPceBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPceBuilder)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 SpecificMetrics (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetrics)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 PceId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pce.id.object.PceId)2 Rp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp)2 Test (org.junit.Test)1 PCEPMonitoringReplyMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPMonitoringReplyMessageParser)1 Pcmonrep (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcmonrep)1 PcmonrepBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcmonrepBuilder)1