Exemplo n.º 1
0
    def calc_star_uptime(self, n, link_fail):
        '''Calc star uptime.

        NOTE: n is the number of nodes.'''
        # Correct for NetworkX, which adds one to n.
        g = nx.star_graph(n - 1)
        # Node 0 is the center of the star.
        edges = g.number_of_edges()
        nodes = g.number_of_nodes()
        paths = nx.single_source_shortest_path(g, g.nodes()[1])
        used = flatten(paths)
        sssp_edges = used.number_of_edges()
        if sssp_edges != g.number_of_edges():
            raise Exception("edge not on sssp for star graph")

        # consider those times when a link failed:
        # first, consider failure on outside of graph
        exp_uptime_outer = link_fail * edges * ((float(edges - 1) / edges) * float(edges) / nodes + \
                                                (float(1) / edges) * float(1) / nodes)
        exp_uptime_outer += (1.0 - (link_fail * sssp_edges)) * 1.0

        # consider only the hub as a controller:
        exp_uptime_inner = link_fail * edges * ((float(edges) / edges) * float(edges) / nodes)
        exp_uptime_inner += (1.0 - (link_fail * edges)) * 1.0

        # merge:
        exp_uptime_weighted = float(edges * exp_uptime_outer + 1 * exp_uptime_inner) / nodes
        return exp_uptime_weighted
Exemplo n.º 2
0
    def calc_star_uptime(self, n, link_fail):
        '''Calc star uptime.

        NOTE: n is the number of nodes.'''
        # Correct for NetworkX, which adds one to n.
        g = nx.star_graph(n - 1)
        # Node 0 is the center of the star.
        edges = g.number_of_edges()
        nodes = g.number_of_nodes()
        paths = nx.single_source_shortest_path(g, list(g.nodes())[1])
        used = flatten(paths)
        sssp_edges = used.number_of_edges()
        if sssp_edges != g.number_of_edges():
            raise Exception("edge not on sssp for star graph")

        # consider those times when a link failed:
        # first, consider failure on outside of graph
        exp_uptime_outer = link_fail * edges * ((float(edges - 1) / edges) * float(edges) / nodes + \
                                                (float(1) / edges) * float(1) / nodes)
        exp_uptime_outer += (1.0 - (link_fail * sssp_edges)) * 1.0

        # consider only the hub as a controller:
        exp_uptime_inner = link_fail * edges * ((float(edges) / edges) * float(edges) / nodes)
        exp_uptime_inner += (1.0 - (link_fail * edges)) * 1.0

        # merge:
        exp_uptime_weighted = float(edges * exp_uptime_outer + 1 * exp_uptime_inner) / nodes
        return exp_uptime_weighted
Exemplo n.º 3
0
 def calc_complete_uptime(self, n, link_fail):
     g = nx.complete_graph(n)
     # edges in a complete graph:
     edges = n * (n - 1) / 2
     if edges != g.number_of_edges():
         raise Exception("fix number of edges for complete graphs")
     paths = nx.single_source_shortest_path(g, g.nodes()[0])
     used = flatten(paths)
     sssp_edges = used.number_of_edges()
     nodes = g.number_of_nodes()
     # consider those times when a link failed
     exp_uptime = link_fail * (sssp_edges * (float(sssp_edges) / nodes) + (edges - sssp_edges) * 1.0)
     # consider no-failures case
     exp_uptime += (1.0 - (link_fail * edges)) * 1.0
     return exp_uptime
Exemplo n.º 4
0
Arquivo: cc.py Projeto: sdsd08013/cpp
def sssp_conn_single(g, controller_node, link_fail_prob):
    # Store pairs of (probability, connectivity)
    uptime_dist = []

    # Compute SSSP.
    # Need a list of nodes from each switch to the controller to see how
    # connectivity changes when links go down.
    paths = nx.single_source_shortest_path(g, controller_node)
    # Store the flattened set of shortest paths to the controller as a
    # graph.  Useful later to only consider those nodes or edges that might
    # have an effect on reliability.
    used = flatten(paths)

    for failed_edge in g.edges():
        lg.debug("------------------------")
        lg.debug("considering failed edge: %s" % str(failed_edge))

        # If failed edge is not a part of the path set, then no effect on
        # reliability.
        if used.has_edge(failed_edge[0], failed_edge[1]):
            # Failed edge matters for connectivity for some switch.

            # Check switch-to-controller connectivity.
            connected = 0
            disconnected = 0
            for sw in g.nodes():
                path_graph = nx.Graph()
                #path_graph.add_path(paths[sw])
                nx.add_path(path_graph, paths[sw])
                #lg.debug("path graph edges: %s" % path_graph.edges())
                if path_graph.has_edge(failed_edge[0], failed_edge[1]):
                    lg.debug("disconnected sw: %s" % sw)
                    disconnected += 1
                else:
                    lg.debug("connected sw: %s" % sw)
                    connected += 1
            connectivity = float(connected) / g.number_of_nodes()
            uptime_dist.append((link_fail_prob, connectivity))
        else:
            # No effect on connectivity.
            lg.debug("edge not in sssp graph; ignoring")
            uptime_dist.append((link_fail_prob, 1.0))

    return uptime_dist
Exemplo n.º 5
0
Arquivo: cc.py Projeto: NKSG/cpp
def sssp_conn_single(g, controller_node, link_fail_prob):
    # Store pairs of (probability, connectivity)
    uptime_dist = []

    # Compute SSSP.
    # Need a list of nodes from each switch to the controller to see how
    # connectivity changes when links go down.
    paths = nx.single_source_shortest_path(g, controller_node)
    # Store the flattened set of shortest paths to the controller as a
    # graph.  Useful later to only consider those nodes or edges that might
    # have an effect on reliability.
    used = flatten(paths)

    for failed_edge in g.edges():
        lg.debug("------------------------")
        lg.debug("considering failed edge: %s" % str(failed_edge))

        # If failed edge is not a part of the path set, then no effect on
        # reliability.
        if used.has_edge(failed_edge[0], failed_edge[1]):
            # Failed edge matters for connectivity for some switch.

            # Check switch-to-controller connectivity.
            connected = 0
            disconnected = 0
            for sw in g.nodes():
                path_graph = nx.Graph()
                path_graph.add_path(paths[sw])
                #lg.debug("path graph edges: %s" % path_graph.edges())
                if path_graph.has_edge(failed_edge[0], failed_edge[1]):
                    lg.debug("disconnected sw: %s" % sw)
                    disconnected += 1
                else:
                    lg.debug("connected sw: %s" % sw)
                    connected += 1
            connectivity = float(connected) / g.number_of_nodes()
            uptime_dist.append((link_fail_prob, connectivity))
        else:
            # No effect on connectivity.
            lg.debug("edge not in sssp graph; ignoring")
            uptime_dist.append((link_fail_prob, 1.0))

    return uptime_dist