Search in sources :

Example 6 with RepliesBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder 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 RepliesBuilder

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

the class PCEPValidatorTest method testReplyMsgWithTwoEros.

@Test
public void testReplyMsgWithTwoEros() throws IOException, PCEPDeserializerException {
    // Success Reply with two EROs: the first one is followed by Bandwidth Object and one Metric Object
    final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
    final PcrepMessageBuilder builder = new PcrepMessageBuilder();
    final List<Replies> replies = new ArrayList<>();
    final BandwidthBuilder bwBuilder = new BandwidthBuilder();
    bwBuilder.setIgnore(false);
    bwBuilder.setProcessingRule(false);
    bwBuilder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x47, (byte) 0x74, (byte) 0x24, (byte) 0x00 }));
    RepliesBuilder repliesBuilder = new RepliesBuilder();
    repliesBuilder = new RepliesBuilder();
    repliesBuilder.setRp(this.rpTrue);
    final List<Paths> paths = new ArrayList<>();
    final PathsBuilder paBuilder1 = new PathsBuilder().setEro(this.ero).setBandwidth(bwBuilder.build()).setMetrics(Lists.newArrayList(this.metrics));
    paths.add(paBuilder1.build());
    final PathsBuilder paBuilder2 = new PathsBuilder();
    paBuilder2.setEro(this.ero);
    paths.add(paBuilder2.build());
    repliesBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build()).build();
    replies.add(repliesBuilder.build());
    builder.setReplies(replies);
    ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.7.bin"));
    assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
    ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
}
Also used : RepliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder) PcrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) BandwidthBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.BandwidthBuilder) 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) PCEPReplyMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser) SuccessBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.SuccessBuilder) SuccessCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.SuccessCaseBuilder) Bandwidth(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth) PcrepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcrepBuilder) Paths(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.Paths) Replies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.Replies) Test(org.junit.Test)

Example 8 with RepliesBuilder

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

the class PCEPValidatorTest method testRepWithMonitoring.

@Test
public void testRepWithMonitoring() throws IOException, PCEPDeserializerException {
    final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
    final PcrepMessageBuilder builder = new PcrepMessageBuilder();
    RepliesBuilder repliesBuilder = new RepliesBuilder();
    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRepMon.5.bin"));
    final List<Replies> replies4 = new ArrayList<>();
    repliesBuilder = new RepliesBuilder().setRp(this.rpTrue).setMonitoring(this.monitoring).setPccIdReq(this.pccIdReq).setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build()));
    final List<Paths> paths = new ArrayList<>();
    final PathsBuilder paBuilder = new PathsBuilder().setEro(this.ero).setLspa(this.lspa).setMetrics(Lists.newArrayList(this.metrics)).setIro(this.iro).setOf(this.of);
    paths.add(paBuilder.build());
    repliesBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build()).build();
    replies4.add(repliesBuilder.build());
    builder.setReplies(replies4);
    assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
    final ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
}
Also used : RepliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder) PcrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) MetricPceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.metrics.MetricPceBuilder) 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) PCEPReplyMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser) SuccessBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.SuccessBuilder) SuccessCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.SuccessCaseBuilder) PcrepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcrepBuilder) Paths(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.Paths) Replies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.Replies) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)7 RepliesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder)7 PcrepBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcrepBuilder)6 PcrepMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder)6 SuccessCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.SuccessCaseBuilder)5 SuccessBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.SuccessBuilder)5 Paths (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.Paths)5 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)5 ByteBuf (io.netty.buffer.ByteBuf)4 Test (org.junit.Test)4 PCEPReplyMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser)4 Replies (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.Replies)4 FailureCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.FailureCaseBuilder)2 Bandwidth (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth)1 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object)1 Ero (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero)1 MetricPce (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce)1 Monitoring (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring)1 PccIdReq (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq)1 PceId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId)1