use of org.opendaylight.protocol.pcep.parser.message.PCEPOpenMessageParser in project bgpcep by opendaylight.
the class PCEPValidatorTest method testOpenMsg.
@Test
public void testOpenMsg() throws IOException, PCEPDeserializerException {
try (StatefulActivator a = new StatefulActivator()) {
a.start(this.ctx);
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenMessage1.bin"));
final PCEPOpenMessageParser parser = new PCEPOpenMessageParser(this.ctx.getObjectHandlerRegistry());
final OpenMessageBuilder builder = new OpenMessageBuilder();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder();
b.setProcessingRule(false);
b.setIgnore(false);
b.setVersion(new ProtocolVersion((short) 1));
b.setKeepalive((short) 30);
b.setDeadTimer((short) 120);
b.setSessionId((short) 1);
final Stateful tlv1 = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).build();
b.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(tlv1).build()).build());
builder.setOpen(b.build());
assertEquals(new OpenBuilder().setOpenMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
final ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new OpenBuilder().setOpenMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
}
}
use of org.opendaylight.protocol.pcep.parser.message.PCEPOpenMessageParser 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;
}
use of org.opendaylight.protocol.pcep.parser.message.PCEPOpenMessageParser in project bgpcep by opendaylight.
the class PCEPValidatorTest method testOpenMsg.
@Test
public void testOpenMsg() throws IOException, PCEPDeserializerException {
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenMessage1.bin"));
final PCEPOpenMessageParser parser = new PCEPOpenMessageParser(this.ctx.getObjectHandlerRegistry());
final OpenMessageBuilder builder = new OpenMessageBuilder();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder();
b.setProcessingRule(false);
b.setIgnore(false);
b.setVersion(new ProtocolVersion((short) 1));
b.setKeepalive((short) 30);
b.setDeadTimer((short) 120);
b.setSessionId((short) 1);
b.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().build());
builder.setOpen(b.build());
assertEquals(new OpenBuilder().setOpenMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
final ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new OpenBuilder().setOpenMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
try {
parser.serializeMessage(new OpenBuilder().setOpenMessage(new OpenMessageBuilder().build()).build(), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Open Object must be present in Open Message.", e.getMessage());
}
}
Aggregations