def run_test(self, combinations: List = None): for combination in combinations: # 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_n4_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)
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
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
def setUp(self): config.TESTING['round'] = [1, 5] # [1, 5] config.TESTING['flow-size'] = [10, 100] config.TESTING['x-axis-gap'] = 5 config.TESTING['draw-gantt-chart'] = False config.OPTIMIZATION['enable'] = True config.GRAPH_CONFIG['all-bandwidth'] = 0.5 # 500Mbps config.GRAPH_CONFIG['core-node-num'] = 10 config.GRAPH_CONFIG['edge-node-num'] = 10 config.GRAPH_CONFIG['topo-strategy'] = [ { 'strategy': TOPO_STRATEGY.ER_STRATEGY, 'type': ErdosRenyiStrategy.ER_TYPE.GNP, 'n': 10, 'm': 14, 'p': 0.2, }, { 'strategy': TOPO_STRATEGY.BA_STRATEGY, 'n': 10, 'm': 2, }, { 'strategy': TOPO_STRATEGY.RRG_STRATEGY, 'd': 3, 'n': 10, }, { 'strategy': TOPO_STRATEGY.WS_STRATEGY, 'n': 10, 'k': 4, 'p': 1.0, }, ] self.topo_generator = TopoGenerator() self.tsn_network_factory = TSNNetworkFactory()
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)
def run_test(self, combinations: List = None): for combination in combinations: # 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']) solution = solver.generate_init_solution() solution.generate_solution_name(prefix='b_fixed_f{}_n{}_'.format(10, 10)) Analyzer.analyze_per_flow( solution, target_filename=os.path.join(config.solutions_res_dir, solution.solution_name)) if config.TESTING['draw-gantt-chart'] is True: solver.draw_gantt_chart(solution) logger.info('Native Objective: ' + str(solver.objective_function(solution))) # optimization method if config.OPTIMIZATION['enable'] is False or \ combination['allocating_strategy'] == ALLOCATING_STRATEGY.AEAPBF_ALLOCATING_STRATEGY or \ combination['allocating_strategy'] == ALLOCATING_STRATEGY.AEAPWF_ALLOCATING_STRATEGY or \ combination['routing_strategy'] == ROUTING_STRATEGY.DIJKSTRA_SINGLE_ROUTING_STRATEGY: continue solution = solver.optimize() # optimize solution.generate_solution_name(prefix='o_fixed_f{}_n{}_'.format(10, 10)) Analyzer.analyze_per_flow( solution, target_filename=os.path.join(config.solutions_res_dir, solution.solution_name)) if config.TESTING['draw-gantt-chart'] is True: solver.draw_gantt_chart(solution) logger.info('Optimal Objective: ' + str(solver.objective_function(solution))) # create network solver.save_solution(solution=solution) # save solution tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory() tsn_network: TSNNetwork = tsn_network_factory.product( solution_filename=solution.solution_name, enhancement_enable=config.XML_CONFIG['enhancement-tsn-switch-enable']) tsn_network = tsn_network node_edge_mac_info = tsn_network_factory.node_edge_mac_info # create test scenario ConfigFileGenerator.create_test_scenario(tsn_network=tsn_network, solution=solution, node_edge_mac_info=node_edge_mac_info)
class SimulationTestCase3(unittest.TestCase): def setUp(self): config.TESTING['round'] = [1, 5] # [1, 5] config.TESTING['flow-size'] = [10, 100] config.TESTING['x-axis-gap'] = 5 config.TESTING['draw-gantt-chart'] = False config.OPTIMIZATION['enable'] = True config.GRAPH_CONFIG['all-bandwidth'] = 0.5 # 500Mbps config.GRAPH_CONFIG['core-node-num'] = 10 config.GRAPH_CONFIG['edge-node-num'] = 10 config.GRAPH_CONFIG['topo-strategy'] = [ { 'strategy': TOPO_STRATEGY.ER_STRATEGY, 'type': ErdosRenyiStrategy.ER_TYPE.GNP, 'n': 10, 'm': 14, 'p': 0.2, }, { 'strategy': TOPO_STRATEGY.BA_STRATEGY, 'n': 10, 'm': 2, }, { 'strategy': TOPO_STRATEGY.RRG_STRATEGY, 'd': 3, 'n': 10, }, { 'strategy': TOPO_STRATEGY.WS_STRATEGY, 'n': 10, 'k': 4, 'p': 1.0, }, ] self.topo_generator = TopoGenerator() self.tsn_network_factory = TSNNetworkFactory() def test_simulation(self): for test_round in range(config.TESTING['round'][0], config.TESTING['round'][1] + 1): for topo_strategy_entity in config.GRAPH_CONFIG['topo-strategy']: topo_strategy: TopoStrategy = TopoStrategyFactory.get_instance( **topo_strategy_entity) self.topo_generator.topo_strategy = topo_strategy graph: nx.Graph = self.topo_generator.generate_core_topo() attached_edge_nodes_num: int = config.GRAPH_CONFIG[ 'edge-node-num'] attached_edge_nodes: List[ NodeId] = self.topo_generator.attach_edge_nodes( graph, attached_edge_nodes_num) self.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']): # create solver solver: Solver = Solver( nx_graph=graph, flows=None, 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']) solver.add_flows(copy.deepcopy(flows[:i])) # origin method self.solution = solver.generate_init_solution( ) # get initial solution solution_name: str = solver.generate_solution_name( solution=self.solution, prefix='b_fz_t{}_n{}_'.format( test_round, len(self.solution.graph.nodes))) filename: str = os.path.join(config.flow_size_res_dir, self.solution.solution_name) solver.analyze( solution=self.solution, target_filename=filename) # analyze solution self.solution.solution_name = self.generate_solution_filename( anchor='n{}_'.format(len(self.solution.graph.nodes)), addition='f{}_'.format(i)) solver.save_solution(filename=self.solution.solution_name) self.generate_test_scenario() # generate test scenario # optimized method if config.OPTIMIZATION['enable'] is True: self.solution = solver.optimize() # optimize solution_name: str = solver.generate_solution_name( solution=self.solution, prefix='o_fz_t{}_n{}_'.format( test_round, len(self.solution.graph.nodes))) filename: str = os.path.join( config.flow_size_res_dir, self.solution.solution_name) solver.analyze(solution=self.solution, target_filename=filename) self.solution.solution_name = self.generate_solution_filename( anchor='n{}_'.format(len( self.solution.graph.nodes)), addition='f{}_'.format(i)) solver.save_solution( filename=self.solution.solution_name) self.generate_test_scenario() # generate test scenario def generate_solution_filename(self, anchor: str, addition: str): tl: List[str] = list(self.solution.solution_name) ti: int = self.solution.solution_name.index(anchor) [tl.insert(i + ti, c) for i, c in enumerate(list(addition))] return ''.join(tl) def generate_test_scenario(self): # create tsn network tsn_network: TSNNetwork = self.tsn_network_factory.product( solution_filename=self.solution.solution_name, enhancement_enable=config. XML_CONFIG['enhancement-tsn-switch-enable']) self.tsn_network = tsn_network self.node_edge_mac_info = self.tsn_network_factory.node_edge_mac_info # generate configuration file ConfigFileGenerator.create_test_scenario( tsn_network=self.tsn_network, solution=self.solution, node_edge_mac_info=self.node_edge_mac_info)