X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnsim%2Fnode.c;h=25112abe299232382c7154b88821452de978478d;hb=10c5ff143;hp=69dc9be919b09f3ba74b61a51b2b8f7825e989cd;hpb=9e3252b5cec76dddb9877e593c799ebe15cae0af;p=vpp.git diff --git a/src/plugins/nsim/node.c b/src/plugins/nsim/node.c index 69dc9be919b..25112abe299 100644 --- a/src/plugins/nsim/node.c +++ b/src/plugins/nsim/node.c @@ -25,6 +25,7 @@ typedef struct f64 expires; u32 tx_sw_if_index; int is_drop; + int is_lost; } nsim_trace_t; #ifndef CLIB_MARCH_VARIANT @@ -38,20 +39,22 @@ format_nsim_trace (u8 * s, va_list * args) nsim_trace_t *t = va_arg (*args, nsim_trace_t *); if (t->is_drop) - s = format (s, "NSIM: ring drop"); + s = format (s, "NSIM: dropped, %s", t->is_lost ? + "simulated network loss" : "no space in ring"); else s = format (s, "NSIM: tx time %.6f sw_if_index %d", t->expires, t->tx_sw_if_index); return s; } -#endif /* CLIB_MARCH_VARIANT */ vlib_node_registration_t nsim_node; +#endif /* CLIB_MARCH_VARIANT */ #define foreach_nsim_error \ _(BUFFERED, "Packets buffered") \ -_(DROPPED, "Packets dropped due to lack of space") +_(DROPPED, "Packets dropped due to lack of space") \ +_(LOSS, "Network loss simulation drop packets") typedef enum { @@ -90,6 +93,7 @@ nsim_inline (vlib_main_t * vm, int is_drop0; u32 no_error = node->errors[NSIM_ERROR_BUFFERED]; u32 no_buffer_error = node->errors[NSIM_ERROR_DROPPED]; + u32 loss_error = node->errors[NSIM_ERROR_LOSS]; nsim_wheel_entry_t *ep = 0; ASSERT (wp); @@ -109,6 +113,19 @@ nsim_inline (vlib_main_t * vm, is_drop0 = 0; if (PREDICT_TRUE (wp->cursize < wp->wheel_size)) { + if (PREDICT_FALSE (nsm->drop_fraction != 0.0)) + { + /* Get a random number on the closed interval [0,1] */ + f64 rnd = random_f64 (&nsm->seed); + /* Drop the pkt? */ + if (rnd <= nsm->drop_fraction) + { + b[0]->error = loss_error; + is_drop0 = 1; + goto do_trace; + } + } + ep = wp->entries + wp->tail; wp->tail++; if (wp->tail == wp->wheel_size) @@ -121,12 +138,16 @@ nsim_inline (vlib_main_t * vm, ? nsm->sw_if_index1 : nsm->sw_if_index0; ep->current_length = vlib_buffer_length_in_chain (vm, b[0]); ASSERT (ep->current_length <= WHEEL_ENTRY_DATA_SIZE); - clib_memcpy (ep->data, vlib_buffer_get_current (b[0]), - ep->current_length); + clib_memcpy_fast (ep->data, vlib_buffer_get_current (b[0]), + ep->current_length); } else /* out of wheel space, drop pkt */ - b[0]->error = no_buffer_error; + { + b[0]->error = no_buffer_error; + is_drop0 = 1; + } + do_trace: if (is_trace) { if (b[0]->flags & VLIB_BUFFER_IS_TRACED) @@ -134,8 +155,8 @@ nsim_inline (vlib_main_t * vm, nsim_trace_t *t = vlib_add_trace (vm, node, b[0], sizeof (*t)); t->expires = expires; t->is_drop = is_drop0; - if (is_drop0 == 0) - t->tx_sw_if_index = ep->tx_sw_if_index; + t->is_lost = b[0]->error == loss_error; + t->tx_sw_if_index = (is_drop0 == 0) ? ep->tx_sw_if_index : 0; } }