Search in sources :

Example 81 with NodeId

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId in project bgpcep by opendaylight.

the class PcepStateUtilsTest method createDefaultProtocol.

private void createDefaultProtocol() throws ExecutionException, InterruptedException {
    final WriteTransaction wt = getDataBroker().newWriteOnlyTransaction();
    final Node node = new NodeBuilder().setNodeId(new NodeId(NODE_ID)).addAugmentation(PcepTopologyNodeStatsAug.class, new PcepTopologyNodeStatsAugBuilder().setPcepSessionState(createPcepSessionState()).build()).build();
    final InstanceIdentifier<Node> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(new TopologyId(PCEP_TOPOLOGY))).child(Node.class, new NodeKey(new NodeId(NODE_ID))).build();
    wt.put(LogicalDatastoreType.OPERATIONAL, topology, node, true);
    wt.submit().get();
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) PcepTopologyNodeStatsAugBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.stats.rev171113.PcepTopologyNodeStatsAugBuilder) PcepTopologyNodeStatsAug(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.stats.rev171113.PcepTopologyNodeStatsAug) TopologyKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) NetworkTopology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey) TopologyId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId)

Example 82 with NodeId

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId in project bgpcep by opendaylight.

the class NodeChangedListener method remove.

private void remove(final ReadWriteTransaction trans, final InstanceIdentifier<ReportedLsp> identifier, final ReportedLsp value) throws ReadFailedException {
    final InstanceIdentifier<Link> li = linkForLsp(linkIdForLsp(identifier, value));
    final Optional<Link> ol = trans.read(LogicalDatastoreType.OPERATIONAL, li).checkedGet();
    if (!ol.isPresent()) {
        return;
    }
    final Link l = ol.get();
    LOG.debug("Removing link {} (was {})", li, l);
    trans.delete(LogicalDatastoreType.OPERATIONAL, li);
    LOG.debug("Searching for orphan links/nodes");
    final Optional<Topology> ot = trans.read(LogicalDatastoreType.OPERATIONAL, this.target).checkedGet();
    Preconditions.checkState(ot.isPresent());
    final Topology topology = ot.get();
    final NodeId srcNode = l.getSource().getSourceNode();
    final NodeId dstNode = l.getDestination().getDestNode();
    final TpId srcTp = l.getSource().getSourceTp();
    final TpId dstTp = l.getDestination().getDestTp();
    boolean orphSrcNode = true;
    boolean orphDstNode = true;
    boolean orphDstTp = true;
    boolean orphSrcTp = true;
    for (final Link lw : topology.getLink()) {
        LOG.trace("Checking link {}", lw);
        final NodeId sn = lw.getSource().getSourceNode();
        final NodeId dn = lw.getDestination().getDestNode();
        final TpId st = lw.getSource().getSourceTp();
        final TpId dt = lw.getDestination().getDestTp();
        // Source node checks
        if (srcNode.equals(sn)) {
            if (orphSrcNode) {
                LOG.debug("Node {} held by source of link {}", srcNode, lw);
                orphSrcNode = false;
            }
            if (orphSrcTp && srcTp.equals(st)) {
                LOG.debug("TP {} held by source of link {}", srcTp, lw);
                orphSrcTp = false;
            }
        }
        if (srcNode.equals(dn)) {
            if (orphSrcNode) {
                LOG.debug("Node {} held by destination of link {}", srcNode, lw);
                orphSrcNode = false;
            }
            if (orphSrcTp && srcTp.equals(dt)) {
                LOG.debug("TP {} held by destination of link {}", srcTp, lw);
                orphSrcTp = false;
            }
        }
        // Destination node checks
        if (dstNode.equals(sn)) {
            if (orphDstNode) {
                LOG.debug("Node {} held by source of link {}", dstNode, lw);
                orphDstNode = false;
            }
            if (orphDstTp && dstTp.equals(st)) {
                LOG.debug("TP {} held by source of link {}", dstTp, lw);
                orphDstTp = false;
            }
        }
        if (dstNode.equals(dn)) {
            if (orphDstNode) {
                LOG.debug("Node {} held by destination of link {}", dstNode, lw);
                orphDstNode = false;
            }
            if (orphDstTp && dstTp.equals(dt)) {
                LOG.debug("TP {} held by destination of link {}", dstTp, lw);
                orphDstTp = false;
            }
        }
    }
    if (orphSrcNode && !orphSrcTp) {
        LOG.warn("Orphan source node {} but not TP {}, retaining the node", srcNode, srcTp);
        orphSrcNode = false;
    }
    if (orphDstNode && !orphDstTp) {
        LOG.warn("Orphan destination node {} but not TP {}, retaining the node", dstNode, dstTp);
        orphDstNode = false;
    }
    if (orphSrcNode) {
        LOG.debug("Removing orphan node {}", srcNode);
        trans.delete(LogicalDatastoreType.OPERATIONAL, nodeIdentifier(srcNode));
    } else if (orphSrcTp) {
        LOG.debug("Removing orphan TP {} on node {}", srcTp, srcNode);
        trans.delete(LogicalDatastoreType.OPERATIONAL, tpIdentifier(srcNode, srcTp));
    }
    if (orphDstNode) {
        LOG.debug("Removing orphan node {}", dstNode);
        trans.delete(LogicalDatastoreType.OPERATIONAL, nodeIdentifier(dstNode));
    } else if (orphDstTp) {
        LOG.debug("Removing orphan TP {} on node {}", dstTp, dstNode);
        trans.delete(LogicalDatastoreType.OPERATIONAL, tpIdentifier(dstNode, dstTp));
    }
}
Also used : TpId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) Link(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link)

Example 83 with NodeId

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId in project bgpcep by opendaylight.

the class AbstractReachabilityTopologyBuilder method ensureNodePresent.

private InstanceIdentifier<IgpNodeAttributes> ensureNodePresent(final ReadWriteTransaction trans, final NodeId ni) {
    final NodeUsage present = this.nodes.get(ni);
    if (present != null) {
        return present.attrId;
    }
    final KeyedInstanceIdentifier<Node, NodeKey> nii = nodeInstanceId(ni);
    final InstanceIdentifier<IgpNodeAttributes> ret = nii.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
    trans.merge(LogicalDatastoreType.OPERATIONAL, nii, new NodeBuilder().setKey(nii.getKey()).setNodeId(ni).addAugmentation(Node1.class, new Node1Builder().setIgpNodeAttributes(new IgpNodeAttributesBuilder().setPrefix(Collections.emptyList()).build()).build()).build());
    this.nodes.put(ni, new NodeUsage(ret));
    return ret;
}
Also used : Node1Builder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1Builder) IgpNodeAttributesBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) IgpNodeAttributes(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)

Example 84 with NodeId

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId in project bgpcep by opendaylight.

the class LinkstateTopologyBuilder method createLink.

private void createLink(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final LinkCase linkCase, final Attributes attributes) {
    // defensive lookup
    final LinkAttributes la;
    final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
    if (attr != null) {
        final LinkStateAttribute attrType = attr.getLinkStateAttribute();
        if (attrType != null) {
            la = ((LinkAttributesCase) attrType).getLinkAttributes();
        } else {
            LOG.debug("Missing attribute type in link {} route {}, skipping it", linkCase, value);
            la = null;
        }
    } else {
        LOG.debug("Missing attributes in link {} route {}, skipping it", linkCase, value);
        la = null;
    }
    final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
    if (la != null) {
        if (la.getMetric() != null) {
            ilab.setMetric(la.getMetric().getValue());
        }
        ilab.setName(la.getLinkName());
    }
    ProtocolUtil.augmentProtocolId(value, ilab, la, linkCase.getLinkDescriptors());
    final LinkBuilder lb = new LinkBuilder();
    lb.setLinkId(buildLinkId(base, linkCase));
    lb.addAugmentation(Link1.class, new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
    final NodeId srcNode = buildNodeId(base, linkCase.getLocalNodeDescriptors());
    LOG.trace("Link {} implies source node {}", linkCase, srcNode);
    final NodeId dstNode = buildNodeId(base, linkCase.getRemoteNodeDescriptors());
    LOG.trace("Link {} implies destination node {}", linkCase, dstNode);
    final TerminationPoint srcTp = buildLocalTp(base, linkCase.getLinkDescriptors());
    LOG.trace("Link {} implies source TP {}", linkCase, srcTp);
    final TerminationPoint dstTp = buildRemoteTp(base, linkCase.getLinkDescriptors());
    LOG.trace("Link {} implies destination TP {}", linkCase, dstTp);
    lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
    lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
    LOG.trace("Created TP {} as link source", srcTp);
    NodeHolder snh = this.nodes.get(srcNode);
    if (snh == null) {
        snh = getNode(srcNode);
        snh.addTp(srcTp, lb.getLinkId(), false);
        putNode(trans, snh);
    } else {
        snh.addTp(srcTp, lb.getLinkId(), false);
        final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(snh.getNodeId()));
        trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.getKey()), srcTp);
    }
    LOG.debug("Created TP {} as link destination", dstTp);
    NodeHolder dnh = this.nodes.get(dstNode);
    if (dnh == null) {
        dnh = getNode(dstNode);
        dnh.addTp(dstTp, lb.getLinkId(), true);
        putNode(trans, dnh);
    } else {
        dnh.addTp(dstTp, lb.getLinkId(), true);
        final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class, new NodeKey(dnh.getNodeId()));
        trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.getKey()), dstTp);
    }
    final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
    final Link link = lb.build();
    trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
    LOG.debug("Created link {} at {} for {}", link, lid, linkCase);
}
Also used : IgpLinkAttributesBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder) SourceBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder) LinkBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.routes.linkstate.routes.linkstate.route.Attributes1) LinkStateAttribute(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.LinkStateAttribute) Link1Builder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1Builder) LinkAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) DestinationBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) Link(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link)

Example 85 with NodeId

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId 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.getAugmentation(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<>();
    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 (!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.setKey(new NodeKey(nb.getNodeId()));
    nh.advertized(nb, inab);
    putNode(trans, nh);
}
Also used : IgpNodeAttributesBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder) DomainName(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName) 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.rev171207.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes) ArrayList(java.util.ArrayList) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.routes.linkstate.routes.linkstate.route.Attributes1) LinkStateAttribute(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.LinkStateAttribute) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)

Aggregations

NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)105 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)95 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)73 ArrayList (java.util.ArrayList)68 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)68 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)65 Test (org.junit.Test)56 NodeKey (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)42 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)35 BigInteger (java.math.BigInteger)31 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)30 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)29 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)28 ExecutionException (java.util.concurrent.ExecutionException)25 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)25 NodeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder)25 L2GatewayDevice (org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)24 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)23 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)20 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)19