Skip to content

Commit 4321860

Browse files
committed
tests: improve flood test
Signed-off-by: Christian Hopps <[email protected]>
1 parent 4a9f826 commit 4321860

File tree

2 files changed

+63
-59
lines changed

2 files changed

+63
-59
lines changed

tests/common/config.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -490,18 +490,18 @@ def setup_tunnel_routes(r1con, r2con, tun_ipv6, network3):
490490
return r1ipnh, r1ip6nh, r2ipnh, r2ip6nh
491491

492492

493-
def esp_flags_filter_dir(dir, esp_flags):
493+
def esp_flags_filter_dir(direction, esp_flags):
494494
"""Filter out esp flags inappropriate for the direction."""
495-
if dir == "in":
495+
if direction == "in":
496496
esp_flags = esp_flags.replace("dont-encap-dscp", "")
497497
else:
498498
esp_flags = esp_flags.replace("decap-dscp", "")
499499
return esp_flags
500500

501501

502-
def iptfs_opts_filter_dir(dir, iptfs_opts):
502+
def iptfs_opts_filter_dir(direction, iptfs_opts):
503503
"""Filter out iptfs options inappropriate for the direction."""
504-
if dir == "in":
504+
if direction == "in":
505505
iptfs_opts = iptfs_opts.replace("dont-frag", "")
506506
iptfs_opts = re.sub(r"init-delay \d+", "", iptfs_opts)
507507
iptfs_opts = re.sub(r"max-queue-size \d+", "", iptfs_opts)
@@ -592,28 +592,30 @@ async def setup_policy_tun(
592592
#
593593
# SAs
594594
#
595-
dir = "out" if r == r1 else "in"
596-
eflags = esp_flags_filter_dir(dir, esp_flags)
595+
direction = "out" if r == r1 else "in"
596+
eflags = esp_flags_filter_dir(direction, esp_flags)
597+
esp_args = "replay-window 128" if direction == "in" else ""
597598
repl.cmd_raises(
598599
(
599600
f"ip xfrm state add src {r1ip} dst {r2ip} proto esp "
600601
f"spi {spi_1to2} mode {mode} {sa_auth} {sa_enc} "
601-
f"{eflags} reqid {reqid_1to2} dir {dir} "
602+
f"{esp_args} {eflags} reqid {reqid_1to2} dir {direction} "
602603
# f"reqid {reqid_1to2} "
603604
)
604-
+ iptfs_opts_filter_dir(dir, iptfs_opts)
605+
+ iptfs_opts_filter_dir(direction, iptfs_opts)
605606
)
606607

607-
dir = "in" if r == r1 else "out"
608-
eflags = esp_flags_filter_dir(dir, esp_flags)
608+
direction = "in" if r == r1 else "out"
609+
eflags = esp_flags_filter_dir(direction, esp_flags)
610+
esp_args = "replay-window 128" if direction == "in" else ""
609611
repl.cmd_raises(
610612
(
611613
f"ip xfrm state add src {r2ip} dst {r1ip} proto esp "
612614
f"spi {spi_2to1} mode {mode} {sa_auth} {sa_enc} "
613-
f"{eflags} reqid {reqid_2to1} dir {dir} "
615+
f"{esp_args} {eflags} reqid {reqid_2to1} dir {direction} "
614616
# f"reqid {reqid_2to1} "
615617
)
616-
+ iptfs_opts_filter_dir(dir, iptfs_opts)
618+
+ iptfs_opts_filter_dir(direction, iptfs_opts)
617619
)
618620

619621
#
@@ -831,23 +833,27 @@ async def setup_routed_tun(
831833
lip = r2ip
832834
rip = r1ip
833835

834-
dir = "out" if r == r1 else "in"
836+
direction = "out" if r == r1 else "in"
837+
eflags = esp_flags_filter_dir(direction, esp_flags)
838+
esp_args = "replay-window 128" if direction == "in" else ""
835839
repl.cmd_raises(
836840
(
837841
f"ip xfrm state add src {r1ip} dst {r2ip} proto esp "
838842
f"spi {spi_1to2} mode {mode} {sa_auth} {sa_enc} "
839-
f"{esp_flags} if_id 55 reqid {reqid_1to2} dir {dir} "
843+
f"{esp_args} {eflags} if_id 55 reqid {reqid_1to2} dir {direction} "
840844
)
841-
+ iptfs_opts_filter_dir(dir, iptfs_opts)
845+
+ iptfs_opts_filter_dir(direction, iptfs_opts)
842846
)
843-
dir = "in" if r == r1 else "out"
847+
direction = "in" if r == r1 else "out"
848+
eflags = esp_flags_filter_dir(direction, esp_flags)
849+
esp_args = "replay-window 128" if direction == "in" else ""
844850
repl.cmd_raises(
845851
(
846852
f"ip xfrm state add src {r2ip} dst {r1ip} proto esp "
847853
f"spi {spi_2to1} mode {mode} {sa_auth} {sa_enc} "
848-
f"{esp_flags} if_id 55 reqid {reqid_2to1} dir {dir} "
854+
f"{esp_args} {eflags} if_id 55 reqid {reqid_2to1} dir {direction} "
849855
)
850-
+ iptfs_opts_filter_dir(dir, iptfs_opts)
856+
+ iptfs_opts_filter_dir(direction, iptfs_opts)
851857
)
852858

853859
# repl.cmd_raises(f"ip add vti0 local {lip} remote {rip} mode vti key 55")

tests/flood/test_flood.py

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -45,65 +45,63 @@ async def network_up(unet):
4545
# +----+ .1 .2 +----+ .2 .3 +----+ .3 .4 +----+
4646
# 10.0.0.0/24 10.0.1.0/24 10.0.2.0/24
4747

48+
PING_COUNT = 5
49+
INIT_DELAY = 100000
50+
4851

4952
async def test_net_up(unet, astepf):
5053
await astepf("Before test network up")
5154
await _test_net_up(unet, ipv6=True)
5255

5356

54-
async def do_ping(h1, astepf):
55-
count = 3000
56-
57-
await astepf("first IPv6 ping")
58-
logging.debug(h1.cmd_raises("ping -c1 fc00:0:0:2::4"))
59-
await astepf(f"flood {count} IPv6 ping")
60-
logging.debug(h1.cmd_raises(f"ping -f -c{count} fc00:0:0:2::4"))
57+
async def do_ping(host, dest4, dest6, astepf):
58+
count = PING_COUNT
6159

62-
await astepf("first IPv4 ping")
63-
logging.debug(h1.cmd_raises("ping -c1 10.0.2.4"))
6460
await astepf(f"flood {count} IPv4 ping")
65-
logging.debug(h1.cmd_raises(f"ping -f -c{count} 10.0.2.4"))
61+
logging.debug(host.cmd_raises(f"ping -q -n -s 8 -f -c{count} {dest4}"))
6662

63+
await astepf(f"flood {count} IPv6 ping")
64+
logging.debug(host.cmd_raises(f"ping -q -n -s 8 -f -c{count} {dest6}"))
6765

68-
async def test_policy_tun4_up(unet, astepf, pytestconfig):
69-
h1 = unet.hosts["h1"]
7066

71-
opts = pytestconfig.getoption("--iptfs-opts", "dont-frag")
67+
@pytest.mark.parametrize("tun_ipv6", [False, True])
68+
async def test_policy_tun_agg(unet, astepf, tun_ipv6):
7269
await setup_policy_tun(
73-
unet, mode="iptfs", iptfs_opts=opts, ipv6=True, tun_ipv6=False
70+
unet,
71+
mode="iptfs",
72+
iptfs_opts=f"init-delay {INIT_DELAY}",
73+
ipv6=True,
74+
tun_ipv6=tun_ipv6,
7475
)
7576

76-
await do_ping(h1, astepf)
77+
await do_ping(unet.hosts["r1"], "10.0.1.3", "fc00:0:0:1::3", astepf)
78+
await do_ping(unet.hosts["h1"], "10.0.2.4", "fc00:0:0:2::4", astepf)
7779

80+
# Now validate that we have sent and received exactly 8 ESP packets
81+
base = "fc00:0:0:1::" if tun_ipv6 else "10.0.1."
82+
o = unet.hosts["r1"].cmd_raises(f"ip x s l src {base}2")
83+
assert " oseq 0x4" in o
84+
o = unet.hosts["r1"].cmd_raises(f"ip x s l src {base}3")
85+
assert " seq 0x4" in o
7886

79-
async def test_routed_tun4_up(unet, astepf, pytestconfig):
80-
h1 = unet.hosts["h1"]
8187

82-
opts = pytestconfig.getoption("--iptfs-opts", "")
88+
@pytest.mark.parametrize("tun_ipv6", [False, True])
89+
async def test_routed_tun_agg(unet, astepf, tun_ipv6):
8390
await setup_routed_tun(
84-
unet, mode="iptfs", iptfs_opts=opts, ipv6=True, tun_ipv6=False
91+
unet,
92+
mode="iptfs",
93+
esp_flags="esn",
94+
iptfs_opts=f"init-delay {INIT_DELAY}",
95+
ipv6=True,
96+
tun_ipv6=tun_ipv6,
8597
)
8698

87-
await do_ping(h1, astepf)
88-
89-
90-
async def test_policy_tun6_up(unet, astepf, pytestconfig):
91-
h1 = unet.hosts["h1"]
92-
93-
opts = pytestconfig.getoption("--iptfs-opts", "dont-frag")
94-
await setup_policy_tun(
95-
unet, mode="iptfs", iptfs_opts=opts, ipv6=True, tun_ipv6=True
96-
)
97-
98-
await do_ping(h1, astepf)
99-
100-
101-
async def test_routed_tun6_up(unet, astepf, pytestconfig):
102-
h1 = unet.hosts["h1"]
103-
104-
opts = pytestconfig.getoption("--iptfs-opts", "")
105-
await setup_routed_tun(
106-
unet, mode="iptfs", iptfs_opts=opts, ipv6=True, tun_ipv6=True
107-
)
99+
# We don't have routes setup for local originated pings
100+
await do_ping(unet.hosts["h1"], "10.0.2.4", "fc00:0:0:2::4", astepf)
108101

109-
await do_ping(h1, astepf)
102+
# Now validate that we have sent and received exactly 8 ESP packets
103+
base = "fc00:0:0:1::" if tun_ipv6 else "10.0.1."
104+
o = unet.hosts["r1"].cmd_raises(f"ip x s l src {base}2")
105+
assert " oseq 0x2" in o
106+
o = unet.hosts["r1"].cmd_raises(f"ip x s l src {base}3")
107+
assert " seq 0x2" in o

0 commit comments

Comments
 (0)