qdisc: netem add support to duplicate packets.

using this option the chosen percent of packets is duplicated before
queuing them
This commit is contained in:
Susant Sahani 2019-10-30 18:58:02 +01:00
parent 673d873a42
commit b9c5aa3c65
5 changed files with 26 additions and 6 deletions

View File

@ -2351,6 +2351,14 @@
</listitem>
</varlistentry>
<varlistentry>
<term><varname>NetworkEmulatorDuplicateRate=</varname></term>
<listitem>
<para>Specifies that the chosen percent of packets is duplicated before queuing them.
Takes a percentage value, suffixed with "%". Defaults to unset.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@ -247,7 +247,8 @@ CAN.TripleSampling, config_parse_tristate,
TrafficControlQueueingDiscipline.Parent, config_parse_tc_qdiscs_parent, 0, 0
TrafficControlQueueingDiscipline.NetworkEmulatorDelaySec, config_parse_tc_network_emulator_delay, 0, 0
TrafficControlQueueingDiscipline.NetworkEmulatorDelayJitterSec, config_parse_tc_network_emulator_delay, 0, 0
TrafficControlQueueingDiscipline.NetworkEmulatorLossRate, config_parse_tc_network_emulator_loss_rate, 0, 0
TrafficControlQueueingDiscipline.NetworkEmulatorLossRate, config_parse_tc_network_emulator_rate, 0, 0
TrafficControlQueueingDiscipline.NetworkEmulatorDuplicateRate, config_parse_tc_network_emulator_rate, 0, 0
TrafficControlQueueingDiscipline.NetworkEmulatorPacketLimit, config_parse_tc_network_emulator_packet_limit, 0, 0
/* backwards compatibility: do not add new entries to this section */
Network.IPv4LL, config_parse_ipv4ll, 0, offsetof(Network, link_local)

View File

@ -50,6 +50,9 @@ int network_emulator_fill_message(Link *link, QDiscs *qdisc, sd_netlink_message
if (qdisc->ne.loss > 0)
opt.loss = qdisc->ne.loss;
if (qdisc->ne.duplicate > 0)
opt.duplicate = qdisc->ne.duplicate;
if (qdisc->ne.delay != USEC_INFINITY) {
r = tc_time_to_tick(qdisc->ne.delay, &opt.latency);
if (r < 0)
@ -124,7 +127,7 @@ int config_parse_tc_network_emulator_delay(
return 0;
}
int config_parse_tc_network_emulator_loss_rate(
int config_parse_tc_network_emulator_rate(
const char *unit,
const char *filename,
unsigned line,
@ -138,6 +141,7 @@ int config_parse_tc_network_emulator_loss_rate(
_cleanup_(qdisc_free_or_set_invalidp) QDiscs *qdisc = NULL;
Network *network = data;
uint32_t rate;
int r;
assert(filename);
@ -156,14 +160,19 @@ int config_parse_tc_network_emulator_loss_rate(
return 0;
}
r = parse_tc_percent(rvalue, &qdisc->ne.loss);
r = parse_tc_percent(rvalue, &rate);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to parse 'NetworkEmularorLossRate=', ignoring assignment: %s",
rvalue);
"Failed to parse '%s=', ignoring assignment: %s",
lvalue, rvalue);
return 0;
}
if (streq(lvalue, "NetworkEmulatorLossRate"))
qdisc->ne.loss = rate;
else if (streq(lvalue, "NetworkEmulatorDuplicateRate"))
qdisc->ne.duplicate = rate;
qdisc = NULL;
return 0;
}

View File

@ -16,11 +16,12 @@ typedef struct NetworkEmulator {
uint32_t limit;
uint32_t loss;
uint32_t duplicate;
} NetworkEmulator;
int network_emulator_new(NetworkEmulator **ret);
int network_emulator_fill_message(Link *link, QDiscs *qdisc, sd_netlink_message *req);
CONFIG_PARSER_PROTOTYPE(config_parse_tc_network_emulator_delay);
CONFIG_PARSER_PROTOTYPE(config_parse_tc_network_emulator_loss_rate);
CONFIG_PARSER_PROTOTYPE(config_parse_tc_network_emulator_rate);
CONFIG_PARSER_PROTOTYPE(config_parse_tc_network_emulator_packet_limit);

View File

@ -268,4 +268,5 @@ Parent=
NetworkEmulatorDelaySec=
NetworkEmulatorDelayJitterSec=
NetworkEmulatorLossRate=
NetworkEmulatorDuplicateRate=
NetworkEmulatorPacketLimit=