use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId in project bgpcep by opendaylight.
the class XROSRLGSubobjectParser method serializeSubobject.
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrlgCase, "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass());
final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
Preconditions.checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory.");
writeUnsignedInt(specObj.getSrlgId().getValue(), body);
Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
writeUnsignedByte(null, body);
writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId in project bgpcep by opendaylight.
the class XROSubobjectParserTest method testXROSrlgSubobject.
@Test
public void testXROSrlgSubobject() throws RSVPParsingException {
final XROSrlgSubobjectParser parser = new XROSrlgSubobjectParser();
final SubobjectContainerBuilder subs = new SubobjectContainerBuilder();
subs.setMandatory(true);
subs.setAttribute(ExcludeRouteSubobjects.Attribute.Srlg);
subs.setSubobjectType(new SrlgCaseBuilder().setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(0x12345678L)).build()).build());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(SRLG_BYTES, 2)), true));
final ByteBuf buff = Unpooled.buffer();
parser.serializeSubobject(subs.build(), buff);
Assert.assertArrayEquals(SRLG_BYTES, ByteArray.getAllBytes(buff));
try {
parser.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 {
parser.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.rsvp.rev150820.SrlgId in project bgpcep by opendaylight.
the class XROSrlgSubobjectParser method serializeSubobject.
@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrlgCase, "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass());
final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
Preconditions.checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory.");
writeUnsignedInt(specObj.getSrlgId().getValue(), body);
Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
writeUnsignedByte(null, body);
writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId in project bgpcep by opendaylight.
the class PCEPXROSubobjectParserTest method testXROSrlgSubobject.
@Test
public void testXROSrlgSubobject() throws PCEPDeserializerException {
final XROSRLGSubobjectParser parser = new XROSRLGSubobjectParser();
final SubobjectBuilder subs = new SubobjectBuilder();
subs.setMandatory(true);
subs.setAttribute(Attribute.Srlg);
subs.setSubobjectType(new SrlgCaseBuilder().setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(0x12345678L)).build()).build());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(srlgBytes, 2)), true));
final ByteBuf buff = Unpooled.buffer();
parser.serializeSubobject(subs.build(), buff);
assertArrayEquals(srlgBytes, 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.rsvp.rev150820.SrlgId in project bgpcep by opendaylight.
the class LinkAttributesParser method parseSrlg.
private static void parseSrlg(final ByteBuf value, final LinkAttributesBuilder builder) {
final List<SrlgId> sharedRiskLinkGroups = new ArrayList<>();
while (value.isReadable()) {
sharedRiskLinkGroups.add(new SrlgId(value.readUnsignedInt()));
}
builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
LOG.debug("Parsed Shared Risk Link Groups {}", builder.getSharedRiskLinkGroups());
}
Aggregations