use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder in project bgpcep by opendaylight.
the class AbstractPCEPSessionTest method createEroWithIpPrefixes.
Ero createEroWithIpPrefixes(final List<String> ipPrefixes) {
final List<Subobject> subobjs = new ArrayList<>(ipPrefixes.size());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder();
for (final String ipPrefix : ipPrefixes) {
subobjBuilder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix(ipPrefix))).build()).build());
subobjs.add(subobjBuilder.build());
}
return new EroBuilder().setSubobject(subobjs).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder in project bgpcep by opendaylight.
the class PCEPRROSubobjectParserTest method testRROIp4PrefixSubobject.
@Test
public void testRROIp4PrefixSubobject() throws PCEPDeserializerException {
final RROIpv4PrefixSubobjectParser parser = new RROIpv4PrefixSubobjectParser();
final SubobjectBuilder subs = new SubobjectBuilder();
subs.setProtectionAvailable(true);
subs.setProtectionInUse(false);
subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build()).build());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip4PrefixBytes, 2))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeSubobject(subs.build(), buff);
assertArrayEquals(ip4PrefixBytes, ByteArray.getAllBytes(buff));
try {
parser.parseSubobject(null);
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);
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.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder in project bgpcep by opendaylight.
the class PCEPRROSubobjectParserTest method testRROIp6PrefixSubobject.
@Test
public void testRROIp6PrefixSubobject() throws PCEPDeserializerException {
final RROIpv6PrefixSubobjectParser parser = new RROIpv6PrefixSubobjectParser();
final SubobjectBuilder subs = new SubobjectBuilder();
subs.setProtectionAvailable(false);
subs.setProtectionInUse(true);
subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build()).build());
assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip6PrefixBytes, 2))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeSubobject(subs.build(), buff);
assertArrayEquals(ip6PrefixBytes, ByteArray.getAllBytes(buff));
try {
parser.parseSubobject(null);
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);
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.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder in project bgpcep by opendaylight.
the class RROIpv6PrefixSubobjectParser method parseSubobject.
@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final SubobjectBuilder builder = new SubobjectBuilder();
if (buffer.readableBytes() != CONTENT_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
}
final int length = buffer.getUnsignedByte(PREFIX_F_OFFSET);
final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH), length)));
buffer.skipBytes(PREFIX_F_LENGTH);
final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder in project bgpcep by opendaylight.
the class XROIpv4PrefixSubobjectParser method parseSubobject.
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException {
Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final SubobjectBuilder builder = new SubobjectBuilder();
builder.setMandatory(mandatory);
if (buffer.readableBytes() != CONTENT4_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
}
final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET);
final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH), length)));
builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
buffer.skipBytes(PREFIX_F_LENGTH);
builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte()));
return builder.build();
}
Aggregations