Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDT v0.0.2 #29931

Merged
merged 72 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
197ee77
Squashed commit of the following:
aBozowski Oct 24, 2023
9f6c346
Restyled by prettier-markdown
restyled-commits Oct 24, 2023
ae08ff9
Restyled by shellharden
restyled-commits Oct 24, 2023
c9d97a8
Restyled by autopep8
restyled-commits Oct 24, 2023
741053f
Restyled by isort
restyled-commits Oct 24, 2023
cbb5d74
Spelling
aBozowski Oct 24, 2023
51d41ec
Lints
aBozowski Oct 24, 2023
eccd8ff
Support RPi install
aBozowski Oct 24, 2023
b04e3ac
Restyled by prettier-markdown
restyled-commits Oct 24, 2023
508e9c3
Uneeded sudo
aBozowski Oct 24, 2023
abb7682
Readme clarification
aBozowski Oct 25, 2023
66da92d
Remove dead comment
aBozowski Oct 25, 2023
44a674f
Remove dead comment
aBozowski Oct 25, 2023
2c45a83
Squashed commit of the following:
aBozowski Oct 26, 2023
fec6ade
Fix stopping procs on mac
aBozowski Oct 26, 2023
5be5566
Replace multiproc with async
aBozowski Oct 26, 2023
ab2b58a
Fix sudo kill issue on macOS
aBozowski Oct 26, 2023
e5e907e
Note
aBozowski Oct 26, 2023
bb5da32
Fix stopping pcap issue on macOS
aBozowski Oct 26, 2023
458eabe
Cleanup
aBozowski Oct 26, 2023
32faea9
BLE scanning on macOS
aBozowski Oct 26, 2023
3538604
Final cleanup for macOS and README
aBozowski Oct 28, 2023
813d1c1
Squashed commit of the following:
aBozowski Nov 3, 2023
b1c5205
Nits
aBozowski Nov 3, 2023
e7850b8
Merge branch 'project-chip:master' into idt/0.0.2
aBozowski Nov 3, 2023
73bd395
Remove temp tests
aBozowski Nov 3, 2023
034fb94
Prevent re run of Bash proc and nits
aBozowski Nov 3, 2023
ab05527
Restyled by prettier-markdown
restyled-commits Nov 3, 2023
49f12ad
Restyled by autopep8
restyled-commits Nov 3, 2023
a92c249
Restyled by isort
restyled-commits Nov 3, 2023
e4ec4d9
Spelling
aBozowski Nov 3, 2023
7227137
Lint
aBozowski Nov 3, 2023
d5cfffc
Respond comment.
aBozowski Nov 3, 2023
823b65b
Comment and rename
aBozowski Nov 3, 2023
42f2afc
Nits
aBozowski Nov 3, 2023
5f80ab3
Clarify
aBozowski Nov 3, 2023
2c8af56
Add info on interfaces to README
aBozowski Nov 3, 2023
3e95a19
Document failure mode of not allowing bt perms in macOS
aBozowski Nov 3, 2023
21772e6
Restyled by prettier-markdown
restyled-commits Nov 3, 2023
855f16f
Restyled by isort
restyled-commits Nov 3, 2023
7ca67b1
Verify py version and fix non py dep check
aBozowski Nov 3, 2023
84aea8b
Move host dependencies back to main
aBozowski Nov 3, 2023
8cd3f6b
Fix py version check
aBozowski Nov 3, 2023
43d047e
Make task cleanup more graceful
aBozowski Nov 6, 2023
48f84ff
Nit
aBozowski Nov 6, 2023
2e829e3
Respond comments
aBozowski Nov 6, 2023
437e057
Ensure which is available in host_platform
aBozowski Nov 7, 2023
4282315
Add mac tcpdump build script thanks to James
aBozowski Nov 8, 2023
68d1f33
README
aBozowski Nov 8, 2023
5188d5d
Logging
aBozowski Nov 8, 2023
e2d3dfa
Explain all DNS SD content to the user (parse TXT etc.)
aBozowski Nov 9, 2023
312a2ce
Remove TODO
aBozowski Nov 9, 2023
75251da
TTL and nits
aBozowski Nov 9, 2023
4663ea6
Logging, limit tracert, nits
aBozowski Nov 11, 2023
f0f2581
Restyled by prettier-markdown
restyled-commits Nov 11, 2023
900ae84
Restyled by shellharden
restyled-commits Nov 11, 2023
05260ab
Restyled by shfmt
restyled-commits Nov 11, 2023
273ef27
Restyled by autopep8
restyled-commits Nov 11, 2023
4bf9c00
Restyled by isort
restyled-commits Nov 11, 2023
ba42fb4
Integrate mac android tcp and bump restyle
aBozowski Nov 11, 2023
5529108
Use termcolor for colored logs
aBozowski Nov 15, 2023
9c2d5d2
Timeout config documentation
aBozowski Nov 15, 2023
c306d97
Remove unnecessary abstractions from controller
aBozowski Nov 15, 2023
728bdc5
Cleanup py version check
aBozowski Nov 15, 2023
2077921
Cleanup error reporting in controller
aBozowski Nov 15, 2023
34994fb
Remove unneeded instance vars in playservices
aBozowski Nov 15, 2023
7b96280
Fix logcat file scope issue introd in last commit
aBozowski Nov 15, 2023
3c7d84b
Fix dedent
aBozowski Nov 15, 2023
8ac91e8
Add bison to Dockerfile
aBozowski Nov 15, 2023
49cb349
Make screen on check in android explicit
aBozowski Nov 15, 2023
7f8bd3c
Restyled by autopep8
restyled-commits Nov 15, 2023
1da33c2
Restyled by isort
restyled-commits Nov 15, 2023
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
1 change: 1 addition & 0 deletions src/tools/interop/idt/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__/
pycache/
venv/
.zip
BUILD
5 changes: 5 additions & 0 deletions src/tools/interop/idt/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ RUN apt-get update && \
adb \
aircrack-ng \
apt-utils \
byacc \
dnsutils \
flex \
aBozowski marked this conversation as resolved.
Show resolved Hide resolved
gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabi \
git \
glib-2.0 \
kmod \
Expand Down
209 changes: 131 additions & 78 deletions src/tools/interop/idt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,32 @@ issue uncovered via the manual test. Each ecosystem may implement an analysis
that analyzes capture data, displays info to the user, probes the local
environment and generates additional artifacts.

## Getting started
## Single host installation (no Raspberry Pi)

All features of `idt` are available on macOS and Linux (tested with Debian based
systems).
If you would prefer to execute capture and discovery from a Raspberry Pi, read
the next section instead.

The machine running `idt` should be connected to the same Wi-Fi network used for
testing.
Follow the steps below to execute capture and discovery without a Raspberry Pi:

- From the parent directory of `idt`, run `source idt/scripts/alias.sh`.
- Optionally, run `source idt/scripts/setup_shell.sh` to install aliases
permanently.
- After `idt` aliases are available in your environment, calling any `idt`
command will automatically create a new virtual environment and install
python dependencies.
- If you're missing non-Python dependencies, you'll be prompted to install
them until they're available.
- Bluetooth discovery on macOS will require granting the program where `idt`
is run, e.g. terminal emulator or IDE permission to access bluetooth in
macOS settings.
- Failure to do so may result in any of the following:
- A single `abort` message and no further output in the terminal.
- Failure with a relevant stack trace in the terminal.
- A prompt to allow the application access to bluetooth.

## Raspberry Pi installation

Expand Down Expand Up @@ -137,62 +162,21 @@ idt_clean
```

NOTE the idt artifacts directory is contained in idt, so running this will
delete any artifacts ([TODO] change).
delete any artifacts.

Then from the admin computer:

```
idt_push
```

## Single host installation (no Raspberry Pi)

Follow the steps below to execute capture and discovery without a Raspberry Pi.

### Linux installation

#### Requirements

- This package should work on most Debian (/based) systems.
- `idt` is currently tested on `Python 3.11`.
- `adb` and `tcpdump` are required.
- The machine running `idt` should be connected to the same Wi-Fi network used
for testing.

#### Setup

- From the parent directory of `idt`, run `source idt/scripts/alias.sh`.
- Optionally, run `source idt/scripts/setup_shell.sh` to install aliases
permanently.

> You may use `idt` in a Python virtual environment OR using a container from
> the idt image.

#### Python virtual environment

- After `idt` aliases are available in your environment, calling any `idt`
command will automatically create a new virtual environment and install
dependencies.

#### Docker

- Run `idt_build` and `idt_activate` to enter the `idt` container.

[TODO] Podman

### macOS installation

Most features other than BLE should work on macOS.

Follow the Linux installation steps above, but do not use Docker.

[TODO] macOS BLE support

## User guide

> **_IMPORTANT_**
> `idt_` commands are shell aliases helpful for administrative commands.
> `idt` invokes the `idt` python package.
> `idt` invokes the `idt` python package.
> Output from `idt` will generally be colorized while output from sub processes
> is generally not.

RPi users, as needed:

Expand All @@ -208,45 +192,38 @@ RPi users, as needed:

### Capture

> **_IMPORTANT_**
> Ensure you've made it to the log line "Starting real time analysis, press
> enter to stop!" before launching the app under test.

```
idt capture -h

usage: idt capture [-h] [--platform {Android}]
[--ecosystem {PlayServices,PlayServicesUser,ALL}]
[--pcap {t,f}]
[--interface {wlp0s20f3,docker0,lo}]
[--additional {t,f}]
usage: idt capture [-h] [--platform {Android}] [--ecosystem {PlayServicesUser,PlayServices,ALL}] [--pcap {t,f}] [--interface {wlp0s20f3,lo,docker0,any}]
aBozowski marked this conversation as resolved.
Show resolved Hide resolved

options:
-h, --help show this help message and exit
--platform {Android}, -p {Android}
Run capture for a particular platform
(default Android)
--ecosystem {PlayServices,PlayServicesUser,ALL}, -e {PlayServices,PlayServicesUser,ALL}
Run capture for a particular ecosystem or ALL
ecosystems (default ALL)
Run capture for a particular platform (default Android)
--ecosystem {PlayServicesUser,PlayServices,ALL}, -e {PlayServicesUser,PlayServices,ALL}
Run capture for a particular ecosystem or ALL ecosystems (default ALL)
--pcap {t,f}, -c {t,f}
Run packet capture (default t)
--interface {wlp0s20f3,docker0,lo}, -i {wlp0s20f3,docker0,lo}
Run packet capture against a specified
interface (default wlp0s20f3)
--additional {t,f}, -a {t,f}
Run ble and mdns scanners in the background
while capturing (default t)
--interface {wlp0s20f3,lo,docker0,any}, -i {wlp0s20f3,lo,docker0,any}
Specify packet capture interface (default any)
```

For packet capture interface (`-i`/`--interface`:

- On macOS, the only available interface is `any`.
- On Linux, `idt` checks available interfaces from `/sys/class/net/` as well
as allowing `any`.

#### Artifacts

Each ecosystem and platform involved in the capture will have their own
subdirectory in the root artifact dir.

To download your artifacts, run these commands from your admin computer:

`idt_fetch_artifacts`

On windows admin computers, you may use `FileZilla` to pull the archive listed
at the end of output.

### Discovery

```
Expand All @@ -260,7 +237,7 @@ options:
Specify the type of discovery to execute
```

#### ble
#### BLE

```
idt discover -t b
Expand All @@ -274,13 +251,90 @@ idt discover -t d

#### Artifacts

There is a per device log for ble scanning in `ble` subdirectory of the root
artifact dir.
There is a per device log in `ble` and `dnssd` subdirectory of the root artifact
dir.

### Probe

```
usage: idt probe [-h]

options:
-h, --help show this help message and exit
```

[TODO] dnssd per device log
Collect contextually relevant networking info from the local environment and
provide artifacts.

## Troubleshooting

- Wireless `adb` may fail to connect indefinitely depending on network
configuration. Use a wired connection if wireless fails repeatedly.
- Change log level from `INFO` to `DEBUG` in root `config.py` for additional
logging.
- Compiling `tcpdump` for android may require additional dependencies.
- If the build script fails for you, try
`idt_go && source idt/scripts/compilers.sh`.
- You may disable colors and splash by setting `enable_color` in `config.py`
to `False`.
- `idt_clean_child` will kill any stray `tcpdump` and `adb` commands.
- `idt_check_child` will look for leftover processes.
- Not expected to be needed outside of development scenarios.

## Project overview

- The entry point is in `idt.py` which contains simple CLI parsing with
`argparse`.

### `capture`

- `base` contains the base classes for ecosystems and platforms.
- `controller` contains the ecosystem and platform producer and controller
- `loader` is a generic class loader that dynamically imports classes matching
a given super class from a given directory.
- `/platform` and `/ecosystem` contain one package for each platform and
ecosystem, which should each contain one implementation of the respective
base class.

### `discovery`

- `matter_ble` provides a simple ble scanner that shows matter devices being
discovered and lost, as well as their VID/PID, RSSI, etc.
- `matter_dnssd` provides a simple DNS-SD browser that searches for matter
devices and thread border routers.
aBozowski marked this conversation as resolved.
Show resolved Hide resolved

### `probe`

- `probe` contains the base class for (`idt`'s) host platform specific
implementation.
- Reuses the dnssd discovery implementation to build probe targets.
- Calls platform + addr type specific probe methods for each target.
- `linux` and `mac` contain `probe` implementations for each host platform.

### `utils`

- `log` contains logging utilities used by everything in the project.
- `artifact` contains helper functions for managing artifacts.
- `shell` contains a simple helper class for background and foreground Bash
commands.
- `host_platform` contains helper functions for the interacting with the host
running `idt`.

### Conventions

- `config.py` should be used to hold development configs within the directory
where they are needed.
- It may also hold configs for flaky/cumbersome features that might need
to be disabled in an emergency.
- `config.py` **should not** be used for everyday operation.
- When needed, execute builds in a folder called `BUILD` within the source
tree.
- `idt_clean_all` deletes all `BUILD` dirs and `BUILD` is in `.gitignore`.

## Extending functionality

### Capture

Ecosystem and Platform implementations are dynamically loaded.

For each package in `capture/ecosystem`, the ecosystem loader expects a module
Expand All @@ -299,14 +353,13 @@ $ idt capture -h
usage: idt capture [-h] [--platform {Android}] [--ecosystem {DemoExtEcosystem...
```

> **IMPORTANT:** Note the following runtime expectations of ecosystems:
> `analyze_capture()` must not block the async event loop excessively and must
> not interact with standard in

The platform loader functions the same as `capture/ecosystem`.

For each package in `capture/platform`, the platform loader expects a module
name matching the package name.
This module must contain a single class which is a subclass of
`capture.base.PlatformLogStreamer`.

Note the following runtime expectations of platforms:

- Start should be able to be called repeatedly without restarting streaming.
- Stop should not cause an error even if the stream is not running.
2 changes: 2 additions & 0 deletions src/tools/interop/idt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#

from idt import InteropDebuggingTool
from utils.host_platform import verify_py_version

if __name__ == "__main__":
verify_py_version()
InteropDebuggingTool()
4 changes: 2 additions & 2 deletions src/tools/interop/idt/capture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

from capture import ecosystem, platform

from .factory import EcosystemCapture, EcosystemController, EcosystemFactory, PlatformFactory, PlatformLogStreamer
from .controller import EcosystemCapture, EcosystemFactory, Orchestrator, PlatformFactory, PlatformLogStreamer
from .pcap import PacketCaptureRunner

__all__ = [
'ecosystem',
'platform',
'EcosystemCapture',
'EcosystemController',
'EcosystemFactory',
'Orchestrator',
'PacketCaptureRunner',
'PlatformFactory',
'PlatformLogStreamer',
Expand Down
34 changes: 29 additions & 5 deletions src/tools/interop/idt/capture/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,33 @@ def __init__(self, artifact_dir: str) -> None:
"""
raise NotImplementedError

@abstractmethod
async def connect(self) -> None:
"""
Establish connections to log targets for this platform
"""
raise NotImplementedError

@abstractmethod
async def start_streaming(self) -> None:
"""
Begin streaming logs
Start should be able to be called repeatedly without restarting streaming
aBozowski marked this conversation as resolved.
Show resolved Hide resolved
"""
raise NotImplementedError

@abstractmethod
async def run_observers(self) -> None:
"""
Observe log procs and restart as needed
Must be async aware and not interact with stdin
"""
raise NotImplementedError

@abstractmethod
async def stop_streaming(self) -> None:
"""
Stop streaming logs
Stop should not cause an error even if the stream is not running
Stop the capture and pull any artifacts from remote devices
aBozowski marked this conversation as resolved.
Show resolved Hide resolved
Write artifacts to artifact_dir passed on instantiation
"""
raise NotImplementedError

Expand Down Expand Up @@ -71,20 +85,30 @@ def __init__(
async def start_capture(self) -> None:
"""
Start the capture
Platform is already started
"""
raise NotImplementedError

@abstractmethod
async def stop_capture(self) -> None:
"""
Stop the capture
Stop the capture and pull any artifacts from remote devices
Write artifacts to artifact_dir passed on instantiation
Platform is already stopped
"""
raise NotImplementedError

@abstractmethod
async def analyze_capture(self) -> None:
"""
Parse the capture and create + display helpful analysis artifacts that are unique to the ecosystem
Write analysis artifacts to artifact_dir
Must be async aware and not interact with stdin
"""
raise NotImplementedError

@abstractmethod
async def probe_capture(self) -> None:
"""
Probe the local environment, e.g. ping relevant remote services and write respective artifacts
aBozowski marked this conversation as resolved.
Show resolved Hide resolved
"""
raise NotImplementedError
Loading
Loading