diff --git a/src/pathcomp/frontend/service/OpticalPathComp.py b/src/pathcomp/frontend/service/OpticalPathComp.py index 20d4dc5eb17870e47a10c0e8d99f28b92216d8bd..c83a550510a8bbb37f3b49c02b1ec1ab3ae81a37 100644 --- a/src/pathcomp/frontend/service/OpticalPathComp.py +++ b/src/pathcomp/frontend/service/OpticalPathComp.py @@ -60,6 +60,12 @@ def group_block(group, action, group_id_override=None, node=None): } def compute_optical_path(service: Service) -> PathCompReply: + return _optical_path_computation(service, is_recompute=False) + +def recompute_optical_path(service: Service) -> PathCompReply: + return _optical_path_computation(service, is_recompute=True) + +def _optical_path_computation(service: Service, is_recompute: bool = False) -> PathCompReply: # Extract intent from config rules intent_str = "" for cr in service.service_config.config_rules: @@ -112,197 +118,27 @@ def compute_optical_path(service: Service) -> PathCompReply: "band": 200, "subcarriers_per_source": [4] * len(destinations_list) } + LOGGER.info(f"Optical Path Computation Payload: {payload}") - url = "http://10.30.7.66:31060/OpticalTFS/restconf/operations/tapi-path-computation:compute-p2mp" + if is_recompute: + url = "http://10.30.7.65:31060/OpticalTFS/restconf/operations/tapi-path-computation:recompute-p2mp" + else: + url = "http://10.30.7.65:31060/OpticalTFS/restconf/operations/tapi-path-computation:compute-p2mp" headers = { "Content-Type": "application/json", "Accept": "*/*" } - # resp = requests.post(url, headers=headers, json=payload, timeout=15) - # resp.raise_for_status() - # resp_json = resp.json() - - # MOCK RESPONSE (If the Optical Controller is down) - resp_json = { - "tapi-connectivity:connectivity-service": { - "connection": [ - { - "optical-connection-attributes": { - "central-frequency": 195000000000000, - "Tx-power": 0, - "modulation": { - "modulation-technique": "DP-16QAM", - "operational-mode": 9, - "port": "port-1" - }, - "digital-subcarrier-spacing": 300000000, - "subcarrier-attributes": { - "digital-subcarrier-group": [ - { - "group-id": 1, - "modulation-technique": "DP-QPSK", - "central-frequency": 195006250, - "operational-mode": 4, - "Tx-power": -99, - "group-size": 4, - "port": "port-1", - "subcarrier-id": [1, 2, 3, 4] - }, - { - "group-id": 2, - "modulation-technique": "DP-QPSK", - "central-frequency": 195018750, - "operational-mode": 4, - "Tx-power": -99, - "group-size": 4, - "port": "port-3", - "subcarrier-id": [5, 6, 7, 8] - }, - { - "group-id": 3, - "modulation-technique": "DP-QPSK", - "central-frequency": 195031250, - "operational-mode": 4, - "Tx-power": -99, - "group-size": 4, - "port": "port-5", - "subcarrier-id": [9, 10, 11, 12] - } - ] - } - }, - "end-point": [ - { - "direction": "BIDIRECTIONAL", - "layer-protocol-name": "PHOTONIC_MEDIA", - "layer-protocol-qualifier": "tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_MC", - "local-id": "T1.1", - "service-interface-point": { - "service-interface-point-uuid": "T2.1" - }, - "tapi-photonic-media:media-channel-connectivity-service-end-point-spec": { - "mc-config": { - "spectrum": { - "center-frequency": 195000000000000, - "frequency-constraint": { - "adjustment-granularity": "G_6_25GHZ", - "grid-type": "FLEX" - } - } - } - } - }, - { - "direction": "BIDIRECTIONAL", - "layer-protocol-name": "PHOTONIC_MEDIA", - "layer-protocol-qualifier": "tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_MC", - "local-id": "T2.1", - "service-interface-point": { - "service-interface-point-uuid": "T1.1" - }, - "tapi-photonic-media:media-channel-connectivity-service-end-point-spec": { - "mc-config": { - "spectrum": { - "center-frequency": 195006250, - "frequency-constraint": { - "adjustment-granularity": "G_6_25GHZ", - "grid-type": "FLEX" - } - } - } - } - }, - { - "direction": "BIDIRECTIONAL", - "layer-protocol-name": "PHOTONIC_MEDIA", - "layer-protocol-qualifier": "tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_MC", - "local-id": "T1.2", - "service-interface-point": { - "service-interface-point-uuid": "T2.1" - }, - "tapi-photonic-media:media-channel-connectivity-service-end-point-spec": { - "mc-config": { - "spectrum": { - "center-frequency": 195018750, - "frequency-constraint": { - "adjustment-granularity": "G_6_25GHZ", - "grid-type": "FLEX" - } - } - } - } - }, - { - "direction": "BIDIRECTIONAL", - "layer-protocol-name": "PHOTONIC_MEDIA", - "layer-protocol-qualifier": "tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_MC", - "local-id": "T2.1", - "service-interface-point": { - "service-interface-point-uuid": "T1.2" - }, - "tapi-photonic-media:media-channel-connectivity-service-end-point-spec": { - "mc-config": { - "spectrum": { - "center-frequency": 195018750, - "frequency-constraint": { - "adjustment-granularity": "G_6_25GHZ", - "grid-type": "FLEX" - } - } - } - } - }, - { - "direction": "BIDIRECTIONAL", - "layer-protocol-name": "PHOTONIC_MEDIA", - "layer-protocol-qualifier": "tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_MC", - "local-id": "T1.3", - "service-interface-point": { - "service-interface-point-uuid": "T2.1" - }, - "tapi-photonic-media:media-channel-connectivity-service-end-point-spec": { - "mc-config": { - "spectrum": { - "center-frequency": 195031250, - "frequency-constraint": { - "adjustment-granularity": "G_6_25GHZ", - "grid-type": "FLEX" - } - } - } - } - }, - { - "direction": "BIDIRECTIONAL", - "layer-protocol-name": "PHOTONIC_MEDIA", - "layer-protocol-qualifier": "tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_MC", - "local-id": "T2.1", - "service-interface-point": { - "service-interface-point-uuid": "T1.3" - }, - "tapi-photonic-media:media-channel-connectivity-service-end-point-spec": { - "mc-config": { - "spectrum": { - "center-frequency": 195031250, - "frequency-constraint": { - "adjustment-granularity": "G_6_25GHZ", - "grid-type": "FLEX" - } - } - } - } - } - ] - } - ] - } - } - + resp = requests.post(url, headers=headers, json=payload, timeout=15) + resp.raise_for_status() + resp_json = resp.json() + LOGGER.info(f"Optical Path Computation Response: {resp_json}") + # Generate Rules src_name = source # T2.1 dest_list = destinations_list # T1.1, T1.2 # Extract destinations from response end-points if available + endpoints = [] try: endpoints = resp_json.get("tapi-connectivity:connectivity-service", {}).get("connection", [{}])[0].get("end-point", []) extracted_dests = [] @@ -310,7 +146,7 @@ def compute_optical_path(service: Service) -> PathCompReply: local_id = ep.get("local-id") if local_id and local_id != src_name and local_id not in extracted_dests: extracted_dests.append(local_id) - if extracted_dests: + if extracted_dests and any(d in nodes for d in extracted_dests): dest_list = extracted_dests except Exception: pass @@ -343,8 +179,9 @@ def compute_optical_path(service: Service) -> PathCompReply: hub_freq_raw = attributes.get("central-frequency", 195000000000000) hub_freq = int(hub_freq_raw / 1e6) if hub_freq_raw > 1e10 else int(hub_freq_raw) + hub_name = endpoints[0].get("local-id") if len(endpoints) > 0 else "channel-1" hub = { - "name": "channel-1", + "name": hub_name, "frequency": hub_freq, "target_output_power": attributes.get("Tx-power", 0), "operational_mode": operational_mode, @@ -355,12 +192,15 @@ def compute_optical_path(service: Service) -> PathCompReply: leaves = [] print("dest_list:", dest_list) print("groups:", groups) - for dest, group in zip(dest_list, groups): - port = group.get("port", "port-1") - if port.startswith("port-"): - name = f"channel-{port.split('-')[1]}" + for index, (dest, group) in enumerate(zip(dest_list, groups)): + if len(endpoints) > index + 1: + name = endpoints[index + 1].get("local-id") else: - name = "channel-1" + port = group.get("port", "port-1") + if port.startswith("port-"): + name = f"channel-{port.split('-')[1]}" + else: + name = "channel-1" freq_raw = group.get("central-frequency", 195006250) freq = int(freq_raw / 1e6) if freq_raw > 1e10 else int(freq_raw) diff --git a/src/pathcomp/frontend/service/PathCompServiceServicerImpl.py b/src/pathcomp/frontend/service/PathCompServiceServicerImpl.py index d7e3f2daf81ee77e63611c6c51d1ac8b51a7ce72..652fd53d7665a41b4605185e97e7f8bbcc676b1e 100644 --- a/src/pathcomp/frontend/service/PathCompServiceServicerImpl.py +++ b/src/pathcomp/frontend/service/PathCompServiceServicerImpl.py @@ -28,7 +28,7 @@ from pathcomp.frontend.Config import is_forecaster_enabled #from context.client.ContextClient import ContextClient from pathcomp.frontend.service.TopologyTools import get_pathcomp_topology_details from pathcomp.frontend.service.algorithms.Factory import get_algorithm -from pathcomp.frontend.service.OpticalPathComp import compute_optical_path +from pathcomp.frontend.service.OpticalPathComp import compute_optical_path, recompute_optical_path from common.proto.context_pb2 import ServiceTypeEnum LOGGER = logging.getLogger(__name__) @@ -48,8 +48,17 @@ class PathCompServiceServicerImpl(PathCompServiceServicer): LOGGER.debug('[Compute] begin ; request = {:s}'.format(grpc_message_to_json_string(request))) if len(request.services) > 0 and request.services[0].service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY: - LOGGER.info('[Compute] Intercepting OPTICAL_CONNECTIVITY request...') - return compute_optical_path(request.services[0]) + is_recompute = False + for cr in request.services[0].service_config.config_rules: + if cr.WhichOneof('config_rule') == 'custom' and cr.custom.resource_key == "recompute" and cr.custom.resource_value == "true": + is_recompute = True + break + if is_recompute: + LOGGER.info('[Compute] Intercepting OPTICAL_CONNECTIVITY recomputation request...') + return recompute_optical_path(request.services[0]) + else: + LOGGER.info('[Compute] Intercepting OPTICAL_CONNECTIVITY request...') + return compute_optical_path(request.services[0]) #context_client = ContextClient()