Skip to content

switch: makes driver architecture compliant#282

Merged
lePereT merged 6 commits into
migration-basefrom
swdrv-fix
Jun 23, 2026
Merged

switch: makes driver architecture compliant#282
lePereT merged 6 commits into
migration-basefrom
swdrv-fix

Conversation

@lePereT

@lePereT lePereT commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Bug Fix
  • Code Refactor
  • Documentation Update
  • Test

Description

Fixes HAL wired manager startup and RTL8380M switch observation when the external switch is slow, temporarily unavailable or expensive to poll.

The wired manager previously let switch reads affect configuration admission. In practice, a slow RTL8380M command such as sys_cpumem could cause HAL manager apply to fail even though the wired provider configuration was valid. The manager could also emit provider state before HAL had processed capability registration, creating ordering and backpressure problems during startup.

This PR separates configuration admission, capability registration and switch observation.

Changes include:

  • HAL wired manager now validates config, constructs backend objects, constructs provider runners, registers wired-provider capabilities, and starts runners.

  • The manager no longer calls RTL8380M backend methods directly after construction.

  • Each provider has one owned runner with a mailbox.

  • The runner owns backend access, request serialisation, poll scheduling, observation cache and changed-retained raw publication.

  • Runner emission waits for HAL capability registration before publishing raw provider facts.

  • External switch failures are published as raw provider status facts instead of failing manager apply.

  • Internal admission failures, such as invalid config, backend construction failure or runner start failure, still fail manager apply.

  • RTL8380M grouped observation now uses observe_groups_op.

  • Switch polling coalesces due groups and de-duplicates shared CGI commands such as home_main.

  • Saturated polling does not catch up in a tight loop; the next attempt is scheduled from completion time.

  • Backend naming is now explicit:

    • backend: callable backend object
    • provider_name: configured backend kind, for example rtl8380m_http
    • provider_id: instance id, for example switch-main
  • Raw retained topics remain under raw/host/wired/provider/<id>/....

  • Device/Wired boundaries remain unchanged: Device owns physical assembly, and Wired owns semantic state/wired/... projection.

The measured switch timings and grouped observation design are documented in docs/switch.md.

Manual test

  • yes

Manual test description

Started Devicecode with switch credentials set and confirmed HAL wired manager no longer fails configuration admission on switch observation timeout.

Validated that:

  • HAL continues starting when a switch observation times out.
  • Provider capability registration happens before raw provider facts are emitted.
  • The provider runner serialises switch access without locks or semaphores.
  • Grouped observations coalesce duplicate switch CGI commands.
  • The fast switch observation path continues to publish link/PoE/counter state independently of the slow runtime read.
  • The real RTL8380M switch path works through devhost integration tests.
  • OpenWrt VM composition still works after the manager/runner changes.

Representative checks:

cd tests

SWITCH_TEST_BASE_URL=http://192.168.1.1/ \
SWITCH_TEST_USERNAME=admin \
SWITCH_TEST_PASSWORD=admin \
TEST_FILTER=rtl8380m_real_switch \
lua run.lua
cd tests/integration/openwrt_vm
make test

Added tests?

  • yes

Added or updated tests cover:

  • real RTL8380M grouped observation via HTTP capability
  • real RTL8380M runner publication of raw observations
  • real switch raw observations projecting into state/wired
  • strict wired-provider configuration errors
  • mandatory observe_groups_op backend contract
  • backend/provider naming separation
  • Device assembly plus raw switch observations projecting to Wired
  • OpenWrt VM wired composition continuing to work after the runner changes

Added to documentation?

  • docs/switch.md

@lePereT lePereT changed the title makes switch driver architecture cimpliant switch: makes driver architecture compliant Jun 17, 2026
@lePereT lePereT requested a review from rslater-cs June 18, 2026 00:25
@lePereT lePereT marked this pull request as ready for review June 18, 2026 00:25
@lePereT lePereT merged commit 71ba495 into migration-base Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant