Skip to content
Snippets Groups Projects
Commit d7c5d0d0 authored by Shayan Hajipour's avatar Shayan Hajipour
Browse files

feat & debug:

- app flow ids changed to match the expectations
- proper sdp removal parsing added to nce service handler
parent 5700d692
No related branches found
No related tags found
3 merge requests!346Draft: support for restconf protocol,!345Draft: support ipinfusion devices via netconf,!306Resolve "(CTTC) L3NM-NCE Service Handler is Required"
...@@ -40,7 +40,7 @@ def setup_config_rules(service_uuid: str, json_settings: Dict) -> List[Dict]: ...@@ -40,7 +40,7 @@ def setup_config_rules(service_uuid: str, json_settings: Dict) -> List[Dict]:
app_flow_service_profile: str = f"service_{app_flow_id}" app_flow_service_profile: str = f"service_{app_flow_id}"
app_id: str = f"app_{app_flow_id}" app_id: str = f"app_{app_flow_id}"
app_feature_id: str = f"feature_{app_flow_id}" app_feature_id: str = f"feature_{app_flow_id}"
app_flow_name: str = json_settings.get("app_flow_name", "App_Flow_Example") app_flow_name: str = f"App_Flow_{app_flow_id}"
app_flow_max_online_users: int = json_settings.get("app_flow_max_online_users", 1) app_flow_max_online_users: int = json_settings.get("app_flow_max_online_users", 1)
app_flow_stas: str = json_settings.get("stas", "00:3D:E1:18:82:9E") app_flow_stas: str = json_settings.get("stas", "00:3D:E1:18:82:9E")
qos_profile_name: str = json_settings.get("app_flow_qos_profile", "AR_VR_Gaming") qos_profile_name: str = json_settings.get("app_flow_qos_profile", "AR_VR_Gaming")
...@@ -72,7 +72,7 @@ def setup_config_rules(service_uuid: str, json_settings: Dict) -> List[Dict]: ...@@ -72,7 +72,7 @@ def setup_config_rules(service_uuid: str, json_settings: Dict) -> List[Dict]:
}, },
} }
application = { application = {
"name": app_flow_name, "name": app_flow_app_name,
"app-id": app_id, "app-id": app_id,
"app-features": { "app-features": {
"app-feature": [ "app-feature": [
......
...@@ -51,6 +51,77 @@ MATCH_CRITERION_DIFF_RE = re.compile( ...@@ -51,6 +51,77 @@ MATCH_CRITERION_DIFF_RE = re.compile(
) )
def get_removed_items(
candidate_ietf_slice_dict: dict, running_ietf_slice_dict: dict
) -> dict:
removed_items = {
"sdp": {"sdp_idx": None, "value": {}},
"connection_group": {"connection_group_idx": None, "value": {}},
"match_criterion": {
"sdp_idx": None,
"match_criterion_idx": None,
"value": {},
},
}
running_slice_services = running_ietf_slice_dict["network-slice-services"][
"slice-service"
][0]
running_slice_sdps = [sdp["id"] for sdp in running_slice_services["sdps"]["sdp"]]
candidate_slice_services = candidate_ietf_slice_dict["network-slice-services"][
"slice-service"
][0]
candidiate_slice_sdps = [
sdp["id"] for sdp in candidate_slice_services["sdps"]["sdp"]
]
removed_sdps = set(running_slice_sdps) - set(candidiate_slice_sdps)
if len(removed_sdps) > 1:
raise Exception("Multiple SDPs removed")
removed_sdp_id = list(removed_sdps)[0]
removed_items["sdp"]["sdp_idx"] = running_slice_sdps.index(removed_sdp_id)
removed_items["sdp"]["value"] = next(
sdp
for sdp in running_slice_services["sdps"]["sdp"]
if sdp["id"] == removed_sdp_id
)
match_criteria = removed_items["sdp"]["value"]["service-match-criteria"][
"match-criterion"
]
if len(match_criteria) > 1:
raise Exception("Multiple match criteria found")
match_criterion = match_criteria[0]
connection_grp_id = match_criterion["target-connection-group-id"]
connection_groups = running_slice_services["connection-groups"]["connection-group"]
connection_group = next(
(idx, cg)
for idx, cg in enumerate(connection_groups)
if cg["id"] == connection_grp_id
)
removed_items["connection_group"]["connection_group_idx"] = connection_group[0]
removed_items["connection_group"]["value"] = connection_group[1]
for sdp in running_slice_services["sdps"]["sdp"]:
if sdp["id"] == removed_sdp_id:
continue
for mc in sdp["service-match-criteria"]["match-criterion"]:
if mc["target-connection-group-id"] == connection_grp_id:
removed_items["match_criterion"]["sdp_idx"] = running_slice_sdps.index(
sdp["id"]
)
removed_items["match_criterion"]["match_criterion_idx"] = sdp[
"service-match-criteria"
]["match-criterion"].index(mc)
removed_items["match_criterion"]["value"] = mc
break
if (
removed_items["match_criterion"]["sdp_idx"] is None
or removed_items["sdp"]["sdp_idx"] is None
or removed_items["connection_group"]["connection_group_idx"] is None
):
raise Exception("sdp, connection group or match criterion not found")
return removed_items
def get_custom_config_rule( def get_custom_config_rule(
service_config: ServiceConfig, resource_key: str service_config: ServiceConfig, resource_key: str
) -> Optional[ConfigRule]: ) -> Optional[ConfigRule]:
...@@ -100,13 +171,13 @@ class L3NMNCEServiceHandler(_ServiceHandler): ...@@ -100,13 +171,13 @@ class L3NMNCEServiceHandler(_ServiceHandler):
endpoints: List[Tuple[str, str, Optional[str]]], endpoints: List[Tuple[str, str, Optional[str]]],
connection_uuid: Optional[str] = None, connection_uuid: Optional[str] = None,
) -> List[Union[bool, Exception]]: ) -> List[Union[bool, Exception]]:
LOGGER.debug(f"P3: {len(endpoints)} {endpoints}")
chk_type("endpoints", endpoints, list) chk_type("endpoints", endpoints, list)
if len(endpoints) == 0: if len(endpoints) == 0:
return [] return []
results = [] results = []
try: try:
context_client = ContextClient() context_client = ContextClient()
service_name = self.__service.name
service_config = self.__service.service_config service_config = self.__service.service_config
settings = self.__settings_handler.get("/settings") settings = self.__settings_handler.get("/settings")
src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0]) src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0])
...@@ -133,6 +204,10 @@ class L3NMNCEServiceHandler(_ServiceHandler): ...@@ -133,6 +204,10 @@ class L3NMNCEServiceHandler(_ServiceHandler):
running_resource_value_dict = json.loads( running_resource_value_dict = json.loads(
running_ietf_slice_cr.custom.resource_value running_ietf_slice_cr.custom.resource_value
) )
service_name = running_resource_value_dict["network-slice-services"][
"slice-service"
][0]["id"]
LOGGER.debug(f"P1: {service_name}")
if not running_candidate_diff: # Slice Creation if not running_candidate_diff: # Slice Creation
operation_type = "create" operation_type = "create"
slice_services = candidate_resource_value_dict[ slice_services = candidate_resource_value_dict[
...@@ -235,57 +310,25 @@ class L3NMNCEServiceHandler(_ServiceHandler): ...@@ -235,57 +310,25 @@ class L3NMNCEServiceHandler(_ServiceHandler):
"connection-group" "connection-group"
] ]
operation_type = "delete" operation_type = "delete"
added_items = { removed_items = get_removed_items(
"sdp": {"sdp_idx": None, "value": {}}, candidate_resource_value_dict, running_resource_value_dict
"connection_group": {"connection_group_idx": None, "value": {}}, )
"match_criterion": { removed_sdp = sdps[removed_items["sdp"]["sdp_idx"]]
"sdp_idx": None, src_sdp_idx = removed_sdp["id"]
"match_criterion_idx": None, dst_sdp_idx = sdps[removed_items["match_criterion"]["sdp_idx"]]["id"]
"value": {},
},
}
for added_key, added_value in running_candidate_diff[
"iterable_item_removed"
].items():
sdp_match = SDP_DIFF_RE.match(added_key)
connection_group_match = CONNECTION_GROUP_DIFF_RE.match(added_key)
match_criterion_match = MATCH_CRITERION_DIFF_RE.match(added_key)
if sdp_match:
added_items["sdp"] = {
"sdp_idx": int(sdp_match.groups()[0]),
"value": added_value,
}
elif connection_group_match:
added_items["connection_group"] = {
"connection_group_idx": int(
connection_group_match.groups()[0]
),
"value": added_value,
}
elif match_criterion_match:
added_items["match_criterion"] = {
"sdp_idx": int(match_criterion_match.groups()[0]),
"match_criterion_idx": int(
match_criterion_match.groups()[1]
),
"value": added_value,
}
new_sdp = sdps[added_items["sdp"]["sdp_idx"]]
src_sdp_idx = new_sdp["id"]
dst_sdp_idx = sdps[added_items["match_criterion"]["sdp_idx"]]["id"]
connection_grp_id = connection_groups[ connection_grp_id = connection_groups[
added_items["connection_group"]["connection_group_idx"] removed_items["connection_group"]["connection_group_idx"]
]["id"] ]["id"]
if ( if (
connection_grp_id connection_grp_id
!= added_items["match_criterion"]["value"][ != removed_items["match_criterion"]["value"][
"target-connection-group-id" "target-connection-group-id"
] ]
): ):
raise Exception( raise Exception(
"connection group missmatch in destination sdp and added connection group" "connection group missmatch in destination sdp and added connection group"
) )
match_criteria = new_sdp["service-match-criteria"]["match-criterion"] match_criteria = removed_sdp["service-match-criteria"]["match-criterion"]
match_criterion = match_criteria[0] match_criterion = match_criteria[0]
for type_value in match_criterion["match-type"]: for type_value in match_criterion["match-type"]:
if type_value["type"] == "ietf-network-slice-service:source-ip-prefix": if type_value["type"] == "ietf-network-slice-service:source-ip-prefix":
...@@ -364,11 +407,15 @@ class L3NMNCEServiceHandler(_ServiceHandler): ...@@ -364,11 +407,15 @@ class L3NMNCEServiceHandler(_ServiceHandler):
"dst_port": dst_port, "dst_port": dst_port,
} }
json_config_rules = setup_config_rules(service_name, resource_value_dict) json_config_rules = setup_config_rules(service_name, resource_value_dict)
LOGGER.debug(f"Config Rules: {json_config_rules}")
del controller.device_config.config_rules[:] del controller.device_config.config_rules[:]
for jcr in json_config_rules: for jcr in json_config_rules:
controller.device_config.config_rules.append(ConfigRule(**jcr)) controller.device_config.config_rules.append(ConfigRule(**jcr))
self.__task_executor.configure_device(controller) self.__task_executor.configure_device(controller)
LOGGER.debug('Configured device "{:s}"'.format(controller.name))
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
LOGGER.exception(f'P4: {e}')
raise e
results.append(e) results.append(e)
return results return results
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment