Skip to content

Implements extra ETS cache for DevAddr range lookups#326

Merged
macpie merged 8 commits intomainfrom
macpie/devaddr_cache
Mar 12, 2026
Merged

Implements extra ETS cache for DevAddr range lookups#326
macpie merged 8 commits intomainfrom
macpie/devaddr_cache

Conversation

@macpie
Copy link
Member

@macpie macpie commented Mar 11, 2026

Implements a fast in-memory cache for DevAddr range lookups to address performance issues when the devaddr_ranges ETS table grows large.

Changes:

  • Added cache ETS table (hpr_devaddr_cache_ets) storing {DevAddr, {RouteIDs, Timestamp}}
  • Modified lookup/1 to check cache before expensive ETS select operations
  • Implemented TTL-based expiration (default 12 hours, configurable via devaddr_cache_ttl_ms)
  • Added cache invalidation on route updates (insert, delete, replace operations)
  • Added Prometheus metrics: devaddr_cache_hit_counter and devaddr_cache_miss_counter
  • Added CLI commands: "hpr config cache clear" and "hpr config cache stats"
  • Added comprehensive unit tests (8 tests covering cache behavior)

performance issues when the devaddr_ranges ETS table grows large.

Changes:
- Added cache ETS table (hpr_devaddr_cache_ets) storing {DevAddr, {RouteIDs, Timestamp}}
- Modified lookup/1 to check cache before expensive ETS select operations
- Implemented TTL-based expiration (default 12 hours, configurable via devaddr_cache_ttl_ms)
- Added cache invalidation on route updates (insert, delete, replace operations)
- Added Prometheus metrics: devaddr_cache_hit_counter and devaddr_cache_miss_counter
- Added CLI commands: "hpr config cache clear" and "hpr config cache stats"
- Added comprehensive unit tests (8 tests covering cache behavior)
@macpie macpie requested a review from michaeldjeffrey March 11, 2026 19:56
@macpie macpie marked this pull request as ready for review March 11, 2026 20:10
@macpie macpie force-pushed the macpie/devaddr_cache branch from 48437ac to 0e05928 Compare March 11, 2026 20:57
macpie added 4 commits March 11, 2026 15:00
Adds three new CLI commands to manage all routes for a given OUI:
- config oui activate <oui> - Activate all routes for an OUI
- config oui deactivate <oui> - Deactivate all routes for an OUI
- config oui refresh <oui> - Refresh all routes for an OUI from API

Also refactors activate/deactivate logic into a common set_routes_active/2
helper function used by both route-level and OUI-level commands, reducing
code duplication and ensuring consistent behavior.

The refresh command fetches all routes from the Config Service API using
get_api_routes_for_oui/1 to ensure completeness, then spawns a background
process to refresh each route with detailed logging.
Extended the `set_routes_active` helper function to automatically manage route data during activation and deactivation:

When deactivating routes:
- Remove all Session Key Filters (SKFs) for the route
- Remove all DevAddr ranges for the route
- Remove all EUI pairs for the route
- Keep the route record itself for potential reactivation

When activating routes:
- Automatically refresh the route to fetch SKFs, DevAddr ranges, and EUI pairs from the IoT Config Service

This ensures routes are in a clean, consistent state when toggled and eliminates orphaned data that could cause routing issues.

Changes:
- Update `set_routes_active/2` to call delete/refresh functions based on activation state
- Export test functions from hpr_cli_config for CT suite testing
- Add 4 new CT tests verifying single route and OUI-level activation/deactivation
- Fix race condition in hpr_packet_router_service eunit test (add timer:sleep before meck assertion)
- Add hpr_metrics mocking to test setup functions to prevent undefined function errors
- Add .coverdata to gitignore
@macpie macpie merged commit 26ad52e into main Mar 12, 2026
17 checks passed
@macpie macpie deleted the macpie/devaddr_cache branch March 12, 2026 16:51
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.

2 participants