Search in sources :

Example 1 with NaiType

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

the class AbstractSrSubobjectParser method serializeNai.

private static void serializeNai(final Nai nai, final NaiType naiType, final ByteBuf buffer) {
    switch(naiType) {
        case Ipv4NodeId:
            Ipv4Util.writeIpv4Address(((IpNodeId) nai).getIpAddress().getIpv4AddressNoZone(), buffer);
            break;
        case Ipv6NodeId:
            Ipv6Util.writeIpv6Address(((IpNodeId) nai).getIpAddress().getIpv6AddressNoZone(), buffer);
            break;
        case Ipv4Adjacency:
            Ipv4Util.writeIpv4Address(((IpAdjacency) nai).getLocalIpAddress().getIpv4AddressNoZone(), buffer);
            Ipv4Util.writeIpv4Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv4AddressNoZone(), buffer);
            break;
        case Ipv6Adjacency:
            Ipv6Util.writeIpv6Address(((IpAdjacency) nai).getLocalIpAddress().getIpv6AddressNoZone(), buffer);
            Ipv6Util.writeIpv6Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv6AddressNoZone(), buffer);
            break;
        case Unnumbered:
            final UnnumberedAdjacency unnumbered = (UnnumberedAdjacency) nai;
            ByteBufUtils.writeOrZero(buffer, unnumbered.getLocalNodeId());
            ByteBufUtils.writeOrZero(buffer, unnumbered.getLocalInterfaceId());
            ByteBufUtils.writeOrZero(buffer, unnumbered.getRemoteNodeId());
            ByteBufUtils.writeOrZero(buffer, unnumbered.getRemoteInterfaceId());
            break;
        case Ipv6Local:
            final Ipv6Local ipv6Local = (Ipv6Local) nai;
            Ipv6Util.writeIpv6Address(ipv6Local.getLocalIpv6Address(), buffer);
            ByteBufUtils.writeOrZero(buffer, ipv6Local.getLocalId());
            Ipv6Util.writeIpv6Address(ipv6Local.getRemoteIpv6Address(), buffer);
            ByteBufUtils.writeOrZero(buffer, ipv6Local.getRemoteId());
            break;
        default:
            break;
    }
}
Also used : IpNodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.nai.IpNodeId) UnnumberedAdjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.nai.UnnumberedAdjacency) IpAdjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.nai.IpAdjacency) Ipv6Local(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.nai.Ipv6Local)

Example 2 with NaiType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.NaiType 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)

Aggregations

PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)1 BitArray (org.opendaylight.protocol.util.BitArray)1 NaiType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.NaiType)1 Nai (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.Nai)1 IpAdjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.nai.IpAdjacency)1 IpNodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.nai.IpNodeId)1 Ipv6Local (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.nai.Ipv6Local)1 UnnumberedAdjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.nai.UnnumberedAdjacency)1 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)1