Skip to content

Commit

Permalink
blabla
Browse files Browse the repository at this point in the history
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
  • Loading branch information
ton31337 committed Jul 4, 2023
1 parent 1f322e4 commit 1e3d37d
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 0 deletions.
Empty file.
25 changes: 25 additions & 0 deletions tests/topotests/bgp_redistribute_ospf/r1/frr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
!
int r1-eth0
ip address 192.168.1.1/24
!
int r1-eth1
ip address 192.168.2.1/24
ip ospf dead-interval 3
ip ospf hello-interval 1
!
int r1-eth2
ip address 172.16.0.1/16
!
router bgp 1
no bgp ebgp-requires-policy
neighbor 192.168.1.2 remote-as external
address-family ipv4 unicast
network 172.16.0.0/16
exit-address-family
!
router-id 0.0.0.1
!
router ospf
network 192.168.2.0/24 area 0
network 172.16.0.0/16 area 0
!
18 changes: 18 additions & 0 deletions tests/topotests/bgp_redistribute_ospf/r2/frr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
!
!
int r2-eth0
ip address 192.168.2.2/24
ip ospf dead-interval 3
ip ospf hello-interval 1
!
int r2-eth1
ip address 192.168.3.1/24
ip ospf dead-interval 3
ip ospf hello-interval 1
!
router-id 0.0.0.2
!
router ospf
network 192.168.2.0/24 area 0
network 192.168.3.0/24 area 0
!
32 changes: 32 additions & 0 deletions tests/topotests/bgp_redistribute_ospf/r3/frr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
!
debug zebra events
debug zebra packet
debug zebra kernel
debug zebra rib detailed
debug bgp zebra

!
int r3-eth0
ip address 192.168.1.2/24
!
int r3-eth1
ip address 192.168.3.2/24
ip ospf dead-interval 3
ip ospf hello-interval 1
!
router-id 0.0.0.3
!
router bgp 100
no bgp ebgp-requires-policy
neighbor 192.168.1.1 remote-as external
address-family ipv4 unicast
redistribute ospf route-map red
exit-address-family
!
router ospf
network 192.168.3.0/24 area 0
exit
!
route-map red permit 10
! set weight 0
exit
135 changes: 135 additions & 0 deletions tests/topotests/bgp_redistribute_ospf/test_bgp_redistribute_ospf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env python
# SPDX-License-Identifier: ISC

# Copyright (c) 2023 by
# Donatas Abraitis <donatas@opensourcerouting.org>
#

"""
"""

import os
import sys
import json
import pytest
import functools

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.ospfd, pytest.mark.bgpd]


def build_topo(tgen):
for routern in range(1, 4):
tgen.add_router("r{}".format(routern))

switch = tgen.add_switch("s1")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r3"])

switch = tgen.add_switch("s2")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r2"])

switch = tgen.add_switch("s3")
switch.add_link(tgen.gears["r2"])
switch.add_link(tgen.gears["r3"])

switch = tgen.add_switch("s4")
switch.add_link(tgen.gears["r1"])

def setup_module(mod):
tgen = Topogen(build_topo, mod.__name__)
tgen.start_topology()

router_list = tgen.routers()

for i, (rname, router) in enumerate(router_list.items(), 1):
router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname)))

tgen.start_router()


def teardown_module(mod):
tgen = get_topogen()
tgen.stop_topology()


def test_bgp_node_target_extended_communities():
tgen = get_topogen()

if tgen.routers_have_failure():
pytest.skip(tgen.errors)

r1 = tgen.gears["r1"]
r2 = tgen.gears["r2"]
r3 = tgen.gears["r3"]
r4 = tgen.gears["r4"]

def _bgp_converge():
output = json.loads(r1.vtysh_cmd("show bgp summary json"))
expected = {
"ipv4Unicast": {
"peers": {
"192.168.1.2": {
"pfxSnt": 1,
"state": "Established",
},
"192.168.1.3": {
"pfxSnt": 1,
"state": "Established",
},
"192.168.1.4": {
"pfxSnt": 1,
"state": "Established",
},
}
}
}
return topotest.json_cmp(output, expected)

test_func = functools.partial(_bgp_converge)
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert result is None, "Failed announcing 10.10.10.10/32 to r2, r3, and r4"

def _bgp_check_route(router, exists):
output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast json"))
if exists:
expected = {
"routes": {
"10.10.10.10/32": [
{
"valid": True,
}
]
}
}
else:
expected = {
"routes": {
"10.10.10.10/32": None,
}
}
return topotest.json_cmp(output, expected)

test_func = functools.partial(_bgp_check_route, r3, True)
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert result is None, "10.10.10.10/32 is not installed, but SHOULD be"

test_func = functools.partial(_bgp_check_route, r4, True)
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert result is None, "10.10.10.10/32 is not installed, but SHOULD be"

test_func = functools.partial(_bgp_check_route, r2, False)
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert result is None, "10.10.10.10/32 is installed, but SHOULD NOT be"


if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))
2 changes: 2 additions & 0 deletions zebra/zebra_rib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,8 @@ static void rib_process(struct route_node *rn)
}
if (best != re)
UNSET_FLAG(re->status, ROUTE_ENTRY_CHANGED);
else
redistribute_update(rn, re, NULL);
} /* RNODE_FOREACH_RE */

/* If no FIB override route, use the selected route also for FIB */
Expand Down

0 comments on commit 1e3d37d

Please sign in to comment.