def parse_network(self) -> dict: """ Converts the NetworkX network in the simulator to a dict in a format specified in the SimulatorState class. """ max_node_usage = metrics.get_metrics()['run_max_node_usage'] self.network_dict = {'nodes': [], 'edges': []} for node in self.params.network.nodes(data=True): node_cap = node[1]['cap'] run_max_node_usage = max_node_usage[node[0]] # 'used_resources' here is the max usage for the run. self.network_dict['nodes'].append({ 'id': node[0], 'resource': node_cap, 'used_resources': run_max_node_usage }) for edge in self.network.edges(data=True): edge_src = edge[0] edge_dest = edge[1] edge_delay = edge[2]['delay'] edge_dr = edge[2]['cap'] # We use a fixed user data rate for the edges here as the functionality is not yet incorporated in the # simulator. # TODO: Implement used edge data rates in the simulator. edge_used_dr = 0 self.network_dict['edges'].append({ 'src': edge_src, 'dst': edge_dest, 'delay': edge_delay, 'data_rate': edge_dr, 'used_data_rate': edge_used_dr })
def test_simulator(self): """ Test the simulator """ # Collect metrics self.metric_collection = metrics.get_metrics() # Check if Simulator is initiated correctly self.assertIsInstance(self.flow_simulator, FlowSimulator) # Check if Params are set correctly self.assertIsInstance(self.simulator_params, SimulatorParams) # Check if generated flows are equal to processed flow + dropped + active flows gen_flow_check = self.metric_collection['generated_flows'] == (self.metric_collection['processed_flows'] + self.metric_collection['dropped_flows'] + self.metric_collection['total_active_flows']) self.assertIs(gen_flow_check, True)
def network_metrics(self): """ Processes the metrics and parses them in a format specified in the SimulatorState class. """ stats = metrics.get_metrics() self.traffic = stats['run_total_requested_traffic'] self.network_stats = { 'total_flows': stats['generated_flows'], 'successful_flows': stats['processed_flows'], 'dropped_flows': stats['dropped_flows'], 'in_network_flows': stats['total_active_flows'], 'avg_end2end_delay': stats['avg_end2end_delay'], 'run_avg_end2end_delay': stats['run_avg_end2end_delay'], 'run_max_end2end_delay': stats['run_max_end2end_delay'], 'run_total_processed_traffic': stats['run_total_processed_traffic'] }