-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bgpd: Allow overriding default distance if set to 0
`set distance` with route-maps allow setting it to zero. Relax zebra to use distance as 0 as well. Or imagine a case when you have a static kernel route with distance 0, but you need to override it from BGP with 0 distance as well. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
- Loading branch information
Showing
11 changed files
with
173 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
! | ||
router bgp 65001 | ||
no bgp ebgp-requires-policy | ||
no bgp network import-check | ||
neighbor 192.168.1.2 remote-as external | ||
address-family ipv4 unicast | ||
network 10.10.10.1/32 | ||
exit-address-family | ||
! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
! | ||
int r1-eth0 | ||
ip address 192.168.1.1/24 | ||
! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
! | ||
router bgp 65002 | ||
neighbor 192.168.1.1 remote-as external | ||
address-family ipv4 unicast | ||
neighbor 192.168.1.1 route-map r1 in | ||
exit-address-family | ||
! | ||
route-map r1 permit 10 | ||
set distance 0 | ||
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
! | ||
int r2-eth0 | ||
ip address 192.168.1.2/24 | ||
! |
86 changes: 86 additions & 0 deletions
86
tests/topotests/bgp_distance_zero/test_bgp_distance_zero.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python | ||
# SPDX-License-Identifier: ISC | ||
|
||
# Copyright (c) 2023 by | ||
# Donatas Abraitis <donatas@opensourcerouting.org> | ||
# | ||
|
||
""" | ||
Test if distance can be set to zero via route-maps. | ||
""" | ||
|
||
import os | ||
import sys | ||
import json | ||
import pytest | ||
import functools | ||
|
||
pytestmark = pytest.mark.bgpd | ||
|
||
CWD = os.path.dirname(os.path.realpath(__file__)) | ||
sys.path.append(os.path.join(CWD, "../")) | ||
|
||
# pylint: disable=C0413 | ||
from lib import topotest | ||
from lib.topogen import Topogen, TopoRouter, get_topogen | ||
|
||
pytestmark = [pytest.mark.bgpd] | ||
|
||
|
||
def setup_module(mod): | ||
topodef = {"s1": ("r1", "r2")} | ||
tgen = Topogen(topodef, mod.__name__) | ||
tgen.start_topology() | ||
|
||
router_list = tgen.routers() | ||
|
||
for i, (rname, router) in enumerate(router_list.items(), 1): | ||
router.load_config( | ||
TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) | ||
) | ||
router.load_config( | ||
TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) | ||
) | ||
|
||
tgen.start_router() | ||
|
||
|
||
def teardown_module(mod): | ||
tgen = get_topogen() | ||
tgen.stop_topology() | ||
|
||
|
||
def test_bgp_distance_zero(): | ||
tgen = get_topogen() | ||
|
||
if tgen.routers_have_failure(): | ||
pytest.skip(tgen.errors) | ||
|
||
r2 = tgen.gears["r2"] | ||
|
||
def _bgp_converge_table(): | ||
output = json.loads(r2.vtysh_cmd("show bgp ipv4 unicast 10.10.10.1/32 json")) | ||
expected = {"paths": [{"valid": True}]} | ||
return topotest.json_cmp(output, expected) | ||
|
||
test_func = functools.partial(_bgp_converge_table) | ||
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1) | ||
assert result is None, "Can't see distance 0 in BGP table" | ||
|
||
def _bgp_converge_rib(): | ||
output = json.loads(r2.vtysh_cmd("show ip route 10.10.10.1/32 json")) | ||
expected = { | ||
"10.10.10.1/32": [ | ||
{"protocol": "bgp", "distance": 0, "selected": True, "installed": True} | ||
] | ||
} | ||
return topotest.json_cmp(output, expected) | ||
|
||
test_func = functools.partial(_bgp_converge_rib) | ||
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1) | ||
assert result is None, "Can't see distance 0 in RIB" | ||
|
||
|
||
if __name__ == "__main__": | ||
args = ["-s"] + sys.argv[1:] | ||
sys.exit(pytest.main(args)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters