Skip to content

Commit

Permalink
bfd-topo1: add fast reconvergence test
Browse files Browse the repository at this point in the history
Test that after a link goes down BGPd will be notified and recovered
quickly. Also test that BFD show command tells us that the peer went
down.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  • Loading branch information
rzalamena committed Sep 6, 2018
1 parent 7bf96ff commit ce25a5d
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 0 deletions.
52 changes: 52 additions & 0 deletions bfd-topo1/r1/bgp_prefixes.json
@@ -0,0 +1,52 @@
{
"routes": {
"10.254.254.2/32": [
{
"aspath": "102",
"prefix": "10.254.254.2",
"valid": true,
"peerId": "192.168.0.2",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.0.2",
"used": true,
"afi": "ipv4"
}
]
}
],
"10.254.254.3/32": [
{
"aspath": "102 103",
"prefix": "10.254.254.3",
"valid": true,
"peerId": "192.168.0.2",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.0.2",
"used": true,
"afi": "ipv4"
}
]
}
],
"10.254.254.4/32": [
{
"aspath": "102 104",
"prefix": "10.254.254.4",
"valid": true,
"peerId": "192.168.0.2",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.0.2",
"used": true,
"afi": "ipv4"
}
]
}
]
}
}
3 changes: 3 additions & 0 deletions bfd-topo1/r1/bgpd.conf
@@ -1,4 +1,7 @@
router bgp 101 router bgp 101
neighbor 192.168.0.2 remote-as 102 neighbor 192.168.0.2 remote-as 102
neighbor 192.168.0.2 bfd neighbor 192.168.0.2 bfd
address-family ipv4 unicast
network 10.254.254.1/32
exit-address-family
! !
52 changes: 52 additions & 0 deletions bfd-topo1/r2/bgp_prefixes.json
@@ -0,0 +1,52 @@
{
"routes": {
"10.254.254.1/32": [
{
"aspath": "101",
"prefix": "10.254.254.1",
"valid": true,
"peerId": "192.168.0.1",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.0.1",
"used": true,
"afi": "ipv4"
}
]
}
],
"10.254.254.3/32": [
{
"aspath": "103",
"prefix": "10.254.254.3",
"valid": true,
"peerId": "192.168.1.1",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.1.1",
"used": true,
"afi": "ipv4"
}
]
}
],
"10.254.254.4/32": [
{
"aspath": "104",
"prefix": "10.254.254.4",
"valid": true,
"peerId": "192.168.2.1",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.2.1",
"used": true,
"afi": "ipv4"
}
]
}
]
}
}
3 changes: 3 additions & 0 deletions bfd-topo1/r2/bgpd.conf
Expand Up @@ -5,4 +5,7 @@ router bgp 102
neighbor 192.168.1.1 bfd neighbor 192.168.1.1 bfd
neighbor 192.168.2.1 remote-as 104 neighbor 192.168.2.1 remote-as 104
neighbor 192.168.2.1 bfd neighbor 192.168.2.1 bfd
address-family ipv4 unicast
network 10.254.254.2/32
exit-address-family
! !
52 changes: 52 additions & 0 deletions bfd-topo1/r3/bgp_prefixes.json
@@ -0,0 +1,52 @@
{
"routes": {
"10.254.254.1/32": [
{
"aspath": "102 101",
"prefix": "10.254.254.1",
"valid": true,
"peerId": "192.168.1.2",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.1.2",
"used": true,
"afi": "ipv4"
}
]
}
],
"10.254.254.2/32": [
{
"aspath": "102",
"prefix": "10.254.254.2",
"valid": true,
"peerId": "192.168.1.2",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.1.2",
"used": true,
"afi": "ipv4"
}
]
}
],
"10.254.254.4/32": [
{
"aspath": "102 104",
"prefix": "10.254.254.4",
"valid": true,
"peerId": "192.168.1.2",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.1.2",
"used": true,
"afi": "ipv4"
}
]
}
]
}
}
3 changes: 3 additions & 0 deletions bfd-topo1/r3/bgpd.conf
@@ -1,4 +1,7 @@
router bgp 103 router bgp 103
neighbor 192.168.1.2 remote-as 102 neighbor 192.168.1.2 remote-as 102
neighbor 192.168.1.2 bfd neighbor 192.168.1.2 bfd
address-family ipv4 unicast
network 10.254.254.3/32
exit-address-family
! !
52 changes: 52 additions & 0 deletions bfd-topo1/r4/bgp_prefixes.json
@@ -0,0 +1,52 @@
{
"routes": {
"10.254.254.1/32": [
{
"aspath": "102 101",
"prefix": "10.254.254.1",
"valid": true,
"peerId": "192.168.2.2",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.2.2",
"used": true,
"afi": "ipv4"
}
]
}
],
"10.254.254.2/32": [
{
"aspath": "102",
"prefix": "10.254.254.2",
"valid": true,
"peerId": "192.168.2.2",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.2.2",
"used": true,
"afi": "ipv4"
}
]
}
],
"10.254.254.3/32": [
{
"aspath": "102 103",
"prefix": "10.254.254.3",
"valid": true,
"peerId": "192.168.2.2",
"prefixLen": 32,
"nexthops": [
{
"ip": "192.168.2.2",
"used": true,
"afi": "ipv4"
}
]
}
]
}
}
3 changes: 3 additions & 0 deletions bfd-topo1/r4/bgpd.conf
@@ -1,4 +1,7 @@
router bgp 104 router bgp 104
neighbor 192.168.2.2 remote-as 102 neighbor 192.168.2.2 remote-as 102
neighbor 192.168.2.2 bfd neighbor 192.168.2.2 bfd
address-family ipv4 unicast
network 10.254.254.4/32
exit-address-family
! !
90 changes: 90 additions & 0 deletions bfd-topo1/test_bfd_topo1.py
Expand Up @@ -143,6 +143,96 @@ def test_bgp_convergence():
assert res is None, assertmsg assert res is None, assertmsg




def test_bgp_fast_convergence():
"Assert that BGP is converging before setting a link down."
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

logger.info('waiting for bgp peers converge')

for router in tgen.routers().values():
ref_file = '{}/{}/bgp_prefixes.json'.format(CWD, router.name)
expected = json.loads(open(ref_file).read())
test_func = partial(topotest.router_json_cmp,
router, 'show ip bgp json', expected)
_, res = topotest.run_and_expect(test_func, None, count=40, wait=0.5)
assertmsg = '{}: bgp did not converge'.format(router.name)
assert res is None, assertmsg


def test_bfd_fast_convergence():
"""
Assert that BFD notices the link down after simulating network
failure.
"""
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

# Disable r1-eth0 link.
tgen.gears['r1'].link_enable('r1-eth0', enabled=False)

# Wait the minimum time we can before checking that BGP/BFD
# converged.
logger.info('waiting for BFD converge')

# Check that BGP converged quickly.
for router in tgen.routers().values():
json_file = '{}/{}/peers.json'.format(CWD, router.name)
expected = json.loads(open(json_file).read())

# Load the same file as previous test, but expect R1 to be down.
if router.name == 'r1':
for peer in expected:
if peer['peer'] == '192.168.0.2':
peer['status'] = 'down'
else:
for peer in expected:
if peer['peer'] == '192.168.0.1':
peer['status'] = 'down'

test_func = partial(topotest.router_json_cmp,
router, 'show bfd peers json', expected)
_, res = topotest.run_and_expect(test_func, None, count=20, wait=0.5)
assertmsg = '"{}" JSON output mismatches'.format(router.name)
assert res is None, assertmsg


def test_bgp_fast_reconvergence():
"Assert that BGP is converging after setting a link down."
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

logger.info('waiting for BGP re convergence')

# Check that BGP converged quickly.
for router in tgen.routers().values():
ref_file = '{}/{}/bgp_prefixes.json'.format(CWD, router.name)
expected = json.loads(open(ref_file).read())

# Load the same file as previous test, but set networks to None
# to test absence.
if router.name == 'r1':
expected['routes']['10.254.254.2/32'] = None
expected['routes']['10.254.254.3/32'] = None
expected['routes']['10.254.254.4/32'] = None
else:
expected['routes']['10.254.254.1/32'] = None

test_func = partial(topotest.router_json_cmp,
router, 'show ip bgp json', expected)
_, res = topotest.run_and_expect(
test_func,
None,
count=3,
wait=1
)
assertmsg = '{}: bgp did not converge'.format(router.name)
assert res is None, assertmsg


def test_memory_leak(): def test_memory_leak():
"Run the memory leak test and report results." "Run the memory leak test and report results."
tgen = get_topogen() tgen = get_topogen()
Expand Down

0 comments on commit ce25a5d

Please sign in to comment.