Search in sources :

Example 6 with LinkStateAttribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute in project bgpcep by opendaylight.

the class LinkstateTopologyBuilder method createNode.

private void createNode(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final NodeCase nodeCase, final Attributes attributes) {
    final NodeAttributes na;
    // defensive lookup
    final Attributes1 attr = attributes.augmentation(Attributes1.class);
    if (attr != null) {
        final LinkStateAttribute attrType = attr.getLinkStateAttribute();
        if (attrType != null) {
            na = ((NodeAttributesCase) attrType).getNodeAttributes();
        } else {
            LOG.debug("Missing attribute type in node {} route {}, skipping it", nodeCase, value);
            na = null;
        }
    } else {
        LOG.debug("Missing attributes in node {} route {}, skipping it", nodeCase, value);
        na = null;
    }
    final IgpNodeAttributesBuilder inab = new IgpNodeAttributesBuilder();
    final List<IpAddress> ids = new ArrayList<>();
    Long srgbFirstValue = null;
    Integer srgbRangeSize = null;
    if (na != null) {
        if (na.getIpv4RouterId() != null) {
            ids.add(new IpAddress(na.getIpv4RouterId()));
        }
        if (na.getIpv6RouterId() != null) {
            ids.add(new IpAddress(na.getIpv6RouterId()));
        }
        if (na.getDynamicHostname() != null) {
            inab.setName(new DomainName(na.getDynamicHostname()));
        }
        if (na.getSrCapabilities() != null) {
            final SidLabelIndex sidLabelIndex = na.getSrCapabilities().getSidLabelIndex();
            if (sidLabelIndex instanceof LocalLabelCase) {
                srgbFirstValue = ((LocalLabelCase) sidLabelIndex).getLocalLabel().getValue().longValue();
            }
            srgbRangeSize = na.getSrCapabilities().getRangeSize() != null ? na.getSrCapabilities().getRangeSize().getValue().intValue() : null;
        }
    }
    if (!ids.isEmpty()) {
        inab.setRouterId(ids);
    }
    ProtocolUtil.augmentProtocolId(value, inab, na, nodeCase.getNodeDescriptors());
    final NodeId nid = buildNodeId(base, nodeCase.getNodeDescriptors());
    final NodeHolder nh = getNode(nid);
    /*
         *  Eventhough the the holder creates a dummy structure, we need to duplicate it here,
         *  as that is the API requirement. The reason for it is the possible presence of supporting
         *  node -- something which the holder does not track.
         */
    final NodeBuilder nb = new NodeBuilder();
    nb.setNodeId(nid);
    nb.withKey(new NodeKey(nb.getNodeId()));
    nh.advertized(nb, inab);
    if (srgbFirstValue != null && srgbRangeSize != null) {
        nh.createSrHolderIfRequired().addSrgb(trans, false, srgbFirstValue, srgbRangeSize);
    }
    putNode(trans, nh);
}
Also used : DomainName(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName) ArrayList(java.util.ArrayList) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.linkstate.route.Attributes1) LinkStateAttribute(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder) IgpNodeAttributesBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder) LocalLabelCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase) IgpNodeAttributes(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes) NodeAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) SidLabelIndex(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.SidLabelIndex) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)

Example 7 with LinkStateAttribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute 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.rev200120.ExtendedRouteTag) ArrayList(java.util.ArrayList) PrefixAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributesBuilder) ByteBuf(io.netty.buffer.ByteBuf) ExtendedRouteTag(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ExtendedRouteTag) RouteTag(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.RouteTag) PrefixAttributesCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.PrefixAttributesCaseBuilder)

Example 8 with LinkStateAttribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute in project bgpcep by opendaylight.

the class LinkstateAttributeParser method serializeAttribute.

/**
 * Serialize linkstate attributes.
 *
 * @param attribute DataObject representing LinkstatePathAttribute
 * @param byteAggregator ByteBuf where all serialized data are aggregated
 */
@Override
public void serializeAttribute(final Attributes attribute, final ByteBuf byteAggregator) {
    final Attributes1 pathAttributes1 = attribute.augmentation(Attributes1.class);
    if (pathAttributes1 == null) {
        return;
    }
    final LinkStateAttribute linkState = pathAttributes1.getLinkStateAttribute();
    final ByteBuf lsBuffer = Unpooled.buffer();
    if (linkState instanceof LinkAttributesCase) {
        LinkAttributesParser.serializeLinkAttributes((LinkAttributesCase) linkState, lsBuffer);
    } else if (linkState instanceof NodeAttributesCase) {
        NodeAttributesParser.serializeNodeAttributes((NodeAttributesCase) linkState, lsBuffer);
    } else if (linkState instanceof PrefixAttributesCase) {
        PrefixAttributesParser.serializePrefixAttributes((PrefixAttributesCase) linkState, lsBuffer);
    } else if (linkState instanceof TeLspAttributesCase) {
        TeLspAttributesParser.serializeLspAttributes(this.rsvpTeObjectRegistry, (TeLspAttributesCase) linkState, lsBuffer);
        byteAggregator.writeBytes(lsBuffer);
        return;
    }
    AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, getType(), lsBuffer, byteAggregator);
}
Also used : TeLspAttributesCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.TeLspAttributesCase) PrefixAttributesCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Attributes1) LinkStateAttribute(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute) ByteBuf(io.netty.buffer.ByteBuf) LinkAttributesCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase) NodeAttributesCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.NodeAttributesCase)

Example 9 with LinkStateAttribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute in project bgpcep by opendaylight.

the class TeLspAttributesParser method parseTeLspAttributes.

static LinkStateAttribute parseTeLspAttributes(final RSVPTeObjectRegistry registry, final ByteBuf attributes) throws BGPParsingException {
    final TeLspAttributesBuilder builder = new TeLspAttributesBuilder();
    LOG.trace("Initiated parsing TE LSP Objects.");
    while (attributes.isReadable()) {
        final int length = attributes.readUnsignedShort();
        final int classNum = attributes.readUnsignedByte();
        final int cType = attributes.readUnsignedByte();
        final ByteBuf value = attributes.readSlice(length);
        try {
            addObject(builder, registry.parseRSPVTe(classNum, cType, value));
        } catch (final RSVPParsingException e) {
            LOG.debug("Parsering TE LSP Object error. class number: {} cType: {} value: {}", classNum, cType, value, e);
            throw new BGPParsingException(e.getMessage(), e);
        }
    }
    LOG.trace("Finished parsing TE LSP Objects.");
    return new TeLspAttributesCaseBuilder().setTeLspAttributes(builder.build()).build();
}
Also used : TeLspAttributesCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.TeLspAttributesCaseBuilder) TeLspAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.te.lsp.attributes._case.TeLspAttributesBuilder) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) ByteBuf(io.netty.buffer.ByteBuf) RSVPParsingException(org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException)

Example 10 with LinkStateAttribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute in project bgpcep by opendaylight.

the class LinkstateGraphBuilder method createPrefix.

/**
 * Create new Prefix in the Connected Graph.
 *
 * @param value       The complete Linkstate route information
 * @param prefixCase  The Prefix part of the Linkstate route
 * @param attributes  The Prefix attributes
 */
private void createPrefix(final LinkstateRoute value, final PrefixCase prefixCase, final Attributes attributes) {
    final IpPrefix ippfx = prefixCase.getPrefixDescriptors().getIpReachabilityInformation();
    if (ippfx == null) {
        LOG.warn("IP reachability not present in prefix {} route {}, skipping it", prefixCase, value);
        return;
    }
    /* Verify that all mandatory information are present */
    final PrefixAttributes pa;
    final Attributes1 attr = attributes.augmentation(Attributes1.class);
    if (attr != null) {
        final LinkStateAttribute attrType = attr.getLinkStateAttribute();
        if (attrType instanceof PrefixAttributesCase) {
            pa = ((PrefixAttributesCase) attrType).getPrefixAttributes();
        } else {
            LOG.warn("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
            return;
        }
    } else {
        LOG.warn("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
        return;
    }
    /*
         * Get Connected Vertex from Connected Graph corresponding to the
         * Advertising Node Descriptor
         */
    Uint64 vertexId = getVertexId(prefixCase.getAdvertisingNodeDescriptors().getCRouterIdentifier());
    if (vertexId == Uint64.ZERO) {
        LOG.warn("Unable to get the Vertex Identifier from descriptor {}, skipping it", prefixCase.getAdvertisingNodeDescriptors());
        return;
    }
    /* Create Prefix */
    PrefixBuilder builder = new PrefixBuilder().setVertexId(vertexId).setPrefix(ippfx);
    if (pa.getSrPrefix() != null && pa.getSrPrefix().getSidLabelIndex() instanceof SidCase) {
        builder.setPrefixSid(((SidCase) pa.getSrPrefix().getSidLabelIndex()).getSid());
        if (pa.getSrPrefix().getFlags() instanceof IsisPrefixFlagsCase) {
            builder.setNodeSid(((IsisPrefixFlagsCase) pa.getSrPrefix().getFlags()).getIsisPrefixFlags().getNodeSid());
        } else {
            /*
                 * Seems that OSPF Flags are not accessible. Assuming that the
                 * Prefix is a Node SID
                 */
            builder.setNodeSid(true);
        }
    }
    Prefix prefix = builder.build();
    /* Add the Prefix to the Connected Vertex within the Connected Graph */
    LOG.info("Add prefix {} in TED[{}]", builder.getPrefix(), cgraph);
    cgraph.addPrefix(prefix);
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) IsisPrefixFlagsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.prefix.sid.tlv.flags.IsisPrefixFlagsCase) PrefixAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes) PrefixAttributesCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.linkstate.route.Attributes1) Prefix(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Prefix) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) LinkStateAttribute(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute) SidCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCase) Uint64(org.opendaylight.yangtools.yang.common.Uint64) PrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.PrefixBuilder)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)6 LinkStateAttribute (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute)6 Attributes1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.linkstate.route.Attributes1)5 ArrayList (java.util.ArrayList)4 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)3 NodeKey (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)3 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)2 Ipv4RouterIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv4RouterIdentifier)2 Ipv6RouterIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv6RouterIdentifier)2 SrAdjIds (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.SrAdjIds)2 PrefixAttributesCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase)2 SidLabelIndex (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.SidLabelIndex)2 LocalLabelCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase)2 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)2 IgpNodeAttributes (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes)2 Preconditions (com.google.common.base.Preconditions)1 BGPParsingException (org.opendaylight.protocol.bgp.parser.BGPParsingException)1 RSVPParsingException (org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException)1 BitArray (org.opendaylight.protocol.util.BitArray)1 DomainName (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName)1