def _init_signal_listeners(self): CORE_MANAGER.get_core_service()._signal_bus.register_listener( BgpSignalBus.BGP_BEST_PATH_CHANGED, lambda _, info: self._notify_best_path_changed(info['path'], info['is_withdraw']) )
def stop(**kwargs): """Stops current context is one is active. Raises RuntimeConfigError if runtime is not active or initialized yet. """ if not CORE_MANAGER.started: raise RuntimeConfigError('No runtime is active. Call start to create ' 'a runtime') CORE_MANAGER.stop() return True
def add_evpn_local(route_type, route_dist, next_hop, **kwargs): """Adds EVPN route from VRF identified by *route_dist*. """ if (route_type in [EVPN_ETH_AUTO_DISCOVERY, EVPN_ETH_SEGMENT] and kwargs['esi'] == 0): raise ConfigValueError(conf_name=EVPN_ESI, conf_value=kwargs['esi']) try: # Create new path and insert into appropriate VRF table. tm = CORE_MANAGER.get_core_service().table_manager label = tm.update_vrf_table(route_dist, next_hop=next_hop, route_family=VRF_RF_L2_EVPN, route_type=route_type, **kwargs) # Currently we only allocate one label per local route, # so we share first label from the list. if label: label = label[0] # Send success response with new label. return [{ EVPN_ROUTE_TYPE: route_type, ROUTE_DISTINGUISHER: route_dist, VRF_RF: VRF_RF_L2_EVPN, VPN_LABEL: label }.update(kwargs)] except BgpCoreError as e: raise PrefixError(desc=e)
def add_evpn_local(route_type, route_dist, next_hop, **kwargs): """Adds EVPN route from VRF identified by *route_dist*. """ if(route_type in [EVPN_ETH_AUTO_DISCOVERY, EVPN_ETH_SEGMENT] and kwargs['esi'] == 0): raise ConfigValueError(conf_name=EVPN_ESI, conf_value=kwargs['esi']) try: # Create new path and insert into appropriate VRF table. tm = CORE_MANAGER.get_core_service().table_manager label = tm.update_vrf_table(route_dist, next_hop=next_hop, route_family=VRF_RF_L2_EVPN, route_type=route_type, **kwargs) # Currently we only allocate one label per local route, # so we share first label from the list. if label: label = label[0] # Send success response with new label. return [{EVPN_ROUTE_TYPE: route_type, ROUTE_DISTINGUISHER: route_dist, VRF_RF: VRF_RF_L2_EVPN, VPN_LABEL: label}.update(kwargs)] except BgpCoreError as e: raise PrefixError(desc=e)
def _create_rt_match_importmap(name, value): core_service = CORE_MANAGER.get_core_service() importmap_manager = core_service.importmap_manager try: importmap_manager.create_rt_import_map(name, value) except ImportMapAlreadyExistsError: raise RuntimeConfigError('Map with this name already exists') return True
def delete_evpn_local(route_type, route_dist, **kwargs): """Deletes/withdraws EVPN route from VRF identified by *route_dist*. """ try: tm = CORE_MANAGER.get_core_service().table_manager tm.update_vrf_table(route_dist, route_family=VRF_RF_L2_EVPN, route_type=route_type, is_withdraw=True, **kwargs) # Send success response. return [{EVPN_ROUTE_TYPE: route_type, ROUTE_DISTINGUISHER: route_dist, VRF_RF: VRF_RF_L2_EVPN}.update(kwargs)] except BgpCoreError as e: raise PrefixError(desc=e)
def _create_rt_match_importmap(name, value): core_service = CORE_MANAGER.get_core_service() importmap_manager = core_service.importmap_manager try: importmap_manager.create_rt_import_map(name, value) except ImportMapAlreadyExistsError: raise RuntimeConfigError( 'Map with this name already exists' ) return True
def delete_local(route_dist, prefix, route_family=VRF_RF_IPV4): """Deletes/withdraws *prefix* from VRF identified by *route_dist* and source as network controller. """ try: tm = CORE_MANAGER.get_core_service().table_manager tm.update_vrf_table(route_dist, prefix, route_family=route_family, is_withdraw=True) # Send success response. return [{ROUTE_DISTINGUISHER: route_dist, PREFIX: prefix, VRF_RF: route_family}] except BgpCoreError as e: raise PrefixError(desc=e)
def get_neighbor_attribute_map(neigh_ip_address, route_dist=None, route_family=VRF_RF_IPV4): """Returns a neighbor attribute_map for given ip address if exists.""" core = CORE_MANAGER.get_core_service() peer = core.peer_manager.get_by_addr(neigh_ip_address) at_maps_key = const.ATTR_MAPS_LABEL_DEFAULT if route_dist is not None: at_maps_key = ':'.join([route_dist, route_family]) at_maps = peer.attribute_maps.get(at_maps_key) if at_maps: return at_maps.get(const.ATTR_MAPS_ORG_KEY) else: return []
def _create_prefix_match_importmap(name, value, route_family): core_service = CORE_MANAGER.get_core_service() importmap_manager = core_service.importmap_manager try: if route_family == 'ipv4': importmap_manager.create_vpnv4_nlri_import_map(name, value) elif route_family == 'ipv6': importmap_manager.create_vpnv6_nlri_import_map(name, value) else: raise RuntimeConfigError( 'Unknown address family %s. it should be ipv4 or ipv6' % route_family) except ImportMapAlreadyExistsError: raise RuntimeConfigError('Map with this name already exists') return True
def del_flowspec_local(flowspec_family, route_dist, rules): """Deletes/withdraws Flow Specification route from VRF identified by *route_dist*. """ try: tm = CORE_MANAGER.get_core_service().table_manager tm.update_flowspec_vrf_table( flowspec_family=flowspec_family, route_dist=route_dist, rules=rules, is_withdraw=True) # Send success response. return [{FLOWSPEC_FAMILY: flowspec_family, ROUTE_DISTINGUISHER: route_dist, FLOWSPEC_RULES: rules}] except BgpCoreError as e: raise PrefixError(desc=e)
def add_flowspec_local(flowspec_family, route_dist, rules, **kwargs): """Adds Flow Specification route from VRF identified by *route_dist*. """ try: # Create new path and insert into appropriate VRF table. tm = CORE_MANAGER.get_core_service().table_manager tm.update_flowspec_vrf_table( flowspec_family=flowspec_family, route_dist=route_dist, rules=rules, **kwargs) # Send success response. return [{FLOWSPEC_FAMILY: flowspec_family, ROUTE_DISTINGUISHER: route_dist, FLOWSPEC_RULES: rules}.update(kwargs)] except BgpCoreError as e: raise PrefixError(desc=e)
def add_local(route_dist, prefix, next_hop, route_family=VRF_RF_IPV4): """Adds *prefix* from VRF identified by *route_dist* and sets the source as network controller. """ try: # Create new path and insert into appropriate VRF table. tm = CORE_MANAGER.get_core_service().table_manager label = tm.update_vrf_table(route_dist, prefix, next_hop, route_family) # Currently we only allocate one label per local_prefix, # so we share first label from the list. if label: label = label[0] # Send success response with new label. return [{ROUTE_DISTINGUISHER: route_dist, PREFIX: prefix, VRF_RF: route_family, VPN_LABEL: label}] except BgpCoreError as e: raise PrefixError(desc=e)
def _create_prefix_match_importmap(name, value, route_family): core_service = CORE_MANAGER.get_core_service() importmap_manager = core_service.importmap_manager try: if route_family == 'ipv4': importmap_manager.create_vpnv4_nlri_import_map(name, value) elif route_family == 'ipv6': importmap_manager.create_vpnv6_nlri_import_map(name, value) else: raise RuntimeConfigError( 'Unknown address family %s. it should be ipv4 or ipv6' % route_family ) except ImportMapAlreadyExistsError: raise RuntimeConfigError( 'Map with this name already exists' ) return True
def route_refresh(self, peer_ip=None, afi=None, safi=None): if not peer_ip: peer_ip = 'all' try: route_families = [] if afi is None and safi is None: route_families.extend(SUPPORTED_GLOBAL_RF) else: route_family = nlri.get_rf(afi, safi) if (route_family not in SUPPORTED_GLOBAL_RF): raise WrongParamError('Not supported address-family' ' %s, %s' % (afi, safi)) route_families.append(route_family) pm = CORE_MANAGER.get_core_service().peer_manager pm.make_route_refresh_request(peer_ip, *route_families) except Exception as e: LOG.error(traceback.format_exc()) raise WrongParamError(str(e)) return None
def route_refresh(self, peer_ip=None, afi=None, safi=None): if not peer_ip: peer_ip = 'all' try: route_families = [] if afi is None and safi is None: route_families.extend(SUPPORTED_GLOBAL_RF) else: route_family = RouteFamily(afi, safi) if (route_family not in SUPPORTED_GLOBAL_RF): raise WrongParamError('Not supported address-family' ' %s, %s' % (afi, safi)) route_families.append(route_family) pm = CORE_MANAGER.get_core_service().peer_manager pm.make_route_refresh_request(peer_ip, *route_families) except Exception as e: LOG.error(traceback.format_exc()) raise WrongParamError(str(e)) return None
def set_neighbor_attribute_map(neigh_ip_address, at_maps, route_dist=None, route_family=VRF_RF_IPV4): """set attribute_maps to the neighbor.""" core = CORE_MANAGER.get_core_service() peer = core.peer_manager.get_by_addr(neigh_ip_address) at_maps_key = const.ATTR_MAPS_LABEL_DEFAULT at_maps_dict = {} if route_dist is not None: vrf_conf =\ CORE_MANAGER.vrfs_conf.get_vrf_conf(route_dist, route_family) if vrf_conf: at_maps_key = ':'.join([route_dist, route_family]) else: raise RuntimeConfigError(desc='No VrfConf with rd %s' % route_dist) at_maps_dict[const.ATTR_MAPS_LABEL_KEY] = at_maps_key at_maps_dict[const.ATTR_MAPS_VALUE] = at_maps peer.attribute_maps = at_maps_dict return True
def get_neighbor_attribute_map(neigh_ip_address): """Returns a neighbor attribute_map for given ip address if exists.""" core = CORE_MANAGER.get_core_service() ret = core.peer_manager.get_by_addr(neigh_ip_address).attribute_maps return ret
def set_neighbor_in_filter(neigh_ip_address, filters): """Returns a neighbor in_filter for given ip address if exists.""" core = CORE_MANAGER.get_core_service() peer = core.peer_manager.get_by_addr(neigh_ip_address) peer.out_filters = filters return True
def set_neighbor_out_filter(neigh_ip_address, filters): """Sets the out_filter of a neighbor.""" core = CORE_MANAGER.get_core_service() peer = core.peer_manager.get_by_addr(neigh_ip_address) peer.out_filters = filters return True
def _get_vrf_tables(self): return CORE_MANAGER.get_core_service().table_manager.get_vrf_tables()
def get_core_service(self): return CORE_MANAGER.get_core_service()
def bmp_stop(host, port): core = CORE_MANAGER.get_core_service() return core.stop_bmp(host, port)
def _init_signal_listeners(self): CORE_MANAGER.get_core_service()._signal_bus.register_listener( BgpSignalBus.BGP_BEST_PATH_CHANGED, lambda _, dest: self._notify_best_path_changed(dest) )
def del_network(prefix): tm = CORE_MANAGER.get_core_service().table_manager tm.add_to_ipv4_global_table(prefix, is_withdraw=True) return True
def add_network(prefix): tm = CORE_MANAGER.get_core_service().table_manager tm.add_to_ipv4_global_table(prefix) return True
def add_network(prefix, next_hop=None): tm = CORE_MANAGER.get_core_service().table_manager tm.add_to_global_table(prefix, next_hop) return True
def _get_vrf_table(self, vrf_name, vrf_rf): return CORE_MANAGER.get_core_service()\ .table_manager.get_vrf_table(vrf_name, vrf_rf)
def del_network(prefix): tm = CORE_MANAGER.get_core_service().table_manager tm.add_to_global_table(prefix, is_withdraw=True) return True
def add_flowspec(flowspec_family, rules, **kwargs): tm = CORE_MANAGER.get_core_service().table_manager tm.update_flowspec_global_table(flowspec_family, rules, **kwargs) return True
def del_flowspec(flowspec_family, rules): tm = CORE_MANAGER.get_core_service().table_manager tm.update_flowspec_global_table(flowspec_family, rules, is_withdraw=True) return True
def get_neighbor_out_filter(neigh_ip_address): """Returns a neighbor out_filter for given ip address if exists.""" core = CORE_MANAGER.get_core_service() ret = core.peer_manager.get_by_addr(neigh_ip_address).out_filters return ret