use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.load.balancing.object.LoadBalancingBuilder in project bgpcep by opendaylight.
the class PCEPLoadBalancingObjectParser method parseObject.
@Override
public LoadBalancing parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (bytes.readableBytes() != SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: " + SIZE + ".");
}
bytes.skipBytes(RESERVED + FLAGS_F_LENGTH);
return new LoadBalancingBuilder().setIgnore(header.getIgnore()).setProcessingRule(header.getProcessingRule()).setMaxLsp(ByteBufUtils.readUint8(bytes)).setMinBandwidth(new Bandwidth(ByteArray.readAllBytes(bytes))).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.load.balancing.object.LoadBalancingBuilder in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testLoadBalancingObject.
@Test
public void testLoadBalancingObject() throws IOException, PCEPDeserializerException {
final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser();
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin"));
final LoadBalancingBuilder builder = new LoadBalancingBuilder().setProcessingRule(true).setIgnore(false).setMaxLsp(Uint8.valueOf(0xf1)).setMinBandwidth(new Bandwidth(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
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());
}
}
Aggregations