Search in sources :

Example 1 with PathKeys

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeys in project bgpcep by opendaylight.

the class PCEPPathKeyObjectParser method serializeObject.

@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
    Preconditions.checkArgument(object instanceof PathKey, "Wrong instance of PCEPObject. Passed %s. Needed PathKeyObject.", object.getClass());
    final PathKey pkey = (PathKey) object;
    final ByteBuf body = Unpooled.buffer();
    final List<Subobject> subs = new ArrayList<>();
    for (final PathKeys pk : pkey.nonnullPathKeys()) {
        subs.add(new SubobjectBuilder().setLoose(pk.getLoose()).setSubobjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder().setPathKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder().setPathKey(pk.getPathKey()).setPceId(pk.getPceId()).build()).build()).build());
    }
    serializeSubobject(subs, body);
    ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);
}
Also used : Subobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject) Preconditions(com.google.common.base.Preconditions) ArrayList(java.util.ArrayList) PathKeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.PathKeyBuilder) ByteBuf(io.netty.buffer.ByteBuf) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder) PathKeys(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeys) PathKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.PathKey)

Example 2 with PathKeys

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeys in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testPathKeyObject.

@Test
public void testPathKeyObject() throws Exception {
    final PCEPPathKeyObjectParser parser = new PCEPPathKeyObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
    final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPPathKeyObject.bin"));
    final PathKeyBuilder builder = new PathKeyBuilder();
    builder.setProcessingRule(true);
    builder.setIgnore(false);
    final List<PathKeys> list = new ArrayList<>();
    list.add(new PathKeysBuilder().setLoose(true).setPathKey(new PathKey(Uint16.valueOf(0x1234))).setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })).build());
    builder.setPathKeys(list);
    assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buf = Unpooled.buffer();
    parser.serializeObject(builder.build(), buf);
    assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}
Also used : PathKeys(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeys) PathKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey) ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) PCEPPathKeyObjectParser(org.opendaylight.protocol.pcep.parser.object.PCEPPathKeyObjectParser) ArrayList(java.util.ArrayList) PathKeysBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeysBuilder) 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.pcep.types.rev181109.path.key.object.PathKeyBuilder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 3 with PathKeys

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeys in project bgpcep by opendaylight.

the class PCEPPathKeyObjectParser method parseObject.

@Override
public PathKey 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 List<PathKeys> pk = new ArrayList<>();
    final List<Subobject> subs = parseSubobjects(bytes);
    for (final Subobject sub : subs) {
        final PathKeyCase pkc = (PathKeyCase) sub.getSubobjectType();
        pk.add(new PathKeysBuilder().setLoose(sub.getLoose()).setPceId(pkc.getPathKey().getPceId()).setPathKey(pkc.getPathKey().getPathKey()).build());
    }
    return new PathKeyBuilder().setIgnore(header.getIgnore()).setProcessingRule(header.getProcessingRule()).setPathKeys(pk).build();
}
Also used : PathKeys(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeys) Subobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject) PathKeyCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase) ArrayList(java.util.ArrayList) PathKeysBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeysBuilder) PathKeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.PathKeyBuilder)

Aggregations

ArrayList (java.util.ArrayList)3 PathKeyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.PathKeyBuilder)3 PathKeys (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeys)3 ByteBuf (io.netty.buffer.ByteBuf)2 Subobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject)2 PathKeysBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.path.key.PathKeysBuilder)2 Preconditions (com.google.common.base.Preconditions)1 Test (org.junit.Test)1 PCEPPathKeyObjectParser (org.opendaylight.protocol.pcep.parser.object.PCEPPathKeyObjectParser)1 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)1 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder)1 PathKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.key.object.PathKey)1 PathKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey)1 PceId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId)1 PathKeyCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase)1