Skip to content

Commit

Permalink
Earlier prober
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Nov 1, 2023
1 parent 3538604 commit 12307e4
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,11 @@ def __init__(self, platform: Android, artifact_dir: str) -> None:
self.resolver_logs = ''
self.sigma_logs = ''
self.fail_trace_line_counter = -1
self.real_time = True

def rt_log(self, line):
if self.real_time:
self.logger.info(line)

def _log_proc_matter_commissioner(self, line: str) -> None:
"""Core commissioning flow"""
if 'MatterCommissioner' in line:
self.rt_log(line)
self.logger.info(line)
self.matter_commissioner_logs += line

def _log_proc_commissioning_failed(self, line: str) -> None:
Expand All @@ -62,29 +57,28 @@ def _log_proc_commissioning_failed(self, line: str) -> None:
self.failure_stack_trace += line
self.fail_trace_line_counter += 1
if 'SetupDeviceView' and 'Commissioning failed' in line:
self.rt_log(line)
self.logger.info(line)
self.fail_trace_line_counter = 0
self.failure_stack_trace += line

def _log_proc_pake(self, line: str) -> None:
"""Three logs for pake 1-3 expected"""
if "Pake" in line and "chip_logging" in line:
self.rt_log(line)
self.logger.info(line)
self.pake_logs += line

def _log_proc_mdns(self, line: str) -> None:
if "_matter" in line and "ServiceResolverAdapter" in line:
self.rt_log(line)
self.logger.info(line)
self.resolver_logs += line

def _log_proc_sigma(self, line: str) -> None:
"""Three logs expected for sigma 1-3"""
if "Sigma" in line and "chip_logging" in line:
self.rt_log(line)
self.logger.info(line)
self.sigma_logs += line

def show_analysis(self) -> None:
self.real_time = False
analysis_file = open(self.analysis_file_name, mode="w+")
print_and_write(add_border('Matter commissioner logs'), analysis_file)
print_and_write(self.matter_commissioner_logs, analysis_file)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/interop/idt/capture/pcap/pcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, artifact_dir: str, interface: str) -> None:
self.artifact_dir,
create_standard_log_name(
"pcap",
"cap")))
"pcap")))
self.start_delay_seconds = 2
self.interface = interface
self.pcap_command = f"tcpdump -i {self.interface} -n -w {self.output_path}"
Expand Down
3 changes: 2 additions & 1 deletion src/tools/interop/idt/capture/platform/android/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
#

enable_build_push_tcpdump = True
enable_bug_report = True
# TODO: Replace
enable_bug_report = False
hci_log_level = "full"
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

import asyncio
import os
import platform as host_platform
from typing import TYPE_CHECKING

from capture.utils.artifact import create_standard_log_name, safe_mkdir
from capture.utils.shell import Bash
from capture.utils.host_platform import is_mac

from ... import config
from ..base import AndroidStream
Expand All @@ -39,7 +39,7 @@ class AndroidPcap(AndroidStream):
def __init__(self, platform: "Android"):
self.logger = logger
self.platform = platform
self.pcap_artifact = create_standard_log_name("android_tcpdump", "cap", parent=platform.artifact_dir)
self.pcap_artifact = create_standard_log_name("android_tcpdump", "pcap", parent=platform.artifact_dir)
self.pcap_phone_out_path = f"/sdcard/Movies/{os.path.basename(self.pcap_artifact)}"
self.pcap_phone_bin_location = "tcpdump" if platform.capabilities.c_has_tcpdump else "/sdcard/Movies/tcpdump"
self.pcap_command = f"shell {self.pcap_phone_bin_location} -w {self.pcap_phone_out_path}"
Expand Down Expand Up @@ -69,8 +69,7 @@ async def start(self):
return
if not os.path.exists(os.path.join(self.build_dir, "tcpdump")):
self.logger.warning("tcpdump bin not found, attempting to build, please wait a few moments!")
p = host_platform.platform().lower()
if "darwin" in p or "mac" in p:
if is_mac():
self.logger.critical("Build Android tcpdump on macOS not supported!")
return
safe_mkdir(self.build_dir)
Expand Down
34 changes: 34 additions & 0 deletions src/tools/interop/idt/capture/utils/host_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2023 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import platform as host_platform


def is_mac():
p = host_platform.platform().lower()
return "darwin" in p or "mac" in p


def get_ll_interface():
net_interface_path = "/sys/class/net/"
available_net_interfaces = os.listdir(net_interface_path) \
if os.path.exists(net_interface_path) \
else []
for interface in available_net_interfaces:
if "wl" in interface:
return interface
return "en0"
1 change: 1 addition & 0 deletions src/tools/interop/idt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@

enable_color = True
log_level = logging.INFO
enable_generic_prober_in_capture = False
1 change: 1 addition & 0 deletions src/tools/interop/idt/discovery/ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, artifact_dir: str):

def parse_vid_pid(self, loggable_data: str) -> str:
try:
self.logger.critical(loggable_data)
vid = loggable_data[8:10] + loggable_data[6:8]
pid = loggable_data[12:14] + loggable_data[10:12]
except IndexError:
Expand Down
18 changes: 17 additions & 1 deletion src/tools/interop/idt/discovery/dnssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
# limitations under the License.
#

import asyncio

import log
from zeroconf import ServiceBrowser, ServiceInfo, ServiceListener, Zeroconf

logger = log.get_logger(__file__)


_MDNS_TYPES = {
"_matterd._udp.local.": "COMMISSIONER",
"_matterc._udp.local.": "COMMISSIONABLE",
Expand All @@ -29,12 +30,16 @@
}


# TODO: display discriminator (to hex), device type (decode), Pairing hint (decode)
# TODO: Write log!

class MatterDnssdListener(ServiceListener):

def __init__(self, artifact_dir: str) -> None:
super().__init__()
self.artifact_dir = artifact_dir
self.logger = logger
self.discovered_matter_devices: [str, ServiceInfo] = {}

@staticmethod
def log_addr(info: ServiceInfo) -> str:
Expand All @@ -60,6 +65,8 @@ def handle_service_info(
name: str,
delta_type: str) -> None:
info = zc.get_service_info(type_, name)
if "matter" in type_:
self.discovered_matter_devices[name] = info
to_log = f"{name}\n"
if info.properties is not None:
for name, value in info.properties.items():
Expand All @@ -80,6 +87,8 @@ def update_service(self, zc: Zeroconf, type_: str, name: str) -> None:
def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None:
to_log = f"Service {name} removed\n"
to_log += _MDNS_TYPES[type_]
if name in self.discovered_matter_devices:
del self.discovered_matter_devices[name]
self.logger.warning(to_log)

def browse_interactive(self) -> None:
Expand All @@ -89,3 +98,10 @@ def browse_interactive(self) -> None:
input("Browsing Matter DNS-SD, press enter to stop\n")
finally:
zc.close()

async def browse_once(self) -> Zeroconf:
zc = Zeroconf()
ServiceBrowser(zc, list(_MDNS_TYPES.keys()), self)
await asyncio.sleep(10)
zc.close()
return zc
19 changes: 19 additions & 0 deletions src/tools/interop/idt/idt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from capture import EcosystemController, EcosystemFactory, PacketCaptureRunner, PlatformFactory
from capture.utils.artifact import create_file_timestamp, safe_mkdir
from capture.utils.shell import Bash
from probe import GenericMatterProber
from discovery import MatterBleScanner, MatterDnssdListener
from log import border_print

Expand Down Expand Up @@ -91,6 +92,7 @@ def __init__(self) -> None:

self.ble_artifact_dir = os.path.join(self.artifact_dir, "ble")
self.dnssd_artifact_dir = os.path.join(self.artifact_dir, "dnssd")
self.prober_dir = os.path.join(self.artifact_dir, "probes")

self.process_args()

Expand Down Expand Up @@ -175,6 +177,9 @@ def process_args(self) -> None:

capture_parser.set_defaults(func=self.command_capture)

prober_parser = subparsers.add_parser("probe", help="Probe all Matter devices on the local environment.")
prober_parser.set_defaults(func=self.command_probe)

args, unknown = parser.parse_known_args()
if not hasattr(args, 'func'):
parser.print_help()
Expand Down Expand Up @@ -225,5 +230,19 @@ def command_capture(self, args: argparse.Namespace) -> None:
border_print("Errors seen this run:")
EcosystemController.error_report(self.artifact_dir)

if config.enable_generic_prober_in_capture:
border_print("Starting generic Matter prober for local environment!")
safe_mkdir(self.dnssd_artifact_dir)
safe_mkdir(self.prober_dir)
GenericMatterProber(self.prober_dir, self.dnssd_artifact_dir).probe()
else:
border_print("Generic prober disabled in config!")

border_print("Compressing artifacts...")
self.zip_artifacts()

def command_probe(self, args: argparse.Namespace) -> None:
border_print("Starting generic Matter prober for local environment!")
safe_mkdir(self.dnssd_artifact_dir)
safe_mkdir(self.prober_dir)
GenericMatterProber(self.prober_dir, self.dnssd_artifact_dir).probe()
22 changes: 22 additions & 0 deletions src/tools/interop/idt/probe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) 2023 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from .probe import GenericMatterProber

__all__ = [
'GenericMatterProber',
]
Loading

0 comments on commit 12307e4

Please sign in to comment.