use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKey in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method getRequests.
protected List<Requests> getRequests(final List<Object> objects, final List<Message> errors) {
final List<Requests> requests = new ArrayList<>();
while (!objects.isEmpty()) {
final RequestsBuilder rBuilder = new RequestsBuilder();
Rp rpObj = null;
if (!(objects.get(0) instanceof Rp)) {
// if RP obj is missing return error only
errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.absent()));
return null;
}
rpObj = (Rp) objects.get(0);
objects.remove(0);
if (!rpObj.isProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.absent()));
} else {
rBuilder.setRp(rpObj);
}
final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
if (!vendorInfo.isEmpty()) {
rBuilder.setVendorInformationObject(vendorInfo);
}
// expansion
if (rpObj.isPathKey() && objects.get(0) instanceof PathKey) {
rBuilder.setPathKeyExpansion(new PathKeyExpansionBuilder().setPathKey((PathKey) objects.get(0)).build());
}
final P2pBuilder p2pBuilder = new P2pBuilder();
if (!objects.isEmpty() && objects.get(0) instanceof EndpointsObj) {
final EndpointsObj ep = (EndpointsObj) objects.get(0);
objects.remove(0);
if (!ep.isProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rpObj)));
} else {
p2pBuilder.setEndpointsObj(ep);
}
} else {
errors.add(createErrorMsg(PCEPErrors.END_POINTS_MISSING, Optional.of(rpObj)));
return null;
}
// p2p
if (!rpObj.isP2mp()) {
final SegmentComputation segm = getSegmentComputation(p2pBuilder, objects, errors, rpObj);
if (segm != null) {
rBuilder.setSegmentComputation(segm);
}
}
requests.add(rBuilder.build());
}
return requests;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKey in project bgpcep by opendaylight.
the class PCEPPathKeyObjectParser method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
Preconditions.checkArgument(object instanceof PathKey, "Wrong instance of PCEPObject. Passed %s. Needed PathKeyObject.", object.getClass());
final PathKey pkey = (PathKey) object;
final ByteBuf body = Unpooled.buffer();
final List<PathKeys> pk = pkey.getPathKeys();
final List<Subobject> subs = new ArrayList<>();
for (final PathKeys p : pk) {
subs.add(new SubobjectBuilder().setLoose(p.isLoose()).setSubobjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder().setPathKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder().setPathKey(p.getPathKey()).setPceId(p.getPceId()).build()).build()).build());
}
serializeSubobject(subs, body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKey in project bgpcep by opendaylight.
the class PCEPXROSubobjectParserTest method testXROPathKey128Subobject.
@Test
public void testXROPathKey128Subobject() throws PCEPDeserializerException {
final XROPathKey128SubobjectParser parser = new XROPathKey128SubobjectParser();
final SubobjectBuilder subs = new SubobjectBuilder();
subs.setMandatory(true);
final PathKeyBuilder pBuilder = new PathKeyBuilder();
pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
pBuilder.setPathKey(new PathKey(4660));
subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey128Bytes, 2)), true));
final ByteBuf buff = Unpooled.buffer();
XROPathKey128SubobjectParser.serializeSubobject(subs.build(), buff);
assertArrayEquals(pathKey128Bytes, ByteArray.getAllBytes(buff));
try {
parser.parseSubobject(null, true);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
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.path.key.object.PathKey in project bgpcep by opendaylight.
the class EROSubobjectParserTest method testEROPathKey128Subobject.
@Test
public void testEROPathKey128Subobject() throws RSVPParsingException {
final EROPathKey128SubobjectParser parser128 = new EROPathKey128SubobjectParser();
final EROPathKey32SubobjectParser parser = new EROPathKey32SubobjectParser();
final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
subs.setLoose(true);
final PathKeyBuilder pBuilder = new PathKeyBuilder();
pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
pBuilder.setPathKey(new PathKey(4660));
subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
assertEquals(subs.build(), parser128.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY_128_BYTES, 2)), true));
final ByteBuf buff = Unpooled.buffer();
parser.serializeSubobject(subs.build(), buff);
Assert.assertArrayEquals(PATH_KEY_128_BYTES, ByteArray.getAllBytes(buff));
try {
parser128.parseSubobject(null, true);
Assert.fail();
} catch (final IllegalArgumentException e) {
Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
try {
parser128.parseSubobject(Unpooled.EMPTY_BUFFER, true);
Assert.fail();
} catch (final IllegalArgumentException e) {
Assert.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.path.key.object.PathKey in project bgpcep by opendaylight.
the class RROSubobjectParserTest method testRROPathKey128Subobject.
@Test
public void testRROPathKey128Subobject() throws RSVPParsingException {
final RROPathKey128SubobjectParser parser = new RROPathKey128SubobjectParser();
final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
final PathKeyBuilder pBuilder = new PathKeyBuilder();
pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
pBuilder.setPathKey(new PathKey(4660));
subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(PATH_KEY_128_BYTES, 2))));
final ByteBuf buff = Unpooled.buffer();
RROPathKey128SubobjectParser.serializeSubobject(subs.build(), buff);
Assert.assertArrayEquals(PATH_KEY_128_BYTES, ByteArray.getAllBytes(buff));
try {
parser.parseSubobject(null);
Assert.fail();
} catch (final IllegalArgumentException e) {
Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER);
Assert.fail();
} catch (final IllegalArgumentException e) {
Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
}
Aggregations