Skip to content

Commit

Permalink
tests: Add v4/v6 forwarding off/on
Browse files Browse the repository at this point in the history
There are no tests that ensured that turning off then on
v4 and v6 forwarding actually worked.  This does so.
This was found via looking at the code coverage.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
  • Loading branch information
donaldsharp committed Sep 23, 2024
1 parent fcc8738 commit ddbea65
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/topotests/forwarding_on_off/r1/frr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int lo
ip address 10.1.1.1/32
ip address 10:1::1:1/128

int eth0
ip address 10.1.2.1/24
ipv6 address 10:1::2:1/120

ip route 10.1.1.2/32 10.1.2.2
ip route 10.1.1.3/32 10.1.2.2
ip route 10.1.3.0/24 10.1.2.2
ipv6 route 10:1::1:2/128 10:1::2:2
ipv6 route 10:1::1:3/128 10:1::2:2
ipv6 route 10:1::3:0/90 10:1::2:2
19 changes: 19 additions & 0 deletions tests/topotests/forwarding_on_off/r2/frr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
no ip forwarding
no ipv6 forwarding

int lo
ip address 10.1.1.2/32
ipv6 address 10:1::1:2/128

int eth0
ip address 10.1.2.2/24
ipv6 address 10:1::2:2/120

int eth1
ip address 10.1.3.2/24
ipv6 address 10:1::3:2/120

ip route 10.1.1.1/32 10.1.2.1
ip route 10.1.1.3/32 10.1.3.3
ipv6 route 10:1::1:1/128 10:1::2:1
ipv6 route 10:1::1:3/128 10:1::3:3
15 changes: 15 additions & 0 deletions tests/topotests/forwarding_on_off/r3/frr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
int lo
ip address 10.1.1.3/32
ipv6 address 10:1::1:3/128

int eth0
ip address 10.1.3.3/24
ipv6 address 10:1::3:3/120


ip route 10.1.1.1/32 10.1.3.2
ip route 10.1.1.2/32 10.1.3.2
ip route 10.1.2.0/24 10.1.3.2
ipv6 route 10:1::1:1/128 10:1::3:2
ipv6 route 10:1::1:2/128 10:1::3:2
ipv6 route 10:1::2:0/120 10:1::3:2
104 changes: 104 additions & 0 deletions tests/topotests/forwarding_on_off/test_forwarding_on_off.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env python
# SPDX-License-Identifier: ISC
#
# test_forwarding_on_off.py
#
# Copyright (c) 2024 by Nvidia Corporation
# Donald Sharp
#

"""
test_forwarding_on_off.py: Test that forwarding is turned off then back on
"""

import ipaddress
import json
import pytest
import sys
import time

from functools import partial
from lib import topotest
from lib.topogen import Topogen, get_topogen
from lib.topolog import logger
from lib.checkping import check_ping

pytestmark = [
pytest.mark.staticd,
]


def build_topo(tgen):
"""Build the topology used by all tests below."""

# Create 3 routers
r1 = tgen.add_router("r1")
r2 = tgen.add_router("r2")
r3 = tgen.add_router("r3")

# Add a link between r1 <-> r2 and r2 <-> r3
tgen.add_link(r1, r2, ifname1="eth0", ifname2="eth0")
tgen.add_link(r2, r3, ifname1="eth1", ifname2="eth0")


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

router_list = tgen.routers()

for _, router in router_list.items():
router.load_frr_config("frr.conf")

tgen.start_router()


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


def test_no_forwarding():
tgen = get_topogen()
r2 = tgen.gears["r2"]

def _no_forwarding(family, status):
logger.info("Testing for: {} {}".format(family, status))
rc, o, e = r2.net.cmd_status(
'vtysh -c "show zebra" | grep "{}" | grep "{}"'.format(family, status)
)

logger.info("Output: {}".format(o))
return rc

test_func = partial(_no_forwarding, "v4 Forwarding", "Off")
_, result = topotest.run_and_expect(test_func, 0, count=15, wait=1)
assert result == 0

test_func = partial(_no_forwarding, "v6 Forwarding", "Off")
_, result = topotest.run_and_expect(test_func, 0, count=15, wait=1)
assert result == 0

logger.info("Sending pings that should fail")
check_ping("r1", "10.1.1.3", False, 10, 1)
check_ping("r1", "10:1::1:3", False, 10, 1)

logger.info("Turning on Forwarding")
r2.vtysh_cmd("conf\nip forwarding\nipv6 forwarding")

test_func = partial(_no_forwarding, "v4 Forwarding", "On")
_, result = topotest.run_and_expect(test_func, 0, count=15, wait=1)
assert result == 0

test_func = partial(_no_forwarding, "v6 Forwarding", "On")
_, result = topotest.run_and_expect(test_func, 0, count=15, wait=1)
assert result == 0

check_ping("r1", "10.1.1.3", True, 10, 1)
check_ping("r1", "10:1::1:3", True, 10, 1)


if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

0 comments on commit ddbea65

Please sign in to comment.