◐ Off-By-One · answer catalog

bgp-route-reflector-rib-in

1 answer(s)gogo1.26

bgp-route-reflector-rib-in

📦 Source in repository (JSON)

Answer

The implementation provides a BGP route reflector with the following data structures and algorithms:

Data Structures

Adj-RIB-In — per-peer incoming route storage:

type AdjRIBIn struct {
    PeerID string
    Routes []Route
}

Loc-RIB — best routes after the selection process:

type LocRIB struct {
    BestRoutes map[string]Route  // keyed by NLRI prefix
}

Route — carries all BGP path attributes needed for selection and reflection: - Nlri — prefix - NextHop — next-hop IP address - LocalPref — local preference (step 1 tiebreaker) - ASPath — AS sequence for loop detection and path length comparison - Origin — IGP(0) < EGP(1) < INCOMPLETE(2) - MED — multi-exit discriminator (step 4, only when same neighboring AS) - PeerID + OriginatorID — for route-reflector loop prevention

Route Selection (7-step decision process)

1. Highest LOCAL_PREF
2. Shortest AS_PATH
3. Lowest ORIGIN (IGP < EGP < INCOMPLETE)
4. Lowest MED (only if same neighboring AS)
5. eBGP over iBGP
6. Lowest IGP metric to NEXT_HOP (reachability)
7. Lowest Router ID

Routes with AS-path loops (own AS in path) or unreachable next-hops (<ip-address>, empty, ::) are excluded before selection via RunRouteSelection().

Export Policy

The shouldExportToClient function implements RFC 4456 rules: - Routes from clients → reflected to all clients and non-clients - Routes from non-clients → reflected to clients only (never to other non-clients) - Routes are never reflected back to their originator (via OriginatorID check) - Originator ID loop detection prevents reflection back to the originating RR


Evidence & signatures

All 26 tests pass covering every edge case:

| Category | Tests | What's verified |
|---|---|---|
| **AS-path loop detection** | 3 | Own AS found in path → loop; own AS not in path → no loop; empty AS-path → no loop |
| **Originator loop detection** | 2 | Originator equals reflector → loop; different originator → no loop |
| **Next-hop reachability** | 3 | Valid IP → reachable; empty IP → unreachable; `<ip-address>` → unreachable |
| **Route selection steps** | 6 | Higher LOCAL_PREF; shorter AS_PATH; lower ORIGIN; lower MED (same AS); MED ignored (different AS); lower Router ID; equal routes |
| **Selection integration** | 3 | Basic multi-peer selection; looped route excluded; unreachable next-hop excluded |
| **Export policies** | 5 | Client→client; client→non-client; non-client→client; non-client↛non-client; not back to originator |
| **Full integration** | 1 | End-to-end with 3 peers, 2 prefixes, route selection, and export |
| **MED tiebreaking** | 1 | MED chosen when same neighboring AS |
| **Multiple prefixes** | 1 | 3 distinct prefixes all in Loc-RIB |
| **Benchmarks** | 2 | Route selection: ~17µs (100 routes); Export: ~379ns (1000 pre-inserted routes) |

**Edge cases explicitly tested:**
- Empty AS-path loop detection
- IPv4 `<ip-address>` as unreachable next-hop
- Empty string as unreachable next-hop
- MED ignored across different neighboring ASes
- Client receiving its own route back (blocked by originator check)
- Non-client to non-client route leaking (blocked by export policy)
- Multiple prefixes with different winners

---
{"model": "gpt-4o", "problem_class": "bgp-route-reflector-rib-in", "result": "passed", "tests": 26}
Generated from the verified corpus · MIT licensedBack to the catalog