Exemplo n.º 1
0
    def setUp(self):
        edges: List[Tuple[int, int]] = [(1, 5), (2, 6), (3, 8), (4, 11), (5, 6), (5, 9),
                                        (6, 7), (7, 9), (7, 8), (8, 9), (8, 11), (9, 10), (10, 11)]
        self.graph: nx.Graph = nx.Graph()
        self.graph.add_edges_from(edges)
        self.graph = self.graph.to_directed()
        TopoGenerator.draw(self.graph)

        config.TESTING['generate-flow'] = True  # whether enable flow generation or not
        config.FLOW_CONFIG['reliability-set'] = [0.5]
        config.FLOW_CONFIG['redundancy_degree'] = 2
        if config.TESTING['generate-flow']:
            attached_nodes: List[NodeId] = [1, 2, 3, 4]
            config.FLOW_CONFIG['dest-num-set'] = [1, 2, 3]
            config.FLOW_CONFIG['flow-num'] = 10
            self.flows: List[Flow] = FlowGenerator.generate_flows(edge_nodes=attached_nodes, graph=self.graph)
            FlowGenerator.save_flows(self.flows)
        else:
            self.flows: List[Flow] = FlowGenerator.load_flows()

        config.FLOW_CONFIG['redundancy_degree'] = 5
        config.GRAPH_CONFIG['routing_strategy'] = ROUTING_STRATEGY.BACKTRACKING_REDUNDANT_ROUTING_STRATEGY
        # config.GRAPH_CONFIG['routing_strategy'] = ROUTING_STRATEGY.DIJKSTRA_SINGLE_ROUTING_STRATEGY
        config.GRAPH_CONFIG['scheduling_strategy'] = SCHEDULING_STRATEGY.LRF_REDUNDANT_SCHEDULING_STRATEGY
        config.GRAPH_CONFIG['allocating_strategy'] = ALLOCATING_STRATEGY.AEAP_ALLOCATING_STRATEGY
        config.GRAPH_CONFIG['reliability-strategy'] = RELIABILITY_STRATEGY.ENUMERATION_METHOD_RELIABILITY_STRATEGY
        solver: Solver = Solver(nx_graph=self.graph,
                                flows=self.flows,
                                topo_strategy=None,
                                routing_strategy=config.GRAPH_CONFIG['routing_strategy'],
                                scheduling_strategy=config.GRAPH_CONFIG['scheduling_strategy'],
                                allocating_strategy=config.GRAPH_CONFIG['allocating_strategy'],
                                reliability_strategy=config.GRAPH_CONFIG['reliability-strategy'])
        self.solution = solver.generate_init_solution()
        solver.draw_gantt_chart(self.solution)  # draw gantt chart
        solution_name: str = solver.generate_solution_name(solution=self.solution, prefix='n7_f10_r6_')
        import os
        filename: str = os.path.join(config.res_dir, solution_name)
        solver.analyze(solution=self.solution, target_filename=filename)  # analyze solution
        config.OPTIMIZATION['enable'] = False
        if config.OPTIMIZATION['enable'] is True:
            # optimized method
            self.solution = solver.optimize()  # optimize
            solver.draw_gantt_chart(self.solution)  # draw gantt chart
            solution_name: str = solver.generate_solution_name(
                solution=self.solution,
                prefix='o_n7_f10_r5_')
            filename: str = os.path.join(config.res_dir, solution_name)
            solver.analyze(solution=self.solution, target_filename=filename)
        solver.save_solution(solution=self.solution)  # save solution

        tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory()
        tsn_network: TSNNetwork = tsn_network_factory.product(
            solution_filename=solution_name,
            enhancement_enable=config.XML_CONFIG['enhancement-tsn-switch-enable'])
        self.tsn_network = tsn_network
        self.node_edge_mac_info = tsn_network_factory.node_edge_mac_info
Exemplo n.º 2
0
    def setUp(self):
        edges: List[Tuple[int, int]] = [(1, 2), (2, 3), (2, 4), (3, 4), (3, 5),
                                        (4, 5), (3, 8), (5, 6), (5, 7)]
        self.graph: nx.Graph = nx.Graph()
        self.graph.add_edges_from(edges)
        self.graph = self.graph.to_directed()
        TopoGenerator.draw(self.graph)

        config.TESTING[
            'generate-flow'] = False  # whether enable flow generation or not
        if config.TESTING['generate-flow']:
            attached_nodes: List[NodeId] = [1, 6, 7, 8]
            config.FLOW_CONFIG['dest-num-set'] = [1, 2, 3]
            config.FLOW_CONFIG['flow-num'] = 5
            self.flows: List[Flow] = FlowGenerator.generate_flows(
                edge_nodes=attached_nodes, graph=self.graph)
            FlowGenerator.save_flows(self.flows)
        else:
            self.flows: List[Flow] = FlowGenerator.load_flows()

        config.GRAPH_CONFIG[
            'routing_strategy'] = ROUTING_STRATEGY.BACKTRACKING_REDUNDANT_ROUTING_STRATEGY
        # config.GRAPH_CONFIG['routing_strategy'] = ROUTING_STRATEGY.DIJKSTRA_SINGLE_ROUTING_STRATEGY
        config.GRAPH_CONFIG[
            'scheduling_strategy'] = SCHEDULING_STRATEGY.LRF_REDUNDANT_SCHEDULING_STRATEGY
        config.GRAPH_CONFIG[
            'allocating_strategy'] = ALLOCATING_STRATEGY.AEAP_ALLOCATING_STRATEGY
        solver: Solver = Solver(
            nx_graph=self.graph,
            flows=self.flows,
            topo_strategy=None,
            routing_strategy=config.GRAPH_CONFIG['routing_strategy'],
            scheduling_strategy=config.GRAPH_CONFIG['scheduling_strategy'],
            allocating_strategy=config.GRAPH_CONFIG['allocating_strategy'])
        self.solution = solver.generate_init_solution()
        solver.draw_gantt_chart(self.solution)  # draw gantt chart
        solution_name: str = solver.generate_solution_name(
            solution=self.solution)
        import os
        filename: str = os.path.join(config.res_dir, solution_name)
        solver.analyze(solution=self.solution,
                       target_filename=filename)  # analyze solution
        solver.save_solution(solution=self.solution)  # save solution

        tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory()
        tsn_network: TSNNetwork = tsn_network_factory.product(
            solution_filename=solution_name,
            enhancement_enable=config.
            XML_CONFIG['enhancement-tsn-switch-enable'])
        self.tsn_network = tsn_network
        self.node_edge_mac_info = tsn_network_factory.node_edge_mac_info
Exemplo n.º 3
0
 def setUp(self):
     topo_generator: TopoGenerator = TopoGenerator()
     topo_strategy_entity: Dict = {
         'strategy': TOPO_STRATEGY.BA_STRATEGY,
         'n': 5,
         'm': 2,
     }
     config.GRAPH_CONFIG['edge-nodes-distribution-degree'] = 2
     config.FLOW_CONFIG['dest-num-set'] = [1, 2]
     config.FLOW_CONFIG['flow-num'] = 3
     topo_generator.topo_strategy = TopoStrategyFactory.get_instance(
         **topo_strategy_entity)
     graph: nx.Graph = topo_generator.generate_core_topo()
     attached_edge_nodes_num: int = 3
     attached_edge_nodes: List[NodeId] = topo_generator.attach_edge_nodes(
         graph, attached_edge_nodes_num)
     topo_generator.draw(graph)
     config.TESTING['generate-flow'] = False
     if config.TESTING['generate-flow']:
         flows: List[Flow] = FlowGenerator.generate_flows(
             edge_nodes=attached_edge_nodes, graph=graph)
         FlowGenerator.save_flows(flows)
     else:
         flows: List[Flow] = FlowGenerator.load_flows()
     solver: Solver = Solver(
         nx_graph=graph,
         flows=flows,
         topo_strategy=topo_strategy_entity['strategy'],
         routing_strategy=ROUTING_STRATEGY.
         BACKTRACKING_REDUNDANT_ROUTING_STRATEGY,
         scheduling_strategy=SCHEDULING_STRATEGY.
         LRF_REDUNDANT_SCHEDULING_STRATEGY,
         allocating_strategy=ALLOCATING_STRATEGY.AEAP_ALLOCATING_STRATEGY)
     solver.visual = True
     self.solution = solver.generate_init_solution()
     self.solution.solution_name = 'solution'
     solver.save_solution(solution=self.solution)
     tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory()
     tsn_network: TSNNetwork = tsn_network_factory.product(
         solution_filename='solution',
         enhancement_enable=config.
         XML_CONFIG['enhancement-tsn-switch-enable'])
     self.node_edge_mac_info = tsn_network_factory.node_edge_mac_info
     logger.info(str(tsn_network.__class__) + ': ' + str(tsn_network))
     self.tsn_network = tsn_network
    def run_test(self, combinations: List = None):
        for combination in combinations:
            # create flows
            if combination['enable_flow_gen']:
                attached_nodes: List[NodeId] = [1, 2, 3, 4]
                self.flows: List[Flow] = FlowGenerator.generate_flows(
                    edge_nodes=attached_nodes, graph=self.graph)
                FlowGenerator.save_flows(self.flows)
            else:
                self.flows: List[Flow] = FlowGenerator.load_flows()
            # origin method
            solver: Solver = Solver(
                nx_graph=self.graph,
                flows=self.flows[:],
                topo_strategy=None,
                routing_strategy=combination['routing_strategy'],
                scheduling_strategy=combination['scheduling_strategy'],
                allocating_strategy=combination['allocating_strategy'],
                reliability_strategy=combination['reliability_strategy'])
            self.solution = solver.generate_init_solution()
            solver.draw_gantt_chart(self.solution)  # draw gantt chart
            solution_name: str = self.solution.generate_solution_name(
                prefix='b_n7_f10_')

            if combination['enable_op']:
                # optimized method
                self.solution = solver.optimize()  # optimize
                solver.draw_gantt_chart(self.solution)  # draw gantt chart
                solution_name: str = self.solution.generate_solution_name(
                    prefix='o_n7_f10_')
            solver.save_solution(solution=self.solution)  # save solution
            # create network
            tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory()
            tsn_network: TSNNetwork = tsn_network_factory.product(
                solution_filename=solution_name,
                enhancement_enable=config.
                XML_CONFIG['enhancement-tsn-switch-enable'])
            self.tsn_network = tsn_network
            self.node_edge_mac_info = tsn_network_factory.node_edge_mac_info
            # create test scenario
            ConfigFileGenerator.create_test_scenario(
                tsn_network=self.tsn_network,
                solution=self.solution,
                node_edge_mac_info=self.node_edge_mac_info)
Exemplo n.º 5
0
 def test_graph_size(self):
     topo_generator: TopoGenerator = TopoGenerator()
     flow_properties: List[Dict] = FlowGenerator.generate_flow_properties(
         config.FLOW_CONFIG['flow-num'])
     for test_round in range(config.TESTING['round'][0],
                             config.TESTING['round'][1] + 1):
         for graph_size in range(config.TESTING['graph-core-size'][0],
                                 config.TESTING['graph-core-size'][1] + 1,
                                 config.TESTING['x-axis-gap']):
             for topo_strategy_entity in config.GRAPH_CONFIG[
                     'topo-strategy']:
                 topo_strategy_entity['n'] = graph_size
                 topo_strategy: TopoStrategy = TopoStrategyFactory.get_instance(
                     **topo_strategy_entity)
                 topo_generator.topo_strategy = topo_strategy
                 config.GRAPH_CONFIG['core-node-num'] = graph_size
                 # config.GRAPH_CONFIG['edge-nodes-distribution-degree'] = \
                 #     int(graph_size * 0.6) if int(graph_size * 0.6) < config.GRAPH_CONFIG['edge-node-num'] \
                 #     else config.GRAPH_CONFIG['edge-node-num']
                 config.GRAPH_CONFIG['edge-nodes-distribution-degree'] = 6
                 # generate topology
                 graph: nx.Graph = topo_generator.generate_core_topo()
                 attached_edge_nodes_num: int = config.GRAPH_CONFIG[
                     'edge-node-num']
                 attached_edge_nodes: List[
                     NodeId] = topo_generator.attach_edge_nodes(
                         graph, attached_edge_nodes_num)
                 topo_generator.draw(graph)
                 flows: List[Flow] = FlowGenerator.generate_flows(
                     edge_nodes=attached_edge_nodes,
                     graph=graph,
                     flow_properties=flow_properties)
                 solver: Solver = Solver(
                     nx_graph=graph,
                     flows=flows,
                     topo_strategy=topo_strategy_entity['strategy'],
                     routing_strategy=config.
                     GRAPH_CONFIG['routing-strategy'],
                     scheduling_strategy=config.
                     GRAPH_CONFIG['scheduling-strategy'],
                     allocating_strategy=config.
                     GRAPH_CONFIG['allocating-strategy'])
                 try:
                     import time
                     import os
                     # origin method
                     self.solution = solver.generate_init_solution(
                     )  # get initial solution
                     solution_name: str = solver.generate_solution_name(
                         solution=self.solution,
                         prefix='gz_t{}_f{}_'.format(
                             test_round, len(flows)))
                     filename: str = os.path.join(config.graph_size_res_dir,
                                                  solution_name)
                     solver.analyze(
                         solution=self.solution,
                         target_filename=filename)  # analyze solution
                     if config.OPTIMIZATION['enable'] is True:
                         # optimized method
                         self.solution = solver.optimize()  # optimize
                         solution_name: str = solver.generate_solution_name(
                             solution=self.solution,
                             prefix='o_gz_t{}_f{}_'.format(
                                 test_round, len(flows)))
                         filename: str = os.path.join(
                             config.graph_size_res_dir, solution_name)
                         solver.analyze(solution=self.solution,
                                        target_filename=filename)
                 except:
                     # save flows if error happen
                     FlowGenerator.save_flows(flows)
Exemplo n.º 6
0
 def test_flow_size(self):
     topo_generator: TopoGenerator = TopoGenerator()
     for topo_strategy_entity in config.GRAPH_CONFIG['topo-strategy']:
         topo_strategy: TopoStrategy = TopoStrategyFactory.get_instance(
             **topo_strategy_entity)
         topo_generator.topo_strategy = topo_strategy
         for test_round in range(config.TESTING['round'][0],
                                 config.TESTING['round'][1] + 1):
             self.round = test_round
             # generate topology
             graph: nx.Graph = topo_generator.generate_core_topo()
             attached_edge_nodes_num: int = config.GRAPH_CONFIG[
                 'edge-node-num']
             attached_edge_nodes: List[
                 NodeId] = topo_generator.attach_edge_nodes(
                     graph, attached_edge_nodes_num)
             topo_generator.draw(graph)
             # generate flows
             flows: List[Flow] = FlowGenerator.generate_flows(
                 edge_nodes=attached_edge_nodes,
                 graph=graph,
                 flow_num=config.TESTING['flow-size'][1])
             for i in range(config.TESTING['flow-size'][0],
                            config.TESTING['flow-size'][1] + 1,
                            config.TESTING['x-axis-gap']):
                 solver: Solver = Solver(
                     nx_graph=graph,
                     flows=flows[:i],
                     topo_strategy=topo_strategy_entity['strategy'],
                     routing_strategy=config.
                     GRAPH_CONFIG['routing-strategy'],
                     scheduling_strategy=config.
                     GRAPH_CONFIG['scheduling-strategy'],
                     allocating_strategy=config.
                     GRAPH_CONFIG['allocating-strategy'],
                     reliability_strategy=config.
                     GRAPH_CONFIG['reliability-strategy'])
                 try:
                     import time
                     import os
                     # origin method
                     self.solution = solver.generate_init_solution(
                     )  # get initial solution
                     self.solution.generate_solution_name(
                         prefix='b_fz_t{}_n{}_'.format(
                             test_round, len(self.solution.graph.nodes)))
                     Analyzer.analyze_flow_size(
                         self.solution,
                         target_filename=os.path.join(
                             config.flow_size_res_dir,
                             self.solution.solution_name))
                     self.solution.generate_solution_name(
                         prefix='b_fz_t{}_n{}_f{}_'.format(
                             test_round, len(self.solution.graph.nodes), i))
                     Analyzer.analyze_flow_routes_repetition_degree(
                         self.solution,
                         target_filename=os.path.join(
                             config.flow_routes_repetition_degree_dir,
                             self.solution.solution_name))
                     if config.OPTIMIZATION['enable'] is True:
                         # optimized method
                         self.solution = solver.optimize()  # optimize
                         self.solution.generate_solution_name(
                             prefix='o_fz_t{}_n{}_'.format(
                                 test_round, len(
                                     self.solution.graph.nodes)))
                         Analyzer.analyze_flow_size(
                             self.solution,
                             target_filename=os.path.join(
                                 config.flow_size_res_dir,
                                 self.solution.solution_name))
                         self.solution.generate_solution_name(
                             prefix='o_fz_t{}_n{}_f{}_'.format(
                                 test_round, len(self.solution.graph.nodes),
                                 i))
                         Analyzer.analyze_flow_routes_repetition_degree(
                             self.solution,
                             target_filename=os.path.join(
                                 config.flow_routes_repetition_degree_dir,
                                 self.solution.solution_name))
                 except:
                     # save flows if error happen
                     FlowGenerator.save_flows(flows)