Search in sources :

Example 1 with SrSubobject

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.SrSubobject in project bgpcep by opendaylight.

the class SrRroSubobjectParser method serializeSubobject.

@Override
public void serializeSubobject(Subobject subobject, ByteBuf buffer) {
    final SubobjectType subobjType = subobject.getSubobjectType();
    checkArgument(subobjType instanceof SrSubobject, "Unknown subobject instance. Passed %s. Needed SrSubobject.", subobjType.getClass());
    final SrSubobject srSubobject = (SrSubobject) subobjType;
    final ByteBuf body = serializeSubobject(srSubobject);
    RROSubobjectUtil.formatSubobject(this.type, body, buffer);
}
Also used : SubobjectType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.SubobjectType) SrSubobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.SrSubobject) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with SrSubobject

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.SrSubobject 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;
}
Also used : Nai(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.Nai) BitArray(org.opendaylight.protocol.util.BitArray) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with SrSubobject

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.SrSubobject 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);
}
Also used : Nai(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.Nai) NaiType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.NaiType) BitArray(org.opendaylight.protocol.util.BitArray) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 4 with SrSubobject

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.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.getLoose(), body, buffer);
}
Also used : SrSubobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.SrSubobject) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)3 BitArray (org.opendaylight.protocol.util.BitArray)2 SrSubobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.SrSubobject)2 Nai (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.Nai)2 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)1 NaiType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.NaiType)1 SubobjectType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.SubobjectType)1 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)1