diff --git a/manifests/opticalcontrollerservice.yaml b/manifests/opticalcontrollerservice.yaml index fcf1be742366bd2f31e63418716b1f1743efb44f..4b677ee4f7287b0790aaa0b19f034db03978fac0 100644 --- a/manifests/opticalcontrollerservice.yaml +++ b/manifests/opticalcontrollerservice.yaml @@ -37,12 +37,12 @@ spec: env: - name: LOG_LEVEL value: "INFO" - readinessProbe: - exec: - command: ["/bin/grpc_health_probe", "-addr=:10060"] - livenessProbe: - exec: - command: ["/bin/grpc_health_probe", "-addr=:10060"] + #readinessProbe: + # exec: + # command: ["/bin/grpc_health_probe", "-addr=:10060"] + #livenessProbe: + # exec: + # command: ["/bin/grpc_health_probe", "-addr=:10060"] resources: requests: cpu: 500m diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py index 35c542854b156433c5aa7a2af6f03e7aee999d39..f3700e10488228387145a2c4c8574a899675aade 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -11,30 +11,27 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from uuid import UUID, uuid4, uuid5 + import json, logging from typing import Any, Dict, List, Optional, Tuple, Union from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME -from common.method_wrappers.ServiceExceptions import InvalidArgumentException -from common.proto.context_pb2 import ConfigActionEnum, ConfigRule_ACL, Device, DeviceConfig, Link, Location +from common.DeviceTypes import DeviceTypeEnum +from common.method_wrappers.ServiceExceptions import InvalidArgumentException, NotFoundException +from common.proto.context_pb2 import ConfigActionEnum, ConfigRule_ACL, Device, DeviceConfig, EndPoint, Link, Location from common.proto.device_pb2 import MonitoringSettings from common.proto.kpi_sample_types_pb2 import KpiSampleType from common.tools.grpc.ConfigRules import update_config_rule_custom from common.tools.grpc.Tools import grpc_message_to_json +from common.type_checkers.Checkers import chk_length, chk_type from .driver_api._Driver import _Driver, RESOURCE_ENDPOINTS from .monitoring.MonitoringLoops import MonitoringLoops from .ErrorMessages import ( ERROR_BAD_RESOURCE, ERROR_DELETE, ERROR_GET, ERROR_GET_INIT, ERROR_MISSING_KPI, ERROR_SAMPLETYPE, ERROR_SET, ERROR_SUBSCRIBE, ERROR_UNSUBSCRIBE, ERROR_UNSUP_RESOURCE ) -from .drivers.oc_driver.OCDriver import OCDriver -from common.method_wrappers.ServiceExceptions import NotFoundException -from common.type_checkers.Checkers import chk_length, chk_type -from common.proto.context_pb2 import EndPoint LOGGER = logging.getLogger(__name__) - def get_endpoint_matching(device : Device, endpoint_uuid_or_name : str) -> EndPoint: for endpoint in device.device_endpoints: choices = {endpoint.endpoint_id.endpoint_uuid.uuid, endpoint.name} @@ -454,89 +451,74 @@ def update_endpoints(src_device : Device, dst_device : Device) -> None: dst_topology_id = dst_endpoint_id.topology_id if len(src_topology_uuid) > 0: dst_topology_id.topology_uuid.uuid = src_topology_uuid if len(src_context_uuid) > 0: dst_topology_id.context_id.context_uuid.uuid = src_context_uuid -def oc_default_endpoints( - device : Device, driver : _Driver, monitoring_loops : MonitoringLoops, - new_sub_devices : Dict[str, Device], new_sub_links : Dict[str, Link] -) -> List[str]: - - pass -#def get_enpoint_name (device:Device,endpoint_id:str): -# str(UUID(str_uuid_or_name)) - -def get_edit_target (device:Device,is_opticalband:bool)-> str: - if (is_opticalband): return "optical-band" - else : - if device.device_type =='optical-roadm': return 'media-channel' - else : return 'optical-channel' - -def is_key_existed( key:str ,keys_dic=dict,key_name_to_use= None ) -> dict: - dic={} - dic["resource_key"]=key + +def get_edit_target(device : Device, is_opticalband : bool) -> str: + if is_opticalband: return 'optical-band' + if device.device_type == DeviceTypeEnum.OPTICAL_ROADM: return 'media-channel' + return 'optical-channel' + +def is_key_existed(key : str, keys_dic = dict, key_name_to_use = None) -> dict: + dic = {} + dic['resource_key'] = key if key_name_to_use is not None: - dic["resource_key"]=key_name_to_use - if key in keys_dic : - dic["value"]=keys_dic[key] - else : - dic["value"]=None - return dic - -def extract_resources (config:dict,device:Device)-> list : - conditions={} - resources=[] - resources.append(is_key_existed("channel_namespace",config)) - resources.append(is_key_existed("add_transceiver",config)) - is_opticalband=False - if ( 'is_opticalband' in config): - is_opticalband=config['is_opticalband'] - conditions["is_opticalband"]=is_opticalband - conditions["edit_type"]=get_edit_target(device=device,is_opticalband=is_opticalband) - if ('flow' in config): - #for tuple_value in config['flow'][device.name]: - source_vals = [] - dest_vals = [] - for tuple_value in config['flow']: - source_port=None - destination_port=None - #resources.append({"resource_key":"source_port","value":source_port}) - #resources.append({"resource_key":"destination_port","value":destination_port}) - source_port_uuid,destination_port_uuid=tuple_value - if (source_port_uuid !='0'): - src_endpoint_obj = get_endpoint_matching(device, source_port_uuid) - source_port = src_endpoint_obj.name - source_vals.append(source_port) - if (destination_port_uuid !='0'): - dst_endpoint_obj = get_endpoint_matching(device, destination_port_uuid) - destination_port = dst_endpoint_obj.name - dest_vals.append(destination_port) - resources.append({"resource_key":"source_port","value":source_vals}) - resources.append({"resource_key":"destination_port","value":dest_vals}) - if ('new_config' in config): - lower_frequency=None - upper_frequency=None - resources.append(is_key_existed(key="target-output-power",keys_dic=config["new_config"])) - resources.append(is_key_existed(key="frequency",keys_dic=config["new_config"])) - resources.append(is_key_existed(key="operational-mode",keys_dic=config["new_config"])) - resources.append(is_key_existed(key="line-port",keys_dic=config["new_config"])) - resources.append(is_key_existed(key="band_type",keys_dic=config["new_config"],key_name_to_use='name')) - resources.append(is_key_existed("ob_id",config["new_config"],key_name_to_use='optical-band-parent')) - resources.append(is_key_existed(key="name",keys_dic=config["new_config"],key_name_to_use="channel_name")) - if not is_opticalband : - if 'frequency' in config['new_config'] and 'band' in config['new_config'] and conditions["edit_type"] == 'media-channel': - lower_frequency= int(int(config['new_config']['frequency']) - (int(config['new_config']['band'])/2)) - upper_frequency= int(int(config['new_config']['frequency']) + (int(config['new_config']['band'])/2)) - - #lower_frequency= (config['new_config']['frequency']- config['new_config']['band'])/2 - #upper_frequency=(config['new_config']['frequency']+ config['new_config']['band'])/2 - - resources.append(is_key_existed(key="flow_id",keys_dic=config["new_config"],key_name_to_use="index")) - #resources.append({"resource_key":"index","value":config["new_config"]["flow_id"] if "flow_id" in config["new_config"] else None}) - else : - lower_frequency=config['new_config']['low-freq'] if "low-freq" in config['new_config'] else None - upper_frequency=config['new_config']['up-freq'] if 'up-freq' in config['new_config'] else None - resources.append(is_key_existed(key="ob_id",keys_dic=config["new_config"],key_name_to_use="index")) - #resources.append({"resource_key":"index","value":config["new_config"]["ob_id"] if "ob_id" in config["new_config"] else None}) - - resources.append({"resource_key":"lower-frequency","value":lower_frequency}) - resources.append({"resource_key":"upper-frequency","value":upper_frequency}) - return [resources,conditions] - + dic['resource_key'] = key_name_to_use + if key in keys_dic: + dic['value'] = keys_dic[key] + else: + dic['value'] = None + return dic + +def extract_resources(config : dict, device : Device) -> list: + conditions = {} + resources = [] + resources.append(is_key_existed('channel_namespace', config)) + resources.append(is_key_existed('add_transceiver', config)) + is_opticalband = config.get('is_opticalband', False) + conditions['is_opticalband'] = is_opticalband + conditions['edit_type'] = get_edit_target(device, is_opticalband) + if 'flow' in config: + #for tuple_value in config['flow'][device.name]: + source_vals = [] + dest_vals = [] + for tuple_value in config['flow']: + source_port = None + destination_port = None + source_port_uuid, destination_port_uuid = tuple_value + if source_port_uuid != '0': + src_endpoint_obj = get_endpoint_matching(device, source_port_uuid) + source_port = src_endpoint_obj.name + source_vals.append(source_port) + if destination_port_uuid != '0': + dst_endpoint_obj = get_endpoint_matching(device, destination_port_uuid) + destination_port = dst_endpoint_obj.name + dest_vals.append(destination_port) + resources.append({'resource_key': 'source_port', 'value': source_vals}) + resources.append({'resource_key': 'destination_port', 'value': dest_vals }) + + if 'new_config' in config: + lower_frequency = None + upper_frequency = None + resources.append(is_key_existed('target-output-power', keys_dic=config['new_config'])) + resources.append(is_key_existed('frequency', keys_dic=config['new_config'])) + resources.append(is_key_existed('operational-mode', keys_dic=config['new_config'])) + resources.append(is_key_existed('line-port', keys_dic=config['new_config'])) + resources.append(is_key_existed('band_type', keys_dic=config['new_config'], key_name_to_use='name')) + resources.append(is_key_existed('ob_id', keys_dic=config['new_config'], key_name_to_use='optical-band-parent')) + resources.append(is_key_existed('name', keys_dic=config['new_config'], key_name_to_use='channel_name')) + if not is_opticalband: + if 'frequency' in config['new_config'] and 'band' in config['new_config'] and conditions['edit_type'] == 'media-channel': + lower_frequency = int(int(config['new_config']['frequency']) - (int(config['new_config']['band'])/2)) + upper_frequency = int(int(config['new_config']['frequency']) + (int(config['new_config']['band'])/2)) + #lower_frequency = (config['new_config']['frequency'] - config['new_config']['band'])/2 + #upper_frequency = (config['new_config']['frequency'] + config['new_config']['band'])/2 + resources.append(is_key_existed('flow_id', keys_dic=config['new_config'], key_name_to_use='index')) + #resources.append({'resource_key':'index','value':config['new_config']['flow_id'] if 'flow_id' in config['new_config'] else None}) + else: + lower_frequency = config['new_config']['low-freq'] if 'low-freq' in config['new_config'] else None + upper_frequency = config['new_config']['up-freq' ] if 'up-freq' in config['new_config'] else None + resources.append(is_key_existed('ob_id', keys_dic=config['new_config'], key_name_to_use='index')) + #resources.append({'resource_key':'index','value':config['new_config']['ob_id'] if 'ob_id' in config['new_config'] else None}) + resources.append({'resource_key': 'lower-frequency', 'value': lower_frequency}) + resources.append({'resource_key': 'upper-frequency', 'value': upper_frequency}) + + return [resources, conditions] diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py index 0d571a9bdbe42512c19d711efbfa123616815534..c2805695a75933c73d4ad367176bee8b504d4460 100644 --- a/src/opticalcontroller/OpticalController.py +++ b/src/opticalcontroller/OpticalController.py @@ -238,8 +238,8 @@ if __name__ == '__main__': nodes_dict, links_dict = readTopologyData(nodes_json, topology_json) - #topologies,links= getTopology() - #print ("topologies{} and devices {}".format(topologies,links)) + #topologies, links = getTopology() + #print("topologies{} and devices {}".format(topologies,links)) rsa = RSA(nodes_dict, links_dict) - app.run(host='0.0.0.0', port=10060,debug=True) + app.run(host='0.0.0.0', port=10060, debug=True) diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py index 138b5399c3467f4813a77f6803442a0f453ad2e8..9b12b1ac8d9302c2bb622b2d4b81924b5453036c 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -1,3 +1,17 @@ +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import dijsktra from tools import * from variables import * diff --git a/src/opticalcontroller/dijsktra.py b/src/opticalcontroller/dijsktra.py index 5be78c6242d26fc0b0332321559ac17b3c72f2d5..94975fd557990e89d11e706e4614f7c69617ceea 100644 --- a/src/opticalcontroller/dijsktra.py +++ b/src/opticalcontroller/dijsktra.py @@ -1,3 +1,17 @@ +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import sys class Vertex: diff --git a/src/opticalcontroller/tools.py b/src/opticalcontroller/tools.py index fc349b49934fe2a63283015272671a9975b3b94f..3b3223d81b2fe4e80956c02afae1a71c429493cf 100644 --- a/src/opticalcontroller/tools.py +++ b/src/opticalcontroller/tools.py @@ -1,4 +1,3 @@ - # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - import numpy as np from variables import * import json diff --git a/src/opticalcontroller/variables.py b/src/opticalcontroller/variables.py index 88e8ce5136a27347ee6968c670de5798016e4337..cbb65200f2f0c5ef9cd490c1435fb7a9120e5d63 100644 --- a/src/opticalcontroller/variables.py +++ b/src/opticalcontroller/variables.py @@ -1,4 +1,3 @@ - # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - debug = 1 Fl = 184800 diff --git a/src/service/service/service_handlers/oc/OCServiceHandler.py b/src/service/service/service_handlers/oc/OCServiceHandler.py index 87a9a00755fc87426a511c94c28ebdc00d829425..6359f2a09e53cab1002acd55d477aeb2d9b393b0 100644 --- a/src/service/service/service_handlers/oc/OCServiceHandler.py +++ b/src/service/service/service_handlers/oc/OCServiceHandler.py @@ -23,12 +23,11 @@ from service.service.service_handler_api._ServiceHandler import _ServiceHandler from service.service.service_handler_api.SettingsHandler import SettingsHandler from service.service.task_scheduler.TaskExecutor import TaskExecutor from .ConfigRules import setup_config_rules, teardown_config_rules - -from common.proto.context_pb2 import EndPointId from .OCTools import convert_endpoints_to_flows, handle_flows_names + LOGGER = logging.getLogger(__name__) -METRICS_POOL = MetricsPool('Service', 'Handler', labels={'handler': 'l3nm_emulated'}) +METRICS_POOL = MetricsPool('Service', 'Handler', labels={'handler': 'oc'}) class OCServiceHandler(_ServiceHandler): def __init__( # pylint: disable=super-init-not-called @@ -38,9 +37,6 @@ class OCServiceHandler(_ServiceHandler): self.__task_executor = task_executor self.__settings_handler = SettingsHandler(service.service_config, **settings) - - - @metered_subclass_method(METRICS_POOL) def SetEndpoint( self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None @@ -58,7 +54,7 @@ class OCServiceHandler(_ServiceHandler): settings = self.__settings_handler.get('/settings') - # settings = self.__settings_handler.get('/settings') + # settings = self.__settings_handler.get('/settings') #flow is the new variable that stores input-output relationship diff --git a/src/service/service/service_handlers/oc/OCTools.py b/src/service/service/service_handlers/oc/OCTools.py index 529a1bc7f595bdfd32ce10a65599c4a7af2e8e12..2b202a8a9ce2183342fc23f3563cc16d81abcd5d 100644 --- a/src/service/service/service_handlers/oc/OCTools.py +++ b/src/service/service/service_handlers/oc/OCTools.py @@ -11,11 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching from typing import Dict, Any, List, Optional, Tuple import logging from common.proto.context_pb2 import ConfigRule, DeviceId, Service from common.tools.object_factory.Device import json_device_id + log = logging.getLogger(__name__) #def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])->Dict[str: List[Tuple[str, str]]]: @@ -26,7 +28,7 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]]) entries = {} #tuple is in, out #end = len(endpoints) if isinstance(endpoints,list) else 0 - end=len(endpoints) + end = len(endpoints) i = 0 bidir = 0 log.debug("end={}".format(end)) @@ -115,14 +117,10 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]]) def get_device_endpint_name (endpoint_uuid:str,device_uuid:str,task_executor)->Tuple: - - - device_obj = task_executor.get_device(DeviceId(**json_device_id(device_uuid))) endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) endpoint_name = endpoint_obj.name - - return (device_obj.name,endpoint_name) + return (device_obj.name, endpoint_name) def handle_flows_names (task_executor,flows:dict)->Dict : new_flows={} @@ -141,4 +139,4 @@ def handle_flows_names (task_executor,flows:dict)->Dict : if (device_name not in new_flows): new_flows[device_name]=[] new_flows[device_name].append((source_port,destination_port)) - return new_flows \ No newline at end of file + return new_flows