diff --git a/scripts/dockerhub_k8s_secret.sh b/scripts/dockerhub_k8s_secret.sh old mode 100644 new mode 100755 diff --git a/scripts/dockerhub_login.sh b/scripts/dockerhub_login.sh old mode 100644 new mode 100755 diff --git a/scripts/run_tests_locally-device-gnmi-nokia-srlinux-delete.sh b/scripts/run_tests_locally-device-gnmi-nokia-srlinux-delete.sh old mode 100644 new mode 100755 diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py index ca3d8e318be3b0ed171a90659044b1f0cf8ae4ca..da65ad81cf007dff3840ea33edc130c28e165bbd 100644 --- a/src/opticalcontroller/OpticalController.py +++ b/src/opticalcontroller/OpticalController.py @@ -30,6 +30,15 @@ global links_dict rsa = None +logging.basicConfig(level=logging.DEBUG) + +LOGGER = logging.getLogger(__name__) +LOGGER.setLevel(logging.DEBUG) + +def print(*args) -> None: + LOGGER.info(' '.join([str(a) for a in args])) + + app = Flask(__name__) api = Api(app, version='1.0', title='Optical controller API', description='Rest API to configure OC Optical devices in TFS') @@ -338,7 +347,8 @@ class GetFlows(Resource): print(rsa.db_flows) return rsa.db_flows, 200 except: - return "Error", 404 + LOGGER.exception('Error while getting lightpaths') + return 'Error', 404 @optical.route('/GetOpticalBands') @optical.response(200, 'Success') @@ -351,7 +361,8 @@ class GetBands(Resource): print(rsa.optical_bands) return rsa.optical_bands, 200 except: - return "Error", 404 + LOGGER.exception('Error while getting optical bands') + return 'Error', 404 @optical.route('/GetOpticalBand/') @@ -406,7 +417,8 @@ class GetFlows(Resource): print(links) return links, 200 except: - return "Error", 404 + LOGGER.exception('Error while getting links') + return 'Error', 404 @optical.route('/GetTopology//',methods=['GET']) @@ -424,20 +436,24 @@ class GetTopology(Resource): topog_id = TopologyId() topog_id.topology_uuid.uuid=topology_id topog_id.context_id.context_uuid.uuid=context_id - - try: + + try: links_dict={"optical_links":[]} node_dict = {} topo , nodes = readTopologyDataFromContext(topog_id) OPTICAL_ROADM_TYPES = { - DeviceTypeEnum.OPTICAL_ROADM.value, DeviceTypeEnum.EMULATED_OPTICAL_ROADM.value + DeviceTypeEnum.OPTICAL_ROADM.value, + DeviceTypeEnum.EMULATED_OPTICAL_ROADM.value, } OPTICAL_OPENROADM_TYPES = { - DeviceTypeEnum.OPEN_ROADM.value, DeviceTypeEnum.EMULATED_OPEN_ROADM.value + DeviceTypeEnum.OPEN_ROADM.value, + DeviceTypeEnum.EMULATED_OPEN_ROADM.value, } OPTICAL_TRANSPONDER_TYPES = { - DeviceTypeEnum.OPTICAL_TRANSPONDER.value, DeviceTypeEnum.EMULATED_OPTICAL_TRANSPONDER.value + DeviceTypeEnum.OPTICAL_TRANSPONDER.value, + DeviceTypeEnum.EMULATED_OPTICAL_TRANSPONDER.value, + DeviceTypeEnum.NETWORK.value, } added_device_uuids = set() for device in nodes: @@ -462,7 +478,7 @@ class GetTopology(Resource): #i+=1 #print(f"refresh_optical controller optical_links_dict= {links_dict}") #print(f"refresh_optical controller node_dict {node_dict}") - + for link in topo: endpoint_id_a = link.link_endpoint_ids[ 0] endpoint_id_z = link.link_endpoint_ids[-1] @@ -490,12 +506,11 @@ class GetTopology(Resource): if debug: print(f'rsa.init_link_slots2() {rsa}') print(rsa.init_link_slots2()) - - - return "ok" ,200 - except Exception as e: - print(f"err {e}") - return "Error", 400 - -if __name__ == '__main__': + return 'OK', 200 + except Exception: + LOGGER.exception('Error while processing topology data') + #print(f'err {e}') + return 'Error', 400 + +if __name__ == '__main__': app.run(host='0.0.0.0', port=10060, debug=True) diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py index 9a48a9e34f404d083367b11650d3b3f253d03e11..d9c73a1d323f66b15ec9e7f03ddeebfb5a768cb5 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -13,12 +13,12 @@ # limitations under the License. import logging +from typing import Dict, Tuple from opticalcontroller.dijkstra import * from opticalcontroller.tools import * from opticalcontroller.variables import * -logging.basicConfig(level=logging.DEBUG) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @@ -31,17 +31,18 @@ class RSA(): self.nodes_dict = nodes self.links_dict = links self.g = None + self.node_key__to__node_name : Dict[str, Dict] = dict() + self.link_key__to__src_dst_node_names : Dict[str, Tuple[str, str]] = dict() self.flow_id = 0 self.opt_band_id = 0 self.db_flows = {} - self.initGraph2() + self.init_graph() self.c_slot_number = 0 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"]: @@ -97,45 +98,53 @@ class RSA(): break return "{},{},{}".format(self.c_slot_number, self.l_slot_number, self.s_slot_number) - def initGraph(self): + def init_graph(self): + self.node_key__to__node_name.clear() + self.link_key__to__src_dst_node_names.clear() self.g = Graph() - for n in self.nodes_dict: - self.g.add_vertex(n) - for l in self.links_dict["optical_links"]: - #if debug: - # print(l) - [s, d] = l["optical_link"]["name"].split('-') - ps = l["optical_link"]["details"]["source"] - pd = l["optical_link"]["details"]["target"] - self.g.add_edge(s, d, ps, pd, 1) - print("INFO: Graph initiated.") - if debug: - self.g.printGraph() + for node_name, node_data in self.nodes_dict.items(): + MSG = '[RSA:init_graph] processing node: name={:s}, data={:s}' + LOGGER.debug(MSG.format(str(node_name), str(node_data))) - def initGraph2(self): - - self.g = Graph() - - for n in self.nodes_dict: - self.g.add_vertex(n) - for l in self.links_dict["optical_links"]: - #if debug: - # print(l) - [s, d] = l["name"].split('-') - ps = l["optical_details"]["src_port"] - pd = l["optical_details"]["dst_port"] - self.g.add_edge(s, d, ps, pd, 1) + node_id = node_data['id'] + self.node_key__to__node_name[node_id] = node_name + self.node_key__to__node_name[node_name] = node_name + self.g.add_vertex(node_name) - print("INFO: Graph initiated.2") - if debug: - self.g.printGraph() + for link in self.links_dict['optical_links']: + MSG = '[RSA:init_graph] processing link: {:s}' + LOGGER.debug(MSG.format(str(link))) + + src_ep_id = link['link_endpoint_ids'][ 0] + src_node_uuid = src_ep_id['device_id']['device_uuid']['uuid'] + src_node_name = self.node_key__to__node_name[src_node_uuid] + + dst_ep_id = link['link_endpoint_ids'][-1] + dst_node_uuid = dst_ep_id['device_id']['device_uuid']['uuid'] + dst_node_name = self.node_key__to__node_name[dst_node_uuid] + + src_port = link['optical_details']['src_port'] + dst_port = link['optical_details']['dst_port'] + + link_name = '{:s}-{:s}'.format(src_node_name, dst_node_name) + self.link_key__to__src_dst_node_names[link_name] = (src_node_name, dst_node_name) + link['name'] = link_name + + self.g.add_edge(src_node_name, dst_node_name, src_port, dst_port, 1) + + LOGGER.info('[RSA:init_graph] Graph initiated') + self.g.printGraph() def compute_path(self, src, dst): path = shortest_path(self.g, self.g.get_vertex(src), self.g.get_vertex(dst)) - print("INFO: Path from {} to {} with distance: {}".format(src, dst, self.g.get_vertex(dst).get_distance())) - if debug: - print(f"compute_path shortest_path {path}") + + MSG = '[RSA:compute_path] Path from {:s} to {:s} with distance {:f}' + LOGGER.info(MSG.format(src, dst, float(self.g.get_vertex(dst).get_distance()))) + + MSG = '[RSA:compute_path] Path: {:s}' + LOGGER.debug(MSG.format(str(path))) + links = [] for i in range(0, len(path) - 1): s = path[i] @@ -155,10 +164,18 @@ class RSA(): def compute_disjoint_path(self, src, dst, path1=None): if path1 is None: path1 = shortest_path(self.g, self.g.get_vertex(src), self.g.get_vertex(dst)) - path = disjoint_path(self.g, src, dst, path1, False) - print("INFO: Path from {} to {} with distance: {}".format(src, dst, self.g.get_vertex(dst).get_distance())) - if debug: - print(path) + + MSG = '[RSA:compute_disjoint_path] Path1: {:s}' + LOGGER.info(MSG.format(str(path1))) + + path = disjoint_path(self.g, src, dst, path1, False) + + MSG = '[RSA:compute_disjoint_path] Path from {:s} to {:s} with distance {:f}' + LOGGER.info(MSG.format(src, dst, float(self.g.get_vertex(dst).get_distance()))) + + MSG = '[RSA:compute_disjoint_path] Path: {:s}' + LOGGER.debug(MSG.format(str(path))) + links = [] for i in range(0, len(path) - 1): s = path[i] @@ -195,13 +212,13 @@ class RSA(): s_slots = {} add = "" drop = "" - src_1, dst_1 = links[0].split('-') - src_2, dst_2 = links[-1].split('-') + src_1, dst_1 = self.link_key__to__src_dst_node_names[links[ 0]] + src_2, dst_2 = self.link_key__to__src_dst_node_names[links[-1]] if self.nodes_dict[src_1]["type"] == "OC-TP": add = links[0] if self.nodes_dict[dst_2]["type"] == "OC-TP": drop = links[-1] - found = 0 + for l in links: c_slots[l] = [] l_slots[l] = [] @@ -318,7 +335,7 @@ class RSA(): print(f"fib updated {fib}") #print(fib) - def update_link_2(self, fib, slots, band,link): + def update_link_2(self, fib, slots, band, link): #print(fib) for i in slots: fib[band][str(i)] = 0 @@ -411,9 +428,10 @@ class RSA(): #self.restore_optical_band_2(o_b_id, slots, band,links) if bidir: for l in links: - r_l = reverse_link(l) - if debug: - print(f"reverse_link {r_l}") + r_l = reverse_link(l, self.link_key__to__src_dst_node_names) + MSG = '[RSA:del_flow] reverse link: {:s}' + LOGGER.debug(MSG.format(str(r_l))) + rlink = self.get_link_by_name(r_l) fib = rlink["optical_details"] #fib = self.get_link_by_name(r_l)["optical_details"] @@ -496,7 +514,7 @@ class RSA(): #self.restore_optical_band_2(o_b_id, slots, band,links) if bidir: for l in links: - r_l = reverse_link(l) + r_l = reverse_link(l, self.link_key__to__src_dst_node_names) if debug: print(r_l) rlink = self.get_link_by_name(r_l) @@ -524,6 +542,10 @@ class RSA(): def get_fibers_forward(self, links, slots, band): + LOGGER.info('[RSA:get_fibers_forward] Starting path forward computation') + MSG = '[RSA:get_fibers_forward] Input parameters: links={:s}, slots={:s}, band={:s}' + LOGGER.info(MSG.format(str(links), str(slots), str(band))) + fiber_list = {} add = links[0] drop = links[-1] @@ -560,16 +582,23 @@ class RSA(): #self.update_link(fib, slots, band) self.update_link_2(fib,slots,band,link) break - print("INFO: Path forward computation completed") + + MSG = '[RSA:get_fibers_forward] Path forward computation completed: fiber_list={:s}' + LOGGER.info(MSG.format(str(fiber_list))) return fiber_list - def get_link_by_name (self, key): + def get_link_by_name(self, key : str) -> Dict: for link in self.links_dict["optical_links"]: if link["name"] == key: #if debug: # print(link) - break - return link + return link + + MSG = '[RSA:get_link_by_name] Link with name {:s} not found. links_dict: {:s}' + LOGGER.error(MSG.format(str(key), str(self.links_dict["optical_links"]))) + + MSG = '[RSA:get_link_by_name] Link with name {:s} not found' + raise ValueError(MSG.format(str(key))) def get_fiber_details(self, link_key, fiber_id): for link in self.links_dict["optical_links"]: @@ -582,9 +611,13 @@ class RSA(): return None def get_fibers_backward(self, links, slots, band): + LOGGER.info('[RSA:get_fibers_backward] Starting path backward computation') + MSG = '[RSA:get_fibers_backward] Input parameters: links={:s}, slots={:s}, band={:s}' + LOGGER.info(MSG.format(str(links), str(slots), str(band))) + fiber_list = {} - #r_drop = reverse_link(links[0]) - #r_add = reverse_link(links[-1]) + #r_drop = reverse_link(links[0], self.link_key__to__src_dst_node_names) + #r_add = reverse_link(links[-1], self.link_key__to__src_dst_node_names) for l in links: fib = self.get_link_by_name(l)["optical_details"] ''' @@ -596,13 +629,14 @@ class RSA(): s_port = fib["src_port"] d_port = fib["dst_port"] - if debug: - print(l, s_port, d_port) + MSG = '[RSA:get_fibers_backward] processing link: {:s}, src_port: {:s}, dst_port: {:s}' + LOGGER.debug(MSG.format(str(l), str(s_port), str(d_port))) - r_l = reverse_link(l) + r_l = reverse_link(l, self.link_key__to__src_dst_node_names) r_link = self.get_link_by_name(r_l) - #if debug: - # print(r_l) + + MSG = '[RSA:get_fibers_backward] reverse link: {:s}' + LOGGER.debug(MSG.format(str(r_l))) #for f in r_link["fibers"].keys(): r_fib = r_link["optical_details"] @@ -610,7 +644,9 @@ class RSA(): if list_in_list(slots, str_list_to_int(r_fib[band].keys())): #fiber_list[r_l] = r_fib["ID"] self.update_link(r_fib, slots, band) - print("INFO: Path backward computation completed") + + MSG = '[RSA:get_fibers_backward] Path backward computation completed: fiber_list={:s}' + LOGGER.info(MSG.format(str(fiber_list))) return fiber_list #function invoked for lightpaths and OB @@ -652,7 +688,7 @@ class RSA(): fibx = self.get_fiber_details(lx, f) ''' - src, dst = llx.split("-") + src, dst = self.link_key__to__src_dst_node_names[llx] #outport = self.links_dict[lx]['fibers'][f]["src_port"] lx = self.get_link_by_name(llx)["optical_details"] outport = lx["src_port"] @@ -724,7 +760,7 @@ class RSA(): t_flows = {} #flows_add_side - src, dst = add.split("-") + src, dst = self.link_key__to__src_dst_node_names[add] lx = self.get_link_by_name(add)["optical_details"] #outport = self.links_dict[add]['fibers'][f]["src_port"] outport = lx["src_port"] @@ -761,7 +797,7 @@ class RSA(): #flows_drop_side # R2 rules ly = self.get_link_by_name(drop)["optical_details"] - src, dst = drop.split("-") + src, dst = self.link_key__to__src_dst_node_names[drop] #outport = self.links_dict[drop]['fibers'][f]["src_port"] outport = ly["src_port"] @@ -813,7 +849,7 @@ class RSA(): ''' #flows_add_side - src, dst = add.split("-") + src, dst = self.link_key__to__src_dst_node_names[add] lx = self.get_link_by_name(add)["optical_details"] #outport = self.links_dict[add]['fibers'][f]["src_port"] outport = lx["src_port"] @@ -1268,8 +1304,8 @@ class RSA(): temp_links2.append(list(dst_links.keys())[0]) if len(temp_links2) == 2: - [t_src, roadm_src] = temp_links2[0].split('-') - [roadm_dst, t_dst] = temp_links2[1].split('-') + t_src, roadm_src = self.link_key__to__src_dst_node_names[temp_links2[0]] + roadm_dst, t_dst = self.link_key__to__src_dst_node_names[temp_links2[1]] temp_path.append(t_src) temp_path.append(roadm_src) temp_path.append(roadm_dst) @@ -1585,7 +1621,7 @@ class RSA(): #self.restore_optical_band_2(o_b_id, slots, band,links) if bidir: for l in links: - r_l = reverse_link(l) + r_l = reverse_link(l, self.link_key__to__src_dst_node_names) if debug: print(r_l) rlink = self.get_link_by_name(r_l) @@ -1627,8 +1663,8 @@ class RSA(): r1 = "" r2 = "" if len(links) == 2: - [t1, r1] = links[0].split("-") - [r2, t2] = links[1].split("-") + t1, r1 = self.link_key__to__src_dst_node_names[links[0]] + r2, t2 = self.link_key__to__src_dst_node_names[links[1]] else: return 0, 0 existing_ob = self.get_optical_bands(r1, r2) diff --git a/src/opticalcontroller/dijkstra.py b/src/opticalcontroller/dijkstra.py index f113c74255642fd20e7f55dee09549e0a087a8e3..54b29b3851b1bd9d6c8fee8813534fc54caa6051 100644 --- a/src/opticalcontroller/dijkstra.py +++ b/src/opticalcontroller/dijkstra.py @@ -16,7 +16,9 @@ # https://networkx.org/documentation/stable/index.html # https://networkx.org/documentation/stable/reference/algorithms/shortest_paths.html -import sys +import logging + +LOGGER = logging.getLogger(__name__) class Vertex: def __init__(self, node): @@ -99,11 +101,20 @@ class Graph: self.get_vertex(n).reset_vertex() def printGraph(self): + MSG = ', '.join([ + 'src_node={:s}', 'dst_node={:s}', + 'src_port={:s}', 'dst_port={:s}', + 'weight_src_to_dst={:d}', 'weight_dst_to_src={:d}' + ]) + for v in self: for w in v.get_connections(): vid = v.get_id() wid = w.get_id() - print ('( %s , %s, %s, %s, %s, %s)' % ( vid, wid, v.get_port(w), w.get_port(v), v.get_weight(w), w.get_weight(v))) + LOGGER.debug(MSG.format( + vid, wid, v.get_port(w), w.get_port(v), + v.get_weight(w), w.get_weight(v) + )) def add_vertex(self, node): self.num_vertices = self.num_vertices + 1 diff --git a/src/opticalcontroller/tools.py b/src/opticalcontroller/tools.py index d3d40a6c1e723a6328b3077462e9f8ecbf468293..8a335c4b338e8668fbb4f4435e1a4a705a31cc01 100644 --- a/src/opticalcontroller/tools.py +++ b/src/opticalcontroller/tools.py @@ -15,7 +15,6 @@ import json, logging, numpy as np from typing import Dict, List, Optional, Tuple from opticalcontroller.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 @@ -132,10 +131,10 @@ def list_in_list(a, b): return False -def reverse_link(link): - s, d = link.split('-') - r_link = "{}-{}".format(d, s) - return r_link +def reverse_link(link, link_key__to__src_dst_node_names : Dict[str, Tuple[str, str]]) -> str: + src_name, dst_name = link_key__to__src_dst_node_names[link] + rev_link_name = '{:s}-{:s}'.format(dst_name, src_name) + return rev_link_name def get_slot_frequency(b, n): @@ -226,28 +225,29 @@ def readTopologyDataFromContext(topology_id:TopologyId): return topo , nodes -def reverse_links(links): - temp_links = links.copy() - temp_links.reverse() - result = [] - for link in temp_links: - [a, b] = link.split("-") - result.append("{}-{}".format(b, a)) - return result +def reverse_links( + links : List[str], link_key__to__src_dst_node_names : Dict[str, Tuple[str, str]] +) -> List[str]: + return [ + reverse_link(link, link_key__to__src_dst_node_names) + for link in reversed(links) + ] def get_links_from_node(topology, node): + link_prefix = "{}-".format(node) result = {} for link in topology["optical_links"]: - if "{}-".format(node) in link["name"]: + if str(link["name"]).startswith(link_prefix): result[link["name"]] = link return result def get_links_to_node(topology, node): + link_suffix = "-{}".format(node) result = {} for link in topology["optical_links"]: - if "-{}".format(node) in link["name"]: + if str(link["name"]).endswith(link_suffix): result[link["name"]] = link return result diff --git a/src/service/service/service_handlers/oc/OCTools.py b/src/service/service/service_handlers/oc/OCTools.py index 8a07de8596a08efb9a9b74eb12eba87e2b67ba9a..d3fbb5e8f6b0b49e0206510d2daabb1bd5f0899b 100644 --- a/src/service/service/service_handlers/oc/OCTools.py +++ b/src/service/service/service_handlers/oc/OCTools.py @@ -18,8 +18,8 @@ from common.proto.context_pb2 import DeviceId, Service from common.tools.object_factory.Device import json_device_id from service.service.service_handler_api.Tools import get_endpoint_matching -log = logging.getLogger(__name__) +LOGGER = logging.getLogger(__name__) def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])->Dict: @@ -28,7 +28,7 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]]) end = len(endpoints) i = 0 bidir = 0 - log.debug("end={}".format(end)) + LOGGER.debug("end={}".format(end)) while(i < end): endpoint = endpoints[i] device_uuid, endpoint_uuid = endpoint[0:2] @@ -41,12 +41,12 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]]) next_device_uuid, next_endpoint_uuid = next_endpoint[0:2] if next_device_uuid == device_uuid : bidir = 1 - log.info("connection is bidirectional") + LOGGER.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") + LOGGER.debug("connection is unidirectional") else: if not bidir: if i == end-1: @@ -62,17 +62,17 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]]) entries[device_uuid].append(entry_tuple) i = i + 1 else: - log.debug("ERROR in unidirectional connection 4") + LOGGER.debug("ERROR in unidirectional connection 4") return {} else: - log.debug("Ocheck i {}, {}, {}".format(i, i+1, end-1)) + LOGGER.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)) + LOGGER.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)) + LOGGER.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: @@ -80,10 +80,10 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]]) entries[device_uuid].append(entry_tuple) i = i + 1 else: - log.debug("ERROR in bidirectional connection 2") + LOGGER.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)) + LOGGER.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] @@ -91,8 +91,8 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]]) 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)) + LOGGER.debug("ERROR in bidirectional connection 3") + LOGGER.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid)) return entries #i+2 next_2_endpoint = endpoints[i+2] @@ -100,14 +100,14 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]]) #i+3 next_3_endpoint = endpoints[i+3] next_3_device_uuid, next_3_endpoint_uuid = next_3_endpoint[0:2] - log.debug(f"de {device_uuid} and i {i}") - log.debug(f"de2 {next_2_device_uuid} and dev3 {next_3_device_uuid}") + LOGGER.debug(f"de {device_uuid} and i {i}") + LOGGER.debug(f"de2 {next_2_device_uuid} and dev3 {next_3_device_uuid}") 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") + LOGGER.debug("ERROR in bidirection connection 4") return {} i = i + 1 return entries @@ -121,7 +121,7 @@ def convert_or_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str] end = len(endpoints) i = 0 if bidir: - log.info(f"i starts with {i} ") + LOGGER.info(f"i starts with {i} ") i = i + 1 while(i < end-2): #i @@ -146,8 +146,8 @@ def convert_or_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str] #i+3 next_3_endpoint = endpoints[i+3] next_3_device_uuid, next_3_endpoint_uuid = next_3_endpoint[0:2] - log.info(f"dev {device_uuid} ") - log.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ") + LOGGER.info(f"dev {device_uuid} ") + LOGGER.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ") 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) @@ -198,7 +198,7 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int): entry_tuple = next_endpoint_uuid, "0" entries[next_device_uuid].append(entry_tuple) else: - log.info("error expected device_id {}, found {}".format(device_uuid, next_device_uuid)) + LOGGER.info("error expected device_id {}, found {}".format(device_uuid, next_device_uuid)) return {} i = i + 2 if end > 4: @@ -207,7 +207,7 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int): #i endpoint = endpoints[i] device_uuid, endpoint_uuid = endpoint[0:2] - log.debug("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid)) + LOGGER.debug("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid)) if device_uuid not in entries.keys(): entries[device_uuid] = [] #i+1 @@ -217,8 +217,8 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int): entry_tuple = endpoint_uuid, next_endpoint_uuid entries[device_uuid].append(entry_tuple) else: - log.debug("ERROR in bidirectional ob") - log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid)) + LOGGER.debug("ERROR in bidirectional ob") + LOGGER.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid)) return {} #i+2 next_2_endpoint = endpoints[i+2] @@ -231,7 +231,7 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int): entries[device_uuid].append(entry_tuple) i = i + 4 else: - log.debug("ERROR in bidirection ob") + LOGGER.debug("ERROR in bidirection ob") return {} endpoint = endpoints[i] device_uuid, endpoint_uuid = endpoint[0:2] @@ -247,7 +247,7 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int): entry_tuple = "0", next_endpoint_uuid entries[next_device_uuid].append(entry_tuple) else: - log.debug("error expected device_id {}, found {}".format(device_uuid, next_device_uuid)) + LOGGER.debug("error expected device_id {}, found {}".format(device_uuid, next_device_uuid)) else: endpoint = endpoints[i] device_uuid, endpoint_uuid = endpoint[0:2] @@ -273,8 +273,8 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int): entry_tuple = endpoint_uuid, next_endpoint_uuid entries[device_uuid].append(entry_tuple) else: - log.debug("ERROR in bidirectional ob") - log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid)) + LOGGER.debug("ERROR in bidirectional ob") + LOGGER.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid)) return {} i = i + 2 next_endpoint = endpoints[i] @@ -284,9 +284,12 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int): entry_tuple = next_endpoint_uuid, "0" entries[next_device_uuid].append(entry_tuple) return entries - - + + def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op_mode: int): + MSG = '[OCTools:conn_flows] endpoints={:s}, bidir={:s}, op_mode={:s}' + LOGGER.info(MSG.format(str(endpoints), str(bidir), str(op_mode))) + if op_mode is not None: entries = {} end = len(endpoints) @@ -302,7 +305,7 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op i = i + 1 #if bidir reading 4 endpoints per node if bidir: - log.info(f"i starts with {i} ") + LOGGER.info(f"i starts with {i} ") device0 , endpoint0=endpoints[0][0:2] device1 , endpoint1=endpoints[1][0:2] finalend=end-2 @@ -324,23 +327,25 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op entry_tuple = endpoint_uuid, next_endpoint_uuid entries[device_uuid].append(entry_tuple) else: - log.info(f"error : next_dev {next_device_uuid} dev {device_uuid} for i {i} ") - return {} + MSG = '[OCTools:conn_flows] error : next_dev {:s} dev {:s} for i {:d}' + LOGGER.error(MSG.format(str(next_device_uuid), str(device_uuid), i)) + return {} #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] - log.info(f"dev {device_uuid} ") - log.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ") + LOGGER.info(f"dev {device_uuid} ") + LOGGER.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ") 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 + 4 else: - log.info(f"error : next_2_dev {next_2_device_uuid} next_3_device{next_3_device_uuid} dev {device_uuid} for i {i} ") + MSG = '[OCTools:conn_flows] error : next_2_dev {:s} next_3_device{:s} dev {:s} for i {:d}' + LOGGER.error(MSG.format(str(next_2_device_uuid), str(next_3_device_uuid), str(device_uuid), i)) return {} else: while(i < end-1): @@ -358,8 +363,10 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op entries[device_uuid].append(entry_tuple) i = i + 2 else: + MSG = '[OCTools:conn_flows] error : next_dev {:s} dev {:s} for i {:d}' + LOGGER.error(MSG.format(str(next_device_uuid), str(device_uuid), i)) return {} - #rx tp + #rx tp endpoint = endpoints[i] device_uuid, endpoint_uuid = endpoint[0:2] if device_uuid not in entries.keys(): @@ -369,8 +376,9 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op else: entries = {} if len(endpoints) != 4: - log.info(f"PDP : expected alien configuration with 4 endpoints ") - return {} + MSG = '[OCTools:conn_flows] error : expected 4 endpoints for PDP, found {:d}' + LOGGER.error(MSG.format(len(endpoints))) + return {} i = 0 device0 , endpoint0 = endpoints[0][0:2] device1 , endpoint1 = endpoints[1][0:2] @@ -395,7 +403,7 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op #if bidir reading 4 endpoints per node ''' if bidir: - log.info(f"i starts with {i} ") + LOGGER.info(f"i starts with {i} ") device0 , endpoint0=endpoints[0][0:2] device1 , endpoint1=endpoints[1][0:2] finalend=end-2 @@ -417,7 +425,7 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op entry_tuple = endpoint_uuid, next_endpoint_uuid entries[device_uuid].append(entry_tuple) else: - log.info(f"error : next_dev {next_device_uuid} dev {device_uuid} for i {i} ") + LOGGER.info(f"error : next_dev {next_device_uuid} dev {device_uuid} for i {i} ") return {} #i+2 @@ -426,14 +434,14 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op #i+3 next_3_endpoint = endpoints[i+3] next_3_device_uuid, next_3_endpoint_uuid = next_3_endpoint[0:2] - log.info(f"dev {device_uuid} ") - log.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ") + LOGGER.info(f"dev {device_uuid} ") + LOGGER.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ") 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 + 4 else: - log.info(f"error : next_2_dev {next_2_device_uuid} next_3_device{next_3_device_uuid} dev {device_uuid} for i {i} ") + LOGGER.info(f"error : next_2_dev {next_2_device_uuid} next_3_device{next_3_device_uuid} dev {device_uuid} for i {i} ") return {} else: while(i < end-1): @@ -460,18 +468,22 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op entry_tuple = endpoint_uuid, "0", entries[device_uuid].append(entry_tuple) ''' + + MSG = '[OCTools:conn_flows] entries={:s}' + LOGGER.info(MSG.format(str(entries))) return entries - -def endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, is_ob: bool, op_mode: int)->Dict: +def endpoints_to_flows( + endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, is_ob : bool, op_mode : int +) -> Dict: if is_ob: entries = ob_flows(endpoints, bidir) else: entries = conn_flows(endpoints, bidir, op_mode) - return entries + def get_device_endpint_name(endpoint_uuid : str, device_uuid : str, task_executor) -> Tuple: device_obj = task_executor.get_device(DeviceId(**json_device_id(device_uuid))) endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid)