From patchwork Mon Aug 27 02:42:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousuk Seung X-Patchwork-Id: 962325 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="WzoOLl0d"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41zGQP1t4Bz9s3Z for ; Mon, 27 Aug 2018 12:42:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727119AbeH0G1Y (ORCPT ); Mon, 27 Aug 2018 02:27:24 -0400 Received: from mail-qk0-f202.google.com ([209.85.220.202]:47988 "EHLO mail-qk0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726968AbeH0G1X (ORCPT ); Mon, 27 Aug 2018 02:27:23 -0400 Received: by mail-qk0-f202.google.com with SMTP id u195-v6so13882471qka.14 for ; Sun, 26 Aug 2018 19:42:47 -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=oyG01FVjadQsmoQ/oYx6xjAGRW3yXEaj7Y9hLckWkkM=; b=WzoOLl0dbhHRDFztAjPNeoaHoxEx/VoMgBMOTlLQQO//z1N6mCzc2FZLK5kpxk7sOt OlNufCvbQwpvrAaeWpL/OeMyhs3E2VNsfxzpBsJrKW+ZGiPsFVHXGeF3kWfFnEB68vD8 wYId8YgVWO7SFodvwTK9uxryrwm2Ev6Q1giwzxmKlSyHzfh9B0MzwaqOYG2kjQhZhv/k BhtOU2ZzebpInzFX1mYOr9GDdBAX7UYplRIRN4XXauayYds4TPJsfy/DQLUlb+qsOQEY ewBh7OwLIJGa6MM7YNgF3CuKruqvUssoUBZrjCt+ycAIUWMw6UChqbNwX43m1zEaBBGe N/GQ== 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=oyG01FVjadQsmoQ/oYx6xjAGRW3yXEaj7Y9hLckWkkM=; b=k1yuVaS9RW4tbPvaz1cuPCwuTlrpb1Y79Cx3alX2G1Wc+l/utItQ0IPWljCMn0JUUA gYM/41nOh4FLzl6bLP86fKwocNS+BOJxeAIRvr+s7eM6+qgFG1YSpXBUdz0dnPS4eGtL vngQxo/47AFzLZLk7qL9Z0KHawwUBBCaa7Andak+1ZA1gNKR/3I39zUlADiSJRx+/Xyz YwjIjL3HXat7A76XWemxNXq8H7s74lZLfC+wTLKmtc0yXI3qv/q3eT5dRMiPPHXNXgDT 9ZBgNsq2bz6A9yLWgRAaMyKl2hgqql40shcCD8Afpkaoik3KgJEDmO+A05nsAzZ1XcrM KttQ== X-Gm-Message-State: APzg51Aj+nXz4vXyjdw7Ayrm5itEkPW38lDvwFICqY0v3D760dFGluC+ OTl7Ey4vuSRwertNmgL9fzaTuEZTsjQZ9QzIo99FE7hMVTLB1syRMlmfD5HfTrLUVRvRphhDZil O7I6nxjMvVOODzaduexUXcuxGKRQgEgUTrsHXxzrcGQXSqVQ2JKnPz2faqFG6vstK X-Google-Smtp-Source: ANB0VdZre5eSp/nDgv14U+C06HduZ03S/0hKT6C4tEhAsZRpbpyIniRPJtNuM0nfNYabCUhQ9owm97+OehZI X-Received: by 2002:a0c:add1:: with SMTP id x17-v6mr6838818qvc.50.1535337767012; Sun, 26 Aug 2018 19:42:47 -0700 (PDT) Date: Sun, 26 Aug 2018 19:42:30 -0700 In-Reply-To: <20180827024230.246445-1-ysseung@google.com> Message-Id: <20180827024230.246445-4-ysseung@google.com> Mime-Version: 1.0 References: <20180827024230.246445-1-ysseung@google.com> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog Subject: [PATCH v2 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 | 77 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 78 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 53a7a1056f5d..5bfdfcd5478c 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,55 @@ 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) || - slot.max_delay < slot.min_delay) { - explain1("slot 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) || + slot.max_delay < slot.min_delay) { + explain1("slot max_delay"); + return -1; + } + } else { + slot.max_delay = slot.min_delay; + } } else { - slot.max_delay = slot.min_delay; + 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); + if (!slot_dist_data) + return -1; + 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 (NEXT_ARG_OK() && matches(*(argv+1), "packets") == 0) { @@ -559,6 +597,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; } @@ -713,8 +759,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)