Skip to content

Commit

Permalink
tests: add ping flood test
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hopps <[email protected]>
  • Loading branch information
choppsv1 committed Sep 4, 2024
1 parent 85a692d commit 4a9f826
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/flood/common
44 changes: 44 additions & 0 deletions tests/flood/munet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
topology:
ipv6-enable: true
networks-autonumber: true
dns-network: "mgmt0"
networks:
- name: mgmt0
ip: 192.168.0.254/24
ipv6: "fd00::ff/64"
nat: true
- name: net0
ip: 10.0.0.0/24
ipv6: "fc00::/64"
- name: net1
ip: 10.0.1.0/24
ipv6: "fc00:0:0:1::/64"
- name: net2
ip: 10.0.2.0/24
ipv6: "fc00:0:0:2::/64"
nodes:
- name: h1
connections:
- to: mgmt0
- to: net0
- name: r1
kind: linux
connections:
- to: mgmt0
- to: net0
- to: net1
# eth2 is router interconnect
- name: r2
kind: linux
connections:
- to: mgmt0
name: eth0
- to: net2
name: eth1
- to: net1
# eth2 is router interconnect
name: eth2
- name: h2
connections:
- to: mgmt0
- to: net2
109 changes: 109 additions & 0 deletions tests/flood/test_flood.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# -*- coding: utf-8 eval: (blacken-mode 1) -*-
#
# February 9 2022, Christian Hopps <[email protected]>
#
# Copyright 2022, LabN Consulting, L.L.C.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; see the file COPYING; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
"Simple virtual interface qemu based iptfs test."
import logging
import os

import pytest
from common.config import _network_up, setup_policy_tun, setup_routed_tun
from common.tests import _test_net_up

# All tests are coroutines
pytestmark = pytest.mark.asyncio

SRCDIR = os.path.dirname(os.path.abspath(__file__))


@pytest.fixture(scope="module", autouse=True)
async def network_up(unet):
await _network_up(unet, ipv6=True)


# 192.168.0.0/24 fd00::/64
# --+-------------------+------ mgmt0 ------+-------------------+---
# | .1 | .2 | .3 | .4
# +----+ +----+ +----+ +----+
# | h1 | --- net0 --- | r1 | --- net1 --- | r2 | --- net2 --- | r1 |
# +----+ .1 .2 +----+ .2 .3 +----+ .3 .4 +----+
# 10.0.0.0/24 10.0.1.0/24 10.0.2.0/24


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


async def do_ping(h1, astepf):
count = 3000

await astepf("first IPv6 ping")
logging.debug(h1.cmd_raises("ping -c1 fc00:0:0:2::4"))
await astepf(f"flood {count} IPv6 ping")
logging.debug(h1.cmd_raises(f"ping -f -c{count} fc00:0:0:2::4"))

await astepf("first IPv4 ping")
logging.debug(h1.cmd_raises("ping -c1 10.0.2.4"))
await astepf(f"flood {count} IPv4 ping")
logging.debug(h1.cmd_raises(f"ping -f -c{count} 10.0.2.4"))


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

opts = pytestconfig.getoption("--iptfs-opts", "dont-frag")
await setup_policy_tun(
unet, mode="iptfs", iptfs_opts=opts, ipv6=True, tun_ipv6=False
)

await do_ping(h1, astepf)


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

opts = pytestconfig.getoption("--iptfs-opts", "")
await setup_routed_tun(
unet, mode="iptfs", iptfs_opts=opts, ipv6=True, tun_ipv6=False
)

await do_ping(h1, astepf)


async def test_policy_tun6_up(unet, astepf, pytestconfig):
h1 = unet.hosts["h1"]

opts = pytestconfig.getoption("--iptfs-opts", "dont-frag")
await setup_policy_tun(
unet, mode="iptfs", iptfs_opts=opts, ipv6=True, tun_ipv6=True
)

await do_ping(h1, astepf)


async def test_routed_tun6_up(unet, astepf, pytestconfig):
h1 = unet.hosts["h1"]

opts = pytestconfig.getoption("--iptfs-opts", "")
await setup_routed_tun(
unet, mode="iptfs", iptfs_opts=opts, ipv6=True, tun_ipv6=True
)

await do_ping(h1, astepf)
2 changes: 1 addition & 1 deletion tests/simplenet/test_simplenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import os

import pytest
from common.config import _network_up, get_sa_values, setup_policy_tun, setup_routed_tun
from common.config import _network_up, setup_policy_tun, setup_routed_tun
from common.tests import _test_net_up

# All tests are coroutines
Expand Down

0 comments on commit 4a9f826

Please sign in to comment.