Browse Source

ospf6d: add "auto-cost reference-bandwidth" command

This command allows the user to change to default reference bandwidth
for cost calculations. The default value is 100 Mbps. With a default
bandwidth of 10 MBps, the default cost becomes 10. Those values are
consistent with OSPFv2.

[DL: resolved conflicts in vty command additions & docs]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Vincent Bernat 6 years ago
parent
commit
fd5006896f
6 changed files with 94 additions and 3 deletions
  1. 14 1
      doc/ospf6d.texi
  2. 9 0
      ospf6d/README
  3. 60 1
      ospf6d/ospf6_interface.c
  4. 3 1
      ospf6d/ospf6_snmp.c
  5. 6 0
      ospf6d/ospf6_top.c
  6. 2 0
      ospf6d/ospf6_top.h

+ 14 - 1
doc/ospf6d.texi

@@ -66,6 +66,18 @@ within the hold-time of the previous SPF calculation.
 
 @end deffn
 
+@deffn {OSPF6 Command} {auto-cost reference-bandwidth @var{cost}} {}
+@deffnx {OSPF6 Command} {no auto-cost reference-bandwidth} {}
+This sets the reference bandwidth for cost calculations, where this
+bandwidth is considered equivalent to an OSPF cost of 1, specified in
+Mbits/s. The default is 100Mbit/s (i.e. a link of bandwidth 100Mbit/s
+or higher will have a cost of 1. Cost of lower bandwidth links will be
+scaled with reference to this cost).
+
+This configuration setting MUST be consistent across all routers
+within the OSPF domain.
+@end deffn
+
 @node OSPF6 area
 @section OSPF6 area
 
@@ -75,7 +87,8 @@ Area support for OSPFv3 is not yet implemented.
 @section OSPF6 interface
 
 @deffn {Interface Command} {ipv6 ospf6 cost COST} {}
-Sets interface's output cost.  Default value depends on the interface bandwidth.
+Sets interface's output cost.  Default value depends on the interface
+bandwidth and on the auto-cost reference bandwidth.
 @end deffn
 
 @deffn {Interface Command} {ipv6 ospf6 hello-interval HELLOINTERVAL} {}

+ 9 - 0
ospf6d/README

@@ -85,6 +85,15 @@ OSPF6 NODE:
     Binds interface to specified Area, and start
     sending OSPFv3 packets.
 
+  auto-cost reference-bandwidth COST
+    Sets the reference bandwidth for cost calculations, where this
+    bandwidth is considered equivalent to an OSPF cost of 1, specified
+    in Mbits/s. The default is 100Mbit/s (i.e. a link of bandwidth
+    100Mbit/s or higher will have a cost of 1. Cost of lower bandwidth
+    links will be scaled with reference to this cost).  This
+    configuration setting MUST be consistent across all routers within
+    the OSPF domain.
+
 Sample configuration is in ospf6d.conf.sample.
 
 --

+ 60 - 1
ospf6d/ospf6_interface.c

@@ -125,7 +125,7 @@ ospf6_interface_get_cost (struct ospf6_interface *oi)
   u_int32_t bw, refbw;
 
   bw = oi->interface->bandwidth ? oi->interface->bandwidth : OSPF6_INTERFACE_BANDWIDTH;
-  refbw = OSPF6_REFERENCE_BANDWIDTH;
+  refbw = ospf6 ? ospf6->ref_bandwidth : OSPF6_REFERENCE_BANDWIDTH;
 
   /* A specifed ip ospf cost overrides a calculated one. */
   if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_NOAUTOCOST))
@@ -1300,6 +1300,61 @@ DEFUN (no_ipv6_ospf6_cost,
   return CMD_SUCCESS;
 }
 
+DEFUN (auto_cost_reference_bandwidth,
+       auto_cost_reference_bandwidth_cmd,
+       "auto-cost reference-bandwidth <1-4294967>",
+       "Calculate OSPF interface cost according to bandwidth\n"
+       "Use reference bandwidth method to assign OSPF cost\n"
+       "The reference bandwidth in terms of Mbits per second\n")
+{
+  struct ospf6 *o = vty->index;
+  struct ospf6_area *oa;
+  struct ospf6_interface *oi;
+  struct listnode *i, *j;
+  u_int32_t refbw;
+
+  refbw = strtol (argv[0], NULL, 10);
+  if (refbw < 1 || refbw > 4294967)
+    {
+      vty_out (vty, "reference-bandwidth value is invalid%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
+  /* If reference bandwidth is changed. */
+  if ((refbw * 1000) == o->ref_bandwidth)
+    return CMD_SUCCESS;
+
+  o->ref_bandwidth = refbw * 1000;
+  for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa))
+      for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
+          ospf6_interface_recalculate_cost (oi);
+
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_auto_cost_reference_bandwidth,
+       no_auto_cost_reference_bandwidth_cmd,
+       "no auto-cost reference-bandwidth",
+       NO_STR
+       "Calculate OSPF interface cost according to bandwidth\n"
+       "Use reference bandwidth method to assign OSPF cost\n")
+{
+  struct ospf6 *o = vty->index;
+  struct ospf6_area *oa;
+  struct ospf6_interface *oi;
+  struct listnode *i, *j;
+
+  if (o->ref_bandwidth == OSPF6_REFERENCE_BANDWIDTH)
+    return CMD_SUCCESS;
+
+  o->ref_bandwidth = OSPF6_REFERENCE_BANDWIDTH;
+  for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa))
+      for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
+          ospf6_interface_recalculate_cost (oi);
+
+  return CMD_SUCCESS;
+}
+
 DEFUN (ipv6_ospf6_hellointerval,
        ipv6_ospf6_hellointerval_cmd,
        "ipv6 ospf6 hello-interval <1-65535>",
@@ -1854,6 +1909,10 @@ ospf6_interface_init (void)
 
   install_element (INTERFACE_NODE, &ipv6_ospf6_network_cmd);
   install_element (INTERFACE_NODE, &no_ipv6_ospf6_network_cmd);
+
+  /* reference bandwidth commands */
+  install_element (OSPF6_NODE, &auto_cost_reference_bandwidth_cmd);
+  install_element (OSPF6_NODE, &no_auto_cost_reference_bandwidth_cmd);
 }
 
 DEFUN (debug_ospf6_interface,

+ 3 - 1
ospf6d/ospf6_snmp.c

@@ -488,7 +488,9 @@ ospfv3GeneralGroup (struct variable *v, oid *name, size_t *length,
     case OSPFv3DEMANDEXTENSIONS:
       return SNMP_INTEGER (0);	/* Not supported */
     case OSPFv3REFERENCEBANDWIDTH:
-      return SNMP_INTEGER (100000);
+      if (ospf6)
+        return SNMP_INTEGER (ospf6->ref_bandwidth);
+      /* Otherwise, like for "not implemented". */
     case OSPFv3RESTARTSUPPORT:
     case OSPFv3RESTARTINTERVAL:
     case OSPFv3RESTARTSTRICTLSACHECKING:

+ 6 - 0
ospf6d/ospf6_top.c

@@ -148,6 +148,8 @@ ospf6_create (void)
 
   o->external_id_table = route_table_init ();
 
+  o->ref_bandwidth = OSPF6_REFERENCE_BANDWIDTH;
+
   return o;
 }
 
@@ -890,6 +892,10 @@ config_write_ospf6 (struct vty *vty)
       vty_out(vty, "%s", VTY_NEWLINE);
     }
 
+  if (ospf6->ref_bandwidth != OSPF6_REFERENCE_BANDWIDTH)
+    vty_out (vty, " auto-cost reference-bandwidth %d%s", ospf6->ref_bandwidth / 1000,
+             VNL);
+
   ospf6_stub_router_config_write (vty);
   ospf6_redistribute_config_write (vty);
   ospf6_area_config_write (vty);

+ 2 - 0
ospf6d/ospf6_top.h

@@ -80,6 +80,8 @@ struct ospf6
   struct thread *t_spf_calc;	        /* SPF calculation timer. */
   struct thread *t_ase_calc;		/* ASE calculation timer. */
   struct thread *maxage_remover;
+
+  u_int32_t ref_bandwidth;
 };
 
 #define OSPF6_DISABLED    0x01