From: Ayan Banerjee <[email protected]> Modified the number of writes to service at most 20 interfaces.
Signed-off-by: Ayan Banerjee <[email protected]> Reviewed-by: Dinesh G Dutt <[email protected]> --- ospfd/ospf_packet.c | 54 ++++++++++++++++++++++++++++++----------------------- ospfd/ospf_vty.c | 41 ++++++++++++++++++++++++++++------------ ospfd/ospfd.c | 2 +- ospfd/ospfd.h | 4 ++-- 4 files changed, 63 insertions(+), 38 deletions(-) diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index 1e1e946..eb3600c 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -217,13 +217,6 @@ ospf_fifo_flush (struct ospf_fifo *fifo) fifo->count = 0; } -/* Return the current fifo count */ -static int -ospf_fifo_count (struct ospf_fifo *fifo) -{ - return (fifo->count); -} - /* Free ospf packet fifo. */ void ospf_fifo_free (struct ospf_fifo *fifo) @@ -640,6 +633,7 @@ ospf_write (struct thread *thread) { struct ospf *ospf = THREAD_ARG (thread); struct ospf_interface *oi; + struct ospf_interface *last_serviced_oi = NULL; struct ospf_packet *op; struct sockaddr_in sa_dst; struct ip iph; @@ -667,18 +661,23 @@ ospf_write (struct thread *thread) /* seed ipid static with low order bits of time */ if (ipid == 0) ipid = (time(NULL) & 0xffff); - - /* convenience - max OSPF data per packet, - * and reliability - not more data, than our - * socket can accept - */ - maxdatasize = MIN (oi->ifp->mtu, ospf->maxsndbuflen) - - sizeof (struct ip); #endif /* WANT_OSPF_WRITE_FRAGMENT */ - - while ((pkt_count < ospf->write_multiplier) && ospf_fifo_count(oi->obuf)) - { + + while ((pkt_count < ospf->write_oi_count) && oi && (last_serviced_oi != oi)) + { + /* If there is only packet in the queue, the oi is removed from + write-q, so fix up the last interface that was serviced */ + if (last_serviced_oi == NULL) { + last_serviced_oi = oi; + } pkt_count++; + /* convenience - max OSPF data per packet, + * and reliability - not more data, than our + * socket can accept + */ + maxdatasize = MIN (oi->ifp->mtu, ospf->maxsndbuflen) - + sizeof (struct ip); + /* Get one packet from queue. */ op = ospf_fifo_head (oi->obuf); assert (op); @@ -804,15 +803,24 @@ ospf_write (struct thread *thread) /* Now delete packet from queue. */ ospf_packet_delete (oi); - } - /* Move this interface to the tail of write_q to + /* Move this interface to the tail of write_q to serve everyone in a round robin fashion */ - listnode_move_to_tail (ospf->oi_write_q, node); - if (ospf_fifo_head (oi->obuf) == NULL) - { - oi->on_write_q = 0; list_delete_node (ospf->oi_write_q, node); + if (ospf_fifo_head (oi->obuf) == NULL) + { + oi->on_write_q = 0; + list_delete_node (ospf->oi_write_q, node); + } + + /* Setup to service from the head of the queue again */ + if (!list_isempty (ospf->oi_write_q)) + { + node = listhead (ospf->oi_write_q); + assert (node); + oi = listgetdata (node); + assert (oi); + } } /* If packets still remain in queue, call write thread. */ diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 922577e..d9038c8 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -2657,35 +2657,50 @@ DEFUN (no_ospf_auto_cost_reference_bandwidth, DEFUN (ospf_write_multiplier, ospf_write_multiplier_cmd, - "write-multiplier <1-50>", - "Number of writes per thread callback\n") + "ospf write-multiplier <1-100>", + "OSPF specific commands\n" + "Write multiplier\n" + "Maximum number of interface serviced per write\n") { struct ospf *ospf = vty->index; - u_int32_t write_multiplier; + u_int32_t write_oi_count; - write_multiplier = strtol (argv[0], NULL, 10); - if (write_multiplier < 1 || write_multiplier > 50) + write_oi_count = strtol (argv[0], NULL, 10); + if (write_oi_count < 1 || write_oi_count > 100) { vty_out (vty, "write-multiplier value is invalid%s", VTY_NEWLINE); return CMD_WARNING; } - ospf->write_multiplier = write_multiplier; + ospf->write_oi_count = write_oi_count; return CMD_SUCCESS; } +ALIAS (ospf_write_multiplier, + write_multiplier_cmd, + "write-multiplier <1-100>", + "Write multiplier\n" + "Maximum number of interface serviced per write\n") + DEFUN (no_ospf_write_multiplier, no_ospf_write_multiplier_cmd, - "no write-multiplier", + "no ospf write-multiplier", NO_STR - "Number of writes per thread callback\n") + "OSPF specific commands\n" + "Write multiplier\n") { struct ospf *ospf = vty->index; - ospf->write_multiplier = OSPF_WRITE_MULTIPLIER_DEFAULT; + ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; return CMD_SUCCESS; } +ALIAS (no_ospf_write_multiplier, + no_write_multiplier_cmd, + "no write-multiplier", + NO_STR + "Write multiplier\n") + const char *ospf_abr_type_descr_str[] = { "Unknown", @@ -2915,7 +2930,7 @@ DEFUN (show_ip_ospf, /* Show write multiplier values */ vty_out (vty, " Write Multiplier set to %d %s", - ospf->write_multiplier, VTY_NEWLINE); + ospf->write_oi_count, VTY_NEWLINE); /* Show refresh parameters. */ vty_out (vty, " Refresh timer %d secs%s", @@ -7547,9 +7562,9 @@ ospf_config_write (struct vty *vty) ospf->spf_max_holdtime, VTY_NEWLINE); /* Write multiplier print. */ - if (ospf->write_multiplier != OSPF_WRITE_MULTIPLIER_DEFAULT) + if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) vty_out (vty, " ospf write-multiplier %d%s", - ospf->write_multiplier, VTY_NEWLINE); + ospf->write_oi_count, VTY_NEWLINE); /* Max-metric router-lsa print */ config_write_stub_router (vty, ospf); @@ -8047,6 +8062,8 @@ ospf_vty_init (void) /* write multiplier commands */ install_element (OSPF_NODE, &ospf_write_multiplier_cmd); install_element (OSPF_NODE, &no_ospf_write_multiplier_cmd); + install_element (OSPF_NODE, &write_multiplier_cmd); + install_element (OSPF_NODE, &no_write_multiplier_cmd); /* Init interface related vty commands. */ ospf_vty_if_init (); diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index b271d89..5e97588 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -245,7 +245,7 @@ ospf_new (void) } new->t_read = thread_add_read (master, ospf_read, new, new->fd); new->oi_write_q = list_new (); - new->write_multiplier = OSPF_WRITE_MULTIPLIER_DEFAULT; + new->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; return new; } diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index 2ce3018..cca225c 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -220,8 +220,8 @@ struct ospf struct thread *t_deferred_shutdown; /* deferred/stub-router shutdown timer*/ struct thread *t_write; -#define OSPF_WRITE_MULTIPLIER_DEFAULT 3 - int write_multiplier; /* Num of packets sent per thread invocation */ +#define OSPF_WRITE_INTERFACE_COUNT_DEFAULT 20 + int write_oi_count; /* Num of packets sent per thread invocation */ struct thread *t_read; int fd; unsigned int maxsndbuflen; -- 1.9.1 _______________________________________________ Quagga-dev mailing list [email protected] https://lists.quagga.net/mailman/listinfo/quagga-dev
