use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject in project bgpcep by opendaylight.
the class RROIpv6PrefixSubobjectParser method parseSubobject.
@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
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);
final SubobjectBuilder builder = new SubobjectBuilder().setProtectionAvailable(flags.get(LPA_F_OFFSET)).setProtectionInUse(flags.get(LPIU_F_OFFSET)).setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject in project bgpcep by opendaylight.
the class RROPathKey128SubobjectParser method serializeSubobject.
public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
final ByteBuf body = Unpooled.buffer();
final PathKey pathKey = pk.getPathKey();
checkArgument(pathKey != null, "PathKey is mandatory.");
ByteBufUtils.write(body, pathKey.getValue());
final PceId pceId = pk.getPceId();
checkArgument(pceId != null, "PceId is mandatory.");
body.writeBytes(pceId.getValue());
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject 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<Subobject> subs = new ArrayList<>();
for (final PathKeys pk : pkey.nonnullPathKeys()) {
subs.add(new SubobjectBuilder().setLoose(pk.getLoose()).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(pk.getPathKey()).setPceId(pk.getPceId()).build()).build()).build());
}
serializeSubobject(subs, body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject in project bgpcep by opendaylight.
the class PCEPSecondaryExplicitRouteObjecParser method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
Preconditions.checkArgument(object instanceof Sero, "Wrong instance of PCEPObject. Passed %s. Needed EroObject.", object.getClass());
final Sero sero = (Sero) object;
final ByteBuf body = Unpooled.buffer();
final List<Subobject> subObjects = sero.nonnullSubobject().stream().map(so -> new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder().setLoose(so.getLoose()).setSubobjectType(so.getSubobjectType()).build()).collect(Collectors.toList());
serializeSubobject(subObjects, body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject in project bgpcep by opendaylight.
the class AbstractEROWithSubobjectsParser method parseSubobjects.
protected List<Subobject> parseSubobjects(final ByteBuf buffer) throws PCEPDeserializerException {
// Explicit approval of empty ERO
Preconditions.checkArgument(buffer != null, "Array of bytes is mandatory. Can't be null.");
final List<Subobject> subs = new ArrayList<>();
while (buffer.isReadable()) {
final boolean loose = (buffer.getUnsignedByte(buffer.readerIndex()) & 1 << Values.FIRST_BIT_OFFSET) != 0;
final int type = buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES & ~(1 << Values.FIRST_BIT_OFFSET);
final int length = buffer.readUnsignedByte() - HEADER_LENGTH;
if (length > buffer.readableBytes()) {
throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= " + buffer.readableBytes());
}
LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer));
final Subobject sub = this.subobjReg.parseSubobject(type, buffer.readSlice(length), loose);
if (sub == null) {
LOG.warn("Parsing failed for subobject type: {}. Ignoring subobject.", type);
} else {
LOG.debug("Subobject was parsed. {}", sub);
subs.add(sub);
}
}
return subs;
}
Aggregations