Search in sources :

Example 1 with PCEPErrorMessageParser

use of org.opendaylight.protocol.pcep.parser.message.PCEPErrorMessageParser in project bgpcep by opendaylight.

the class BaseParserExtensionActivator method startImpl.

@Override
protected List<AutoCloseable> startImpl(final PCEPExtensionProviderContext context) {
    final List<AutoCloseable> regs = new ArrayList<>();
    registerLabelParsers(regs, context);
    final LabelRegistry labelReg = context.getLabelHandlerRegistry();
    registerEROParsers(regs, context, labelReg);
    registerRROParsers(regs, context, labelReg);
    registerXROParsers(regs, context);
    registerTlvParsers(regs, context);
    registerObjectParsers(regs, context);
    final ObjectRegistry objReg = context.getObjectHandlerRegistry();
    final PCEPOpenMessageParser openParser = new PCEPOpenMessageParser(objReg);
    regs.add(context.registerMessageParser(PCEPOpenMessageParser.TYPE, openParser));
    regs.add(context.registerMessageSerializer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open.class, openParser));
    final PCEPKeepAliveMessageParser kaParser = new PCEPKeepAliveMessageParser(objReg);
    regs.add(context.registerMessageParser(PCEPKeepAliveMessageParser.TYPE, kaParser));
    regs.add(context.registerMessageSerializer(Keepalive.class, kaParser));
    final PCEPRequestMessageParser reqParser = new PCEPRequestMessageParser(objReg);
    regs.add(context.registerMessageParser(PCEPRequestMessageParser.TYPE, reqParser));
    regs.add(context.registerMessageSerializer(Pcreq.class, reqParser));
    final PCEPReplyMessageParser repParser = new PCEPReplyMessageParser(objReg);
    regs.add(context.registerMessageParser(PCEPReplyMessageParser.TYPE, repParser));
    regs.add(context.registerMessageSerializer(Pcrep.class, repParser));
    final PCEPNotificationMessageParser notParser = new PCEPNotificationMessageParser(objReg);
    regs.add(context.registerMessageParser(PCEPNotificationMessageParser.TYPE, notParser));
    regs.add(context.registerMessageSerializer(Pcntf.class, notParser));
    final PCEPErrorMessageParser errParser = new PCEPErrorMessageParser(objReg);
    regs.add(context.registerMessageParser(PCEPErrorMessageParser.TYPE, errParser));
    regs.add(context.registerMessageSerializer(Pcerr.class, errParser));
    final PCEPCloseMessageParser closeParser = new PCEPCloseMessageParser(objReg);
    regs.add(context.registerMessageParser(PCEPCloseMessageParser.TYPE, closeParser));
    regs.add(context.registerMessageSerializer(Close.class, closeParser));
    final PCEPMonitoringReplyMessageParser monRepParser = new PCEPMonitoringReplyMessageParser(objReg);
    regs.add(context.registerMessageParser(PCEPMonitoringReplyMessageParser.TYPE, monRepParser));
    regs.add(context.registerMessageSerializer(Pcmonrep.class, monRepParser));
    final PCEPMonitoringRequestMessageParser monReqParser = new PCEPMonitoringRequestMessageParser(objReg);
    regs.add(context.registerMessageParser(PCEPMonitoringRequestMessageParser.TYPE, monReqParser));
    regs.add(context.registerMessageSerializer(Pcmonreq.class, monReqParser));
    final PCEPStartTLSMessageParser startTLSParser = new PCEPStartTLSMessageParser(objReg);
    regs.add(context.registerMessageParser(PCEPStartTLSMessageParser.TYPE, startTLSParser));
    regs.add(context.registerMessageSerializer(Starttls.class, startTLSParser));
    return regs;
}
Also used : ArrayList(java.util.ArrayList) PCEPMonitoringReplyMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPMonitoringReplyMessageParser) PCEPMonitoringRequestMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPMonitoringRequestMessageParser) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open) PCEPCloseMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPCloseMessageParser) Pcmonreq(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcmonreq) Pcmonrep(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcmonrep) PCEPNotificationMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPNotificationMessageParser) PCEPRequestMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPRequestMessageParser) LabelRegistry(org.opendaylight.protocol.pcep.spi.LabelRegistry) Pcerr(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive) PCEPKeepAliveMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPKeepAliveMessageParser) PCEPStartTLSMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPStartTLSMessageParser) Starttls(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Starttls) PCEPReplyMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser) PCEPOpenMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPOpenMessageParser) PCEPErrorMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPErrorMessageParser) Close(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close) CClose(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CClose) Pcntf(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcntf) Pcrep(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcrep) Pcreq(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcreq) ObjectRegistry(org.opendaylight.protocol.pcep.spi.ObjectRegistry)

Example 2 with PCEPErrorMessageParser

use of org.opendaylight.protocol.pcep.parser.message.PCEPErrorMessageParser in project bgpcep by opendaylight.

the class PCEPValidatorTest method testErrorMsg.

@Test
public void testErrorMsg() throws IOException, PCEPDeserializerException {
    ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCErr.5.bin"));
    ErrorObject error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false).setType((short) 3).setValue((short) 1).build();
    final PCEPErrorMessageParser parser = new PCEPErrorMessageParser(this.ctx.getObjectHandlerRegistry());
    List<Errors> innerErr = new ArrayList<>();
    final PcerrMessageBuilder builder = new PcerrMessageBuilder();
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.Rps> rps = Lists.newArrayList();
    rps.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.RpsBuilder().setRp(this.rpFalse).build());
    innerErr.add(new ErrorsBuilder().setErrorObject(error1).build());
    builder.setErrors(innerErr);
    builder.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(rps).build()).build());
    assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
    ByteBuf buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
    result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCErr.3.bin"));
    error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false).setType((short) 3).setValue((short) 1).build();
    innerErr = new ArrayList<>();
    innerErr.add(new ErrorsBuilder().setErrorObject(error1).build());
    builder.setErrors(innerErr);
    builder.setErrorType(new SessionCaseBuilder().setSession(new SessionBuilder().setOpen(this.open).build()).build());
    assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
    buf = Unpooled.buffer(result.readableBytes());
    parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf);
    assertArrayEquals(result.array(), buf.array());
    try {
        parser.serializeMessage(new PcerrBuilder().setPcerrMessage(new PcerrMessageBuilder().build()).build(), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Errors should not be empty.", e.getMessage());
    }
    try {
        parser.serializeMessage(new PcerrBuilder().setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.emptyList()).build()).build(), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Errors should not be empty.", e.getMessage());
    }
}
Also used : MonitoringRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.MonitoringRequestBuilder) RequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.RequestBuilder) Notifications(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications) Collections(java.util.Collections) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) Rps(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Rps) RequestCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.RequestCaseBuilder) PcerrMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder) PcerrBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject) ErrorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder) SessionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.session._case.SessionBuilder) Errors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors) SessionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.SessionCaseBuilder) PCEPErrorMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPErrorMessageParser) ErrorObjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 PCEPErrorMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPErrorMessageParser)2 ByteBuf (io.netty.buffer.ByteBuf)1 Collections (java.util.Collections)1 Test (org.junit.Test)1 PCEPCloseMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPCloseMessageParser)1 PCEPKeepAliveMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPKeepAliveMessageParser)1 PCEPMonitoringReplyMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPMonitoringReplyMessageParser)1 PCEPMonitoringRequestMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPMonitoringRequestMessageParser)1 PCEPNotificationMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPNotificationMessageParser)1 PCEPOpenMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPOpenMessageParser)1 PCEPReplyMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser)1 PCEPRequestMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPRequestMessageParser)1 PCEPStartTLSMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPStartTLSMessageParser)1 LabelRegistry (org.opendaylight.protocol.pcep.spi.LabelRegistry)1 ObjectRegistry (org.opendaylight.protocol.pcep.spi.ObjectRegistry)1 Close (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close)1 Keepalive (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive)1 Pcerr (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr)1 PcerrBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder)1