diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2014-03-31 06:33:37 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-04-01 17:29:16 +0900 |
commit | 7c67afd263e0d3f7ed5fc506076a55c59a995bcd (patch) | |
tree | 24108d635648e3669f429b3400db2b107b2c15f8 | |
parent | b1a320170509e6ff04afb370fd1bacbc74c62dc1 (diff) |
bgp: enable to propagate ipv4 networks
Newly add an api network.add to add a ipv4 network to propagate.
Networks can be registered in configure file using networks direction
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/api/rtconf.py | 12 | ||||
-rw-r--r-- | ryu/services/protocols/bgp/application.py | 18 | ||||
-rw-r--r-- | ryu/services/protocols/bgp/core_managers/table_manager.py | 20 |
3 files changed, 50 insertions, 0 deletions
diff --git a/ryu/services/protocols/bgp/api/rtconf.py b/ryu/services/protocols/bgp/api/rtconf.py index aca14a26..49e80229 100644 --- a/ryu/services/protocols/bgp/api/rtconf.py +++ b/ryu/services/protocols/bgp/api/rtconf.py @@ -167,3 +167,15 @@ def get_vrf(route_dist, route_family=VRF_RF_IPV4): def get_vrfs_conf(): vrfs_conf = CORE_MANAGER.vrfs_conf return vrfs_conf.settings + +#============================================================================== +# network configuration related APIs +#============================================================================== + +@register(name='network.add') +def add_network(prefix): + tm = CORE_MANAGER.get_core_service().table_manager + tm.add_to_ipv4_global_table(prefix) + return True + + diff --git a/ryu/services/protocols/bgp/application.py b/ryu/services/protocols/bgp/application.py index b09253b1..5a991eb7 100644 --- a/ryu/services/protocols/bgp/application.py +++ b/ryu/services/protocols/bgp/application.py @@ -165,6 +165,9 @@ class BaseApplication(object): # Add Vrfs. self._add_vrfs(routing_settings) + # Add Networks + self._add_networks(routing_settings) + def _add_neighbors(self, routing_settings): """Add bgp peers/neighbors from given settings to BGPS runtime. @@ -196,3 +199,18 @@ class BaseApplication(object): except RuntimeConfigError as e: LOG.error(e) continue + + def _add_networks(self, routing_settings): + """Add networks from given settings to BGPS runtime. + + If any of the networks are miss-configured errors are logged. + All valid networks are loaded. + """ + networks = routing_settings.setdefault('networks', []) + for prefix in networks: + try: + call('network.add', prefix=prefix) + LOG.debug('Added network %s' % str(prefix)) + except RuntimeConfigError as e: + LOG.error(e) + continue diff --git a/ryu/services/protocols/bgp/core_managers/table_manager.py b/ryu/services/protocols/bgp/core_managers/table_manager.py index 5554e4a1..60a624fa 100644 --- a/ryu/services/protocols/bgp/core_managers/table_manager.py +++ b/ryu/services/protocols/bgp/core_managers/table_manager.py @@ -1,4 +1,5 @@ import logging +from collections import OrderedDict from ryu.services.protocols.bgp.base import SUPPORTED_GLOBAL_RF from ryu.services.protocols.bgp.info_base.rtc import RtcTable @@ -13,6 +14,7 @@ from ryu.services.protocols.bgp.info_base.vrf6 import Vrf6Table from ryu.services.protocols.bgp.rtconf import vrfs from ryu.services.protocols.bgp.rtconf.vrfs import VRF_RF_IPV4 from ryu.services.protocols.bgp.rtconf.vrfs import VRF_RF_IPV6 +from ryu.services.protocols.bgp.protocols.bgp import pathattr from ryu.services.protocols.bgp.protocols.bgp import nlri from ryu.services.protocols.bgp.utils.validation import is_valid_ipv4 from ryu.services.protocols.bgp.utils.validation import is_valid_ipv4_prefix @@ -468,6 +470,24 @@ class TableCoreManager(object): gen_lbl=True ) + def add_to_ipv4_global_table(self, prefix): + _nlri = nlri.Ipv4(prefix) + src_ver_num = 1 + peer = None + # set mandatory path attributes + nexthop = pathattr.NextHop("0.0.0.0") + origin = pathattr.Origin('igp') + aspath = pathattr.AsPath([[]]) + + pathattrs = OrderedDict() + pathattrs[origin.ATTR_NAME] = origin + pathattrs[aspath.ATTR_NAME] = aspath + + new_path = Ipv4Path(peer, _nlri, src_ver_num, + pattrs=pathattrs, nexthop=nexthop) + # add to global ipv4 table and propagates to neighbors + self.learn_path(new_path) + def remove_from_vrf(self, route_dist, prefix, route_family): """Removes `prefix` from VRF identified by `route_dist`. |