bgp: Enable to configure default local preference

This patch enables to configure the default local preference.
If not specified, the value will be 100 as a default.

Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Satoshi Fujimoto 2017-04-04 14:44:52 +09:00 committed by FUJITA Tomonori
parent 2354bd7df3
commit 09fa78182f
5 changed files with 38 additions and 4 deletions

View File

@ -43,6 +43,8 @@ from ryu.services.protocols.bgp.rtconf.common import LOCAL_AS
from ryu.services.protocols.bgp.rtconf.common import REFRESH_MAX_EOR_TIME
from ryu.services.protocols.bgp.rtconf.common import REFRESH_STALEPATH_TIME
from ryu.services.protocols.bgp.rtconf.common import ROUTER_ID
from ryu.services.protocols.bgp.rtconf.common import LOCAL_PREF
from ryu.services.protocols.bgp.rtconf.common import DEFAULT_LOCAL_PREF
from ryu.services.protocols.bgp.utils.validation import is_valid_ipv4
from ryu.services.protocols.bgp.utils.validation import is_valid_ipv6
@ -262,6 +264,8 @@ class RyuBGPSpeaker(RyuApp):
LABEL_RANGE, DEFAULT_LABEL_RANGE)
bgp_settings['allow_local_as_in_count'] = settings.get(
'allow_local_as_in_count', 0)
bgp_settings[LOCAL_PREF] = settings.get(
LOCAL_PREF, DEFAULT_LOCAL_PREF)
# Create BGPSpeaker instance.
LOG.debug('Starting BGPSpeaker...')

View File

@ -30,6 +30,9 @@ BGP = {
# BGP Router ID.
'router_id': '172.17.0.1',
# Default local preference
'local_pref': 100,
# List of BGP neighbors.
# The parameters for each neighbor are the same as the arguments of
# BGPSpeaker.neighbor_add() method.

View File

@ -72,6 +72,8 @@ from ryu.services.protocols.bgp.rtconf.common import REFRESH_MAX_EOR_TIME
from ryu.services.protocols.bgp.rtconf.common import REFRESH_STALEPATH_TIME
from ryu.services.protocols.bgp.rtconf.common import LABEL_RANGE
from ryu.services.protocols.bgp.rtconf.common import ALLOW_LOCAL_AS_IN_COUNT
from ryu.services.protocols.bgp.rtconf.common import LOCAL_PREF
from ryu.services.protocols.bgp.rtconf.common import DEFAULT_LOCAL_PREF
from ryu.services.protocols.bgp.rtconf import neighbors
from ryu.services.protocols.bgp.rtconf import vrfs
from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_IPV4
@ -198,7 +200,8 @@ class BGPSpeaker(object):
ssh_port=None, ssh_host=None, ssh_host_key=None,
label_range=DEFAULT_LABEL_RANGE,
allow_local_as_in_count=0,
cluster_id=None):
cluster_id=None,
local_pref=DEFAULT_LOCAL_PREF):
"""Create a new BGPSpeaker object with as_number and router_id to
listen on bgp_server_port.
@ -256,6 +259,9 @@ class BGPSpeaker(object):
``cluster_id`` specifies the cluster identifier for Route Reflector.
It must be the string representation of an IPv4 address.
If omitted, "router_id" is used for this field.
``local_pref`` specifies the default local preference. It must be an
integer.
"""
super(BGPSpeaker, self).__init__()
@ -269,6 +275,7 @@ class BGPSpeaker(object):
LABEL_RANGE: label_range,
ALLOW_LOCAL_AS_IN_COUNT: allow_local_as_in_count,
CLUSTER_ID: cluster_id,
LOCAL_PREF: local_pref,
}
self._core_start(settings)
self._init_signal_listeners()

View File

@ -1162,8 +1162,10 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
# For iBGP peers we are required to send local-pref attribute
# for connected or local prefixes. We check if the path matches
# attribute_maps and set local-pref value.
# If the path doesn't match, we set default local-pref 100.
localpref_attr = BGPPathAttributeLocalPref(100)
# If the path doesn't match, we set default local-pref given
# from the user. The default value is 100.
localpref_attr = BGPPathAttributeLocalPref(
self._common_conf.local_pref)
key = const.ATTR_MAPS_LABEL_DEFAULT
if isinstance(path, (Vpnv4Path, Vpnv6Path)):

View File

@ -41,6 +41,7 @@ CLUSTER_ID = 'cluster_id'
LABEL_RANGE = 'label_range'
LABEL_RANGE_MAX = 'max'
LABEL_RANGE_MIN = 'min'
LOCAL_PREF = 'local_pref'
# Similar to Cisco command 'allowas-in'. Allows the local ASN in the path.
# Facilitates auto rd, auto rt import/export
@ -85,6 +86,7 @@ DEFAULT_TCP_CONN_TIMEOUT = 30
DEFAULT_BGP_CONN_RETRY_TIME = 30
DEFAULT_MED = 0
DEFAULT_MAX_PATH_EXT_RTFILTER_ALL = True
DEFAULT_LOCAL_PREF = 100
@validate(name=ALLOW_LOCAL_AS_IN_COUNT)
@ -219,6 +221,15 @@ def validate_max_path_ext_rtfilter_all(max_path_ext_rtfilter_all):
return max_path_ext_rtfilter_all
@validate(name=LOCAL_PREF)
def validate_local_pref(local_pref):
if not isinstance(local_pref, numbers.Integral):
raise ConfigTypeError(desc=('Invalid local_pref'
' configuration value %s' %
local_pref))
return local_pref
class CommonConf(BaseConf):
"""Encapsulates configurations applicable to all peer sessions.
@ -238,7 +249,8 @@ class CommonConf(BaseConf):
BGP_CONN_RETRY_TIME,
MAX_PATH_EXT_RTFILTER_ALL,
ALLOW_LOCAL_AS_IN_COUNT,
CLUSTER_ID])
CLUSTER_ID,
LOCAL_PREF])
def __init__(self, **kwargs):
super(CommonConf, self).__init__(**kwargs)
@ -264,6 +276,8 @@ class CommonConf(BaseConf):
**kwargs)
self._settings[CLUSTER_ID] = compute_optional_conf(
CLUSTER_ID, kwargs[ROUTER_ID], **kwargs)
self._settings[LOCAL_PREF] = compute_optional_conf(
LOCAL_PREF, DEFAULT_LOCAL_PREF, **kwargs)
# =========================================================================
# Required attributes
@ -316,6 +330,10 @@ class CommonConf(BaseConf):
def max_path_ext_rtfilter_all(self):
return self._settings[MAX_PATH_EXT_RTFILTER_ALL]
@property
def local_pref(self):
return self._settings[LOCAL_PREF]
@classmethod
def get_opt_settings(self):
self_confs = super(CommonConf, self).get_opt_settings()