Skip to content

Add named discovery scans and Discovery Node parity to Spotter - #1511

Draft
khyatimahendru wants to merge 31 commits into
faucetsdn:masterfrom
khyatimahendru:spotter-named-scans-parity
Draft

khyatimahendru wants to merge 31 commits into
faucetsdn:masterfrom
khyatimahendru:spotter-named-scans-parity

Conversation

@khyatimahendru

Copy link
Copy Markdown
Collaborator

Adds UDMI named discovery scans (config.discovery.scans.<name>) and Discovery Node (#1449) feature parity to the Spotter reference edge node (edge/spotter/), enabling concurrent independent scans, per-family exclusivity locking, and resilient nmap execution.

Depends on #1487
Depends on #1498

Key changes in this PR:

  • Named scans (config.discovery.scans.<name>): Refactors SpotterDiscoveryManager around ScanKey = (families|scans, name) with per-scan provider factories, state.discovery.scans.<name> lifecycle tracking, [scans/<name>] / [families/<fam>] log prefixes, and scan tagging on both events/discovery and upload/discovery (adding optional scan to schema/upload_discovery.json).
  • Per-family exclusivity lock: Adds a process-wide non-blocking lock for exclusive families (bacnet, shared across standard active scans and depth: "trace" captures); overlapping runs are skipped with status 500 and retried at the next interval if periodic.
  • nmap feature parity (discoverynode: support named scans, netblock targets, various fixes #1449): Writes nmap XML to a temporary file (-oX <tempfile>) so --stats-every 60s progress logging does not corrupt XML stdout, enables OS detection (-O) for system/details depths (ancillary.os), and terminates scans cleanly via process groups (start_new_session=True, os.killpg).

Verification

  • edge/spotter/bin/run_spotter_tests unit — 103 unit tests + 3 self-tests passed (exit 0)
  • bin/gencode check — schema/code/docs/presentation hashes verified (exit 0)
  • bin/test_schema — schema fixture validation passed (exit 0)
  • bin/test_generated_classes_py — 131 passed (exit 0)

PR Stack

# PR Branch Summary
1 #1498 named-scans Named discovery scans schema, pubber, and sequencer
2 #1487 spotter-impl Spotter UDMI discovery & PCAP trace spec compliance
3 (this PR) spotter-named-scans-parity Spotter named scans & Discovery Node feature parity

Author Declaration

  • I have self-reviewed this PR.

Pull request created by Gemini

…Upload

- Add schema/upload_discovery.json defining DiscoveryUpload and ScanManifest for chunked packet capture streaming over upload/discovery.
- Add 'upload' to SubType enum in schema/envelope.json and remove legacy schema/events_streams.json.
- Regenerate Java and Python schema classes, HTML documentation, and .gencode_hash.txt.
- Add schema validation fixtures under tests/schemas/upload_discovery/ and document depth: 'trace' in docs/specs/discovery.md and docs/specs/discovery_bacnet.md.
- Ensure deterministic device ID ordering in SiteModel.getDeviceIds().
…entlib

- Add --upload_pubsub_topic_id support in MqttToPubSubBridge to route subType='upload' messages to a dedicated Pub/Sub publisher with graceful shutdown draining.
- Register uufi_upload flow in UdmiServicePod and udmis/etc/local_pod.json for local upload/# pass-through.
- Add publish_upload helper to clientlib BaseManager and include upload/# in MessageConnection default subscribe topics.
- Add unit tests in MqttToPubSubBridgeTest covering upload publisher routing and shutdown.
- Add PcapUploadHandler to reassemble gzip-compressed upload/discovery chunks in order, verify terminal SHA-256 digests, and archive .pcap and scan_manifest.json artifacts to GCS or local disk.
- Exclude subType='upload' messages from RawFallbackHandler so raw PCAP chunks are never persisted in udmi_messages.
- Add udmi_pcap_captures table in PostgresManager to track capture lifecycle metadata and URIs.
- Add trigger_bacnet_trace and get_pcap_capture tools across Butler discovery, ButlerProvider, ButlerMcpServer, and ButlerClient with unit tests and schema docs.
…CAP streaming

- Enforce strict UDMI discovery depth compliance ('buckets', 'entries', 'system', 'details', 'trace') across Spotter providers and fail fast on non-canonical legacy depths.
- Emit canonical '<TYPE>/<INSTANCE>' BACnet refs, hyphenated object types and ancillary keys, explicit families.ipv4.port (47808), ARP-resolved families.ethmac, and routed MS/TP '<net>:<mac>' bindings.
- Decode BACnet/IP BVLL Forwarded-NPDU real controller IPs/ports behind BBMDs, NPDU SNET/SADR MS/TP headers, and I-Am-Router-To-Network DNET lists in PassiveFamilyProvider.
- Implement raw-socket (SOCK_RAW) BACnet Who-Is and Who-Is-Router-To-Network discovery rounds during depth: 'trace' without binding UDP 47808, and stream gzipped DiscoveryUpload chunks with SHA-256 and ScanManifest over upload/discovery.
- Update reassemble_pcap, compare_field_parity, Spotter documentation, and unit/integration test suites.
…odel

- Lazily initialize Google Cloud Storage client in PcapUploadHandler._upload_to_gcs when BUTLER_PCAP_GCS_BUCKET is set and require sha256 on terminal EOF markers.
- Guard SpotterDiscoveryManager against superseded scan generation races when active scans are cancelled or replaced.
- Preserve BACnet I-Am enrichment and routed MS/TP re-emission across passive_sec holdoff intervals and bound I-Am-Router-To-Network parsing by bvlc_len.
- Issue per-range BACnet Who-Is discovery calls instead of collapsing disjoint addrs ranges and validate Nmap target specifications.
- Collect sorted device IDs into LinkedHashSet in SiteModel.getDeviceIds() and require connection spec in ButlerProvider.trigger_bacnet_trace.
- Wrap 101-character gracefulShutdown call in MqttToPubSubBridge.java to satisfy Checkstyle LineLength (<= 100 chars).
- Code-quote protocol and compression terms (BVLL, BBMD, NPDU, MS/TP, DNET, gzip) in docs/specs/discovery.md, docs/specs/discovery_bacnet.md, and docs/tools/spotter.md for Docs Spelling Checks.
Allow discovery configurations to define multiple independent scan schedules (such as concurrent periodic and on-demand scans, or distinct scans targeting the same protocol family) under `config.discovery.scans.<scan>`, reporting per-scan status in `state.discovery.scans.<scan>` and attributing emitted events via `scan` in `events_discovery`.

Named scans declare their target protocol via `family` in `config_discovery_family`, while legacy `config.discovery.families.<family>` entries preserve implicit key-based targeting and reject mismatched `family` overrides. `DiscoveryManager` coordinates both legacy family scans and named scans across shared protocol providers with mutual exclusion, preemption, and retry backoff.
Define named scans as a standalone primary mechanism in the discovery specs, schemas, and examples rather than framing them relative to legacy `families`. Extract scan scheduling into a concrete scheduler with FIFO deferral for busy sporadic scans, periodic retry semantics without implicit start-time fallback, and non-blocking host state locking so provider callbacks cannot deadlock `stopScan()` during config updates.
# Conflicts:
#	.gencode_hash.txt
Replace host-level lock hooks with a single-monitor outbox in DiscoveryScheduler and streamline DiscoveryManagerTest around behavioral coverage. Simplify periodic scheduling to target the next upcoming grid slot and skip busy periodic slots without emitting error noise, keeping the discovery spec and schema aligned.
# Conflicts:
#	.gencode_hash.txt
#	gencode/java/udmi/schema/DiscoveryEvents.java
#	gencode/python/udmi/schema/events_discovery.py
…it interface, exclude_capture_host, and I-Am manifest counts
…scans

Introduce a dedicated schema/config_discovery_scan.json (ScanDiscoveryConfig)
with required family for discovery.scans.<name>, remove family from
schema/config_discovery_family.json so legacy discovery.families.<family>
statically forbids it, regenerate Java/Python/HTML bindings, and update
DiscoveryScheduler, DiscoverySequences, DiscoveryManagerTest, and schema
error fixtures.
khyatimahendru added a commit to khyatimahendru/udmi that referenced this pull request Nov 27, 2026

This branch has not been deployed

No deployments
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