use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.PcntfMessageBuilder in project bgpcep by opendaylight.
the class PCEPNotificationMessageParser method validate.
@Override
protected 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("Notification message cannot be empty.");
}
final List<Notifications> compositeNotifications = new ArrayList<>();
while (!objects.isEmpty()) {
final Notifications comObj = getValidNotificationComposite(objects, errors);
if (comObj == null) {
break;
}
compositeNotifications.add(comObj);
}
if (compositeNotifications.isEmpty()) {
throw new PCEPDeserializerException("Atleast one Notifications is mandatory.");
}
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new PcntfBuilder().setPcntfMessage(new PcntfMessageBuilder().setNotifications(compositeNotifications).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.PcntfMessageBuilder in project bgpcep by opendaylight.
the class PCEPNotificationMessageParser method validate.
@Override
protected Message validate(final Queue<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Notification message cannot be empty.");
}
final List<Notifications> compositeNotifications = new ArrayList<>();
while (!objects.isEmpty()) {
final Notifications comObj = getValidNotificationComposite(objects, errors);
if (comObj == null) {
break;
}
compositeNotifications.add(comObj);
}
if (compositeNotifications.isEmpty()) {
throw new PCEPDeserializerException("Atleast one Notifications is mandatory.");
}
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new PcntfBuilder().setPcntfMessage(new PcntfMessageBuilder().setNotifications(compositeNotifications).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.PcntfMessageBuilder in project bgpcep by opendaylight.
the class PCEPValidatorTest method testNotificationMsg.
@Test
public void testNotificationMsg() throws IOException, PCEPDeserializerException {
final CNotification cn1 = new CNotificationBuilder().setIgnore(false).setProcessingRule(false).setType(Uint8.ONE).setValue(Uint8.ONE).build();
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.notifications.Notifications> innerNot = new ArrayList<>();
innerNot.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(cn1).build());
final List<Rps> rps = new ArrayList<>();
rps.add(new RpsBuilder().setRp(this.rpFalse).build());
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCNtf.5.bin"));
final PCEPNotificationMessageParser parser = new PCEPNotificationMessageParser(this.objectRegistry);
final PcntfMessageBuilder builder = new PcntfMessageBuilder();
final List<Notifications> nots = new ArrayList<>();
final NotificationsBuilder b = new NotificationsBuilder();
b.setNotifications(innerNot);
b.setRps(rps);
nots.add(b.build());
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.notifications.Notifications> innerNot1 = new ArrayList<>();
innerNot1.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(cn1).build());
innerNot1.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(cn1).build());
final List<Rps> rps1 = new ArrayList<>();
rps1.add(new RpsBuilder().setRp(this.rpFalse).build());
rps1.add(new RpsBuilder().setRp(this.rpFalse).build());
b.setNotifications(innerNot1);
b.setRps(rps1);
nots.add(b.build());
builder.setNotifications(nots);
assertEquals(new PcntfBuilder().setPcntfMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
final ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcntfBuilder().setPcntfMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
}
Aggregations