<s> from ryu . services . protocols . bgp . rtconf . base import ConfWithStats <EOL> from ryu . services . protocols . bgp . rtconf . common import CommonConfListener <EOL> from ryu . services . protocols . bgp . rtconf . neighbors import NeighborsConfListener <EOL> from ryu . services . protocols . bgp . rtconf import vrfs <EOL> from ryu . services . protocols . bgp . rtconf . vrfs import VrfConf <EOL> from ryu . services . protocols . bgp . rtconf . vrfs import VrfsConfListener <EOL> import logging <EOL> LOG = logging . getLogger ( '<STR_LIT>' ) <EOL> class ConfigurationManager ( CommonConfListener , VrfsConfListener , <EOL> NeighborsConfListener ) : <EOL> def __init__ ( self , core_service , common_conf , vrfs_conf , neighbors_conf ) : <EOL> self . _signal_bus = core_service . signal_bus <EOL> self . _common_config = common_conf <EOL> self . _peer_manager = core_service . peer_manager <EOL> self . _table_manager = core_service . table_manager <EOL> self . _rt_manager = core_service . rt_manager <EOL> CommonConfListener . __init__ ( self , common_conf ) <EOL> VrfsConfListener . __init__ ( self , vrfs_conf ) <EOL> NeighborsConfListener . __init__ ( self , neighbors_conf ) <EOL> def on_update_common_conf ( self , evt ) : <EOL> raise NotImplementedError ( ) <EOL> def on_add_neighbor_conf ( self , evt ) : <EOL> neigh_conf = evt . value <EOL> self . _peer_manager . add_peer ( neigh_conf , self . _common_config ) <EOL> def on_remove_neighbor_conf ( self , evt ) : <EOL> neigh_conf = evt . value <EOL> self . _peer_manager . remove_peer ( neigh_conf ) <EOL> def on_chg_vrf_conf ( self , evt ) : <EOL> evt_value = evt . value <EOL> vrf_conf = evt . src <EOL> new_imp_rts , removed_imp_rts , import_maps , re_export , re_import = evt_value <EOL> route_family = vrf_conf . route_family <EOL> vrf_table = self . _table_manager . get_vrf_table ( <EOL> vrf_conf . route_dist , route_family <EOL> ) <EOL> assert vrf_table <EOL> self . _table_manager . update_vrf_table_links ( <EOL> vrf_table , new_imp_rts , removed_imp_rts <EOL> ) <EOL> if re_export : <EOL> self . _table_manager . re_install_net_ctrl_paths ( vrf_table ) <EOL> vrf_table . clean_uninteresting_paths ( ) <EOL> if import_maps is not None : <EOL> vrf_table . init_import_maps ( import_maps ) <EOL> changed_dests = vrf_table . apply_import_maps ( ) <EOL> for dest in changed_dests : <EOL> self . _signal_bus . dest_changed ( dest ) <EOL> if re_import : <EOL> LOG . debug ( <EOL> "<STR_LIT>" , vrf_table <EOL> ) <EOL> self . _table_manager . import_all_vpn_paths_to_vrf ( vrf_table ) <EOL> else : <EOL> self . _table_manager . import_all_vpn_paths_to_vrf ( <EOL> vrf_table , new_imp_rts <EOL> ) <EOL> self . _rt_manager . update_local_rt_nlris ( ) <EOL> def on_remove_vrf_conf ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> vrf_conf = evt . value <EOL> vrf_conf . remove_listener ( VrfConf . VRF_CHG_EVT , self . on_chg_vrf_conf ) <EOL> self . _table_manager . remove_vrf_by_vrf_conf ( vrf_conf ) <EOL> self . _rt_manager . update_local_rt_nlris ( ) <EOL> self . _signal_bus . vrf_removed ( vrf_conf . route_dist ) <EOL> rd = vrf_conf . route_dist <EOL> rf = vrf_conf . route_family <EOL> peers = self . _peer_manager . iterpeers <EOL> for peer in peers : <EOL> key = '<STR_LIT::>' . join ( [ rd , rf ] ) <EOL> peer . attribute_maps . pop ( key , None ) <EOL> def on_add_vrf_conf ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> vrf_conf = evt . value <EOL> route_family = vrf_conf . route_family <EOL> assert route_family in vrfs . SUPPORTED_VRF_RF <EOL> vrf_table = self . _table_manager . create_and_link_vrf_table ( vrf_conf ) <EOL> vrf_conf . add_listener ( ConfWithStats . UPDATE_STATS_LOG_ENABLED_EVT , <EOL> self . on_stats_config_change ) <EOL> vrf_conf . add_listener ( ConfWithStats . UPDATE_STATS_TIME_EVT , <EOL> self . on_stats_config_change ) <EOL> vrf_conf . add_listener ( VrfConf . VRF_CHG_EVT , self . on_chg_vrf_conf ) <EOL> self . _table_manager . import_all_vpn_paths_to_vrf ( vrf_table ) <EOL> self . _rt_manager . update_local_rt_nlris ( ) <EOL> self . _signal_bus . vrf_added ( vrf_conf ) <EOL> def on_stats_config_change ( self , evt ) : <EOL> vrf_conf = evt . src <EOL> self . _signal_bus . stats_config_changed ( vrf_conf ) </s>
