Search in sources :

Example 46 with Monitoring

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring 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 47 with Monitoring

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring 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 48 with Monitoring

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

the class PCEPMonitoringReplyMessageParser method validate.

@Override
protected Message validate(final Queue<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
    checkArgument(objects != null, "Passed list can't be null.");
    final Object monitoring = objects.poll();
    if (monitoring == null) {
        throw new PCEPDeserializerException("Pcmonrep message cannot be empty.");
    }
    if (!(monitoring instanceof Monitoring)) {
        errors.add(createErrorMsg(PCEPErrors.MONITORING_OBJECT_MISSING, Optional.empty()));
        return null;
    }
    final PcmonrepMessageBuilder builder = new PcmonrepMessageBuilder().setMonitoring((Monitoring) monitoring);
    final Object obj = objects.peek();
    if (obj instanceof PccIdReq) {
        builder.setPccIdReq((PccIdReq) obj);
        objects.remove();
    }
    validateSpecificMetrics(objects, builder);
    if (!objects.isEmpty()) {
        throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
    }
    return new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build();
}
Also used : PcmonrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcmonrep.message.PcmonrepMessageBuilder) PcmonrepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcmonrepBuilder) 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) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException) Monitoring(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring)

Example 49 with Monitoring

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring 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)16 Optional (com.google.common.base.Optional)11 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)11 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 List (java.util.List)9 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)9 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)9 Collections (java.util.Collections)8 MonitorProfile (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile)8 IfTunnel (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel)8 FutureCallback (com.google.common.util.concurrent.FutureCallback)7 ExecutionException (java.util.concurrent.ExecutionException)7 Inject (javax.inject.Inject)7 Singleton (javax.inject.Singleton)7 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 ManagedNewTransactionRunnerImpl (org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl)7 EtherTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes)7