Originally published at https://blog.pathvector.dev/protocol-in-code-bgp-04/ — part of the free Protocol Lab series.
This post is part of Protocol in Code, a free series that reads network protocols as logic — inputs, state, and branches — rather than as configuration examples. The full source, walkthroughs, and site lessons live in the repo: pathvector-studio/protocol-in-code. If you're newer to this and want to build the protocols hands-on before dissecting them, start with the companion Protocol Lab series instead.
Today we're on the BGP track, session 04, reading a single small file: src/protocol_in_code/bgp/validation.py. It's about 40 lines. The idea inside it is one that trips up a lot of engineers who've been running BGP for years.
The question to keep in your head
BGP's best path selection already ran. It compared local preference, AS_PATH length, MED, and the rest of the tiebreak ladder, and it picked a winner. So here's the question this module wants you turning over:






