Search in sources :

Example 16 with Topology

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

the class AbstractTopologySessionListener method onSessionUp.

@Override
public final synchronized void onSessionUp(final PCEPSession psession) {
    /*
         * The session went up. Look up the router in Inventory model,
         * create it if it is not there (marking that fact for later
         * deletion), and mark it as synchronizing. Also create it in
         * the topology model, with empty LSP list.
         */
    final InetAddress peerAddress = psession.getRemoteAddress();
    this.syncOptimization = new SyncOptimization(psession);
    final TopologyNodeState state = this.serverSessionManager.takeNodeState(peerAddress, this, isLspDbRetreived());
    // takeNodeState(..) may fail when the server session manager is being restarted due to configuration change
    if (state == null) {
        LOG.error("Unable to fetch topology node state for PCEP session. Closing session {}", psession);
        psession.close(TerminationReason.UNKNOWN);
        this.onSessionTerminated(psession, new PCEPCloseTermination(TerminationReason.UNKNOWN));
        return;
    }
    if (this.session != null || this.nodeState != null) {
        LOG.error("PCEP session is already up with {}. Closing session {}", psession.getRemoteAddress(), psession);
        psession.close(TerminationReason.UNKNOWN);
        this.onSessionTerminated(psession, new PCEPCloseTermination(TerminationReason.UNKNOWN));
        return;
    }
    this.session = psession;
    this.nodeState = state;
    this.serverSessionManager.bind(this.nodeState.getNodeId(), this.listenerState);
    LOG.trace("Peer {} resolved to topology node {}", peerAddress, state.getNodeId());
    // Our augmentation in the topology node
    final PathComputationClientBuilder pccBuilder = new PathComputationClientBuilder();
    onSessionUp(psession, pccBuilder);
    this.synced.set(isSynchronized());
    pccBuilder.setIpAddress(IpAddressBuilder.getDefaultInstance(peerAddress.getHostAddress()));
    final InstanceIdentifier<Node1> topologyAugment = state.getNodeId().augmentation(Node1.class);
    this.pccIdentifier = topologyAugment.child(PathComputationClient.class);
    final Node initialNodeState = state.getInitialNodeState();
    final boolean isNodePresent = isLspDbRetreived() && initialNodeState != null;
    if (isNodePresent) {
        loadLspData(initialNodeState, this.lspData, this.lsps, isIncrementalSynchro());
        pccBuilder.setReportedLsp(initialNodeState.getAugmentation(Node1.class).getPathComputationClient().getReportedLsp());
    }
    state.storeNode(topologyAugment, new Node1Builder().setPathComputationClient(pccBuilder.build()).build(), this.session);
    this.listenerState.init(psession);
    LOG.info("Session with {} attached to topology node {}", psession.getRemoteAddress(), state.getNodeId());
}
Also used : PCEPCloseTermination(org.opendaylight.protocol.pcep.PCEPCloseTermination) Node1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1) Node1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1Builder) PathComputationClient(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.PathComputationClient) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) PathComputationClientBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.PathComputationClientBuilder) InetAddress(java.net.InetAddress)

Example 17 with Topology

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology 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 18 with Topology

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

the class NodeChangedListener method onDataTreeChanged.

@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
    final ReadWriteTransaction trans = this.dataProvider.newReadWriteTransaction();
    final Set<InstanceIdentifier<ReportedLsp>> lsps = new HashSet<>();
    final Set<InstanceIdentifier<Node>> nodes = new HashSet<>();
    final Map<InstanceIdentifier<?>, DataObject> original = new HashMap<>();
    final Map<InstanceIdentifier<?>, DataObject> updated = new HashMap<>();
    final Map<InstanceIdentifier<?>, DataObject> created = new HashMap<>();
    for (final DataTreeModification<?> change : changes) {
        final InstanceIdentifier<?> iid = change.getRootPath().getRootIdentifier();
        final DataObjectModification<?> rootNode = change.getRootNode();
        handleChangedNode(rootNode, iid, lsps, nodes, original, updated, created);
    }
    // Now walk all nodes, check for removals/additions and cascade them to LSPs
    for (final InstanceIdentifier<Node> iid : nodes) {
        enumerateLsps(iid, (Node) original.get(iid), lsps);
        enumerateLsps(iid, (Node) updated.get(iid), lsps);
        enumerateLsps(iid, (Node) created.get(iid), lsps);
    }
    // We now have list of all affected LSPs. Walk them create/remove them
    updateTransaction(trans, lsps, original, updated, created);
    Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.submit()), new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void result) {
            LOG.trace("Topology change committed successfully");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to propagate a topology change, target topology became inconsistent", throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : HashMap(java.util.HashMap) SupportingNode(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNode) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) HashSet(java.util.HashSet)

Example 19 with Topology

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

the class NodeChangedListener method getIpTerminationPoint.

private InstanceIdentifier<TerminationPoint> getIpTerminationPoint(final ReadWriteTransaction trans, final IpAddress addr, final InstanceIdentifier<Node> sni, final Boolean inControl) throws ReadFailedException {
    final Topology topo = trans.read(LogicalDatastoreType.OPERATIONAL, this.target).checkedGet().get();
    if (topo.getNode() != null) {
        for (final Node n : topo.getNode()) {
            if (n.getTerminationPoint() != null) {
                for (final TerminationPoint tp : n.getTerminationPoint()) {
                    final TerminationPoint1 tpa = tp.getAugmentation(TerminationPoint1.class);
                    if (tpa != null) {
                        final TerminationPointType tpt = tpa.getIgpTerminationPointAttributes().getTerminationPointType();
                        if (tpt instanceof Ip) {
                            for (final IpAddress address : ((Ip) tpt).getIpAddress()) {
                                if (addr.equals(address)) {
                                    handleSni(sni, n, inControl, trans);
                                    return this.target.builder().child(Node.class, n.getKey()).child(TerminationPoint.class, tp.getKey()).build();
                                }
                            }
                        } else {
                            LOG.debug("Ignoring termination point type {}", tpt);
                        }
                    }
                }
            }
        }
    }
    LOG.debug("Termination point for {} not found, creating a new one", addr);
    return createTP(addr, sni, inControl, trans);
}
Also used : TerminationPoint1(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1) SupportingNode(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNode) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Ip(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.termination.point.type.Ip) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) TerminationPointType(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.TerminationPointType)

Example 20 with Topology

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

the class ServerSessionManager method instantiateServiceInstance.

/**
 * Create Base Topology.
 */
synchronized void instantiateServiceInstance() {
    final TopologyKey key = InstanceIdentifier.keyOf(this.topology);
    final TopologyId topologyId = key.getTopologyId();
    final WriteTransaction tx = this.dependenciesProvider.getDataBroker().newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.OPERATIONAL, this.topology, new TopologyBuilder().setKey(key).setTopologyId(topologyId).setTopologyTypes(new TopologyTypesBuilder().addAugmentation(TopologyTypes1.class, new TopologyTypes1Builder().setTopologyPcep(new TopologyPcepBuilder().build()).build()).build()).setNode(new ArrayList<>()).build(), true);
    try {
        tx.submit().get();
        LOG.info("PCEP Topology {} created successfully.", topologyId.getValue());
        ServerSessionManager.this.isClosed.set(false);
    } catch (final ExecutionException | InterruptedException throwable) {
        LOG.error("Failed to create PCEP Topology {}.", topologyId.getValue(), throwable);
        ServerSessionManager.this.isClosed.set(true);
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) TopologyTypesBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder) TopologyKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey) TopologyBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder) TopologyTypes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.TopologyTypes1) TopologyTypes1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.TopologyTypes1Builder) TopologyPcepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.topology.pcep.type.TopologyPcepBuilder) ExecutionException(java.util.concurrent.ExecutionException) TopologyId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId)

Aggregations

Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)30 Topology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)26 Test (org.junit.Test)20 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)15 NetworkTopology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology)12 TopologyId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId)12 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)12 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)10 Link (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link)10 TerminationPoint (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint)10 TopologyBuilder (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder)9 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)8 Optional (com.google.common.base.Optional)7 TpId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId)7 TopologyKey (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey)7 ExecutionException (java.util.concurrent.ExecutionException)6 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)6 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)5 NodeKey (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)5 ArrayList (java.util.ArrayList)4