def validate_local_port(port): if not isinstance(port, numbers.Integral): raise ConfigTypeError(desc='Invalid local port: %s' % port) if port < 1025 or port > 65535: raise ConfigValueError(desc='Invalid local port value: %s, has to be' ' between 1025 and 65535' % port) return port
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 validate_router_id(cluster_id): if not isinstance(cluster_id, str): raise ConfigTypeError(conf_name=CLUSTER_ID) if not is_valid_ipv4(cluster_id): raise ConfigValueError(desc='Invalid cluster id %s' % cluster_id) return cluster_id
def validate_refresh_stalepath_time(rst): if not isinstance(rst, numbers.Integral): raise ConfigTypeError(desc=('Configuration value for %s has to be ' 'integral type' % REFRESH_STALEPATH_TIME)) if rst < 0: raise ConfigValueError(desc='Invalid refresh stalepath time %s' % rst) return rst
def validate_refresh_max_eor_time(rmet): if not isinstance(rmet, numbers.Integral): raise ConfigTypeError(desc=('Configuration value for %s has to be of ' 'integral type ' % REFRESH_MAX_EOR_TIME)) if rmet < 0: raise ConfigValueError(desc='Invalid refresh stalepath time %s' % rmet) return rmet
def validate_bgp_server_port(server_port): if not isinstance(server_port, numbers.Integral): raise ConfigTypeError(desc=('Invalid bgp sever port configuration ' 'value %s' % server_port)) if server_port < 0 or server_port > 65535: raise ConfigValueError(desc='Invalid server port %s' % server_port) return server_port
def validate_allow_local_as_in_count(count): if not isinstance(count, numbers.Integral): raise ConfigTypeError(desc=('Configuration value for %s has to be ' 'integral type' % ALLOW_LOCAL_AS_IN_COUNT)) if count < 0: raise ConfigValueError(desc='Invalid local AS count %s' % count) return count
def validate_local_as(asn): if asn is None: raise MissingRequiredConf(conf_name=LOCAL_AS) if not is_valid_old_asn(asn): raise ConfigValueError( desc='Invalid local_as configuration value: %s' % asn) return asn
def is_valid_ip_addr(addr): # Note: Allows empty IP Address (means length=0). # e.g.) L2VPN MAC advertisement of Cisco NX-OS if not (addr is None or validation.is_valid_ipv4(addr) or validation.is_valid_ipv6(addr)): raise ConfigValueError(conf_name=IP_ADDR, conf_value=addr)
def validate_import_rts(import_rts): if not isinstance(import_rts, list): raise ConfigTypeError(conf_name=IMPORT_RTS, conf_value=import_rts) if not (len(import_rts) <= MAX_NUM_IMPORT_RT): raise ConfigValueError(desc='Max. import RT is limited to %s' % MAX_NUM_IMPORT_RT) try: ExtCommunity.validate_supported_attributes(import_rts) except ValueError: raise ConfigValueError(conf_name=IMPORT_RTS, conf_value=import_rts) # Check if we have duplicates unique_rts = set(import_rts) if len(unique_rts) != len(import_rts): raise ConfigValueError(desc='Duplicate value provided %s' % (import_rts)) return import_rts
def valdiate_rd(route_disc): if not isinstance(route_disc, str): raise ConfigTypeError(conf_name=ROUTE_DISTINGUISHER, conf_value=route_disc) if not validation.is_valid_route_disc(route_disc): raise ConfigValueError(conf_name=ROUTE_DISTINGUISHER, conf_value=route_disc) return route_disc
def validate_changes(changes): for k, v in changes.iteritems(): if k not in (MULTI_EXIT_DISC, ENABLED): raise ConfigValueError(desc="Unknown field to change: %s" % k) if k == MULTI_EXIT_DISC: validate_med(v) elif k == ENABLED: validate_enabled(v) return changes
def validate_router_id(router_id): if not router_id: raise MissingRequiredConf(conf_name=ROUTER_ID) if not isinstance(router_id, str): raise ConfigTypeError(conf_name=ROUTER_ID) if not is_valid_ipv4(router_id): raise ConfigValueError(desc='Invalid router id %s' % router_id) return router_id
def validate_label_range(label_range): min_label, max_label = label_range if (not min_label or not max_label or not isinstance(min_label, numbers.Integral) or not isinstance(max_label, numbers.Integral) or min_label < 17 or min_label >= max_label): raise ConfigValueError(desc=('Invalid label_range configuration value:' ' (%s).' % label_range)) return label_range
def validate_bgp_conn_retry_time(bgp_conn_retry_time): if not isinstance(bgp_conn_retry_time, numbers.Integral): raise ConfigTypeError(desc=('Invalid bgp conn. retry time ' 'configuration value %s' % bgp_conn_retry_time)) if bgp_conn_retry_time < 10: raise ConfigValueError(desc=('Invalid bgp connection retry time' ' configuration value %s' % bgp_conn_retry_time)) return bgp_conn_retry_time
def validate_tcp_conn_timeout(tcp_conn_timeout): # TODO(apgw-dev) made-up some valid values for this settings, check if we # have a standard value in any routers if not isinstance(tcp_conn_timeout, numbers.Integral): raise ConfigTypeError(desc=('Invalid tcp connection timeout ' 'configuration value %s' % tcp_conn_timeout)) if tcp_conn_timeout < 10: raise ConfigValueError(desc=('Invalid tcp connection timeout' ' configuration value %s' % tcp_conn_timeout)) return tcp_conn_timeout
def update(self, **kwargs): """Updates this `VrfConf` settings. Notifies listeners if any settings changed. Returns `True` if update was successful. This vrfs' route family, id and route dist settings cannot be updated/changed. """ # Update inherited configurations super(VrfConf, self).update(**kwargs) vrf_id = kwargs.get(ConfWithId.ID) vrf_rd = kwargs.get(ROUTE_DISTINGUISHER) vrf_rf = kwargs.get(VRF_RF) if (vrf_id != self.id or vrf_rd != self.route_dist or vrf_rf != self.route_family): raise ConfigValueError(desc='id/route-distinguisher/route-family' ' do not match configured value.') # Validate and update individual settings new_imp_rts, old_imp_rts = \ self._update_import_rts(**kwargs) export_rts_changed = self._update_export_rts(**kwargs) soos_list_changed = self._update_soo_list(**kwargs) med_changed = self._update_med(**kwargs) re_export_needed = (export_rts_changed or soos_list_changed or med_changed) import_maps = kwargs.get(IMPORT_MAPS, []) re_import_needed = self._update_importmaps(import_maps) # If we did have any change in value of any settings, we notify # listeners if (new_imp_rts is not None or old_imp_rts is not None or re_export_needed or re_import_needed): evt_value = ( new_imp_rts, old_imp_rts, import_maps, re_export_needed, re_import_needed ) self._notify_listeners(VrfConf.VRF_CHG_EVT, evt_value) return True
def is_valid_esi(esi): if not validation.is_valid_esi(esi): raise ConfigValueError(conf_name=EVPN_ESI, conf_value=esi)
def is_valid_ethernet_tag_id(ethernet_tag_id): if not validation.is_valid_ethernet_tag_id(ethernet_tag_id): raise ConfigValueError(conf_name=EVPN_ETHERNET_TAG_ID, conf_value=ethernet_tag_id)
def is_valid_redundancy_mode(redundancy_mode): if redundancy_mode not in SUPPORTED_REDUNDANCY_MODES: raise ConfigValueError(conf_name=REDUNDANCY_MODE, conf_value=redundancy_mode)
def is_valid_gw_ip_addr(addr): if not (validation.is_valid_ipv4(addr) or validation.is_valid_ipv6(addr)): raise ConfigValueError(conf_name=GW_IP_ADDR, conf_value=addr)
def is_valid_flowspec_rules(rules): if not isinstance(rules, dict): raise ConfigValueError(conf_name=FLOWSPEC_RULES, conf_value=rules)
def is_valid_flowspec_family(flowspec_family): if flowspec_family not in SUPPORTED_FLOWSPEC_FAMILIES: raise ConfigValueError(conf_name=FLOWSPEC_FAMILY, conf_value=flowspec_family)
def is_valid_pmsi_tunnel_type(pmsi_tunnel_type): if pmsi_tunnel_type not in SUPPORTED_PMSI_TUNNEL_TYPES: raise ConfigValueError(conf_name=PMSI_TUNNEL_TYPE, conf_value=pmsi_tunnel_type)
def is_valid_tunnel_type(tunnel_type): if tunnel_type not in SUPPORTED_TUNNEL_TYPES: raise ConfigValueError(conf_name=TUNNEL_TYPE, conf_value=tunnel_type)
def is_valid_vni(vni): if not validation.is_valid_vni(vni): raise ConfigValueError(conf_name=EVPN_VNI, conf_value=vni)
def is_valid_mac_addr(addr): if not validation.is_valid_mac(addr): raise ConfigValueError(conf_name=MAC_ADDR, conf_value=addr)
def is_valid_flowspec_actions(actions): for k in actions: if k not in SUPPORTTED_FLOWSPEC_ACTIONS: raise ConfigValueError(conf_name=FLOWSPEC_ACTIONS, conf_value=actions)
def is_valid_mpls_labels(labels): if not validation.is_valid_mpls_labels(labels): raise ConfigValueError(conf_name=MPLS_LABELS, conf_value=labels)
def is_valid_ip_prefix(prefix): if not (validation.is_valid_ipv4_prefix(prefix) or validation.is_valid_ipv6_prefix(prefix)): raise ConfigValueError(conf_name=IP_PREFIX, conf_value=prefix)