Search in sources :

Example 86 with Subobject

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.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;
}
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 87 with Subobject

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.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);
}
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 88 with Subobject

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.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();
}
Also used : SrRroTypeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.add.lsp.input.arguments.rro.subobject.subobject.type.SrRroTypeBuilder) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder)

Example 89 with Subobject

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.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();
}
Also used : SrEroTypeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.add.lsp.input.arguments.ero.subobject.subobject.type.SrEroTypeBuilder) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder)

Example 90 with Subobject

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.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);
}
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)59 ArrayList (java.util.ArrayList)24 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)23 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)15 Subobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject)15 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder)14 BitArray (org.opendaylight.protocol.util.BitArray)13 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)13 IpPrefixSubobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject)12 PathKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey)11 IpPrefixCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase)10 Attribute (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute)9 PceId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId)8 IpPrefixCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder)8 IpPrefixBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder)8 Preconditions (com.google.common.base.Preconditions)7 EroBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.EroBuilder)7 SubobjectType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType)6 RSVPParsingException (org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException)5 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)5