BGP Always-compare-med & Deterministic-med

There are two BGP configuration commands that can influence the MED-based path selection, the bgp deterministic-med and the bgp always-compare-med commands.Enabling the bgp deterministic-med command ensures the comparison of the MED variable when choosing routes advertised by different peers in the same autonomous system. Enabling the bgp always-compare-med command ensures the comparison of the MED for paths from neighbors in different autonomous systems. The bgp always-compare-med command is useful when multiple service providers or enterprises agree on a uniform policy for setting MED. Thus, for network X, if Internet Service Provider A (ISP A) sets the MED to 10, and ISP B sets the MED to 20, both ISPs agree that ISP A has the better performing path to X.

【命令作用】使用bgp deterministric-med命令后,路由器基于邻居AS和MED分类路径,以保证任何时候都用相同的方法分类路径。这样可以产生确定性的最好路径。?
1>先根据AS分类,比较同一AS内的MED
2>再比较AS之间的属性,如果使用了bgp always-compare-med,则不论到来的时间先后,都是med值最小的优选。如果没有使用bgp always-compare-med,则比较BGP十三条以后的几项。直到得出结果。
即,使用bgp deterministric-med后不看到来的时间,只根据AS分类。
【实验前奏】
默认BGP处理路由条目时的步骤时,会按照时间排序逐次比较。比如entry1,entry2,entry3 (entry1是最新收到的,entry3是最老的条目),路由器将新的放在栈顶,老的放在栈底
entry 1
entry 2
entry 3
先用entry1和entry2比较,选出优胜者,再和entry3比较,依此类推,这样选出最优的路径。
这个运算过程大家可以通过下面的实验结果来分析。
[实验]

【注:R1,R2,R3环回口都是192.168.1.0/24网段,用来模拟到达R7的三条到达同一目的地址的BGP路由,R 1通告出去标记MED值为100,R2通告出去标记MED值为150,在R7的三个接口上分别使用ip os co来手工设定IGP metric值,通过nei命令的先后次序来决定路由条目到达的时间顺序】
我们考察三个路由条目entyrA1,entryA2,entryB来分析问题:

下面通过控制这三条路由到达R7的时间来看不同的结果,下表显示了最终的结果
(注:先理论分析一下下表第一行,A1先到达R7的路由表,然后A2到达,最后B到达,按照时间顺序我们可以按照从新到老排序
entryB: AS(PATH) 3, med 0, igp metric 12, internal, rid 6.6.6.6
entryA2: AS(PATH) 12, med 150, igp metric 11, internal, rid 5.5.5.5
entryA1: AS(PATH) 12, med 100, igp metric 13, internal, rid 4.4.4.4
然后B先和A2比,AS号不一样,不考虑MED;同时IBGP路由,比较IGPmetrcic,A2(metric =11<12)胜出;然后A2和A1比较,同一个AS号,比较MED值,A1MED值小,A1胜出,和实验结果一致,下面几个条目大家可以自己分析一下)

1>对于没有使用bgp deterministric-med,大家可以按照上面的计算方法自己算算结果。 2>使用了bgp deterministric-med命令以后的结果都一样,这是将路由条目分组以后再比较的结果。路由器是将三条路由按照AS 号分成2组,A1,A2一组;B一组,然后从A1,A2中按照MED值选出优胜者A1,再和B组的优胜者比较,B因为到下一跳的IGP度量值小而胜出,不管谁先收到都会是B胜出。 牋牋 ?可见bgp deterministric-med确实可以产生出确定性最好的路由,因为按照AS分组以后,同一个组内的每个条目都会使用MED值比较,从而确定出MED值最优的出来,如果再和bgp always-compare-med这个命令一起使用,就肯定会产生出MED值最小的最优路由了;而没有使用它之前的结果就不定了。这个命令直译也就是bgp确定性的med,可见其还是很有作用的。