Skip to content
Snippets Groups Projects
Commit cca3e72c authored by Mohammad Ismaeel's avatar Mohammad Ismaeel
Browse files

fixing bugs for bidericational service

parent 1e93daad
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!284Resolve: "(CNIT) Multi-Granular Optical Nodes and Optical Transpoders management"
......@@ -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:
......
......@@ -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
......
......@@ -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=[ ]
......
......@@ -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
......
......@@ -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
......
......@@ -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]
......@@ -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=[]
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
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