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

fix bi service deployment , deletion , and expansion

parent 2dc50012
No related branches found
No related tags found
1 merge request!341Draft: Resolve "optical bandwidth expansion"
......@@ -65,7 +65,8 @@ def add_transceiver (transceiver_name:str):
def create_optical_channel(resources:list[dict],ports:list[dict],config:list[dict] ):
#unwanted_keys=['destination_port','source_port','channel_namespace','optical-band-parent','index', 'name','admin-state']
# unwanted_keys=['bidir','source_port','destination_port','handled_flow','name','channel_namespace','admin-state'
# ,'optical-band-parent']
results =[]
data ={}
data["channel_namespace"]=next((i["value"] for i in resources if i["resource_key"] == "channel_namespace"), None)
......@@ -141,7 +142,7 @@ def change_optical_channel_status (state:str,ports:list[dict]) :
def edit_optical_channel (resources:list[dict]):
unwanted_keys=['destination_port','source_port','channel_namespace'
,'optical-band-parent','index', 'name','admin-state','handled_flow']
,'optical-band-parent','index', 'name','admin-state','handled_flow','bidir']
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)
......
......@@ -25,7 +25,7 @@ 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 (
endpoints_to_flows
endpoints_to_flows,convert_endpoints_to_flows
#handle_flows_names, check_media_channel_existance
)
......@@ -136,11 +136,11 @@ class OCServiceHandler(_ServiceHandler):
self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None
) -> List[Union[bool, Exception]]:
is_opticalband =False
flows = convert_endpoints_to_flows(endpoints)
service_uuid = self.__service.service_id.service_uuid.uuid
chk_type('endpoints', endpoints, list)
if len(endpoints) == 0: return []
if self.__settings_handler.get('/settings-ob_{}'.format(connection_uuid)):
is_opticalband =True
settings = self.__settings_handler.get('/settings-ob_{}'.format(connection_uuid))
......@@ -148,6 +148,7 @@ class OCServiceHandler(_ServiceHandler):
settings = self.__settings_handler.get('/settings')
bidir = settings.value.get("bidir",None)
flows = convert_endpoints_to_flows(endpoints)
results = []
for endpoint in endpoints:
......@@ -174,7 +175,7 @@ class OCServiceHandler(_ServiceHandler):
except Exception as e: # pylint: disable=broad-except
LOGGER.exception('Unable to DeleteEndpoint({:s})'.format(str(endpoint)))
results.append(e)
LOGGER.info(f"delete_endpoints_flows-> {flows}")
for device_uuid, dev_flows in flows.items():
try:
channel_indexes= []
......
......@@ -20,100 +20,98 @@ from service.service.service_handler_api.Tools import get_endpoint_matching
log = logging.getLogger(__name__)
#def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])->Dict[str: List[Tuple[str, str]]]:
# def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])->Dict:
# #entries = List[Tuple[str, str, str, Optional[str]]]
# #entries = Dict[str: List[Tuple[str, str]]]
# entries = {}
# #tuple is in, out
# #end = len(endpoints) if isinstance(endpoints,list) else 0
# end = len(endpoints)
# i = 0
# bidir = 0
# log.debug("end={}".format(end))
# while(i < end):
# 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] = []
# if i == 0:
# 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:
# bidir = 1
# log.info("connection is bidirectional")
# entry_tuple = next_endpoint_uuid, "0"
# entries[device_uuid].append(entry_tuple)
# i = i + 1
# else:
# log.debug("connection is unidirectional")
# else:
# if not bidir:
# if i == end-1:
# #is the last node
# entry_tuple = endpoint_uuid, "0"
# entries[device_uuid].append(entry_tuple)
# else:
# #it is a transit node
# 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 + 1
# log.info("current OCTools step {}, {}, {}".format(i, next_device_uuid, device_uuid))
# else:
# log.debug("ERROR in unidirectional connection 4")
# return {}
# else:
# log.debug("Ocheck i {}, {}, {}".format(i, i+1, end-1))
# if i + 1 == end-1:
# log.debug("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
# #is the last node
# entry_tuple = endpoint_uuid, "0"
# entries[device_uuid].append(entry_tuple)
# next_endpoint = endpoints[i+1]
# log.debug("OCTools i+1 step {}, {}, {}".format(i+1, next_device_uuid, device_uuid))
def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])->Dict:
#entries = List[Tuple[str, str, str, Optional[str]]]
#entries = Dict[str: List[Tuple[str, str]]]
entries = {}
#tuple is in, out
#end = len(endpoints) if isinstance(endpoints,list) else 0
end = len(endpoints)
i = 0
bidir = 0
log.debug("end={}".format(end))
while(i < end):
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] = []
if i == 0:
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:
bidir = 1
log.info("connection is bidirectional")
entry_tuple = next_endpoint_uuid, "0"
entries[device_uuid].append(entry_tuple)
i = i + 1
else:
log.debug("connection is unidirectional")
else:
if not bidir:
if i == end-1:
#is the last node
entry_tuple = endpoint_uuid, "0"
entries[device_uuid].append(entry_tuple)
else:
#it is a transit node
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 + 1
log.info("current OCTools step {}, {}, {}".format(i, next_device_uuid, device_uuid))
else:
log.debug("ERROR in unidirectional connection 4")
return {}
else:
log.debug("Ocheck i {}, {}, {}".format(i, i+1, end-1))
if i + 1 == end-1:
log.debug("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
#is the last node
entry_tuple = endpoint_uuid, "0"
entries[device_uuid].append(entry_tuple)
next_endpoint = endpoints[i+1]
log.debug("OCTools i+1 step {}, {}, {}".format(i+1, next_device_uuid, device_uuid))
# next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
# if next_device_uuid == device_uuid:
# entry_tuple = "0", next_endpoint_uuid
# entries[device_uuid].append(entry_tuple)
# i = i + 1
# else:
# log.debug("ERROR in bidirectional connection 2")
# return entries
# else:
# log.debug("OCTools i+1+2+3 step {}, {}, {}".format(i+1, next_device_uuid, 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 connection 3")
# log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
# return entries
# #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 + 3
# else:
# log.debug("ERROR in bidirection connection 4")
# return {}
# i = i + 1
# return entries
next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
if next_device_uuid == device_uuid:
entry_tuple = "0", next_endpoint_uuid
entries[device_uuid].append(entry_tuple)
i = i + 1
else:
log.debug("ERROR in bidirectional connection 2")
return entries
else:
log.debug("OCTools i+1+2+3 step {}, {}, {}".format(i+1, next_device_uuid, 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 connection 3")
log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
return entries
#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 + 3
else:
log.debug("ERROR in bidirection connection 4")
return {}
i = i + 1
return entries
......@@ -398,11 +396,17 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int):
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:
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:
......
......@@ -21,7 +21,9 @@ from service.service.service_handler_api.Tools import check_errors_setendpoint
from service.service.task_scheduler.TaskExecutor import TaskExecutor
from service.service.tools.EndpointIdFormatters import endpointids_to_raw
from service.service.tools.ObjectKeys import get_connection_key
from ._Task import _Task
import logging
if TYPE_CHECKING:
from service.service.service_handler_api._ServiceHandler import _ServiceHandler
......@@ -49,23 +51,36 @@ class Task_OpticalConnectionConfigure(_Task):
service = self._task_executor.get_service(connection.service_id)
service_handler_settings = {}
service_handlers : Dict[DeviceTypeEnum, Tuple['_ServiceHandler', Dict[str, Device]]] = \
self._task_executor.get_service_handlers(connection, service, **service_handler_settings)
service_handler=None
service_handlers = self._task_executor.get_service_handlers(connection, service, **service_handler_settings)
for _, (handler, connection_devices) in service_handlers.items():
logging.info(f"type_servicehandler {type(handler)}")
if service_handler is None : service_handler=handler
else :
if type(handler) != type(service_handler) :
raise Exception("Devices are not compatible ")
connection_uuid = connection.connection_id.connection_uuid.uuid
logging.info(f"connection-> uuid{connection_uuid}")
endpointids_to_set = endpointids_to_raw(connection.path_hops_endpoint_ids)
logging.info(f" _endpointids_to_set-> {endpointids_to_set}")
errors = list()
for _, (service_handler, connection_devices) in service_handlers.items():
_endpointids_to_set = [
(device_uuid, endpoint_uuid, topology_uuid)
for device_uuid, endpoint_uuid, topology_uuid in endpointids_to_set
if device_uuid in connection_devices
]
results_setendpoint = service_handler.SetEndpoint(
_endpointids_to_set, connection_uuid=connection_uuid
)
errors.extend(check_errors_setendpoint(endpointids_to_set, results_setendpoint))
connection_uuid = connection.connection_id.connection_uuid.uuid
results_setendpoint = service_handler.SetEndpoint(endpointids_to_set, connection_uuid=connection_uuid)
# for _, (service_handler, connection_devices) in service_handlers.items():
# logging.info(f" connection_devices-> {connection_devices}")
# _endpointids_to_set = [
# (device_uuid, endpoint_uuid, topology_uuid)
# for device_uuid, endpoint_uuid, topology_uuid in endpointids_to_set
# if device_uuid in connection_devices
# ]
# logging.info(f" results_endpointids_to_set-> {_endpointids_to_set}")
# results_setendpoint = service_handler.SetEndpoint(
# _endpointids_to_set, connection_uuid=connection_uuid
# )
errors.extend(check_errors_setendpoint(endpointids_to_set, results_setendpoint))
if len(errors) > 0:
MSG = 'SetEndpoint for Connection({:s}) from Service({:s})'
......@@ -76,7 +91,7 @@ class Task_OpticalConnectionConfigure(_Task):
self._task_executor.set_connection(connection)
results_setendOpticalConfigs = service_handler.SetOpticalConfig(
_endpointids_to_set, connection_uuid=connection_uuid
endpointids_to_set, connection_uuid=connection_uuid
)
errors.extend(check_errors_setendpoint(endpointids_to_set, results_setendOpticalConfigs))
......
......@@ -12,10 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import List, Optional, Tuple
from typing import List, Optional, Tuple
import logging
from common.proto.context_pb2 import EndPointId
def endpointids_to_raw(traversed_endpoint_ids : List[EndPointId]) -> List[Tuple[str, str, Optional[str]]]:
raw_endpoint_ids : List[Tuple[str, str, Optional[str]]] = []
for endpoint_id in traversed_endpoint_ids:
device_uuid = endpoint_id.device_id.device_uuid.uuid
......
......@@ -370,6 +370,8 @@ def adapt_reply(devices, service, reply_json, context_id, topology_id, optical_b
opt_reply.services.add().CopyFrom(service)
return opt_reply
def add_service_to_reply(reply : PathCompReply, service : Service) -> Service:
service_x = reply.services.add()
service_x.CopyFrom(service)
......
......@@ -25,7 +25,9 @@ docker rm na3
docker rm t2
docker rm na2
screen -dmS t1 -T xterm sh -c "docker run --name t1 -p 10.0.2.4:2023:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/oc23bgp.img:latest bash -c 'cp /files/transponders_x4.xml demoECOC21.xml ; ./startNetconfAgent.sh'"
screen -dmS t3 -T xterm sh -c "docker run --name na3 -p 10.0.2.4:2025:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/flexscale-node.img:latest bash -c 'cp /files/platform_r1.xml init_openconfig-platform.xml ; ./startNetconfAgent.sh'"
screen -dmS t2 -T xterm sh -c "docker run --name t2 -p 10.0.2.4:2024:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/oc23bgp.img:latest bash -c 'cp /files/transponders_x4_2.xml demoECOC21.xml ; ./startNetconfAgent.sh'"
screen -dmS t4 -T xterm sh -c "docker run --name na2 -p 10.0.2.4:2026:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/flexscale-node.img:latest bash -c 'cp /files/platform_r2.xml init_openconfig-platform.xml ; ./startNetconfAgent.sh'"
docker network create --subnet=192.168.100.0/24 my-custom-network
screen -dmS t1 -T xterm sh -c "docker run --name t1 --net my-custom-network -p 10.0.2.4:2023:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/oc23bgp.img:latest bash -c 'cp /files/transponders_x4.xml demoECOC21.xml ; ./startNetconfAgent.sh'"
screen -dmS t3 -T xterm sh -c "docker run --name na3 --net my-custom-network -p 10.0.2.4:2025:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/flexscale-node.img:latest bash -c 'cp /files/platform_r1.xml init_openconfig-platform.xml ; ./startNetconfAgent.sh'"
screen -dmS t2 -T xterm sh -c "docker run --name t2 --net my-custom-network -p 10.0.2.4:2024:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/oc23bgp.img:latest bash -c 'cp /files/transponders_x4_2.xml demoECOC21.xml ; ./startNetconfAgent.sh'"
screen -dmS t4 -T xterm sh -c "docker run --name na2 --net my-custom-network -p 10.0.2.4:2026:2022 -v /home/tfs/tfs-ctrl/src/tests/ofc24/tempOC/files:/files -it asgamb1/flexscale-node.img:latest bash -c 'cp /files/platform_r2.xml init_openconfig-platform.xml ; ./startNetconfAgent.sh'"
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