Skip to content

Commit

Permalink
Add basic tests for VLAN
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Karis <[email protected]>
  • Loading branch information
andreaskaris committed Jan 22, 2025
1 parent 2430ad7 commit 3665cc7
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,66 @@ def two_ns_simple(netns):
yield netns


@pytest.fixture
def two_ns_vlan(netns):
"""Fixture that creates two netns connected through VLAN interfaces on top of a
veth pair."""
ipr = IPRoute()

# Create netns & a veth pair
ns0 = netns.add("ns0")
ns1 = netns.add("ns1")
ipr.link("add", ifname="veth01", peer="veth10", kind="veth")

# Wait until links appear
peer, veth = ipr.poll(
ipr.link, "dump", timeout=5, ifname=lambda x: x in ("veth01", "veth10")
)

# Move ifaces to netns
ipr.link("set", ifname="veth01", net_ns_fd="ns0")
ipr.link("set", ifname="veth10", net_ns_fd="ns1")

# Setup ifaces
ns0.link("set", ifname="veth01", state="up")
ns1.link("set", ifname="veth10", state="up")

# Create VLANs
ns0.link(
"add",
ifname="veth01.123",
link=ns0.link_lookup(ifname="veth01")[0],
kind="vlan",
vlan_id=123)
ns1.link(
"add",
ifname="veth10.123",
link=ns1.link_lookup(ifname="veth10")[0],
kind="vlan",
vlan_id=123)

# Set VLANs up
ns0.link("set", ifname="veth01.123", state="up")
ns1.link("set", ifname="veth10.123", state="up")

# Assign IP addresses to VLANs
ns0.addr(
"add",
index=ns0.link_lookup(ifname="veth01.123")[0],
address="10.0.42.1",
prefixlen=24,
)
ns1.addr(
"add",
index=ns1.link_lookup(ifname="veth10.123")[0],
address="10.0.42.2",
prefixlen=24,
)

ipr.close()
yield netns


@pytest.fixture
def three_ns_nat(netns):
"""Fixture that creates three netns connected through veth pairs, a VIP and DNATing
Expand Down
86 changes: 86 additions & 0 deletions tests/test_skb.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,89 @@ def test_skb_tcp_cc(two_ns_simple):
]
events = retis.events()
assert_events_present(events, expected_events)


def test_skb_vlan(two_ns_vlan):
ns = two_ns_vlan
retis = Retis()

retis.collect(
"-c",
"skb",
"--skb-sections",
"arp,dev,eth,vlan",
"-f",
"arp",
"-p",
"tp:net:netif_rx",
)
print(ns.run_bg("ns1", "socat", "TCP-LISTEN:80", "STDOUT"))
print(ns.run("ns0", "socat", "-T", "1", "-", "TCP:10.0.42.2:80"))
retis.stop()

expected_events = [
# ARP req
{
"common": {
"task": {
"comm": "socat",
},
},
"kernel": {
"probe_type": "raw_tracepoint",
"symbol": "net:netif_rx",
},
"skb": {
"arp": {
"operation": "Request",
"spa": "10.0.42.1",
"tpa": "10.0.42.2",
},
"dev": {
"name": "veth10",
},
"eth": {
"etype": 2054,
},
"vlan": {
"acceleration": True,
"dei": False,
"pcp": 0,
"vid": 123,
},
},
},
# ARP rep
{
"common": {
"task": {
"comm": "socat",
},
},
"kernel": {
"probe_type": "raw_tracepoint",
"symbol": "net:netif_rx",
},
"skb": {
"arp": {
"operation": "Reply",
"spa": "10.0.42.2",
"tpa": "10.0.42.1",
},
"dev": {
"name": "veth01",
},
"eth": {
"etype": 2054,
},
"vlan": {
"acceleration": True,
"dei": False,
"pcp": 0,
"vid": 123,
},
},
},
]
events = retis.events()
assert_events_present(events, expected_events)

0 comments on commit 3665cc7

Please sign in to comment.