Search in sources :

Example 1 with SrSubobject

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

Example 4 with SrSubobject

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);
}
Also used : SrSubobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev171025.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.rev171025.SrSubobject)2 Nai (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev171025.sr.subobject.Nai)2 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)1 SidType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev171025.SidType)1