use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject in project bgpcep by opendaylight.
the class AbstractSrSubobjectParser method serializeSubobject.
public ByteBuf serializeSubobject(final SrSubobject srSubobject) {
checkArgument(srSubobject.getNai() != null || srSubobject.getSid() != null, "Both SID and NAI are absent in SR subobject.");
final ByteBuf buffer = Unpooled.buffer(MINIMAL_LENGTH);
/* Write NAI Type */
buffer.writeByte(srSubobject.getNaiType().getIntValue() << NAI_TYPE_BITS_OFFSET);
/* Flags set according to RFC8664#section 4.3.1 */
final BitArray bits = new BitArray(BITSET_LENGTH);
bits.set(M_FLAG_POSITION, srSubobject.getMFlag());
/* C flag MUST be set to 0 if M flag is set to 0 */
if (!srSubobject.getMFlag()) {
bits.set(C_FLAG_POSITION, Boolean.FALSE);
} else {
bits.set(C_FLAG_POSITION, srSubobject.getCFlag());
}
/* M & C flags MUST be set to 0 if S flag is set to 1 */
if (srSubobject.getSid() == null) {
bits.set(M_FLAG_POSITION, Boolean.FALSE);
bits.set(C_FLAG_POSITION, Boolean.FALSE);
bits.set(S_FLAG_POSITION, Boolean.TRUE);
}
/* F flag MUST be set if NT=0 or NAI is absent */
if (srSubobject.getNai() == null || srSubobject.getNaiType().getIntValue() == 0) {
bits.set(F_FLAG_POSITION, Boolean.TRUE);
}
/* Write Flags */
bits.toByteBuf(buffer);
/* Write SID */
if (srSubobject.getSid() != null) {
if (srSubobject.getMFlag()) {
buffer.writeInt(srSubobject.getSid().intValue() << MPLS_LABEL_OFFSET);
} else {
ByteBufUtils.writeOrZero(buffer, srSubobject.getSid());
}
}
/* Write NAI */
final Nai nai = srSubobject.getNai();
if (nai != null) {
serializeNai(nai, srSubobject.getNaiType(), buffer);
}
return buffer;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject in project bgpcep by opendaylight.
the class AbstractSrSubobjectParser method parseSrSubobject.
protected static SrSubobject parseSrSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
final int naiTypeByte = buffer.readByte() >> NAI_TYPE_BITS_OFFSET;
final NaiType naiType = NaiType.forValue(naiTypeByte);
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.");
}
final Uint32 sid;
if (!s) {
final long tmp = buffer.readUnsignedInt();
sid = Uint32.valueOf(m ? tmp >> MPLS_LABEL_OFFSET : tmp);
} else {
sid = null;
}
final Nai nai;
if (naiType != null && naiType.getIntValue() != 0 && !f) {
nai = parseNai(naiType, buffer);
} else {
nai = null;
}
return new SrSubobjectImpl(m, c, naiType, sid, nai);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject in project bgpcep by opendaylight.
the class SrRroSubobjectParser method parseSubobject.
@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
final SrRroTypeBuilder srRroSubobjectBuilder = new SrRroTypeBuilder(parseSrSubobject(buffer));
final SubobjectBuilder subobjectBuilder = new SubobjectBuilder();
subobjectBuilder.setSubobjectType(srRroSubobjectBuilder.build());
return subobjectBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject in project bgpcep by opendaylight.
the class SrEroSubobjectParser method parseSubobject.
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
final SrEroTypeBuilder srEroSubobjectBuilder = new SrEroTypeBuilder(parseSrSubobject(buffer));
final SubobjectBuilder subobjectBuilder = new SubobjectBuilder();
subobjectBuilder.setLoose(loose);
subobjectBuilder.setSubobjectType(srEroSubobjectBuilder.build());
return subobjectBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject 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.getLoose(), body, buffer);
}
Aggregations