diff --git a/gnpy/tools/json_io.py b/gnpy/tools/json_io.py index ef75aa2d..55c6d795 100644 --- a/gnpy/tools/json_io.py +++ b/gnpy/tools/json_io.py @@ -547,7 +547,7 @@ def requests_from_json(json_data, equipment): params['format'] = params['trx_mode'] params['spacing'] = req['path-constraints']['te-bandwidth']['spacing'] try: - nd_list = req['explicit-route-objects']['route-object-include-exclude'] + nd_list = sorted(req['explicit-route-objects']['route-object-include-exclude'], key=lambda x: x['index']) except KeyError: nd_list = [] params['nodes_list'] = [n['num-unnum-hop']['node-id'] for n in nd_list] diff --git a/tests/test_parser.py b/tests/test_parser.py index 92afd121..3ff8d888 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -506,3 +506,71 @@ def test_eqpt_creation(tmpdir): # check that all amp in the converted files corresponds to an eqpt line for ampuid in jsonconverted.keys(): assert ampuid in possiblename + + +def test_service_json_constraint_order(): + """test that the constraints are read in correct order""" + + unsorted_request = { + "request-id": "unsorted", + "source": "trx Brest_KLA", + "destination": "trx Vannes_KBE", + "src-tp-id": "trx Brest_KLA", + "dst-tp-id": "trx Vannes_KBE", + "bidirectional": False, + "path-constraints": { + "te-bandwidth": { + "technology": "flexi-grid", + "trx_type": "Voyager", + "trx_mode": "mode 1", + "spacing": 50000000000.0, + "output-power": 0.001, + "path_bandwidth": 10000000000.0 + } + }, + "explicit-route-objects": { + "route-object-include-exclude": [ + { + "explicit-route-usage": "route-include-ero", + "index": 2, + "num-unnum-hop": { + "node-id": "roadm Lorient_KMA", + "link-tp-id": "link-tp-id is not used", + "hop-type": "STRICT" + } + }, + { + "explicit-route-usage": "route-include-ero", + "index": 3, + "num-unnum-hop": { + "node-id": "roadm Vannes_KBE", + "link-tp-id": "link-tp-id is not used", + "hop-type": "STRICT" + } + }, + { + "explicit-route-usage": "route-include-ero", + "index": 1, + "num-unnum-hop": { + "node-id": "roadm Lannion_CAS", + "link-tp-id": "link-tp-id is not used", + "hop-type": "LOOSE" + } + }, + { + "explicit-route-usage": "route-include-ero", + "index": 0, + "num-unnum-hop": { + "node-id": "roadm Brest_KLA", + "link-tp-id": "link-tp-id is not used", + "hop-type": "STRICT" + } + } + ] + } + } + + data = {'path-request': [unsorted_request]} + rqs = requests_from_json(data, equipment) + assert rqs[0].nodes_list == ['roadm Brest_KLA', 'roadm Lannion_CAS', 'roadm Lorient_KMA', 'roadm Vannes_KBE'] + assert rqs[0].loose_list == ['STRICT', 'LOOSE', 'STRICT', 'STRICT']