use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev171025.SrSubobject in project bgpcep by opendaylight.
the class SrRroSubobjectParser method serializeSubobject.
@Override
public void serializeSubobject(Subobject subobject, ByteBuf buffer) {
Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrSubobject, "Unknown subobject instance. Passed %s. Needed SrSubobject.", subobject.getSubobjectType().getClass());
final SrSubobject srSubobject = (SrSubobject) subobject.getSubobjectType();
final ByteBuf body = serializeSubobject(srSubobject);
RROSubobjectUtil.formatSubobject(this.type, body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev171025.SrSubobject 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev171025.SrSubobject 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev171025.SrSubobject in project bgpcep by opendaylight.
the class SrEroSubobjectParser method serializeSubobject.
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrSubobject, "Unknown subobject instance. Passed %s. Needed SrSubobject.", subobject.getSubobjectType().getClass());
final SrSubobject srSubobject = (SrSubobject) subobject.getSubobjectType();
final ByteBuf body = serializeSubobject(srSubobject);
EROSubobjectUtil.formatSubobject(this.type, subobject.isLoose(), body, buffer);
}
Aggregations