Search in sources :

Example 6 with TopologyEdge

use of org.onosproject.net.topology.TopologyEdge in project onos by opennetworkinglab.

the class DefaultTopology method getPaths.

/**
 * Computes on-demand the set of shortest paths between source and
 * destination devices, the set of returned paths will be no more than,
 * maxPaths in size.  The first {@code maxPaths} paths will be returned
 * maintaining any ordering guarantees provided by the underlying
 * (default or if no default is specified {@link DijkstraGraphSearch})
 * search. If returning all paths of a given length would exceed
 * {@code maxPaths} a subset of paths of that length will be returned,
 * which paths will be returned depends on the currently specified
 * {@code GraphPathSearch}. See {@link #setDefaultGraphPathSearch}.
 *
 * @param src      source device
 * @param dst      destination device
 * @param weigher  link weight function
 * @param maxPaths maximum number of paths
 * @return set of shortest paths
 */
public Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeigher weigher, int maxPaths) {
    DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
    DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
    Set<TopologyVertex> vertices = graph.getVertexes();
    if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
        // src or dst not part of the current graph
        return ImmutableSet.of();
    }
    GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = graphPathSearch().search(graph, srcV, dstV, weigher, maxPaths);
    ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        builder.add(networkPath(path));
    }
    return builder.build();
}
Also used : DefaultDisjointPath(org.onosproject.net.DefaultDisjointPath) Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) DisjointPath(org.onosproject.net.DisjointPath) DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyEdge(org.onosproject.net.topology.TopologyEdge) GraphPathSearch(org.onlab.graph.GraphPathSearch)

Example 7 with TopologyEdge

use of org.onosproject.net.topology.TopologyEdge in project onos by opennetworkinglab.

the class DefaultTopology method buildIndexes.

// Builds cluster-devices, cluster-links and device-cluster indexes.
private ClusterIndexes buildIndexes() {
    // Prepare the index builders
    ImmutableMap.Builder<DeviceId, TopologyCluster> clusterBuilder = ImmutableMap.builder();
    ImmutableSetMultimap.Builder<TopologyCluster, DeviceId> devicesBuilder = ImmutableSetMultimap.builder();
    ImmutableSetMultimap.Builder<TopologyCluster, Link> linksBuilder = ImmutableSetMultimap.builder();
    // Now scan through all the clusters
    for (TopologyCluster cluster : clusters.get().values()) {
        int i = cluster.id().index();
        // Scan through all the cluster vertexes.
        for (TopologyVertex vertex : clusterResults.get().clusterVertexes().get(i)) {
            devicesBuilder.put(cluster, vertex.deviceId());
            clusterBuilder.put(vertex.deviceId(), cluster);
        }
        // Scan through all the cluster edges.
        for (TopologyEdge edge : clusterResults.get().clusterEdges().get(i)) {
            linksBuilder.put(cluster, edge.link());
        }
    }
    // Finalize all indexes.
    return new ClusterIndexes(clusterBuilder.build(), devicesBuilder.build(), linksBuilder.build());
}
Also used : DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) DeviceId(org.onosproject.net.DeviceId) TopologyCluster(org.onosproject.net.topology.TopologyCluster) DefaultTopologyCluster(org.onosproject.net.topology.DefaultTopologyCluster) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ImmutableMap(com.google.common.collect.ImmutableMap) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 8 with TopologyEdge

use of org.onosproject.net.topology.TopologyEdge in project onos by opennetworkinglab.

the class DefaultTopology method addClusterBroadcastSet.

// Finds all broadcast points for the cluster. These are those connection
// points which lie along the shortest paths between the cluster root and
// all other devices within the cluster.
private void addClusterBroadcastSet(TopologyCluster cluster, Builder<ClusterId, ConnectPoint> builder) {
    // Use the graph root search results to build the broadcast set.
    Result<TopologyVertex, TopologyEdge> result = DIJKSTRA.search(graph, cluster.root(), null, hopCountWeigher, 1);
    for (Map.Entry<TopologyVertex, Set<TopologyEdge>> entry : result.parents().entrySet()) {
        TopologyVertex vertex = entry.getKey();
        // Ignore any parents that lead outside the cluster.
        if (clustersByDevice().get(vertex.deviceId()) != cluster) {
            continue;
        }
        // Ignore any back-link sets that are empty.
        Set<TopologyEdge> parents = entry.getValue();
        if (parents.isEmpty()) {
            continue;
        }
        // Use the first back-link source and destinations to add to the
        // broadcast set.
        Link link = parents.iterator().next().link();
        builder.put(cluster.id(), link.src());
        builder.put(cluster.id(), link.dst());
    }
}
Also used : DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TopologyEdge(org.onosproject.net.topology.TopologyEdge) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Link(org.onosproject.net.Link)

Example 9 with TopologyEdge

use of org.onosproject.net.topology.TopologyEdge in project onos by opennetworkinglab.

the class OpticalConnectivityIntentCompiler method getOpticalPaths.

/**
 * Calculates optical paths in WDM topology.
 *
 * @param intent optical connectivity intent
 * @return set of paths in WDM topology
 */
private Stream<Path> getOpticalPaths(OpticalConnectivityIntent intent) {
    // Route in WDM topology
    Topology topology = topologyService.currentTopology();
    // TODO: refactor with LinkWeigher class Implementation
    LinkWeigher weight = new LinkWeigher() {

        @Override
        public Weight getInitialWeight() {
            return ScalarWeight.toWeight(0.0);
        }

        @Override
        public Weight getNonViableWeight() {
            return ScalarWeight.NON_VIABLE_WEIGHT;
        }

        /**
         * @param edge edge to be weighed
         * @return the metric retrieved from the annotations otherwise 1
         */
        @Override
        public Weight weight(TopologyEdge edge) {
            log.debug("Link {} metric {}", edge.link(), edge.link().annotations().value("metric"));
            // Disregard inactive or non-optical links
            if (edge.link().state() == Link.State.INACTIVE) {
                return ScalarWeight.toWeight(-1);
            }
            if (edge.link().type() != Link.Type.OPTICAL) {
                return ScalarWeight.toWeight(-1);
            }
            // Adhere to static port mappings
            DeviceId srcDeviceId = edge.link().src().deviceId();
            if (srcDeviceId.equals(intent.getSrc().deviceId())) {
                ConnectPoint srcStaticPort = staticPort(intent.getSrc());
                if (srcStaticPort != null) {
                    return ScalarWeight.toWeight(srcStaticPort.equals(edge.link().src()) ? 1 : -1);
                }
            }
            DeviceId dstDeviceId = edge.link().dst().deviceId();
            if (dstDeviceId.equals(intent.getDst().deviceId())) {
                ConnectPoint dstStaticPort = staticPort(intent.getDst());
                if (dstStaticPort != null) {
                    return ScalarWeight.toWeight(dstStaticPort.equals(edge.link().dst()) ? 1 : -1);
                }
            }
            Annotations annotations = edge.link().annotations();
            if (annotations != null && annotations.value("metric") != null && !annotations.value("metric").isEmpty()) {
                double metric = Double.parseDouble(annotations.value("metric"));
                return ScalarWeight.toWeight(metric);
            } else {
                return ScalarWeight.toWeight(1);
            }
        }
    };
    ConnectPoint start = intent.getSrc();
    ConnectPoint end = intent.getDst();
    // 0 hop case
    if (start.deviceId().equals(end.deviceId())) {
        log.debug("install optical intent for 0 hop i.e srcDeviceId=dstDeviceId");
        DefaultLink defaultLink = DefaultLink.builder().providerId(PROVIDER_ID).src(start).dst(end).state(Link.State.ACTIVE).type(Link.Type.DIRECT).isExpected(true).build();
        List<Link> links = ImmutableList.<Link>builder().add(defaultLink).build();
        Annotations annotations = DefaultAnnotations.builder().build();
        DefaultPath defaultPath = new DefaultPath(PROVIDER_ID, links, null, annotations);
        return ImmutableList.<Path>builder().add(defaultPath).build().stream();
    }
    // head link's src port should be same as intent src port and tail link dst port
    // should be same as intent dst port in the path.
    Stream<Path> paths = topologyService.getKShortestPaths(topology, start.deviceId(), end.deviceId(), weight).filter(p -> p.links().get(0).src().port().equals(start.port()) && p.links().get(p.links().size() - 1).dst().port().equals(end.port()));
    if (log.isDebugEnabled()) {
        return paths.map(path -> {
            // no-op map stage to add debug logging
            log.debug("Candidate path: {}", path.links().stream().map(lk -> lk.src() + "-" + lk.dst()).collect(Collectors.toList()));
            return path;
        });
    }
    return paths;
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) DefaultLink(org.onosproject.net.DefaultLink) DeviceId(org.onosproject.net.DeviceId) Topology(org.onosproject.net.topology.Topology) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ConnectPoint(org.onosproject.net.ConnectPoint) Annotations(org.onosproject.net.Annotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) LinkWeigher(org.onosproject.net.topology.LinkWeigher) DefaultPath(org.onosproject.net.DefaultPath) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink)

Example 10 with TopologyEdge

use of org.onosproject.net.topology.TopologyEdge in project onos by opennetworkinglab.

the class OpticalOduIntentCompiler method getOpticalPaths.

/**
 * Calculates optical paths in OTU topology.
 *
 * @param intent optical ODU intent
 * @return set of paths in OTU topology
 */
private Set<Path> getOpticalPaths(OpticalOduIntent intent) {
    // Route in OTU topology
    Topology topology = topologyService.currentTopology();
    class Weigher implements LinkWeigher {

        @Override
        public Weight weight(TopologyEdge edge) {
            if (edge.link().state() == Link.State.INACTIVE) {
                return ScalarWeight.toWeight(-1);
            }
            if (edge.link().type() != Link.Type.OPTICAL) {
                return ScalarWeight.toWeight(-1);
            }
            // Find path with available TributarySlots resources
            if (!isAvailableTributarySlots(intent, edge.link())) {
                return ScalarWeight.toWeight(-1);
            }
            return ScalarWeight.toWeight(1);
        }

        @Override
        public Weight getInitialWeight() {
            return null;
        }

        @Override
        public Weight getNonViableWeight() {
            return null;
        }
    }
    LinkWeigher weigher = new Weigher();
    ConnectPoint start = intent.getSrc();
    ConnectPoint end = intent.getDst();
    return topologyService.getPaths(topology, start.deviceId(), end.deviceId(), weigher);
}
Also used : LinkWeigher(org.onosproject.net.topology.LinkWeigher) LinkWeigher(org.onosproject.net.topology.LinkWeigher) Topology(org.onosproject.net.topology.Topology) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

TopologyEdge (org.onosproject.net.topology.TopologyEdge)10 TopologyVertex (org.onosproject.net.topology.TopologyVertex)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 ConnectPoint (org.onosproject.net.ConnectPoint)6 DefaultTopologyVertex (org.onosproject.net.topology.DefaultTopologyVertex)6 Link (org.onosproject.net.Link)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 GraphPathSearch (org.onlab.graph.GraphPathSearch)3 DefaultDisjointPath (org.onosproject.net.DefaultDisjointPath)3 DeviceId (org.onosproject.net.DeviceId)3 DisjointPath (org.onosproject.net.DisjointPath)3 Set (java.util.Set)2 DefaultLink (org.onosproject.net.DefaultLink)2 DefaultPath (org.onosproject.net.DefaultPath)2 Path (org.onosproject.net.Path)2 DefaultTopologyCluster (org.onosproject.net.topology.DefaultTopologyCluster)2 LinkWeigher (org.onosproject.net.topology.LinkWeigher)2 Topology (org.onosproject.net.topology.Topology)2 TopologyCluster (org.onosproject.net.topology.TopologyCluster)2 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1