use of org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser 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.PCEPReplyMessageParser 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 rBuilder = new RepliesBuilder();
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.6.bin"));
final List<Replies> replies = Lists.newArrayList();
rBuilder = new RepliesBuilder();
rBuilder.setRp(this.rpTrue);
rBuilder.setVendorInformationObject(this.viObjects);
final List<Paths> paths = Lists.newArrayList();
final PathsBuilder paBuilder = new PathsBuilder();
paBuilder.setEro(this.ero);
paths.add(paBuilder.build());
rBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).setVendorInformationObject(this.viObjects).build()).build()).build();
replies.add(rBuilder.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());
}
use of org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser in project bgpcep by opendaylight.
the class PCEPValidatorTest method testReplyMsg.
@Test
public void testReplyMsg() throws IOException, PCEPDeserializerException {
// only RP
ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.1.bin"));
final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
final PcrepMessageBuilder builder = new PcrepMessageBuilder();
RepliesBuilder rBuilder = new RepliesBuilder();
final List<Replies> replies1 = Lists.newArrayList();
rBuilder.setRp(this.rpTrue);
replies1.add(rBuilder.build());
builder.setReplies(replies1);
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 = Lists.newArrayList();
rBuilder = new RepliesBuilder();
rBuilder.setRp(this.rpTrue);
replies2.add(rBuilder.build());
final RepliesBuilder rBuilder2 = new RepliesBuilder();
rBuilder2.setRp(this.rpTrue);
rBuilder2.setResult(new FailureCaseBuilder().setNoPath(this.noPath).build());
replies2.add(rBuilder2.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 = Lists.newArrayList();
rBuilder = new RepliesBuilder();
rBuilder.setRp(this.rpTrue);
rBuilder.setResult(new FailureCaseBuilder().setNoPath(this.noPath).setLspa(this.lspa).setMetrics(Lists.newArrayList(this.metrics)).setIro(this.iro).build());
replies3.add(rBuilder.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 = Lists.newArrayList();
rBuilder = new RepliesBuilder();
rBuilder.setRp(this.rpTrue);
final List<Paths> paths = Lists.newArrayList();
final PathsBuilder paBuilder = new PathsBuilder();
paBuilder.setEro(this.ero);
paBuilder.setLspa(this.lspa);
paBuilder.setMetrics(Lists.newArrayList(this.metrics));
paBuilder.setIro(this.iro);
paBuilder.setOf(this.of);
paths.add(paBuilder.build());
rBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build()).build();
replies4.add(rBuilder.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());
}
}
use of org.opendaylight.protocol.pcep.parser.message.PCEPReplyMessageParser 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 rBuilder = new RepliesBuilder();
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRepMon.5.bin"));
final List<Replies> replies4 = Lists.newArrayList();
rBuilder = new RepliesBuilder();
rBuilder.setRp(this.rpTrue);
rBuilder.setMonitoring(this.monitoring);
rBuilder.setPccIdReq(this.pccIdReq);
rBuilder.setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build()));
final List<Paths> paths = Lists.newArrayList();
final PathsBuilder paBuilder = new PathsBuilder();
paBuilder.setEro(this.ero);
paBuilder.setLspa(this.lspa);
paBuilder.setMetrics(Lists.newArrayList(this.metrics));
paBuilder.setIro(this.iro);
paBuilder.setOf(this.of);
paths.add(paBuilder.build());
rBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build()).build();
replies4.add(rBuilder.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());
}
Aggregations