use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.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();
builder.setProcessingRule(true);
builder.setIgnore(false);
builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
builder.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());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.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 {
Preconditions.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 + ".");
}
final LoadBalancingBuilder builder = new LoadBalancingBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
bytes.skipBytes(RESERVED + FLAGS_F_LENGTH);
builder.setMaxLsp(bytes.readUnsignedByte());
builder.setMinBandwidth(new Bandwidth(ByteArray.readAllBytes(bytes)));
return builder.build();
}
Aggregations