Skip to content
Merged

Dns #44

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test_orc/modules/dns/conf/module_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"name": "dns.network.from_dhcp",
"description": "Verify the device allows for a DNS server to be entered automatically",
"expected_behavior": "The device sends DNS requests to the DNS server provided by the DHCP server"
},
{
"name": "dns.mdns",
"description": "If the device has MDNS (or any kind of IP multicast), can it be disabled"
}
]
}
Expand Down
37 changes: 31 additions & 6 deletions test_orc/modules/dns/python/src/dns_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
from test_module import TestModule

LOG_NAME = 'test_dns'
CAPTURE_FILE = '/runtime/network/dns.pcap'
DNS_SERVER_CAPTURE_FILE = '/runtime/network/dns.pcap'
STARTUP_CAPTURE_FILE = '/runtime/device/startup.pcap'
MONITOR_CAPTURE_FILE = '/runtime/device/monitor.pcap'
LOGGER = None


Expand All @@ -31,14 +33,24 @@ def __init__(self, module):
LOGGER = self._get_logger()

def _check_dns_traffic(self, tcpdump_filter):
to_dns = self._exec_tcpdump(tcpdump_filter)
num_query_dns = len(to_dns)
dns_server_queries = self._exec_tcpdump(tcpdump_filter,DNS_SERVER_CAPTURE_FILE)
LOGGER.info('DNS Server queries found: ' + str(len(dns_server_queries)))

dns_startup_queries = self._exec_tcpdump(tcpdump_filter,STARTUP_CAPTURE_FILE)
LOGGER.info('Startup DNS queries found: ' + str(len(dns_startup_queries)))

dns_monitor_queries = self._exec_tcpdump(tcpdump_filter,MONITOR_CAPTURE_FILE)
LOGGER.info('Monitor DNS queries found: ' + str(len(dns_monitor_queries)))

num_query_dns = len(dns_server_queries) + len(dns_startup_queries) + len(dns_monitor_queries)

LOGGER.info('DNS queries found: ' + str(num_query_dns))
dns_traffic_detected = len(to_dns) > 0
dns_traffic_detected = num_query_dns > 0
LOGGER.info('DNS traffic detected: ' + str(dns_traffic_detected))
return dns_traffic_detected

def _dns_network_from_dhcp(self):
LOGGER.info("Running dns.network.from_dhcp")
LOGGER.info('Checking DNS traffic for configured DHCP DNS server: ' +
self._dns_server)

Expand All @@ -53,6 +65,7 @@ def _dns_network_from_dhcp(self):
return result

def _dns_network_from_device(self):
LOGGER.info("Running dns.network.from_device")
LOGGER.info('Checking DNS traffic from device: ' + self._device_mac)

# Check if the device DNS traffic is to appropriate server
Expand All @@ -63,15 +76,27 @@ def _dns_network_from_device(self):
LOGGER.info('DNS traffic detected from device: ' + str(result))
return result

def _exec_tcpdump(self, tcpdump_filter):
def _dns_mdns(self):
LOGGER.info("Running dns.mdns")

# Check if the device sends any MDNS traffic
tcpdump_filter = f'udp port 5353 and ether src {self._device_mac}'

result = self._check_dns_traffic(tcpdump_filter=tcpdump_filter)

LOGGER.info('MDNS traffic detected from device: ' + str(result))
return not result


def _exec_tcpdump(self, tcpdump_filter, capture_file):
"""
Args
tcpdump_filter: Filter to pass onto tcpdump file
capture_file: Optional capture file to look
Returns
List of packets matching the filter
"""
command = f'tcpdump -tttt -n -r {CAPTURE_FILE} {tcpdump_filter}'
command = f'tcpdump -tttt -n -r {capture_file} {tcpdump_filter}'

LOGGER.debug('tcpdump command: ' + command)

Expand Down
17 changes: 17 additions & 0 deletions test_orc/python/src/test_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ def _run_test_module(self, module, device):
network_runtime_dir = os.path.join(self._root_path, "runtime/network")
os.makedirs(container_runtime_dir)

device_startup_capture = os.path.join(
self._root_path, "runtime/test/" + device.mac_addr.replace(":", "") +
"/startup.pcap")

device_monitor_capture = os.path.join(
self._root_path, "runtime/test/" + device.mac_addr.replace(":", "") +
"/monitor.pcap")


client = docker.from_env()

module.container = client.containers.run(
Expand All @@ -151,6 +160,14 @@ def _run_test_module(self, module, device):
source=network_runtime_dir,
type="bind",
read_only=True),
Mount(target="/runtime/device/startup.pcap",
source=device_startup_capture,
type="bind",
read_only=True),
Mount(target="/runtime/device/monitor.pcap",
source=device_monitor_capture,
type="bind",
read_only=True),
],
environment={
"HOST_USER": self._get_host_user(),
Expand Down