From patchwork Mon Aug 6 17:09:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousuk Seung X-Patchwork-Id: 954006 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="kIPoR0c4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41kkfp6pdmz9ryt for ; Tue, 7 Aug 2018 03:10:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732636AbeHFTUK (ORCPT ); Mon, 6 Aug 2018 15:20:10 -0400 Received: from mail-ua0-f202.google.com ([209.85.217.202]:43275 "EHLO mail-ua0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728349AbeHFTUK (ORCPT ); Mon, 6 Aug 2018 15:20:10 -0400 Received: by mail-ua0-f202.google.com with SMTP id k5-v6so9269674ual.10 for ; Mon, 06 Aug 2018 10:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ljAQgwRw5Vo3uIJuaUvqF9tL3y4yEO0DCpIHR7sc9pE=; b=kIPoR0c47hAyRwEXZAPAvfdc5QViJLHht1xwu/REHGqzaCEoRQMLQTZx1P9g560frx 3yaBweUpuJ/6mZNyWQjKHgF2jOlVMHGwvZ4rmxbnsvg+Pn/Q0cjqvxmuvM7dT1L/hXrb Dn3wESPsNl8BTCXsQWkTx3+vr7Q85f6Hdb6o+5rjibM1HUAnEMo9B0WwYB0qevtL27lf GJB47Al+EsV5XoIJNCQYqJQ3/U9+z3rqn6A2eNfcHncqBwKEuF1ti4ID4StOqxZmZ81R JG0xSBq0Z4aa2NU1u04hcNOUBIlP2YR90WvEarqEsqWGDDi0eGLGp8Fs/VWqdkGv2dhK hq/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ljAQgwRw5Vo3uIJuaUvqF9tL3y4yEO0DCpIHR7sc9pE=; b=YvjeLAHV/6lFXxfMG9G6LRNouu+cvtNVMXjg/bWYlL+vGCGMeinl/2y+NVNZK7o1Rj Hj1cLb7ba6B8EDAZeYXppL8XqypGJVi1hY4xLf0lfwcN/wYT8nyKfJku7eHThWug2YXv NwNm3mMqA2JVk6OMD9euArNLxCvUYqOFYd5YcFzxurMIFeGxtuDxA8sNK1s8rwApzDxp OPZbEK9oEAdf21URV4yOhi3Yln4veHCNBfy2R/OjGdbS4GuRMoE/N9/GyuxM9VmoC59b KNEjRUyYQP/W6zd274akbjqDZoRX/+cKcmGzHyLEga6TLux7NTeEi+BDIXTY5hWCs3yV YBFw== X-Gm-Message-State: AOUpUlHfF9cUm5NVdi2NL/uDVAbYpUIE2SULSRck0TZyVoPVNndOVrnK xpYV1Vhise/654AyBxK6f3zFNawkeYcwjM5auCGq3R1Ei2BO+k0FgkvLZAnbOEA2pMYq5BdoQ59 /I8292szsH6HtmG4QG7uWb7+SOcucX6B276Ye7SZtq3rVtIJxeCqfbORnGi/ChMDz X-Google-Smtp-Source: AAOMgpf+qQBr3UiNFwH7ep8bcnSTpPsuH0MAkFDCevQZHxBD69c1fMOJptgLYOVPkp8/utVkP5213+DQJgYX X-Received: by 2002:a1f:bd07:: with SMTP id n7-v6mr10232622vkf.11.1533575408885; Mon, 06 Aug 2018 10:10:08 -0700 (PDT) Date: Mon, 6 Aug 2018 10:09:53 -0700 In-Reply-To: <20180806170953.164776-1-ysseung@google.com> Message-Id: <20180806170953.164776-4-ysseung@google.com> Mime-Version: 1.0 References: <20180806170953.164776-1-ysseung@google.com> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog Subject: [PATCH iproute2-next 3/3] q_netem: slotting with non-uniform distribution From: Yousuk Seung To: netdev@vger.kernel.org Cc: Stephen Hemminger , David Ahern , Michael McLennan , Priyaranjan Jha , Yousuk Seung , Neal Cardwell , Dave Taht Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Extend slotting with support for non-uniform distributions. This is similar to netem's non-uniform distribution delay feature. Syntax: slot distribution DISTRIBUTION DELAY JITTER [packets MAX_PACKETS] \ [bytes MAX_BYTES] The syntax and use of the distribution table is the same as in the non-uniform distribution delay feature. A file DISTRIBUTION must be present in TC_LIB_DIR (e.g. /usr/lib/tc) containing numbers scaled by NETEM_DIST_SCALE. A random value x is selected from the table and it takes DELAY + ( x * JITTER ) as delay. Correlation between values is not supported. Examples: Normal distribution delay with mean = 800us and stdev = 100us. > tc qdisc add dev eth0 root netem slot distribution normal \ 800us 100us Optionally set the max slot size in bytes and/or packets. > tc qdisc add dev eth0 root netem slot distribution normal \ 800us 100us bytes 64k packets 42 Signed-off-by: Yousuk Seung Signed-off-by: Neal Cardwell Signed-off-by: Dave Taht --- man/man8/tc-netem.8 | 20 ++++++++---- tc/q_netem.c | 75 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 76 insertions(+), 19 deletions(-) diff --git a/man/man8/tc-netem.8 b/man/man8/tc-netem.8 index 8d485b026751..111109cf042f 100644 --- a/man/man8/tc-netem.8 +++ b/man/man8/tc-netem.8 @@ -53,9 +53,13 @@ NetEm \- Network Emulator .IR RATE " [ " PACKETOVERHEAD " [ " CELLSIZE " [ " CELLOVERHEAD " ]]]]" .IR SLOT " := " -.BR slot -.IR MIN_DELAY " [ " MAX_DELAY " ] [" -.BR packets +.BR slot " { " +.IR MIN_DELAY " [ " MAX_DELAY " ] |" +.br +.RB " " distribution " { "uniform " | " normal " | " pareto " | " paretonormal " | " +.IR FILE " } " DELAY " " JITTER " } " +.br +.RB " [ " packets .IR PACKETS " ] [ " .BR bytes .IR BYTES " ]" @@ -172,9 +176,13 @@ an artificial packet compression (bursts). Another influence factor are network adapter buffers which can also add artificial delay. .SS slot -defer delivering accumulated packets to within a slot, with each available slot -configured with a minimum delay to acquire, and an optional maximum delay. Slot -delays can be specified in nanoseconds, microseconds, milliseconds or seconds +defer delivering accumulated packets to within a slot. Each available slot can be +configured with a minimum delay to acquire, and an optional maximum delay. +Alternatively it can be configured with the distribution similar to +.BR distribution +for +.BR delay +option. Slot delays can be specified in nanoseconds, microseconds, milliseconds or seconds (e.g. 800us). Values for the optional parameters .I BYTES will limit the number of bytes delivered per slot, and/or diff --git a/tc/q_netem.c b/tc/q_netem.c index f52a36b6c31c..e655e1a82e12 100644 --- a/tc/q_netem.c +++ b/tc/q_netem.c @@ -43,7 +43,9 @@ static void explain(void) " [ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]\n" \ " [ slot MIN_DELAY [MAX_DELAY] [packets MAX_PACKETS]" \ " [bytes MAX_BYTES]]\n" \ - ); +" [ slot distribution" \ +" {uniform|normal|pareto|paretonormal|custom} DELAY JITTER" \ +" [packets MAX_PACKETS] [bytes MAX_BYTES]]\n"); } static void explain1(const char *arg) @@ -159,6 +161,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev) { int dist_size = 0; + int slot_dist_size = 0; struct rtattr *tail; struct tc_netem_qopt opt = { .limit = 1000 }; struct tc_netem_corr cor = {}; @@ -169,6 +172,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct tc_netem_rate rate = {}; struct tc_netem_slot slot = {}; __s16 *dist_data = NULL; + __s16 *slot_dist_data = NULL; __u16 loss_type = NETEM_LOSS_UNSPEC; int present[__TCA_NETEM_MAX] = {}; __u64 rate64 = 0; @@ -417,21 +421,53 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, } } } else if (matches(*argv, "slot") == 0) { - NEXT_ARG(); - present[TCA_NETEM_SLOT] = 1; - if (get_time64(&slot.min_delay, *argv)) { - explain1("slot min_delay"); - return -1; - } if (NEXT_IS_NUMBER()) { NEXT_ARG(); - if (get_time64(&slot.max_delay, *argv)) { - explain1("slot min_delay max_delay"); + present[TCA_NETEM_SLOT] = 1; + if (get_time64(&slot.min_delay, *argv)) { + explain1("slot min_delay"); + return -1; + } + if (NEXT_IS_NUMBER()) { + NEXT_ARG(); + if (get_time64(&slot.max_delay, *argv)) { + explain1("slot min_delay max_delay"); + return -1; + } + } + if (slot.max_delay < slot.min_delay) + slot.max_delay = slot.min_delay; + } else { + NEXT_ARG(); + if (strcmp(*argv, "distribution") == 0) { + present[TCA_NETEM_SLOT] = 1; + NEXT_ARG(); + slot_dist_data = calloc(sizeof(slot_dist_data[0]), MAX_DIST); + slot_dist_size = get_distribution(*argv, slot_dist_data, MAX_DIST); + if (slot_dist_size <= 0) { + free(slot_dist_data); + return -1; + } + NEXT_ARG(); + if (get_time64(&slot.dist_delay, *argv)) { + explain1("slot delay"); + return -1; + } + NEXT_ARG(); + if (get_time64(&slot.dist_jitter, *argv)) { + explain1("slot jitter"); + return -1; + } + if (slot.dist_jitter <= 0) { + fprintf(stderr, "Non-positive jitter\n"); + return -1; + } + } else { + fprintf(stderr, "Unknown slot parameter: %s\n", + *argv); return -1; } } - if (slot.max_delay < slot.min_delay) - slot.max_delay = slot.min_delay; if (NEXT_ARG_OK() && matches(*(argv+1), "packets") == 0) { NEXT_ARG(); @@ -558,6 +594,14 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, return -1; free(dist_data); } + + if (slot_dist_data) { + if (addattr_l(n, MAX_DIST * sizeof(slot_dist_data[0]), + TCA_NETEM_SLOT_DIST, + slot_dist_data, slot_dist_size * sizeof(slot_dist_data[0])) < 0) + return -1; + free(slot_dist_data); + } tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; return 0; } @@ -712,8 +756,13 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) } if (slot) { - fprintf(f, " slot %s", sprint_time64(slot->min_delay, b1)); - fprintf(f, " %s", sprint_time64(slot->max_delay, b1)); + if (slot->dist_jitter > 0) { + fprintf(f, " slot distribution %s", sprint_time64(slot->dist_delay, b1)); + fprintf(f, " %s", sprint_time64(slot->dist_jitter, b1)); + } else { + fprintf(f, " slot %s", sprint_time64(slot->min_delay, b1)); + fprintf(f, " %s", sprint_time64(slot->max_delay, b1)); + } if(slot->max_packets) fprintf(f, " packets %d", slot->max_packets); if(slot->max_bytes)