diff --git a/src/context/service/database/OpticalConfig.py b/src/context/service/database/OpticalConfig.py index 033a25a5670197960d99cf1e64fa391d07662dd5..c16912036d07831d85248229842475b6151a4d70 100644 --- a/src/context/service/database/OpticalConfig.py +++ b/src/context/service/database/OpticalConfig.py @@ -120,12 +120,12 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): #channels = [channel['name']['index'] for channel in config['channels']] channel_num=0 for channel_params in config['media_channels']: - channel_num+=1 + channel_index=channel_params['channel_index'] if 'channel_index' is not None else None channels.append( { # "opticalconfig_uuid":opticalconfig_uuid, "roadm_uuid" : roadm_get_uuid(device_id), - "channel_uuid" : channel_get_uuid(f'media_channel_{channel_num}',device_uuid), + "channel_uuid" : channel_get_uuid(f'media_channel_{channel_index}',device_uuid), "band_name" : channel_params['band_name'], "lower_frequency" : int(channel_params["lower_frequency"]) if "lower_frequency" in channel_params else 0, "upper_frequency" : int(channel_params["upper_frequency"]) if "upper_frequency" in channel_params else 0, @@ -134,7 +134,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): "status" : channel_params["status"] if "status" in channel_params else "", "type" : 'media_channel', "optical_band_parent":str(channel_params['optical_band_parent']) if 'optical_band_parent' in channel_params else None, - "channel_index" : channel_params['channel_index'] if 'channel_index' in channel_params else None, + "channel_index" : channel_index if channel_index is not None else None, } ) if 'optical_bands' in config and len(config['optical_bands']) > 0: @@ -254,8 +254,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): src_port=stmt.excluded.src_port, channel_index=stmt.excluded.channel_index, optical_band_parent = stmt.excluded.optical_band_parent - - + ) ) @@ -357,57 +356,62 @@ def update_opticalconfig(db_engine : Engine, request : OpticalConfig): if config_type == "optical-roadm": - if 'flow_handled' in config and len(config['flow_handled'])==0 : - config['flow_handled'] =[(None,None)] if channel_namespace is None and 'channel_namespace' in config['new_config']: channel_namespace=config['new_config']['channel_namespace'] if 'is_opticalband' in config and not config['is_opticalband']: #channels = [channel['name']['index'] for channel in config['channels']] - channel_num=0 - for flow in config['flow_handled']: - src_port,dest_port=flow - channel_num+=1 - channels.append( - { - # "opticalconfig_uuid":opticalconfig_uuid, - "roadm_uuid" : roadm_get_uuid(device_id), - "channel_uuid" : channel_get_uuid(f'media_channel_{channel_num}',device_uuid), - "band_name" : config['new_config']['band_type'], - "lower_frequency" : int(int(config['new_config']['frequency']) - (int(config['new_config']['band'])/2)) if "frequency" in config['new_config'] else 0, - "upper_frequency" :int(int(config['new_config']['frequency']) + (int(config['new_config']['band'])/2)) if "frequency" in config['new_config'] else 0, - "dest_port" : dest_port, - "src_port" : src_port, - "status" : config['new_config']["status"] if "status" in config['new_config'] else "", - "type" : 'media_channel', - "optical_band_parent":str( config['new_config']['ob_id']) if 'ob_id' in config['new_config'] else None, - "channel_index":str(config["new_config"]["flow_id"]) if "flow_id" in config["new_config"] else None - } - ) + if 'flow_handled' in config and len(config['flow_handled'])>0 : + num=0 + flow_id=config["new_config"]["flow_id"] if 'flow_id' in config['new_config'] else None + for flow in config['flow_handled']: + src_port,dest_port=flow + channel_index=flow_id+num + num+=1 + channels.append( + { + # "opticalconfig_uuid":opticalconfig_uuid, + "roadm_uuid" : roadm_get_uuid(device_id), + "channel_uuid" : channel_get_uuid(f'media_channel_{channel_index}',device_uuid), + "band_name" : config['new_config']['band_type'], + "lower_frequency" : int(int(config['new_config']['frequency']) - (int(config['new_config']['band'])/2)) if "frequency" in config['new_config'] else 0, + "upper_frequency" :int(int(config['new_config']['frequency']) + (int(config['new_config']['band'])/2)) if "frequency" in config['new_config'] else 0, + "dest_port" :dest_port, + "src_port" : src_port, + "status" : config['new_config']["status"] if "status" in config['new_config'] else "", + "type" : 'media_channel', + "optical_band_parent":str( config['new_config']['ob_id']) if 'ob_id' in config['new_config'] else None, + "channel_index":str(channel_index) if channel_index is not None else None + } + ) if 'is_opticalband' in config and config['is_opticalband']: #channels = [channel['name']['index'] for channel in config['channels']] - channel_num=0 - for flow in config['flow_handled']: - src_port,dest_port=flow - LOGGER.info(f"udpate_optical_bands src: {src_port} and dest :{dest_port} for flow {flow}") - channel_num+=1 - channels.append( + + if 'flow_handled' in config and len(config['flow_handled'])>0 : + ob_id =config['new_config']['ob_id'] if 'ob_id' in config['new_config'] else None + num=0 + for flow in config['flow_handled']: - { - # "opticalconfig_uuid":opticalconfig_uuid, - "roadm_uuid" : roadm_get_uuid(device_id), - "channel_uuid" : channel_get_uuid(f'optical_bands_{channel_num}',device_uuid), - "band_name" : config['new_config']['band_type'], - "lower_frequency" : int(config['new_config']["low-freq"]) if "low-freq" in config['new_config'] else 0, - "upper_frequency" : int(config['new_config']["up-freq"]) if "up-freq" in config['new_config'] else 0, - "dest_port" :dest_port, - "src_port" : src_port, - "status" : config['new_config']["status"] if "status" in config['new_config'] else "", - "type" : 'optical_band', - "channel_index" :str( config['new_config']['ob_id']) if 'ob_id' in config['new_config'] else None - } - ) + src_port,dest_port=flow + channel_index=ob_id+num + num+=1 + channels.append( + + { + # "opticalconfig_uuid":opticalconfig_uuid, + "roadm_uuid" : roadm_get_uuid(device_id), + "channel_uuid" : channel_get_uuid(f'optical_bands_{channel_index}',device_uuid), + "band_name" : config['new_config']['band_type'], + "lower_frequency" : int(config['new_config']["low-freq"]) if "low-freq" in config['new_config'] else 0, + "upper_frequency" : int(config['new_config']["up-freq"]) if "up-freq" in config['new_config'] else 0, + "dest_port" :dest_port, + "src_port" : src_port, + "status" : config['new_config']["status"] if "status" in config['new_config'] else "", + "type" : 'optical_band', + "channel_index" :str( channel_index) if channel_index is not None else None + } + ) roadms.append({ "roadm_uuid":roadm_get_uuid(device_id), @@ -551,6 +555,7 @@ def delete_opticalchannel(db_engine : Engine ,messagebroker : MessageBroker, re opticalconfig_uuid = request.opticalconfig_id.opticalconfig_uuid channels=[] config_type=None + LOGGER.info(f"delete_optical_channel config {config}") if "type" in config : config_type= config["type"] if 'new_config' in config: diff --git a/src/context/service/database/models/OpticalConfig/RoadmModel.py b/src/context/service/database/models/OpticalConfig/RoadmModel.py index 8e37a3cf688d3455c9a7b3bf16862b4c39ef4cb2..6a3add33524f0b01731e53bf828679c97ae4f9eb 100644 --- a/src/context/service/database/models/OpticalConfig/RoadmModel.py +++ b/src/context/service/database/models/OpticalConfig/RoadmModel.py @@ -53,7 +53,8 @@ class ChannelModel(_Base): channel_index = Column(String , nullable=True) status = Column(String , nullable=True) src_port = Column(String, nullable=True) - dest_port = Column(String, nullable=True) + dest_port = Column(String, nullable=True) + type = Column(String, nullable=False) optical_band_parent = Column(String, nullable=True) @@ -74,6 +75,7 @@ class ChannelModel(_Base): "type" : self.type, "src_port" : self.src_port, "dest_port" : self.dest_port, + "status":self.status, "optical_band_parent":self.optical_band_parent, "channel_index":self.channel_index diff --git a/src/device/service/OpenConfigServicer.py b/src/device/service/OpenConfigServicer.py index 358f98fc22de21c3447f322caf99f0554f2db0e6..798c1b218042e3dba6b46abb894b8c72b5e27cda 100644 --- a/src/device/service/OpenConfigServicer.py +++ b/src/device/service/OpenConfigServicer.py @@ -79,6 +79,7 @@ class OpenConfigServicer(DeviceServiceServicer): resources:list[dict]=[] is_all_good=True config =json.loads(request.config) + results=None LOGGER.info(f" config from openconfigservicer {config}") try: context_client = ContextClient() @@ -95,23 +96,25 @@ class OpenConfigServicer(DeviceServiceServicer): for result in results: if not result : is_all_good=False + LOGGER.info(f"resluts {results} and is_all_good {is_all_good}") if is_all_good: #driver.GetConfig(resource_keys=[]) config = json.loads(request.config) + handled_flow=next((i for i in resources if i['resource_key']=='handled_flow'),None) flow_handled=[ ] - if "new_config" in config and "flow" in config: - for flow in config['flow']: - src,dest= flow - LOGGER.info(f"src {src} and dest {dest}") - src_raw=get_endpoint_matching(device,src)if src != '0' else '0' - dest_raw=get_endpoint_matching(device,dest) if dest != '0' else '0' - src_name = src_raw.name if isinstance(src_raw,EndPoint) else '0' - dest_name= dest_raw.name if isinstance(dest_raw,EndPoint) else '0' - flow_handled.append((src_name,dest_name)) - LOGGER.info(f"flow_handled {flow_handled}") - if len(flow_handled)>0: - config['flow_handled']=flow_handled + # if "new_config" in config : + # for flow in config['flow']: + # src,dest= flow + # LOGGER.info(f"src {src} and dest {dest}") + # src_raw=get_endpoint_matching(device,src)if src != '0' else '0' + # dest_raw=get_endpoint_matching(device,dest) if dest != '0' else '0' + # src_name = src_raw.name if isinstance(src_raw,EndPoint) else '0' + # dest_name= dest_raw.name if isinstance(dest_raw,EndPoint) else '0' + # flow_handled.append((src_name,dest_name)) + LOGGER.info(f"flow_handled {handled_flow}") + if handled_flow is not None and len(handled_flow)>0: + config['flow_handled']=handled_flow['value'] request.config=json.dumps(config) @@ -190,7 +193,7 @@ class OpenConfigServicer(DeviceServiceServicer): for result in results: if not result : is_all_good=False - LOGGER.info(f"resluts {results} and is_all_good {is_all_good}") + LOGGER.info(f"Disable resluts {results} and is_all_good {is_all_good}") if is_all_good: config = json.loads(request.config) flow_handled=[ ] diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py index 0a700481ff3cdcb4d30d1b79a626dc35c5d0b8e1..dc4d4b20e0a5d68860f05833903d95f9a590a8e2 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -491,6 +491,7 @@ def extract_resources(config : dict, device : Device) -> list[list[dict],dict]: #for tuple_value in config['flow'][device.name]: source_vals = [] dest_vals = [] + handled_flow=[] for tuple_value in config['flow']: source_port = None destination_port = None @@ -503,9 +504,10 @@ def extract_resources(config : dict, device : Device) -> list[list[dict],dict]: dst_endpoint_obj = get_endpoint_matching(device, destination_port_uuid) destination_port = dst_endpoint_obj.name dest_vals.append(destination_port) + handled_flow.append((source_port,destination_port)) resources.append({'resource_key': 'source_port', 'value': source_vals}) resources.append({'resource_key': 'destination_port', 'value': dest_vals }) - + resources.append({'resource_key':'handled_flow','value':handled_flow}) if 'new_config' in config: lower_frequency = None upper_frequency = None diff --git a/src/device/service/drivers/oc_driver/OCDriver.py b/src/device/service/drivers/oc_driver/OCDriver.py index ffb57da05c98dde165f79eaf3c5bb6089da4ae9c..40d3d0e4c21e290240a562a581c10da0bf0e8d7d 100644 --- a/src/device/service/drivers/oc_driver/OCDriver.py +++ b/src/device/service/drivers/oc_driver/OCDriver.py @@ -225,6 +225,7 @@ class OCDriver(_Driver): timezone=pytz.utc) self._temp_address=f"{address}{port}" self.__out_samples = queue.Queue() + logging.info(f"setting ocdriver address {self.address} and {self.port} {self.settings}") self.__netconf_handler = NetconfSessionHandler(self.address, self.port, **(self.settings)) self.__type = self.settings.get("type","optical-transponder") self.__device_uuid=device_uuid diff --git a/src/device/service/drivers/oc_driver/templates/VPN/common.py b/src/device/service/drivers/oc_driver/templates/VPN/common.py index a1ad52ab7947c085700c0d558882358609e70aeb..3b21974f08f842cf6a19023f23f52e515b411a47 100644 --- a/src/device/service/drivers/oc_driver/templates/VPN/common.py +++ b/src/device/service/drivers/oc_driver/templates/VPN/common.py @@ -51,3 +51,34 @@ def seperate_port_config(resources:list,unwanted_keys=[])->list[list,dict,str]: return [config,ports,index] + + +def extract_ports (resources:list): + if len(resources) ==0 :return + ports=[] + flow=next((i for i in resources if i['resource_key']=='handled_flow'),None) + if flow is not None: + ports = flow['value'] + return ports + + + + + +def filter_config(resources:list,unwanted_keys=[])->list[list,dict,str]: + config=[] + ports=() + index=None + for item in resources : + if len(unwanted_keys)>0: + if (item['value'] is not None and (item['resource_key'] not in unwanted_keys)): + config.append({'resource_key':item['resource_key'], 'value':item['value']} ) + if (item['resource_key']=='index' and item['value'] is not None) : + index=item['value'] + #if (item['resource_key'] == 'destination_port' or item['resource_key'] == 'source_port') and item['value'] is not None: + # ports[item['resource_key']]=item['value'] + ports = extract_ports(resources=resources) + + return [config,ports,index] + + diff --git a/src/device/service/drivers/oc_driver/templates/VPN/roadms.py b/src/device/service/drivers/oc_driver/templates/VPN/roadms.py index 4e3c24291c7f52af25e5d022ddab0858f42facd1..1c89aa2573d359dce3537727c5c63e41c1ffcc49 100644 --- a/src/device/service/drivers/oc_driver/templates/VPN/roadms.py +++ b/src/device/service/drivers/oc_driver/templates/VPN/roadms.py @@ -16,16 +16,19 @@ from yattag import Doc, indent import logging -from .common import seperate_port_config +from .common import seperate_port_config ,filter_config -def create_media_channel (resources): +def create_media_channel_old (resources): optical_band_namespaces="http://flex-scale-project.eu/yang/flex-scale-mg-on" results=[] - unwanted_keys=['destination_port','source_port','channel_namespace','frequency','operational-mode'] + unwanted_keys=['destination_port','source_port','channel_namespace' + ,'frequency','operational-mode','target-output-power', + "admin-state","flow_handled","channel_num"] config,ports,index= seperate_port_config(resources,unwanted_keys=unwanted_keys) + doc, tag, text = Doc().tagtext() #with tag('config'): @@ -69,12 +72,66 @@ def create_media_channel (resources): results.append(result) return results + + + +def create_media_channel (resources): + optical_band_namespaces="http://flex-scale-project.eu/yang/flex-scale-mg-on" + results=[] + unwanted_keys=['destination_port','source_port','channel_namespace' + ,'frequency','operational-mode','target-output-power', + "admin-state","handled_flow","channel_num"] + + config,ports,index=filter_config(resources,unwanted_keys) + + doc, tag, text = Doc().tagtext() + #with tag('config'): + with tag('config',xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"): + with tag('wavelength-router', xmlns="http://openconfig.net/yang/wavelength-router"): + with tag('media-channels'): + n = 0 + + for flow in ports: + src,dest=flow + #with tag('channel', operation="create"): + with tag('channel'): + with tag('index'):text(str(int(index)+n)) + with tag('config'): + #with tag('index'):text(index) + for resource in config: + + if resource['resource_key'] == "index": + with tag('index'):text(str(int(index)+n)) + elif resource['resource_key']== 'optical-band-parent' : + with tag('optical-band-parent',xmlns=optical_band_namespaces):text(resource['value']) + else: + with tag(resource['resource_key']):text(resource['value']) + if dest is not None and dest != '0': + with tag('dest'): + with tag('config'): + with tag('port-name'):text(dest) + if src is not None and src != '0': + with tag('source'): + with tag('config'): + with tag('port-name'):text(src) + n+=1 + + result = indent( + doc.getvalue(), + indentation = ' '*2, + newline = '' + ) + results.append(result) + return results + + + -def create_optical_band (resources) : +def create_optical_band_old (resources) : results =[] - unwanted_keys=['destination_port','source_port','channel_namespace','frequency','optical-band-parent'] + unwanted_keys=['destination_port','source_port','channel_namespace','frequency','optical-band-parent','flow_handled'] config,ports,index= seperate_port_config(resources,unwanted_keys=unwanted_keys) doc, tag, text = Doc().tagtext() @@ -121,6 +178,56 @@ def create_optical_band (resources) : return results + + +def create_optical_band (resources) : + results =[] + unwanted_keys=['destination_port','source_port','channel_namespace','frequency','optical-band-parent','handled_flow'] + config,ports,index= filter_config(resources,unwanted_keys=unwanted_keys) + + doc, tag, text = Doc().tagtext() + #with tag('config'): + with tag('config',xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"): + with tag('wavelength-router', xmlns="http://openconfig.net/yang/wavelength-router"): + with tag('optical-bands',xmlns="http://flex-scale-project.eu/yang/flex-scale-mg-on"): + n = 0 + + for flow in ports: + #with tag('optical-band', operation="create"): + src,dest=flow + with tag('optical-band'): + if index is not None: + with tag('index'):text(str(int(index)+n)) + with tag('config'): + #if index is not None: + # with tag('index'):text(str(int(index)+i)) + for resource in config: + if resource['resource_key'] == "index": + with tag('index'):text(str(int(index)+n)) + else: + with tag(resource['resource_key']):text(resource['value']) + with tag('admin-status'):text('ENABLED') + #with tag('fiber-parent'):text(ports['destination_port'] if 'destination_port' in ports else ports['source_port']) + if dest is not None and dest != '0': + with tag('dest'): + with tag('config'): + with tag('port-name'):text(dest) + if src is not None and src !='0': + with tag('source'): + with tag('config'): + with tag('port-name'):text(src) + n +=1 + + + result = indent( + doc.getvalue(), + indentation = ' '*2, + newline = '' + ) + results.append(result) + return results + + def disable_media_channel (resources): results=[] diff --git a/src/device/service/drivers/oc_driver/templates/VPN/transponder.py b/src/device/service/drivers/oc_driver/templates/VPN/transponder.py index 0ec952e7444706bc1a20557c4e5ebe7912029546..c4a2c3c521e299adf129765e88543056c6b56cb9 100644 --- a/src/device/service/drivers/oc_driver/templates/VPN/transponder.py +++ b/src/device/service/drivers/oc_driver/templates/VPN/transponder.py @@ -142,7 +142,8 @@ def change_optical_channel_status (state:str,ports:list[dict]) : def edit_optical_channel (resources:list[dict]): logging.info(f"building xml {resources}") - unwanted_keys=['destination_port','source_port','channel_namespace','optical-band-parent','index', 'name','admin-state'] + unwanted_keys=['destination_port','source_port','channel_namespace' + ,'optical-band-parent','index', 'name','admin-state','handled_flow'] config,ports,index=seperate_port_config(resources,unwanted_keys=unwanted_keys) results = [] # channel_name=next((i["value"] for i in resources if i["resource_key"]=="channel_name" and i["value"] != None),None) diff --git a/src/service/service/task_scheduler/TaskExecutor.py b/src/service/service/task_scheduler/TaskExecutor.py index 1b8aeaf99a202729ab1ee0c1b20598b21411e2ed..77447c9e3a6d25689f29d124f419f089233e0e16 100644 --- a/src/service/service/task_scheduler/TaskExecutor.py +++ b/src/service/service/task_scheduler/TaskExecutor.py @@ -133,7 +133,7 @@ class TaskExecutor: try: result = self._context_client.SelectOpticalConfig(optical_config_id) - LOGGER.info("resul from select optical config %s",result) + new_config = json.loads(result.config) if 'type' in new_config: config_type=new_config['type'] @@ -147,6 +147,7 @@ class TaskExecutor: new_config["flow"] = flows result.config = json.dumps(new_config) optical_config.CopyFrom(result) + LOGGER.info("resul from select optical config %s",optical_config) self._device_client.ConfigureOpticalDevice(optical_config) self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device) diff --git a/src/webui/service/opticalconfig/routes.py b/src/webui/service/opticalconfig/routes.py index 872ed97c3c0103fedca632d41371811f393b5a17..8594048ded9baae83a1245ecd6dcefc5841e4d4a 100644 --- a/src/webui/service/opticalconfig/routes.py +++ b/src/webui/service/opticalconfig/routes.py @@ -180,6 +180,7 @@ def update_externally () : target_power=device.get( "target-output-power") freq = device.get("frequency") mode = device.get("operational-mode") + status= device.get("status","ENABLED") LOGGER.info(f"target power {target_power} freq {freq} mode {mode}") if target_channel: if target_power : @@ -191,6 +192,8 @@ def update_externally () : if mode : target_channel["operational-mode"] =mode + if status : + target_channel["status"]="ENABLED" #del target_channel['name'] config["new_config"]=target_channel config["new_config"]["channel_name"]=channel_name