def test_mininet_conversion_to_logical():
    """Test the conversion from a mininet logical network to a logical one."""

    import networkx as nx
    from distriopt import VirtualNetwork
    from mininet.topo import Topo

    virt_topo_mn = Topo()

    # Add nodes
    u = virt_topo_mn.addHost("u", cores=2, memory=1000)
    v = virt_topo_mn.addHost("v", cores=2, memory=1000)
    z = virt_topo_mn.addSwitch("z", cores=2, memory=1000)
    # Add links
    virt_topo_mn.addLink(u, v, rate=1000)
    virt_topo_mn.addLink(v, z, rate=1000)
    virt_topo_mn.addLink(u, z, rate=1000)

    virtual_topo = VirtualNetwork.from_mininet(virt_topo_mn)

    assert virtual_topo.number_of_nodes() == 3
    assert len(virtual_topo.edges()) == 3
    assert nx.is_connected(virtual_topo.g)

    for node in virtual_topo.nodes():
        assert virtual_topo.req_cores(node) == 2
        assert virtual_topo.req_memory(node) == 1000
    for i, j in virtual_topo.edges():
        assert virtual_topo.req_rate(i, j) == 1000
예제 #2
0
def virtual_nw():
    g = nx.Graph()
    g.add_node("Node_0", cores=3, memory=3000)
    g.add_node("Node_1", cores=3, memory=3000)
    g.add_edge("Node_0", "Node_1", rate=20000)

    yield VirtualNetwork(g)
예제 #3
0
def main():
    virtual_topo_file = sys.argv[1]
    physical_topo_file = sys.argv[2]
    mapper = sys.argv[3]

    virtual = VirtualNetwork.from_file(virtual_topo_file)
    physical = PhysicalNetwork.from_files(physical_topo_file)
    if mapper not in MAPPERS:
        raise ValueError(f"{mapper} not in {MAPPERS}")
    algo = MAPPERS[mapper]
    prob = algo(virtual, physical)
    time_solution, status = prob.solve()
    temp = tempfile.NamedTemporaryFile(delete=False)
    try:
        if status == 1:
            # problem solved
            with open(temp.name, "w") as f:
                json.dump({"mapping": prob.solution.node_mapping}, f)
        else:
            with open(temp.name, "w") as f:
                json.dump({"Infeasible": None}, f)

        print(temp.name, end="")
    except:
        raise RuntimeError("problem in distrinet_runner.py")
예제 #4
0
 def __init__(self, virtual, physical):
     """"""
     self.virtual = (VirtualNetwork.from_mininet(virtual) if isinstance(
         virtual, Topo) else virtual)
     self.physical = physical
     self.solution = None
     self.status = NotSolved
     self.lb = 0
def test_logical_ec2():
    """Test the creation of a logical EC2 random instance."""

    from distriopt import VirtualNetwork

    virtual = VirtualNetwork.create_random_EC2(n_nodes=10)
    for node in virtual.nodes():
        assert virtual.req_cores(node) in range(1, 9)
        assert virtual.req_memory(node) in [512] + list(range(1024, 8193, 1024))
예제 #6
0
파일: mapper.py 프로젝트: helllb/Distrinet
    def __init__(self, virtual_topo, physical_topo, solver=EmbedGreedy):
        """ virtual_topo: virtual topology to map
            physical_topo: physical topology to map on
            solver: solver class to use to solve the mapping"""
        self.virtual_topo = VirtualNetwork.from_mininet(virtual_topo)
        self.mininet_virtual = virtual_topo
        self.physical_topo = PhysicalNetwork.from_files(physical_topo)
        self.prob = None
        self.solver = solver
        self.solve()

        self.places = self.__places()
예제 #7
0
파일: mapper.py 프로젝트: helllb/Distrinet
    def __init__(self, virtual_topo, cloud_prices, solver=BestFitDopProduct):
        """ virtual_topo: virtual topology to map
            physical_topo: physical topology to map on
            solver: solver class to use to solve the mapping"""
        self.virtual_topo = VirtualNetwork.from_mininet(virtual_topo)
        self.cloud = CloudInstance.read_ec2_instances(vm_type=cloud_prices)
        self.mininet_virtual = virtual_topo
        self.prob = None

        self.solver = solver

        self.places = self.__places()
def test_logical_random():
    """Test the creation of a logical random network topology."""

    from distriopt import VirtualNetwork

    virtual = VirtualNetwork.create_random_nw(
        20, req_cores=2, req_memory=8000, req_rate=200
    )
    assert virtual.number_of_nodes() == 20
    for node in virtual.nodes():
        assert virtual.req_cores(node) == 2
        assert virtual.req_memory(node) == 8000
    for i, j in virtual.edges():
        assert virtual.req_rate(i, j) == 200
def test_logical_fat_tree():
    """Test the creation of a logical fat tree network topology"""

    from distriopt import VirtualNetwork

    virtual = VirtualNetwork.create_fat_tree(
        k=4, density=2, req_cores=2, req_memory=8000, req_rate=200
    )
    assert virtual.number_of_nodes() == 36
    assert len(virtual.edges()) == 48
    for node in virtual.nodes():
        assert virtual.req_cores(node) == 2
        assert virtual.req_memory(node) == 8000
    for i, j in virtual.edges():
        assert virtual.req_rate(i, j) == 200
예제 #10
0
            self.status = Infeasible
            return Infeasible


if __name__ == "__main__":
    from distriopt.embedding import PhysicalNetwork
    from distriopt import VirtualNetwork

    import networkx as nx

    g = nx.Graph()
    g.add_node("Node_0", cores=3, memory=3000)
    g.add_node("Node_1", cores=3, memory=3000)
    g.add_edge("Node_0", "Node_1", rate=20000)

    virtual_topo = VirtualNetwork(g)

    # unfeasible, not enough rate
    physical_topo = PhysicalNetwork.create_test_nw(cores=4,
                                                   memory=4000,
                                                   rate=10000,
                                                   group_interfaces=False)

    prob = EmbedPartition(virtual_topo, physical_topo)
    time_solution, status = prob.solve()
    print(status)

    exit(1)

    physical_topo = PhysicalNetwork.from_files("grisou",
                                               group_interfaces=False)
예제 #11
0
                        res_link_mapping[(u, v)].append((i, device_id, j))

                # build solution from the output
                self.solution = Solution.build_solution(
                    self.virtual, self.physical, res_node_mapping, res_link_mapping
                )
                self.status = Solved
                return Solved

            except (NodeResourceError, NoPathFoundError):
                # unfeasible, increase the number of partitions to be used
                pass
        else:
            self.status = Infeasible
            return Infeasible


if __name__ == "__main__":
    from distriopt.embedding import PhysicalNetwork
    from distriopt import VirtualNetwork

    physical_topo = PhysicalNetwork.from_files("grisou", group_interfaces=True)
    virtual_topo = VirtualNetwork.create_random_nw(n_nodes=120, seed=1)
    # virtual_topo = VirtualNetwork.create_fat_tree(k=4)

    embed = EmbedBalanced(virtual_topo, physical_topo)
    time_solution = embed.solve()
    print(time_solution, embed.status, embed.solution.n_machines_used)
    exit(1)
    print(embed.solution)
예제 #12
0
파일: mapper.py 프로젝트: helllb/Distrinet
            node: node in the virtual topology
            return: name of the physical host to use
        """
        if self.prob == None:
            self.solve()
        place = self.prob.solution.node_info(node)

        return place

    def placeLink(self, link):
        """ Returns physical placement of the link
            link: link in the virtual topology
            returns: list of placements for the link
        """
        if self.prob == None:
            self.solve()

        place = self.prob.solution.link_mapping[link]

        return place


if __name__ == '__main__':
    #physical = PhysicalNetwork.from_files("/Users/giuseppe/.distrinet/gros_partial")
    virtual_topo = VirtualNetwork.create_fat_tree(k=2,
                                                  density=2,
                                                  req_cores=2,
                                                  req_memory=100,
                                                  req_rate=100)
    from distriopt.packing import CloudInstance
예제 #13
0
def time_comparison_grid5000(timelimit, net_type="fat-tree"):
    """
    Custom Network  (for the moment fat tree and random are available on virtual.py)
    """
    # create the physical network representation
    physical = PhysicalNetwork.from_files("grisou")

    solvers_ilp = {"cplex"}
    solvers_heu = {
        "GreedyPartition": EmbedGreedy,
        "k-balanced": EmbedBalanced,
        "DivideSwap": EmbedPartition,
    }

    res_experiments = {"x": [], "time": {}, "value": {}}
    for method_name in solvers_ilp | solvers_heu.keys():
        res_experiments["time"][method_name] = {}
        res_experiments["value"][method_name] = {}

    if net_type == "fat-tree":
        min_v = 2
        max_v = 12
        step_size = 2
    elif net_type == "random":
        min_v = 25
        max_v = 175
        step_size = 25
    else:
        raise ValueError("invalid experiment type")

    for v in range(min_v, max_v + 1, step_size):
        res_experiments["x"].append(v)

        if net_type == "fat-tree":
            virtual = VirtualNetwork.create_fat_tree(v)
        else:
            virtual = VirtualNetwork.create_random_nw(v)

        # ILP solver
        prob = EmbedILP(virtual, physical)

        for solver_name in solvers_ilp:

            time_solution, status = prob.solve(solver_name=solver_name,
                                               timelimit=timelimit)

            if SolutionStatus[status] != "Solved":
                res_experiments["time"][solver_name][v] = time_solution
                res_experiments["value"][solver_name][v] = prob.current_val
            else:
                res_experiments["time"][solver_name][v] = time_solution
                res_experiments["value"][solver_name][
                    v] = prob.solution.n_machines_used

        # Heuristic approaches
        for heu in solvers_heu:
            prob = solvers_heu[heu](virtual, physical)
            time_solution, status = prob.solve()

            if SolutionStatus[status] == "Not Solved":
                sys.exit("Failed to solve")
            elif SolutionStatus[status] == "Unfeasible":
                sys.exit("unfeasible Problem")
            else:
                pass

            res_experiments["time"][heu][v] = time_solution
            res_experiments["value"][heu][v] = prob.solution.n_machines_used

        pprint.pprint(res_experiments)

        with open(
                os.path.join("results", f"res_{net_type}_{timelimit}s.pickle"),
                "wb") as res_file:
            pickle.dump(res_experiments,
                        res_file,
                        protocol=pickle.HIGHEST_PROTOCOL)