use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testRPObjectWithTlv.
@Test
public void testRPObjectWithTlv() throws PCEPDeserializerException, IOException {
final PCEPRequestParameterObjectParser parser = new PCEPRequestParameterObjectParser(this.tlvRegistry, this.viTlvRegistry);
ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject1.bin"));
final RpBuilder builder = new RpBuilder();
builder.setProcessingRule(true);
builder.setIgnore(true);
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().build());
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
ByteBuf buf = Unpooled.buffer();
parser.serializeObject(builder.build(), buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRPObject2.bin"));
builder.setReoptimization(false);
builder.setFragmentation(true);
builder.setEroCompression(true);
final OrderBuilder b = new OrderBuilder();
b.setDelete(0xffffffffL);
b.setSetup(1L);
builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.rp.TlvsBuilder().setOrder(b.build()).build());
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
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.RequestId in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testErrorObjectWithTlv.
@Test
public void testErrorObjectWithTlv() throws PCEPDeserializerException, IOException {
final PCEPErrorObjectParser parser = new PCEPErrorObjectParser(this.tlvRegistry, this.viTlvRegistry);
ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject1.bin"));
final ErrorObjectBuilder builder = new ErrorObjectBuilder();
builder.setProcessingRule(true);
builder.setIgnore(true);
builder.setType((short) 1);
builder.setValue((short) 1);
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
ByteBuf buf = Unpooled.buffer();
parser.serializeObject(builder.build(), buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject3.bin"));
builder.setType((short) 7);
builder.setValue((short) 0);
builder.setTlvs(new TlvsBuilder().setReqMissing(new ReqMissingBuilder().setRequestId(new RequestId(0x00001155L)).build()).build());
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
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.RequestId 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId in project bgpcep by opendaylight.
the class PCEPTlvParserTest method testReqMissingTlv.
@Test
public void testReqMissingTlv() throws PCEPDeserializerException {
final ReqMissingTlvParser parser = new ReqMissingTlvParser();
final ReqMissing tlv = new ReqMissingBuilder().setRequestId(new RequestId(0xF7823517L)).build();
assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(reqMissingBytes, 4))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(reqMissingBytes, ByteArray.getAllBytes(buff));
assertNull(parser.parseTlv(null));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId in project bgpcep by opendaylight.
the class ReqMissingTlvParser method serializeTlv.
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
Preconditions.checkArgument(tlv instanceof ReqMissing, "ReqMissingTlv is mandatory.");
final ReqMissing req = (ReqMissing) tlv;
final ByteBuf body = Unpooled.buffer();
Preconditions.checkArgument(req.getRequestId() != null, "RequestId is mandatory.");
writeUnsignedInt(req.getRequestId().getValue(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
Aggregations