OSPF Reference Bandwidth Calculator

From Internetworkpro

Jump to: navigation, search

Contents

[edit] Intro

In today's networks 10G+ is becoming more and more prevalent. OSPF port costs are automatically determined with a formula of <reference bandwith>/<interface bandwidth>. The default reference bandwidth for IOS and JunOS is 100. This means that 100mbit, 1gbit, 10gbit, or higher all gets the same OSPF cost of 1 which is less than optimal and may cause some inappropriate routing decisions.

This is a very quick and dirty script to help me visualize the effects of chaning the reference bandwidth. It is written in python and should run in just about any version of python.

Please let me know if you want more features or any change. Maybe i will work on it some more

nemith 15:15, 18 June 2007 (CDT)

[edit] Usage

Either chmod 755 the script or run as an argument of your python binary.

The script takes one argument, the reference bandwith

[edit] Examples

Costs for the default reference bandwidth of 100

trogdor% python refbw.py 100

Calculating the OSPF cost values for reference bandwidth: 100

Cost at 100Gbps:          1      (less than min)  hops @ 24-bit   16777215   hops @ 32-bit 4294967295
Cost at 40Gbps:           1      (less than min)  hops @ 24-bit   16777215   hops @ 32-bit 4294967295
Cost at 10Gbps:           1      (less than min)  hops @ 24-bit   16777215   hops @ 32-bit 4294967295
Cost at 1Gps:             1      (less than min)  hops @ 24-bit   16777215   hops @ 32-bit 4294967295
Cost at 100Mbps:          1                       hops @ 24-bit   16777215   hops @ 32-bit 4294967295
Cost at 10Mbps:          10                       hops @ 24-bit    1677721   hops @ 32-bit  429496729
Cost at 6.176Mbps:       16                       hops @ 24-bit    1036160   hops @ 32-bit  265257180
Cost at 4.632Mbps:       21                       hops @ 24-bit     777120   hops @ 32-bit  198942885
Cost at 3.088Mbps:       32                       hops @ 24-bit     518080   hops @ 32-bit  132628590
Cost at 1.544Mps:        64                       hops @ 24-bit     259040   hops @ 32-bit   66314295
Cost at 768kbps:        133                       hops @ 24-bit     125829   hops @ 32-bit   32212254
Cost at 384kbps:        266                       hops @ 24-bit      62914   hops @ 32-bit   16106127
Cost at 128kbps:        800                       hops @ 24-bit      20971   hops @ 32-bit    5368709

[edit] Code

import sys
 
def calc_cost(refbw, bw):
  cost = refbw/bw
  tag = ""
 
  if cost < 1:
    cost = 1
    tag = "(less than min)"
 
  if cost > 65535:
    cost = 65535
    tag = "(greater than max)"
 
  hops_24 = 16777215/cost
  hops_32 = 4294967295/cost
 
  return "%5i %20s  hops @ 24-bit %10d   hops @ 32-bit %10d" % (cost, tag, hops_24, hops_32)
 
if len(sys.argv) == 1:
    print 'No reference bandwidth specified!'
    sys.exit()
 
try: 
  ref_bw = int(sys.argv[1])
except:
  print "Reference bandwith must be an interger!"
  sys.exit()
 
print ""
print "Calculating the OSPF cost values for reference bandwidth: %i" % ref_bw
print ""
print "Cost at 100Gbps:      %s" % calc_cost(ref_bw, 100000)
print "Cost at 40Gbps:       %s" % calc_cost(ref_bw, 40000)
print "Cost at 10Gbps:       %s" % calc_cost(ref_bw, 10000)
print "Cost at 1Gps:         %s" % calc_cost(ref_bw, 1000)
print "Cost at 100Mbps:      %s" % calc_cost(ref_bw, 100)
print "Cost at 10Mbps:       %s" % calc_cost(ref_bw, 10)
print "Cost at 6.176Mbps:    %s" % calc_cost(ref_bw, 6.176)
print "Cost at 4.632Mbps:    %s" % calc_cost(ref_bw, 4.632)
print "Cost at 3.088Mbps:    %s" % calc_cost(ref_bw, 3.088)
print "Cost at 1.544Mps:     %s" % calc_cost(ref_bw, 1.544)
print "Cost at 768kbps:      %s" % calc_cost(ref_bw, 0.75)
print "Cost at 384kbps:      %s" % calc_cost(ref_bw, 0.375)
print "Cost at 128kbps:      %s" % calc_cost(ref_bw, 0.125)

[edit] See Also

Cisco-NSP thread about max OSPF metric

Personal tools
Namespaces
Variants
Actions
Navigation
Categories
Toolbox