Skip to content

Commit 3576450

Browse files
committed
test: verify mDNS allow/deny interfaces
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent bb987cf commit 3576450

File tree

6 files changed

+289
-1
lines changed

6 files changed

+289
-1
lines changed

test/case/infix_services/Readme.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33

44
<<<
55

6+
include::mdns_allow_deny/Readme.adoc[]
7+
68
include::services_basic/Readme.adoc[]
9+

test/case/infix_services/infix_services.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
# are transparent with respect to IEEE link-local multicast.
77
#- name: services_basic
88
# case: services_basic/test.py
9-
[]
9+
10+
- name: mdns_allow_deny
11+
case: mdns_allow_deny/test.py
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== mDNS allow/deny interfaces
2+
==== Description
3+
Verify the mDNS responder interface allow/deny configuration. Both
4+
settings can be used independently and in concert. We verify operation
5+
with three scenarios:
6+
7+
1. Allow p2, no mDNS traffic should be received on p1 and p3
8+
2. Deny p2, mDNS traffic should only be received on p1 and p3
9+
3. Allow p1 and p3, deny p2 and p3, traffic only on p1
10+
11+
==== Topology
12+
ifdef::topdoc[]
13+
image::../../test/case/infix_services/mdns_allow_deny/topology.svg[mDNS allow/deny interfaces topology]
14+
endif::topdoc[]
15+
ifndef::topdoc[]
16+
ifdef::testgroup[]
17+
image::mdns_allow_deny/topology.svg[mDNS allow/deny interfaces topology]
18+
endif::testgroup[]
19+
ifndef::testgroup[]
20+
image::topology.svg[mDNS allow/deny interfaces topology]
21+
endif::testgroup[]
22+
endif::topdoc[]
23+
==== Test sequence
24+
. Set up topology and attach to target DUT
25+
. Configure device
26+
. Allow mDNS on a single interface: p2
27+
. Deny mDNS on a single interface: p2
28+
. Allow mDNS on p1, p3 deny on p2, p3
29+
30+
31+
<<<
32+
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#!/usr/bin/env python3
2+
"""mDNS allow/deny interfaces
3+
4+
Verify the mDNS responder interface allow/deny configuration. Both
5+
settings can be used independently and in concert. We verify operation
6+
with three scenarios:
7+
8+
1. Allow p2, no mDNS traffic should be received on p1 and p3
9+
2. Deny p2, mDNS traffic should only be received on p1 and p3
10+
3. Allow p1 and p3, deny p2 and p3, traffic only on p1
11+
12+
"""
13+
14+
import time
15+
import infamy
16+
from infamy.util import parallel
17+
18+
19+
def mdns_scan(tgt):
20+
"""Trigger Avahi to send traffic on allowed interfaces"""
21+
time.sleep(2)
22+
tgt.runsh("logger -t scan 'calling avahi-browse ...'")
23+
tgt.runsh("avahi-browse -lat")
24+
25+
26+
def check(ns, expr, must):
27+
"""Wrap netns.must_receive() with common defaults"""
28+
return ns.must_receive(expr, timeout=3, must=must)
29+
30+
31+
with infamy.Test() as test:
32+
with test.step("Set up topology and attach to target DUT"):
33+
env = infamy.Env()
34+
dut = env.attach("dut", "mgmt")
35+
ssh = env.attach("dut", "mgmt", "ssh")
36+
_, p1 = env.ltop.xlate("dut", "p1")
37+
_, p2 = env.ltop.xlate("dut", "p2")
38+
_, p3 = env.ltop.xlate("dut", "p3")
39+
_, eth1 = env.ltop.xlate("host", "eth1")
40+
_, eth2 = env.ltop.xlate("host", "eth2")
41+
_, eth3 = env.ltop.xlate("host", "eth3")
42+
43+
with test.step("Configure device"):
44+
dut.put_config_dicts(
45+
{
46+
"ietf-interfaces": {
47+
"interfaces": {
48+
"interface": [
49+
{
50+
"name": p1,
51+
"enabled": True,
52+
"ipv4": {
53+
"address": [
54+
{
55+
"ip": "10.0.1.1",
56+
"prefix-length": 24
57+
}
58+
]
59+
}
60+
61+
},
62+
{
63+
"name": p2,
64+
"enabled": True,
65+
"ipv4": {
66+
"address": [
67+
{
68+
"ip": "10.0.2.1",
69+
"prefix-length": 24
70+
}
71+
]
72+
}
73+
74+
},
75+
{
76+
"name": p3,
77+
"enabled": True,
78+
"ipv4": {
79+
"address": [
80+
{
81+
"ip": "10.0.3.1",
82+
"prefix-length": 24
83+
}
84+
]
85+
}
86+
87+
},
88+
]
89+
}
90+
},
91+
"ietf-system": {
92+
"system": {
93+
"hostname": "dut"
94+
}
95+
},
96+
"infix-services": {
97+
"mdns": {
98+
"enabled": True
99+
}
100+
}
101+
}
102+
)
103+
104+
with infamy.IsolatedMacVlan(eth1) as ns1, \
105+
infamy.IsolatedMacVlan(eth2) as ns2, \
106+
infamy.IsolatedMacVlan(eth3) as ns3:
107+
ns1.addip("10.0.1.2")
108+
ns2.addip("10.0.2.2")
109+
ns3.addip("10.0.3.2")
110+
111+
EXPR1 = "host 10.0.1.1 and port 5353"
112+
EXPR2 = "host 10.0.2.1 and port 5353"
113+
EXPR3 = "host 10.0.3.1 and port 5353"
114+
115+
with test.step("Allow mDNS on a single interface: p2"):
116+
dut.put_config_dict("infix-services", {
117+
"mdns": {
118+
"interfaces": {
119+
"allow": [p2],
120+
}
121+
}
122+
})
123+
124+
parallel(lambda: mdns_scan(ssh),
125+
lambda: check(ns1, EXPR1, False),
126+
lambda: check(ns2, EXPR2, True),
127+
lambda: check(ns3, EXPR3, False))
128+
129+
with test.step("Deny mDNS on a single interface: p2"):
130+
dut.delete_xpath("/infix-services:mdns/interfaces")
131+
dut.put_config_dict("infix-services", {
132+
"mdns": {
133+
"interfaces": {
134+
"deny": [p2],
135+
}
136+
}
137+
})
138+
139+
parallel(lambda: mdns_scan(ssh),
140+
lambda: check(ns1, EXPR1, True),
141+
lambda: check(ns2, EXPR2, False),
142+
lambda: check(ns3, EXPR3, True))
143+
144+
with test.step("Allow mDNS on p1, p3 deny on p2, p3"):
145+
dut.delete_xpath("/infix-services:mdns/interfaces")
146+
dut.put_config_dict("infix-services", {
147+
"mdns": {
148+
"interfaces": {
149+
"allow": [p1, p3],
150+
"deny": [p2, p3],
151+
}
152+
}
153+
})
154+
155+
parallel(lambda: mdns_scan(ssh),
156+
lambda: check(ns1, EXPR1, True),
157+
lambda: check(ns2, EXPR2, False),
158+
lambda: check(ns3, EXPR3, False))
159+
160+
test.succeed()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
graph "1x4" {
2+
layout="neato";
3+
overlap="false";
4+
esep="+80";
5+
6+
node [shape=record, fontname="DejaVu Sans Mono, Book"];
7+
edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"];
8+
9+
host [
10+
label="host | { <mgmt> mgmt | <eth1> eth1 | <eth2> eth2 | <eth3> eth3 }",
11+
pos="0,12!",
12+
kind="controller",
13+
];
14+
15+
dut [
16+
label="{ <mgmt> mgmt | <p1> p1 | <p2> p2 | <p3> p3 } | dut \n\n(br0)\n10.0.p.1/24",
17+
pos="10,12!",
18+
19+
kind="infix",
20+
];
21+
22+
host:mgmt -- dut:mgmt [kind=mgmt, color="lightgray"]
23+
host:eth1 -- dut:p1 [color=black, fontcolor=black, taillabel="10.0.1.2/24"]
24+
host:eth2 -- dut:p2 [color=black, fontcolor=black, taillabel="10.0.2.2/24"]
25+
host:eth3 -- dut:p3 [color=black, fontcolor=black, taillabel="10.0.3.2/24"]
26+
}
Lines changed: 65 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)