use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.Reports in project bgpcep by opendaylight.
the class Stateful07PCReportMessageParser method validate.
@Override
public Message 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("Pcrpt message cannot be empty.");
}
final List<Reports> reports = Lists.newArrayList();
while (!objects.isEmpty()) {
final Reports report = getValidReports(objects, errors);
if (report != null) {
reports.add(report);
}
}
return new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.Reports in project bgpcep by opendaylight.
the class Stateful07PCReportMessageParser method serializeMessage.
@Override
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof Pcrpt, "Wrong instance of Message. Passed instance of %s. Need Pcrpt.", message.getClass());
final Pcrpt msg = (Pcrpt) message;
final List<Reports> reports = msg.getPcrptMessage().getReports();
final ByteBuf buffer = Unpooled.buffer();
for (final Reports report : reports) {
serializeReport(report, buffer);
}
MessageUtil.formatMessage(TYPE, buffer, out);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.Reports in project bgpcep by opendaylight.
the class Stateful07TopologySessionListenerTest method testUnknownLsp.
@Test
public void testUnknownLsp() throws Exception {
final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setPath(new PathBuilder().setEro(new EroBuilder().build()).build()).setLsp(new LspBuilder().setPlspId(new PlspId(5L)).setSync(false).setRemove(false).setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(1L)).build()).setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(new byte[] { 22, 34 })).build()).build()).build()).build());
final Pcrpt rptmsg = new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build()).build();
this.listener.onSessionUp(this.session);
this.listener.onMessage(this.session, rptmsg);
readDataOperational(getDataBroker(), TOPO_IID, node -> {
assertFalse(node.getNode().isEmpty());
return node;
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.Reports in project bgpcep by opendaylight.
the class PCEPValidatorTest method testRptMsg.
@Test
public void testRptMsg() throws IOException, PCEPDeserializerException {
try (CrabbeInitiatedActivator a = new CrabbeInitiatedActivator();
StatefulActivator b = new StatefulActivator()) {
a.start(this.ctx);
b.start(this.ctx);
ByteBuf result = Unpooled.wrappedBuffer(PCRT1);
final Stateful07PCReportMessageParser parser = new Stateful07PCReportMessageParser(this.ctx.getObjectHandlerRegistry());
final PcrptMessageBuilder builder = new PcrptMessageBuilder();
final List<Reports> reports = Lists.newArrayList();
reports.add(new ReportsBuilder().setLsp(this.lsp).build());
builder.setReports(reports);
final Message parseResult = parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList());
assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parseResult);
ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
result = Unpooled.wrappedBuffer(PCRT2);
final List<Reports> reports1 = Lists.newArrayList();
reports1.add(new ReportsBuilder().setLsp(this.lsp).setPath(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.reports.PathBuilder().setEro(this.ero).setLspa(this.lspa).build()).build());
builder.setReports(reports1);
final ByteBuf input = result.slice(4, result.readableBytes() - 4);
assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(input, Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRpt.3.bin"));
final List<Reports> reports2 = Lists.newArrayList();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.reports.PathBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.reports.PathBuilder();
pBuilder.setEro(this.ero);
pBuilder.setLspa(this.lspa);
pBuilder.setMetrics(Lists.newArrayList(this.metrics, this.metrics));
pBuilder.setRro(this.rro);
reports2.add(new ReportsBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder.build()).build());
builder.setReports(reports2);
assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRpt.5.bin"));
final List<Reports> reports3 = Lists.newArrayList();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.reports.PathBuilder pBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.reports.PathBuilder();
pBuilder1.setEro(this.ero);
pBuilder1.setLspa(this.lspa);
pBuilder1.setMetrics(Lists.newArrayList(this.metrics, this.metrics));
pBuilder1.setRro(this.rro);
reports3.add(new ReportsBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder.build()).build());
reports3.add(new ReportsBuilder().setSrp(this.srp).setLsp(this.lspSrp).setPath(pBuilder1.build()).build());
builder.setReports(reports3);
assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
result = Unpooled.wrappedBuffer(PCRT3);
final List<Reports> reports4 = Lists.newArrayList();
reports4.add(new ReportsBuilder().setLsp(this.lsp).setPath(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.reports.PathBuilder().setEro(this.ero).setLspa(this.lspa).setBandwidth(this.bandwidth).setReoptimizationBandwidth(this.reoptimizationBandwidth).build()).build());
builder.setReports(reports4);
final ByteBuf input2 = result.slice(4, result.readableBytes() - 4);
assertEquals(new PcrptBuilder().setPcrptMessage(builder.build()).build(), parser.parseMessage(input2, Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrptBuilder().setPcrptMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.pcrpt.message.pcrpt.message.Reports in project bgpcep by opendaylight.
the class Stateful07PCReportMessageParser method getValidReports.
protected Reports getValidReports(final List<Object> objects, final List<Message> errors) {
final ReportsBuilder builder = new ReportsBuilder();
boolean lspViaSR = false;
Object object = objects.remove(0);
if (object instanceof Srp) {
final Srp srp = (Srp) object;
final Tlvs tlvs = srp.getTlvs();
if (tlvs != null) {
lspViaSR = PSTUtil.isDefaultPST(tlvs.getPathSetupType());
}
builder.setSrp(srp);
if (objects.isEmpty()) {
object = null;
} else {
object = objects.remove(0);
}
}
if (validateLsp(object, lspViaSR, errors, builder)) {
if (!objects.isEmpty()) {
if (!validatePath(objects, errors, builder)) {
return null;
}
}
return builder.build();
}
return null;
}
Aggregations