mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-08 22:06:10 +02:00
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>
This commit is contained in:
parent
b1a3201705
commit
7c67afd263
@ -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
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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`.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user