<s> """<STR_LIT>""" <EOL> import logging <EOL> import numbers <EOL> from ryu . services . protocols . bgp . utils . validation import is_valid_ipv4 <EOL> from ryu . services . protocols . bgp . utils . validation import is_valid_old_asn <EOL> from ryu . services . protocols . bgp import rtconf <EOL> from ryu . services . protocols . bgp . rtconf . base import BaseConf <EOL> from ryu . services . protocols . bgp . rtconf . base import BaseConfListener <EOL> from ryu . services . protocols . bgp . rtconf . base import compute_optional_conf <EOL> from ryu . services . protocols . bgp . rtconf . base import ConfigTypeError <EOL> from ryu . services . protocols . bgp . rtconf . base import ConfigValueError <EOL> from ryu . services . protocols . bgp . rtconf . base import MissingRequiredConf <EOL> from ryu . services . protocols . bgp . rtconf . base import validate <EOL> LOG = logging . getLogger ( '<STR_LIT>' ) <EOL> LOCAL_AS = '<STR_LIT>' <EOL> ROUTER_ID = '<STR_LIT>' <EOL> LABEL_RANGE = '<STR_LIT>' <EOL> LABEL_RANGE_MAX = '<STR_LIT>' <EOL> LABEL_RANGE_MIN = '<STR_LIT>' <EOL> REFRESH_STALEPATH_TIME = '<STR_LIT>' <EOL> REFRESH_MAX_EOR_TIME = '<STR_LIT>' <EOL> BGP_CONN_RETRY_TIME = '<STR_LIT>' <EOL> BGP_SERVER_PORT = '<STR_LIT>' <EOL> TCP_CONN_TIMEOUT = '<STR_LIT>' <EOL> MAX_PATH_EXT_RTFILTER_ALL = '<STR_LIT>' <EOL> DEFAULT_LABEL_RANGE = ( <NUM_LIT:100> , <NUM_LIT> ) <EOL> DEFAULT_REFRESH_STALEPATH_TIME = <NUM_LIT:0> <EOL> DEFAULT_REFRESH_MAX_EOR_TIME = <NUM_LIT:0> <EOL> DEFAULT_BGP_SERVER_PORT = <NUM_LIT> <EOL> DEFAULT_TCP_CONN_TIMEOUT = <NUM_LIT:30> <EOL> DEFAULT_BGP_CONN_RETRY_TIME = <NUM_LIT:30> <EOL> DEFAULT_MED = <NUM_LIT:0> <EOL> DEFAULT_MAX_PATH_EXT_RTFILTER_ALL = True <EOL> @ validate ( name = LOCAL_AS ) <EOL> def validate_local_as ( asn ) : <EOL> if asn is None : <EOL> raise MissingRequiredConf ( conf_name = LOCAL_AS ) <EOL> if not is_valid_old_asn ( asn ) : <EOL> raise ConfigValueError ( desc = '<STR_LIT>' <EOL> % asn ) <EOL> return asn <EOL> @ validate ( name = ROUTER_ID ) <EOL> def validate_router_id ( router_id ) : <EOL> if not router_id : <EOL> raise MissingRequiredConf ( conf_name = ROUTER_ID ) <EOL> if not isinstance ( router_id , str ) : <EOL> raise ConfigTypeError ( conf_name = ROUTER_ID ) <EOL> if not is_valid_ipv4 ( router_id ) : <EOL> raise ConfigValueError ( desc = '<STR_LIT>' % router_id ) <EOL> return router_id <EOL> @ validate ( name = REFRESH_STALEPATH_TIME ) <EOL> def validate_refresh_stalepath_time ( rst ) : <EOL> if not isinstance ( rst , numbers . Integral ) : <EOL> raise ConfigTypeError ( desc = ( '<STR_LIT>' <EOL> '<STR_LIT>' % REFRESH_STALEPATH_TIME ) ) <EOL> if rst < <NUM_LIT:0> : <EOL> raise ConfigValueError ( desc = '<STR_LIT>' % rst ) <EOL> return rst <EOL> @ validate ( name = REFRESH_MAX_EOR_TIME ) <EOL> def validate_refresh_max_eor_time ( rmet ) : <EOL> if not isinstance ( rmet , numbers . Integral ) : <EOL> raise ConfigTypeError ( desc = ( '<STR_LIT>' <EOL> '<STR_LIT>' % REFRESH_MAX_EOR_TIME ) ) <EOL> if rmet < <NUM_LIT:0> : <EOL> raise ConfigValueError ( desc = '<STR_LIT>' % rmet ) <EOL> return rmet <EOL> @ validate ( name = LABEL_RANGE ) <EOL> def validate_label_range ( label_range ) : <EOL> min_label , max_label = label_range <EOL> if ( not min_label or <EOL> not max_label or <EOL> not isinstance ( min_label , numbers . Integral ) or <EOL> not isinstance ( max_label , numbers . Integral ) or min_label < <NUM_LIT> or <EOL> min_label >= max_label ) : <EOL> raise ConfigValueError ( desc = ( '<STR_LIT>' <EOL> '<STR_LIT>' % label_range ) ) <EOL> return label_range <EOL> @ validate ( name = BGP_SERVER_PORT ) <EOL> def validate_bgp_server_port ( server_port ) : <EOL> if not isinstance ( server_port , numbers . Integral ) : <EOL> raise ConfigTypeError ( desc = ( '<STR_LIT>' <EOL> '<STR_LIT>' % server_port ) ) <EOL> if server_port < <NUM_LIT:0> or server_port > <NUM_LIT> : <EOL> raise ConfigValueError ( desc = '<STR_LIT>' % server_port ) <EOL> return server_port <EOL> @ validate ( name = TCP_CONN_TIMEOUT ) <EOL> def validate_tcp_conn_timeout ( tcp_conn_timeout ) : <EOL> if not isinstance ( tcp_conn_timeout , numbers . Integral ) : <EOL> raise ConfigTypeError ( desc = ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> tcp_conn_timeout ) ) <EOL> if tcp_conn_timeout < <NUM_LIT:10> : <EOL> raise ConfigValueError ( desc = ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> tcp_conn_timeout ) ) <EOL> return tcp_conn_timeout <EOL> @ validate ( name = BGP_CONN_RETRY_TIME ) <EOL> def validate_bgp_conn_retry_time ( bgp_conn_retry_time ) : <EOL> if not isinstance ( bgp_conn_retry_time , numbers . Integral ) : <EOL> raise ConfigTypeError ( desc = ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> bgp_conn_retry_time ) ) <EOL> if bgp_conn_retry_time < <NUM_LIT:10> : <EOL> raise ConfigValueError ( desc = ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> bgp_conn_retry_time ) ) <EOL> return bgp_conn_retry_time <EOL> @ validate ( name = MAX_PATH_EXT_RTFILTER_ALL ) <EOL> def validate_max_path_ext_rtfilter_all ( max_path_ext_rtfilter_all ) : <EOL> if max_path_ext_rtfilter_all not in ( True , False ) : <EOL> raise ConfigTypeError ( desc = ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> max_path_ext_rtfilter_all ) ) <EOL> return max_path_ext_rtfilter_all <EOL> class CommonConf ( BaseConf ) : <EOL> """<STR_LIT>""" <EOL> CONF_CHANGED_EVT = <NUM_LIT:1> <EOL> VALID_EVT = frozenset ( [ CONF_CHANGED_EVT ] ) <EOL> REQUIRED_SETTINGS = frozenset ( [ ROUTER_ID , LOCAL_AS ] ) <EOL> OPTIONAL_SETTINGS = frozenset ( [ REFRESH_STALEPATH_TIME , <EOL> REFRESH_MAX_EOR_TIME , <EOL> LABEL_RANGE , BGP_SERVER_PORT , <EOL> TCP_CONN_TIMEOUT , <EOL> BGP_CONN_RETRY_TIME , <EOL> MAX_PATH_EXT_RTFILTER_ALL ] ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( CommonConf , self ) . __init__ ( ** kwargs ) <EOL> def _init_opt_settings ( self , ** kwargs ) : <EOL> super ( CommonConf , self ) . _init_opt_settings ( ** kwargs ) <EOL> self . _settings [ LABEL_RANGE ] = compute_optional_conf ( <EOL> LABEL_RANGE , DEFAULT_LABEL_RANGE , ** kwargs ) <EOL> self . _settings [ REFRESH_STALEPATH_TIME ] = compute_optional_conf ( <EOL> REFRESH_STALEPATH_TIME , DEFAULT_REFRESH_STALEPATH_TIME , ** kwargs ) <EOL> self . _settings [ REFRESH_MAX_EOR_TIME ] = compute_optional_conf ( <EOL> REFRESH_MAX_EOR_TIME , DEFAULT_REFRESH_MAX_EOR_TIME , ** kwargs ) <EOL> self . _settings [ BGP_SERVER_PORT ] = compute_optional_conf ( <EOL> BGP_SERVER_PORT , DEFAULT_BGP_SERVER_PORT , ** kwargs ) <EOL> self . _settings [ TCP_CONN_TIMEOUT ] = compute_optional_conf ( <EOL> TCP_CONN_TIMEOUT , DEFAULT_TCP_CONN_TIMEOUT , ** kwargs ) <EOL> self . _settings [ BGP_CONN_RETRY_TIME ] = compute_optional_conf ( <EOL> BGP_CONN_RETRY_TIME , DEFAULT_BGP_CONN_RETRY_TIME , ** kwargs ) <EOL> self . _settings [ MAX_PATH_EXT_RTFILTER_ALL ] = compute_optional_conf ( <EOL> MAX_PATH_EXT_RTFILTER_ALL , DEFAULT_MAX_PATH_EXT_RTFILTER_ALL , <EOL> ** kwargs ) <EOL> @ property <EOL> def local_as ( self ) : <EOL> return self . _settings [ LOCAL_AS ] <EOL> @ property <EOL> def router_id ( self ) : <EOL> return self . _settings [ ROUTER_ID ] <EOL> @ property <EOL> def bgp_conn_retry_time ( self ) : <EOL> return self . _settings [ BGP_CONN_RETRY_TIME ] <EOL> @ property <EOL> def tcp_conn_timeout ( self ) : <EOL> return self . _settings [ TCP_CONN_TIMEOUT ] <EOL> @ property <EOL> def refresh_stalepath_time ( self ) : <EOL> return self . _settings [ REFRESH_STALEPATH_TIME ] <EOL> @ property <EOL> def refresh_max_eor_time ( self ) : <EOL> return self . _settings [ REFRESH_MAX_EOR_TIME ] <EOL> @ property <EOL> def label_range ( self ) : <EOL> return self . _settings [ LABEL_RANGE ] <EOL> @ property <EOL> def bgp_server_port ( self ) : <EOL> return self . _settings [ BGP_SERVER_PORT ] <EOL> @ property <EOL> def max_path_ext_rtfilter_all ( self ) : <EOL> return self . _settings [ MAX_PATH_EXT_RTFILTER_ALL ] <EOL> @ classmethod <EOL> def get_opt_settings ( self ) : <EOL> self_confs = super ( CommonConf , self ) . get_opt_settings ( ) <EOL> self_confs . update ( CommonConf . OPTIONAL_SETTINGS ) <EOL> return self_confs <EOL> @ classmethod <EOL> def get_req_settings ( self ) : <EOL> self_confs = super ( CommonConf , self ) . get_req_settings ( ) <EOL> self_confs . update ( CommonConf . REQUIRED_SETTINGS ) <EOL> return self_confs <EOL> @ classmethod <EOL> def get_valid_evts ( self ) : <EOL> self_valid_evts = super ( CommonConf , self ) . get_valid_evts ( ) <EOL> self_valid_evts . update ( CommonConf . VALID_EVT ) <EOL> return self_valid_evts <EOL> def update ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( CommonConf , self ) . update ( ** kwargs ) <EOL> conf_changed = False <EOL> for conf_name , conf_value in kwargs . items ( ) : <EOL> rtconf . base . get_validator ( conf_name ) ( conf_value ) <EOL> item1 = self . _settings . get ( conf_name , None ) <EOL> item2 = kwargs . get ( conf_name , None ) <EOL> if item1 != item2 : <EOL> conf_changed = True <EOL> if conf_changed : <EOL> for conf_name , conf_value in kwargs . items ( ) : <EOL> self . _settings [ conf_name ] = conf_value <EOL> self . _notify_listeners ( CommonConf . CONF_CHANGED_EVT , self ) <EOL> class CommonConfListener ( BaseConfListener ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , global_conf ) : <EOL> super ( CommonConfListener , self ) . __init__ ( global_conf ) <EOL> global_conf . add_listener ( CommonConf . CONF_CHANGED_EVT , <EOL> self . on_update_common_conf ) <EOL> def on_update_common_conf ( self , evt ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) </s>
