Example for Configuring BGP Load Balancing and the MED Attribute
Networking Requirements
As shown in Figure 9-26, BGP is configured on all switches; SwitchA resides in AS 65008; SwitchB and SwitchC reside in AS 65009. EBGP connections are established between SwitchA and SwitchB, and between SwitchA and SwitchC. An IBGP connection is established between SwitchB and SwitchC. Load balancing needs to be implemented between AS 65008 and AS 65009. After a period, traffic from AS 65008 to AS 65009 needs to first pass through SwitchC.
Configuration Roadmap
The configuration roadmap is as follows:
- Configure load balancing on SwitchA.
- Set the MED value on SwitchA to enable traffic from AS 65008 to AS 65009 to first pass through SwitchC.
Procedure
- Configure the VLAN to which each interface belongs.
<HUAWEI> system-view [~HUAWEI] sysname SwitchA [*HUAWEI] commit [~SwitchA] vlan batch 10 20 [*SwitchA] interface 10ge 1/0/1 [*SwitchA-10GE1/0/1] port link-type trunk [*SwitchA-10GE1/0/1] port trunk allow-pass vlan 10 [*SwitchA-10GE1/0/1] quit [*SwitchA] interface 10ge 1/0/2 [*SwitchA-10GE1/0/2] port link-type trunk [*SwitchA-10GE1/0/2] port trunk allow-pass vlan 20 [*SwitchA-10GE1/0/2] quit [*SwitchA] commit
The configurations of SwitchB and SwitchC are similar to the configuration of SwitchA, and are not mentioned here.
- Configure VLANIF interfaces and assign IP addresses to the VLANIF interfaces.
[~SwitchA] interface vlanif 10 [*SwitchA-Vlanif10] ip address 192.168.1.2 24 [*SwitchA-Vlanif10] quit [*SwitchA] interface vlanif 20 [*SwitchA-Vlanif20] ip address 192.168.2.2 24 [*SwitchA-Vlanif20] quit [*SwitchA] commit
The configurations of SwitchB and SwitchC are similar to the configuration of SwitchA, and are not mentioned here.
- Configure BGP connections.
# Configure SwitchA.
[~SwitchA] bgp 65008 [*SwitchA-bgp] router-id 172.16.1.1 [*SwitchA-bgp] peer 192.168.1.1 as-number 65009 [*SwitchA-bgp] peer 192.168.2.1 as-number 65009 [*SwitchA-bgp] quit [*SwitchA] commit
# Configure SwitchB.
[~SwitchB] bgp 65009 [*SwitchB-bgp] router-id 172.16.2.2 [*SwitchB-bgp] peer 192.168.1.2 as-number 65008 [*SwitchB-bgp] peer 10.1.1.2 as-number 65009 [*SwitchB-bgp] ipv4-family unicast [*SwitchB-bgp-af-ipv4] network 10.1.1.0 255.255.255.0 [*SwitchB-bgp-af-ipv4] quit [*SwitchB-bgp] quit [*SwitchB] commit
# Configure SwitchC.
[~SwitchC] bgp 65009 [*SwitchC-bgp] router-id 172.16.3.3 [*SwitchC-bgp] peer 192.168.2.2 as-number 65008 [*SwitchC-bgp] peer 10.1.1.1 as-number 65009 [*SwitchC-bgp] ipv4-family unicast [*SwitchC-bgp-af-ipv4] network 10.1.1.0 255.255.255.0 [*SwitchC-bgp-af-ipv4] quit [*SwitchC-bgp] quit [*SwitchC] commit
# View the BGP routing table of SwitchA.
[~SwitchA] display bgp routing-table BGP Local router ID is 172.16.1.1 Status codes: * - valid, > - best, d - damped,h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/24 192.168.1.1 0 0 65009i * 192.168.2.1 0 0 65009i
[~SwitchA] display ip routing-table Proto: Protocol Pre: Preference Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Table : _public_ Destinations : 12 Routes : 12 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.1.0/24 EBGP 255 0 RD 192.168.1.1 Vlanif10 10.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 192.168.1.0/24 Direct 0 0 D 192.168.1.2 Vlanif10 192.168.1.2/32 Direct 0 0 D 127.0.0.1 Vlanif10 192.168.1.255/32 Direct 0 0 D 127.0.0.1 Vlanif10 192.168.2.0/24 Direct 0 0 D 192.168.2.2 Vlanif20 192.168.2.2/32 Direct 0 0 D 127.0.0.1 Vlanif20 192.168.2.255/32 Direct 0 0 D 127.0.0.1 Vlanif20 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
In the BGP routing table, there are two valid routes to destination 10.1.1.0/24. The route with next-hop address 192.168.1.1 is the optimal route because the router ID of SwitchB is the smallest.
- Configure load balancing.
# Configure SwitchA.
[~SwitchA] bgp 65008 [~SwitchA-bgp] ipv4-family unicast [~SwitchA-bgp-af-ipv4] maximum load-balancing 2 [*SwitchA-bgp-af-ipv4] quit [*SwitchA-bgp] quit [*SwitchA] commit
# View the BGP routing table of SwitchA.
[~SwitchA] display bgp routing-table BGP Local router ID is 172.16.1.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/24 192.168.1.1 0 0 65009i *> 192.168.2.1 0 0 65009i
[~SwitchA] display ip routing-table Proto: Protocol Pre: Preference Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Table : _public_ Destinations : 12 Routes : 13 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.1.0/24 EBGP 255 0 RD 192.168.1.1 Vlanif10 EBGP 255 0 RD 192.168.2.1 Vlanif20 10.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 192.168.1.0/24 Direct 0 0 D 192.168.1.2 Vlanif10 192.168.1.2/32 Direct 0 0 D 127.0.0.1 Vlanif10 192.168.1.255/32 Direct 0 0 D 127.0.0.1 Vlanif10 192.168.2.0/24 Direct 0 0 D 192.168.2.2 Vlanif20 192.168.2.2/32 Direct 0 0 D 127.0.0.1 Vlanif20 192.168.2.255/32 Direct 0 0 D 127.0.0.1 Vlanif20 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
In the BGP routing table, BGP route 10.1.1.0/24 has two next hops: 192.168.1.1 and 192.168.2.1. Both of them are optimal routes.
- Configure the MED attribute.
# Set the MED value for the route sent from SwitchB to SwitchA using a route-policy.
[~SwitchB] route-policy 10 permit node 10 [*SwitchB-route-policy] apply cost 100 [*SwitchB-route-policy] quit [*SwitchB] bgp 65009 [*SwitchB-bgp] peer 192.168.1.2 route-policy 10 export [*SwitchB-bgp] quit [*SwitchB] commit
# View the BGP routing table of SwitchA.
[~SwitchA] display bgp routing-table BGP Local router ID is 172.16.1.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/24 192.168.2.1 0 0 65009i * 192.168.1.1 100 0 65009i
[~SwitchA] display ip routing-table Proto: Protocol Pre: Preference Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Table : _public_ Destinations : 26 Routes : 26 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.1.0/24 EBGP 255 0 RD 192.168.2.1 Vlanif20 10.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 192.168.1.0/24 Direct 0 0 D 192.168.1.2 Vlanif10 192.168.1.2/32 Direct 0 0 D 127.0.0.1 Vlanif10 192.168.1.255/32 Direct 0 0 D 127.0.0.1 Vlanif10 192.168.2.0/24 Direct 0 0 D 192.168.2.2 Vlanif20 192.168.2.2/32 Direct 0 0 D 127.0.0.1 Vlanif20 192.168.2.255/32 Direct 0 0 D 127.0.0.1 Vlanif20 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
In the BGP routing table, the MED value of the route with next hop 192.168.1.1 (SwitchB) is 100, and the MED value of the route with next hop 192.168.2.1 is 0. Therefore, the route with the smaller MED value is preferred.
Configuration Files
Configuration file of SwitchA
# sysname SwitchA # vlan batch 10 20 # interface Vlanif10 ip address 192.168.1.2 255.255.255.0 # interface Vlanif20 ip address 192.168.2.2 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 10 # interface 10GE1/0/2 port link-type trunk port trunk allow-pass vlan 20 # bgp 65008 router-id 172.16.1.1 peer 192.168.1.1 as-number 65009 peer 192.168.2.1 as-number 65009 # ipv4-family unicast maximum load-balancing 2 peer 192.168.1.1 enable peer 192.168.2.1 enable # return
Configuration file of SwitchB
# sysname SwitchB # vlan batch 10 30 # interface Vlanif10 ip address 192.168.1.1 255.255.255.0 # interface Vlanif30 ip address 10.1.1.1 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 10 # interface 10GE1/0/2 port link-type trunk port trunk allow-pass vlan 30 # bgp 65009 router-id 172.16.2.2 peer 10.1.1.2 as-number 65009 peer 192.168.1.2 as-number 65008 # ipv4-family unicast default med 100 network 10.1.1.0 255.255.255.0 peer 10.1.1.2 enable peer 192.168.1.2 enable peer 192.168.1.2 route-policy 10 export # route-policy 10 permit node 10 apply cost 100 # return
Configuration file of SwitchC
# sysname SwitchC # vlan batch 20 30 # interface Vlanif20 ip address 192.168.2.1 255.255.255.0 # interface Vlanif30 ip address 10.1.1.2 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 20 # interface 10GE1/0/2 port link-type trunk port trunk allow-pass vlan 30 # bgp 65009 router-id 172.16.3.3 peer 10.1.1.1 as-number 65009 peer 192.168.2.2 as-number 65008 # ipv4-family unicast network 10.1.1.0 255.255.255.0 peer 10.1.1.1 enable peer 192.168.2.2 enable # return