Search in sources :

Example 1 with PcrepBuilder

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

the class PCEPReplyMessageParser method validate.

@Override
protected Pcrep validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
    Preconditions.checkArgument(objects != null, "Passed list can't be null.");
    if (objects.isEmpty()) {
        throw new PCEPDeserializerException("Pcrep message cannot be empty.");
    }
    final List<Replies> replies = new ArrayList<>();
    while (!objects.isEmpty()) {
        final Replies r = this.getValidReply(objects, errors);
        if (r != null) {
            replies.add(r);
        }
    }
    if (!objects.isEmpty()) {
        throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
    }
    return new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().setReplies(replies).build()).build();
}
Also used : PcrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessageBuilder) ArrayList(java.util.ArrayList) PcrepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcrepBuilder) Replies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.Replies) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)

Example 2 with PcrepBuilder

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

the class PCEPReplyMessageParser method validate.

@Override
protected Pcrep validate(final Queue<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
    checkArgument(objects != null, "Passed list can't be null.");
    if (objects.isEmpty()) {
        throw new PCEPDeserializerException("Pcrep message cannot be empty.");
    }
    final List<Replies> replies = new ArrayList<>();
    while (!objects.isEmpty()) {
        final Replies r = this.getValidReply(objects, errors);
        if (r != null) {
            replies.add(r);
        }
    }
    if (!objects.isEmpty()) {
        throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
    }
    return new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().setReplies(replies).build()).build();
}
Also used : PcrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder) ArrayList(java.util.ArrayList) PcrepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcrepBuilder) Replies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.Replies) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)

Example 3 with PcrepBuilder

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

the class PCEPValidatorTest method testRepMsgWithVendorInforObjects.

@Test
public void testRepMsgWithVendorInforObjects() 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/PCRep.6.bin"));
    final List<Replies> replies = new ArrayList<>();
    repliesBuilder = new RepliesBuilder().setRp(this.rpTrue).setVendorInformationObject(this.viObjects);
    final List<Paths> paths = new ArrayList<>();
    final PathsBuilder paBuilder = new PathsBuilder();
    paBuilder.setEro(this.ero);
    paths.add(paBuilder.build());
    repliesBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).setVendorInformationObject(this.viObjects).build()).build()).build();
    replies.add(repliesBuilder.build());
    builder.setReplies(replies);
    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) 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)

Example 4 with PcrepBuilder

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

the class PCEPValidatorTest method testReplyMsg.

@Test
public void testReplyMsg() throws IOException, PCEPDeserializerException {
    // only RP
    final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
    final PcrepMessageBuilder builder = new PcrepMessageBuilder();
    RepliesBuilder repliesBuilder = new RepliesBuilder();
    final List<Replies> replies1 = new ArrayList<>();
    repliesBuilder.setRp(this.rpTrue);
    replies1.add(repliesBuilder.build());
    builder.setReplies(replies1);
    ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.1.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());
    // simple Failure
    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.2.bin"));
    final List<Replies> replies2 = new ArrayList<>();
    repliesBuilder = new RepliesBuilder();
    repliesBuilder.setRp(this.rpTrue);
    replies2.add(repliesBuilder.build());
    final RepliesBuilder repliesBuilder2 = new RepliesBuilder();
    repliesBuilder2.setRp(this.rpTrue);
    repliesBuilder2.setResult(new FailureCaseBuilder().setNoPath(this.noPath).build());
    replies2.add(repliesBuilder2.build());
    builder.setReplies(replies2);
    assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
    buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
    // Failure with attributes
    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.3.bin"));
    final List<Replies> replies3 = new ArrayList<>();
    repliesBuilder = new RepliesBuilder();
    repliesBuilder.setRp(this.rpTrue);
    repliesBuilder.setResult(new FailureCaseBuilder().setNoPath(this.noPath).setLspa(this.lspa).setMetrics(Lists.newArrayList(this.metrics)).setIro(this.iro).build());
    replies3.add(repliesBuilder.build());
    builder.setReplies(replies3);
    assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
    buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
    // Success
    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.5.bin"));
    final List<Replies> replies4 = new ArrayList<>();
    repliesBuilder = new RepliesBuilder();
    repliesBuilder.setRp(this.rpTrue);
    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()));
    buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
    try {
        parser.serializeMessage(new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().build()).build(), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Replies cannot be null or empty.", e.getMessage());
    }
    try {
        parser.serializeMessage(new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().setReplies(Collections.emptyList()).build()).build(), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Replies cannot be null or empty.", e.getMessage());
    }
}
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) 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) FailureCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.FailureCaseBuilder) 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)

Example 5 with PcrepBuilder

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

the class MessagesUtil method createPcRepMessage.

public static Pcrep createPcRepMessage(final Rp rp, final P2p p2p, final ConstrainedPath cpath) {
    /* Prepare Path Object with ERO and Object from the Request */
    final ArrayList<Paths> paths = new ArrayList<>();
    PathsBuilder pathBuilder = buildPath(cpath);
    if (p2p.getLspa() != null) {
        pathBuilder.setLspa(p2p.getLspa());
    }
    if (p2p.getIro() != null) {
        pathBuilder.setIro(p2p.getIro());
    }
    if (p2p.getXro() != null) {
        pathBuilder.setXro(p2p.getXro());
    }
    paths.add(pathBuilder.build());
    /* Prepare Reply with Path Object */
    final RepliesBuilder replyBuilder = new RepliesBuilder().setRp(rp).setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build());
    /* Prepare PcRep Message */
    final PcrepMessageBuilder msgBuilder = new PcrepMessageBuilder().setReplies(Lists.newArrayList(replyBuilder.build()));
    return new PcrepBuilder().setPcrepMessage(msgBuilder.build()).build();
}
Also used : RepliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder) 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) PcrepMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder) ArrayList(java.util.ArrayList) 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) 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)

Aggregations

ArrayList (java.util.ArrayList)7 PcrepBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcrepBuilder)7 PcrepMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.PcrepMessageBuilder)7 RepliesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.RepliesBuilder)6 Replies (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.Replies)5 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 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)2 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 PcrepBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcrepBuilder)1 PcrepMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessageBuilder)1 Replies (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.Replies)1 Flags (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.NoPathVectorTlv.Flags)1 BandwidthBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.BandwidthBuilder)1