Ejemplo n.º 1
0
def test_reversed_direction(equipment, setup, requests, services):
    """ checks that if spectrum is selected on one direction it is also selected on reversed
        direction
    """
    network, oms_list = setup
    dsjn = disjunctions_from_json(services)
    dsjn = deduplicate_disjunctions(dsjn)
    paths = compute_path_dsjctn(network, equipment, requests, dsjn)
    rev_pths = []
    for pth in paths:
        if pth:
            rev_pths.append(find_reversed_path(pth))
        else:
            rev_pths.append([])
    # build the list of spectrum slots that will be used for each request. For this purpose
    # play the selection part of path_assign_spectrum
    spectrum_list = []
    for i, pth in enumerate(paths):
        if pth:
            number_wl = ceil(requests[i].path_bandwidth / requests[i].bit_rate)
            requested_m = ceil(requests[i].spacing / slot) * number_wl
            (center_n, startn,
             stopn), path_oms = spectrum_selection(pth,
                                                   oms_list,
                                                   requested_m,
                                                   requested_n=None)
            spectrum_list.append([center_n, startn, stopn])
        else:
            spectrum_list.append([])
    pth_assign_spectrum(paths, requests, oms_list, rev_pths)
    # pth-assign concatenates path and reversed path
    for i, pth in enumerate(paths):
        # verifies that each element (not trx and not roadm) in the path has same
        # spectrum occupation
        if pth:
            this_path = [
                elem for elem in pth if not isinstance(elem, Roadm)
                and not isinstance(elem, Transceiver)
            ]
            print(f'path {[el.uid for el in this_path]}')
            this_revpath = [
                elem for elem in rev_pths[i] if not isinstance(elem, Roadm)
                and not isinstance(elem, Transceiver)
            ]
            print(f'rev_path {[el.uid for el in this_revpath]}')
            print('')
            for j, elem in enumerate(this_revpath):
                imin = elem.oms.spectrum_bitmap.geti(spectrum_list[i][1])
                imax = elem.oms.spectrum_bitmap.geti(spectrum_list[i][2])
                print(f'rev_elem {elem.uid}')
                print(f'    elem {this_path[len(this_path)-j-1].uid}')
                print(
                    f'\trev_spectrum: {elem.oms.spectrum_bitmap.bitmap[imin:imax]}'
                )
                print(
                    f'\t    spectrum: ' +
                    f'{this_path[len(this_path)-j-1].oms.spectrum_bitmap.bitmap[imin:imax]}'
                )
                assert elem.oms.spectrum_bitmap.bitmap[imin:imax] == \
                    this_path[len(this_path) - j - 1].oms.spectrum_bitmap.bitmap[imin:imax]
Ejemplo n.º 2
0
def test_n_m_requests(setup, equipment, n, m, final_n, final_m,
                      blocking_reason, request_set):
    """ test that various N and M values for a request end up with the correct path assgnment
    """
    network, oms_list = setup
    # add an occupation on one of the span of the expected path OMS list on both directions
    # as defined by its offsets within the OMS list: [17, 20, 13, 22] and reversed path [19, 16, 21, 26]
    expected_path = [17, 20, 13, 22]
    expected_oms = [13, 16, 17, 19, 20, 21, 22, 26]
    some_oms = oms_list[expected_oms[3]]
    some_oms.assign_spectrum(
        -30, 32
    )  # means that spectrum is occupied from indexes -62 to 1 on reversed path
    params = request_set
    params['effective_freq_slot'] = {'N': n, 'M': m}
    rqs = [PathRequest(**params)]

    paths = compute_path_dsjctn(network, equipment, rqs, [])
    # check that the computed path is the expected one (independant of blocking issues due to spectrum)
    path_oms = list(
        set([
            e.oms_id for e in paths[0]
            if not isinstance(e, (Transceiver, Roadm))
        ]))
    assert path_oms == expected_path
    # function to be tested:
    pth_assign_spectrum(paths, rqs, oms_list, [find_reversed_path(paths[0])])
    # check that spectrum is correctly assigned
    assert rqs[0].N == final_n
    assert rqs[0].M == final_m
    assert getattr(rqs[0], 'blocking_reason', None) == blocking_reason
Ejemplo n.º 3
0
def test_disjunction(serv):
    ''' service_file contains sevaral combination of disjunction constraint. The test checks
        that computed paths with disjunction constraint are effectively disjoint
    '''
    network, equipment, rqs, dsjn = serv
    pths = compute_path_dsjctn(network, equipment, rqs, dsjn)
    print(dsjn)

    dsjn_list = [d.disjunctions_req for d in dsjn]

    # assumes only pairs in dsjn list
    test = True
    for e in dsjn_list:
        rqs_id_list = [r.request_id for r in rqs]
        p1 = pths[rqs_id_list.index(e[0])][1:-1]
        p2 = pths[rqs_id_list.index(e[1])][1:-1]
        if isdisjoint(p1, p2) + isdisjoint(p1, find_reversed_path(p2)) > 0:
            test = False
            print(
                f'Computed path (roadms):{[e.uid for e in p1  if isinstance(e, Roadm)]}\n'
            )
            print(
                f'Computed path (roadms):{[e.uid for e in p2  if isinstance(e, Roadm)]}\n'
            )
            break
    print(dsjn_list)
    assert test
def test_spectrum_assignment_on_path(equipment, setup, requests):
    """ test assignment functions on path and network
    """
    network, oms_list = setup
    req = [deepcopy(requests[1])]
    paths = compute_path_dsjctn(network, equipment, req, [])

    print(req)
    for nval in range(100):
        req = [deepcopy(requests[1])]
        (center_n, startn, stopn), path_oms = spectrum_selection(paths[0], oms_list, 4)
        pth_assign_spectrum(paths, req, oms_list, [find_reversed_path(paths[0])])
        print(f'testing on following oms {path_oms}')
        # check that only 96 channels are feasible
        if nval >= 96:
            print(center_n, startn, stopn)
            print('only 96 channels of 4 slots pass in this grid')
            assert center_n is None and startn is None and stopn is None
        else:
            print(center_n, startn, stopn)
            print('at least 96 channels of 4 slots should pass in this grid')
            assert center_n is not None and startn is not None and stopn is not None

    req = [requests[2]]
    paths = compute_path_dsjctn(network, equipment, req, [])
    (center_n, startn, stopn), path_oms = spectrum_selection(paths[0], oms_list, 4, 478)
    print(oms_list[0].spectrum_bitmap.freq_index_max)
    print(oms_list[0])
    print(center_n, startn, stopn)
    print('spectrum selection error: should be None')
    assert center_n is None and startn is None and stopn is None
    (center_n, startn, stopn), path_oms = spectrum_selection(paths[0], oms_list, 4, 477)
    print(center_n, startn, stopn)
    print('spectrum selection error should not be None')
    assert center_n is not None and startn is not None and stopn is not None
Ejemplo n.º 5
0
def test_freq_slot_exist(setup, equipment, request_set):
    """ test that assignment works even if effective_freq_slot is not populated
    """
    network, oms_list = setup
    params = request_set
    params['effective_freq_slot'] = None
    rqs = [PathRequest(**params)]
    paths = compute_path_dsjctn(network, equipment, rqs, [])
    pth_assign_spectrum(paths, rqs, oms_list, [find_reversed_path(paths[0])])
    assert rqs[0].N == -256
    assert rqs[0].M == 32
Ejemplo n.º 6
0
def test_inconsistant_freq_slot(setup, equipment, request_set):
    """ test that an inconsistant M correctly raises an error
    """
    network, oms_list = setup
    params = request_set
    # minimum required nb of slots is 32 (800Gbit/100Gbit/s channels each occupying 50GHz ie 4 slots)
    params['effective_freq_slot'] = {'N': 0, 'M': 4}
    with pytest.raises(ServiceError):
        _check_one_request(params, 196.05e12)
    params['trx_mode'] = None
    rqs = [PathRequest(**params)]
    paths = compute_path_dsjctn(network, equipment, rqs, [])
    pth_assign_spectrum(paths, rqs, oms_list, [find_reversed_path(paths[0])])
    assert rqs[0].blocking_reason == 'NOT_ENOUGH_RESERVED_SPECTRUM'