BGP path selection–Preferred Value

BGP attributes

Routing attributes are specific descriptions of routes. All BGP routing attributes can be divided into the following four categories. Common BGP attribute types are shown in Table 1:

  • Well-known mandatory: All BGP devices can recognize this type of attribute and must exist in Update messages. If such attributes are missing, the routing information will be incorrect.

  • Well-known discretionary: All BGP devices can recognize this type of attribute, but it is not required to exist in the Update message. That is, even if this type of attribute is missing, the routing information will not be wrong.

  • Optional transitive: The BGP device does not need to recognize such attributes. If the BGP device does not recognize such attributes, it will still receive such attributes and notify them to other peers.

  • Optional non-transitive: The BGP device does not need to recognize such attributes. If the BGP device does not recognize such attributes, the attribute will be ignored and will not be advertised to other peers.

When there are multiple BGP routes to the same target network in a BGP router, the BGP protocol will compare the attributes of these BGP routes to determine the optimal BGP route to the target network, and then use the optimal BGP route to the target network. The route is compared with other protocol routes to the same destination network to determine whether to put the optimal BGP route into the IP routing table. Note that the router ultimately forwards actual packets based on the P routing table. When comparing BGP route attributes, BGP will follow a certain order of comparison until an optimal route is determined. During the comparison process of BGP routing attributes, the first thing to be compared is the preferred value of routing information, also referred to as PrefVal.

The preferred value of routing information. The value range of Preferred Value is 0~65535. The larger the value, the higher the priority. By default, the value of Preferred Value is 0; by modifying the value of Preferred Value, it can be easily realized. Control of path selection. The Preferred Value attribute will not be sent to any BGP neighbors and is only used by the local router to select the best BGP path.

R1 configuration

R1 basic configuration

<Huawei>system-view
[Huawei]sysname R1

[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip address 192.168.21.1 24
[R1-GigabitEthernet0/0/0]q

[R1]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ip address 192.168.14.1 24
[R1-GigabitEthernet0/0/1]q

[R1]interface LoopBack 0
[R1-LoopBack0]ip address 1.1.1.1 32


R1 configure ospf
Configuring ospf is to allow R1 R2 R3 to communicate with each other

R1]ospf 1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 192.168.21.0 0.0.0.255


R1 writes a static route pointing to R4 as the next hop of the LoopBack interface.

[R1]ip route-static 4.4.4.4 32 192.168.14.4


R1 bgp configuration

[R1]bgp 100
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 3.3.3.3 as-number 100
[R1-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[R1-bgp]peer 3.3.3.3 next-hop-local

[R1-bgp]peer 2.2.2.2 as-number 100
[R1-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[R1-bgp]peer 2.2.2.2 next-hop-local

[R1-bgp]peer 4.4.4.4 as-number 200
[R1-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[R1-bgp]peer 4.4.4.4 ebgp-max-hop










R2

R2 basic configuration

<Huawei>system-view
[Huawei]sysname R2

[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 192.168.21.2 24
[R2-GigabitEthernet0/0/0]q

[R2]interface GigabitEthernet 0/0/1
[R2-GigabitEthernet0/0/1]ip address 192.168.23.2 24
[R2-GigabitEthernet0/0/1]q

R2]interface LoopBack 0
[R2-LoopBack0]ip address 2.2.2.2 32
[R2-LoopBack0]q

[R2]interface LoopBack 1
[R2-LoopBack1]ip address 22.22.22.22 32
[R2-LoopBack1]q


R2 ospf configuration
[R2]ospf 1
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 192.168.21.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 192.168.23.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0



[R2]bgp 100
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 1.1.1.1 as-number 100
[R2-bgp]peer 3.3.3.3 as-number 100
\t
[R2-bgp]peer 1.1.1.1 connect-interface LoopBack 0
[R2-bgp]peer 3.3.3.3 connect-interface LoopBack 0

[R2-bgp]network 33.33.33.33 32


traceroute

[R2] tracert -a 22.22.22.22 44.44.44.44

 traceroute to 44.44.44.44(44.44.44.44)
, max hops: 30 ,packet length: 40,press CTRL_C to break

 1 192.168.21.1 20 ms 1 ms 30 ms

 2 192.168.14.4 30 ms 20 ms 30 ms


Modify protocol preference value

[R2]ip ip-prefix 1 index 10 permit 44.44.55.55 32
[R2]route-policy 1 permit node 10
[R2-route-policy]if-match ip-prefix 1
[R2-route-policy]apply preferred-value 100
[R2-route-policy]q
\t
[R2]route-policy-change 1 perm
[R2]route-policy 1 permit node 20
[R2-route-policy]q

[R2]bgp 100
[R2-bgp]peer 3.3.3.3 route-policy 1 import


Result after modification
[R2]display bgp routing-table
*> 22.22.22.22/32 0.0.0.0 0 0 i
 *>i 44.44.44.44/32 1.1.1.1 0 100 0 200i
 * i 3.3.3.3 0 100 0 200i
 *>i 44.44.55.55/32 3.3.3.3 0 100 100 200i
 * i 1.1.1.1 0 100 0 200i

R3

R3 basic configuration

<Huawei>system-view
[Huawei]sysname R3

[R3]interface GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]ip address 192.168.23.3 24
[R3-GigabitEthernet0/0/0]q

[R3]interface GigabitEthernet 0/0/1
[R3-GigabitEthernet0/0/1]ip address 192.168.34.3 24
[R3-GigabitEthernet0/0/1]q
\t
[R3]interface LoopBack 0
[R3-LoopBack0]ip address 3.3.3.3 32


R3 ospf configuration

[R3]ospf 1
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 192.168.23.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 192.168.34.0 0.0.0.255

R3 writes a static route pointing to R4 as the next hop of the LoopBack interface.
[R3]ip route-static 4.4.4.4 32 192.168.34.4


R3 configure BGP

[R3]bgp 100
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 1.1.1.1 as-number 100
[R3-bgp]peer 1.1.1.1 connect-interface LoopBack 0
[R3-bgp]peer 1.1.1.1 next-hop-local

[R3-bgp]peer 2.2.2.2 as-number 100
[R3-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[R3-bgp]peer 2.2.2.2 next-hop-local

[R3-bgp]peer 4.4.4.4 as-number 200
[R3-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[R3-bgp]peer 4.4.4.4 ebgp-max-hop



R4

R4 basic configuration

<Huawei>system-view
[Huawei]sysname R4

[R4]interface GigabitEthernet 0/0/0
[R4-GigabitEthernet0/0/0]ip address 192.168.34.4 24
[R4-GigabitEthernet0/0/0]q

[R4]interface GigabitEthernet 0/0/1
[R4-GigabitEthernet0/0/1]ip address 192.168.14.4 24
[R4-GigabitEthernet0/0/1]q

[R4]interface LoopBack 0
[R4-LoopBack0]ip address 4.4.4.4 32
[R4-LoopBack0]q

[R4]interface LoopBack 1
[R4-LoopBack1]ip address 44.44.44.44 32
[R4-LoopBack1]q

[R4]interface LoopBack 2
[R4-LoopBack2]ip address 44.44.55.55 32

R4 writes a static route pointing to R1 and R3 is the next hop of the LoopBack interface.
[R4]ip route-static 1.1.1.1 32 192.168.14.1
[R4]ip route-static 3.3.3.3 32 192.168.34.3


R4 bgp configuration
[R4]bgp 200
[R4-bgp]router-id 4.4.4.4
[R4-bgp]peer 1.1.1.1 as-number 100
[R4-bgp]peer 1.1.1.1 connect-interface LoopBack 0
[R4-bgp]peer 1.1.1.1 ebgp-max-hop

[R4-bgp]peer 3.3.3.3 as-number 100
[R4-bgp]peer 3.3.3.3 connect-interface LoopBack 0
[R4-bgp]peer 3.3.3.3 ebgp-max-hop

[R4-bgp]network 4.4.4.4 32
[R4-bgp]network 44.44.44.44 32
[R4-bgp]network 44.44.55.55 32