Search in sources :

Example 16 with ProtocolId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.ProtocolId in project bgpcep by opendaylight.

the class PrefixAttributesParser method parsePrefixAttributes.

/**
 * Parse prefix attributes.
 *
 * @param attributes key is the tlv type and value are the value bytes of the tlv
 * @param protocolId to differentiate parsing methods
 * @return {@link LinkStateAttribute}
 */
static LinkStateAttribute parsePrefixAttributes(final Multimap<Integer, ByteBuf> attributes, final ProtocolId protocolId) {
    final PrefixAttributesBuilder builder = new PrefixAttributesBuilder();
    final List<RouteTag> routeTags = new ArrayList<>();
    final List<ExtendedRouteTag> exRouteTags = new ArrayList<>();
    for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
        final int key = entry.getKey();
        final ByteBuf value = entry.getValue();
        LOG.trace("Prefix attribute TLV {}", key);
        parseAttribute(key, value, protocolId, builder, routeTags, exRouteTags);
    }
    LOG.trace("Finished parsing Prefix Attributes.");
    builder.setRouteTags(routeTags);
    builder.setExtendedTags(exRouteTags);
    return new PrefixAttributesCaseBuilder().setPrefixAttributes(builder.build()).build();
}
Also used : ExtendedRouteTag(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.ExtendedRouteTag) ArrayList(java.util.ArrayList) PrefixAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributesBuilder) ByteBuf(io.netty.buffer.ByteBuf) RouteTag(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.RouteTag) ExtendedRouteTag(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.ExtendedRouteTag) PrefixAttributesCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.link.state.attribute.PrefixAttributesCaseBuilder)

Example 17 with ProtocolId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.ProtocolId in project bgpcep by opendaylight.

the class PrefixAttributesParser method parseBindingSid.

private static void parseBindingSid(final PrefixAttributesBuilder builder, final ByteBuf value, final ProtocolId protocolId) {
    final List<SrBindingSidLabels> labels;
    if (builder.getSrBindingSidLabels() != null) {
        labels = builder.getSrBindingSidLabels();
    } else {
        labels = new ArrayList<>();
        builder.setSrBindingSidLabels(labels);
    }
    final SrBindingSidLabels label = BindingSidLabelParser.parseBindingSidLabel(value, protocolId);
    labels.add(label);
    LOG.debug("Parsed SR Binding SID {}", label);
}
Also used : SrBindingSidLabels(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrBindingSidLabels)

Example 18 with ProtocolId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.ProtocolId in project bgpcep by opendaylight.

the class RangeTlvParser method parseSrRange.

public static SrRange parseSrRange(final ByteBuf buffer, final ProtocolId protocolId) {
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
    final SrRangeBuilder range = new SrRangeBuilder();
    if (protocolId.equals(ProtocolId.Ospf)) {
        range.setInterArea(flags.get(INNER_AREA));
    } else {
        range.setInterArea(Boolean.FALSE);
    }
    buffer.skipBytes(RESERVED);
    range.setRangeSize(buffer.readUnsignedShort());
    range.setSubTlvs(parseRangeSubTlvs(buffer, protocolId));
    return range.build();
}
Also used : SrRangeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRangeBuilder) BitArray(org.opendaylight.protocol.util.BitArray)

Example 19 with ProtocolId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.ProtocolId in project bgpcep by opendaylight.

the class RangeTlvParser method parseRangeSubTlvs.

private static List<SubTlvs> parseRangeSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) {
    final List<SubTlvs> subTlvs = new ArrayList<>();
    while (buffer.isReadable()) {
        final SubTlvsBuilder subTlv = new SubTlvsBuilder();
        final RangeSubTlv subTlvCase;
        final int type = buffer.readUnsignedShort();
        final int length = buffer.readUnsignedShort();
        switch(type) {
            case PREFIX_SID:
                subTlvCase = new PrefixSidTlvCaseBuilder(SrPrefixAttributesParser.parseSrPrefix(buffer.readSlice(length), protocolId)).build();
                break;
            case IPV6_PREFIX_SID:
                subTlvCase = new Ipv6PrefixSidTlvCaseBuilder(Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(buffer.readSlice(length))).build();
                break;
            case BINDING_SID:
                subTlvCase = new BindingSidTlvCaseBuilder(BindingSidLabelParser.parseBindingSidLabel(buffer.readSlice(length), protocolId)).build();
                break;
            case SID_TYPE:
                subTlvCase = new SidLabelTlvCaseBuilder().setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex(Size.forValue(length), buffer.readSlice(length))).build();
                break;
            default:
                LOG.info("Unknown type of range sub-tlv: {}", type);
                buffer.skipBytes(length);
                continue;
        }
        subTlvs.add(subTlv.setRangeSubTlv(subTlvCase).build());
    }
    return subTlvs;
}
Also used : SubTlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.tlv.SubTlvsBuilder) RangeSubTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.sub.tlvs.RangeSubTlv) ArrayList(java.util.ArrayList) Ipv6PrefixSidTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.sub.tlvs.range.sub.tlv.Ipv6PrefixSidTlvCaseBuilder) Ipv6PrefixSidTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.sub.tlvs.range.sub.tlv.Ipv6PrefixSidTlvCaseBuilder) PrefixSidTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.sub.tlvs.range.sub.tlv.PrefixSidTlvCaseBuilder) SubTlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.tlv.SubTlvs) SidLabelTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.sub.tlvs.range.sub.tlv.SidLabelTlvCaseBuilder) BindingSidTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.sub.tlvs.range.sub.tlv.BindingSidTlvCaseBuilder)

Example 20 with ProtocolId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.ProtocolId in project bgpcep by opendaylight.

the class SrLinkAttributesParser method parseLanAdjacencySegmentIdentifier.

public static SrLanAdjIds parseLanAdjacencySegmentIdentifier(final ByteBuf buffer, final ProtocolId protocolId) {
    if (!buffer.isReadable()) {
        return new SrLanAdjIdsBuilder().build();
    }
    final SrLanAdjIdsBuilder srLanAdjIdBuilder = new SrLanAdjIdsBuilder();
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE);
    srLanAdjIdBuilder.setFlags(parseFlags(flags, protocolId));
    srLanAdjIdBuilder.setWeight(new Weight(buffer.readUnsignedByte()));
    buffer.skipBytes(RESERVED);
    switch(protocolId) {
        case IsisLevel1:
        case IsisLevel2:
            srLanAdjIdBuilder.setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(buffer, ISO_SYSTEM_ID_SIZE)));
            break;
        case Ospf:
        case OspfV3:
            srLanAdjIdBuilder.setNeighborId(Ipv4Util.addressForByteBuf(buffer));
            break;
        default:
            return null;
    }
    // length determines a type of next field, which is used for parsing
    srLanAdjIdBuilder.setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer));
    return srLanAdjIdBuilder.build();
}
Also used : SrLanAdjIdsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.attribute.SrLanAdjIdsBuilder) IsoSystemIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier) BitArray(org.opendaylight.protocol.util.BitArray) Weight(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)9 Test (org.junit.Test)6 BitArray (org.opendaylight.protocol.util.BitArray)6 BigInteger (java.math.BigInteger)5 ArrayList (java.util.ArrayList)5 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)5 DomainIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.DomainIdentifier)5 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)5 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)4 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)4 ImmutableLeafNodeBuilder (org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder)4 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)3 Identifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Identifier)3 CLinkstateDestination (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.destination.CLinkstateDestination)3 IsoSystemIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier)3 AreaIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.AreaIdentifier)2 Ipv4InterfaceIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Ipv4InterfaceIdentifier)2 Ipv4RouterIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Ipv4RouterIdentifier)2 Ipv6RouterIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Ipv6RouterIdentifier)2 OspfInterfaceIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.OspfInterfaceIdentifier)2