From patchwork Tue Sep 18 15:27:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 971161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42F6Lq5G7Hz9s9h for ; Wed, 19 Sep 2018 01:27:47 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 6A969E8D; Tue, 18 Sep 2018 15:27:12 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 3D00EE7C for ; Tue, 18 Sep 2018 15:27:10 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 954B979F for ; Tue, 18 Sep 2018 15:27:09 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id n11-v6so3304436wmc.2 for ; Tue, 18 Sep 2018 08:27:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=xZkCw3xzv19nct2yqci+xKauz4RmFugNafrwKLi4aWk=; b=XcBD83bD3Y++9zhXa0Fa8FM0afSaivM8Qsi7OGCIa675FRxbIem2Vkcvwg8q9yblmE 8AhsQO/RlFQXb39MNhbIkTRoC497IG67edJKgpktGCFjswhJcxz7sU4jZAn9VVuAngwK 2nDdxhRManT0YfPiaO6sXcvbA32LgIEvLUuXheQW2AbOWRqMRw1jJ15V8sxhy/dt4Jz7 gXjjMn8q9iGg5bMakhQFKcTyB+RL3Lszgag7htftten3u7jcRBGp2mcHKEnCUJ8qYIRf oH9c5qLmWulaukNbIVFEajgjYlwDw2GtL4+tIAqCmbLtwSDlNaJEDN/Tw76RLFpgxk3+ HdTg== X-Gm-Message-State: APzg51BFPtXvhWIkCelfZdqc2HZpkXj6Q+orqEmPtFmW0XjxzXmeD7Cl q3fIRT8u6Uj9jKvUoUtC94fUX5oWV0Y= X-Google-Smtp-Source: ANB0VdZ4jKiQbTidVCMt0GYgPn8haSWFRR78sbZNl4r9sjKCjxudnDqIbOj80MP7ijFhg0HBmmtqaQ== X-Received: by 2002:a1c:4857:: with SMTP id v84-v6mr15427801wma.8.1537284427788; Tue, 18 Sep 2018 08:27:07 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id y17-v6sm20439923wrm.61.2018.09.18.08.27.06 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 18 Sep 2018 08:27:07 -0700 (PDT) From: Lorenzo Bianconi To: dev@openvswitch.org Date: Tue, 18 Sep 2018 17:27:00 +0200 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] OVN: add CT_LB action to ovn-trace X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Add CT_LB action to ovn-trace utility in order to fix the following ovn-trace error if a load balancer rule is added to OVN configuration ct_next(ct_state=est|trk /* default (use --ct to customize) */) { *** ct_lb action not implemented; }; Add '--lb_dst' option in order to specify the ip address to use in the VIP pool. If --lb_dst is not provided the destination ip will be randomly choosen Signed-off-by: Lorenzo Bianconi --- ovn/utilities/ovn-trace.c | 61 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c index 7ca3d97aa..5755ea0bc 100644 --- a/ovn/utilities/ovn-trace.c +++ b/ovn/utilities/ovn-trace.c @@ -46,6 +46,7 @@ #include "stream.h" #include "unixctl.h" #include "util.h" +#include "random.h" VLOG_DEFINE_THIS_MODULE(ovntrace); @@ -77,6 +78,9 @@ static uint32_t *ct_states; static size_t n_ct_states; static size_t ct_state_idx; +/* --lb_dst: load balancer destination info */ +static struct ovnact_ct_lb_dst lb_dst; + /* --friendly-names, --no-friendly-names: Whether to substitute human-friendly * port and datapath names for the awkward UUIDs typically used in the actual * logical flows. */ @@ -186,6 +190,16 @@ parse_ct_option(const char *state_s_) ct_states[n_ct_states++] = state; } +static void +parse_lb_option(const char *s) +{ + if (ip_parse(s, &lb_dst.ipv4)) { + lb_dst.family = AF_INET; + } else if (ipv6_parse(s, &lb_dst.ipv6)) { + lb_dst.family = AF_INET6; + } +} + static void parse_options(int argc, char *argv[]) { @@ -202,7 +216,8 @@ parse_options(int argc, char *argv[]) OPT_NO_FRIENDLY_NAMES, DAEMON_OPTION_ENUMS, SSL_OPTION_ENUMS, - VLOG_OPTION_ENUMS + VLOG_OPTION_ENUMS, + OPT_LB_DST }; static const struct option long_options[] = { {"db", required_argument, NULL, OPT_DB}, @@ -217,6 +232,7 @@ parse_options(int argc, char *argv[]) {"no-friendly-names", no_argument, NULL, OPT_NO_FRIENDLY_NAMES}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, + {"lb_dst", required_argument, NULL, OPT_LB_DST}, DAEMON_LONG_OPTIONS, VLOG_LONG_OPTIONS, STREAM_SSL_LONG_OPTIONS, @@ -274,6 +290,10 @@ parse_options(int argc, char *argv[]) use_friendly_names = false; break; + case OPT_LB_DST: + parse_lb_option(optarg); + break; + case 'h': usage(); @@ -1822,6 +1842,42 @@ execute_ct_nat(const struct ovnact_ct_nat *ct_nat, * flow, not ct_flow. */ } +static void +execute_ct_lb(const struct ovnact_ct_lb *ct_lb, + const struct ovntrace_datapath *dp, struct flow *uflow, + enum ovnact_pipeline pipeline, struct ovs_list *super) +{ + struct flow ct_lb_flow = *uflow; + + if (ct_lb->n_dsts) { + int i, dest = random_range(ct_lb->n_dsts); + + for (i = 0; i < ct_lb->n_dsts; i++) { + if ((lb_dst.family == AF_INET && + ct_lb->dsts[i].ipv4 == lb_dst.ipv4) || + (lb_dst.family == AF_INET6 && + ipv6_addr_equals(&ct_lb->dsts[i].ipv6, + &lb_dst.ipv6))) { + dest = i; + break; + } + } + + if (ct_lb->dsts->family == AF_INET6) { + ct_lb_flow.ipv6_dst = ct_lb->dsts[dest].ipv6; + } else { + ct_lb_flow.nw_dst = ct_lb->dsts[dest].ipv4; + } + if (ct_lb->dsts->port > 0) { + ct_lb_flow.tp_dst = ct_lb->dsts->port; + } + } + + struct ovntrace_node *node = ovntrace_node_append( + super, OVNTRACE_NODE_TRANSFORMATION, "ct_lb"); + trace__(dp, &ct_lb_flow, ct_lb->ltable, pipeline, &node->subs); +} + static void execute_log(const struct ovnact_log *log, struct flow *uflow, struct ovs_list *super) @@ -1910,8 +1966,7 @@ trace_actions(const struct ovnact *ovnacts, size_t ovnacts_len, break; case OVNACT_CT_LB: - ovntrace_node_append(super, OVNTRACE_NODE_ERROR, - "*** ct_lb action not implemented"); + execute_ct_lb(ovnact_get_CT_LB(a), dp, uflow, pipeline, super); break; case OVNACT_CT_CLEAR: