Ejemplo n.º 1
0
    def test_dq_period_yero(self):
        p = OutputPort('SW1')
        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 100

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 100

        # Test Queue Association
        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        # Test initial window creation
        self.assertEqual(p._M_Windows.shape[0], 3)

        # Test window assignment
        p.set_window(0, 0, 10, 100)
        p.set_window(1, 10, 50, 100)
        p.set_window(2, 60, 40, 100)

        ret = p.dq_modify_period(True)
        self.assertEqual(p._free_period, 0)
        self.assertEqual(100, p._M_Windows[0][2])
Ejemplo n.º 2
0
    def test_same_period_empty_but_period(self):
        p = OutputPort('SW1')

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

        p._M_Windows = M

        self.assertEqual(p.get_occupation_percentage(), 0 / 100)
Ejemplo n.º 3
0
    def test_same_period_overlap(self):
        p = OutputPort('SW1')

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

        p._M_Windows = M

        self.assertEqual(p.get_occupation_percentage(), 20 / 100)
Ejemplo n.º 4
0
    def test_different_period_overlap(self):
        p = OutputPort('SW1')

        M = np.array([[0, 10, 50], [0, 10, 65]])

        p._M_Windows = M

        self.assertEqual(p.get_occupation_percentage(), 210 / 650)
Ejemplo n.º 5
0
    def test_empty_windows(self):
        p = OutputPort('SW1')

        M = np.array([[0, 0, 0], [0, 0, 0]])

        p._M_Windows = M

        with self.assertRaises(ValueError) as e:
            p.get_occupation_percentage()
Ejemplo n.º 6
0
    def test_dq_period_zero(self):
        p = OutputPort('SW1')

        p._free_period = 0

        ret = p.dq_modify_period(True)
        self.assertEqual(p._free_period, 0)
        self.assertEqual(ret, False)

        ret = p.dq_modify_period(False)
        self.assertEqual(p._free_period, 0)
        self.assertEqual(ret, False)
Ejemplo n.º 7
0
    def test_different_period_overlap_later(self):
        switches = {}

        p = OutputPort('port1')
        p.associate_stream_to_queue('tt1', 0, 50, 0)
        p.associate_stream_to_queue('tt2', 0, 65, 1)

        M = np.array([[0, 10, 50], [10, 10, 65]])

        p.set_window(0, 0, 10, 50)
        p.set_window(1, 10, 10, 65)

        self.assertEqual(p.get_occupation_percentage(), 210 / 650)
Ejemplo n.º 8
0
    def test_sorted_queuenrs(self):
        p = OutputPort('port1')

        s1_uid = 'tt1'
        s1_length = 20
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 200

        s3_uid = 'tt3'
        s3_length = 50
        s3_period = 200

        s4_uid = 'tt4'
        s4_length = 50
        s4_period = 200

        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 5), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 2), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 7), True)
        self.assertEqual(
            p.associate_stream_to_queue(s4_uid, s4_length, s4_period, 4), True)

        self.assertIn(5, p.queues)
        self.assertIn(2, p.queues)
        self.assertIn(7, p.queues)
        self.assertIn(4, p.queues)

        self.assertEqual(p.get_sorted_queuenrs(), [2, 4, 5, 7])
Ejemplo n.º 9
0
    def add_outputport_to(self, node_uid):
        """
        Adds an output port to a certain node to this switch

        Args:
            node_uid (str): Unique name of the node the output port leads to.
        """
        if node_uid not in self.output_ports.keys():
            self.output_ports[node_uid] = OutputPort(node_uid)
Ejemplo n.º 10
0
    def test_dq_period_unevenstart(self):
        p = OutputPort('SW1')
        p.queues = {None}
        p._M_Windows = np.array([[0, 0, 100]])

        p._free_period = 1337

        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 668)
Ejemplo n.º 11
0
    def test_data_structure_assignment_same_q(self):
        p = OutputPort('port1')

        s1_uid = 'tt1'
        s1_length = 20
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 200

        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 0),
            False)
        self.assertIn(0, p.queues)

        self.assertEqual(p.queues[0].window_percentage, 0.45)

        self.assertEqual(p.queues[0].stream_uids, ['tt1', 'tt2'])
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
    def test_minimum_window_percentage(self):
        p = OutputPort('port1')

        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 200

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 1000

        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        self.assertEqual(p.queues[0].window_percentage, 0.1)
        self.assertEqual(p.queues[1].window_percentage, 0.25)
        self.assertEqual(p.queues[2].window_percentage, 0.01)

        self.assertEqual(p.get_minimum_window_percentage(), 0.01)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
    def test_occupation_percentage_same_period(self):
        p = OutputPort('port1')

        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 100

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 100

        # Test Queue Association
        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        # Test initial window creation
        self.assertEqual(p._M_Windows.shape[0], 3)

        # Test window assignment
        p.set_window(0, 0, 10, 100)
        p.set_window(1, 10, 50, 100)
        p.set_window(2, 60, 10, 100)

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

        self.assertEqual(np.array_equal(p._M_Windows, M), True)

        # Test occupation percentage
        self.assertEqual(p.get_occupation_percentage(), 7 / 10)
Ejemplo n.º 16
0
    def test_set_window_and_period_multiplication(self):
        p = OutputPort('port1')

        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 200

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 1000

        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        self.assertEqual(p._M_Windows.shape[0], 3)

        p.set_window(1, 10, 50, 200)
        p.set_window(0, 0, 10, 100)
        p.set_window(2, 60, 10, 1000)

        M = np.array([[0, 10, 100], [10, 60, 200], [60, 70, 1000]])

        self.assertEqual(np.array_equal(p._M_Windows, M), True)

        M_expected = np.array([[0, 10, 300], [10, 60, 600], [60, 70, 3000]])

        p.multipy_period(3)

        self.assertEqual(np.array_equal(p._M_Windows, M_expected), True)
Ejemplo n.º 17
0
    def test_name(self):
        name = 'port1'
        p = OutputPort(name)

        self.assertEqual(p.name, name)
Ejemplo n.º 18
0
    def test_dq_period_lower(self):
        p = OutputPort('SW1')
        p.queues = {None}
        p._M_Windows = np.array([[0, 0, 100]])

        p._free_period = 100

        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 50)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 25)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 12)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 6)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 3)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 1)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 0)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 0)
        self.assertEqual(p.dq_modify_period(True), False)
Ejemplo n.º 19
0
    def test_set_period(self):
        p = OutputPort('SW1')

        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 100

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 100

        # Test Queue Association
        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        # Test initial window creation
        self.assertEqual(p._M_Windows.shape[0], 3)

        # Test window assignment
        p.set_window(0, 0, 10, 100)
        p.set_window(1, 10, 50, 100)
        p.set_window(2, 60, 10, 100)

        p.set_period_for_priority(70, 2)
        self.assertEqual(70, p.get_window(2)[2])

        p.set_period_for_priority(99, 2)
        self.assertEqual(99, p.get_window(2)[2])
Ejemplo n.º 20
0
    def test_minimum_period(self):
        p = OutputPort('SW1')

        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 100

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 100

        # Test Queue Association
        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        # Test initial window creation
        self.assertEqual(p._M_Windows.shape[0], 3)

        # Test window assignment
        p.set_window(0, 0, 10, 100)
        p.set_window(1, 10, 50, 100)
        p.set_window(2, 60, 10, 100)

        self.assertEqual(70, p.get_minimum_period_with_current_windows())

        p.set_window(0, 50, 30, 100)
        p.set_window(1, 10, 20, 100)
        p.set_window(2, 0, 60, 100)

        self.assertEqual(80, p.get_minimum_period_with_current_windows())

        p.set_window(0, 0, 10, 100)
        p.set_window(1, 10, 50, 100)
        p.set_window(2, 80, 10, 100)

        self.assertEqual(90, p.get_minimum_period_with_current_windows())
Ejemplo n.º 21
0
    def test_dq_period_normal(self):
        p = OutputPort('SW1')
        p.queues = {None}
        p._M_Windows = np.array([[0, 0, 100]])

        p._free_period = 100

        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 50)
        p.dq_modify_period(False)
        self.assertEqual(p._free_period, 75)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 62)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 56)
        p.dq_modify_period(False)
        self.assertEqual(p._free_period, 59)
        self.assertEqual(p.dq_modify_period(True), True)