コード例 #1
0
    def test_dq_optimizer_simple(self):
        wcdtool_path, wcdtool_testcase_subpath = config_parser.parse_config(
            "config.ini")
        solution_checker = SolutionChecker(wcdtool_path,
                                           wcdtool_testcase_subpath, 20)

        n1 = Node('ES1')
        n2 = Node('SW1')
        n3 = Node('ES2')
        stream1 = Stream('tt1', 1500, 100, 100, 0, [n1, n2, n3])
        streams = {'tt1': stream1}

        sw1 = Switch('SW1')
        sw1.associate_stream_to_queue(stream1.uid, stream1.sending_time,
                                      stream1.period, stream1.priority, 'ES2')
        p = sw1.output_ports['ES2']
        p.set_window(stream1.priority, 0, 24, 100)
        switches = {'SW1': sw1}

        solution = TC(switches, streams, 'TC1')

        is_valid, is_feasible, exceeding_percentages, wcds, infinite_streams = solution_checker.check_solution(
            solution)
        optimized_solution = optimize_ports_for_stream(solution, stream1,
                                                       solution_checker)

        is_valid, is_feasible, exceeding_percentages, wcds, infinite_streams = solution_checker.check_solution(
            optimized_solution)
        self.assertEqual(True, stream1.deadline > float(wcds[stream1.uid]))
        self.assertEqual(True, stream1.deadline < float(wcds[stream1.uid]) + 1)
コード例 #2
0
    def test_infinite_stream2(self):
        wcdtool_path, wcdtool_testcase_subpath = config_parser.parse_config(
            "config.ini")
        solution_checker = SolutionChecker(wcdtool_path,
                                           wcdtool_testcase_subpath, 20)

        n1 = Node('ES1')
        n2 = Node('SW1')
        n3 = Node('ES2')
        stream1 = Stream('tt1', 7500, 300, 100, 1, [n1, n2, n3])
        stream3 = Stream('tt3', 3000, 300, 100, 1, [n1, n2, n3])
        stream2 = Stream('tt2', 3000, 100, 100, 2, [n1, n2, n3])
        streams = {'tt1': stream1, 'tt2': stream2, 'tt3': stream3}

        sw1 = Switch('SW1')
        sw1.associate_stream_to_queue(stream1.uid, stream1.sending_time,
                                      stream1.period, stream1.priority, 'ES2')
        sw1.associate_stream_to_queue(stream3.uid, stream3.sending_time,
                                      stream3.period, stream3.priority, 'ES2')
        sw1.associate_stream_to_queue(stream2.uid, stream2.sending_time,
                                      stream2.period, stream2.priority, 'ES2')
        switches = {'SW1': sw1}

        tc = TC(switches, streams, 'TC5')
        initial_solution = create_initial_solution(tc)

        is_valid, is_feasible, exceeding_percentages, wcds, infinite_streams = solution_checker.check_solution(
            initial_solution)
        self.assertEqual(False, is_feasible)
        self.assertEqual(True, is_valid)
        self.assertEqual(True, stream2.uid in infinite_streams)
        self.assertEqual(
            True, stream1.uid not in infinite_streams
            and stream3.uid not in infinite_streams)
コード例 #3
0
    def test_dq_optimizer_simple_multi_streams_same_port(self):
        wcdtool_path, wcdtool_testcase_subpath = config_parser.parse_config(
            "config.ini")
        solution_checker = SolutionChecker(wcdtool_path,
                                           wcdtool_testcase_subpath, 20)

        n1 = Node('ES1')
        n2 = Node('SW1')
        n3 = Node('SW2')
        n4 = Node('ES2')
        stream1 = Stream('tt1', 1500, 300, 100, 0, [n1, n2, n3, n4])
        stream2 = Stream('tt2', 1500, 100, 100, 3, [n1, n3, n4])
        streams = {'tt1': stream1, 'tt2': stream2}

        sw1 = Switch('SW1')
        sw1.associate_stream_to_queue(stream1.uid, stream1.sending_time,
                                      stream1.period, stream1.priority, 'SW2')
        p = sw1.output_ports['SW2']
        p.set_window(stream1.priority, 0, 24, 100)

        sw2 = Switch('SW2')
        sw2.associate_stream_to_queue(stream1.uid, stream1.sending_time,
                                      stream1.period, stream1.priority, 'ES2')
        sw2.associate_stream_to_queue(stream2.uid, stream2.sending_time,
                                      stream2.period, stream2.priority, 'ES2')
        p = sw2.output_ports['ES2']
        p.set_window(stream1.priority, 0, 24, 100)
        p.set_window(stream2.priority, 24, 24, 100)
        switches = {'SW1': sw1, 'SW2': sw2}

        solution = TC(switches, streams, 'TC3')

        is_valid, is_feasible, exceeding_percentages, wcds, infinite_streams = solution_checker.check_solution(
            solution)
        optimized_solution = optimize_ports_for_stream(solution, stream1,
                                                       solution_checker)
        optimized_solution = optimize_ports_for_stream(solution, stream2,
                                                       solution_checker)

        is_valid, is_feasible, exceeding_percentages, wcds, infinite_streams = solution_checker.check_solution(
            optimized_solution)
        self.assertEqual(True, is_feasible)

        self.assertEqual(
            True, optimized_solution.switches['SW2'].output_ports['ES2'].
            get_hyperperiod() == 49)
コード例 #4
0
    def test_port_costs(self):
        p = OutputPort('SW2')
        p2 = OutputPort('ES2')

        M = np.array([[0, 10, 100], [10, 20, 100]])

        M2 = np.array([[0, 10, 100], [10, 50, 100]])

        p._M_Windows = M
        p2._M_Windows = M2

        s1 = Switch('SW1')
        s2 = Switch('SW2')

        s1.output_ports = {'SW2': p}
        s2.output_ports = {'ES2': p2}

        tc = TC({'SW1': s1, 'SW2': s2}, {}, '')

        cc = cost_check.CostChecker()
        self.assertEqual(cc.cost(tc), 20 / 100 + 50 / 100)

        d = cc.port_costs(tc)
        self.assertEqual(True, d['SW1,SW2'] == 20 / 100)
        self.assertEqual(True, d['SW2,ES2'] == 50 / 100)
コード例 #5
0
    def test_port_costs(self):
        p = OutputPort('SW2')

        M = np.array([[0, 20, 80], [20, 50, 90], [50, 70, 100]])

        tl = 0
        hp = 3600
        for r in M:
            tl = tl + hp / r[2] * (r[1] - r[0])
        tp = tl / hp

        p._M_Windows = M

        s1 = Switch('SW1')

        s1.output_ports = {'ES2': p}

        tc = TC({'SW1': s1}, {}, '')

        cc = cost_check.CostChecker()
        cp = cc.cost(tc)
        self.assertEqual(True, cp < tp)
コード例 #6
0
def parse_testcase(test_case_path: str, wcdtool_path: str, wcdtool_testcase_path: str):
    """

    Args:
        test_case_path (str): Path to .streams file
        wcdtool_path (str):  Path to wcdtool executable
        wcdtool_testcase_path (str): Path to wcdtool testcase folder

    Returns:
        TestCase object
    """

    ##### 1. Setup #####
    # Data Structures
    streams = {}  # Map: Stream Name -> Stream
    switches = {}  # Map: Switch Name -> Switch

    _nodes = {}  # Map: Node Name -> Node
    _routes = {}  # Map: VLS Name -> Route (Ordered List of Nodes)

    # Files
    stream_file = open(test_case_path, 'r')
    vls_file = open(test_case_path[:-7] + 'vls', 'r') # remove ".streams" ending and add ".vls" instead

    # Determine test case name from path
    tc_name = os.path.splitext(os.path.basename(test_case_path))[0]  # removes file ending and dot

    ##### 2. Copying #####
    # Copy over stream and vls file for later use with wcd tool
    if not os.path.exists("{}\\in\\".format(wcdtool_path + wcdtool_testcase_path + tc_name)):
        os.makedirs("{}\\in\\".format(wcdtool_path + wcdtool_testcase_path + tc_name),
                    exist_ok=True)

    if not os.path.exists("{}\\out\\".format(wcdtool_path + wcdtool_testcase_path + tc_name)):
        os.makedirs("{}\\out\\".format(wcdtool_path + wcdtool_testcase_path + tc_name),
                    exist_ok=True)
    copyfile(stream_file.name, "{}\\in\\{}".format(wcdtool_path + wcdtool_testcase_path + tc_name, 'msg.txt'))
    copyfile(vls_file.name, "{}\\in\\{}".format(wcdtool_path + wcdtool_testcase_path + tc_name, 'vls.txt'))

    ##### 3. Parsing #####
    # Parsing .vls file
    for line in vls_file:
        if not line.startswith('#'):
            # TODO: allow more chars
            m = re.findall(r'([a-zA-Z0-9_]+)\s?,\s?([a-zA-Z0-9_]+)', line)
            if m is not None:
                _routes[line.split(' ')[0]] = []  # Create Route with name of vl
                r = _routes[line.split(' ')[0]]

                first = True
                for tpl in m:
                    # For each link create nodes if not existent yet
                    n1_name = tpl[0]
                    n2_name = tpl[1]

                    if n1_name not in _nodes:
                        _nodes[n1_name] = Node(n1_name)
                        if _nodes[n1_name].type == 'SW':
                            switches[n1_name] = Switch(n1_name)

                    if n2_name not in _nodes:
                        _nodes[n2_name] = Node(n2_name)
                        if _nodes[n2_name].type == 'SW':
                            switches[n2_name] = Switch(n2_name)

                    # Add nodes to route
                    if first:
                        # first link -> add both nodes
                        r.append(_nodes[n1_name])
                        r.append(_nodes[n2_name])
                        first = False
                    else:
                        # add second node
                        r.append(_nodes[n2_name])

                    # Add output port to first node if it is a switch
                    if n1_name in switches.keys():
                        switches[n1_name].add_outputport_to(n2_name)

    # Parsing .streams file
    for line in stream_file:
        if not line.startswith('#'):
            m = re.search(r'([^\s,]+),\s?(\d+),\s?(\d+),\s?([^\s,]+),\s?([^\s,]+),\s?(\d+),\s?(\d+)', line)
            if m is not None:
                if m.group(5) != 'TT':
                    print('Warning. Unknow traffic class {} found. Will assume TT'.format(m.group(5)))
                s = Stream(m.group(1), int(m.group(2)), int(m.group(3)), int(m.group(7)), int(m.group(6)),
                           _routes[m.group(4)])
                streams[m.group(1)] = s  # Add to list

                # Associate Stream with each switch on route (skip end systems)
                i = 1
                for node in s.route[1:-1]:
                    switches[node.uid].associate_stream_to_queue(s.uid, s.sending_time, s.period, s.priority, s.route[i + 1].uid)
                    i += 1

    ##### 4. Return TestCase #####
    return TestCase(switches, streams, tc_name, len(_nodes)-len(switches))