Search in sources :

Example 1 with CNotification

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification in project bgpcep by opendaylight.

the class PCEPNotificationObjectParser method serializeObject.

@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
    Preconditions.checkArgument(object instanceof CNotification, "Wrong instance of PCEPObject. Passed %s. Needed CNotificationObject.", object.getClass());
    final CNotification notObj = (CNotification) object;
    final ByteBuf body = Unpooled.buffer();
    body.writeZero(NT_F_OFFSET);
    Preconditions.checkArgument(notObj.getType() != null, "Type is mandatory.");
    writeUnsignedByte(notObj.getType(), body);
    Preconditions.checkArgument(notObj.getValue() != null, "Value is mandatory.");
    writeUnsignedByte(notObj.getValue(), body);
    serializeTlvs(notObj.getTlvs(), body);
    ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification)

Example 2 with CNotification

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification 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((short) 1).setValue((short) 1).build();
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications> innerNot = Lists.newArrayList();
    innerNot.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(cn1).build());
    final List<Rps> rps = Lists.newArrayList();
    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 = Lists.newArrayList();
    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.rev131005.pcntf.message.pcntf.message.notifications.Notifications> innerNot1 = Lists.newArrayList();
    innerNot1.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.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.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder().setCNotification(cn1).build());
    final List<Rps> rps1 = Lists.newArrayList();
    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());
}
Also used : Notifications(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications) Collections(java.util.Collections) 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) PcntfBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcntfBuilder) PCEPNotificationMessageParser(org.opendaylight.protocol.pcep.parser.message.PCEPNotificationMessageParser) RpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.RpsBuilder) CNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification) NotificationsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.NotificationsBuilder) PcntfMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.PcntfMessageBuilder) CNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder) Notifications(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications) Test(org.junit.Test)

Example 3 with CNotification

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification in project bgpcep by opendaylight.

the class PCEPNotificationMessageParser method insertObject.

private static State insertObject(final State state, final Object obj, final List<Message> errors, final List<Rps> requestParameters, final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications> notifications) {
    switch(state) {
        case INIT:
            if (obj instanceof Rp) {
                final Rp rp = (Rp) obj;
                if (rp.isProcessingRule()) {
                    errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.absent()));
                    return null;
                }
                requestParameters.add(new RpsBuilder().setRp(rp).build());
                return State.INIT;
            }
        case RP_IN:
            if (obj instanceof CNotification) {
                final CNotification n = (CNotification) obj;
                notifications.add(new NotificationsBuilder().setCNotification(n).build());
                return State.RP_IN;
            }
        case NOTIFICATION_IN:
        case END:
            return State.END;
        default:
            return state;
    }
}
Also used : RpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.RpsBuilder) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp) CNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification) NotificationsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder)

Example 4 with CNotification

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification in project bgpcep by opendaylight.

the class PCEPNotificationObjectParser method parseObject.

@Override
public CNotification parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    final CNotificationBuilder builder = new CNotificationBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    bytes.skipBytes(NT_F_OFFSET);
    builder.setType(bytes.readUnsignedByte());
    builder.setValue(bytes.readUnsignedByte());
    parseTlvs(builder, bytes.slice());
    return builder.build();
}
Also used : CNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder)

Aggregations

CNotification (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification)3 ByteBuf (io.netty.buffer.ByteBuf)2 CNotificationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder)2 RpsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.RpsBuilder)2 Collections (java.util.Collections)1 Test (org.junit.Test)1 PCEPNotificationMessageParser (org.opendaylight.protocol.pcep.parser.message.PCEPNotificationMessageParser)1 PcntfBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcntfBuilder)1 PcntfMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.PcntfMessageBuilder)1 Notifications (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications)1 NotificationsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.NotificationsBuilder)1 NotificationsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.NotificationsBuilder)1 Rps (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Rps)1 Rp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp)1