Skip to content

Commit 9b84294

Browse files
committed
Revert "[bgpcfgd] ECMP overlay VxLan with BGP support (sonic-net#10716)"
This reverts commit 35c9bec.
1 parent a76899b commit 9b84294

File tree

5 files changed

+34
-263
lines changed

5 files changed

+34
-263
lines changed

src/sonic-bgpcfgd/bgpcfgd/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from .managers_intf import InterfaceMgr
1818
from .managers_setsrc import ZebraSetSrc
1919
from .managers_static_rt import StaticRouteMgr
20-
from .managers_rm import RouteMapMgr
2120
from .runner import Runner, signal_handler
2221
from .template import TemplateFabric
2322
from .utils import read_constants
@@ -61,7 +60,6 @@ def do_work():
6160
StaticRouteMgr(common_objs, "CONFIG_DB", "STATIC_ROUTE"),
6261
# Route Advertisement Managers
6362
AdvertiseRouteMgr(common_objs, "STATE_DB", swsscommon.STATE_ADVERTISE_NETWORK_TABLE_NAME),
64-
RouteMapMgr(common_objs, "APPL_DB", swsscommon.APP_BGP_PROFILE_TABLE_NAME),
6563
]
6664
runner = Runner(common_objs['cfg_mgr'])
6765
for mgr in managers:
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
from .manager import Manager
22
from .template import TemplateFabric
33
from swsscommon import swsscommon
4-
from .managers_rm import ROUTE_MAPS
5-
import ipaddress
6-
from .log import log_info, log_err, log_debug
74

85

96
class AdvertiseRouteMgr(Manager):
107
""" This class Advertises routes when ADVERTISE_NETWORK_TABLE in STATE_DB is updated """
11-
128
def __init__(self, common_objs, db, table):
139
"""
1410
Initialize the object
@@ -22,105 +18,82 @@ def __init__(self, common_objs, db, table):
2218
db,
2319
table,
2420
)
25-
21+
2622
self.directory.subscribe([("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/bgp_asn"),], self.on_bgp_asn_change)
2723
self.advertised_routes = dict()
2824

2925

30-
OP_DELETE = "DELETE"
31-
OP_ADD = "ADD"
26+
OP_DELETE = 'DELETE'
27+
OP_ADD = 'ADD'
28+
3229

3330
def set_handler(self, key, data):
34-
log_debug("AdvertiseRouteMgr:: set handler")
35-
if not self.__set_handler_validate(key, data):
36-
return True
3731
vrf, ip_prefix = self.split_key(key)
38-
self.add_route_advertisement(vrf, ip_prefix, data)
32+
self.add_route_advertisement(vrf, ip_prefix)
3933

4034
return True
4135

36+
4237
def del_handler(self, key):
43-
log_debug("AdvertiseRouteMgr:: del handler")
4438
vrf, ip_prefix = self.split_key(key)
4539
self.remove_route_advertisement(vrf, ip_prefix)
4640

47-
def __set_handler_validate(self, key, data):
48-
if data:
49-
if ("profile" in data and data["profile"] in ROUTE_MAPS) or data == {"":""}:
50-
"""
51-
APP which config the data should be responsible to pass a valid IP prefix
52-
"""
53-
return True
54-
55-
log_err("BGPAdvertiseRouteMgr:: Invalid data %s for advertised route %s" % (data, key))
56-
return False
57-
58-
def add_route_advertisement(self, vrf, ip_prefix, data):
41+
42+
def add_route_advertisement(self, vrf, ip_prefix):
5943
if self.directory.path_exist("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/bgp_asn"):
60-
if not self.advertised_routes.get(vrf, dict()):
44+
if not self.advertised_routes.get(vrf, set()):
6145
self.bgp_network_import_check_commands(vrf, self.OP_ADD)
62-
self.advertise_route_commands(ip_prefix, vrf, self.OP_ADD, data)
46+
self.advertise_route_commands(ip_prefix, vrf, self.OP_ADD)
47+
48+
self.advertised_routes.setdefault(vrf, set()).add(ip_prefix)
6349

64-
self.advertised_routes.setdefault(vrf, dict()).update({ip_prefix: data})
6550

6651
def remove_route_advertisement(self, vrf, ip_prefix):
67-
if ip_prefix not in self.advertised_routes.get(vrf, dict()):
68-
log_info("BGPAdvertiseRouteMgr:: %s|%s does not exist" % (vrf, ip_prefix))
69-
return
70-
self.advertised_routes.get(vrf, dict()).pop(ip_prefix)
71-
if not self.advertised_routes.get(vrf, dict()):
52+
self.advertised_routes.setdefault(vrf, set()).discard(ip_prefix)
53+
if not self.advertised_routes.get(vrf, set()):
7254
self.advertised_routes.pop(vrf, None)
7355

7456
if self.directory.path_exist("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/bgp_asn"):
75-
if not self.advertised_routes.get(vrf, dict()):
57+
if not self.advertised_routes.get(vrf, set()):
7658
self.bgp_network_import_check_commands(vrf, self.OP_DELETE)
7759
self.advertise_route_commands(ip_prefix, vrf, self.OP_DELETE)
7860

79-
def advertise_route_commands(self, ip_prefix, vrf, op, data=None):
61+
62+
def advertise_route_commands(self, ip_prefix, vrf, op):
8063
is_ipv6 = TemplateFabric.is_ipv6(ip_prefix)
8164
bgp_asn = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]["bgp_asn"]
8265

8366
cmd_list = []
84-
if vrf == "default":
67+
if vrf == 'default':
8568
cmd_list.append("router bgp %s" % bgp_asn)
8669
else:
8770
cmd_list.append("router bgp %s vrf %s" % (bgp_asn, vrf))
8871

8972
cmd_list.append(" address-family %s unicast" % ("ipv6" if is_ipv6 else "ipv4"))
90-
91-
if data and "profile" in data:
92-
cmd_list.append(" network %s route-map %s" % (ip_prefix, "%s_RM" % data["profile"]))
93-
log_debug(
94-
"BGPAdvertiseRouteMgr:: Update bgp %s network %s with route-map %s"
95-
% (bgp_asn, vrf + "|" + ip_prefix, "%s_RM" % data["profile"])
96-
)
97-
else:
98-
cmd_list.append(" %snetwork %s" % ("no " if op == self.OP_DELETE else "", ip_prefix))
99-
log_debug(
100-
"BGPAdvertiseRouteMgr:: %sbgp %s network %s"
101-
% ("Remove " if op == self.OP_DELETE else "Update ", bgp_asn, vrf + "|" + ip_prefix)
102-
)
73+
cmd_list.append(" %snetwork %s" % ('no ' if op == self.OP_DELETE else '', ip_prefix))
10374

10475
self.cfg_mgr.push_list(cmd_list)
105-
log_debug("BGPAdvertiseRouteMgr::Done")
76+
10677

10778
def bgp_network_import_check_commands(self, vrf, op):
10879
bgp_asn = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]["bgp_asn"]
10980
cmd_list = []
110-
if vrf == "default":
81+
if vrf == 'default':
11182
cmd_list.append("router bgp %s" % bgp_asn)
11283
else:
11384
cmd_list.append("router bgp %s vrf %s" % (bgp_asn, vrf))
114-
cmd_list.append(" %sbgp network import-check" % ("" if op == self.OP_DELETE else "no "))
85+
cmd_list.append(" %sbgp network import-check" % ('' if op == self.OP_DELETE else 'no '))
11586

11687
self.cfg_mgr.push_list(cmd_list)
11788

89+
11890
def on_bgp_asn_change(self):
11991
if self.directory.path_exist("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/bgp_asn"):
12092
for vrf, ip_prefixes in self.advertised_routes.items():
12193
self.bgp_network_import_check_commands(vrf, self.OP_ADD)
12294
for ip_prefix in ip_prefixes:
123-
self.add_route_advertisement(vrf, ip_prefix, ip_prefixes[ip_prefix])
95+
self.add_route_advertisement(vrf, ip_prefix)
96+
12497

12598
@staticmethod
12699
def split_key(key):
@@ -129,7 +102,7 @@ def split_key(key):
129102
:param key: key to split
130103
:return: vrf name extracted from the key, ip prefix extracted from the key
131104
"""
132-
if "|" not in key:
133-
return "default", key
105+
if '|' not in key:
106+
return 'default', key
134107
else:
135-
return tuple(key.split("|", 1))
108+
return tuple(key.split('|', 1))

src/sonic-bgpcfgd/bgpcfgd/managers_rm.py

-78
This file was deleted.

src/sonic-bgpcfgd/tests/test_advertise_rt.py

+6-66
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_set_del():
4848
set_del_test(
4949
mgr,
5050
"SET",
51-
("10.1.0.0/24", {"":""}),
51+
("10.1.0.0/24", {}),
5252
True,
5353
[
5454
["router bgp 65100",
@@ -62,7 +62,7 @@ def test_set_del():
6262
set_del_test(
6363
mgr,
6464
"SET",
65-
("fc00:10::/64", {"":""}),
65+
("fc00:10::/64", {}),
6666
True,
6767
[
6868
["router bgp 65100",
@@ -103,7 +103,7 @@ def test_set_del_vrf():
103103
set_del_test(
104104
mgr,
105105
"SET",
106-
("vrfRED|10.2.0.0/24", {"":""}),
106+
("vrfRED|10.2.0.0/24", {}),
107107
True,
108108
[
109109
["router bgp 65100 vrf vrfRED",
@@ -117,7 +117,7 @@ def test_set_del_vrf():
117117
set_del_test(
118118
mgr,
119119
"SET",
120-
("vrfRED|fc00:20::/64", {"":""}),
120+
("vrfRED|fc00:20::/64", {}),
121121
True,
122122
[
123123
["router bgp 65100 vrf vrfRED",
@@ -158,9 +158,7 @@ def test_set_del_bgp_asn_change():
158158
set_del_test(
159159
mgr,
160160
"SET",
161-
("vrfRED|10.3.0.0/24", {
162-
"profile": "FROM_SDN_SLB_ROUTES"
163-
}),
161+
("vrfRED|10.3.0.0/24", {}),
164162
True,
165163
[]
166164
)
@@ -172,7 +170,7 @@ def test_set_del_bgp_asn_change():
172170
" no bgp network import-check"],
173171
["router bgp 65100 vrf vrfRED",
174172
" address-family ipv4 unicast",
175-
" network 10.3.0.0/24 route-map FROM_SDN_SLB_ROUTES_RM"]
173+
" network 10.3.0.0/24"]
176174
]
177175
def push_list(cmds):
178176
test_set_del_bgp_asn_change.push_list_called = True
@@ -185,61 +183,3 @@ def push_list(cmds):
185183
mgr.directory.put("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost", {"bgp_asn": "65100"})
186184

187185
assert test_set_del_bgp_asn_change.push_list_called
188-
189-
def test_set_del_with_community():
190-
mgr = constructor()
191-
set_del_test(
192-
mgr,
193-
"SET",
194-
("10.1.0.0/24", {
195-
"profile": "FROM_SDN_SLB_ROUTES"
196-
}),
197-
True,
198-
[
199-
["router bgp 65100",
200-
" no bgp network import-check"],
201-
["router bgp 65100",
202-
" address-family ipv4 unicast",
203-
" network 10.1.0.0/24 route-map FROM_SDN_SLB_ROUTES_RM"]
204-
]
205-
)
206-
207-
set_del_test(
208-
mgr,
209-
"SET",
210-
("fc00:10::/64", {
211-
"profile": "FROM_SDN_SLB_ROUTES"
212-
}),
213-
True,
214-
[
215-
["router bgp 65100",
216-
" address-family ipv6 unicast",
217-
" network fc00:10::/64 route-map FROM_SDN_SLB_ROUTES_RM"]
218-
]
219-
)
220-
221-
set_del_test(
222-
mgr,
223-
"DEL",
224-
("10.1.0.0/24",),
225-
True,
226-
[
227-
["router bgp 65100",
228-
" address-family ipv4 unicast",
229-
" no network 10.1.0.0/24"]
230-
]
231-
)
232-
233-
set_del_test(
234-
mgr,
235-
"DEL",
236-
("fc00:10::/64",),
237-
True,
238-
[
239-
["router bgp 65100",
240-
" bgp network import-check"],
241-
["router bgp 65100",
242-
" address-family ipv6 unicast",
243-
" no network fc00:10::/64"]
244-
]
245-
)

0 commit comments

Comments
 (0)