diff --git a/src/tests/tools/load_gen/Constants.py b/src/tests/tools/load_gen/Constants.py index 1eeb6268649e4b2db7c2b2125c0c96431fa25ab9..32b457bae849a50ccbe61e1997aec944cb6a2257 100644 --- a/src/tests/tools/load_gen/Constants.py +++ b/src/tests/tools/load_gen/Constants.py @@ -18,6 +18,7 @@ class RequestType(Enum): SERVICE_L2NM = 'svc-l2nm' SERVICE_L3NM = 'svc-l3nm' SERVICE_TAPI = 'svc-tapi' + SERVICE_MW = 'svc-mw' SLICE_L2NM = 'slc-l2nm' SLICE_L3NM = 'slc-l3nm' diff --git a/src/tests/tools/load_gen/RequestGenerator.py b/src/tests/tools/load_gen/RequestGenerator.py index b0ec9bea6d2ee62b23b8ae1dcd78f18aae3b54c4..d38291d380d044fa3b91a1b653ea47f6e917fe16 100644 --- a/src/tests/tools/load_gen/RequestGenerator.py +++ b/src/tests/tools/load_gen/RequestGenerator.py @@ -100,7 +100,8 @@ class RequestGenerator: LOGGER.info('[dump_state] used_device_endpoints = {:s}'.format(json.dumps(self._used_device_endpoints))) def _use_device_endpoint( - self, service_uuid : str, endpoint_types : Optional[Set[str]] = None, exclude_device_uuids : Set[str] = set() + self, service_uuid : str, request_type : RequestType, endpoint_types : Optional[Set[str]] = None, + exclude_device_uuids : Set[str] = set(), exclude_endpoint_uuids : Set[Tuple[str, str]] = set(), ) -> Optional[Tuple[str, str]]: with self._lock: compatible_endpoints : Set[Tuple[str, str]] = set() @@ -109,9 +110,14 @@ class RequestGenerator: if endpoint_types is None: # allow all elegible_device_endpoints : Dict[str, Set[str]] = { - device_uuid:device_endpoint_uuids + device_uuid:[ + endpoint_uuid for endpoint_uuid in device_endpoint_uuids + if (len(exclude_endpoint_uuids) == 0) or \ + ((device_uuid,endpoint_uuid) not in exclude_endpoint_uuids) + ] for device_uuid,device_endpoint_uuids in self._available_device_endpoints.items() - if device_uuid not in exclude_device_uuids and len(device_endpoint_uuids) > 0 + if (device_uuid not in exclude_device_uuids) and \ + (len(device_endpoint_uuids) > 0) } else: # allow only compatible endpoints @@ -123,6 +129,7 @@ class RequestGenerator: if device_uuid in exclude_device_uuids or len(device_endpoint_uuids) == 0: continue for endpoint_uuid in device_endpoint_uuids: endpoint_key = (device_uuid,endpoint_uuid) + if endpoint_key in exclude_endpoint_uuids: continue if endpoint_key not in compatible_endpoints: continue elegible_device_endpoints.setdefault(device_uuid, set()).add(endpoint_uuid) @@ -136,16 +143,19 @@ class RequestGenerator: 'compatible_endpoints={:s}'.format(str(compatible_endpoints)), ])) return None + device_uuid = random.choice(list(elegible_device_endpoints.keys())) device_endpoint_uuids = elegible_device_endpoints.get(device_uuid) endpoint_uuid = random.choice(list(device_endpoint_uuids)) - self._available_device_endpoints.setdefault(device_uuid, set()).discard(endpoint_uuid) - self._used_device_endpoints.setdefault(device_uuid, dict())[endpoint_uuid] = service_uuid + if request_type not in {RequestType.SERVICE_MW}: + # reserve the resources + self._available_device_endpoints.setdefault(device_uuid, set()).discard(endpoint_uuid) + self._used_device_endpoints.setdefault(device_uuid, dict())[endpoint_uuid] = service_uuid return device_uuid, endpoint_uuid def _release_device_endpoint(self, device_uuid : str, endpoint_uuid : str) -> None: with self._lock: - self._used_device_endpoints.setdefault(device_uuid, set()).pop(endpoint_uuid, None) + self._used_device_endpoints.setdefault(device_uuid, dict()).pop(endpoint_uuid, None) self._available_device_endpoints.setdefault(device_uuid, set()).add(endpoint_uuid) def compose_request(self) -> Optional[Dict]: @@ -159,7 +169,9 @@ class RequestGenerator: # choose request type request_type = random.choice(self._parameters.request_types) - if request_type in {RequestType.SERVICE_L2NM, RequestType.SERVICE_L3NM, RequestType.SERVICE_TAPI}: + if request_type in { + RequestType.SERVICE_L2NM, RequestType.SERVICE_L3NM, RequestType.SERVICE_TAPI, RequestType.SERVICE_MW + }: return self._compose_service(num_request, request_uuid, request_type) elif request_type in {RequestType.SLICE_L2NM, RequestType.SLICE_L3NM}: return self._compose_slice(num_request, request_uuid, request_type) @@ -167,7 +179,7 @@ class RequestGenerator: def _compose_service(self, num_request : int, request_uuid : str, request_type : str) -> Optional[Dict]: # choose source endpoint src_endpoint_types = set(ENDPOINT_COMPATIBILITY.keys()) if request_type in {RequestType.SERVICE_TAPI} else None - src = self._use_device_endpoint(request_uuid, endpoint_types=src_endpoint_types) + src = self._use_device_endpoint(request_uuid, request_type, endpoint_types=src_endpoint_types) if src is None: LOGGER.warning('>> No source endpoint is available') return None @@ -179,11 +191,12 @@ class RequestGenerator: dst_endpoint_types = {dst_endpoint_type} if request_type in {RequestType.SERVICE_TAPI} else None # identify excluded destination devices - exclude_device_uuids = {} if request_type in {RequestType.SERVICE_TAPI} else {src_device_uuid} + exclude_device_uuids = {} if request_type in {RequestType.SERVICE_TAPI, RequestType.SERVICE_MW} else {src_device_uuid} # choose feasible destination endpoint dst = self._use_device_endpoint( - request_uuid, endpoint_types=dst_endpoint_types, exclude_device_uuids=exclude_device_uuids) + request_uuid, request_type, endpoint_types=dst_endpoint_types, exclude_device_uuids=exclude_device_uuids, + exclude_endpoint_uuids={src}) # if destination endpoint not found, release source, and terminate current service generation if dst is None: @@ -281,19 +294,29 @@ class RequestGenerator: return json_service_tapi_planned( request_uuid, endpoint_ids=endpoint_ids, constraints=[], config_rules=config_rules) + elif request_type == RequestType.SERVICE_MW: + vlan_id = 1000 + num_request % 1000 + config_rules = [ + json_config_rule_set('/settings', { + 'vlan_id': vlan_id, + }), + ] + return json_service_l2nm_planned( + request_uuid, endpoint_ids=endpoint_ids, constraints=[], config_rules=config_rules) + def _compose_slice(self, num_request : int, request_uuid : str, request_type : str) -> Optional[Dict]: # choose source endpoint - src = self._use_device_endpoint(request_uuid) + src = self._use_device_endpoint(request_uuid, request_type) if src is None: LOGGER.warning('>> No source endpoint is available') return None src_device_uuid,src_endpoint_uuid = src # identify excluded destination devices - exclude_device_uuids = {} if request_type in {RequestType.SERVICE_TAPI} else {src_device_uuid} + exclude_device_uuids = {} if request_type in {RequestType.SERVICE_TAPI, RequestType.SERVICE_MW} else {src_device_uuid} # choose feasible destination endpoint - dst = self._use_device_endpoint(request_uuid, exclude_device_uuids=exclude_device_uuids) + dst = self._use_device_endpoint(request_uuid, request_type, exclude_device_uuids=exclude_device_uuids) # if destination endpoint not found, release source, and terminate current service generation if dst is None: diff --git a/src/tests/tools/load_gen/__main__.py b/src/tests/tools/load_gen/__main__.py index f622f4d14e64b29d36200b6823c2883d22bfa210..9a5ea2b6949d1b6dd50d0a40407c6740bf266dd3 100644 --- a/src/tests/tools/load_gen/__main__.py +++ b/src/tests/tools/load_gen/__main__.py @@ -28,6 +28,7 @@ def main(): request_types = [ RequestType.SERVICE_L2NM, RequestType.SERVICE_L3NM, + #RequestType.SERVICE_MW, #RequestType.SERVICE_TAPI, RequestType.SLICE_L2NM, RequestType.SLICE_L3NM, diff --git a/src/tests/tools/load_gen/deploy_specs.sh b/src/tests/tools/load_gen/deploy_specs.sh index 1982ef2272f8a67edc2364df4c60c765b9ac71b6..a688f1c0ad920bab2fb5157dce72225671ed837e 100644 --- a/src/tests/tools/load_gen/deploy_specs.sh +++ b/src/tests/tools/load_gen/deploy_specs.sh @@ -7,7 +7,7 @@ export TFS_REGISTRY_IMAGE="http://localhost:32000/tfs/" # interdomain slice pathcomp dlt # dbscanserving opticalattackmitigator opticalattackdetector # l3_attackmitigator l3_centralizedattackdetector l3_distributedattackdetector -export TFS_COMPONENTS="context device pathcomp service slice webui dlt" # automation monitoring compute +export TFS_COMPONENTS="context device pathcomp service slice webui" # automation monitoring compute dlt # Set the tag you want to use for your images. export TFS_IMAGE_TAG="dev"