use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class Ipv4EroParser method serializeEroFlags.
static void serializeEroFlags(final ByteBuf buffer, final Boolean loose) {
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(LOOSE, loose);
flags.toByteBuf(buffer);
buffer.writeZero(RESERVED_ERO);
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class Ipv6EroParser method parseIpv6EroCase.
public static Ipv6EroCase parseIpv6EroCase(final ByteBuf buffer) {
final Ipv6EroCaseBuilder builder = new Ipv6EroCaseBuilder();
final BitArray flags = BitArray.valueOf(buffer, Ipv4EroParser.FLAGS_SIZE);
builder.setLoose(flags.get(Ipv4EroParser.LOOSE));
buffer.skipBytes(Ipv4EroParser.RESERVED_ERO);
builder.setAddress(Ipv6Util.addressForByteBuf(buffer));
return builder.build();
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class AbstractSrSubobjectParser method serializeSubobject.
public ByteBuf serializeSubobject(final SrSubobject srSubobject) {
final ByteBuf buffer = Unpooled.buffer(MINIMAL_LENGTH);
// sid type
writeUnsignedByte((short) (srSubobject.getSidType().getIntValue() << SID_TYPE_BITS_OFFSET), buffer);
final BitArray bits = new BitArray(BITSET_LENGTH);
bits.set(M_FLAG_POSITION, srSubobject.isMFlag());
bits.set(C_FLAG_POSITION, srSubobject.isCFlag());
if (srSubobject.getSid() == null) {
bits.set(S_FLAG_POSITION, Boolean.TRUE);
}
if (srSubobject.getNai() == null) {
bits.set(F_FLAG_POSITION, Boolean.TRUE);
}
// bits
bits.toByteBuf(buffer);
// sid
Preconditions.checkArgument(srSubobject.getNai() != null || srSubobject.getSid() != null, "Both SID and NAI are absent in SR subobject.");
if (srSubobject.getSid() != null) {
if (srSubobject.isMFlag()) {
writeUnsignedInt(srSubobject.getSid() << MPLS_LABEL_OFFSET, buffer);
} else {
writeUnsignedInt(srSubobject.getSid(), buffer);
}
}
// nai
final Nai nai = srSubobject.getNai();
if (nai != null) {
serializeNai(nai, srSubobject.getSidType(), buffer);
}
return buffer;
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class AbstractSrSubobjectParser method parseSrSubobject.
protected static SrSubobject parseSrSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
final int sidTypeByte = buffer.readByte() >> SID_TYPE_BITS_OFFSET;
final SidType sidType = SidType.forValue(sidTypeByte);
final BitArray bitSet = BitArray.valueOf(buffer.readByte());
final boolean f = bitSet.get(F_FLAG_POSITION);
final boolean s = bitSet.get(S_FLAG_POSITION);
final boolean c = bitSet.get(C_FLAG_POSITION);
final boolean m = bitSet.get(M_FLAG_POSITION);
if (f && s) {
throw new PCEPDeserializerException("Both SID and NAI are absent in SR subobject.");
}
Long tmp = null;
if (!s) {
if (m) {
tmp = buffer.readUnsignedInt() >>> MPLS_LABEL_OFFSET;
} else {
tmp = buffer.readUnsignedInt();
}
}
final Long sid = tmp;
final Nai nai;
if (sidType != null && !f) {
nai = parseNai(sidType, buffer);
} else {
nai = null;
}
return new SrSubobjectImpl(m, c, sidType, sid, nai);
}
use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.
the class ObjectUtil method formatSubobject.
public static void formatSubobject(final int objectType, final int objectClass, final Boolean processingRule, final Boolean ignore, final ByteBuf body, final ByteBuf out) {
out.writeByte(objectClass);
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(IGNORED, ignore);
flags.set(PROCESSED, processingRule);
final byte flagB = flags.toByte();
final int typeByte = objectType << FLAGS_SIZE | (flagB & 0xff);
out.writeByte(typeByte);
out.writeShort(body.writerIndex() + HEADER_SIZE);
out.writeBytes(body);
}
Aggregations