Search in sources :

Example 1 with PceId

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

the class PCEPRROSubobjectParserTest method testRROPathKey128Subobject.

@Test
public void testRROPathKey128Subobject() throws PCEPDeserializerException {
    final RROPathKey128SubobjectParser parser = new RROPathKey128SubobjectParser();
    final SubobjectBuilder subs = new SubobjectBuilder();
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
    pBuilder.setPathKey(new PathKey(4660));
    subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey128Bytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    RROPathKey128SubobjectParser.serializeSubobject(subs.build(), buff);
    assertArrayEquals(pathKey128Bytes, ByteArray.getAllBytes(buff));
    try {
        parser.parseSubobject(null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseSubobject(Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}
Also used : PathKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey) PathKeyCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder) PceId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId) RROPathKey128SubobjectParser(org.opendaylight.protocol.pcep.parser.subobject.RROPathKey128SubobjectParser) PathKeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder) ByteBuf(io.netty.buffer.ByteBuf) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder) Test(org.junit.Test)

Example 2 with PceId

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

the class RROPathKey128SubobjectParser method parseSubobject.

@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT128_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" + CONTENT128_LENGTH + ".");
    }
    final int pathKey = buffer.readUnsignedShort();
    final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
    final SubobjectBuilder builder = new SubobjectBuilder();
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(pceId));
    pBuilder.setPathKey(new PathKey(pathKey));
    builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    return builder.build();
}
Also used : PathKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey) PathKeyCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder) PceId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId) PathKeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder)

Example 3 with PceId

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

the class RROPathKey128SubobjectParser method serializeSubobject.

public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
    final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
    final ByteBuf body = Unpooled.buffer();
    Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
    writeUnsignedShort(pk.getPathKey().getValue(), body);
    Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
    body.writeBytes(pk.getPceId().getBinary());
    RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) PathKeyCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase)

Example 4 with PceId

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

the class RROPathKey32SubobjectParser method parseSubobject.

@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" + CONTENT_LENGTH + ".");
    }
    final int pathKey = buffer.readUnsignedShort();
    final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
    final SubobjectBuilder builder = new SubobjectBuilder();
    final PathKeyBuilder pBuilder = new PathKeyBuilder();
    pBuilder.setPceId(new PceId(pceId));
    pBuilder.setPathKey(new PathKey(pathKey));
    builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
    return builder.build();
}
Also used : PathKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey) PathKeyCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder) PceId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId) PathKeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder)

Example 5 with PceId

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

the class XROPathKey32SubobjectParser method serializeSubobject.

@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
    Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
    final ByteBuf body = Unpooled.buffer();
    Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
    if (pk.getPceId().getBinary().length == XROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
        XROPathKey128SubobjectParser.serializeSubobject(subobject, buffer);
    }
    Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
    writeUnsignedShort(pk.getPathKey().getValue(), body);
    Preconditions.checkArgument(pk.getPceId().getBinary().length == PCE_ID_F_LENGTH, "PceId 32 Bit required.");
    body.writeBytes(pk.getPceId().getBinary());
    XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) PathKeyCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)22 PceId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId)22 PathKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey)21 Test (org.junit.Test)14 PathKeyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder)13 PathKeyCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder)11 PathKeyCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder)8 PathKeyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder)8 PceId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId)6 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)5 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder)4 SubobjectContainerBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder)4 PathKeyCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase)4 ArrayList (java.util.ArrayList)3 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder)3 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder)3 PathKeyCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase)3 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)2 EROPathKey32SubobjectParser (org.opendaylight.protocol.rsvp.parser.impl.subobject.ero.EROPathKey32SubobjectParser)2 XROPathKey32SubobjectParser (org.opendaylight.protocol.rsvp.parser.impl.subobject.xro.XROPathKey32SubobjectParser)2