From 9bf7940266c0d22bf486fcb5bc8f021c32f5c191 Mon Sep 17 00:00:00 2001 From: sgambelluri <andrea.sgambelluri@cnit.it> Date: Tue, 5 Mar 2024 14:20:19 +0000 Subject: [PATCH] First Round Cleaning For Merge --- manifests/opticalcontrollerservice.yaml | 4 +- .../startExtraNetConfigAgent.sh | 0 start_topo.sh => ofc24/start_topo.sh | 0 proto/context.proto | 24 +- proto/openconfig_device.proto | 4 +- scripts/show_logs_opticalcontroller.sh | 2 +- src/context/client/ContextClient.py | 24 +- .../service/ContextServiceServicerImpl.py | 28 +- src/context/service/database/ConfigModel.py | 2 +- .../{MyConfigOperator.py => OpticalConfig.py} | 52 +- ...MyConfigModel.py => OpticalConfigModel.py} | 6 +- src/device/client/DeviceClient.py | 4 +- .../service/DeviceServiceServicerImpl.py | 2 +- src/device/service/OpenConfigServicer.py | 8 +- src/device/service/Tools.py | 46 +- .../service/drivers/oc_driver/OCDriver.py | 14 +- .../templates/Interfaces/interfaces.py | 2 +- .../oc_driver/templates/VPN/physical.py | 2 +- src/opticalcontroller/OpticalController.py | 14 + src/opticalcontroller/RSA.py | 47 - .../json_files/tfs copy.json | 1286 ----------------- src/opticalcontroller/tools.py | 16 + src/opticalcontroller/variables.py | 16 + src/service/service/__main__.py | 10 +- .../service_handlers/oc/OCServiceHandler.py | 105 +- .../service/task_scheduler/TaskExecutor.py | 46 +- 26 files changed, 180 insertions(+), 1584 deletions(-) rename startExtraNetConfigAgent.sh => ofc24/startExtraNetConfigAgent.sh (100%) rename start_topo.sh => ofc24/start_topo.sh (100%) rename src/context/service/database/{MyConfigOperator.py => OpticalConfig.py} (71%) rename src/context/service/database/models/{MyConfigModel.py => OpticalConfigModel.py} (93%) delete mode 100644 src/opticalcontroller/json_files/tfs copy.json diff --git a/manifests/opticalcontrollerservice.yaml b/manifests/opticalcontrollerservice.yaml index ba1edcc56..db760c23e 100644 --- a/manifests/opticalcontrollerservice.yaml +++ b/manifests/opticalcontrollerservice.yaml @@ -9,9 +9,7 @@ spec: replicas: 1 template: metadata: - annotations: - # Required for IETF L2VPN SBI when both parent and child run in same K8s cluster with Linkerd - config.linkerd.io/skip-outbound-ports: "8022" + labels: app: opticalcontrollerservice spec: diff --git a/startExtraNetConfigAgent.sh b/ofc24/startExtraNetConfigAgent.sh similarity index 100% rename from startExtraNetConfigAgent.sh rename to ofc24/startExtraNetConfigAgent.sh diff --git a/start_topo.sh b/ofc24/start_topo.sh similarity index 100% rename from start_topo.sh rename to ofc24/start_topo.sh diff --git a/proto/context.proto b/proto/context.proto index e96181693..73c478865 100644 --- a/proto/context.proto +++ b/proto/context.proto @@ -77,9 +77,9 @@ service ContextService { // ------------------------------ Experimental------------------------------ - rpc GetMyConfig (Empty ) returns ( MyConfigList ) {} - rpc SetMyConfig (MyConfig) returns (MyConfigId) {} - rpc SelectMyConfig (MyConfigId) returns (MyConfig) {} + rpc GetOpticalConfig (Empty ) returns ( OpticalConfigList ) {} + rpc SetOpticalConfig (OpticalConfig) returns (OpticalConfigId) {} + rpc SelectOpticalConfig (OpticalConfigId) returns (OpticalConfig) {} rpc SetOpticalLink (OpticalLink) returns (Empty) {} rpc GetOpticalLink (OpticalLinkId) returns (OpticalLink) {} @@ -211,9 +211,11 @@ enum DeviceDriverEnum { DEVICEDRIVER_XR = 6; DEVICEDRIVER_IETF_L2VPN = 7; DEVICEDRIVER_GNMI_OPENCONFIG = 8; - DEVICEDRIVER_OC = 11; - DEVICEDRIVER_FLEXSCALE=10; DEVICEDRIVER_IETF_ACTN=9; + DEVICEDRIVER_FLEXSCALE=10; + DEVICEDRIVER_OC = 11; + + } enum DeviceOperationalStatusEnum { @@ -626,15 +628,15 @@ message AuthenticationResult { } // ---------------- Experimental ------------------------ -message MyConfigId { - string myconfig_uuid= 1; +message OpticalConfigId { + string opticalconfig_uuid= 1; } -message MyConfig { - MyConfigId myconfig_id=1; +message OpticalConfig { + OpticalConfigId opticalconfig_id=1; string config =2 ; } -message MyConfigList { - repeated MyConfig MyConfigs =1 ; +message OpticalConfigList { + repeated OpticalConfig opticalconfigs =1 ; } //----Optical Link ---- message OpticalLinkId { diff --git a/proto/openconfig_device.proto b/proto/openconfig_device.proto index d00e46645..8a0a97df2 100644 --- a/proto/openconfig_device.proto +++ b/proto/openconfig_device.proto @@ -19,8 +19,8 @@ import "context.proto"; import "monitoring.proto"; service OpenConfigService { - rpc AddOpenConfigDevice (context.MyConfig ) returns (context.MyConfigId ) {} + rpc AddOpenConfigDevice (context.OpticalConfig ) returns (context.OpticalConfigId ) {} - rpc ConfigureOpticalDevice (context.MyConfig) returns (context.Empty) {} + rpc ConfigureOpticalDevice (context.OpticalConfig) returns (context.Empty) {} } diff --git a/scripts/show_logs_opticalcontroller.sh b/scripts/show_logs_opticalcontroller.sh index e32ea7ef9..a4778c308 100755 --- a/scripts/show_logs_opticalcontroller.sh +++ b/scripts/show_logs_opticalcontroller.sh @@ -24,4 +24,4 @@ export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-"tfs"} # Automated steps start here ######################################################################################################################## -kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/opticalcontrollerservice -c server > logs/opticalcontroller.log && vi logs/opticalcontroller.log +kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/opticalcontrollerservice -c server > logs/opticalcontroller.log diff --git a/src/context/client/ContextClient.py b/src/context/client/ContextClient.py index a1a6bcb08..96a2f3f8d 100644 --- a/src/context/client/ContextClient.py +++ b/src/context/client/ContextClient.py @@ -27,7 +27,7 @@ from common.proto.context_pb2 import ( Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList, - MyConfig,MyConfigId,MyConfigList) + OpticalConfig,OpticalConfigId,OpticalConfigList) from common.proto.context_pb2_grpc import ContextServiceStub from common.proto.context_policy_pb2_grpc import ContextPolicyServiceStub from common.proto.policy_pb2 import PolicyRuleIdList, PolicyRuleId, PolicyRuleList, PolicyRule @@ -439,22 +439,22 @@ class ContextClient: return response #//////////////// Experimental ////////////////// @RETRY_DECORATOR - def SetMyConfig (self,request:MyConfig) ->MyConfigId: - LOGGER.debug('SettingMyConfig request: {:s}'.format(grpc_message_to_json_string(request))) - response = self.stub.SetMyConfig(request) - LOGGER.debug('SettingMyconfig result: {:s}'.format(grpc_message_to_json_string(response))) + def SetOpticalConfig (self,request:OpticalConfig) ->OpticalConfigId: + LOGGER.debug('SettingOpticalConfig request: {:s}'.format(grpc_message_to_json_string(request))) + response = self.stub.SetOpticalConfig(request) + LOGGER.debug('SettingOpticalConfig result: {:s}'.format(grpc_message_to_json_string(response))) return response @RETRY_DECORATOR - def GetMyConfig (self,request:Empty) ->MyConfigList: - LOGGER.debug('GettingMyConfig request: {:s}'.format(grpc_message_to_json_string(request))) - response = self.stub.GetMyConfig(request) - LOGGER.debug('GetMyConfig result: {:s}'.format(grpc_message_to_json_string(response))) + def GetOpticalConfig (self,request:Empty) ->OpticalConfigList: + LOGGER.debug('GettingOpticalConfig request: {:s}'.format(grpc_message_to_json_string(request))) + response = self.stub.GetOpticalConfig(request) + LOGGER.debug('GetOpticalConfig result: {:s}'.format(grpc_message_to_json_string(response))) return response @RETRY_DECORATOR - def SelectMyConfig (self,request:MyConfigId) ->MyConfigList: + def SelectOpticalConfig (self,request:OpticalConfigId) ->OpticalConfigList: LOGGER.debug('Selecting request: {:s}'.format(grpc_message_to_json_string(request))) - response = self.stub.SelectMyConfig(request) - LOGGER.debug('GetMyConfig result: {:s}'.format(grpc_message_to_json_string(response))) + response = self.stub.SelectOpticalConfig(request) + LOGGER.debug('GetOpticalConfig result: {:s}'.format(grpc_message_to_json_string(response))) return response diff --git a/src/context/service/ContextServiceServicerImpl.py b/src/context/service/ContextServiceServicerImpl.py index f4d2cc307..8b5a3f7bc 100644 --- a/src/context/service/ContextServiceServicerImpl.py +++ b/src/context/service/ContextServiceServicerImpl.py @@ -24,7 +24,7 @@ from common.proto.context_pb2 import ( Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList, - MyConfigList,MyConfigId,MyConfig) + OpticalConfigList,OpticalConfigId,OpticalConfig) from common.proto.policy_pb2 import PolicyRuleIdList, PolicyRuleId, PolicyRuleList, PolicyRule from common.proto.context_pb2_grpc import ContextServiceServicer from common.proto.context_policy_pb2_grpc import ContextPolicyServiceServicer @@ -44,7 +44,7 @@ from .database.Slice import ( slice_delete, slice_get, slice_list_ids, slice_list_objs, slice_select, slice_set, slice_unset) from .database.Topology import ( topology_delete, topology_get, topology_get_details, topology_list_ids, topology_list_objs, topology_set) -from .database.MyConfigOperator import (set_myconfig,select_MyConfig,get_myconfig) +from .database.OpticalConfigOperator import (set_OpticalConfig,select_OpticalConfig,get_OpticalConfig) LOGGER = logging.getLogger(__name__) @@ -300,19 +300,19 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer return policyrule_delete(self.db_engine, self.messagebroker, request) # ---------------------------- Experimental ------------------- @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) - def GetMyConfig(self,request:Empty,context:grpc.ServicerContext) -> MyConfigList: + def GetOpticalConfig(self,request:Empty,context:grpc.ServicerContext) -> OpticalConfigList: - result =get_myconfig(db_engine=self.db_engine) + result =get_OpticalConfig(db_engine=self.db_engine) - return MyConfigList(MyConfigs=result) - def SetMyConfig(self,request:MyConfig,context:grpc.ServicerContext)-> MyConfigId: + return OpticalConfigList(OpticalConfigs=result) + def SetOpticalConfig(self,request:OpticalConfig,context:grpc.ServicerContext)-> OpticalConfigId: - myconfig_id= set_myconfig(db_engine=self.db_engine,request=request) + OpticalConfig_id= set_OpticalConfig(db_engine=self.db_engine,request=request) - return MyConfigId(**myconfig_id) - def SelectMyConfig (self,request:MyConfigId,context:grpc.ServicerContext) -> MyConfig: - result =select_MyConfig(db_engine=self.db_engine,request=request) - logging.info(f"FromSelectMyConfig {result}") - myid =MyConfigId() - myid.CopyFrom(result.myconfig_id) - return MyConfig(config=result.config,myconfig_id=myid) + return OpticalConfigId(**OpticalConfig_id) + def SelectOpticalConfig (self,request:OpticalConfigId,context:grpc.ServicerContext) -> OpticalConfig: + result =select_OpticalConfig(db_engine=self.db_engine,request=request) + logging.info(f"FromSelectOpticalConfig {result}") + myid =OpticalConfigId() + myid.CopyFrom(result.OpticalConfig_id) + return OpticalConfig(config=result.config,OpticalConfig_id=myid) diff --git a/src/context/service/database/ConfigModel.py b/src/context/service/database/ConfigModel.py index 234e155f0..94519dcec 100644 --- a/src/context/service/database/ConfigModel.py +++ b/src/context/service/database/ConfigModel.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +# Todo check if the file is in use by the TFS import functools, logging, operator from enum import Enum from typing import Dict, List, Optional, Tuple, Union diff --git a/src/context/service/database/MyConfigOperator.py b/src/context/service/database/OpticalConfig.py similarity index 71% rename from src/context/service/database/MyConfigOperator.py rename to src/context/service/database/OpticalConfig.py index 0ca58f6ca..33227a016 100644 --- a/src/context/service/database/MyConfigOperator.py +++ b/src/context/service/database/OpticalConfig.py @@ -20,7 +20,7 @@ from sqlalchemy.orm import Session, selectinload, sessionmaker from sqlalchemy_cockroachdb import run_transaction from typing import Dict, List, Optional, Set, Tuple from common.method_wrappers.ServiceExceptions import InvalidArgumentException, NotFoundException -from common.proto.context_pb2 import Device, DeviceFilter, DeviceId, TopologyId,MyConfig,MyConfigId,MyConfigList +from common.proto.context_pb2 import Device, DeviceFilter, DeviceId, TopologyId,OpticalConfig,OpticalConfigId,OpticalConfigList from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.Device import json_device_id from context.service.database.uuids.Topology import topology_get_uuid @@ -33,24 +33,24 @@ from .models.enums.KpiSampleType import grpc_to_enum__kpi_sample_type from .uuids.Device import device_get_uuid from .uuids.EndPoint import endpoint_get_uuid from .ConfigRule import compose_config_rules_data, upsert_config_rules -from .models.MyConfigModel import MyConfigModel +from .models.OpticalConfigModel import OpticalConfigModel LOGGER = logging.getLogger(__name__) -def get_myconfig (db_engine:Engine): +def get_opticalconfig (db_engine:Engine): def callback(session:Session): lst = list() - results = session.query(MyConfigModel).all() + results = session.query(OpticalConfigModel).all() for obj in results: - myconfig=MyConfig() - myconfig.config=json.dump(obj.config) - myid=MyConfigId() - myid.myconfig_uuid=obj.myconfig_uuid - myconfig.myconfig_id.CopyFrom(myid) + OpticalConfig=OpticalConfig() + OpticalConfig.config=json.dump(obj.config) + myid=OpticalConfigId() + myid.opticalconfig_uuid=obj.opticalconfig_uuid + OpticalConfig.opticalconfig_id.CopyFrom(myid) - lst.append(myconfig) + lst.append(OpticalConfig) return lst obj=run_transaction(sessionmaker(bind=db_engine),callback) return obj @@ -58,10 +58,10 @@ def get_myconfig (db_engine:Engine): -def set_myconfig (db_engine:Engine,request:MyConfig): +def set_opticalconfig (db_engine:Engine,request:OpticalConfig): - myconfig_id=MyConfigId() - myconfig_id.myconfig_uuid=request.myconfig_id.myconfig_uuid + opticalconfig_id=OpticalConfigId() + opticalconfig_id.opticalconfig_uuid=request.opticalconfig_id.opticalconfig_uuid my_config_data=[] if (request.config): channels=[] @@ -76,7 +76,7 @@ def set_myconfig (db_engine:Engine,request:MyConfig): my_config_data=[ { - "myconfig_uuid":request.myconfig_id.myconfig_uuid, + "opticalconfig_uuid":request.opticalconfig_id.opticalconfig_uuid, "channels":channels, "transcievers":transceivers, "interfaces":json.dumps(config["interfaces"]["interface"]), @@ -90,38 +90,38 @@ def set_myconfig (db_engine:Engine,request:MyConfig): def callback(session:Session)->bool: - stmt = insert(MyConfigModel).values(my_config_data) + stmt = insert(OpticalConfigModel).values(my_config_data) stmt = stmt.on_conflict_do_update( - index_elements=[MyConfigModel.myconfig_uuid], + index_elements=[OpticalConfigModel.opticalconfig_uuid], set_=dict( channel_namespace=stmt.excluded.channel_namespace ) ) - stmt = stmt.returning(MyConfigModel.myconfig_uuid) + stmt = stmt.returning(OpticalConfigModel.opticalconfig_uuid) id = session.execute(stmt).fetchone() - myconfig_id =run_transaction(sessionmaker(bind=db_engine),callback) + opticalconfig_id =run_transaction(sessionmaker(bind=db_engine),callback) - return {'myconfig_uuid': myconfig_id} + return {'opticalconfig_uuid': opticalconfig_id} -def select_MyConfig(db_engine:Engine,request:MyConfigId): +def select_opticalconfig(db_engine:Engine,request:OpticalConfigId): - def callback(session : Session) -> MyConfig: - result=MyConfig() - obj = session.query(MyConfigModel).filter_by(myconfig_uuid=request.myconfig_uuid).first() + def callback(session : Session) -> OpticalConfig: + result=OpticalConfig() + obj = session.query(OpticalConfigModel).filter_by(opticalconfig_uuid=request.opticalconfig_uuid).first() if (obj is not None): - myid=MyConfigId() - myid.myconfig_uuid=obj.myconfig_uuid + myid=OpticalConfigId() + myid.opticalconfig_uuid=obj.opticalconfig_uuid result.config=json.dumps(obj.dump()) - result.myconfig_id.CopyFrom(myid) + result.opticalconfig_id.CopyFrom(myid) return result diff --git a/src/context/service/database/models/MyConfigModel.py b/src/context/service/database/models/OpticalConfigModel.py similarity index 93% rename from src/context/service/database/models/MyConfigModel.py rename to src/context/service/database/models/OpticalConfigModel.py index 960f7368b..34a8c41f0 100644 --- a/src/context/service/database/models/MyConfigModel.py +++ b/src/context/service/database/models/OpticalConfigModel.py @@ -22,9 +22,9 @@ from ._Base import _Base -class MyConfigModel (_Base): - __tablename__="MyConfig" - myconfig_uuid = Column(String, primary_key=True) +class OpticalConfigModel (_Base): + __tablename__="OpticalConfig" + opticalconfig_uuid = Column(String, primary_key=True) channels=Column(ARRAY(String),nullable=True) transcievers= Column(ARRAY(String),nullable=True) interfaces =Column(String,nullable=True) diff --git a/src/device/client/DeviceClient.py b/src/device/client/DeviceClient.py index 9b4880c04..3fde3df77 100644 --- a/src/device/client/DeviceClient.py +++ b/src/device/client/DeviceClient.py @@ -15,7 +15,7 @@ import grpc, logging from common.Constants import ServiceNameEnum from common.Settings import get_service_host, get_service_port_grpc -from common.proto.context_pb2 import Device, DeviceConfig, DeviceId, Empty,MyConfig,MyConfigId +from common.proto.context_pb2 import Device, DeviceConfig, DeviceId, Empty,OpticalConfig,OpticalConfigId from common.proto.device_pb2 import MonitoringSettings from common.proto.device_pb2_grpc import DeviceServiceStub from common.tools.client.RetryDecorator import retry, delay_exponential @@ -82,7 +82,7 @@ class DeviceClient: response = self.stub.MonitorDeviceKpi(request) LOGGER.debug('MonitorDeviceKpi result: {:s}'.format(grpc_message_to_json_string(response))) return response - def ConfigureOpticalDevice(self, request : MyConfig) -> MyConfigId: + def ConfigureOpticalDevice(self, request : OpticalConfig) -> OpticalConfigId: LOGGER.debug('ConfigureOpticalDevice request: {:s}'.format(grpc_message_to_json_string(request))) response = self.openconfig_stub.ConfigureOpticalDevice(request) LOGGER.debug('ConfigureOpticalDevice result: {:s}'.format(grpc_message_to_json_string(response))) diff --git a/src/device/service/DeviceServiceServicerImpl.py b/src/device/service/DeviceServiceServicerImpl.py index da5d1134e..6abb06dd0 100644 --- a/src/device/service/DeviceServiceServicerImpl.py +++ b/src/device/service/DeviceServiceServicerImpl.py @@ -20,7 +20,7 @@ from common.Settings import ENVVAR_SUFIX_SERVICE_HOST, get_env_var_name from common.method_wrappers.Decorator import MetricTypeEnum, MetricsPool, safe_and_metered_rpc_method from common.method_wrappers.ServiceExceptions import NotFoundException, OperationFailedException from common.proto.context_pb2 import ( - Device, DeviceConfig, DeviceDriverEnum, DeviceId, DeviceOperationalStatusEnum, Empty, Link,MyConfig,MyConfigId) + Device, DeviceConfig, DeviceDriverEnum, DeviceId, DeviceOperationalStatusEnum, Empty, Link,OpticalConfig,OpticalConfigId) from common.proto.device_pb2 import MonitoringSettings from common.proto.device_pb2_grpc import DeviceServiceServicer from common.tools.context_queries.Device import get_device diff --git a/src/device/service/OpenConfigServicer.py b/src/device/service/OpenConfigServicer.py index 329bceef2..fc4e75e67 100644 --- a/src/device/service/OpenConfigServicer.py +++ b/src/device/service/OpenConfigServicer.py @@ -20,7 +20,7 @@ from common.Settings import ENVVAR_SUFIX_SERVICE_HOST, get_env_var_name from common.method_wrappers.Decorator import MetricTypeEnum, MetricsPool, safe_and_metered_rpc_method from common.method_wrappers.ServiceExceptions import NotFoundException, OperationFailedException from common.proto.context_pb2 import ( - Device, DeviceConfig, DeviceDriverEnum, DeviceId, DeviceOperationalStatusEnum, Empty, Link,MyConfig,MyConfigId ,MyConfig,MyConfigList) + Device, DeviceConfig, DeviceDriverEnum, DeviceId, DeviceOperationalStatusEnum, Empty, Link,OpticalConfig,OpticalConfigId ,OpticalConfig,OpticalConfigList) from common.proto.device_pb2 import MonitoringSettings from common.proto.device_pb2_grpc import DeviceServiceServicer from common.tools.context_queries.Device import get_device @@ -54,7 +54,7 @@ class OpenConfigServicer(DeviceServiceServicer): LOGGER.debug('Servicer Created') @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) - def AddOpenConfigDevice(self, request : MyConfig, context : grpc.ServicerContext) -> DeviceId: + def AddOpenConfigDevice(self, request : OpticalConfig, context : grpc.ServicerContext) -> DeviceId: device_uuid = request.device_id.device_uuid.uuid @@ -94,9 +94,9 @@ class OpenConfigServicer(DeviceServiceServicer): #modified Andrea @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) - def ConfigureOpticalDevice (self, request : MyConfig, context:grpc.ServicerContext) -> Empty: + def ConfigureOpticalDevice (self, request : OpticalConfig, context:grpc.ServicerContext) -> Empty: - device_uuid = request.myconfig_id.myconfig_uuid + device_uuid = request.opticalconfig_id.opticalconfig_uuid resources=[] result=None diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py index c4b41020a..04fb54be5 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -468,14 +468,26 @@ def get_edit_target (device:Device,is_opticalband:bool)-> str: else : if device.device_type =='optical-roadm': return 'media-channel' else : return 'optical-channel' - + +def is_key_existed( key:str ,keys_dic=dict,key_name_to_use= None | str ) -> dict: + dic={} + dic["resource_key"]=key + if key_name_to_use is not None: + dic["resource_key"]=key_name_to_use + if key in keys_dic : + dic["value"]=keys_dic[key] + else : + dic["value"]=None + return dic + def extract_resources (config:dict,device:Device)-> list : conditions={} resources=[] - resources.append({"resource_key":"channel_namespace","value":config["channel_namespace"] if "channel_namespace" in config else None}) - resources.append({"resource_key":'add_transceiver',"value":config['add_transceiver'] if 'add_transceiver' in config else None}) - resources.append({"resource_key":"interface","value":config["update_interface"] if 'update_interface' in config else None}) - is_opticalband=config['is_opticalband'] if 'is_opticalband' in config else False + resources.append(is_key_existed("channel_namespace",config)) + resources.append(is_key_existed("add_transceiver",config)) + is_opticalband=False + if ( 'is_opticalband' in config): + is_opticalband=config['is_opticalband'] conditions["is_opticalband"]=is_opticalband conditions["edit_type"]=get_edit_target(device=device,is_opticalband=is_opticalband) if ('flow' in config): @@ -501,16 +513,13 @@ def extract_resources (config:dict,device:Device)-> list : if ('new_config' in config): lower_frequency=None upper_frequency=None - resources.append({"resource_key":"target-output-power","value":config["new_config"]["target-output-power"] if "target-output-power" in config["new_config"] else None }) - #resources.append({"resource_key":"frequency","value":config["new_config"]["frequency"] if "frequency" in config else config["new_config"]["freqency"]}) - resources.append({"resource_key":"frequency","value":config["new_config"]["frequency"] if "frequency" in config["new_config"] else None}) - resources.append({"resource_key":"operational-mode","value":config["new_config"]["operational-mode"] if "operational-mode" in config["new_config"] else None}) - resources.append({"resource_key":"line-port","value":config["new_config"]["line-port"] if "line-port" in config["new_config"] else None}) - - resources.append({"resource_key":"name","value":config['new_config']['band_type'] if 'band_type' in config['new_config'] else None}) - resources.append({"resource_key":"optical-band-parent","value":config["new_config"]["ob_id"] if "ob_id" in config["new_config"] else None }) - resources.append({"resource_key":"channel_name","value":config["new_config"]["name"] if "name" in config["new_config"] else None}) - + resources.append(is_key_existed(key="target-output-power",keys_dic=config["new_config"])) + resources.append(is_key_existed(key="frequency",keys_dic=config["new_config"])) + resources.append(is_key_existed(key="operational-mode",keys_dic=config["new_config"])) + resources.append(is_key_existed(key="line-port",keys_dic=config["new_config"])) + resources.append(is_key_existed(key="band_type",keys_dic=config["new_config"],key_name_to_use='name')) + resources.append(is_key_existed("ob_id",config["new_config"],key_name_to_use='optical-band-parent')) + resources.append(is_key_existed(key="name",keys_dic=config["new_config"],key_name_to_use="channel_name")) if not is_opticalband : if 'frequency' in config['new_config'] and 'band' in config['new_config'] and conditions["edit_type"] == 'media-channel': lower_frequency= int(int(config['new_config']['frequency']) - (int(config['new_config']['band'])/2)) @@ -518,11 +527,14 @@ def extract_resources (config:dict,device:Device)-> list : #lower_frequency= (config['new_config']['frequency']- config['new_config']['band'])/2 #upper_frequency=(config['new_config']['frequency']+ config['new_config']['band'])/2 - resources.append({"resource_key":"index","value":config["new_config"]["flow_id"] if "flow_id" in config["new_config"] else None}) + + resources.append(is_key_existed(key="flow_id",keys_dic=config["new_config"],key_name_to_use="index")) + #resources.append({"resource_key":"index","value":config["new_config"]["flow_id"] if "flow_id" in config["new_config"] else None}) else : lower_frequency=config['new_config']['low-freq'] if "low-freq" in config['new_config'] else None upper_frequency=config['new_config']['up-freq'] if 'up-freq' in config['new_config'] else None - resources.append({"resource_key":"index","value":config["new_config"]["ob_id"] if "ob_id" in config["new_config"] else None}) + resources.append(is_key_existed(key="ob_id",keys_dic=config["new_config"],key_name_to_use="index")) + #resources.append({"resource_key":"index","value":config["new_config"]["ob_id"] if "ob_id" in config["new_config"] else None}) resources.append({"resource_key":"lower-frequency","value":lower_frequency}) resources.append({"resource_key":"upper-frequency","value":upper_frequency}) diff --git a/src/device/service/drivers/oc_driver/OCDriver.py b/src/device/service/drivers/oc_driver/OCDriver.py index 8467a8ceb..16f00cfb4 100644 --- a/src/device/service/drivers/oc_driver/OCDriver.py +++ b/src/device/service/drivers/oc_driver/OCDriver.py @@ -1,4 +1,4 @@ -# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -35,9 +35,9 @@ from .templates.VPN.physical import create_optical_channel,add_transceiver,crea from .RetryDecorator import retry from context.client.ContextClient import ContextClient from common.proto.context_pb2 import ( - MyConfig, + OpticalConfig, ConfigActionEnum, Device, DeviceDriverEnum, DeviceId, DeviceList, DeviceOperationalStatusEnum, Empty - ,MyConfigId,Uuid) + ,OpticalConfigId,Uuid) from .templates.Tools import extractor from .Tools import generate_uuid_from_numbers DEBUG_MODE = False @@ -242,7 +242,7 @@ class OCDriver(_Driver): chk_type('resources', resource_keys, list) results = [] - myConfig= MyConfig() + opticalConfig= OpticalConfig() j=0 with self.__lock: @@ -274,9 +274,9 @@ class OCDriver(_Driver): value_dic["channel_namespace"]=channel_namespace value_dic["endpoints"]=endpoints - myConfig.config=json.dumps(value_dic) - myConfig.myconfig_id.myconfig_uuid=self.__device_uuid if self.__device_uuid is not None else "" - config_id=context_client.SetMyConfig(myConfig) + opticalConfig.config=json.dumps(value_dic) + opticalConfig.opticalconfig_id.opticalconfig_uuid=self.__device_uuid if self.__device_uuid is not None else "" + config_id=context_client.SetOpticalConfig(opticalConfig) context_client.close() diff --git a/src/device/service/drivers/oc_driver/templates/Interfaces/interfaces.py b/src/device/service/drivers/oc_driver/templates/Interfaces/interfaces.py index 8d3049cfe..b4df7c2bf 100644 --- a/src/device/service/drivers/oc_driver/templates/Interfaces/interfaces.py +++ b/src/device/service/drivers/oc_driver/templates/Interfaces/interfaces.py @@ -1,4 +1,4 @@ -# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/device/service/drivers/oc_driver/templates/VPN/physical.py b/src/device/service/drivers/oc_driver/templates/VPN/physical.py index def67a9a8..355858d2d 100644 --- a/src/device/service/drivers/oc_driver/templates/VPN/physical.py +++ b/src/device/service/drivers/oc_driver/templates/VPN/physical.py @@ -1,4 +1,4 @@ -# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py index ceaa97ecf..e1b8c7aeb 100644 --- a/src/opticalcontroller/OpticalController.py +++ b/src/opticalcontroller/OpticalController.py @@ -1,3 +1,17 @@ +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from flask import Flask from flask import render_template from flask_restplus import Resource, Api diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py index 919e5dfcf..138b5399c 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -1,20 +1,3 @@ -<<<<<<< HEAD -======= -# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - ->>>>>>> e19583176d771a8f8c1216d8a79488d0e50097c1 import dijsktra from tools import * from variables import * @@ -325,21 +308,14 @@ class RSA(): return fiber_list def get_link_by_name (self, key): -<<<<<<< HEAD result = None -======= ->>>>>>> e19583176d771a8f8c1216d8a79488d0e50097c1 for link in self.links_dict["links"]: if link["optical_link"]["name"] == key: if debug: print(link) -<<<<<<< HEAD result = link break return result -======= - return link ->>>>>>> e19583176d771a8f8c1216d8a79488d0e50097c1 def get_fiber_details(self, link_key, fiber_id): for link in self.links_dict["links"]: @@ -800,7 +776,6 @@ class RSA(): return self.flow_id, [] optical_band_id, temp_links = self.create_optical_band(links, path, bidir, num_slots_ob) return None, optical_band_id -<<<<<<< HEAD self.flow_id += 1 self.db_flows[self.flow_id] = {} self.db_flows[self.flow_id]["flow_id"] = self.flow_id @@ -808,8 +783,6 @@ class RSA(): self.db_flows[self.flow_id]["dst"] = dst self.db_flows[self.flow_id]["bitrate"] = rate self.db_flows[self.flow_id]["bidir"] = bidir -======= ->>>>>>> e19583176d771a8f8c1216d8a79488d0e50097c1 print("INFO: TP to TP connection") if band is None: temp_links2 = [] @@ -829,17 +802,7 @@ class RSA(): temp_path.append(roadm_dst) temp_path.append(t_dst) existing_ob = self.get_optical_bands(roadm_src, roadm_dst) -<<<<<<< HEAD -======= - self.flow_id += 1 - self.db_flows[self.flow_id] = {} - self.db_flows[self.flow_id]["flow_id"] = self.flow_id - self.db_flows[self.flow_id]["src"] = src - self.db_flows[self.flow_id]["dst"] = dst - self.db_flows[self.flow_id]["bitrate"] = rate - self.db_flows[self.flow_id]["bidir"] = bidir ->>>>>>> e19583176d771a8f8c1216d8a79488d0e50097c1 if len(existing_ob) > 0: print("INFO: Evaluating existing OB {}".format(existing_ob)) @@ -902,7 +865,6 @@ class RSA(): links, path = self.compute_path(src, dst) optical_band_id, temp_links = self.create_optical_band(links, path, bidir, num_slots_ob) op, num_slots = map_rate_to_slot(rate) -<<<<<<< HEAD # self.flow_id += 1 # self.db_flows[self.flow_id] = {} # self.db_flows[self.flow_id]["flow_id"] = self.flow_id @@ -910,15 +872,6 @@ class RSA(): # self.db_flows[self.flow_id]["dst"] = dst # self.db_flows[self.flow_id]["bitrate"] = rate # self.db_flows[self.flow_id]["bidir"] = bidir -======= - self.flow_id += 1 - self.db_flows[self.flow_id] = {} - self.db_flows[self.flow_id]["flow_id"] = self.flow_id - self.db_flows[self.flow_id]["src"] = src - self.db_flows[self.flow_id]["dst"] = dst - self.db_flows[self.flow_id]["bitrate"] = rate - self.db_flows[self.flow_id]["bidir"] = bidir ->>>>>>> e19583176d771a8f8c1216d8a79488d0e50097c1 if debug: print(temp_links) diff --git a/src/opticalcontroller/json_files/tfs copy.json b/src/opticalcontroller/json_files/tfs copy.json deleted file mode 100644 index a108ed13e..000000000 --- a/src/opticalcontroller/json_files/tfs copy.json +++ /dev/null @@ -1,1286 +0,0 @@ -{ - "links": [ - { - "link_id": { - "link_uuid": { - "uuid": "T1->R1" - } - }, - "link_endpoint_ids": [ - { - "device_id": { - "device_uuid": { - "uuid": "T1" - } - }, - "endpoint_uuid": { - "uuid": "1" - } - }, - { - "device_id": { - "device_uuid": { - "uuid": "R1" - } - }, - "endpoint_uuid": { - "uuid": "12" - } - } - ], - "optical_link": { - "name": "T1-R1", - "details": { - "length": 0, - "source": "muxT", - "target": "srgR", - "fibers": [ - { - "ID": "M1", - "length": 0, - "src_port": "1", - "dst_port": "2001", - "local_peer_port": "1", - "remote_peer_port": "1001", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - }, - { - "ID": "M2", - "length": 0, - "src_port": "2", - "dst_port": "2002", - "local_peer_port": "2", - "remote_peer_port": "1002", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - }, - { - "ID": "M3", - "length": 0, - "src_port": "3", - "dst_port": "2003", - "local_peer_port": "3", - "remote_peer_port": "1003", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - } - ] - } - } - }, - { - "link_id": { - "link_uuid": { - "uuid": "R1->T1" - } - }, - "link_endpoint_ids": [ - { - "device_id": { - "device_uuid": { - "uuid": "R1" - } - }, - "endpoint_uuid": { - "uuid": "2" - } - }, - { - "device_id": { - "device_uuid": { - "uuid": "T1" - } - }, - "endpoint_uuid": { - "uuid": "1" - } - } - ], - "optical_link": { - "name": "R1-T1", - "details": { - "length": 0, - "source": "srgT", - "target": "muxT", - "fibers": [ - { - "ID": "M1", - "length": 0, - "src_port": "1001", - "dst_port": "1", - "local_peer_port": "2001", - "remote_peer_port": "1", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - }, - { - "ID": "M2", - "length": 0, - "src_port": "1002", - "dst_port": "2", - "local_peer_port": "2002", - "remote_peer_port": "2", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - }, - { - "ID": "M3", - "length": 0, - "src_port": "1003", - "dst_port": "3", - "local_peer_port": "2003", - "remote_peer_port": "3", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - } - ] - } - } - }, - { - "link_id": { - "link_uuid": { - "uuid": "R1->R2" - } - }, - "link_endpoint_ids": [ - { - "device_id": { - "device_uuid": { - "uuid": "R1" - } - }, - "endpoint_uuid": { - "uuid": "13" - } - }, - { - "device_id": { - "device_uuid": { - "uuid": "R2" - } - }, - "endpoint_uuid": { - "uuid": "24" - } - } - ], - "optical_link": { - "name": "R1-R2", - "details": { - "length": 0, - "source": "D1", - "target": "D1", - "fibers": [ - { - "ID": "D11", - "length": 0, - "src_port": "13", - "dst_port": "24", - "local_peer_port": "23", - "remote_peer_port": "14", - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - } - ] - } - } - }, - { - "link_id": { - "link_uuid": { - "uuid": "R2->R1" - } - }, - "link_endpoint_ids": [ - { - "device_id": { - "device_uuid": { - "uuid": "R2" - } - }, - "endpoint_uuid": { - "uuid": "14" - } - }, - { - "device_id": { - "device_uuid": { - "uuid": "R1" - } - }, - "endpoint_uuid": { - "uuid": "23" - } - } - ], - "optical_link": { - "name": "R2-R1", - "details": { - "length": 0, - "source": "D1", - "target": "D1", - "fibers": [ - { - "ID": "D11", - "length": 0, - "src_port": "14", - "dst_port": "23", - "local_peer_port": "24", - "remote_peer_port": "13", - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - } - ] - } - } - }, - { - "link_id": { - "link_uuid": { - "uuid": "T2->R2" - } - }, - "link_endpoint_ids": [ - { - "device_id": { - "device_uuid": { - "uuid": "T2" - } - }, - "endpoint_uuid": { - "uuid": "1" - } - }, - { - "device_id": { - "device_uuid": { - "uuid": "R2" - } - }, - "endpoint_uuid": { - "uuid": "1001" - } - } - ], - "optical_link": { - "name": "T2-R2", - "details": { - "length": 0, - "source": "srgT", - "target": "muxT", - "fibers": [ - { - "ID": "M1", - "length": 0, - "src_port": "1", - "dst_port": "1001", - "local_peer_port": "1", - "remote_peer_port": "2001", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - }, - { - "ID": "M2", - "length": 0, - "src_port": "2", - "dst_port": "1002", - "local_peer_port": "2", - "remote_peer_port": "2002", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - }, - { - "ID": "M3", - "length": 0, - "src_port": "3", - "dst_port": "1003", - "local_peer_port": "3", - "remote_peer_port": "2003", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - } - ] - } - } - }, - { - "link_id": { - "link_uuid": { - "uuid": "R2->T2" - } - }, - "link_endpoint_ids": [ - { - "device_id": { - "device_uuid": { - "uuid": "R2" - } - }, - "endpoint_uuid": { - "uuid": "5" - } - }, - { - "device_id": { - "device_uuid": { - "uuid": "T2" - } - }, - "endpoint_uuid": { - "uuid": "6" - } - } - ], - "optical_link": { - "name": "R2-T2", - "details": { - "length": 0, - "source": "srgT", - "target": "muxT", - "fibers": [ - { - "ID": "M1", - "length": 0, - "src_port": "1001", - "dst_port": "1", - "local_peer_port": "2001", - "remote_peer_port": "1", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - }, - { - "ID": "M2", - "length": 0, - "src_port": "1002", - "dst_port": "2", - "local_peer_port": "2002", - "remote_peer_port": "2", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - }, - { - "ID": "M3", - "length": 0, - "src_port": "1003", - "dst_port": "3", - "local_peer_port": "2003", - "remote_peer_port": "3", - "used": false, - "c_slots": [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], - "l_slots": [ - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120 - ], - "s_slots": [ - 501, - 502, - 503, - 504, - 505, - 506, - 507, - 508, - 509, - 510, - 511, - 512, - 513, - 514, - 515, - 516, - 517, - 518, - 519, - 520 - ] - } - ] - } - } - } - ] -} \ No newline at end of file diff --git a/src/opticalcontroller/tools.py b/src/opticalcontroller/tools.py index d91240d45..fc349b499 100644 --- a/src/opticalcontroller/tools.py +++ b/src/opticalcontroller/tools.py @@ -1,3 +1,19 @@ + +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + import numpy as np from variables import * import json diff --git a/src/opticalcontroller/variables.py b/src/opticalcontroller/variables.py index 32fe4bd8d..88e8ce513 100644 --- a/src/opticalcontroller/variables.py +++ b/src/opticalcontroller/variables.py @@ -1,3 +1,19 @@ + +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + debug = 1 Fl = 184800 diff --git a/src/service/service/__main__.py b/src/service/service/__main__.py index 52210c8ab..31dbbdbe6 100644 --- a/src/service/service/__main__.py +++ b/src/service/service/__main__.py @@ -48,10 +48,12 @@ def main(): ]) - variables= find_environment_variables([ - get_env_var_name(ServiceNameEnum.OPTICALCONTROLLER,ENVVAR_SUFIX_SERVICE_HOST), - get_env_var_name(ServiceNameEnum.OPTICALCONTROLLER,ENVVAR_SUFIX_SERVICE_PORT_GRPC), - ]) + + #Commented for merging with develop branch + # variables= find_environment_variables([ + # get_env_var_name(ServiceNameEnum.OPTICALCONTROLLER,ENVVAR_SUFIX_SERVICE_HOST), + # get_env_var_name(ServiceNameEnum.OPTICALCONTROLLER,ENVVAR_SUFIX_SERVICE_PORT_GRPC), + # ]) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) diff --git a/src/service/service/service_handlers/oc/OCServiceHandler.py b/src/service/service/service_handlers/oc/OCServiceHandler.py index b2b0a86ee..87a9a0075 100644 --- a/src/service/service/service_handlers/oc/OCServiceHandler.py +++ b/src/service/service/service_handlers/oc/OCServiceHandler.py @@ -41,70 +41,6 @@ class OCServiceHandler(_ServiceHandler): - ''' - @metered_subclass_method(METRICS_POOL) - def SetEndpoint( - self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None - ) -> List[Union[bool, Exception]]: - - chk_type('endpoints', endpoints, list) - if len(endpoints) == 0: return [] - - service_uuid = self.__service.service_id.service_uuid.uuid - if self.__settings_handler.get('/settings-ob_{}'.format(connection_uuid)): - settings = self.__settings_handler.get('/settings-ob_{}'.format(connection_uuid)) - else: - settings = self.__settings_handler.get('/settings') - LOGGER.info("AAAAAAAAAAAAAAAAAAAA settings={}".format(settings)) - - settings = self.__settings_handler.get('/settings') - #new structure - #in, dev, out, topo(opt) - entries = List[Tuple[str, str, str Optional[str]]] - entry_tuple = device_uuid, endpoint_uuid, topology_uuid - entries.append(endpoint_id_tuple) - for i in range (1, len(endpoints)): - endpoint_x = endpoints[i] - dev_x = endpoint_x[0] - if_x = endpoint_x[1] - - - - - - results = [] - for endpoint in endpoints: - try: - device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) - - device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) - endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) - endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) - endpoint_name = endpoint_obj.name - - json_config_rules = setup_config_rules( - service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name, - settings, endpoint_settings) - LOGGER.info("Start configuring device %s",settings) - if (settings): - self.__task_executor.configure_optical_device(device_obj,settings) - if len(json_config_rules) > 0: - LOGGER.info("Start configuring device") - del device_obj.device_config.config_rules[:] - for json_config_rule in json_config_rules: - device_obj.device_config.config_rules.append(ConfigRule(**json_config_rule)) - self.__task_executor.configure_optical_device(device_obj) - #self.__task_executor.configure_device(device_obj) - - results.append(True) - except Exception as e: # pylint: disable=broad-except - LOGGER.exception('Unable to SetEndpoint({:s})'.format(str(endpoint))) - results.append(e) - - return results - ''' - - @metered_subclass_method(METRICS_POOL) def SetEndpoint( self, endpoints : List[Tuple[str, str, Optional[str]]], connection_uuid : Optional[str] = None @@ -138,12 +74,7 @@ class OCServiceHandler(_ServiceHandler): dev_flows = flows[device_uuid] device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) - ''' - #to be imported in the device handler - endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) - endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) - endpoint_name = endpoint_obj.name - ''' + if (settings): self.__task_executor.configure_optical_device(device_obj, settings, dev_flows, is_opticalband) @@ -151,39 +82,7 @@ class OCServiceHandler(_ServiceHandler): except Exception as e: # pylint: disable=broad-except LOGGER.exception('Unable to configure Device({:s})'.format(str(device_uuid))) results.append(e) - - ''' - for endpoint in endpoints: - try: - device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) - - device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid))) - endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid) - endpoint_settings = self.__settings_handler.get_endpoint_settings(device_obj, endpoint_obj) - endpoint_name = endpoint_obj.name - - # json_config_rules = setup_config_rules( - # service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name, - # settings, endpoint_settings) - - if (settings): - LOGGER.debug("Andrea234 settings={}".format(settings)) - self.__task_executor.configure_optical_device(device_obj,settings,handled_flows,is_opticalband) - #we don't use config_rules - # if len(json_config_rules) > 0: - # LOGGER.debug("VBNMHGStart configuring device") - # del device_obj.device_config.config_rules[:] - # for json_config_rule in json_config_rules: - # device_obj.device_config.config_rules.append(ConfigRule(**json_config_rule)) - # self.__task_executor.configure_optical_device(device_obj) - #self.__task_executor.configure_device(device_obj) - - results.append(True) - except Exception as e: # pylint: disable=broad-except - LOGGER.exception('Unable to SetEndpoint({:s})'.format(str(endpoint))) - results.append(e) - ''' - + return results @metered_subclass_method(METRICS_POOL) diff --git a/src/service/service/task_scheduler/TaskExecutor.py b/src/service/service/task_scheduler/TaskExecutor.py index 48449e4d9..487c61efe 100644 --- a/src/service/service/task_scheduler/TaskExecutor.py +++ b/src/service/service/task_scheduler/TaskExecutor.py @@ -16,7 +16,7 @@ import logging , json from enum import Enum from typing import TYPE_CHECKING, Any, Dict, Optional, Union from common.method_wrappers.ServiceExceptions import NotFoundException -from common.proto.context_pb2 import Connection, ConnectionId, Device, DeviceDriverEnum, DeviceId, Service, ServiceId,MyConfig,MyConfigId +from common.proto.context_pb2 import Connection, ConnectionId, Device, DeviceDriverEnum, DeviceId, Service, ServiceId,OpticalConfig,OpticalConfigId from common.tools.context_queries.Connection import get_connection_by_id from common.tools.context_queries.Device import get_device from common.tools.context_queries.Service import get_service_by_id @@ -108,7 +108,7 @@ class TaskExecutor: return device def configure_device(self, device : Device) -> None: - self._context_client.SelectMyConfig() + self._context_client.SelectOpticalConfig() device_key = get_device_key(device.device_id) self._device_client.ConfigureDevice(device) self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device) @@ -118,15 +118,15 @@ class TaskExecutor: device_key = get_device_key(device.device_id) - myid=MyConfigId() - myid.myconfig_uuid=device.device_id.device_uuid.uuid - myConfig=MyConfig() + myid=OpticalConfigId() + myid.opticalconfig_uuid=device.device_id.device_uuid.uuid + opticalconfig=OpticalConfig() setting =settings.value if settings else "" new_config={} try: - result=self._context_client.SelectMyConfig(myid) + result=self._context_client.SelectOpticalConfig(myid) new_config=json.loads(result.config) @@ -136,45 +136,15 @@ class TaskExecutor: new_config["is_opticalband"]=is_opticalband new_config["flow"]=flows result.config = str(new_config) - myConfig.CopyFrom(result) + opticalconfig.CopyFrom(result) - self._device_client.ConfigureOpticalDevice(myConfig) + self._device_client.ConfigureOpticalDevice(opticalconfig) self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device) except Exception as e: LOGGER.info("error in config my config %s",e) - ''' - # For Optical Devices - def configure_optical_device (self,device:Device,settings:str,flows:dict,is_opticalband:bool) : - - - device_key = get_device_key(device.device_id) - myid=MyConfigId() - myid.myconfig_uuid=device.device_id.device_uuid.uuid - myConfig=MyConfig() - setting =settings.value if settings else "" - - new_config={} - try: - result=self._context_client.SelectMyConfig(myid) - new_config=eval(result.config) - - if result is not None : - - new_config["new_config"]=setting - new_config["is_opticalband"]=is_opticalband - new_config["flow"]=flows - result.config = str(new_config) - myConfig.CopyFrom(result) - - self._device_client.ConfigureOpticalDevice(myConfig) - - self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device) - except Exception as e: - LOGGER.debug("error in config my config %s",e) - ''' def get_device_controller(self, device : Device) -> Optional[Device]: -- GitLab