Skip to content
Snippets Groups Projects
Commit a6adad8b authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Optical controller:

-Pre-merge cleanup
parent 48d4900a
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!212Resolve "(CNIT) Integrate leftover common contributions related to Optical Controller component"
......@@ -28,6 +28,9 @@ export TFS_COMPONENTS="context device pathcomp service slice nbi webui load_gene
# Uncomment to activate BGP-LS Speaker
#export TFS_COMPONENTS="${TFS_COMPONENTS} bgpls_speaker"
# Uncomment to activate Optical Controller
#export TFS_COMPONENTS="${TFS_COMPONENTS} opticalcontroller"
# Uncomment to activate ZTP
#export TFS_COMPONENTS="${TFS_COMPONENTS} ztp"
......
......@@ -248,80 +248,78 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
if len(service_with_uuids.service_endpoint_ids) >= num_expected_endpoints:
pathcomp_request = PathCompRequest()
pathcomp_request.services.append(service_with_uuids) # pylint: disable=no-member
if service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY:
context_id_x = json_context_id(DEFAULT_CONTEXT_NAME)
topology_id_x = json_topology_id(
DEFAULT_TOPOLOGY_NAME, context_id_x)
topology_details = context_client.GetTopologyDetails(
TopologyId(**topology_id_x))
# devices = get_devices_in_topology(context_client, TopologyId(**topology_id_x), ContextId(**context_id_x))
devices = topology_details.devices
context_uuid_x = topology_details.topology_id.context_id.context_uuid.uuid
topology_uuid_x = topology_details.topology_id.topology_uuid.uuid
devs = []
ports = []
for endpoint_id in service.service_endpoint_ids:
devs.append(endpoint_id.device_id.device_uuid.uuid)
ports.append(endpoint_id.endpoint_uuid.uuid)
src = devs[0]
dst = devs[1]
bidir = None
ob_band = None
bitrate = 100
for constraint in service.service_constraints:
if "bandwidth" in constraint.custom.constraint_type:
bitrate = int(float(constraint.custom.constraint_value))
elif "bidirectionality" in constraint.custom.constraint_type:
bidir = int(constraint.custom.constraint_value)
elif "optical-band-width" in constraint.custom.constraint_type:
ob_band = int(constraint.custom.constraint_value)
# to get the reply form the optical module
reply_txt = add_lightpath(src, dst, bitrate, bidir, ob_band)
# reply with 2 transponders and 2 roadms
reply_json = json.loads(reply_txt)
optical_band_txt = ""
if "new_optical_band" in reply_json.keys():
if reply_json["new_optical_band"] == 1:
if reply_json["parent_opt_band"]:
if "parent_opt_band" in reply_json.keys():
parent_ob = reply_json["parent_opt_band"]
LOGGER.debug('Parent optical-band={}'.format(parent_ob))
optical_band_txt = get_optical_band(parent_ob)
LOGGER.info('optical-band details={}'.format(optical_band_txt))
else:
LOGGER.debug('expected optical band not found')
context_id_x = json_context_id(DEFAULT_CONTEXT_NAME)
topology_id_x = json_topology_id(
DEFAULT_TOPOLOGY_NAME, context_id_x)
topology_details = context_client.GetTopologyDetails(
TopologyId(**topology_id_x))
# devices = get_devices_in_topology(context_client, TopologyId(**topology_id_x), ContextId(**context_id_x))
devices = topology_details.devices
context_uuid_x = topology_details.topology_id.context_id.context_uuid.uuid
topology_uuid_x = topology_details.topology_id.topology_uuid.uuid
devs = []
ports = []
for endpoint_id in service.service_endpoint_ids:
devs.append(endpoint_id.device_id.device_uuid.uuid)
ports.append(endpoint_id.endpoint_uuid.uuid)
src = devs[0]
dst = devs[1]
bidir = None
ob_band = None
bitrate = 100
for constraint in service.service_constraints:
if "bandwidth" in constraint.custom.constraint_type:
bitrate = int(float(constraint.custom.constraint_value))
elif "bidirectionality" in constraint.custom.constraint_type:
bidir = int(constraint.custom.constraint_value)
elif "optical-band-width" in constraint.custom.constraint_type:
ob_band = int(constraint.custom.constraint_value)
# to get the reply form the optical module
reply_txt = add_lightpath(src, dst, bitrate, bidir, ob_band)
# reply with 2 transponders and 2 roadms
reply_json = json.loads(reply_txt)
optical_band_txt = ""
if "new_optical_band" in reply_json.keys():
if reply_json["new_optical_band"] == 1:
if reply_json["parent_opt_band"]:
if "parent_opt_band" in reply_json.keys():
parent_ob = reply_json["parent_opt_band"]
LOGGER.debug('Parent optical-band={}'.format(parent_ob))
optical_band_txt = get_optical_band(parent_ob)
LOGGER.info('optical-band details={}'.format(optical_band_txt))
else:
LOGGER.debug('expected optical band not found')
else:
LOGGER.debug('Using existing optical band')
LOGGER.debug('expected optical band not found')
else:
LOGGER.debug('Using existing optical band')
if reply_txt is not None:
optical_reply = adapt_reply(devices, _service, reply_json, context_uuid_x, topology_uuid_x, optical_band_txt)
LOGGER.info('optical_reply={:s}'.format(
grpc_message_to_json_string(optical_reply)))
tasks_scheduler.compose_from_pathcompreply(
optical_reply, is_delete=False)
else:
if num_disjoint_paths is None or num_disjoint_paths in {0, 1} :
pathcomp_request.shortest_path.Clear() # pylint: disable=no-member
else:
pathcomp_request.k_disjoint_path.num_disjoint = num_disjoint_paths # pylint: disable=no-member
else:
LOGGER.debug('Using existing optical band')
if reply_txt is not None:
optical_reply = adapt_reply(devices, _service, reply_json, context_uuid_x, topology_uuid_x, optical_band_txt)
LOGGER.info('optical_reply={:s}'.format(
grpc_message_to_json_string(optical_reply)))
tasks_scheduler.compose_from_pathcompreply(
optical_reply, is_delete=False)
else:
if num_disjoint_paths is None or num_disjoint_paths in {0, 1} :
pathcomp_request.shortest_path.Clear() # pylint: disable=no-member
else:
pathcomp_request.k_disjoint_path.num_disjoint = num_disjoint_paths # pylint: disable=no-member
pathcomp = PathCompClient()
pathcomp_reply = pathcomp.Compute(pathcomp_request)
pathcomp.close()
pathcomp = PathCompClient()
pathcomp_reply = pathcomp.Compute(pathcomp_request)
pathcomp.close()
# Feed TaskScheduler with this path computation reply. TaskScheduler identifies inter-dependencies among
# the services and connections retrieved and produces a schedule of tasks (an ordered list of tasks to be
# executed) to implement the requested create/update operation.
tasks_scheduler.compose_from_pathcompreply(pathcomp_reply, is_delete=False)
tasks_scheduler.compose_from_pathcompreply(pathcomp_reply, is_delete=False)
tasks_scheduler.execute_all()
return service_with_uuids.service_id
......@@ -347,7 +345,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
if service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY:
devs = []
context_id_x = json_context_id(DEFAULT_CONTEXT_NAME)
topology_id_x = json_topology_id(
DEFAULT_TOPOLOGY_NAME, context_id_x)
......@@ -358,17 +356,15 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
devs.append(endpoint_id.device_id.device_uuid.uuid)
src = get_device_name_from_uuid(devices, devs[0])
dst = get_device_name_from_uuid(devices, devs[1])
bitrate = int(
float(service.service_constraints[0].custom.constraint_value))
if len(service.service_config.config_rules) > 0:
c_rules_dict = json.loads(
service.service_config.config_rules[0].custom.resource_value)
if ("flow_id" in c_rules_dict):
flow_id = c_rules_dict["flow_id"]
flow_id = c_rules_dict["flow_id"]
reply = delete_lightpath(flow_id, src, dst, bitrate)
# Normal service
# Feed TaskScheduler with this service and the sub-services and sub-connections related to this service.
......
......@@ -45,7 +45,7 @@ def main():
get_env_var_name(ServiceNameEnum.PATHCOMP, ENVVAR_SUFIX_SERVICE_HOST ),
get_env_var_name(ServiceNameEnum.PATHCOMP, ENVVAR_SUFIX_SERVICE_PORT_GRPC),
])
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
......
......@@ -117,7 +117,7 @@ class TaskExecutor:
self._device_client.ConfigureDevice(device)
self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device)
# New function Andrea for Optical Devices
# New function Andrea for Optical Devices
def configure_optical_device(self, device : Device, settings : str, flows : list, is_opticalband : bool):
device_key = get_device_key(device.device_id)
myid = OpticalConfigId()
......@@ -125,6 +125,7 @@ class TaskExecutor:
opticalconfig = OpticalConfig()
setting = settings.value if settings else ""
new_config = {}
try:
result = self._context_client.SelectOpticalConfig(myid)
new_config = json.loads(result.config)
......
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