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);
}
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());
}
Aggregations