Example for Configuring Load Balancing Among OSPF Routes
Networking Requirements
As shown in Figure 5-35, the networking requirements are as follows:
- SwitchA, SwitchB, SwitchC, and SwitchD connect to each other through OSPF.
- SwitchA, SwitchB, SwitchC, and SwitchD belong to Area 0.
- Load balancing is configured so that the traffic from SwitchA can be sent to SwitchD through SwitchB or SwitchC.
Configuration Roadmap
The configuration roadmap is as follows:
- Configure basic OSPF functions on each Switchto implement interconnection.
- Disable load balancing on SwitchA and then check the routing table on SwitchA.
- (Optional) Set weights of equal-cost routes on SwitchA.
Procedure
- Configure the VLAN for each interface.
<HUAWEI> system-view [~HUAWEI] sysname SwitchA [*HUAWEI] commit [~SwitchA] vlan batch 10 20 50 [*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] interface 10ge 1/0/3 [*SwitchA-10GE1/0/3] port link-type trunk [*SwitchA-10GE1/0/3] port trunk allow-pass vlan 50 [*SwitchA-10GE1/0/3] quit [*SwitchA] commit
The configurations of SwitchB, SwitchC, and SwitchD are similar to the configuration of SwitchA, and are not provided here.
- Assign an IP address to each VLANIF interface.
[~SwitchA] interface vlanif 10 [*SwitchA-Vlanif10] ip address 10.1.1.1 24 [*SwitchA-Vlanif10] quit [*SwitchA] interface vlanif 20 [*SwitchA-Vlanif20] ip address 10.1.2.1 24 [*SwitchA-Vlanif20] quit [*SwitchA] interface vlanif 50 [*SwitchA-Vlanif50] ip address 172.16.1.1 24 [*SwitchA-Vlanif50] quit [*SwitchA] commit
The configurations of SwitchB, SwitchC, and SwitchD are similar to the configuration of SwitchA, and are not provided here.
- Configure basic OSPF functions. For details, see Example for Configuring Basic OSPF Functions.
- Disable load balancing on SwitchA.
[~SwitchA] ospf [*SwitchA-ospf-1] maximum load-balancing 1 [*SwitchA-ospf-1] quit [*SwitchA] commit
# View the routing table of SwitchA.
[~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 : 16 Routes : 16 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.1.0/24 Direct 0 0 D 10.1.1.1 Vlanif10 10.1.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif10 10.1.1.255/32 Direct 0 0 D 127.0.0.1 Vlanif10 10.1.2.0/24 Direct 0 0 D 10.1.2.1 Vlanif20 10.1.2.1/32 Direct 0 0 D 127.0.0.1 Vlanif20 10.1.2.255/32 Direct 0 0 D 127.0.0.1 Vlanif20 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 172.16.1.0/24 Direct 0 0 D 172.16.1.1 Vlanif50 172.16.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif50 172.16.1.255/32 Direct 0 0 D 127.0.0.1 Vlanif50 172.16.2.0/24 OSPF 10 3 D 10.1.1.2 Vlanif10 192.168.0.0/24 OSPF 10 2 D 10.1.1.2 Vlanif10 192.168.1.0/24 OSPF 10 2 D 10.1.2.2 Vlanif20 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
As shown in the routing table, if the maximum number of equal-cost routes for load balancing is set to 1, OSPF selects 10.1.1.2 as the next hop to the destination network 172.16.2.0.
OSPF selects the next hop randomly among equal-cost routes.
- Restore the default number of equal-cost routes for load balancing on SwitchA.
[~SwitchA] ospf [*SwitchA-ospf-1] undo maximum load-balancing [*SwitchA-ospf-1] quit [*SwitchA] commit
# Display the routing table on Switch A.
[~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 : 16 Routes : 17 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.1.0/24 Direct 0 0 D 10.1.1.1 Vlanif10 10.1.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif10 10.1.1.255/32 Direct 0 0 D 127.0.0.1 Vlanif10 10.1.2.0/24 Direct 0 0 D 10.1.2.1 Vlanif20 10.1.2.1/32 Direct 0 0 D 127.0.0.1 Vlanif20 10.1.2.255/32 Direct 0 0 D 127.0.0.1 Vlanif20 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 172.16.1.0/24 Direct 0 0 D 172.16.1.1 Vlanif50 172.16.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif50 172.16.1.255/32 Direct 0 0 D 127.0.0.1 Vlanif50 172.16.2.0/24 OSPF 10 3 D 10.1.1.2 Vlanif10 OSPF 10 3 D 10.1.2.2 Vlanif20 192.168.0.0/24 OSPF 10 2 D 10.1.1.2 Vlanif10 192.168.1.0/24 OSPF 10 2 D 10.1.2.2 Vlanif20 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
As shown in the routing table, when the default settings of load balancing are restored, both next hops of SwitchA, namely, 10.1.1.2 and 10.1.2.2, become valid routes. This is because the default number of equal-cost routes is 64.
- (Optional) Set weights of equal-cost routes on SwitchA.
If you do not want to implement load balancing between SwitchB and SwitchC, set weights for the equal-cost routes to specify the next hop.
[~SwitchA] ospf [~SwitchA-ospf-1] nexthop 10.1.2.2 weight 1 [*SwitchA-ospf-1] quit [*SwitchA] commit
# Display the routing table on SwitchA.
[~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 : 16 Routes : 16 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.1.0/24 Direct 0 0 D 10.1.1.1 Vlanif10 10.1.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif10 10.1.1.255/32 Direct 0 0 D 127.0.0.1 Vlanif10 10.1.2.0/24 Direct 0 0 D 10.1.2.1 Vlanif20 10.1.2.1/32 Direct 0 0 D 127.0.0.1 Vlanif20 10.1.2.255/32 Direct 0 0 D 127.0.0.1 Vlanif20 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 172.16.1.0/24 Direct 0 0 D 172.16.1.1 Vlanif50 172.16.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif50 172.16.1.255/32 Direct 0 0 D 127.0.0.1 Vlanif50 172.16.2.0/24 OSPF 10 3 D 10.1.2.2 Vlanif20 192.168.0.0/24 OSPF 10 2 D 10.1.1.2 Vlanif10 192.168.1.0/24 OSPF 10 2 D 10.1.2.2 Vlanif20 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
As shown in the routing table, after weights are set for the equal-cost routes, the preference of the route with the next hop being 10.1.2.2 (the weight is 1) is higher than that of the route with the next hop being 10.1.1.2. Therefore, OSPF selects the route with the next hop being 10.1.2.2 as the optimal route.
Configuration Files
Configuration file of SwitchA
# sysname SwitchA # vlan batch 10 20 50 # interface Vlanif10 ip address 10.1.1.1 255.255.255.0 # interface Vlanif20 ip address 10.1.2.1 255.255.255.0 # interface Vlanif50 ip address 172.16.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 20 # interface 10GE1/0/3 port link-type trunk port trunk allow-pass vlan 50 # ospf 1 router-id 10.10.10.1 nexthop 10.1.2.2 weight 1 area 0.0.0.0 network 10.1.1.0 0.0.0.255 network 10.1.2.0 0.0.0.255 network 172.16.1.0 0.0.0.255 # return
Configuration file of SwitchB
# sysname SwitchB # vlan batch 20 40 # interface Vlanif20 ip address 10.1.2.2 255.255.255.0 # interface Vlanif40 ip address 192.168.1.1 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 40 # ospf 1 router-id 10.10.10.3 area 0.0.0.0 network 10.1.2.0 0.0.0.255 network 192.168.1.0 0.0.0.255 # return
Configuration file of SwitchC
sysname SwitchC # vlan batch 10 30 # interface Vlanif10 ip address 10.1.1.2 255.255.255.0 # interface Vlanif30 ip address 192.168.0.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 # ospf 1 router-id 10.10.10.2 area 0.0.0.0 network 10.1.1.0 0.0.0.255 network 192.168.0.0 0.0.0.255 # return
Configuration file of SwitchD
# sysname SwitchD # vlan batch 30 40 60 # interface Vlanif30 ip address 192.168.0.2 255.255.255.0 # interface Vlanif40 ip address 192.168.1.2 255.255.255.0 # interface Vlanif60 ip address 172.16.2.1 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 30 # interface 10GE1/0/2 port link-type trunk port trunk allow-pass vlan 40 # interface 10GE1/0/3 port link-type trunk port trunk allow-pass vlan 60 # ospf 1 router-id 10.10.10.4 area 0.0.0.0 network 192.168.0.0 0.0.0.255 network 192.168.1.0 0.0.0.255 network 172.16.2.0 0.0.0.255 # return