Search in sources :

Example 1 with NodeAttributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes in project bgpcep by opendaylight.

the class LinkstateGraphBuilder method createVertex.

/**
 * Create new Connected Vertex in the Connected Graph.
 *
 * @param value       The complete Linkstate route information
 * @param nodeCase    The node part of the Linkstate route
 * @param attributes  The node attributes
 */
private void createVertex(final LinkstateRoute value, final NodeCase nodeCase, final Attributes attributes) {
    checkArgument(nodeCase != null, "Missing Node Case. Skip this Node");
    checkArgument(nodeCase.getNodeDescriptors() != null, "Missing Node Descriptors. Skip this Node");
    Uint64 vertexId = getVertexId(nodeCase.getNodeDescriptors().getCRouterIdentifier());
    if (vertexId == Uint64.ZERO) {
        LOG.warn("Unable to get Vertex Identifier from descriptor {}, skipping it", nodeCase.getNodeDescriptors());
        return;
    }
    NodeAttributes na = getNodeAttributes(attributes);
    if (na == null) {
        LOG.warn("Missing attributes in node {} route {}, skipping it", nodeCase, value);
        return;
    }
    Uint32 asNumber = Uint32.ZERO;
    if (nodeCase.getNodeDescriptors() != null) {
        asNumber = nodeCase.getNodeDescriptors().getAsNumber().getValue();
    }
    Vertex vertex = getVertex(na, vertexId, asNumber);
    /* Add the Connected Vertex and associated Vertex in the Graph */
    LOG.info("Add Vertex {} in TED[{}]", vertex.getName(), cgraph);
    cgraph.addVertex(vertex);
}
Also used : Vertex(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Vertex) 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) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 2 with NodeAttributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes 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 3 with NodeAttributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes in project bgpcep by opendaylight.

the class NodeAttributesParser method serializeNodeAttributes.

static void serializeNodeAttributes(final NodeAttributesCase nodeAttributesCase, final ByteBuf byteAggregator) {
    LOG.trace("Started serializing Node Attributes");
    final NodeAttributes nodeAttributes = nodeAttributesCase.getNodeAttributes();
    serializeTopologyId(nodeAttributes.getTopologyIdentifier(), byteAggregator);
    serializeNodeFlagBits(nodeAttributes.getNodeFlags(), byteAggregator);
    if (nodeAttributes.getDynamicHostname() != null) {
        TlvUtil.writeTLV(DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode(nodeAttributes.getDynamicHostname())), byteAggregator);
    }
    final List<IsisAreaIdentifier> isisList = nodeAttributes.getIsisAreaId();
    if (isisList != null) {
        for (final IsisAreaIdentifier isisAreaIdentifier : isisList) {
            TlvUtil.writeTLV(ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator);
        }
    }
    if (nodeAttributes.getIpv4RouterId() != null) {
        TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(nodeAttributes.getIpv4RouterId()), byteAggregator);
    }
    if (nodeAttributes.getIpv6RouterId() != null) {
        TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(nodeAttributes.getIpv6RouterId()), byteAggregator);
    }
    if (nodeAttributes.getSrCapabilities() != null) {
        final ByteBuf capBuffer = Unpooled.buffer();
        SrNodeAttributesParser.serializeSrCapabilities(nodeAttributes.getSrCapabilities(), capBuffer);
        TlvUtil.writeTLV(SR_CAPABILITIES, capBuffer, byteAggregator);
    }
    if (nodeAttributes.getSrAlgorithm() != null) {
        final ByteBuf capBuffer = Unpooled.buffer();
        SrNodeAttributesParser.serializeSrAlgorithms(nodeAttributes.getSrAlgorithm(), capBuffer);
        TlvUtil.writeTLV(SR_ALGORITHMS, capBuffer, byteAggregator);
    }
    LOG.trace("Finished serializing Node Attributes");
}
Also used : IsisAreaIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.IsisAreaIdentifier) 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) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with NodeAttributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes in project bgpcep by opendaylight.

the class LinkstateAttributeParserTest method testPositiveNodes.

@Test
public void testPositiveNodes() throws BGPParsingException, BGPDocumentedException {
    final AttributesBuilder builder = createBuilder(new NodeCaseBuilder().build());
    this.parser.parseAttribute(Unpooled.copiedBuffer(NODE_ATTR), builder, null);
    final Attributes1 attrs = builder.augmentation(Attributes1.class);
    final NodeAttributes ls = ((NodeAttributesCase) attrs.getLinkStateAttribute()).getNodeAttributes();
    assertNotNull(ls);
    assertEquals(2, ls.getTopologyIdentifier().size());
    assertEquals(42, ls.getTopologyIdentifier().get(0).getValue().intValue());
    assertTrue(ls.getNodeFlags().getOverload());
    assertFalse(ls.getNodeFlags().getAttached());
    assertTrue(ls.getNodeFlags().getExternal());
    assertTrue(ls.getNodeFlags().getAbr());
    assertTrue(ls.getNodeFlags().getRouter());
    assertTrue(ls.getNodeFlags().getV6());
    assertEquals("12K-2", ls.getDynamicHostname());
    assertEquals(2, ls.getIsisAreaId().size());
    assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
    // serialization
    final ByteBuf buff = Unpooled.buffer();
    this.parser.serializeAttribute(builder.build(), buff);
    buff.skipBytes(3);
    assertArrayEquals(NODE_ATTR_S, ByteArray.getAllBytes(buff));
}
Also used : NodeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.NodeCaseBuilder) 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) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Attributes1) ByteBuf(io.netty.buffer.ByteBuf) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) NodeAttributesCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.NodeAttributesCase) Test(org.junit.Test)

Example 5 with NodeAttributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes in project bgpcep by opendaylight.

the class LinkstateGraphBuilder method getNodeAttributes.

/**
 * Get Node Attributes from Link State Route attributes.
 *
 * @param attributes  The attribute part from the Link State route
 *
 * @return Node Attributes
 */
private static NodeAttributes getNodeAttributes(final Attributes attributes) {
    final NodeAttributes na;
    final Attributes1 attr = attributes.augmentation(Attributes1.class);
    if (attr != null) {
        final LinkStateAttribute attrType = attr.getLinkStateAttribute();
        if (attrType != null) {
            na = ((NodeAttributesCase) attrType).getNodeAttributes();
        } else {
            return null;
        }
    } else {
        return null;
    }
    return na;
}
Also used : 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) 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)

Aggregations

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)5 ByteBuf (io.netty.buffer.ByteBuf)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 LinkStateAttribute (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute)2 Attributes1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.routes.linkstate.routes.linkstate.route.Attributes1)2 CRouterIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.CRouterIdentifier)2 IsisPseudonode (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode)2 OspfPseudonode (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode)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 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 DomainName (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName)1 Attributes1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Attributes1)1 IsisAreaIdentifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.IsisAreaIdentifier)1 NodeFlagBits (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.NodeFlagBits)1 NodeCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.NodeCaseBuilder)1 NodeAttributesCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.NodeAttributesCase)1 IsisNodeCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.IsisNodeCase)1 IsisPseudonodeCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.IsisPseudonodeCase)1