Search in sources :

Example 1 with ProcTime

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

the class PCEPProcTimeObjectParser method serializeObject.

@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
    Preconditions.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.isEstimated());
    flagBits.toByteBuf(body);
    ByteBufWriteUtil.writeUnsignedInt(procTime.getCurrentProcTime(), body);
    ByteBufWriteUtil.writeUnsignedInt(procTime.getMinProcTime(), body);
    ByteBufWriteUtil.writeUnsignedInt(procTime.getMaxProcTime(), body);
    ByteBufWriteUtil.writeUnsignedInt(procTime.getAverageProcTime(), body);
    ByteBufWriteUtil.writeUnsignedInt(procTime.getVarianceProcTime(), body);
    ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
Also used : ProcTime(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.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.rev131005.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(4L).setCurrentProcTime(1L).setMaxProcTime(3L).setMinProcTime(2L).setVarianceProcTime(5L).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.rev131005.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.rev131005.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.rev131005.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.rev131005.proc.time.object.ProcTimeBuilder)1