From b91fe7feb87799d1d12224c129d1064605ae6ff5 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Thu, 30 Apr 2020 18:02:33 +0200 Subject: Add as_path parameter to network.add --- ryu/services/protocols/bgp/api/base.py | 1 + ryu/services/protocols/bgp/api/rtconf.py | 4 ++-- ryu/services/protocols/bgp/bgpspeaker.py | 5 ++++- ryu/services/protocols/bgp/core_managers/table_manager.py | 6 ++++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ryu/services/protocols/bgp/api/base.py b/ryu/services/protocols/bgp/api/base.py index 6c4d0fa1..598ee04b 100644 --- a/ryu/services/protocols/bgp/api/base.py +++ b/ryu/services/protocols/bgp/api/base.py @@ -57,6 +57,7 @@ PMSI_TUNNEL_TYPE = 'pmsi_tunnel_type' FLOWSPEC_FAMILY = 'flowspec_family' FLOWSPEC_RULES = 'rules' FLOWSPEC_ACTIONS = 'actions' +AS_PATH = 'as_path' # API call registry _CALL_REGISTRY = {} diff --git a/ryu/services/protocols/bgp/api/rtconf.py b/ryu/services/protocols/bgp/api/rtconf.py index d981499b..82da22f0 100644 --- a/ryu/services/protocols/bgp/api/rtconf.py +++ b/ryu/services/protocols/bgp/api/rtconf.py @@ -273,9 +273,9 @@ def get_vrfs_conf(): @register(name='network.add') -def add_network(prefix, next_hop=None): +def add_network(prefix, next_hop=None, as_path=None): tm = CORE_MANAGER.get_core_service().table_manager - tm.update_global_table(prefix, next_hop) + tm.update_global_table(prefix, next_hop, as_path=as_path) return True diff --git a/ryu/services/protocols/bgp/bgpspeaker.py b/ryu/services/protocols/bgp/bgpspeaker.py index 2f53f636..614bbf55 100644 --- a/ryu/services/protocols/bgp/bgpspeaker.py +++ b/ryu/services/protocols/bgp/bgpspeaker.py @@ -43,6 +43,7 @@ from ryu.services.protocols.bgp.api.base import ROUTE_FAMILY from ryu.services.protocols.bgp.api.base import EVPN_VNI from ryu.services.protocols.bgp.api.base import TUNNEL_TYPE from ryu.services.protocols.bgp.api.base import PMSI_TUNNEL_TYPE +from ryu.services.protocols.bgp.api.base import AS_PATH from ryu.services.protocols.bgp.api.prefix import EVPN_MAX_ET from ryu.services.protocols.bgp.api.prefix import ESI_TYPE_LACP from ryu.services.protocols.bgp.api.prefix import ESI_TYPE_L2_BRIDGE @@ -629,7 +630,7 @@ class BGPSpeaker(object): return call('operator.show', **show) - def prefix_add(self, prefix, next_hop=None, route_dist=None): + def prefix_add(self, prefix, next_hop=None, as_path=None, route_dist=None): """ This method adds a new prefix to be advertised. ``prefix`` must be the string representation of an IP network @@ -649,6 +650,8 @@ class BGPSpeaker(object): } if next_hop: networks[NEXT_HOP] = next_hop + if as_path: + networks[AS_PATH] = as_path if route_dist: func_name = 'prefix.add_local' networks[ROUTE_DISTINGUISHER] = route_dist diff --git a/ryu/services/protocols/bgp/core_managers/table_manager.py b/ryu/services/protocols/bgp/core_managers/table_manager.py index 432a1a46..b60b785d 100644 --- a/ryu/services/protocols/bgp/core_managers/table_manager.py +++ b/ryu/services/protocols/bgp/core_managers/table_manager.py @@ -772,7 +772,7 @@ class TableCoreManager(object): nlri=prefix, communities=communities, is_withdraw=is_withdraw) - def update_global_table(self, prefix, next_hop=None, is_withdraw=False): + def update_global_table(self, prefix, next_hop=None, is_withdraw=False, as_path=None): """Update a BGP route in the Global table for the given `prefix` with the given `next_hop`. @@ -782,9 +782,11 @@ class TableCoreManager(object): """ src_ver_num = 1 peer = None + if as_path is None: + as_path = [[]] # set mandatory path attributes origin = BGPPathAttributeOrigin(BGP_ATTR_ORIGIN_IGP) - aspath = BGPPathAttributeAsPath([[]]) + aspath = BGPPathAttributeAsPath(as_path) pathattrs = OrderedDict() pathattrs[BGP_ATTR_TYPE_ORIGIN] = origin -- cgit v1.2.3