Esempio n. 1
0
    def setUp(self):
        # before test, create graph
        self.nodes: List[int] = [1, 2, 3, 4, 5, 6, 7]

        self.edges: List[Tuple[int]] = [(1, 2), (2, 1), (2, 3), (3, 2), (2, 4),
                                        (4, 2), (3, 4), (4, 3), (3, 5), (5, 3),
                                        (4, 5), (5, 4), (5, 6), (6, 5), (5, 7),
                                        (7, 5)]

        self.graph: nx.Graph = nx.Graph()
        self.graph.add_edges_from(self.edges)
        self.graph = self.graph.to_directed()
        TopoGenerator.draw(self.graph)

        # fid = 1, size = 8Kb, period = 300us, source = 1, destinations = [6, 7], reliability = 0.0, deadline = 300us
        f1: Flow = Flow(1, int(8e3), int(3e5), 1, [6, 7], 0.0, int(1e6))
        # fid = 1, size = 20Kb, period = 150us, source = 1, destinations = [6], reliability = 0.0, deadline = 150us
        f2: Flow = Flow(2, int(2e4), int(1.5e5), 1, [6], 0.0, int(1e6))
        # fid = 1, size = 30Kb, period = 150us, source = 1, destinations = [6, 7], reliability = 0.0, deadline = 300us
        f3: Flow = Flow(3, int(3e4), int(3e5), 1, [6, 7], 0.0, int(1e6))
        # fid = 1, size = 2Kb, period = 150us, source = 1, destinations = [7], reliability = 0.0, deadline = 300us
        f4: Flow = Flow(4, int(2e3), int(3e5), 1, [7], 0.0, int(1e6))

        self.flows: List[Flow] = list()
        self.flows.append(f1)
        self.flows.append(f2)
        self.flows.append(f3)
        self.flows.append(f4)
Esempio n. 2
0
    def setUp(self):
        config.TESTING['round'] = [1, 1]  # [1, 5]
        config.TESTING['flow-size'] = [10, 100]
        config.TESTING['x-axis-gap'] = 5
        config.TESTING['draw-gantt-chart'] = True
        config.OPTIMIZATION['enable'] = True
        config.FLOW_CONFIG[
            'redundancy_degree'] = 2  # at least 2 end-to-end routes
        config.FLOW_CONFIG[
            'max-redundancy-degree'] = 5  # the most no. of end-to-end routes
        config.FLOW_CONFIG[
            'un-neighbors_degree'] = 1  # avoid source and node connecting at the same node
        config.GRAPH_CONFIG['time-granularity'] = TIME_GRANULARITY.NS
        config.GRAPH_CONFIG['all-bandwidth'] = 0.1  # 100Mbps
        config.GRAPH_CONFIG['all-propagation-delay'] = 0  # 1e2 100ns
        config.GRAPH_CONFIG['all-process-delay'] = 0  # 5e3 5us
        config.GRAPH_CONFIG['all-per'] = 0.01  # 0.4%
        config.GRAPH_CONFIG['edge-nodes-distribution-degree'] = 3

        # create flows
        self.flows: List[Flow] = [
            Flow(1, int(1e3), int(1e6), 5, [7, 8], 0.5,
                 int(2e7)),  # 125B 1000us 20ms
            Flow(2, int(1e3), int(1e6), 6, [5], 0.5,
                 int(2e7)),  # 125B 1000us 20ms
            Flow(3, int(1e3), int(1e6), 7, [5, 6], 0.5,
                 int(2e7)),  # 125B 1000us 20ms
            Flow(4, int(1.6e3), int(1e6), 8, [5], 0.5,
                 int(5e7)),  # 200B 1000us 50ms
            Flow(5, int(2.4e3), int(1e6), 6, [7, 8], 0.5,
                 int(5e7)),  # 300B 1000us 50ms
            Flow(6, int(2.4e3), int(1.5e6), 7, [5, 6], 0.5,
                 int(5e7)),  # 300B 1500us 50ms
            Flow(7, int(5e3), int(1.5e6), 5, [8], 0.5,
                 int(1e8)),  # 625B 1500us 100ms
            Flow(8, int(5e3), int(1.5e6), 6, [8], 0.5,
                 int(1e8)),  # 625B 1500us 100ms
            Flow(9, int(1.2e3), int(3e6), 8, [5, 6], 0.5,
                 int(1e8)),  # 150B 3000us 100ms
            Flow(10, int(1.2e3), int(3e6), 8, [5], 0.5,
                 int(1e8)),  # 150B 3000us 100ms
        ]
        # create topology
        edges: List[Tuple[int, int]] = [(1, 2), (1, 3), (2, 3), (2, 4), (3, 4),
                                        (5, 1), (6, 2), (4, 7), (4, 8)]
        self.graph: nx.Graph = nx.Graph()
        self.graph.add_edges_from(edges)
        self.graph = self.graph.to_directed()
        TopoGenerator.draw(self.graph)
Esempio n. 3
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)]
        # 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)

        # fid = 1, size = 1500KB, period = 300us, source = 1, destinations = [6, 7], reliability = 0.95, deadline = 300us
        f1: Flow = Flow(1, int(1.2e4), int(3e5), 1, [3, 4], 0.95, int(1e6))
        # f1: Flow = Flow(1, int(1.2e4), int(3e5), 1, [6, 7], 0.95, int(1e6))
        self.flows: List[Flow] = [f1]

        config.FLOW_CONFIG['redundancy_degree'] = 2
        config.GRAPH_CONFIG['all-per'] = 0.004
        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.UNI_ROUTES_RELIABILITY_STRATEGY
    def setUp(self):
        config.TESTING['round'] = [1, 1]  # [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.FLOW_CONFIG['redundancy_degree'] = 2  # at least 2 end-to-end routes
        config.FLOW_CONFIG['max-redundancy-degree'] = 5  # the most no. of end-to-end routes
        config.FLOW_CONFIG['un-neighbors_degree'] = 1  # avoid source and node connecting at the same node
        config.FLOW_CONFIG['size-set'] = [int(1.6e3), int(5e3), int(1e3)]  # [200B, 625B, 125B]
        config.FLOW_CONFIG['period-set'] = [int(1e5), int(1.5e5), int(3e5)]  # [100us, 150us, 300us]
        config.FLOW_CONFIG['hyper-period'] = int(3e5)  # [300us]
        config.FLOW_CONFIG['deadline-set'] = [int(1e8), int(5e7), int(2e7)]  # [100ms, 50ms, 20ms]
        config.FLOW_CONFIG['reliability-set'] = [0.5]  # [0.98]
        config.GRAPH_CONFIG['time-granularity'] = TIME_GRANULARITY.NS
        config.GRAPH_CONFIG['all-bandwidth'] = 1  # 500Mbps
        config.GRAPH_CONFIG['all-propagation-delay'] = 0  # 1e2 100ns
        config.GRAPH_CONFIG['all-process-delay'] = 0  # 5e3 5us
        config.GRAPH_CONFIG['all-per'] = 0.004  # 0.4%
        config.GRAPH_CONFIG['core-node-num'] = 10
        config.GRAPH_CONFIG['edge-node-num'] = 10
        config.GRAPH_CONFIG['edge-nodes-distribution-degree'] = 6

        # create flows
        self.flows: List[Flow] = [
            Flow(1, int(1e3), int(1e5), 1, [9, 10], 0.5, int(2e7)),  # 125B 100us 20ms
            Flow(2, int(1e3), int(1e5), 2, [1, 10], 0.5, int(2e7)),  # 125B 100us 20ms
            Flow(3, int(1e3), int(1e5), 9, [2, 11], 0.5, int(2e7)),  # 125B 100us 20ms
            Flow(4, int(1.6e3), int(1e5), 10, [1, 2], 0.5, int(5e7)),  # 200B 100us 50ms
            Flow(5, int(2.4e3), int(1e5), 11, [1, 2], 0.5, int(5e7)),  # 300B 100us 50ms
            Flow(6, int(2.4e3), int(1.5e5), 1, [11], 0.5, int(5e7)),  # 300B 150us 50ms
            Flow(7, int(5e3), int(1.5e5), 2, [9, 10], 0.5, int(1e8)),  # 625B 150us 100ms
            Flow(8, int(5e3), int(1.5e5), 9, [2], 0.5, int(1e8)),  # 625B 150us 100ms
            Flow(9, int(1.184e4), int(3e5), 10, [2], 0.5, int(1e8)),  # 1480B 300us 100ms
            Flow(10, int(1.184e4), int(3e5), 11, [1, 2], 0.5, int(1e8)),  # 1480B 300us 100ms
        ]
        # create topology
        edges: List[Tuple[int, int]] = [(1, 3), (2, 4), (3, 4), (3, 5), (3, 6), (4, 5), (5, 6), (5, 7), (6, 8), (7, 8),
                                        (7, 9), (8, 10), (8, 11)]
        # 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)
Esempio n. 5
0
 def generate_r(cls,
                n: int = 0,
                hn: List[int] = 0,
                s: List[int] = [],
                p: List[int] = [],
                dn: List[int] = [],
                rl: List[float] = [],
                dl: List[int] = []) -> List[Flow]:
     '''
     generate flow randomly
     :param n: number of flows, e.g., 20
     :param hn: list of source nodes, e.g., [1, 6, 7]
     :param s: range of data size per cycle time, e.g., [int(1e4), int(2e4)]
     :param p: range of cycle time, e.g., [int(1e5), int(6e5)]
     :param dn: range of number of destination nodes, e.g., [1, 2]
     :param rl: range of reliability requirement, e.g., [0.97, 0.99]
     :param dl: range of ene-to-end delay requirement, e.g., [int(1e5), int(1.5e5)]
     :return: flows
     '''
     _F: List[Flow] = []
     _P: List[int] = [100000, 150000, 300000,
                      600000]  # TODO fake period here
     for _i in range(n):
         _fid = _i + 1
         _s: int = random.randint(s[0], s[1])
         # _p: int = random.randint(p[0], p[1])
         _p: int = _P[random.randint(0, len(_P)) -
                      1]  # TODO fake method here
         _dn: int = random.randint(dn[0], dn[1])
         _rl: int = random.randint(rl[0], rl[1])
         _dl: int = random.randint(dl[0], dl[1])
         _src: int = hn[random.randint(0, len(hn)) - 1]
         while True:
             _D: List[int] = random.sample(hn, _dn)
             _D = list(filter(lambda d: d != _src, set(_D)))
             if len(_D) != 0:
                 break
         _p = cls.smooth_period(p[1], _p)
         _f: Flow = Flow(_fid, _s, _p, _src, _D, _rl, _dl)
         _F.append(_f)
     return _F
Esempio n. 6
0
 def schedule_single_flow(self, flow: Flow) -> bool:
     logger.info('schedule flow [' + str(flow.flow_id) + ']...')
     _all_routes: List[List[List[int]]] = flow.get_routes()
     _union_routes: List[List[int]] = []
     for _e2e_routes in _all_routes:
         for _e2e_route in _e2e_routes:
             _union_routes.append(_e2e_route)
     _union_routes = self.sort_route(_union_routes)
     _ER: List[int] = []  # recover list
     for _e2e_route in _union_routes:
         if not self.schedule_end2end(flow, _e2e_route):
             logger.info('scheduling flow [' + str(flow.flow_id) +
                         '] failure')
             # TODO recover time slots allocation on edge
             for __e2e_route in _ER:
                 for _eid in __e2e_route:
                     self.edge_mapper[
                         _eid].time_slot_allocator.recover_scene()
             return False
         else:
             _ER.append(_e2e_route)
     logger.info('scheduling flow [' + str(flow.flow_id) + '] successful')
     return True
    def setUp(self):
        # configuration
        config.FLOW_CONFIG['hyper-period'] = int(3e5)  # [300us]
        config.FLOW_CONFIG['redundancy_degree'] = 2
        config.FLOW_CONFIG['max-hops'] = 8
        config.FLOW_CONFIG['flow-num'] = 10
        config.GRAPH_CONFIG['time-granularity'] = TIME_GRANULARITY.NS
        config.GRAPH_CONFIG['all-bandwidth'] = 1e0  # 500Mbps
        config.GRAPH_CONFIG['all-propagation-delay'] = 1e2
        config.GRAPH_CONFIG['all-process-delay'] = 5e3
        config.GRAPH_CONFIG['all-per'] = 0.004  # 0.4%
        config.XML_CONFIG['enhancement-tsn-switch-enable'] = True

        # create graph
        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)
        # create flows
        self.flows: List[Flow] = [
            Flow(1, int(1e3), int(1e5), 1, [7, 8], 0.5, int(1e8))
        ]
Esempio n. 8
0
 def generate_flows(edge_nodes: List[NodeId] = None,
                    graph: nx.Graph = None,
                    **kwargs) -> List[Flow]:
     '''
     generate flow randomly
     :param graph:
     :param edge_nodes: arrival source nodes
     :return:
     '''
     flow_num: int = config.FLOW_CONFIG['flow-num']
     flow_id: int = 1
     if 'flow_num' in kwargs.keys():
         flow_num = kwargs['flow_num']
     if 'flow_id' in kwargs.keys():
         flow_id = kwargs['flow_id']
     if len(config.FLOW_CONFIG['dest-num-set']) + 1 > len(edge_nodes):
         raise RuntimeError('too less edge nodes')
     _F: List[Flow] = []
     _fid = flow_id
     for _i in range(flow_num):
         if 'flow_properties' in kwargs.keys():
             _s: int = kwargs['flow_properties'][_i]['size']
             _p: int = kwargs['flow_properties'][_i]['period']
             _rl: int = kwargs['flow_properties'][_i]['reliability']
             _dl: int = kwargs['flow_properties'][_i]['deadline']
             _dn: int = kwargs['flow_properties'][_i]['dest-num']
         else:
             _s: int = \
                 config.FLOW_CONFIG['size-set'][random.randint(0, len(config.FLOW_CONFIG['size-set'])) - 1]
             _p: int = \
                 config.FLOW_CONFIG['period-set'][random.randint(0, len(config.FLOW_CONFIG['period-set'])) - 1]
             _rl: int = \
                 config.FLOW_CONFIG['reliability-set'][
                     random.randint(0, len(config.FLOW_CONFIG['reliability-set'])) - 1]
             _dl: int = \
                 config.FLOW_CONFIG['deadline-set'][random.randint(0, len(config.FLOW_CONFIG['deadline-set'])) - 1]
             _dn: int = \
                 config.FLOW_CONFIG['dest-num-set'][random.randint(0, len(config.FLOW_CONFIG['dest-num-set'])) - 1]
         _o: int = \
             edge_nodes[random.randint(0, len(edge_nodes)) - 1]
         _D: List[int] = []
         _edge_nodes_t: List[int] = copy.deepcopy(edge_nodes)
         _edge_nodes_t.remove(_o)
         source_neighbor: int = list(graph.neighbors(_o))[0]
         neighbors: List[int] = list(graph.neighbors(source_neighbor))
         neighbors.remove(_o)
         neighbors = list(
             filter(lambda n: list(graph.neighbors(n)).__len__() == 1,
                    neighbors))
         _edge_nodes_t = list(set(_edge_nodes_t) - set(neighbors))
         if neighbors.__len__() >= 1:
             _t: List[int] = random.sample(
                 neighbors,
                 int(
                     np.ceil(
                         (1 - config.FLOW_CONFIG['un-neighbors_degree']) *
                         len(neighbors))))
             [_edge_nodes_t.append(n) for n in _t]
         _D = random.sample(_edge_nodes_t, _dn)
         _f: Flow = Flow(_fid, _s, _p, _o, _D, _rl, _dl)
         _F.append(_f)
         _fid += 1
         logger.info(_f)
     return _F