summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2014-07-28 18:22:56 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-07-28 19:13:21 +0900
commite8d81ab194e99750186a1a08e6ab4adc1e4f494f (patch)
treea2756c74b9906f7209c6fec3081cfc0e0e62d107
parent8c42cb30245c61ced13586a06a323ea76471ded2 (diff)
bgp: enable filter configuration via configuration file
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/services/protocols/bgp/rtconf/base.py5
-rw-r--r--ryu/services/protocols/bgp/rtconf/neighbors.py51
2 files changed, 47 insertions, 9 deletions
diff --git a/ryu/services/protocols/bgp/rtconf/base.py b/ryu/services/protocols/bgp/rtconf/base.py
index e7578f87..8dc46658 100644
--- a/ryu/services/protocols/bgp/rtconf/base.py
+++ b/ryu/services/protocols/bgp/rtconf/base.py
@@ -63,9 +63,6 @@ MULTI_EXIT_DISC = 'multi_exit_disc'
# Extended community attribute route origin.
SITE_OF_ORIGINS = 'site_of_origins'
-# OUT FILTER
-OUT_FILTER = 'out_filter'
-
# Constants related to errors.
CONF_NAME = 'conf_name'
CONF_VALUE = 'conf_value'
@@ -714,7 +711,7 @@ def compute_optional_conf(conf_name, default_value, **all_config):
conf_value = all_config.get(conf_name)
if conf_value is not None:
# Validate configuration value.
- get_validator(conf_name)(conf_value)
+ conf_value = get_validator(conf_name)(conf_value)
else:
conf_value = default_value
return conf_value
diff --git a/ryu/services/protocols/bgp/rtconf/neighbors.py b/ryu/services/protocols/bgp/rtconf/neighbors.py
index e41c078c..39b58e30 100644
--- a/ryu/services/protocols/bgp/rtconf/neighbors.py
+++ b/ryu/services/protocols/bgp/rtconf/neighbors.py
@@ -59,9 +59,9 @@ from ryu.services.protocols.bgp.rtconf.base import SITE_OF_ORIGINS
from ryu.services.protocols.bgp.rtconf.base import validate
from ryu.services.protocols.bgp.rtconf.base import validate_med
from ryu.services.protocols.bgp.rtconf.base import validate_soo_list
-from ryu.services.protocols.bgp.rtconf.base import OUT_FILTER
from ryu.services.protocols.bgp.utils.validation import is_valid_ipv4
from ryu.services.protocols.bgp.utils.validation import is_valid_old_asn
+from ryu.services.protocols.bgp.info_base.base import PrefixList
LOG = logging.getLogger('bgpspeaker.rtconf.neighbor')
@@ -87,6 +87,7 @@ DEFAULT_CAP_MBGP_VPNV6 = False
DEFAULT_HOLD_TIME = 40
DEFAULT_ENABLED = True
DEFAULT_CAP_RTC = False
+DEFAULT_OUT_FILTER = []
# Default value for *MAX_PREFIXES* setting is set to 0.
DEFAULT_MAX_PREFIXES = 0
@@ -166,6 +167,46 @@ def validate_remote_as(asn):
return asn
+def valid_prefix_filter(filter_):
+ policy = filter_.get('policy', None)
+ if policy == 'permit':
+ policy = PrefixList.POLICY_PERMIT
+ else:
+ policy = PrefixList.POLICY_DENY
+ prefix = filter_['prefix']
+ ge = filter_.get('ge', None)
+ le = filter_.get('le', None)
+ return PrefixList(prefix, policy, ge=ge, le=le)
+
+PREFIX_FILTER = 'prefix_filter'
+
+SUPPORTED_FILTER_VALIDATORS = {
+ PREFIX_FILTER: valid_prefix_filter
+}
+
+
+def valid_filter(filter_):
+ if not isinstance(filter_, dict):
+ raise ConfigTypeError(desc='Invalid filter: %s' % filter_)
+
+ if 'type' not in filter_:
+ raise ConfigTypeError(desc='Invalid filter: %s, needs \'type\' field'
+ % filter_)
+
+ if not filter_['type'] in SUPPORTED_FILTER_VALIDATORS:
+ raise ConfigTypeError(desc='Invalid filter type: %s, supported filter'
+ ' types are %s'
+ % (filter_['type'],
+ SUPPORTED_FILTER_VALIDATORS.keys()))
+
+ return SUPPORTED_FILTER_VALIDATORS[filter_['type']](filter_)
+
+
+@validate(name=OUT_FILTER)
+def validate_out_filters(filters):
+ return [valid_filter(filter_) for filter_ in filters]
+
+
class NeighborConf(ConfWithId, ConfWithStats):
"""Class that encapsulates one neighbors' configuration."""
@@ -184,7 +225,8 @@ class NeighborConf(ConfWithId, ConfWithStats):
ENABLED, MULTI_EXIT_DISC, MAX_PREFIXES,
ADVERTISE_PEER_AS, SITE_OF_ORIGINS,
LOCAL_ADDRESS, LOCAL_PORT,
- PEER_NEXT_HOP, PASSWORD])
+ PEER_NEXT_HOP, PASSWORD,
+ OUT_FILTER])
def __init__(self, **kwargs):
super(NeighborConf, self).__init__(**kwargs)
@@ -210,6 +252,8 @@ class NeighborConf(ConfWithId, ConfWithStats):
MAX_PREFIXES, DEFAULT_MAX_PREFIXES, **kwargs)
self._settings[ADVERTISE_PEER_AS] = compute_optional_conf(
ADVERTISE_PEER_AS, DEFAULT_ADVERTISE_PEER_AS, **kwargs)
+ self._settings[OUT_FILTER] = compute_optional_conf(
+ OUT_FILTER, DEFAULT_OUT_FILTER, **kwargs)
# We do not have valid default MED value.
# If no MED attribute is provided then we do not have to use MED.
@@ -249,9 +293,6 @@ class NeighborConf(ConfWithId, ConfWithStats):
self._settings[RTC_AS] = \
compute_optional_conf(RTC_AS, default_rt_as, **kwargs)
- # out filter configuration
- self._settings[OUT_FILTER] = []
-
# Since ConfWithId' default values use str(self) and repr(self), we
# call super method after we have initialized other settings.
super(NeighborConf, self)._init_opt_settings(**kwargs)