BGP path selection-Next_Hop and MED experiment examples

1. Understanding attributes:

  • 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.

  • Next_Hop attribute (recognized as required)

    The Next_Hop attribute records the next hop information of the route. The next hop attribute of BGP is different from that of IGP and is not necessarily the IP address of the neighbor device. Normally, the Next_Hop attribute follows the following rules:

    • When the BGP Speaker advertises a route to an EBGP peer, it will set the next hop attribute of the route information to the address of the interface that establishes a BGP neighbor relationship between the local and the peer.

    • When the BGP Speaker advertises a locally originated route to an IBGP peer, it will set the next hop attribute of the routing information to the address of the interface that establishes a BGP neighbor relationship between the local and the peer.

    • When the BGP Speaker advertises the route learned from the EBGP peer to the IBGP peer, it does not change the next hop attribute of the routing information.

  • MED attribute (optional non-transition)

    The MED (Multi-Exit Discriminator) attribute is used to determine the preferred route when traffic enters the AS. When a device running BGP obtains multiple routes with the same destination address but different next hops through different EBGP peers, under other conditions In the same situation, the route with the smaller MED value will be selected as the preferred route.

    The MED attribute is only passed between two adjacent ASs. The AS that receives this attribute will not advertise it to any other third-party AS. The MED attribute can be configured manually. If the route is not configured with the MED attribute, the MED value of the route will be processed as the default value 0 when BGP route selection is made.

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 decide whether to put the optimal BGP route into the IP routing table. Note that the router ultimately forwards the actual packet 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. In the comparison process of BGP route validity, 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.

2. Experiment:

2.1Next_Hop experimental topology diagram 1:

2.2 Configure bgp:

##r1BGP configuration##
bgp 100
 router-id 10.0.100.1
 peer 10.0.12.2 as-number 100
 peer 10.0.13.3 as-number 100
 #
 ipv4-familyunicast
  undo synchronization
  network 10.0.100.1 255.255.255.255
  peer 10.0.12.2 enable
  peer 10.0.13.3 enable
##r2BGP configuration##
bgp 200
 router-id 10.0.2.2
 peer 10.0.3.3 as-number 200
 peer 10.0.3.3 connect-interface LoopBack0
 peer 10.0.4.4 as-number 200
 peer 10.0.4.4 connect-interface LoopBack0
 peer 10.0.12.1 as-number 100
 #
 ipv4-familyunicast
  undo synchronization
  network 10.0.2.2 255.255.255.255
  peer 10.0.3.3 enable
  peer 10.0.3.3 next-hop-local
  peer 10.0.4.4 enable
  peer 10.0.12.1 enable
##r3BGP configuration##
bgp 200
 router-id 10.0.3.3
 peer 10.0.2.2 as-number 200
 peer 10.0.2.2 connect-interface LoopBack0
 peer 10.0.4.4 as-number 200
 peer 10.0.4.4 connect-interface LoopBack0
 peer 10.0.13.1 as-number 100
 #
 ipv4-familyunicast
  undo synchronization
  network 10.0.3.3 255.255.255.255
  peer 10.0.2.2 enable
  peer 10.0.2.2 next-hop-local
  peer 10.0.4.4 enable
  peer 10.0.13.1 enable
##r4BGP configuration##
bgp 200
 router-id 10.0.4.4
 peer 10.0.2.2 as-number 200
 peer 10.0.2.2 connect-interface LoopBack0
 peer 10.0.3.3 as-number 200
 peer 10.0.3.3 connect-interface LoopBack0
 #
 ipv4-familyunicast
  undo synchronization
  network 10.0.4.4 255.255.255.255
  network 10.0.100.4 255.255.255.255
  peer 10.0.2.2 enable
  peer 10.0.3.3 enable

2.3 View the BGP routing table:

We can specify the route by changing the next hop

2.4 Change the value of Cost:

[R4-GigabitEthernet0/0/0]ospf cost 88

2.5 Results:

3. MED experiment:

3.1 Experimental topology diagram:

3.2 Configure BGP:

##r1BGP configuration##
bgp 100
 router-id 10.0.1.1
 peer 10.0.12.2 as-number 200
 peer 10.0.13.3 as-number 200
 peer 10.0.14.4 as-number 300
 #
 ipv4-familyunicast
  undo synchronization
  network 10.0.1.1 255.255.255.255
  network 172.16.1.0 255.255.255.0
  network 172.16.2.0 255.255.255.0
  network 192.168.1.0
  peer 10.0.12.2 enable
  peer 10.0.13.3 enable
  peer 10.0.14.4 enable
##r2BGP configuration##
bgp 200
 router-id 10.0.2.2
 peer 10.0.12.1 as-number 100
 peer 10.0.23.3 as-number 200
 peer 10.0.25.5 as-number 400
 #
 ipv4-familyunicast
  undo synchronization
  network 10.0.2.2 255.255.255.255
  peer 10.0.12.1 enable
  peer 10.0.23.3 enable
  peer 10.0.23.3 next-hop-local
  peer 10.0.25.5 enable
##r3BGP configuration##
bgp 200
 router-id 10.0.3.3
 peer 10.0.13.1 as-number 100
 peer 10.0.23.2 as-number 200
 peer 10.0.35.5 as-number 400
 #
 ipv4-familyunicast
  undo synchronization
  network 10.0.3.3 255.255.255.255
  peer 10.0.13.1 enable
  peer 10.0.23.2 enable
  peer 10.0.23.2 next-hop-local
  peer 10.0.35.5 enable
#
##r4BGP configuration##
bgp 300
 router-id 10.0.4.4
 peer 10.0.14.1 as-number 100
 peer 10.0.45.5 as-number 400
 #
 ipv4-familyunicast
  undo synchronization
  network 10.0.4.4 255.255.255.255
  peer 10.0.14.1 enable
  peer 10.0.45.5 enable
##r5BGP configuration##
bgp 400
 router-id 10.0.5.5
 peer 10.0.25.2 as-number 200
 peer 10.0.35.3 as-number 200
 peer 10.0.45.4 as-number 300
 #
 ipv4-familyunicast
  undo synchronization
  network 10.0.5.5 255.255.255.255
  peer 10.0.25.2 enable
  peer 10.0.35.3 enable
  peer 10.0.45.4 enable

3.3 View BGP routing:

We can change the next hop by changing the MED value

Router No. 2’s route to 172.16.1.0 is the optimal one. Let’s try to see if we can change it through the MED value.

3.4 Configure prefix list:

##Prefix list number 1##
#
route-policy 1 permit node 10
 if-match ip-prefix 1
 apply cost 100
#
route-policy 1 permit node 20
 if-match ip-prefix 2
 apply cost 200
#
route-policy 1 permit node 30

##Prefix list number 2##
#
route-policy 2 permit node 10
 if-match ip-prefix 2
 apply cost 100
#
route-policy 2 permit node 20
 if-match ip-prefix 1
 apply cost 200
#
route-policy 2 permit node 30 

After configuring the prefix list, configure the application and BGP:

 peer 10.0.12.2 route-policy 1 export
  peer 10.0.13.3 route-policy 2 export

3.5 Results: