Signed-off-by: ISHIDA Wataru <ishida.wat...@lab.ntt.co.jp>
---
 ryu/services/protocols/bgp/rtconf/base.py      |    5 +--
 ryu/services/protocols/bgp/rtconf/neighbors.py |   51 +++++++++++++++++++++---
 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 e7578f8..8dc4665 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 e41c078..39b58e3 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)
-- 
1.7.10.4


------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to