summaryrefslogtreecommitdiffstats
path: root/src/plugins/nsim/nsim.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2018-12-06 10:20:14 -0500
committerFlorin Coras <florin.coras@gmail.com>2018-12-06 18:28:47 +0000
commit10c5ff143a86d15e78cb1f8625eb0ab8bf72b6ce (patch)
tree00afabf7ca2ccd4042b2315b38fa6fb1bf5902c2 /src/plugins/nsim/nsim.c
parent995ff06fb73a2d1ac8472977cf3089d763f17d33 (diff)
nsim: add packet loss simulation, docs
Change-Id: Ic9747541aad8148ebf7d520b525b99c4cc3961f3 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/plugins/nsim/nsim.c')
-rw-r--r--src/plugins/nsim/nsim.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/plugins/nsim/nsim.c b/src/plugins/nsim/nsim.c
index ec79070b2e7..ce3396c5845 100644
--- a/src/plugins/nsim/nsim.c
+++ b/src/plugins/nsim/nsim.c
@@ -118,7 +118,8 @@ nsim_enable_disable (nsim_main_t * nsm, u32 sw_if_index0,
}
static int
-nsim_configure (nsim_main_t * nsm, f64 bandwidth, f64 delay, f64 packet_size)
+nsim_configure (nsim_main_t * nsm, f64 bandwidth, f64 delay, f64 packet_size,
+ f64 drop_fraction)
{
u64 total_buffer_size_in_bytes, per_worker_buffer_size;
u64 wheel_slots_per_worker;
@@ -148,6 +149,7 @@ nsim_configure (nsim_main_t * nsm, f64 bandwidth, f64 delay, f64 packet_size)
}
nsm->delay = delay;
+ nsm->drop_fraction = drop_fraction;
/* delay in seconds, bandwidth in bits/sec */
total_buffer_size_in_bytes = (u32) ((delay * bandwidth) / 8.0) + 0.5;
@@ -318,14 +320,21 @@ vl_api_nsim_configure_t_handler (vl_api_nsim_configure_t * mp)
{
vl_api_nsim_configure_reply_t *rmp;
nsim_main_t *nsm = &nsim_main;
- f64 delay, bandwidth, packet_size;
+ f64 delay, bandwidth, packet_size, drop_fraction;
+ u32 packets_per_drop;
int rv;
delay = ((f64) (ntohl (mp->delay_in_usec))) * 1e-6;
bandwidth = (f64) (clib_net_to_host_u64 (mp->bandwidth_in_bits_per_second));
packet_size = (f64) (ntohl (mp->average_packet_size));
- rv = nsim_configure (nsm, bandwidth, delay, packet_size);
+ packets_per_drop = ntohl (mp->packets_per_drop);
+ if (packets_per_drop > 0)
+ drop_fraction = 1.0 / (f64) (packets_per_drop);
+ else
+ drop_fraction = 0.0;
+
+ rv = nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction);
REPLY_MACRO (VL_API_NSIM_CONFIGURE_REPLY);
}
@@ -447,6 +456,8 @@ set_nsim_command_fn (vlib_main_t * vm,
nsim_main_t *nsm = &nsim_main;
f64 delay, bandwidth;
f64 packet_size = 1500.0;
+ f64 drop_fraction = 0.0;
+ u32 packets_per_drop;
u32 num_workers = vlib_num_workers ();
int rv;
@@ -459,11 +470,22 @@ set_nsim_command_fn (vlib_main_t * vm,
;
else if (unformat (input, "packet-size %f", &packet_size))
;
+ else if (unformat (input, "packets-per-drop %d", &packets_per_drop))
+ {
+ if (packets_per_drop > 0)
+ drop_fraction = 1.0 / ((f64) packets_per_drop);
+ }
+ else if (unformat (input, "drop-fraction %f", &drop_fraction))
+ {
+ if (drop_fraction < 0.0 || drop_fraction > 1.0)
+ return clib_error_return
+ (0, "drop fraction must be between zero and 1");
+ }
else
break;
}
- rv = nsim_configure (nsm, bandwidth, delay, packet_size);
+ rv = nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction);
switch (rv)
{
@@ -485,6 +507,10 @@ set_nsim_command_fn (vlib_main_t * vm,
vlib_cli_output (vm, "Configured link delay %.2f ms, %.2f ms round-trip",
nsm->delay * 1e3, 2.0 * nsm->delay * 1e3);
+ if (nsm->drop_fraction > 0.0)
+ vlib_cli_output (vm, "... simulating a network drop fraction of %.5f",
+ nsm->drop_fraction);
+
if (num_workers)
vlib_cli_output (vm, "Sim uses %llu bytes per thread, %llu bytes total",
@@ -548,6 +574,10 @@ show_nsim_command_fn (vlib_main_t * vm,
"...inserting link delay of %.2f ms, %.2f ms round-trip",
nsm->delay * 1e3, 2.0 * nsm->delay * 1e3);
+ if (nsm->drop_fraction > 0.0)
+ vlib_cli_output (vm, "... simulating a network drop fraction of %.5f",
+ nsm->drop_fraction);
+
if (verbose)
{