Search in sources :

Example 1 with Stateful07PCUpdateRequestMessageParser

use of org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07PCUpdateRequestMessageParser in project bgpcep by opendaylight.

the class PCEPValidatorTest method testUnexpectedRroObjectInPcUpdMsg.

@Test
public void testUnexpectedRroObjectInPcUpdMsg() throws PCEPDeserializerException {
    final byte[] badUpdateMsg = { (byte) 0x20, (byte) 0x0b, (byte) 0x00, (byte) 0x50, /* SRP, LSP and ERO objects */
    (byte) 0x21, (byte) 0x12, (byte) 0x00, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x20, (byte) 0x10, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x09, (byte) 0x07, (byte) 0x10, (byte) 0x00, (byte) 0x14, (byte) 0x01, (byte) 0x08, (byte) 0x05, (byte) 0x05, (byte) 0x05, (byte) 0x03, (byte) 0x18, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x08, (byte) 0x08, (byte) 0x08, (byte) 0x04, (byte) 0x18, (byte) 0x00, /* RRO object */
    (byte) 0x08, (byte) 0x10, (byte) 0x00, (byte) 0x24, (byte) 0x01, (byte) 0x08, (byte) 0x0a, (byte) 0x00, (byte) 0x00, (byte) 0x83, (byte) 0x20, (byte) 0x20, (byte) 0x03, (byte) 0x08, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x0a, (byte) 0x00, (byte) 0x09, (byte) 0xde, (byte) 0x20, (byte) 0x00, (byte) 0x03, (byte) 0x08, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
    try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator()) {
        a.start(this.ctx);
        final Stateful07PCUpdateRequestMessageParser parser = new Stateful07PCUpdateRequestMessageParser(this.ctx.getObjectHandlerRegistry());
        final PcerrMessageBuilder errMsgBuilder = new PcerrMessageBuilder();
        errMsgBuilder.setErrors(Lists.newArrayList(new ErrorsBuilder().setErrorObject(new ErrorObjectBuilder().setType((short) 6).setValue((short) 10).build()).build()));
        final PcerrBuilder builder = new PcerrBuilder();
        builder.setPcerrMessage(errMsgBuilder.build());
        final ByteBuf buf = Unpooled.wrappedBuffer(badUpdateMsg);
        final List<Message> errors = Lists.newArrayList();
        parser.parseMessage(buf.slice(4, buf.readableBytes() - 4), errors);
        assertFalse(errors.isEmpty());
        assertEquals(builder.build(), errors.get(0));
    }
}
Also used : PcerrBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder) Message(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message) Stateful07PCUpdateRequestMessageParser(org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07PCUpdateRequestMessageParser) ErrorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder) ByteBuf(io.netty.buffer.ByteBuf) CrabbeInitiatedActivator(org.opendaylight.protocol.pcep.ietf.initiated00.CrabbeInitiatedActivator) PcerrMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder) ErrorObjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder) Test(org.junit.Test)

Example 2 with Stateful07PCUpdateRequestMessageParser

use of org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07PCUpdateRequestMessageParser in project bgpcep by opendaylight.

the class PCEPValidatorTest method testUpdMsg.

@Test
public void testUpdMsg() throws IOException, PCEPDeserializerException {
    try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator()) {
        a.start(this.ctx);
        ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCUpd.2.bin"));
        final Stateful07PCUpdateRequestMessageParser parser = new Stateful07PCUpdateRequestMessageParser(this.ctx.getObjectHandlerRegistry());
        final PcupdMessageBuilder builder = new PcupdMessageBuilder();
        final List<Updates> updates = Lists.newArrayList();
        final PathBuilder pBuilder = new PathBuilder();
        pBuilder.setEro(this.ero);
        pBuilder.setLspa(this.lspa);
        updates.add(new UpdatesBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder.build()).build());
        builder.setUpdates(updates);
        assertEquals(new PcupdBuilder().setPcupdMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
        ByteBuf buf = Unpooled.buffer(result.readableBytes());
        parser.serializeMessage(new PcupdBuilder().setPcupdMessage(builder.build()).build(), buf);
        assertArrayEquals(result.array(), buf.array());
        result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCUpd.5.bin"));
        final List<Updates> updates1 = Lists.newArrayList();
        final PathBuilder pBuilder1 = new PathBuilder();
        pBuilder1.setEro(this.ero);
        pBuilder1.setLspa(this.lspa);
        updates1.add(new UpdatesBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder.build()).build());
        updates1.add(new UpdatesBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder1.build()).build());
        builder.setUpdates(updates1);
        assertEquals(new PcupdBuilder().setPcupdMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
        buf = Unpooled.buffer(result.readableBytes());
        parser.serializeMessage(new PcupdBuilder().setPcupdMessage(builder.build()).build(), buf);
        assertArrayEquals(result.array(), buf.array());
    }
}
Also used : PathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcupd.message.pcupd.message.updates.PathBuilder) Updates(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcupd.message.pcupd.message.Updates) Stateful07PCUpdateRequestMessageParser(org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07PCUpdateRequestMessageParser) PcupdMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcupd.message.PcupdMessageBuilder) ByteBuf(io.netty.buffer.ByteBuf) UpdatesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcupd.message.pcupd.message.UpdatesBuilder) PcupdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.PcupdBuilder) CrabbeInitiatedActivator(org.opendaylight.protocol.pcep.ietf.initiated00.CrabbeInitiatedActivator) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)2 Test (org.junit.Test)2 CrabbeInitiatedActivator (org.opendaylight.protocol.pcep.ietf.initiated00.CrabbeInitiatedActivator)2 Stateful07PCUpdateRequestMessageParser (org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07PCUpdateRequestMessageParser)2 PcupdBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.PcupdBuilder)1 PcupdMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcupd.message.PcupdMessageBuilder)1 Updates (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcupd.message.pcupd.message.Updates)1 UpdatesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcupd.message.pcupd.message.UpdatesBuilder)1 PathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcupd.message.pcupd.message.updates.PathBuilder)1 PcerrBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder)1 Message (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message)1 ErrorObjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder)1 PcerrMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder)1 ErrorsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder)1