Skip to content
Snippets Groups Projects
Commit 15584d15 authored by Andrea Sgambelluri's avatar Andrea Sgambelluri
Browse files

endpoint adaptation bugs solved

parent 75c30dd9
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"
......@@ -127,6 +127,7 @@ def create_optical_band (resources) :
results =[]
unwanted_keys=['destination_port','source_port','channel_namespace','frequency','optical-band-parent']
config,ports,index= seperate_port_config(resources,unwanted_keys=unwanted_keys)
logging.info(f"BBBBBBBBBBBBB {ports}")
doc, tag, text = Doc().tagtext()
#with tag('config'):
with tag('config',xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"):
......@@ -174,6 +175,7 @@ def create_media_channel (resources):
results=[]
unwanted_keys=['destination_port','source_port','channel_namespace','frequency','operational-mode', 'optical-band-parent']
config,ports,index= seperate_port_config(resources,unwanted_keys=unwanted_keys)
logging.info(f"BBBBBBBBBBBBB {ports}")
doc, tag, text = Doc().tagtext()
#with tag('config'):
with tag('config',xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"):
......
......@@ -167,7 +167,11 @@ def create_media_channel_v2 (resources):
with tag('source'):
with tag('config'):
with tag('port-name'):text(src)
n+=1
if dest is not None and dest != '0':
with tag('dest'):
with tag('config'):
with tag('port-name'):text(dest)
n+=1
result = indent(
doc.getvalue(),
......@@ -235,7 +239,7 @@ 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)
logging.info(f"SSSSSSSSSSSSSSS {ports}")
doc, tag, text = Doc().tagtext()
#with tag('config'):
with tag('config',xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"):
......@@ -246,6 +250,7 @@ def create_optical_band (resources) :
for flow in ports:
#with tag('optical-band', operation="create"):
src,dest=flow
logging.info(f"SSSSSSSSSSSSSSS {src}, {dest}")
with tag('optical-band'):
if index is not None:
with tag('index'):text(str(int(index)+n))
......
......@@ -25,7 +25,7 @@ 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 .OCTools import convert_endpoints_to_flows, handle_flows_names , check_media_channel_existance
from .OCTools import convert_endpoints_to_flows, endpoints_to_flows, handle_flows_names , check_media_channel_existance
LOGGER = logging.getLogger(__name__)
......@@ -58,15 +58,18 @@ class OCServiceHandler(_ServiceHandler):
LOGGER.info(f"setEndpoint {connection_uuid}")
settings = self.__settings_handler.get('/settings')
bidir = settings.value.get("bidir")
LOGGER.debug(f"Bidir bvalue is: {bidir}")
# settings = self.__settings_handler.get('/settings')
#flow is the new variable that stores input-output relationship
#flows = convert_endpoints_to_flows(endpoints)
flows = endpoints_to_flows(endpoints, bidir, is_opticalband)
flows = convert_endpoints_to_flows(endpoints)
#handled_flows=handle_flows_names(flows=flows,task_executor=self.__task_executor)
#LOGGER.info("Handled Flows %s",handled_flows)
LOGGER.info(f"Computed Flows {flows}")
results = []
#new cycle for setting optical devices
......@@ -94,6 +97,7 @@ class OCServiceHandler(_ServiceHandler):
is_opticalband =False
flows = convert_endpoints_to_flows(endpoints)
chk_type('endpoints', endpoints, list)
......
......@@ -116,6 +116,197 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])
return entries
def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int):
entries = {}
end = len(endpoints)
i = 0
if bidir:
endpoint = endpoints[i]
device_uuid, endpoint_uuid = endpoint[0:2]
log.info("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
if device_uuid not in entries.keys():
entries[device_uuid] = []
entry_tuple = "0", endpoint_uuid
entries[device_uuid].append(entry_tuple)
next_endpoint = endpoints[i+1]
next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
if next_device_uuid == device_uuid:
if next_device_uuid not in entries.keys():
entries[next_device_uuid] = []
entry_tuple = next_endpoint_uuid, "0"
entries[next_device_uuid].append(entry_tuple)
else:
log.info("error expected device_id {}, found {}".format(device_uuid, next_device_uuid))
return {}
i = i + 2
if end > 4:
log.info("Bidirectional optical band connection with {} (>4) endpoints".format(end))
while(i < end-2):
#i
endpoint = endpoints[i]
device_uuid, endpoint_uuid = endpoint[0:2]
log.debug("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
if device_uuid not in entries.keys():
entries[device_uuid] = []
#i+1
next_endpoint = endpoints[i+1]
next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
if next_device_uuid == device_uuid:
entry_tuple = endpoint_uuid, next_endpoint_uuid
entries[device_uuid].append(entry_tuple)
else:
log.debug("ERROR in bidirectional ob")
log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
return {}
#i+2
next_2_endpoint = endpoints[i+2]
next_2_device_uuid, next_2_endpoint_uuid = next_2_endpoint[0:2]
#i+3
next_3_endpoint = endpoints[i+3]
next_3_device_uuid, next_3_endpoint_uuid = next_3_endpoint[0:2]
if next_2_device_uuid == next_3_device_uuid and next_3_device_uuid == device_uuid:
entry_tuple = next_2_endpoint_uuid, next_3_endpoint_uuid
entries[device_uuid].append(entry_tuple)
i = i + 4
else:
log.debug("ERROR in bidirection ob")
return {}
endpoint = endpoints[i]
device_uuid, endpoint_uuid = endpoint[0:2]
if device_uuid not in entries.keys():
entries[device_uuid] = []
entry_tuple = endpoint_uuid, "0",
entries[device_uuid].append(entry_tuple)
next_endpoint = endpoints[i+1]
next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
if next_device_uuid == device_uuid:
if next_device_uuid not in entries.keys():
entries[next_device_uuid] = []
entry_tuple = "0", next_endpoint_uuid
entries[next_device_uuid].append(entry_tuple)
else:
log.debug("error expected device_id {}, found {}".format(device_uuid, next_device_uuid))
else:
endpoint = endpoints[i]
device_uuid, endpoint_uuid = endpoint[0:2]
log.info("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
if device_uuid not in entries.keys():
entries[device_uuid] = []
entry_tuple = "0", endpoint_uuid
entries[device_uuid].append(entry_tuple)
i = i + 1
if end > 2:
log.info("Unidirectional optical band connection with {} (>2) endpoints".format(end))
while(i < end-1):
#i
endpoint = endpoints[i]
device_uuid, endpoint_uuid = endpoint[0:2]
log.info("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
if device_uuid not in entries.keys():
entries[device_uuid] = []
#i+1
next_endpoint = endpoints[i+1]
next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
if next_device_uuid == device_uuid:
entry_tuple = endpoint_uuid, next_endpoint_uuid
entries[device_uuid].append(entry_tuple)
else:
log.debug("ERROR in bidirectional ob")
log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
return {}
i = i + 2
next_endpoint = endpoints[i]
next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
if next_device_uuid not in entries.keys():
entries[next_device_uuid] = []
entry_tuple = next_endpoint_uuid, "0"
entries[next_device_uuid].append(entry_tuple)
return entries
def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int):
entries = {}
end = len(endpoints)
i = 0
#tx tp
endpoint = endpoints[i]
device_uuid, endpoint_uuid = endpoint[0:2]
log.info("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
if device_uuid not in entries.keys():
entries[device_uuid] = []
entry_tuple = "0", endpoint_uuid
entries[device_uuid].append(entry_tuple)
i = i + 1
#if bidir reading 4 endpoints per node
if bidir:
while(i < end-1):
#i
endpoint = endpoints[i]
device_uuid, endpoint_uuid = endpoint[0:2]
log.info("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
if device_uuid not in entries.keys():
entries[device_uuid] = []
#i+1
next_endpoint = endpoints[i+1]
next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
if next_device_uuid == device_uuid:
entry_tuple = endpoint_uuid, next_endpoint_uuid
entries[device_uuid].append(entry_tuple)
else:
log.info("ERROR in bidirectional ob")
log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
return {}
#i+2
next_2_endpoint = endpoints[i+2]
next_2_device_uuid, next_2_endpoint_uuid = next_2_endpoint[0:2]
#i+3
next_3_endpoint = endpoints[i+3]
next_3_device_uuid, next_3_endpoint_uuid = next_3_endpoint[0:2]
if next_2_device_uuid == next_3_device_uuid and next_3_device_uuid == device_uuid:
entry_tuple = next_2_endpoint_uuid, next_3_endpoint_uuid
entries[device_uuid].append(entry_tuple)
i = i + 4
else:
log.info("ERROR in bidirection ob")
return {}
else:
while(i < end-1):
#i
endpoint = endpoints[i]
device_uuid, endpoint_uuid = endpoint[0:2]
log.info("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
if device_uuid not in entries.keys():
entries[device_uuid] = []
#i+1
next_endpoint = endpoints[i+1]
next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
if next_device_uuid == device_uuid:
entry_tuple = endpoint_uuid, next_endpoint_uuid
entries[device_uuid].append(entry_tuple)
i = i + 2
else:
log.debug("ERROR in bidirectional ob")
log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
return {}
#rx tp
endpoint = endpoints[i]
device_uuid, endpoint_uuid = endpoint[0:2]
if device_uuid not in entries.keys():
entries[device_uuid] = []
entry_tuple = endpoint_uuid, "0",
entries[device_uuid].append(entry_tuple)
return entries
def endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, is_ob: bool)->Dict:
log.info("AAAAAAAAAAAAAAAAAAAAAAAA: {}".format(endpoints))
if is_ob:
entries = ob_flows(endpoints, bidir)
else:
entries = conn_flows(endpoints, bidir)
return entries
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)
......
......@@ -163,6 +163,8 @@ def adapt_reply(devices, service, reply_json, context_id, topology_id, optical_b
rules_ob= []
ob_id = 0
connection_ob=None
r = reply_json
bidir_f = r["bidir"]
if optical_band_txt != "":
ob_json = json.loads(optical_band_txt)
ob = ob_json
......@@ -184,7 +186,7 @@ def adapt_reply(devices, service, reply_json, context_id, topology_id, optical_b
bx = ob["band"]
lf = int(int(freq)-int(bx/2))
uf = int(int(freq)+int(bx/2))
val_ob = {"band_type": band_type, "low-freq": lf, "up-freq": uf, "frequency": freq, "band": bx, "ob_id": ob_id}
val_ob = {"band_type": band_type, "low-freq": lf, "up-freq": uf, "frequency": freq, "band": bx, "ob_id": ob_id, "bidir": bidir_f}
rules_ob.append(ConfigRule_Custom(resource_key="/settings-ob_{}".format(uuuid_x), resource_value=json.dumps(val_ob)))
bidir_ob = ob["bidir"]
for devxb in ob["flows"].keys():
......@@ -229,8 +231,7 @@ def adapt_reply(devices, service, reply_json, context_id, topology_id, optical_b
else:
log.info("no map device port for device {} port {}".format(devxb, out_end_point_b))
log.debug("optical-band connection {}".format(connection_ob))
r = reply_json
bidir_f = r["bidir"]
connection_f = add_connection_to_reply(opt_reply)
connection_f.connection_id.connection_uuid.uuid = str(uuid.uuid4())
connection_f.service_id.CopyFrom(service.service_id)
......@@ -293,9 +294,9 @@ def adapt_reply(devices, service, reply_json, context_id, topology_id, optical_b
band_type = "C_BAND"
if ob_id != 0:
val = {"target-output-power": "1.0", "frequency": frequency, "operational-mode": op_mode, "band": band, "flow_id": flow_id, "ob_id": ob_id, "band_type": band_type,}
val = {"target-output-power": "1.0", "frequency": frequency, "operational-mode": op_mode, "band": band, "flow_id": flow_id, "ob_id": ob_id, "band_type": band_type, "bidir": bidir_f}
else:
val = {"target-output-power": "1.0", "frequency": frequency, "operational-mode": op_mode, "band": band, "flow_id": flow_id, "band_type": band_type,}
val = {"target-output-power": "1.0", "frequency": frequency, "operational-mode": op_mode, "band": band, "flow_id": flow_id, "band_type": band_type, "bidir": bidir_f}
custom_rule = ConfigRule_Custom(resource_key="/settings", resource_value=json.dumps(val))
rule = ConfigRule(action=ConfigActionEnum.CONFIGACTION_SET, custom=custom_rule)
service.service_config.config_rules.add().CopyFrom(rule)
......
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