use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class PCEPRequestParameterObjectParser method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
Preconditions.checkArgument(object instanceof Rp, "Wrong instance of PCEPObject. Passed %s. Needed RPObject.", object.getClass());
final ByteBuf body = Unpooled.buffer();
final Rp rpObj = (Rp) object;
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(R_FLAG_OFFSET, rpObj.isReoptimization());
flags.set(B_FLAG_OFFSET, rpObj.isBiDirectional());
flags.set(O_FLAG_OFFSET, rpObj.isLoose());
flags.set(M_FLAG_OFFSET, rpObj.isMakeBeforeBreak());
flags.set(D_FLAG_OFFSET, rpObj.isOrder());
flags.set(P_FLAG_OFFSET, rpObj.isPathKey());
flags.set(S_FLAG_OFFSET, rpObj.isSupplyOf());
flags.set(F_FLAG_OFFSET, rpObj.isFragmentation());
flags.set(N_FLAG_OFFSET, rpObj.isP2mp());
flags.set(E_FLAG_OFFSET, rpObj.isEroCompression());
final byte[] res = flags.array();
if (rpObj.getPriority() != null) {
final byte p = UnsignedBytes.checkedCast(rpObj.getPriority());
res[res.length - 1] = (byte) (res[res.length - 1] | p);
}
body.writeBytes(res);
Preconditions.checkArgument(rpObj.getRequestId() != null, "RequestId is mandatory");
writeUnsignedInt(rpObj.getRequestId().getValue(), body);
serializeTlvs(rpObj.getTlvs(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class PCEPSvecObjectParser method parseObject.
@Override
public Svec parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (bytes.readableBytes() < MIN_SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: >=" + MIN_SIZE + ".");
}
bytes.skipBytes(FLAGS_F_OFFSET);
final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
final List<RequestId> requestIDs = Lists.newArrayList();
while (bytes.isReadable()) {
requestIDs.add(new RequestId(bytes.readUnsignedInt()));
}
if (requestIDs.isEmpty()) {
throw new PCEPDeserializerException("Empty Svec Object - no request ids.");
}
final SvecBuilder builder = new SvecBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
builder.setLinkDiverse(flags.get(L_FLAG_OFFSET));
builder.setNodeDiverse(flags.get(N_FLAG_OFFSET));
builder.setSrlgDiverse(flags.get(S_FLAG_OFFSET));
builder.setRequestsIds(requestIDs);
return builder.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class PCEPMetricObjectParser method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
Preconditions.checkArgument(object instanceof Metric, "Wrong instance of PCEPObject. Passed %s. Needed MetricObject.", object.getClass());
final Metric mObj = (Metric) object;
final ByteBuf body = Unpooled.buffer(SIZE);
body.writeZero(RESERVED);
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(C_FLAG_OFFSET, mObj.isComputed());
flags.set(B_FLAG_OFFSET, mObj.isBound());
flags.toByteBuf(body);
Preconditions.checkArgument(mObj.getMetricType() != null, "MetricType is mandatory.");
writeUnsignedByte(mObj.getMetricType(), body);
writeFloat32(mObj.getValue(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class RROIpv4PrefixSubobjectParser 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.");
if (buffer.readableBytes() != CONTENT4_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
}
final SubobjectBuilder builder = new SubobjectBuilder();
final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET);
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefix prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH), length))).build();
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());
return builder.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class RROIpv6PrefixSubobjectParser 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();
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(CONTENT_LENGTH);
Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
writeIpv6Prefix(prefix.getIpv6Prefix(), body);
flags.toByteBuf(body);
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
Aggregations