Load-Balancing Traffic Flows

Problem

You want the JUNOS software to choose the path on a per-packet basis when there are multiple equal-cost paths to a destination.

Solution

Create a routing policy that load-balances traffic on a per-flow basis:

	[edit policy-options]
	aviva@router1# set policy-statement balance-traffic from route-filter 192.168.10.0/24
	orlonger
	aviva@router1# set policy-statement balance-traffic then load-balance per-packet

Then apply the policy to the forwarding table:

	[edit routing-options]
	aviva@router1# set forwarding-table export balance-traffic

 

Discussion

The routing protocols populate the routing table with the routes they know about and learn from their neighbors. For each prefix, or destination, RPD chooses one active route and installs its next hop into the forwarding table. If a route points to an indirect next hop, RPD downloads all the next hops of the indirect next hop, and the PFE selects a single next hop to use.

When there are multiple paths to a single destination, the routing protocols install the next hops for each path into the routing table. The protocols do have some degree of freedom when populating the routing table. A protocol can opt to install multiple routes, each with the same next hop, a single route with multiple next hops, or even multiple routes with multiple next hops. BGP, for example, can use any of these variations depending on how many peers advertise a prefix, how those peers can be reached, and whether BGP multipath is enabled.

When an active route has multiple equal-cost paths, the default behavior is for RPD to use a hash algorithm to choose a single gateway and install it into the forwarding table. If multiple prefixes have a common set of next hops, this gateway selection process should result in uniform distribution of prefixes across the next hops. For example, if prefixes A, B, C, and D all have gateways 1 and 2, RPD may install A and D with gateway 1 and B and C with gateway 2, so half the prefixes go through one link and half through the other.

To instead have RPD install all the next hops for a prefix into the forwarding table, you turn on load balancing for that prefix. Load balancing distributes the traffic to the prefix across all the paths, evening out the traffic flow across different interfaces and circuits.

Configuring load balancing is a two-step process. First, create a routing policy to define which packets to load-balance. In this recipe, the from clause matches the prefix 192.168.10.0/24 and any longer prefixes. The then clause has the load-balance per-packet action to turn on load balancing:

	[edit policy-options]
	aviva@router1# set policy-statement load-balance then load-balance per-packet

Even though the JUNOS CLI uses per-packet, the term is misnamed. This command is actually enabling per-flow load balancing.

The second step is to apply the policy to routes exported from the routing table to the forwarding engine. In the [edit routing-options] hierarchy, use a set export command:

	[edit routing-options]
	aviva@router1# set forwarding-table export balance- 
traffic

The result of this policy is that all equal-cost paths to destinations are installed in the forwarding table and traffic to these destinations is load-balanced on a per-flow basis. The exact balancing behavior depends on the ASICs in your router. For older routers with the Internet Processor I ASIC, load balancing uses a round-robin method across up to eight next hops. On newer routers with the Internet Processor II ASIC, packets for each individual flow are kept on a single interface and can be spread across up to 16 next hops.

A flow is defined as packets whose headers have the same source and destination addresses and the same protocol. Use the following commands to check for more information in the packet headers:

	[edit forwarding-options]
	aviva@router1# set hash-key family inet layer-3
	aviva@router1# set hash-key family inet layer-4

With these two commands, the source and destination port numbers, source interface index, and type of service are also checked to determine whether packets are in the same flow. When you have more detailed knowledge of your network's traffic patterns and the network types, these two commands allow you to load-balance traffic flows more precisely.

See Also

Recipes 9.1 and 13.14






JUNOS Cookbook
Junos Cookbook (Cookbooks (OReilly))
ISBN: 0596100140
EAN: 2147483647
Year: 2007
Pages: 290
Authors: Aviva Garrett
Simiral book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net