3

Can one set a link's cost to zero in OSPF?

This could be desirable to force load-balancing in certain cases.

For example, suppose there are four routers A, B, C, and D, and two hosts X and Y, with the following connections:

    /----A-----10Mbps-----C----\
   /     |                |     \
X-1Gbps 1Gbps           1Gbps  1Gbps--Y
   \     |                |     /
    \----B-----10Mbps-----D----/

X and Y are workstations, so they are only configured with static routing. Say A is X's default gateway and C is Y's default gateway. Between the four routers, OSPF is used.

Now X initiates two flows to Y, each of which needs 9Mbps. With OSPF, we get the A-C link selected as the best path and the B-C link goes unused. I would like to administratively set the A-B and C-D links as zero cost so that OSPF will load-balance across the two lower-speed 10Mbps links.

2
  • 3
    Why not increase the OSPF cost of A's egress interface to C so your paths have equal costs to achieve ECMP?
    – one.time
    May 25 '15 at 20:11
  • There is no need for a zero cost, just a cost that is lower over a more prefferred link.
    – jwbensley
    May 28 '15 at 11:00
5

Can one set a link's cost to zero in OSPF?

Yes and no... you can't manually set a link's cost to 0, but if you have a Designated Router election on the network, the cost from the DR to any attached router on the same Broadcast / NBMA network is considered 0.

As such, be sure that the A-B and C-D links are OSPF broadcast networks; this forces a DR election and will make the cost of A-B and C-D zero. The DR is sometimes referred to as a pseudonode in OSPF.

Once you make the A-B and C-D links zero cost in OSPF (by virtue of a DR election), A-C and B-D links should be set to the same cost if you want equal-cost load-balancing.

This could be desirable to force load-balancing in certain cases.

If you want a generalized solution to this problem (without dependencies the topology or type of OSPF network involved), you are making one of the classic cases for MPLS TE; OSPF supports MPLS TE (see RFC 3630).

Let's assume:

  • You are running Cisco IOS
  • You only need load-balancing in a single OSPF area
  • You are not trying to deal with NIC-level failovers on the hosts (which can still be managed with MPLS TE, but I'm not illustrating here for brevity)
  • My configuration below has no errors (caveat emptor: I did not lab test my config below, and it's been close to a decade since I seriously needed MPLS TE); however, even if I have to fix an error in the config, the concept of solving your problem with equal-cost load-balancing through MPLS TE tunnels is correct.

Topology

Assume all IP addresses in the diagram are taken from 10.1.x.x...

          1.1/30   1.2/30
          g1/1     g1/1
         A-------------C
     g1/2|             |g1/2
 2.253/24|             |3.253/24
         |             |
         |             |
 2.252/24|             |3.253/24
     g1/2|             |g1/2
         B-------------D
          g1/1     g1/1
          1.5/30   1.6/30

MPLS TE Tunnels

Build the following tunnels so we can use ECMP to meet your requirements. Each tunnel interface will have the same OSPF cost.

  • Tunnels from head-end Router A
  • Tunnel0: Path A -> C
  • Tunnel1: Path A -> B -> D -> C
  • Tunnels from head-end Router C
  • Tunnel0: Path C -> A
  • Tunnel1: Path C -> D -> B -> A

Loopbacks

  • A:Lo0 10.0.0.1/32
  • B:Lo0 10.0.0.2/32
  • C:Lo0 10.0.0.3/32
  • D:Lo0 10.0.0.4/32

Router A's configuration (you can derive all others from this example)

Reference links:

!
mpls traffic-eng tunnels
!
interface Loopback0
 ip address 10.0.0.1 255.255.255.255
!
interface Tunnel0
 ip unnumbered Loopback0
 tunnel destination 10.0.0.3
 tunnel mode mpls traffic-eng
 tunnel mpls traffic-eng autoroute announce
 tunnel mpls traffic-eng bandwidth 10000
 tunnel mpls traffic-eng path-option 1 explicit name A_C
 !!! NOTE: Keep the tunnel up if path-option 1 fails
 tunnel mpls traffic-eng path-option 2 dynamic
!
interface Tunnel1
 ip unnumbered Loopback0
 tunnel destination 10.0.0.3
 tunnel mode mpls traffic-eng
 tunnel mpls traffic-eng autoroute announce
 tunnel mpls traffic-eng bandwidth 10000
 tunnel mpls traffic-eng path-option 1 explicit name A_B_D_C
 !!! NOTE: Keep the tunnel up if path-option 1 fails
 tunnel mpls traffic-eng path-option 2 dynamic
!
interface GigabitEthernet1/1
 description [A -> C]
 mtu 1524
 mpls mtu 1524
 ip mtu 1500
 ip address 10.1.1.1 255.255.255.252
 ip rsvp bandwidth 10000 10000
 mpls traffic-eng tunnels
!
interface GigabitEthernet 1/2
 description [A -> B]
 mtu 1524
 switchport
 switchport mode access
 switchport access vlan 10
!
interface Vlan10
 mtu 1524
 mpls mtu 1524
 ip mtu 1500
 ip address 10.1.2.253 255.255.255.0
 standby 10 ip 10.1.2.254
 standby 10 priority 105
 standby 10 timers msec 200 750
 ip rsvp bandwidth 1000000 1000000
 mpls traffic-eng tunnels
!
router ospf 10
 router-id 10.0.0.1
 log-adjacency-changes
 network 10.0.0.0 0.255.255.255 area 0
 mpls traffic-eng router-id Loopback0
 mpls traffic-eng area 0
!
ip explicit-path name A_C enable
 next-address 10.1.1.2
! 
ip explicit-path name A_B_D_C enable
 next-address 10.1.2.252
 next-address 10.1.1.6
 next-address 10.1.3.253
!
3

The formula for calculating an OSPF cost is (10^8) / Bandwidth ,especially on CISCO routers. So there is no way of dividing by zero you get infinity.
However you can manually set a cost on a particular interface by entering a cost between 1 - 65535:

Router(config-if)#ip ospf cost ?
<1-65535> Cost


Let me know if this was useful
EDIT If I'm not wrong since the route supplied by a router with a higher router-id is chosen, you can make use of the priority command and make them the same on each link to force equal load balancing:

Router(config)#int fa0/0
Router(config-if)#ip ospf pr
Router(config-if)#ip ospf priority ?
<0-255> Priority

2
  • Apparently in both Cisco and Quagga the cost can only go as low a 1. Please see my updated question for one might want a cost of zero. May 25 '15 at 12:10
  • edited the answer hope it helps @ChrisMerck
    – Manny265
    May 25 '15 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.