def remove_requirement(self, name, prefix): """ @API :name = unique identifier of a requirement :prefix = destination prefix of the requirement """ if not self.simple_req.get(prefix): LOG.critical("No requirement for this prefix : " + str(prefix)) else: index = self.get_index_by_name(name, prefix) if index != -1: del self.simple_req[prefix][index] self.change_pfx.append(prefix) else: LOG.critical("No prefix has this name : " + str(name))
def check_network(config, Error): try: fibbing_ctrl = config.get('fibbing-controller') hosts_link = config.get('hosts-link') links = config.get('links') main_controller = config.get('main-controller') ospf_links = config.get('ospf-links') routers = config.get('routers') routerid = [] ospf_router = [] for r in routers: if r.get('ospf').get('enable'): if r.get('ospf').get('router-id') in routerid: LOG.error('Router id already used %s' % r.get('ospf').get('router-id')) Error = True else: routerid.append(r.get('ospf').get('router-id')) else: LOG.warning( 'For this framework all routers must have ospf enable') ospf_router.append(r.get('name')) link_key_map = {} for link in links: if not link.get('src').get('name'): LOG.error('A link must have a src router name') Error = True if not link.get('src').get('ip'): LOG.error('A link must have a src router ip') Error = True if not link.get('dest').get('name'): LOG.error('A link must have a dest router name') Error = True if not link.get('dest').get('ip'): LOG.error('A link must have a dest router ip') Error = True link_key_map[link.get('name')] = link ospf_config = {} for o_l in ospf_links: link = link_key_map.get(o_l.get('name')) if link.get('src').get('name') not in ospf_router or \ link.get('dest').get('name') not in ospf_router: LOG.error( 'A link with ospf configured must have both src and dest with ospf enabled' ) Error = True src_o_conf = o_l.get('src').get('ospf') dest_o_conf = o_l.get('dest').get('ospf') if src_o_conf.get('area') not in ospf_config: ospf_config[src_o_conf.get('area')] = src_o_conf else: area_conf = ospf_config[src_o_conf.get('area')] if src_o_conf.get('hello-interval') != area_conf.get('hello-interval') or\ src_o_conf.get('dead-interval') != area_conf.get('dead-interval') : LOG.error( 'Hello and dead interval must be the same for the same broadcast domain' ) Error = True if dest_o_conf.get('area') not in ospf_config: ospf_config[dest_o_conf.get('area')] = dest_o_conf else: area_conf = ospf_config[dest_o_conf.get('area')] if dest_o_conf.get('hello-interval') != area_conf.get('hello-interval') or\ dest_o_conf.get('dead-interval') != area_conf.get('dead-interval') : LOG.error( 'Hello and dead interval must be the same for the same broadcast domain' ) Error = True controller_o_conf = fibbing_ctrl.get('controller-config').get('ospf') if controller_o_conf.get('area') not in ospf_config: LOG.error( 'The Fibbing controller should be in the same area of at least some other router' ) Error = True else: area_conf = ospf_config[controller_o_conf.get('area')] if controller_o_conf.get('hello-interval') != area_conf.get('hello-interval') or\ controller_o_conf.get('dead-interval') != area_conf.get('dead-interval') : LOG.error( 'Hello and dead interval must be the same for the same broadcast domain' ) Error = True if not main_controller: LOG.error( 'The host acting as the main controller must be specified') Error = True return Error except Exception as e: LOG.critical('Error :' + str(e)) Error = True return Error
def complete_path(data, Requirement, destRouter): """ @API function called by the NMCore to perform path expansion of :Requirement :data is the network config from ConfD Agent """ routers = [] for r in data.get('routers'): if r.get('ospf6').get('enable'): routers.append(r.get('name')) ospf_link = [] for link in data.get('ospf-links'): ospf_link.append(link.get('name')) edges = [] for link in data.get('link'): if link.get('name') in ospf_link: src = link.get('src') dest = link.get('dest') if link.get('bidirectional'): edges.append((src.get('name'), dest.get('name'), int(link.get('cost')), 'bidirectional')) edges.append((dest.get('name'), src.get('name'), int(link.get('cost')), 'bidirectional')) else: edges.append((src.get('name'), dest.get('name'), int(src.get('cost')), 'unidirectional')) edges.append((dest.get('name'), src.get('name'), int(dest.get('cost')), 'unidirectional')) for i in range(len(Requirement) - 1): # remove edges already in the Requirement if Requirement[i] != '*' and Requirement[i + 1] != '*': edge = find_edge(Requirement[i], Requirement[i + 1], edges) index = edges.index(edge) del edges[index] edge = find_edge(Requirement[i + 1], Requirement[i], edges) index = edges.index(edge) del edges[index] # build graph graph = Graph() for router in routers: graph.add_node(router) for edge in edges: if edge[3] == 'unidirectional': graph.add_edge_unidirectional(edge[0], edge[1], edge[2]) else: graph.add_edge(edge[0], edge[1], edge[2]) try: Simple_path_req = get_simple_path_req(Requirement, destRouter, graph) except KeyError: LOG.critical('Could not solve path expansion for ' + str(Requirement)) return False LOG.info('Success path expansion...') LOG.info('Path : ' + str(Simple_path_req) + ' for :' + str(destRouter)) return Simple_path_req