Search in sources :

Example 1 with TopologyVertex

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

the class FlowAnalyzer method analyze.

/**
 * Analyzes and prints out a report on the status of every flow entry inside
 * the network. The possible states are: Cleared (implying that the entry leads to
 * a host), Cycle (implying that it is part of cycle), and Black Hole (implying
 * that the entry does not lead to a single host).
 *
 * @return result string
 */
public String analyze() {
    graph = topologyService.getGraph(topologyService.currentTopology());
    for (TopologyVertex v : graph.getVertexes()) {
        DeviceId srcDevice = v.deviceId();
        Iterable<FlowEntry> flowTable = flowRuleService.getFlowEntries(srcDevice);
        for (FlowEntry flow : flowTable) {
            dfs(flow);
        }
    }
    // analyze the cycles to look for "critical flows" that can be removed
    // to break the cycle
    Set<FlowEntry> critpts = new HashSet<>();
    for (FlowEntry flow : label.keySet()) {
        if ("Cycle".equals(label.get(flow))) {
            Map<FlowEntry, String> labelSaved = label;
            label = new HashMap<FlowEntry, String>();
            ignoredFlows.add(flow);
            for (TopologyVertex v : graph.getVertexes()) {
                DeviceId srcDevice = v.deviceId();
                Iterable<FlowEntry> flowTable = flowRuleService.getFlowEntries(srcDevice);
                for (FlowEntry flow1 : flowTable) {
                    dfs(flow1);
                }
            }
            boolean replacable = true;
            for (FlowEntry flow2 : label.keySet()) {
                if ("Cleared".equals(labelSaved.get(flow2)) && !("Cleared".equals(label.get(flow2)))) {
                    replacable = false;
                }
            }
            if (replacable) {
                critpts.add(flow);
            }
            label = labelSaved;
        }
    }
    for (FlowEntry flow : critpts) {
        label.put(flow, "Cycle Critical Point");
    }
    String s = "\n";
    for (FlowEntry flow : label.keySet()) {
        s += ("Flow Rule: " + flowEntryRepresentation(flow) + "\n");
        s += ("Analysis: " + label.get(flow) + "!\n\n");
    }
    s += ("Analyzed " + label.keySet().size() + " flows.");
    // log.info(s);
    return s;
}
Also used : TopologyVertex(org.onosproject.net.topology.TopologyVertex) DeviceId(org.onosproject.net.DeviceId) FlowEntry(org.onosproject.net.flow.FlowEntry) HashSet(java.util.HashSet)

Example 2 with TopologyVertex

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

the class DefaultTopology method disjointPaths.

/**
 * Computes on-demand the set of shortest disjoint risk groups path pairs
 * between source and destination devices.
 *
 * @param src         source device
 * @param dst         destination device
 * @param weigher     edge weight object
 * @param riskProfile map representing risk groups for each edge
 * @return set of shortest disjoint paths
 */
private Set<DisjointPath> disjointPaths(DeviceId src, DeviceId dst, LinkWeigher weigher, Map<TopologyEdge, Object> riskProfile) {
    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();
    }
    SrlgGraphSearch<TopologyVertex, TopologyEdge> srlg = new SrlgGraphSearch<>(riskProfile);
    GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = srlg.search(graph, srcV, dstV, weigher, defaultMaxPaths);
    ImmutableSet.Builder<DisjointPath> builder = ImmutableSet.builder();
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        DisjointPath disjointPath = networkDisjointPath((DisjointPathPair<TopologyVertex, TopologyEdge>) path);
        if (disjointPath.backup() != null) {
            builder.add(disjointPath);
        }
    }
    return builder.build();
}
Also used : DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) TopologyEdge(org.onosproject.net.topology.TopologyEdge) GraphPathSearch(org.onlab.graph.GraphPathSearch) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) SrlgGraphSearch(org.onlab.graph.SrlgGraphSearch) DefaultDisjointPath(org.onosproject.net.DefaultDisjointPath) DisjointPath(org.onosproject.net.DisjointPath)

Example 3 with TopologyVertex

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

the class DefaultTopology method buildTopologyClusters.

// Builds the topology clusters and returns the id-cluster bindings.
private ImmutableMap<ClusterId, TopologyCluster> buildTopologyClusters() {
    ImmutableMap.Builder<ClusterId, TopologyCluster> clusterBuilder = ImmutableMap.builder();
    SccResult<TopologyVertex, TopologyEdge> results = clusterResults.get();
    // Extract both vertexes and edges from the results; the lists form
    // pairs along the same index.
    List<Set<TopologyVertex>> clusterVertexes = results.clusterVertexes();
    List<Set<TopologyEdge>> clusterEdges = results.clusterEdges();
    // Scan over the lists and create a cluster from the results.
    for (int i = 0, n = results.clusterCount(); i < n; i++) {
        Set<TopologyVertex> vertexSet = clusterVertexes.get(i);
        Set<TopologyEdge> edgeSet = clusterEdges.get(i);
        ClusterId cid = ClusterId.clusterId(i);
        DefaultTopologyCluster cluster = new DefaultTopologyCluster(cid, vertexSet.size(), edgeSet.size(), findRoot(vertexSet));
        clusterBuilder.put(cid, cluster);
    }
    return clusterBuilder.build();
}
Also used : DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ClusterId(org.onosproject.net.topology.ClusterId) TopologyCluster(org.onosproject.net.topology.TopologyCluster) DefaultTopologyCluster(org.onosproject.net.topology.DefaultTopologyCluster) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultTopologyCluster(org.onosproject.net.topology.DefaultTopologyCluster)

Example 4 with TopologyVertex

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

the class DefaultTopology method getDisjointPaths.

/**
 * Computes on-demand the set of shortest disjoint path pairs between
 * source and destination devices.
 *
 * @param src     source device
 * @param dst     destination device
 * @param weigher link weight function
 * @return set of disjoint shortest path pairs
 */
public Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst, LinkWeigher weigher) {
    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 = SUURBALLE.search(graph, srcV, dstV, weigher, defaultMaxPaths);
    ImmutableSet.Builder<DisjointPath> builder = ImmutableSet.builder();
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        DisjointPath disjointPath = networkDisjointPath((DisjointPathPair<TopologyVertex, TopologyEdge>) path);
        if (disjointPath.backup() != null) {
            builder.add(disjointPath);
        }
    }
    return builder.build();
}
Also used : 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) DefaultDisjointPath(org.onosproject.net.DefaultDisjointPath) DisjointPath(org.onosproject.net.DisjointPath)

Example 5 with TopologyVertex

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

the class DefaultTopology method getKShortestPaths.

/**
 * Lazily computes on-demand the k-shortest paths between source and
 * destination devices.
 *
 * @param src     source device
 * @param dst     destination device
 * @param weigher link weight function
 * @return stream of k-shortest paths
 */
public Stream<Path> getKShortestPaths(DeviceId src, DeviceId dst, LinkWeigher weigher) {
    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 Stream.empty();
    }
    return LAZY_KSHORTEST.lazyPathSearch(graph, srcV, dstV, weigher).map(this::networkPath);
}
Also used : DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex) TopologyVertex(org.onosproject.net.topology.TopologyVertex) DefaultTopologyVertex(org.onosproject.net.topology.DefaultTopologyVertex)

Aggregations

TopologyVertex (org.onosproject.net.topology.TopologyVertex)10 DefaultTopologyVertex (org.onosproject.net.topology.DefaultTopologyVertex)8 TopologyEdge (org.onosproject.net.topology.TopologyEdge)7 ImmutableSet (com.google.common.collect.ImmutableSet)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 GraphPathSearch (org.onlab.graph.GraphPathSearch)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DefaultDisjointPath (org.onosproject.net.DefaultDisjointPath)3 DeviceId (org.onosproject.net.DeviceId)3 DisjointPath (org.onosproject.net.DisjointPath)3 Link (org.onosproject.net.Link)3 Set (java.util.Set)2 DefaultTopologyCluster (org.onosproject.net.topology.DefaultTopologyCluster)2 TopologyCluster (org.onosproject.net.topology.TopologyCluster)2 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 SrlgGraphSearch (org.onlab.graph.SrlgGraphSearch)1 DefaultLink (org.onosproject.net.DefaultLink)1