use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject 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.pcep.types.rev131005.explicit.route.object.ero.Subobject in project bgpcep by opendaylight.
the class EROLabelSubobjectParser method parseSubobject.
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (buffer.readableBytes() < HEADER_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" + HEADER_LENGTH + ".");
}
final BitArray reserved = BitArray.valueOf(buffer, FLAGS_SIZE);
final short cType = buffer.readUnsignedByte();
final LabelType labelType = this.registry.parseLabel(cType, buffer.slice());
if (labelType == null) {
throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
}
final LabelBuilder builder = new LabelBuilder();
builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
builder.setLabelType(labelType);
return new SubobjectBuilder().setLoose(loose).setSubobjectType(new LabelCaseBuilder().setLabel(builder.build()).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject in project bgpcep by opendaylight.
the class GeneralizedLabelParser method serializeLabel.
@Override
public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) {
Preconditions.checkArgument(subobject instanceof GeneralizedLabelCase, "Unknown Label Subobject instance. Passed {}. Needed GeneralizedLabelCase.", subobject.getClass());
final GeneralizedLabel gl = ((GeneralizedLabelCase) subobject).getGeneralizedLabel();
Preconditions.checkArgument(gl != null, "GeneralizedLabel is mandatory.");
final ByteBuf body = Unpooled.wrappedBuffer(gl.getGeneralizedLabel());
LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject in project bgpcep by opendaylight.
the class RROIpv4PrefixSubobjectParser method serializeSubobject.
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
final IpPrefix prefix = specObj.getIpPrefix();
Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null, "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
if (prefix.getIpv6Prefix() != null) {
new RROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
} else {
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
writeIpv4Prefix(prefix.getIpv4Prefix(), body);
flags.toByteBuf(body);
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject 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();
}
Aggregations