use of org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testGlobalConstraintsObject.
@Test
public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException {
final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry, this.viTlvRegistry);
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin"));
final GcBuilder builder = new GcBuilder();
builder.setProcessingRule(true);
builder.setIgnore(false);
builder.setMaxHop((short) 1);
builder.setMaxUtilization((short) 0);
builder.setMinUtilization((short) 100);
builder.setOverBookingFactor((short) 99);
builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.gc.TlvsBuilder().build());
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.protocol.pcep.spi.ObjectHeaderImpl 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.protocol.pcep.spi.ObjectHeaderImpl in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testRpObjectWithPstTlvParser.
@Test
public void testRpObjectWithPstTlvParser() throws PCEPDeserializerException {
final byte[] rpObjectWithPstTlvBytes = { 0x2, 0x10, 0x0, 0x14, 0x0, 0x0, 0x4, 0x2d, (byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef, /* pst-tlv */
0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0 };
final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
final RpBuilder builder = new RpBuilder();
builder.setProcessingRule(false);
builder.setIgnore(false);
builder.setReoptimization(true);
builder.setBiDirectional(false);
builder.setLoose(true);
builder.setMakeBeforeBreak(true);
builder.setOrder(false);
builder.setPathKey(false);
builder.setSupplyOf(false);
builder.setFragmentation(false);
builder.setP2mp(false);
builder.setEroCompression(false);
builder.setPriority((short) 5);
builder.setRequestId(new RequestId(0xdeadbeefL));
builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setPathSetupType(new PathSetupTypeBuilder().setPst((short) 0).build()).build());
final ByteBuf result = Unpooled.wrappedBuffer(rpObjectWithPstTlvBytes);
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer();
parser.serializeObject(builder.build(), buf);
assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
}
use of org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testOverloadObject.
@Test
public void testOverloadObject() throws PCEPDeserializerException {
final byte[] overloadBytes = { /* object header */
0x1B, 0x10, 0x00, 0x08, /* overload duration */
0x00, 0x00, 0x00, 0x78 };
final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser();
final Overload overload = new OverloadBuilder().setDuration(120).build();
final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes);
assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer(overloadBytes.length);
parser.serializeObject(overload, buf);
assertArrayEquals(overloadBytes, buf.array());
}
use of org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl 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