Search in sources :

Example 1 with ProcTime

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTime in project bgpcep by opendaylight.

the class PCEPProcTimeObjectParser method serializeObject.

@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
    checkArgument(object instanceof ProcTime, "Wrong instance of PCEPObject. Passed %s. Needed ProcTimeObject.", object.getClass());
    final ProcTime procTime = (ProcTime) object;
    final ByteBuf body = Unpooled.buffer(BODY_SIZE);
    body.writeZero(RESERVED);
    final BitArray flagBits = new BitArray(FLAGS);
    flagBits.set(E_FLAG_POSITION, procTime.getEstimated());
    flagBits.toByteBuf(body);
    ByteBufUtils.writeOrZero(body, procTime.getCurrentProcTime());
    ByteBufUtils.writeOrZero(body, procTime.getMinProcTime());
    ByteBufUtils.writeOrZero(body, procTime.getMaxProcTime());
    ByteBufUtils.writeOrZero(body, procTime.getAverageProcTime());
    ByteBufUtils.writeOrZero(body, procTime.getVarianceProcTime());
    ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);
}
Also used : ProcTime(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTime) BitArray(org.opendaylight.protocol.util.BitArray) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with ProcTime

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTime in project bgpcep by opendaylight.

the class PCEPObjectParserTest method testProcTimeObject.

@Test
public void testProcTimeObject() throws PCEPDeserializerException {
    final byte[] proctimeBytes = { /* object header */
    0x1A, 0x10, 0x00, 0x1C, /* E flag */
    0x00, 0x00, 0x00, 0x01, /* current proc. time */
    0x00, 0x00, 0x00, 0x01, /* min proc. time */
    0x00, 0x00, 0x00, 0x02, /* max proc time */
    0x00, 0x00, 0x00, 0x03, /* average proc time */
    0x00, 0x00, 0x00, 0x04, /* variance proc time */
    0x00, 0x00, 0x00, 0x05 };
    final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser();
    final ProcTime procTime = new ProcTimeBuilder().setEstimated(true).setAverageProcTime(Uint32.valueOf(4)).setCurrentProcTime(Uint32.ONE).setMaxProcTime(Uint32.valueOf(3)).setMinProcTime(Uint32.TWO).setVarianceProcTime(Uint32.valueOf(5)).build();
    final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes);
    assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
    final ByteBuf buf = Unpooled.buffer(proctimeBytes.length);
    parser.serializeObject(procTime, buf);
    assertArrayEquals(proctimeBytes, buf.array());
}
Also used : ProcTimeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTimeBuilder) PCEPProcTimeObjectParser(org.opendaylight.protocol.pcep.parser.object.PCEPProcTimeObjectParser) ObjectHeaderImpl(org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl) ProcTime(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTime) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)2 ProcTime (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTime)2 Test (org.junit.Test)1 PCEPProcTimeObjectParser (org.opendaylight.protocol.pcep.parser.object.PCEPProcTimeObjectParser)1 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)1 BitArray (org.opendaylight.protocol.util.BitArray)1 ProcTimeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.proc.time.object.ProcTimeBuilder)1