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

Merge branch...

Merge branch 'feat/237-elaborate-ietf-slice-nbi-to-support-adding-deleting-new-sdp-connection-group-and-match' into camara-demo-integration
parents 20cdc262 fc5f3e93
No related branches found
No related tags found
2 merge requests!359Release TeraFlowSDN 5.0,!321Resolve: "(CTTC) CAMARA Demo Integration tests"
...@@ -8,6 +8,7 @@ from common.proto.context_pb2 import ( ...@@ -8,6 +8,7 @@ from common.proto.context_pb2 import (
ConfigRule, ConfigRule,
Constraint, Constraint,
DeviceId, DeviceId,
Device,
Empty, Empty,
EndPointId, EndPointId,
ServiceConfig, ServiceConfig,
...@@ -16,6 +17,8 @@ from common.proto.context_pb2 import ( ...@@ -16,6 +17,8 @@ from common.proto.context_pb2 import (
) )
from common.tools.context_queries.Slice import get_slice_by_defualt_name from common.tools.context_queries.Slice import get_slice_by_defualt_name
from common.tools.grpc.ConfigRules import update_config_rule_custom from common.tools.grpc.ConfigRules import update_config_rule_custom
from common.tools.object_factory.Device import json_device_id
from common.DeviceTypes import DeviceTypeEnum
from context.client import ContextClient from context.client import ContextClient
from .YangValidator import YangValidator from .YangValidator import YangValidator
...@@ -29,6 +32,19 @@ ADDRESS_PREFIX = 24 ...@@ -29,6 +32,19 @@ ADDRESS_PREFIX = 24
RAISE_IF_DIFFERS = False RAISE_IF_DIFFERS = False
def get_endpoint_controller_type(
endpoint: EndPointId, context_client: ContextClient
) -> str:
endpoint_device: Device = context_client.GetDevice(endpoint.device_id)
if endpoint_device.controller_id == DeviceId():
return ""
controller = context_client.GetDevice(endpoint_device.controller_id)
if controller is None:
controller_uuid = endpoint_device.controller_id.device_uuid.uuid
raise Exception("Device({:s}) not found".format(str(controller_uuid)))
return controller.device_type
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]:
...@@ -40,12 +56,29 @@ def get_custom_config_rule( ...@@ -40,12 +56,29 @@ def get_custom_config_rule(
return cr return cr
def sort_endpoints(endpoinst_list: List, sdps: List, connection_group: Dict) -> List: def sort_endpoints(
src_sdp_id = connection_group["connectivity-construct"][0]["p2p-sender-sdp"] endpoinst_list: List[EndPointId],
sdp_id_name_mapping = {sdp["id"]: sdp["node-id"] for sdp in sdps} sdps: List,
if endpoinst_list[0].device_id.device_uuid.uuid == sdp_id_name_mapping[src_sdp_id]: connection_group: Dict,
context_client: ContextClient,
) -> List[EndPointId]:
first_ep = endpoinst_list[0]
first_controller_type = get_endpoint_controller_type(first_ep, context_client)
last_ep = endpoinst_list[-1]
last_controller_type = get_endpoint_controller_type(last_ep, context_client)
if first_controller_type == DeviceTypeEnum.NCE.value:
return endpoinst_list return endpoinst_list
return endpoinst_list[::-1] elif last_controller_type == DeviceTypeEnum.NCE.value:
return endpoinst_list[::-1]
else:
src_sdp_id = connection_group["connectivity-construct"][0]["p2p-sender-sdp"]
sdp_id_name_mapping = {sdp["id"]: sdp["node-id"] for sdp in sdps}
if (
endpoinst_list[0].device_id.device_uuid.uuid
== sdp_id_name_mapping[src_sdp_id]
):
return endpoinst_list
return endpoinst_list[::-1]
def replace_ont_endpoint_with_emu_dc( def replace_ont_endpoint_with_emu_dc(
...@@ -191,7 +224,7 @@ class IETFSliceHandler: ...@@ -191,7 +224,7 @@ class IETFSliceHandler:
break break
else: else:
raise Exception("connection group not found") raise Exception("connection group not found")
list_endpoints = sort_endpoints(list_endpoints, sdps, cg) list_endpoints = sort_endpoints(list_endpoints, sdps, cg, context_client)
list_endpoints = replace_ont_endpoint_with_emu_dc( list_endpoints = replace_ont_endpoint_with_emu_dc(
list_endpoints, context_client list_endpoints, context_client
) )
...@@ -327,16 +360,14 @@ class IETFSliceHandler: ...@@ -327,16 +360,14 @@ class IETFSliceHandler:
slice_services = candidate_ietf_data["network-slice-services"]["slice-service"] slice_services = candidate_ietf_data["network-slice-services"]["slice-service"]
slice_service = slice_services[0] slice_service = slice_services[0]
slice_connection_groups = slice_service["connection-groups"]["connection-group"] slice_connection_groups = slice_service["connection-groups"]["connection-group"]
connection_group_id = updated_connection_group["connection-group"][0]["id"] connection_group_id = updated_connection_group["id"]
cg_idx = list( cg_idx = list(
( (
slice_cg["id"] == connection_group_id slice_cg["id"] == connection_group_id
for slice_cg in slice_connection_groups for slice_cg in slice_connection_groups
) )
).index(True) ).index(True)
slice_connection_groups[cg_idx] = updated_connection_group["connection-group"][ slice_connection_groups[cg_idx] = updated_connection_group
0
]
fields = { fields = {
name: (value, RAISE_IF_DIFFERS) name: (value, RAISE_IF_DIFFERS)
for name, value in candidate_ietf_data.items() for name, value in candidate_ietf_data.items()
...@@ -462,12 +493,6 @@ class IETFSliceHandler: ...@@ -462,12 +493,6 @@ class IETFSliceHandler:
else: else:
raise Exception("connection group not found") raise Exception("connection group not found")
del slice_request.slice_constraints[:] del slice_request.slice_constraints[:]
# del slice_request.slice_endpoint_ids[:]
# list_endpoints = sort_endpoints(list_endpoints, sdps, cg)
# list_endpoints = replace_ont_endpoint_with_emu_dc(
# list_endpoints, context_client
# )
# slice_request.slice_endpoint_ids.extend(list_endpoints)
slice_request.slice_constraints.extend(list_constraints) slice_request.slice_constraints.extend(list_constraints)
fields = {name: (value, RAISE_IF_DIFFERS) for name, value in ietf_data.items()} fields = {name: (value, RAISE_IF_DIFFERS) for name, value in ietf_data.items()}
update_config_rule_custom( update_config_rule_custom(
......
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