From 647352384beb239e289e422860722b06199ac351 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Fri, 30 Jun 2023 17:56:56 +0100 Subject: [PATCH 1/2] Add ipv6 tests --- modules/test/conn/conf/module_config.json | 10 +++++ .../test/conn/python/src/connection_module.py | 41 ++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/modules/test/conn/conf/module_config.json b/modules/test/conn/conf/module_config.json index 0f599c5d3..baf160451 100644 --- a/modules/test/conn/conf/module_config.json +++ b/modules/test/conn/conf/module_config.json @@ -31,6 +31,16 @@ "name": "connection.target_ping", "description": "The device under test responds to an ICMP echo (ping) request.", "expected_behavior": "The device under test responds to an ICMP echo (ping) request." + }, + { + "name": "connection.ipv6_slaac", + "description": "The device forms a valid IPv6 address as a combination of the IPv6 router prefix and the device interface identifier", + "expected_behavior": "The device under test complies with RFC4862 and forms a valid IPv6 SLAAC address" + }, + { + "name": "connection.ipv6_ping", + "description": "The device responds to an IPv6 ping (ICMPv6 Echo) request to the SLAAC address", + "expected_behavior": "The device responds to the ping as per RFC4443" } ] } diff --git a/modules/test/conn/python/src/connection_module.py b/modules/test/conn/python/src/connection_module.py index 196c335d8..764e9c3b8 100644 --- a/modules/test/conn/python/src/connection_module.py +++ b/modules/test/conn/python/src/connection_module.py @@ -24,6 +24,7 @@ DHCP_SERVER_CAPTURE_FILE = '/runtime/network/dhcp-1.pcap' STARTUP_CAPTURE_FILE = '/runtime/device/startup.pcap' MONITOR_CAPTURE_FILE = '/runtime/device/monitor.pcap' +SLAAC_PREFIX = "fd10:77be:4186" class ConnectionModule(TestModule): @@ -34,6 +35,8 @@ def __init__(self, module): global LOGGER LOGGER = self._get_logger() + self._ipv6_addr = None + def _connection_mac_address(self): LOGGER.info("Running connection.mac_address") if self._device_mac is not None: @@ -110,8 +113,42 @@ def _get_oui_manufacturer(self,mac_address): return line[start:].strip() # Extract the company name return None + def _connection_ipv6_slaac(self): + LOGGER.info("Running connection.ipv6_slaac") + packet_capture = rdpcap(MONITOR_CAPTURE_FILE) + + sends_ipv6 = False + + for packet in packet_capture: + if IPv6 in packet and packet.src == self._device_mac: + sends_ipv6 = True + ipv6_addr = packet[IPv6].src + if ipv6_addr.starts_with(SLAAC_PREFIX): + self._ipv6_addr = packet[IPv6].src + LOGGER.info(f"Device has formed SLAAC address {packet[IPv6].src}") + return True + + if sends_ipv6: + LOGGER.info("Device does not support IPv6 SLAAC") + else: + LOGGER.info("Device does not support IPv6") + return False + + def _connection_ipv6_ping(self): + LOGGER.info("Running connection.ipv6_ping") + + if self._ipv6_addr is None: + LOGGER.info("No IPv6 SLAAC address found. Cannot ping") + return + + if self._ping(self._ipv6_addr): + LOGGER.info(f"Device responds to IPv6 ping on {self._ipv6_addr}") + return True + else: + LOGGER.info("Device does not respond to IPv6 ping") + return False + def _ping(self, host): - cmd = 'ping -c 1 ' + str(host) + cmd = "ping -c 1 " + str(host) success = util.run_command(cmd, output=False) return success - \ No newline at end of file From 7d94a44fa08764caa391e2a9cdf78f7dfa2589ef Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Fri, 7 Jul 2023 11:33:54 +0100 Subject: [PATCH 2/2] Check for ND_NS --- framework/python/src/test_orc/test_orchestrator.py | 4 ++-- modules/network/base/bin/start_module | 6 +++--- modules/network/dhcp-1/bin/start_network_service | 9 ++++----- modules/network/dhcp-1/conf/radvd.conf | 1 + modules/test/conn/python/src/connection_module.py | 13 +++++++------ 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/framework/python/src/test_orc/test_orchestrator.py b/framework/python/src/test_orc/test_orchestrator.py index 4bc9fc003..0c9d56a7a 100644 --- a/framework/python/src/test_orc/test_orchestrator.py +++ b/framework/python/src/test_orc/test_orchestrator.py @@ -102,7 +102,7 @@ def _generate_results(self, device): results[module.name] = module_results except (FileNotFoundError, PermissionError, json.JSONDecodeError) as results_error: - LOGGER.error("Error occured whilst obbtaining results for module " + module.name) + LOGGER.error(f"Error occured whilst obbtaining results for module {module.name}") LOGGER.debug(results_error) out_file = os.path.join( @@ -110,7 +110,7 @@ def _generate_results(self, device): "runtime/test/" + device.mac_addr.replace(":", "") + "/results.json") with open(out_file, "w", encoding="utf-8") as f: json.dump(results, f, indent=2) - util.run_command(f'chown -R {self._host_user} {out_file}') + util.run_command(f"chown -R {self._host_user} {out_file}") return results def test_in_progress(self): diff --git a/modules/network/base/bin/start_module b/modules/network/base/bin/start_module index 7fdcbc404..b02ba82dd 100644 --- a/modules/network/base/bin/start_module +++ b/modules/network/base/bin/start_module @@ -15,7 +15,7 @@ useradd $HOST_USER sysctl net.ipv6.conf.all.disable_ipv6=0 sysctl -p -#Read in the config file +# Read in the config file CONF_FILE="/testrun/conf/module_config.json" CONF=`cat $CONF_FILE` @@ -72,8 +72,8 @@ then fi fi -#Small pause to let all core services stabalize +# Small pause to let all core services stabalize sleep 3 -#Start the networking service +# Start the networking service $BIN_DIR/start_network_service $MODULE_NAME $INTF \ No newline at end of file diff --git a/modules/network/dhcp-1/bin/start_network_service b/modules/network/dhcp-1/bin/start_network_service index a60806684..b82d2a3d7 100644 --- a/modules/network/dhcp-1/bin/start_network_service +++ b/modules/network/dhcp-1/bin/start_network_service @@ -6,7 +6,7 @@ DHCP_LOG_FILE=/runtime/network/dhcp1-dhcpd.log RA_PID_FILE=/var/run/radvd/radvd.pid RA_LOG_FILE=/runtime/network/dhcp1-radvd.log -echo "Starrting Network Service..." +echo "Starting Network Service..." #Enable IPv6 Forwarding sysctl net.ipv6.conf.all.forwarding=1 @@ -15,17 +15,16 @@ sysctl -p # Create leases file if needed touch /var/lib/dhcp/dhcpd.leases -#Create directory for radvd +# Create directory for radvd mkdir /var/run/radvd -#Create and set permissions on the log files +# Create and set permissions on the log files touch $DHCP_LOG_FILE touch $RA_LOG_FILE chown $HOST_USER $DHCP_LOG_FILE chown $HOST_USER $RA_LOG_FILE - -#Move the config files to the correct location +# Move the config files to the correct location cp /testrun/conf/dhcpd.conf /etc/dhcp/dhcpd.conf cp /testrun/conf/radvd.conf /etc/radvd.conf diff --git a/modules/network/dhcp-1/conf/radvd.conf b/modules/network/dhcp-1/conf/radvd.conf index f6d6f30d9..89995785f 100644 --- a/modules/network/dhcp-1/conf/radvd.conf +++ b/modules/network/dhcp-1/conf/radvd.conf @@ -8,5 +8,6 @@ interface veth0 AdvOnLink on; AdvAutonomous on; AdvRouterAddr on; + AdvSourceLLAddress off; }; }; \ No newline at end of file diff --git a/modules/test/conn/python/src/connection_module.py b/modules/test/conn/python/src/connection_module.py index 764e9c3b8..136f04d9c 100644 --- a/modules/test/conn/python/src/connection_module.py +++ b/modules/test/conn/python/src/connection_module.py @@ -63,7 +63,7 @@ def _connection_single_ip(self): if self._device_mac is None: LOGGER.info("No MAC address found: ") return result, "No MAC address found." - + # Read all the pcap files containing DHCP packet information packets = rdpcap(DHCP_SERVER_CAPTURE_FILE) packets.append(rdpcap(STARTUP_CAPTURE_FILE)) @@ -122,11 +122,12 @@ def _connection_ipv6_slaac(self): for packet in packet_capture: if IPv6 in packet and packet.src == self._device_mac: sends_ipv6 = True - ipv6_addr = packet[IPv6].src - if ipv6_addr.starts_with(SLAAC_PREFIX): - self._ipv6_addr = packet[IPv6].src - LOGGER.info(f"Device has formed SLAAC address {packet[IPv6].src}") - return True + if ICMPv6ND_NS in packet: + ipv6_addr = str(packet[ICMPv6ND_NS].tgt) + if ipv6_addr.startswith(SLAAC_PREFIX): + self._ipv6_addr = ipv6_addr + LOGGER.info(f"Device has formed SLAAC address {ipv6_addr}") + return True if sends_ipv6: LOGGER.info("Device does not support IPv6 SLAAC")