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