Loading proto/optical_device.proto 0 → 100644 +26 −0 Original line number Diff line number Diff line // 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. syntax = "proto3"; package optical_device; import "context.proto"; service OpenConfigService { rpc AddOpenConfigDevice (context.OpticalConfig) returns (context.OpticalConfigId) {} rpc ConfigureOpticalDevice(context.OpticalConfig) returns (context.Empty ) {} rpc DisableOpticalDevice(context.OpticalConfig) returns (context.Empty ) {} rpc GetDeviceConfiguration(context.OpticalConfigList) returns (context.Empty) {} } src/common/tools/object_factory/OpticalLink.py 0 → 100644 +75 −0 Original line number Diff line number Diff line def convert_to_dict (single_val:int)->dict: slot= dict() bin_num = bin(single_val) sliced_num=bin_num[2:] for i in range(len(sliced_num)): slot[str(i+1)]=int(sliced_num[i]) return slot def order_list (lst:list[tuple])->list: if (len(lst)<=1): return lst else : pivot,bit_val =lst[0] lst_smaller = [] lst_greater = [] for element in lst[1:]: key,val=element if (key <= pivot): lst_smaller.append(element) else : lst_greater.append(element) return order_list(lst_smaller) + [(pivot,bit_val)] + order_list(lst_greater) def list_to_dict (lst:list[tuple[int,int]])->dict: dct = dict() for ele in lst : key,value = ele dct[str(key)]=value return dct def order_dict (dct:dict)->dict: lst = list() for key,value in sorted(dct.items()): lst.append((int(key),value)) ordered_lst= order_list(lst) if (len(ordered_lst)>0): return list_to_dict (ordered_lst) def order_dict_v1 (dct:dict)->dict: lst = list() for key,value in dct.items(): lst.append((int(key),value)) ordered_lst= order_list(lst) if (len(ordered_lst)>0): return list_to_dict (ordered_lst) def correct_slot (dic:dict): ordered_dict= order_dict_v1(dic) keys_list = list(ordered_dict.keys()) if (len(keys_list) < 20): num_keys= [] for i in keys_list: num_keys.append(int(i)) if num_keys[-1] != 20 : missed_keys=[] diff= 20 - len(num_keys) print(f"diff {diff}") for i in range(diff+1): missed_keys.append(num_keys[-1]+i) print(f"missed_keys {missed_keys}") for key in missed_keys : ordered_dict[key]=1 print(f"result {ordered_dict}") return order_dict_v1(ordered_dict) No newline at end of file src/context/service/database/models/OpticalConfig/OpticalConfigModel.py 0 → 100644 +74 −0 Original line number Diff line number Diff line # 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 json , logging from sqlalchemy import Column, String, Integer , ForeignKey, Boolean from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship from context.service.database.models._Base import _Base from .RoadmModel import RoadmTypeModel class OpticalConfigModel(_Base): __tablename__ = 'optical_config' opticalconfig_uuid = Column(String, primary_key=True) channel_namespace = Column(String, nullable=True) endpoints = Column(ARRAY(String), nullable=True) type = Column(String,nullable=False) # transcievers = Column(ARRAY(String), nullable=True) # interfaces = Column(String, nullable=True) #channels = relationship("OpticalChannelModel") transponders = relationship("TransponderTypeModel") roadms = relationship("RoadmTypeModel") device_uuid = Column(ForeignKey("device.device_uuid",ondelete="CASCADE"),index=True ,nullable=False) device= relationship("DeviceModel", back_populates='optical_config') def dump_id (self ): return { "opticalconfig_uuid":self.opticalconfig_uuid, "device_uuid" :self.device_uuid } def dump(self): obj={ # "channels" : [channel.dump() for channel in self.channels], # "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, # "interfaces" : {"interface":json.loads(self.interfaces) if self.interfaces else ''}, "channel_namespace" : self.channel_namespace, "endpoints" : [json.loads(endpoint) for endpoint in self.endpoints if endpoint], "device_name" : self.device.device_name, "type" : self.type } if self.type =="optical-transponder" : channels= [transponer.dump() for transponer in self.transponders ][0] obj['channels']=channels['channels'] if 'channels' in channels else None obj['transceivers']=channels['transceivers'] if 'transceivers' in channels else None obj['interfaces']=channels['interfaces'] if 'interfaces' in channels else None obj['trasponder_uuid']=channels['trasponder_uuid'] if 'trasponder_uuid' in channels else None if self.type =="optical-roadm" : channels=[roadms.dump() for roadms in self.roadms ][0] obj['channels']=channels['channels'] if 'channels' in channels else None obj['roadm_uuid']=channels['roadm_uuid'] if 'roadm_uuid' in channels else None logging.info(f"optical_config_model {obj}") return obj src/context/service/database/models/OpticalConfig/RoadmModel.py 0 → 100644 +81 −0 Original line number Diff line number Diff line # 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 json , logging from sqlalchemy import Column, String, Integer , ForeignKey, Boolean from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship from context.service.database.models._Base import _Base class RoadmTypeModel (_Base): __tablename__ = 'roadm_type' roadm_uuid = Column(String, primary_key=True) channels = relationship("ChannelModel") circuits = Column (String,nullable=True) opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ),index=True ,nullable=False) opticalconfig = relationship('OpticalConfigModel', back_populates='roadms') def dump_id (self): return { "roadm_uuid":self.roadm_uuid } def dump (self): return { "channels" : [channel.dump() for channel in self.channels], "roadm_uuid" : self.dump_id() } class ChannelModel(_Base): __tablename__ = 'channel' channel_uuid = Column(String, primary_key=True) band_name = Column (String,nullable=True) lower_frequency = Column(Integer, nullable=True) upper_frequency = Column(Integer, nullable=True) channel_index = Column(String , nullable=True) status = Column(String , nullable=True) src_port = Column(String, nullable=True) dest_port = Column(String, nullable=True) type = Column(String, nullable=False) optical_band_parent = Column(String, nullable=True) roadm_uuid = Column(ForeignKey('roadm_type.roadm_uuid', ondelete='CASCADE' ),nullable=False) roadm = relationship('RoadmTypeModel',back_populates='channels') # opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ), primary_key=True) # opticalconfig = relationship('OpticalConfigModel', back_populates='channels') def dump_id (self ): return { "channel_uuid":self.channel_uuid } def dump(self): return { "band_name" :self.band_name, "lower_frequency" : self.lower_frequency, "upper_frequency" : self.upper_frequency, "type" : self.type, "src_port" : self.src_port, "dest_port" : self.dest_port, "status":self.status, "optical_band_parent":self.optical_band_parent, "channel_index":self.channel_index } src/context/service/database/models/OpticalConfig/TransponderModel.py 0 → 100644 +78 −0 Original line number Diff line number Diff line # 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 json , logging from sqlalchemy import Column, String, Integer , ForeignKey, Boolean from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship from context.service.database.models._Base import _Base class TransponderTypeModel (_Base): __tablename__ = 'transponder_type' transponder_uuid = Column(String, primary_key=True) transcievers = Column(ARRAY(String), nullable=True) interfaces = Column(String, nullable=True) channels = relationship("OpticalChannelModel") opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ),index=True ,nullable=False) opticalconfig = relationship('OpticalConfigModel', back_populates='transponders') def dump_id (self): return { "transponder_uuid":self.transponder_uuid } def dump (self): return { "channels" : [channel.dump() for channel in self.channels], "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, "interfaces" : {"interface":json.loads(self.interfaces) if self.interfaces else ''}, "trasponder_uuid" : self.dump_id() } class OpticalChannelModel(_Base): __tablename__ = 'optical_channel' channel_uuid = Column(String, primary_key=True) channel_name = Column (String,nullable=True) frequency = Column(Integer, nullable=True) operational_mode = Column(Integer, nullable=True) status = Column(String , nullable=True) target_output_power = Column(String, nullable=True) transponder_uuid = Column(ForeignKey('transponder_type.transponder_uuid', ondelete='CASCADE' ),nullable=False) transponder = relationship('TransponderTypeModel',back_populates='channels') # opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ), primary_key=True) # opticalconfig = relationship('OpticalConfigModel', back_populates='channels') def dump_id (self ): return { "channel_uuid":self.channel_uuid } def dump(self): return { "name" :{'index':self.channel_name}, "frequency" : self.frequency, "target-output-power" : self.target_output_power, "operational-mode" : self.operational_mode, "status":self.status } Loading
proto/optical_device.proto 0 → 100644 +26 −0 Original line number Diff line number Diff line // 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. syntax = "proto3"; package optical_device; import "context.proto"; service OpenConfigService { rpc AddOpenConfigDevice (context.OpticalConfig) returns (context.OpticalConfigId) {} rpc ConfigureOpticalDevice(context.OpticalConfig) returns (context.Empty ) {} rpc DisableOpticalDevice(context.OpticalConfig) returns (context.Empty ) {} rpc GetDeviceConfiguration(context.OpticalConfigList) returns (context.Empty) {} }
src/common/tools/object_factory/OpticalLink.py 0 → 100644 +75 −0 Original line number Diff line number Diff line def convert_to_dict (single_val:int)->dict: slot= dict() bin_num = bin(single_val) sliced_num=bin_num[2:] for i in range(len(sliced_num)): slot[str(i+1)]=int(sliced_num[i]) return slot def order_list (lst:list[tuple])->list: if (len(lst)<=1): return lst else : pivot,bit_val =lst[0] lst_smaller = [] lst_greater = [] for element in lst[1:]: key,val=element if (key <= pivot): lst_smaller.append(element) else : lst_greater.append(element) return order_list(lst_smaller) + [(pivot,bit_val)] + order_list(lst_greater) def list_to_dict (lst:list[tuple[int,int]])->dict: dct = dict() for ele in lst : key,value = ele dct[str(key)]=value return dct def order_dict (dct:dict)->dict: lst = list() for key,value in sorted(dct.items()): lst.append((int(key),value)) ordered_lst= order_list(lst) if (len(ordered_lst)>0): return list_to_dict (ordered_lst) def order_dict_v1 (dct:dict)->dict: lst = list() for key,value in dct.items(): lst.append((int(key),value)) ordered_lst= order_list(lst) if (len(ordered_lst)>0): return list_to_dict (ordered_lst) def correct_slot (dic:dict): ordered_dict= order_dict_v1(dic) keys_list = list(ordered_dict.keys()) if (len(keys_list) < 20): num_keys= [] for i in keys_list: num_keys.append(int(i)) if num_keys[-1] != 20 : missed_keys=[] diff= 20 - len(num_keys) print(f"diff {diff}") for i in range(diff+1): missed_keys.append(num_keys[-1]+i) print(f"missed_keys {missed_keys}") for key in missed_keys : ordered_dict[key]=1 print(f"result {ordered_dict}") return order_dict_v1(ordered_dict) No newline at end of file
src/context/service/database/models/OpticalConfig/OpticalConfigModel.py 0 → 100644 +74 −0 Original line number Diff line number Diff line # 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 json , logging from sqlalchemy import Column, String, Integer , ForeignKey, Boolean from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship from context.service.database.models._Base import _Base from .RoadmModel import RoadmTypeModel class OpticalConfigModel(_Base): __tablename__ = 'optical_config' opticalconfig_uuid = Column(String, primary_key=True) channel_namespace = Column(String, nullable=True) endpoints = Column(ARRAY(String), nullable=True) type = Column(String,nullable=False) # transcievers = Column(ARRAY(String), nullable=True) # interfaces = Column(String, nullable=True) #channels = relationship("OpticalChannelModel") transponders = relationship("TransponderTypeModel") roadms = relationship("RoadmTypeModel") device_uuid = Column(ForeignKey("device.device_uuid",ondelete="CASCADE"),index=True ,nullable=False) device= relationship("DeviceModel", back_populates='optical_config') def dump_id (self ): return { "opticalconfig_uuid":self.opticalconfig_uuid, "device_uuid" :self.device_uuid } def dump(self): obj={ # "channels" : [channel.dump() for channel in self.channels], # "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, # "interfaces" : {"interface":json.loads(self.interfaces) if self.interfaces else ''}, "channel_namespace" : self.channel_namespace, "endpoints" : [json.loads(endpoint) for endpoint in self.endpoints if endpoint], "device_name" : self.device.device_name, "type" : self.type } if self.type =="optical-transponder" : channels= [transponer.dump() for transponer in self.transponders ][0] obj['channels']=channels['channels'] if 'channels' in channels else None obj['transceivers']=channels['transceivers'] if 'transceivers' in channels else None obj['interfaces']=channels['interfaces'] if 'interfaces' in channels else None obj['trasponder_uuid']=channels['trasponder_uuid'] if 'trasponder_uuid' in channels else None if self.type =="optical-roadm" : channels=[roadms.dump() for roadms in self.roadms ][0] obj['channels']=channels['channels'] if 'channels' in channels else None obj['roadm_uuid']=channels['roadm_uuid'] if 'roadm_uuid' in channels else None logging.info(f"optical_config_model {obj}") return obj
src/context/service/database/models/OpticalConfig/RoadmModel.py 0 → 100644 +81 −0 Original line number Diff line number Diff line # 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 json , logging from sqlalchemy import Column, String, Integer , ForeignKey, Boolean from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship from context.service.database.models._Base import _Base class RoadmTypeModel (_Base): __tablename__ = 'roadm_type' roadm_uuid = Column(String, primary_key=True) channels = relationship("ChannelModel") circuits = Column (String,nullable=True) opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ),index=True ,nullable=False) opticalconfig = relationship('OpticalConfigModel', back_populates='roadms') def dump_id (self): return { "roadm_uuid":self.roadm_uuid } def dump (self): return { "channels" : [channel.dump() for channel in self.channels], "roadm_uuid" : self.dump_id() } class ChannelModel(_Base): __tablename__ = 'channel' channel_uuid = Column(String, primary_key=True) band_name = Column (String,nullable=True) lower_frequency = Column(Integer, nullable=True) upper_frequency = Column(Integer, nullable=True) channel_index = Column(String , nullable=True) status = Column(String , nullable=True) src_port = Column(String, nullable=True) dest_port = Column(String, nullable=True) type = Column(String, nullable=False) optical_band_parent = Column(String, nullable=True) roadm_uuid = Column(ForeignKey('roadm_type.roadm_uuid', ondelete='CASCADE' ),nullable=False) roadm = relationship('RoadmTypeModel',back_populates='channels') # opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ), primary_key=True) # opticalconfig = relationship('OpticalConfigModel', back_populates='channels') def dump_id (self ): return { "channel_uuid":self.channel_uuid } def dump(self): return { "band_name" :self.band_name, "lower_frequency" : self.lower_frequency, "upper_frequency" : self.upper_frequency, "type" : self.type, "src_port" : self.src_port, "dest_port" : self.dest_port, "status":self.status, "optical_band_parent":self.optical_band_parent, "channel_index":self.channel_index }
src/context/service/database/models/OpticalConfig/TransponderModel.py 0 → 100644 +78 −0 Original line number Diff line number Diff line # 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 json , logging from sqlalchemy import Column, String, Integer , ForeignKey, Boolean from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship from context.service.database.models._Base import _Base class TransponderTypeModel (_Base): __tablename__ = 'transponder_type' transponder_uuid = Column(String, primary_key=True) transcievers = Column(ARRAY(String), nullable=True) interfaces = Column(String, nullable=True) channels = relationship("OpticalChannelModel") opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ),index=True ,nullable=False) opticalconfig = relationship('OpticalConfigModel', back_populates='transponders') def dump_id (self): return { "transponder_uuid":self.transponder_uuid } def dump (self): return { "channels" : [channel.dump() for channel in self.channels], "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, "interfaces" : {"interface":json.loads(self.interfaces) if self.interfaces else ''}, "trasponder_uuid" : self.dump_id() } class OpticalChannelModel(_Base): __tablename__ = 'optical_channel' channel_uuid = Column(String, primary_key=True) channel_name = Column (String,nullable=True) frequency = Column(Integer, nullable=True) operational_mode = Column(Integer, nullable=True) status = Column(String , nullable=True) target_output_power = Column(String, nullable=True) transponder_uuid = Column(ForeignKey('transponder_type.transponder_uuid', ondelete='CASCADE' ),nullable=False) transponder = relationship('TransponderTypeModel',back_populates='channels') # opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ), primary_key=True) # opticalconfig = relationship('OpticalConfigModel', back_populates='channels') def dump_id (self ): return { "channel_uuid":self.channel_uuid } def dump(self): return { "name" :{'index':self.channel_name}, "frequency" : self.frequency, "target-output-power" : self.target_output_power, "operational-mode" : self.operational_mode, "status":self.status }