- /* Be aware: this is not the usual coding pattern */
- vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
-
- while (n_left_to_next > 0 && ep->tx_time <= now)
- {
- /* Out of local buffer cache? */
- if (PREDICT_FALSE (_vec_len (my_buffer_cache) == 0))
- {
- u32 n =
- vlib_buffer_alloc (vm, my_buffer_cache, VLIB_FRAME_SIZE);
- _vec_len (my_buffer_cache) = n;
-
- /* Ugh, drop the rest of the expired entries */
- if (n == 0)
- {
- u32 drops = 0;
- while (ep->tx_time <= now && wp->cursize)
- {
- wp->head++;
- if (wp->head == wp->wheel_size)
- wp->head = 0;
- ep = wp->entries + wp->head;
- wp->cursize--;
- drops++;
- }
- /* Count the drops */
- vlib_node_increment_counter (vm, node->node_index,
- NSIM_TX_ERROR_DROPPED, drops);
- /* Ship any pkts we already processed */
- vlib_put_next_frame (vm, node, next_index, n_left_to_next);
- return n_rx_packets + drops;
- }
- }
-
- /* Allocate a buffer */
- bi0 = my_buffer_cache[_vec_len (my_buffer_cache) - 1];
- _vec_len (my_buffer_cache) -= 1;
-
- to_next[0] = bi0;
- to_next += 1;
- n_left_to_next -= 1;
-
- b0 = vlib_get_buffer (vm, bi0);
- /* Initialize the buffer */
- vlib_buffer_init_for_free_list (b0, fl);
-
- b0->current_data = 0;
- b0->current_length = ep->current_length;
-
- /* Copy data from the ring */
- clib_memcpy (b0->data, ep->data, ep->current_length);
- b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
- vnet_buffer (b0)->sw_if_index[VLIB_TX] = ep->tx_sw_if_index;
- vnet_buffer (b0)->sw_if_index[VLIB_RX] =
- (ep->tx_sw_if_index == nsm->sw_if_index0) ? nsm->sw_if_index1 :
- nsm->sw_if_index0;
- next0 = (ep->tx_sw_if_index == nsm->sw_if_index0) ?
- nsm->output_next_index0 : nsm->output_next_index1;
-
- /* verify speculative enqueue, maybe switch current next frame */
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, next0);
- /* Advance to the next ring entry */
- wp->head++;
- if (wp->head == wp->wheel_size)
- wp->head = 0;
- wp->cursize--;
- ep = wp->entries + wp->head;
- n_rx_packets++;
-
- /* Out of ring entries? */
- if (PREDICT_FALSE (wp->cursize == 0))
- break;
- }
-
- vlib_put_next_frame (vm, node, next_index, n_left_to_next);
-
- /* If the current entry hasn't expired, we're done */
- if (ep->tx_time > now)
- break;