Skip to content

happy maps#682

Open
taspelund wants to merge 3 commits intomainfrom
trey/map_cleanup
Open

happy maps#682
taspelund wants to merge 3 commits intomainfrom
trey/map_cleanup

Conversation

@taspelund
Copy link
Contributor

Updates some of the map data structures we use in mgd/bgp. In particular:

  1. Moves UnnumberedManager trait impls over to using iddqd::BiHashMap for the interface name to scope id mapping. This ensures we only have to maintain a single map (instead of 2 like what was used by UnnumberedManagerMock) and that we get consistent O(1) lookups (instead of the O(n) lookups in the UnnumberedManagerNdp impl).
  2. Moves Router.sessions over to a new SessionMap type which wraps an iddqd::IdOrdMap, which ensures we can't ever insert a SessionRunner into a map behind an invalid PeerId key since it is derived from the SessionRunner being inserted. There was not a known issue with the existing impl, but this provides some more type safety to prevent anything bad from happening in the future.
  3. Removes the peer_to_session (previously known as addr_to_session prior to bgp unnumbered) entirely. This was providing a way to get the config (SessionInfo) and handle for sending FSM events (event_tx) for a given peer, primarily in service of the Dispatcher. Since the config and FSM handle are just extensions of the SessionRunner itself, this could all be queried using the global SessionMap (item 2 above). This consolidates us down to just 1 mapping of Peer to SessionRunner instead of 2 where one provides a subset of the others' functionality.

The unnumbered manager needs bidirectional lookup between scope_id and
interface name. The prod code used a single HashMap with O(n) reverse
scans; the mock maintained two manually synchronized HashMaps. Replace
both with a ScopeMap newtype wrapping iddqd::BiHashMap.
Updates Router.sessions to be a new SessionMap which wraps an IdOrdMap,
allowing us to use the SessionRunner's PeerId as a HashMap key. This
ensures the map keys are borrowed from the values, so it's impossible to
insert a SessionRunner into the map using a key that isn't derived from
itself, i.e. you can't insert a SessionRunner behind the wrong PeerId.
The peer_to_session map was very similar to the SessionMap in its uses.
It mapped a PeerId to a SessionEndpoint, which was just a lightweight
wrapper for a SessionRunner's event_tx (FSM event sender) and config
(SessionInfo) used by the dispatcher during lookups for incoming TCP
connections. Since both event_tx and SessionInfo are info coming from
SessionRunner, this can all be accessed using the existing SessionMap
without needing to maintain two separate maps. This gets rid of the
peer_to_session map in lieu of using the SessionMap.
@taspelund taspelund requested a review from rcgoodfellow March 26, 2026 23:23
@taspelund taspelund self-assigned this Mar 26, 2026
@taspelund
Copy link
Contributor Author

I have this in a4x2 currently and BGP unnumbered peers have all come up, but nexus hasn't fully come online. I don't suspect the issues are related to these changes, but I will resume troubleshooting this tomorrow.

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