Skip to content

Commit

Permalink
Write dnssd log
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Nov 3, 2023
1 parent 1fe3f98 commit dc98974
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
11 changes: 10 additions & 1 deletion src/tools/interop/idt/discovery/dnssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
#

import asyncio
import os

import log
from zeroconf import ServiceBrowser, ServiceInfo, ServiceListener, Zeroconf
from capture.utils.artifact import create_standard_log_name


logger = log.get_logger(__file__)

Expand All @@ -31,16 +34,20 @@


# 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.log_name = os.path.join(self.artifact_dir, create_standard_log_name("dnssd", "txt"))
self.logger = logger
self.discovered_matter_devices: [str, ServiceInfo] = {}

def write_log(self, line: str) -> None:
with open(self.log_name, "a+") as log_file:
log_file.write(line)

@staticmethod
def log_addr(info: ServiceInfo) -> str:
ret = "\n"
Expand Down Expand Up @@ -76,6 +83,7 @@ def handle_service_info(
to_log += self.log_vid_pid(info)
to_log += self.log_addr(info)
self.logger.info(to_log)
self.write_log(to_log)

def add_service(self, zc: Zeroconf, type_: str, name: str) -> None:
self.handle_service_info(zc, type_, name, "ADDED")
Expand All @@ -89,6 +97,7 @@ def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None:
if name in self.discovered_matter_devices:
del self.discovered_matter_devices[name]
self.logger.warning(to_log)
self.write_log(to_log)

def browse_interactive(self) -> None:
zc = Zeroconf()
Expand Down
1 change: 1 addition & 0 deletions src/tools/interop/idt/probe/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
class ProberLinuxHost(p.GenericMatterProber):

def __init__(self, artifact_dir: str, dnssd_artifact_dir: str) -> None:
# TODO: Parity with macOS
super(ProberLinuxHost, self).__init__(artifact_dir, dnssd_artifact_dir)
self.logger = logger

Expand Down
26 changes: 19 additions & 7 deletions src/tools/interop/idt/probe/mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,31 @@ def __init__(self, artifact_dir: str, dnssd_artifact_dir: str) -> None:
super(ProberMacHost, self).__init__(artifact_dir, dnssd_artifact_dir)
self.logger = logger

def discover_targets_by_neighbor(self) -> None:
self.logger.info("Arp")
self.run_command("arp -a")
self.logger.info("Neigh")
self.run_command("ndp -an")

def check_routes(self) -> None:
self.logger.info("v6")
self.run_command("netstat -r -f inet6 -n")

def probe_v4(self, target: ProbeTarget) -> None:
self.logger.info("Ping")
self.run_command(f"ping -c {config.ping_count} {target.ip}")
self.logger.info("Route")
# TODO

def probe_v6(self, target: ProbeTarget) -> None:
self.logger.info("Ping")
self.run_command(f"ping6 -c {config.ping_count} {target.ip}")
self.logger.info("Route")
# TODO

def probe_v6_ll(self, target: ProbeTarget) -> None:
interface = get_ll_interface()
self.logger.info("Ping")
self.run_command(f"ping6 -c {config.ping_count} -I {interface} {target.ip}")

def discover_targets_by_neighbor(self) -> None:
self.run_command("arp -a")
self.run_command("ndp -an")

def check_routes(self) -> None:
self.run_command("netstat -r -f inet6 -n")
self.logger.info("Route")
# TODO

0 comments on commit dc98974

Please sign in to comment.