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 <[email protected]>
  • Loading branch information
rzalamena committed Aug 8, 2018
1 parent edd4381 commit 6bb9332
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
router bgp 101
neighbor 192.168.0.2 remote-as 102
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ router bgp 102
neighbor 192.168.1.1 bfd
neighbor 192.168.2.1 remote-as 104
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
router bgp 103
neighbor 192.168.1.2 remote-as 102
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
router bgp 104
neighbor 192.168.2.2 remote-as 102
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
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,96 @@ def test_bgp_convergence():
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)

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(bgp_convergence_test,
router, 'show ip bgp json', expected)
_, res = topotest.run_and_expect(
test_func,
None,
count=4,
wait=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.
topotest.sleep(1, 'waiting for BFD to converge')

# Check that BGP converged quickly.
for router in tgen.routers().values():
peers = router.vtysh_cmd('show bfd peers json', isjson=True)
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'

result = topotest.json_cmp(peers, expected)
assertmsg = '"{}" JSON output mismatches'.format(router.name)
assert result 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)

# 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(bgp_convergence_test,
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():
"Run the memory leak test and report results."
tgen = get_topogen()
Expand Down

0 comments on commit 6bb9332

Please sign in to comment.