9.4 Routing control plane:RIP、OSPF 与 BGP
当驿道扩展到多个自治区域,静态路线表不再够用;各路由节点必须交换信息,又不能轻信所有公告。
Forwarding plane 对每个 packet 查 FIB,control plane 学习/计算 candidate route,选出 active route 放入 RIB/FIB。Routing protocol 不直接“携带每个 data packet 走完路径”,它们分发 reachability 与 path information。
1. 先分清 candidate selection 和 packet lookup
Router 可同时从 connected route、static route、OSPF 和 BGP 学到同一 prefix 的 candidate。Vendor/OS 根据 route source preference/administrative distance、protocol metric 和 policy 选 active route。
Packet lookup 则先按 destination 做 longest-prefix match。这两步不能混为“metric 最小的 route 总是选中”:/24 比 /16 specific,即使两者来自不同 protocol/metric space。Metric 通常只在同 prefix/source selection context 中比较。
Equal-cost multipath(ECMP)可将多个 equal candidate 同时安装到 FIB,并按 flow hash 转发。Per-packet load balancing 可造成 reordering,现代实现常使用 per-flow/consistent hash,但 hash field、resiliency 和 rebalancing 为 implementation policy。
2. Distance vector:neighbor 告诉我它能去哪
Distance-vector router 从 neighbor 收到 destination + distance,加上到 neighbor 的 cost 后更新自己的 view。Bellman–Ford relation 给出核心直觉:
D_x(y) = min_v { cost(x, v) + D_v(y) }Failure 时 old information 可在 neighbor 间循环,形成 count-to-infinity。Split horizon、poison reverse、triggered update 和 hold-down 等 mechanism 用于减轻,但不代表 arbitrary topology 中立即 convergence。
RIPv2 以 hop count 为 metric,16 代表 unreachable,因此只适合小 network。Periodic update 的 default timer 与 multicast behavior 是 RIP implementation/protocol detail,理解核心时更重要的是:它不分发全部 topology,只向 neighbor 告知 distance vector。
3. Link state:大家在同一 area 构建 topology database
OSPF router 建 adjacency,用 link-state advertisements(LSA)描述 local state,将它们可靠 flood 到 area 中。同一 area 的 router 努力得到一致 link-state database(LSDB),再独立运行 shortest-path-first calculation,产生 route。
“每台 OSPF router 知道全世界所有 link”不对。Area 是 flooding/LSDB boundary,ABR 在 area 之间传递 summary/reachability information。Backbone area 0 与 area design 影响 scale、failure domain 和 troubleshooting。
OSPF cost 是 operator/implementation-configured metric,不是实时 latency 自动测量值。Reference bandwidth 未统一调整时,多种 high-speed link 可显示相同 cost。Authentication、passive interface、area type、route summarization 与 default route policy 都是 production design 的一部分。
4. Convergence 不只是“算法跑完”
Link failure 后的 convergence chain 包括:
- Failure detection(physical signal、hello/dead timer、BFD);
- Adjacency/state change;
- LSA/update generation 与 flooding;
- SPF/policy recalculation;
- RIB selection 和 FIB programming;
- Neighbor router 在不同时刻更新时的 transient microloop/blackhole。
因此只计 Dijkstra runtime 不能推断 outage duration。Fast reroute 可预先计算 backup next hop,在 control plane 完全 convergence 前先恢复 forwarding,但需要 loop-free condition 和 capacity planning。
5. BGP 在 Autonomous System 之间传递 policy-rich reachability
BGP speaker 通过 TCP connection exchange NLRI(prefix reachability)和 path attributes。eBGP 用于 AS 之间,iBGP 将 external/internal BGP route 在 AS 内分发,常用 route reflector 降低 full-mesh scale。
Common path attributes:
LOCAL_PREF:AS 内选 outbound path 的 high-level policy,高值常优先;AS_PATH:announcement 经过的 AS sequence/set,用于 loop detection 与 policy;ORIGIN:prefix information 进入 BGP 的 origin type,不是 cryptographic identity;MED:对邻居表达多个 entry point 的 preference,比较 scope/policy 需要明确;NEXT_HOP:转发到该 route 的 next-hop address,必须在 IGP/static route 中可达;- Community/large community:给 route 打 policy tag。
BGP 并非“不是算法,只是外交”。它有明确 finite state machine、message processing、loop prevention 和 best-path procedure,但 local policy 能覆盖单纯 shortest AS path。不同 implementation 的 default tie-breaker 和 operator policy 不完全相同,不应把一份 vendor list 当成全 Internet 固定顺序。
6. Route leak、hijack 与 RPKI origin validation
Route hijack 可是 unauthorized AS 宣告他人 prefix,route leak 则常是将按商业/relationship policy 不应再传的 route 传给了另一方。两者都可使 traffic 绕路、blackhole 或被错误 AS 吸引。
RPKI Route Origin Authorization(ROA)声明哪个 origin AS 可宣告某 prefix 及 maximum length。Route Origin Validation(ROV)将 BGP announcement 标记 valid/invalid/not found,operator 再按 policy 处理。
ROV 验证 origin authorization,不 cryptographically validate 整条 AS_PATH,也不自动阻止所有 route leak。Prefix filtering、max-prefix、IRR/RPKI data、peer policy、monitoring 和 incident coordination 要组合使用。
7. 诊断时从 RIB 走到 FIB
- Prefix 是否在 protocol database/Adj-RIB-In 收到?
- Inbound policy 是否拒绝/修改?
- 候选 route 为什么没成为 active route?
- Next hop 是否 resolvable?
- Active route 是否编程到 FIB/hardware?
- Neighbor resolution/adjacency 是否完成?
- Data-plane counter/packet capture 是否符合 control-plane 认知?
只看“BGP session Established”不证明 target prefix 被接收、选中和安装;只看 route table 也不证明 ASIC/neighbor entry 能真正转发。
8. 验收问题
- 区分 control plane、RIB、FIB 和 forwarding plane。
- Distance vector 为什么会 count to infinity?
- OSPF area 解决什么,为什么 area router 不一定拥有全 AS topology?
- BGP 为什么不能用“AS_PATH 最短就必然胜出”概括?
- ROV 能验证什么,不能验证什么?