diff --git a/src/opticalcontroller/Dockerfile b/src/opticalcontroller/Dockerfile index 75245256c27bae0c24f7a9bebb51ae718c8be525..faea3b2e056768ef9947db108df61928c8a177cb 100644 --- a/src/opticalcontroller/Dockerfile +++ b/src/opticalcontroller/Dockerfile @@ -34,8 +34,7 @@ RUN python3 -m pip install --upgrade pip-tools # Get common Python packages # Note: this step enables sharing the previous Docker build steps among all the Python components -WORKDIR /var/teraflow/ - +WORKDIR /var/teraflow COPY common_requirements.in common_requirements.in RUN pip-compile --quiet --output-file=common_requirements.txt common_requirements.in RUN python3 -m pip install -r common_requirements.txt @@ -62,7 +61,7 @@ RUN pip-compile --quiet --output-file=requirements.txt requirements.in RUN python3 -m pip install -r requirements.txt # Add component files into working directory -WORKDIR /var/teraflow/ +WORKDIR /var/teraflow COPY src/context/__init__.py context/__init__.py COPY src/context/client/. context/client/ COPY src/opticalcontroller/. opticalcontroller/ diff --git a/src/opticalcontroller/README.md b/src/opticalcontroller/README.md index 5fd94c59e51cbd78dd76a7db0f24aaaec4ebd9db..f121055cec91470646b9885bfe90db137027f472 100644 --- a/src/opticalcontroller/README.md +++ b/src/opticalcontroller/README.md @@ -1,17 +1,20 @@ -# optical-controller -This a framework to implement the optical controller for the RMSA algorithm. +# Optical Controller + +This is a framework to test the optical controller for the RMSA algorithm in an isolated manner. + + + +```bash #create a venv python -m venv venv -in linux +# in linux source venv/Scripts/activate -in windows +# in windows venv\Scripts\activate -pip install -r requirements_opt.txt +pip install -r requirements_optical_ctrl_test.txt python OpticalController.py - - - +``` diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py index 0d8a62bbfc4349daa760d6dc24d7728aff5b254e..75f12a623cc2b8dc033a40e61aad0bd658a5949f 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -31,8 +31,7 @@ class RSA(): self.l_slot_number = 0 self.s_slot_number = 0 self.optical_bands = {} - - + def init_link_slots(self, testing): if full_links: for l in self.links_dict["optical_links"]: @@ -303,21 +302,14 @@ class RSA(): fib['used'] = False #fib[band].keys().sort() set_link_update(fib,link,test="restoration") - def restore_optical_band(self, optical_band_id, slots, band): - for i in slots: self.optical_bands[optical_band_id][band][str(i)] = 1 #self.optical_bands[optical_band_id][band].append(int(i)) #self.optical_bands[optical_band_id][band].sort() - - - - - def restore_optical_band_2(self, optical_band_id, slots, band ,links): print(f"example of band { band}") print(f"example of slots {slots}") @@ -329,8 +321,7 @@ class RSA(): #link_name= self.optical_bands[optical_band_id]['links'][0] #link = self.get_link_by_name(link_name) #update_optical_band(optical_bands=self.optical_bands,optical_band_id=optical_band_id,band=band,link=link) - - + def del_flow(self, flow,flow_id, o_b_id = None): flows = flow["flows"] band = flow["band_type"] @@ -344,7 +335,6 @@ class RSA(): bidir = flow["bidir"] flow_id = flow["flow_id"] - for l in links: if debug: print(l) @@ -356,11 +346,8 @@ class RSA(): self.restore_link(fib, slots, band) if debug: print(fib[band]) - - - + if o_b_id is not None: - if debug: print("restoring OB") print(f"invoking restore_optical_band o_b_id: {o_b_id} , slots {slots} , band {band} ") @@ -370,6 +357,7 @@ class RSA(): self.optical_bands[o_b_id]["served_lightpaths"].remove(flow_id) #self.restore_optical_band_2(o_b_id, slots, band,links) + if bidir: for l in links: r_l = reverse_link(l) @@ -405,9 +393,7 @@ class RSA(): def del_band(self, flow, o_b_id = None): - print(f"delete band {flow} ") - flows = flow["flows"] band = None @@ -482,8 +468,7 @@ class RSA(): # rev_o_band_id = self.optical_bands[o_b_id]["reverse_optical_band_id"] # self.restore_optical_band(rev_o_band_id, slots, band) return True - - + def del_handler(self, flow,flow_id, o_b_id = None,delete_band=0): print(f" del_handler flow {flow} flow_id {flow_id} o_b_id {o_b_id} delete_band {delete_band}") if delete_band != 0: @@ -491,9 +476,7 @@ class RSA(): self.del_band(flow,flow_id,o_b_id=o_b_id) else : self.del_flow(flow,flow_id=flow_id,o_b_id=o_b_id) - - - + def get_fibers_forward(self, links, slots, band): fiber_list = {} add = links[0] diff --git a/src/opticalcontroller/requirements.in b/src/opticalcontroller/requirements.in index bae2cf3336cc1bf4da132736a438507238d7bcc9..2e552cff84cc8cd31c6630e7e24d7da973d0ee43 100644 --- a/src/opticalcontroller/requirements.in +++ b/src/opticalcontroller/requirements.in @@ -1,4 +1,3 @@ - # Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/opticalcontroller/requirements_opt.txt b/src/opticalcontroller/requirements_opt.txt deleted file mode 100644 index e4b8abe1b410498f4030e0106842052b5a9734b1..0000000000000000000000000000000000000000 --- a/src/opticalcontroller/requirements_opt.txt +++ /dev/null @@ -1,7 +0,0 @@ -Flask==1.1.2 -flask-restplus==0.13.0 -itsdangerous==1.1.0 -Jinja2==2.11.3 -MarkupSafe==1.1.1 -numpy==1.23.0 -Werkzeug==0.16.1 diff --git a/src/opticalcontroller/requirements_optical_ctrl_test.txt b/src/opticalcontroller/requirements_optical_ctrl_test.txt new file mode 100644 index 0000000000000000000000000000000000000000..0b1947bee2c7f1e89491dff4f7589d3465d28c38 --- /dev/null +++ b/src/opticalcontroller/requirements_optical_ctrl_test.txt @@ -0,0 +1,21 @@ +# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (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. + +Flask==1.1.2 +flask-restplus==0.13.0 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==1.1.1 +numpy==1.23.0 +Werkzeug==0.16.1 diff --git a/src/opticalcontroller/test.py b/src/opticalcontroller/test.py deleted file mode 100644 index 255ee2de4faa8d15d41421c76b837705ea49f46d..0000000000000000000000000000000000000000 --- a/src/opticalcontroller/test.py +++ /dev/null @@ -1,12 +0,0 @@ -import json - - -def readTopologyData(): - topo_file = open("json_files/tfs_dict.json", 'r') - topo = json.load(topo_file) - # print(topo) - topo_file.close() - return topo - - -print(readTopologyData()) \ No newline at end of file diff --git a/src/opticalcontroller/tools.py b/src/opticalcontroller/tools.py index 40d180691a1f8a65536bfec649e99edc6b625aa5..08441f5c0010de1be503ee307410431ddfee54ab 100644 --- a/src/opticalcontroller/tools.py +++ b/src/opticalcontroller/tools.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json import numpy as np from variables import * -import json , logging -from context.client.ContextClient import ContextClient from common.proto.context_pb2 import TopologyId , LinkId , OpticalLink , OpticalLinkDetails from common.tools.object_factory.OpticalLink import correct_slot +from context.client.ContextClient import ContextClient def common_slots(a, b): @@ -190,16 +190,14 @@ def frequency_converter(b, slots): def readTopologyData(nodes, topology): - - - nodes_file = open(nodes, 'r') - topo_file = open(topology, 'r') - nodes = json.load(nodes_file) - topo = json.load(topo_file) - #print(topo) - nodes_file.close() - topo_file.close() - return nodes, topo + nodes_file = open(nodes, 'r') + topo_file = open(topology, 'r') + nodes = json.load(nodes_file) + topo = json.load(topo_file) + #print(topo) + nodes_file.close() + topo_file.close() + return nodes, topo def readTopologyDataFromContext(topology_id:TopologyId): @@ -325,6 +323,3 @@ def set_link_update (fib:dict,link:dict,test="updating"): ctx_client.SetOpticalLink(optical_link) except Exception as err: print (f"setOpticalLink {err}") - - - diff --git a/src/opticalcontroller/variables.py b/src/opticalcontroller/variables.py index 90b746d1f0a61c860d91e64c23a3be65b0c2ca41..781b4b1f8fc395511529aecd7385351aa532fcbc 100644 --- a/src/opticalcontroller/variables.py +++ b/src/opticalcontroller/variables.py @@ -31,4 +31,3 @@ topology_json = 'json_files/tfs_dict_modified.json' #LAST testing = 1 full_links = 0 - diff --git a/src/service/service/service_handler_api/SettingsHandler.py b/src/service/service/service_handler_api/SettingsHandler.py index 8bd546eda51b2da443cb070f585909be4b9e9caf..24c5b638a35859b144969425d36ddad63a39d611 100644 --- a/src/service/service/service_handler_api/SettingsHandler.py +++ b/src/service/service/service_handler_api/SettingsHandler.py @@ -13,7 +13,6 @@ # limitations under the License. import anytree, json, logging - from typing import Any, List, Optional, Tuple, Union from common.proto.context_pb2 import ConfigActionEnum, ConfigRule, Device, EndPoint, ServiceConfig from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string diff --git a/src/service/service/service_handlers/qkd/qkd_service_handler.py b/src/service/service/service_handlers/qkd/qkd_service_handler.py index bf874e4849e20edd694dea256be2676356b4fc80..2bfbcb59dd045d10b9267dc15119e1d17e1929d4 100644 --- a/src/service/service/service_handlers/qkd/qkd_service_handler.py +++ b/src/service/service/service_handlers/qkd/qkd_service_handler.py @@ -56,7 +56,7 @@ class QKDServiceHandler(_ServiceHandler): chk_type('endpoints', endpoints, list) if len(endpoints) < 2 or len(endpoints) % 2: return [] - + LOGGER.info('Endpoints: ' + str(endpoints)) service_uuid = self.__service.service_id.service_uuid.uuid