From patchwork Sat Jan 11 00:40:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manoj Sharma X-Patchwork-Id: 1221507 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nutanix.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nutanix.com header.i=@nutanix.com header.a=rsa-sha256 header.s=proofpoint20171006 header.b=EMIxHWiI; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47vgy73tTPz9sR0 for ; Sat, 11 Jan 2020 11:41:03 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 997CB86C6A; Sat, 11 Jan 2020 00:41:01 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lcAb5073L3AW; Sat, 11 Jan 2020 00:40:56 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 5198E86C6D; Sat, 11 Jan 2020 00:40:55 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 43234C1D8B; Sat, 11 Jan 2020 00:40:55 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3B12AC0881 for ; Sat, 11 Jan 2020 00:40:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2A07985413 for ; Sat, 11 Jan 2020 00:40:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gEMn5_UX4HuO for ; Sat, 11 Jan 2020 00:40:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 1810A8521D for ; Sat, 11 Jan 2020 00:40:50 +0000 (UTC) Received: from pps.filterd (m0127840.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 00B0Qg7Y002859 for ; Fri, 10 Jan 2020 16:40:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=RM2+CYdltLBDJ6/5DLCMaMaE9ZKAOrg431P06mT9fp4=; b=EMIxHWiIGLu/HBA9/ud4YMtTJFdxKf7lDvYftblsUP/D8q75yQkfo/hjOA+zFkTE496D kObC4954hrDYf5jxRl0OT26fUAHjAjRlc2r1UTMW88q+hrlNISUcDs5833FyFs+6mnfs dPyI76sARghwf+SvaYKXYP1CcIDwHb0k4cWLoy6Ble0PFDXr71LhLeVFp23Ghi4N7h8g o1wLB+lcydTebFqLoU5GoRcPdgoEZ7pxN47b77Jr/xfC1luRuvSvLfd/dMSwl2FfqNOy wtiLCokAOOkVwhpeBsO25r83nNk+Nuf3Uib9iMc85wkbHnq9tUB5gpur43TXj/aT98+Q pw== Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by mx0a-002c1b01.pphosted.com with ESMTP id 2xex13rptg-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 10 Jan 2020 16:40:49 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CoUXjdZHowU+RmyJ2WYPL0D2rZ/qz07aw0QCyQvYzLIHLSDEzBpRAWgHezvmb3xZBM+F0+0YiG6/SX6WE+iEuyvqL6hIihvmwayOHmW47eawGBz2dzoDyyMyrzZCa1wzSwGypyR9nDeDLkFvn4oeMeNUeoBJV+dk7A8PdxI4BEoNW7h+YaG/hB84r/Acq1zSiY+nly9644xpS80WdNSC1O9JEeguN+d4cQHHx3jZWlNdqJNeYTAd+FnK0aIC4ZBEevUM4agaoumMFVktcPqKHuWbKeuSfHYmGvE0Rvd2g3QY1BbkYSvA3WHcoqvdySbmdoWUsoeF83EiOQSWW9Iulw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RM2+CYdltLBDJ6/5DLCMaMaE9ZKAOrg431P06mT9fp4=; b=Z2KAnA8rk/8S6zkDbnquDZadZB/9DGRD9Kin+c1k8cZ/JQ5O3kFufLOx+Jzvk1BoJkJpDIxs3TBe82/YnlcQ256ETPvmMJhymiEXYdv7elyNbIAaU9tUvgXNJXwe42STm3kc5aEHlGHLVm6spPSp2twcRepBDRgqJwg1OP/g6hMxoRbicHJw2KZF9M3dEdCfFkq7lM78hyGHA2Z2ylQPLNzH+BYXKYvQ7dL8BE1gHxsoJN6E+QSpOp3RVv7uUqzYLVUP+q25tJERbnVwdtYPgsKGRTXpJt++gb1XlvZwxwSSOwGASL+Vosy6tfckZdKC/kUj0gxOY0yvzYNABNwzuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from BYAPR02MB4614.namprd02.prod.outlook.com (52.135.238.212) by BYAPR02MB5608.namprd02.prod.outlook.com (20.177.229.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11; Sat, 11 Jan 2020 00:40:48 +0000 Received: from BYAPR02MB4614.namprd02.prod.outlook.com ([fe80::c08e:617f:5b69:a4d3]) by BYAPR02MB4614.namprd02.prod.outlook.com ([fe80::c08e:617f:5b69:a4d3%6]) with mapi id 15.20.2602.019; Sat, 11 Jan 2020 00:40:48 +0000 Received: from localhost.localdomain (192.146.154.3) by BY5PR04CA0016.namprd04.prod.outlook.com (2603:10b6:a03:1d0::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2623.9 via Frontend Transport; Sat, 11 Jan 2020 00:40:47 +0000 From: Manoj Sharma To: "ovs-dev@openvswitch.org" Thread-Topic: [PATCH v2 ovn 1/3] Forwarding group to load balance l2 traffic with liveness detection Thread-Index: AQHVyBfE0xJgBQNOFEqkZZubLaKOWg== Date: Sat, 11 Jan 2020 00:40:48 +0000 Message-ID: <20200111004027.21707-2-manoj.sharma@nutanix.com> References: <20200111004027.21707-1-manoj.sharma@nutanix.com> In-Reply-To: <20200111004027.21707-1-manoj.sharma@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BY5PR04CA0016.namprd04.prod.outlook.com (2603:10b6:a03:1d0::26) To BYAPR02MB4614.namprd02.prod.outlook.com (2603:10b6:a03:5b::20) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.2 (Apple Git-113) x-originating-ip: [192.146.154.3] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 45b6041a-5b41-413e-1a18-08d7962ee665 x-ms-traffictypediagnostic: BYAPR02MB5608: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:2733; x-forefront-prvs: 0279B3DD0D x-forefront-antispam-report: SFV:SPM; SFS:(10019020)(346002)(136003)(366004)(39860400002)(396003)(376002)(199004)(189003)(66574012)(6506007)(5660300002)(52116002)(71200400001)(6916009)(2616005)(8676002)(86362001)(1076003)(8936002)(186003)(26005)(316002)(16526019)(81156014)(81166006)(30864003)(44832011)(478600001)(4326008)(66446008)(66946007)(64756008)(956004)(66476007)(6512007)(6486002)(69590400006)(36756003)(2906002)(66556008)(107886003)(64030200002); DIR:OUT; SFP:1501; SCL:5; SRVR:BYAPR02MB5608; H:BYAPR02MB4614.namprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nutanix.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: hP3FYyKcr4gYUBvAS9P3B7QWb/L7d1KgOfTt+t+XR/biCQ4MnPr3y3BUW40ca89W7pl4Dhyu5AaoSu8pG5XIYlDNTCSXfIAaEruYWrpkvphlfYYiwuyX66+SWEwZcd8nWl9h+Jh1/txcmKdPu0YG70SmosdJGdqpkz5LjTQroskhJ/ZX+Q5FmKQHc+mPt8qVy+hUYpuSRLPOTdTRuPRRXqKJrqQzJPYLcJ7Ke+p5V891baKR7USGn4IVabXS5dneKQsv9oDdD87XOUH9myOL3Oqk5ogrFYi+QUocJNythgJ2FPBJIXF8eS/kPpDw/l1Aqjkwk0PVA9xY++zQzOYUJq4zlwPiLhs6rNLPxQg5ShjXC1SegCSUDi5V09j6rRB5JfNkvZS3VrabkccCYmpOhsjbwbfPBZZzdpjDWp2Fi9WZ4tNWBQCjaPA3j2DzeJfoEleJosdbGFgNIwa9kto9TgK88MW6VfLIcI1bBoG7eKlmt+Ja5SW9ECSha7chz+cLrYCwYNPuBpjS/aHrNsq/XdaOxwyU/T0CTbILBHfYNZ1O3GmyY8zti+FMRXPvsflQ8ABhKlCyfCQs3OMi2JFX1oCwcTPF8VY3YvfeMYOAXKcAs7YmQn8zY366/HxlzfEpjUF/LHb4Ld1wa42H+NlydeJe4ABCEL6J8WCHCqUAqBwA79xlDv9y2PoeQPe87r2dUn5mGNIkC8pt3PTZi7gJxVDtmOmtE8wqHeYkfGtUpPTK9HPbXZzR5ioGUbB60fd80aqZIR9fhqULz/FykTCAohqZs9d/FZ6GiQiyfWwCIw86MpAroLpV3DVz2SSoCLBk MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45b6041a-5b41-413e-1a18-08d7962ee665 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jan 2020 00:40:48.1507 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: V/9dRR4wnbBslWEiBmN1xuOai5oisOhNcMbKOZvlk5vbrKo97HBj8izQX2O3ghML6ba5OSJKVRrQ+RkdoqEKfZt6WPXp1ue/76y6zKqT04o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR02MB5608 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-01-10_04:2020-01-10, 2020-01-10 signatures=0 X-Proofpoint-Spam-Reason: safe Subject: [ovs-dev] [PATCH v2 ovn 1/3] Forwarding group to load balance l2 traffic with liveness detection X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add a forwarding group table and a reference to the logical switch it is configured on. The forwarding group is configured with a virtual IP, virtual MAC and a number of logical switch ports from a logical switch. Signed-off-by: Manoj Sharma Signed-off-by: Manoj Sharma > --- ovn-nb.ovsschema | 18 +++- ovn-nb.xml | 35 +++++++ utilities/ovn-nbctl.8.xml | 37 +++++++ utilities/ovn-nbctl.c | 253 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 341 insertions(+), 2 deletions(-) diff --git a/ovn-nb.ovsschema b/ovn-nb.ovsschema index 12999a4..99b6285 100644 --- a/ovn-nb.ovsschema +++ b/ovn-nb.ovsschema @@ -1,7 +1,7 @@ { "name": "OVN_Northbound", "version": "5.18.0", - "cksum": "2806349485 24196", + "cksum": "63300136 24879", "tables": { "NB_Global": { "columns": { @@ -59,7 +59,12 @@ "min": 0, "max": "unlimited"}}, "external_ids": { "type": {"key": "string", "value": "string", - "min": 0, "max": "unlimited"}}}, + "min": 0, "max": "unlimited"}}, + "forwarding_groups": { + "type": {"key": {"type": "uuid", + "refTable": "Forwarding_Group", + "refType": "strong"}, + "min": 0, "max": "unlimited"}}}, "isRoot": true}, "Logical_Switch_Port": { "columns": { @@ -113,6 +118,15 @@ "min": 0, "max": "unlimited"}}}, "indexes": [["name"]], "isRoot": false}, + "Forwarding_Group": { + "columns": { + "name": {"type": "string"}, + "vip": {"type": "string"}, + "vmac": {"type": "string"}, + "liveness": {"type": "boolean"}, + "child_port": {"type": {"key": "string", + "min": 1, "max": "unlimited"}}}, + "isRoot": false}, "Address_Set": { "columns": { "name": {"type": "string"}, diff --git a/ovn-nb.xml b/ovn-nb.xml index 5ae52bb..decb4ae 100644 --- a/ovn-nb.xml +++ b/ovn-nb.xml @@ -197,6 +197,11 @@ Please see the table. + + Groups a set of logical port endpoints for traffic going out of the + logical switch. + +

These columns provide names for the logical switch. From OVN's @@ -1152,6 +1157,36 @@ + +

+ Each row represents one forwarding group. +

+ + + A name for the forwarding group. This name has no special meaning or + purpose other than to provide convenience for human interaction with + the ovn-nb database. + + + + The virtual IP address assigned to the forwarding group. It will respond + with vmac when an ARP request is sent for vip. + + + + The virtual MAC address assigned to the forwarding group. + + + + If set to true, liveness is enabled for child ports + otherwise it is disabled. + + + + List of child ports in the forwarding group. + +
+

Each row in this table represents a named set of addresses. diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml index 88ebd13..2f3badd 100644 --- a/utilities/ovn-nbctl.8.xml +++ b/utilities/ovn-nbctl.8.xml @@ -483,6 +483,43 @@ +

Forwarding Group Commands

+ +
+
[--liveness]fwd-group-add group switch vip vmac ports
+
+

+ Creates a new forwarding group named group as the name + with the provided vip and vmac. vip + should be a virtual IP address and vmac should be a + virtual MAC address to access the forwarding group. ports + are the logical switch port names that are put in the forwarding + group. Example for ports is lsp1 lsp2 ... + Traffic destined to virtual IP of the forwarding group will be load + balanced to all the child ports. +

+

+ When --liveness is specified then child ports are + expected to be bound to external devices like routers. BFD should + be configured between hypervisors and the external devices. + The child port selection will become dependent on BFD status with + its external device. +

+
+ +
[--if-exists] fwd-group-del group
+
+ Deletes group. It is an error if group does + not exist, unless --if-exists is specified. +
+ +
fwd-group-list [switch]
+
+ Lists all existing forwarding groups, If switch is specified + then only the forwarding groups configured for switch will + be listed. +
+

Logical Router Commands

diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 46ba3a9..39f53da 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -648,6 +648,13 @@ Logical switch port commands:\n\ lsp-get-dhcpv6-options PORT get the dhcpv6 options for PORT\n\ lsp-get-ls PORT get the logical switch which the port belongs to\n\ \n\ +Forwarding group commands:\n\ + [--liveness]\n\ + fwd-group-add GROUP SWITCH VIP VMAC PORTS...\n\ + add a forwarding group on SWITCH\n\ + fwd-group-del GROUP delete a forwarding group\n\ + fwd-group-list [SWITCH] print forwarding groups\n\ +\n\ Logical router commands:\n\ lr-add [ROUTER] create a logical router named ROUTER\n\ lr-del ROUTER delete ROUTER and all its ports\n\ @@ -4720,6 +4727,244 @@ nbctl_lrp_get_redirect_type(struct ctl_context *ctx) !redirect_type ? "overlay": redirect_type); } +static const struct nbrec_forwarding_group * +fwd_group_by_name_or_uuid(struct ctl_context *ctx, const char *id) +{ + const struct nbrec_forwarding_group *fwd_group = NULL; + struct uuid fwd_uuid; + + bool is_uuid = uuid_from_string(&fwd_uuid, id); + if (is_uuid) { + fwd_group = nbrec_forwarding_group_get_for_uuid(ctx->idl, &fwd_uuid); + } + + if (!fwd_group) { + NBREC_FORWARDING_GROUP_FOR_EACH(fwd_group, ctx->idl) { + if (!strcmp(fwd_group->name, id)) { + break; + } + } + } + + return fwd_group; +} + +static const struct nbrec_logical_switch * +fwd_group_to_logical_switch(struct ctl_context *ctx, + const struct nbrec_forwarding_group *fwd_group) +{ + if (!fwd_group) { + return NULL; + } + + const struct nbrec_logical_switch_port *lsp; + char *error = lsp_by_name_or_uuid(ctx, fwd_group->child_port[0], + false, &lsp); + if (error) { + ctx->error = error; + return NULL; + } + if (!lsp) { + return NULL; + } + + const struct nbrec_logical_switch *ls; + error = lsp_to_ls(ctx->idl, lsp, &ls); + if (error) { + ctx->error = error; + return NULL; + } + + if (!ls) { + return NULL; + } + + return ls; +} + +static void +nbctl_fwd_group_add(struct ctl_context *ctx) +{ + if (ctx->argc <= 5) { + ctl_error(ctx, "Usage : ovn-nbctl fwd-group-add group switch vip vmac " + "child_ports..."); + return; + } + + /* Check if the forwarding group already exists */ + const char *fwd_group_name = ctx->argv[1]; + if (fwd_group_by_name_or_uuid(ctx, fwd_group_name)) { + ctl_error(ctx, "%s: a forwarding group by this name already exists", + fwd_group_name); + return; + } + + /* Check if the logical switch exists */ + const char *ls_name = ctx->argv[2]; + const struct nbrec_logical_switch *ls = NULL; + char *error = ls_by_name_or_uuid(ctx, ls_name, true, &ls); + if (error) { + ctx->error = error; + return; + } + + /* Virtual IP for the group */ + ovs_be32 ipv4 = 0; + const char *fwd_group_vip = ctx->argv[3]; + if (!ip_parse(fwd_group_vip, &ipv4)) { + ctl_error(ctx, "invalid ip address %s", fwd_group_vip); + return; + } + + /* Virtual MAC for the group */ + const char *fwd_group_vmac = ctx->argv[4]; + struct eth_addr ea; + if (!eth_addr_from_string(fwd_group_vmac, &ea)) { + ctl_error(ctx, "invalid mac address %s", fwd_group_vmac); + return; + } + + /* Create the forwarding group */ + struct nbrec_forwarding_group *fwd_group = NULL; + fwd_group = nbrec_forwarding_group_insert(ctx->txn); + nbrec_forwarding_group_set_name(fwd_group, fwd_group_name); + nbrec_forwarding_group_set_vip(fwd_group, fwd_group_vip); + nbrec_forwarding_group_set_vmac(fwd_group, fwd_group_vmac); + + int n_child_port = ctx->argc - 5; + const char **child_port = (const char **)&ctx->argv[5]; + + /* Verify that child ports belong to the logical switch specified */ + for (int i = 5; i < ctx->argc; ++i) { + const struct nbrec_logical_switch_port *lsp; + const char *lsp_name = ctx->argv[i]; + error = lsp_by_name_or_uuid(ctx, lsp_name, false, &lsp); + if (error) { + ctx->error = error; + return; + } + if (lsp) { + error = lsp_to_ls(ctx->idl, lsp, &ls); + if (error) { + ctx->error = error; + return; + } + if (strcmp(ls->name, ls_name)) { + ctl_error(ctx, "%s: port already exists but in logical " + "switch %s", lsp_name, ls->name); + return; + } + } else { + ctl_error(ctx, "%s: logical switch port does not exist", lsp_name); + return; + } + } + nbrec_forwarding_group_set_child_port(fwd_group, child_port, n_child_port); + + /* Liveness option */ + bool liveness = shash_find(&ctx->options, "--liveness") != NULL; + if (liveness) { + nbrec_forwarding_group_set_liveness(fwd_group, true); + } + + struct nbrec_forwarding_group **new_fwd_groups = + xmalloc(sizeof(*new_fwd_groups) * (ls->n_forwarding_groups + 1)); + memcpy(new_fwd_groups, ls->forwarding_groups, + sizeof *new_fwd_groups * ls->n_forwarding_groups); + new_fwd_groups[ls->n_forwarding_groups] = fwd_group; + nbrec_logical_switch_set_forwarding_groups(ls, new_fwd_groups, + (ls->n_forwarding_groups + 1)); + free(new_fwd_groups); + +} + +static void +nbctl_fwd_group_del(struct ctl_context *ctx) +{ + const char *id = ctx->argv[1]; + const struct nbrec_forwarding_group *fwd_group = NULL; + + fwd_group = fwd_group_by_name_or_uuid(ctx, id); + if (!fwd_group) { + return; + } + + const struct nbrec_logical_switch *ls = NULL; + ls = fwd_group_to_logical_switch(ctx, fwd_group); + if (!ls) { + return; + } + + for (int i = 0; i < ls->n_forwarding_groups; ++i) { + if (!strcmp(ls->forwarding_groups[i]->name, fwd_group->name)) { + struct nbrec_forwarding_group **new_fwd_groups = + xmemdup(ls->forwarding_groups, + sizeof *new_fwd_groups * ls->n_forwarding_groups); + new_fwd_groups[i] = + ls->forwarding_groups[ls->n_forwarding_groups - 1]; + nbrec_logical_switch_set_forwarding_groups(ls, new_fwd_groups, + (ls->n_forwarding_groups - 1)); + free(new_fwd_groups); + nbrec_forwarding_group_delete(fwd_group); + return; + } + } +} + +static void +fwd_group_list_all(struct ctl_context *ctx, const char *ls_name) +{ + const struct nbrec_logical_switch *ls; + struct ds *s = &ctx->output; + const struct nbrec_forwarding_group *fwd_group = NULL; + + if (ls_name) { + char *error = ls_by_name_or_uuid(ctx, ls_name, true, &ls); + if (error) { + ctx->error = error; + return; + } + if (!ls) { + ctl_error( + ctx, "%s: a logical switch with this name does not exist", + ls_name); + return; + } + } + + ds_put_format(s, "%-16.16s%-14.16s%-16.7s%-22.21s%s\n", + "FWD_GROUP", "LS", "VIP", "VMAC", "CHILD_PORTS"); + + NBREC_FORWARDING_GROUP_FOR_EACH(fwd_group, ctx->idl) { + ls = fwd_group_to_logical_switch(ctx, fwd_group); + if (!ls) { + continue; + } + + if (ls_name && (strcmp(ls->name, ls_name))) { + continue; + } + + ds_put_format(s, "%-16.16s%-14.18s%-15.16s%-9.18s ", + fwd_group->name, ls->name, + fwd_group->vip, fwd_group->vmac); + for (int i = 0; i < fwd_group->n_child_port; ++i) { + ds_put_format(s, " %s", fwd_group->child_port[i]); + } + ds_put_char(s, '\n'); + } +} + +static void +nbctl_fwd_group_list(struct ctl_context *ctx) +{ + if (ctx->argc == 1) { + fwd_group_list_all(ctx, NULL); + } else if (ctx->argc == 2) { + fwd_group_list_all(ctx, ctx->argv[1]); + } +} + struct ipv4_route { int priority; @@ -5704,6 +5949,14 @@ static const struct ctl_command_syntax nbctl_commands[] = { nbctl_lsp_get_dhcpv6_options, NULL, "", RO }, { "lsp-get-ls", 1, 1, "PORT", NULL, nbctl_lsp_get_ls, NULL, "", RO }, + /* forwarding group commands. */ + { "fwd-group-add", 4, INT_MAX, "SWITCH GROUP VIP VMAC PORT...", + NULL, nbctl_fwd_group_add, NULL, "--liveness", RW }, + { "fwd-group-del", 1, 1, "GROUP", NULL, nbctl_fwd_group_del, NULL, + "--if-exists", RW }, + { "fwd-group-list", 0, 1, "[GROUP]", NULL, nbctl_fwd_group_list, NULL, + "", RO }, + /* logical router commands. */ { "lr-add", 0, 1, "[ROUTER]", NULL, nbctl_lr_add, NULL, "--may-exist,--add-duplicate", RW }, From patchwork Sat Jan 11 00:40:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manoj Sharma X-Patchwork-Id: 1221505 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nutanix.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nutanix.com header.i=@nutanix.com header.a=rsa-sha256 header.s=proofpoint20171006 header.b=O/AE6tzF; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47vgy64CdPz9sP3 for ; Sat, 11 Jan 2020 11:41:00 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 26B3F86D02; Sat, 11 Jan 2020 00:40:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VwdE1JQn0kJJ; Sat, 11 Jan 2020 00:40:54 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 8D22486B34; Sat, 11 Jan 2020 00:40:54 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7743AC1D8B; Sat, 11 Jan 2020 00:40:54 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id CD2C1C0881 for ; Sat, 11 Jan 2020 00:40:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id BC77C87D39 for ; Sat, 11 Jan 2020 00:40:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BVBrTEDfi8um for ; Sat, 11 Jan 2020 00:40:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by hemlock.osuosl.org (Postfix) with ESMTPS id 942D287D96 for ; Sat, 11 Jan 2020 00:40:51 +0000 (UTC) Received: from pps.filterd (m0127840.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 00B0Qg7Z002859 for ; Fri, 10 Jan 2020 16:40:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=ZOpCW/qGpSFso+/uWqf8ng4lqdx3ojz0wnHVeb9+pbU=; b=O/AE6tzF7i0PrMbNn8eftdHYDT9IYXRWXuh+5IxuYpYvuNh567FoQD36UGds5J/ihuP4 haLyve0/OqLk3gsbPFEh78mPeNqRA2pKNbpZ2ECTz6PYZf8fIRAJSIcPFO0pXbVcqEm7 8BntbW01/JtrJKatRE+fHLzfy3F0o6fAUn2sXWQXrF4cWoESfY2rUKk6+HfF0dqCvjeF lxHYRDCh8zo83i2NWymRQy9Ws6TFeqWvQZuXg8CxI+NdGnxnR3FPTyAzgSjEbMkLmBx2 Z8r9a65SMozIheJM9V3Y/jJLSONAqp2ubAzDFplgkbN8AYudZPDvQ8fpfR8zrpXqHoFi KQ== Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by mx0a-002c1b01.pphosted.com with ESMTP id 2xex13rptg-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 10 Jan 2020 16:40:50 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jDIcD9kIC20V4B4WqDF+KnAfGrx/AmqUWLJ17S8vRIby/JCHPwCiptEXjeEPQJu7kOrSPly/mHxwWF1TUtt6SNOyH2DuYhdH2UwLSVoeQfJqSuWvOYuMelfG5M0CPUiLSZOoyfQuoNj/lQSTk+aiGGWhc+RJKZHnSEv4zOkduhEhM4QAGuTnzu3/K7lAX2JNW83nK6GgXAKh7iRluzZOvp1AEBK2hoWsNoK/gCYD/hJH1//DeI7h4FmtN4OvamdQBUnpscAmsl/WNd72VGRvLJwAZH4a5HJGx0trGoiV//xQyTmo4VJ9ApmN2w9QqDtqC/i4lIDqKX74g0LkUsjE2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZOpCW/qGpSFso+/uWqf8ng4lqdx3ojz0wnHVeb9+pbU=; b=Mu0+ui4IuuKmqwN0y/+jXOAE2p7Lk658lkkbDrZb4h8zmhUOaoI/VfbU1tHNBlBFHEfs5ydieejaQlnHR/wj6Rlzzlf6sslxVOz1tCHYc1xZw8W+QO6EB1oqSuffKpoJ0Gk5g1EYvJk6KcgTNYsO0RXffVmDYunOir+F90POuyzOqdsKY63Sxd24R5kuYPCPdWrty++XCu1zN9Zu6PwjFxUIXlKhLavEiIBE1Q5Sy2RJc2oRRoW9LcDUGHK+oOgRok66OYv9lupBsm9EXhJOza2/SoQ0g2UR9pXwBmZCEZkoL6NpHgUDwPo0hZJVwwnbDooQi4SPO/ZdoJQBxL8onw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from BYAPR02MB4614.namprd02.prod.outlook.com (52.135.238.212) by BYAPR02MB5608.namprd02.prod.outlook.com (20.177.229.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11; Sat, 11 Jan 2020 00:40:49 +0000 Received: from BYAPR02MB4614.namprd02.prod.outlook.com ([fe80::c08e:617f:5b69:a4d3]) by BYAPR02MB4614.namprd02.prod.outlook.com ([fe80::c08e:617f:5b69:a4d3%6]) with mapi id 15.20.2602.019; Sat, 11 Jan 2020 00:40:49 +0000 Received: from localhost.localdomain (192.146.154.3) by BY5PR04CA0016.namprd04.prod.outlook.com (2603:10b6:a03:1d0::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2623.9 via Frontend Transport; Sat, 11 Jan 2020 00:40:48 +0000 From: Manoj Sharma To: "ovs-dev@openvswitch.org" Thread-Topic: [PATCH v2 ovn 2/3] Forwarding group to load balance l2 traffic with liveness detection Thread-Index: AQHVyBfE3mM0NpwUaUq+uclMX1cqXA== Date: Sat, 11 Jan 2020 00:40:49 +0000 Message-ID: <20200111004027.21707-3-manoj.sharma@nutanix.com> References: <20200111004027.21707-1-manoj.sharma@nutanix.com> In-Reply-To: <20200111004027.21707-1-manoj.sharma@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BY5PR04CA0016.namprd04.prod.outlook.com (2603:10b6:a03:1d0::26) To BYAPR02MB4614.namprd02.prod.outlook.com (2603:10b6:a03:5b::20) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.2 (Apple Git-113) x-originating-ip: [192.146.154.3] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 07cbc1f6-a9c6-49d9-3137-08d7962ee709 x-ms-traffictypediagnostic: BYAPR02MB5608: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:179; x-forefront-prvs: 0279B3DD0D x-forefront-antispam-report: SFV:SPM; SFS:(10019020)(346002)(136003)(366004)(39860400002)(396003)(376002)(199004)(189003)(6506007)(5660300002)(52116002)(71200400001)(6916009)(2616005)(8676002)(86362001)(1076003)(8936002)(186003)(26005)(316002)(16526019)(81156014)(81166006)(30864003)(44832011)(478600001)(4326008)(66446008)(66946007)(64756008)(956004)(66476007)(6512007)(6486002)(69590400006)(36756003)(2906002)(66556008)(107886003)(64030200002); DIR:OUT; SFP:1501; SCL:5; SRVR:BYAPR02MB5608; H:BYAPR02MB4614.namprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nutanix.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wwz0SZQHFrGJV4PivkTqwRFgjMmmMDEKdpJrXhLRTQGWYIoocT3KIEliXYim4vbpgVW2ZxqhiAl/3+ELKdkRi5BiMpchTw1oY9J8elMxO4/bdwG3ds/KfpLs7DQPn+FXhA4etIBXEAK0yo8F0gxAqbok0femfxVUTInEct6Mw9kE18oLRM2HmNAwBxxkqP64RyQdo/18xXAZSiyPrglAaBmJXAVyhsQU8NpHeT8EDwywurnf38IfgffnNyXWO7kiVrzMKuxeaSmZ8jzbbIddnQwabuPWJJskJ+BGLaApgcnANiGMZtmX5de2IbEqAhI7XFSWKlXxFGraEcEPHPpWDpx3aB/tDQHi+QsqOzV+8b0KuT+fSC5elck5lfpGXz6QC/tSMyvy+3oepObr4tkKQJMhnb14+MODEVrzvsbEBOqj1f8tzFiMEcZRWOiPoE/Nw23R+9qTvgkxL+JmwYhfumTVmz9DYGVN9fg6l21eYyQ563F4mwu2JCeFEXlOMvV/bPaAxUzjtbqJun4qeirLClvn1BIlRy3Wxqg0xpvcP2SJr3G3NPnwH8x4Vl37okUi4/q/O5lOusF1+UMNG7oAyTMqCgj0/XjmAK1LGpcPfdo0980HFgitXHkQj4byUYSnWZsCUtnSkODG4ggHqZh/ly0tA/px+0zLxkgskVmuinfEEaeINkbTAbcherS1GhE4fKWN7OIibUWl+UwcDau2u/deLGDy0YAJpLo7KGJPwRnfOjS85ahpGdRsPdDGrmuBBzOmJcYPim7pWpMZXFCk5cAUDk0/0SzWos0Ij57qbcUf5zqFY25+EEBjO/INpqq3 MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07cbc1f6-a9c6-49d9-3137-08d7962ee709 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jan 2020 00:40:49.1811 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 4nKpuJ2GPcrZJe+rhScInd4a7hU0nvKg//1TJE5QQ63LYSH/zPFsps/4424/M7Xc7P/rn9ruseyMCff3ABYV6Zf3Ja3bGREg0d7B4X016V8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR02MB5608 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-01-10_04:2020-01-10, 2020-01-10 signatures=0 X-Proofpoint-Spam-Reason: safe Subject: [ovs-dev] [PATCH v2 ovn 2/3] Forwarding group to load balance l2 traffic with liveness detection X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add forwarding group support for a logical switch. It will add a new OVN action "fwd_group" with a virtual IP and virtual MAC. Any number of logical switch ports of this switch can be added to this forwarding group. If traffic has to be load balanced across these logical switch ports then traffic should be sent to forwarding group's virtual IP. If the logical switch ports correspond to tunnel interfaces and BFD can be enabled on these tunnel interfaces, then liveness can be enabled for the forwarding group so that if any of the tunnel is down then the corresponding logical switch port will not be selected during load balancing. Signed-off-by: Manoj Sharma Signed-off-by: Manoj Sharma > --- controller/lflow.c | 20 +++++++++ controller/physical.c | 13 ++++++ controller/physical.h | 4 ++ include/ovn/actions.h | 19 +++++++- lib/actions.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ northd/ovn-northd.c | 63 ++++++++++++++++++++++++++ utilities/ovn-trace.c | 3 ++ 7 files changed, 243 insertions(+), 1 deletion(-) diff --git a/controller/lflow.c b/controller/lflow.c index a689320..49dfa06 100644 --- a/controller/lflow.c +++ b/controller/lflow.c @@ -103,6 +103,25 @@ lookup_port_cb(const void *aux_, const char *port_name, unsigned int *portp) return false; } +/* Given the OVN port name, get its openflow port */ +static bool +tunnel_ofport_cb(const void *aux_, const char *port_name, ofp_port_t *ofport) +{ + const struct lookup_port_aux *aux = aux_; + + const struct sbrec_port_binding *pb + = lport_lookup_by_name(aux->sbrec_port_binding_by_name, port_name); + if (!pb || (pb->datapath != aux->dp) || !pb->chassis) { + return false; + } + + if (!get_tunnel_ofport(pb->chassis->name, NULL, ofport)) { + return false; + } + + return true; +} + static bool is_chassis_resident_cb(const void *c_aux_, const char *port_name) { @@ -681,6 +700,7 @@ consider_logical_flow( struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub); struct ovnact_encode_params ep = { .lookup_port = lookup_port_cb, + .tunnel_ofport = tunnel_ofport_cb, .aux = &aux, .is_switch = is_switch(ldp), .group_table = group_table, diff --git a/controller/physical.c b/controller/physical.c index 500d419..af1d10f 100644 --- a/controller/physical.c +++ b/controller/physical.c @@ -1794,3 +1794,16 @@ physical_run(struct ovsdb_idl_index *sbrec_port_binding_by_name, simap_destroy(&new_tunnel_to_ofport); } + +bool +get_tunnel_ofport(const char *chassis_name, char *encap_ip, ofp_port_t *ofport) +{ + struct chassis_tunnel *tun = NULL; + tun = chassis_tunnel_find(chassis_name, encap_ip); + if (!tun) { + return false; + } + + *ofport = tun->ofport; + return true; +} diff --git a/controller/physical.h b/controller/physical.h index c93f6b1..c0e17cd 100644 --- a/controller/physical.h +++ b/controller/physical.h @@ -72,4 +72,8 @@ void physical_handle_mc_group_changes( const struct simap *ct_zones, const struct hmap *local_datapaths, struct ovn_desired_flow_table *); +bool get_tunnel_ofport( + const char *chassis_name, + char *encap_ip, + ofp_port_t *ofport); #endif /* controller/physical.h */ diff --git a/include/ovn/actions.h b/include/ovn/actions.h index 047a8d7..2d39239 100644 --- a/include/ovn/actions.h +++ b/include/ovn/actions.h @@ -89,7 +89,8 @@ struct ovn_extend_table; OVNACT(CHECK_PKT_LARGER, ovnact_check_pkt_larger) \ OVNACT(TRIGGER_EVENT, ovnact_controller_event) \ OVNACT(BIND_VPORT, ovnact_bind_vport) \ - OVNACT(HANDLE_SVC_CHECK, ovnact_handle_svc_check) + OVNACT(HANDLE_SVC_CHECK, ovnact_handle_svc_check) \ + OVNACT(FWD_GROUP, ovnact_fwd_group) /* enum ovnact_type, with a member OVNACT_ for each action. */ enum OVS_PACKED_ENUM ovnact_type { @@ -359,6 +360,15 @@ struct ovnact_handle_svc_check { struct expr_field port; /* Logical port name. */ }; +/* OVNACT_FWD_GROUP. */ +struct ovnact_fwd_group { + struct ovnact ovnact; + bool liveness; + char **child_ports; /* Logical ports */ + size_t n_child_ports; + uint8_t ltable; /* Logical table ID of next table. */ +}; + /* Internal use by the helpers below. */ void ovnact_init(struct ovnact *, enum ovnact_type, size_t len); void *ovnact_put(struct ofpbuf *, enum ovnact_type, size_t len); @@ -620,6 +630,13 @@ struct ovnact_encode_params { * '*portp' and returns true; otherwise, returns false. */ bool (*lookup_port)(const void *aux, const char *port_name, unsigned int *portp); + + /* Looks up tunnel port to a chassis by its port name. If found, stores + * its openflow port number in '*ofport' and returns true; + * otherwise, returns false. */ + bool (*tunnel_ofport)(const void *aux, const char *port_name, + ofp_port_t *ofport); + const void *aux; /* 'true' if the flow is for a switch. */ diff --git a/lib/actions.c b/lib/actions.c index 051e6c8..73dade9 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -2854,6 +2854,126 @@ ovnact_handle_svc_check_free(struct ovnact_handle_svc_check *sc OVS_UNUSED) { } +static void +parse_fwd_group_action(struct action_context *ctx) +{ + char *child_port, **child_port_list = NULL; + size_t allocated_ports = 0; + size_t n_child_ports = 0; + bool liveness = false; + + if (lexer_match(ctx->lexer, LEX_T_LPAREN)) { + if (lexer_match_id(ctx->lexer, "liveness")) { + liveness = true; + lexer_force_match(ctx->lexer, LEX_T_SEMICOLON); + } + while (!lexer_match(ctx->lexer, LEX_T_RPAREN)) { + if (ctx->lexer->token.type != LEX_T_STRING) { + lexer_syntax_error(ctx->lexer, + "expecting logical switch port"); + return; + } + /* Parse child's logical ports */ + child_port = xstrdup(ctx->lexer->token.s); + lexer_get(ctx->lexer); + lexer_match(ctx->lexer, LEX_T_COMMA); + + if (n_child_ports >= allocated_ports) { + child_port_list = x2nrealloc(child_port_list, &allocated_ports, + sizeof *child_port_list); + } + child_port_list[n_child_ports++] = child_port; + } + } + + struct ovnact_fwd_group *fwd_group = ovnact_put_FWD_GROUP(ctx->ovnacts); + fwd_group->ltable = ctx->pp->cur_ltable + 1; + fwd_group->liveness = liveness; + fwd_group->child_ports = child_port_list; + fwd_group->n_child_ports = n_child_ports; +} + +static void +format_FWD_GROUP(const struct ovnact_fwd_group *fwd_group, struct ds *s) +{ + ds_put_cstr(s, "fwd_group("); + if (fwd_group->liveness) { + ds_put_cstr(s, "liveness;"); + } + if (fwd_group->n_child_ports) { + for (size_t i = 0; i < fwd_group->n_child_ports; i++) { + if (i) { + ds_put_cstr(s, ", "); + } + + ds_put_format(s, "%s", fwd_group->child_ports[i]); + } + } + ds_put_cstr(s, ");"); +} + +static void +encode_FWD_GROUP(const struct ovnact_fwd_group *fwd_group, + const struct ovnact_encode_params *ep, + struct ofpbuf *ofpacts) +{ + if (!fwd_group->n_child_ports) { + /* Nothing to do without child ports */ + return; + } + + uint32_t reg_index = MFF_LOG_OUTPORT - MFF_REG0; + struct ds ds = DS_EMPTY_INITIALIZER; + + ds_put_format(&ds, "type=select,selection_method=dp_hash"); + + for (size_t i = 0; i < fwd_group->n_child_ports; i++) { + uint32_t port_tunnel_key; + ofp_port_t ofport; + + const char *port_name = fwd_group->child_ports[i]; + + /* Find the tunnel key of the logical port */ + if (!ep->lookup_port(ep->aux, port_name, &port_tunnel_key)) { + return; + } + ds_put_format(&ds, ",bucket="); + + if (fwd_group->liveness) { + /* Find the openflow port number of the tunnel port */ + if (!ep->tunnel_ofport(ep->aux, port_name, &ofport)) { + return; + } + + /* Watch port for failure, used with BFD */ + ds_put_format(&ds, "watch_port:%d,", ofport); + } + + ds_put_format(&ds, "load=0x%d->NXM_NX_REG%d[0..15]", + port_tunnel_key, reg_index); + ds_put_format(&ds, ",resubmit(,%d)", ep->output_ptable); + } + + uint32_t table_id = 0; + struct ofpact_group *og; + table_id = ovn_extend_table_assign_id(ep->group_table, ds_cstr(&ds), + ep->lflow_uuid); + ds_destroy(&ds); + if (table_id == EXT_TABLE_ID_INVALID) { + return; + } + + /* Create an action to set the group */ + og = ofpact_put_GROUP(ofpacts); + og->group_id = table_id; +} + +static void +ovnact_fwd_group_free(struct ovnact_fwd_group *fwd_group) +{ + free(fwd_group->child_ports); +} + /* Parses an assignment or exchange or put_dhcp_opts action. */ static void parse_set_action(struct action_context *ctx) @@ -2973,6 +3093,8 @@ parse_action(struct action_context *ctx) parse_bind_vport(ctx); } else if (lexer_match_id(ctx->lexer, "handle_svc_check")) { parse_handle_svc_check(ctx); + } else if (lexer_match_id(ctx->lexer, "fwd_group")) { + parse_fwd_group_action(ctx); } else { lexer_syntax_error(ctx->lexer, "expecting action"); } diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index b6dc809..29bb27a 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -5419,6 +5419,60 @@ build_stateful(struct ovn_datapath *od, struct hmap *lflows, struct hmap *lbs) } static void +build_fwd_group_lflows(struct ovn_datapath *od, struct hmap *lflows) +{ + struct ds match = DS_EMPTY_INITIALIZER; + struct ds actions = DS_EMPTY_INITIALIZER; + + for (int i = 0; i < od->nbs->n_forwarding_groups; ++i) { + const struct nbrec_forwarding_group *fwd_group = NULL; + fwd_group = od->nbs->forwarding_groups[i]; + if (!fwd_group || (fwd_group->n_child_port == 0)) { + continue; + } + + /* ARP responder for the forwarding group's virtual IP */ + ds_put_format(&match, "arp.tpa == %s && arp.op == 1", + fwd_group->vip); + ds_put_format(&actions, + "eth.dst = eth.src; " + "eth.src = %s; " + "arp.op = 2; /* ARP reply */ " + "arp.tha = arp.sha; " + "arp.sha = %s; " + "arp.tpa = arp.spa; " + "arp.spa = %s; " + "outport = inport; " + "flags.loopback = 1; " + "output;", + fwd_group->vmac, fwd_group->vmac, fwd_group->vip); + + ovn_lflow_add(lflows, od, S_SWITCH_IN_ARP_ND_RSP, 50, + ds_cstr(&match), ds_cstr(&actions)); + + /* L2 lookup for the forwarding group's virtual MAC */ + ds_clear(&match); + ds_put_format(&match, "eth.dst == %s", fwd_group->vmac); + + /* Create a comma separated string of child ports */ + struct ds group_ports = DS_EMPTY_INITIALIZER; + if (fwd_group->liveness) { + ds_put_cstr(&group_ports, "liveness;"); + } + for (i = 0; i < (fwd_group->n_child_port - 1); ++i) { + ds_put_format(&group_ports, "\"%s\",", fwd_group->child_port[i]); + } + ds_put_format(&group_ports, "\"%s\"", + fwd_group->child_port[fwd_group->n_child_port - 1]); + + ds_clear(&actions); + ds_put_format(&actions, "fwd_group(%s);", group_ports.string); + ovn_lflow_add(lflows, od, S_SWITCH_IN_L2_LKUP, 50, + ds_cstr(&match), ds_cstr(&actions)); + } +} + +static void build_lrouter_groups__(struct hmap *ports, struct ovn_datapath *od) { ovs_assert((od && od->nbr && od->lr_group)); @@ -5718,6 +5772,15 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports, build_stateful(od, lflows, lbs); } + /* Build logical flows for the forwarding groups */ + HMAP_FOR_EACH (od, key_node, datapaths) { + if (!od->nbs) { + continue; + } + + build_fwd_group_lflows(od, lflows); + } + /* Logical switch ingress table 0: Admission control framework (priority * 100). */ HMAP_FOR_EACH (od, key_node, datapaths) { diff --git a/utilities/ovn-trace.c b/utilities/ovn-trace.c index 2645438..a40700a 100644 --- a/utilities/ovn-trace.c +++ b/utilities/ovn-trace.c @@ -2224,6 +2224,9 @@ trace_actions(const struct ovnact *ovnacts, size_t ovnacts_len, case OVNACT_HANDLE_SVC_CHECK: break; + + case OVNACT_FWD_GROUP: + break; } } ds_destroy(&s); From patchwork Sat Jan 11 00:40:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manoj Sharma X-Patchwork-Id: 1221508 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nutanix.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nutanix.com header.i=@nutanix.com header.a=rsa-sha256 header.s=proofpoint20171006 header.b=xulbLtgo; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47vgyF4hn6z9sP6 for ; Sat, 11 Jan 2020 11:41:09 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id E424086D2C; Sat, 11 Jan 2020 00:41:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t4L3d3BrPnvb; Sat, 11 Jan 2020 00:41:04 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 5AD3786CD7; Sat, 11 Jan 2020 00:40:57 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3D804C1D8B; Sat, 11 Jan 2020 00:40:57 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id D13ECC1D85 for ; Sat, 11 Jan 2020 00:40:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id CB451228DB for ; Sat, 11 Jan 2020 00:40:55 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vD+6-XETqPvu for ; Sat, 11 Jan 2020 00:40:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) by silver.osuosl.org (Postfix) with ESMTPS id DEA8E20335 for ; Sat, 11 Jan 2020 00:40:51 +0000 (UTC) Received: from pps.filterd (m0127840.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 00B0Qg7a002859 for ; Fri, 10 Jan 2020 16:40:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=OB+Lnyv0PEDtL+i1xbt2oQaODzIpfRBbDHKk08n/RPg=; b=xulbLtgohIVS6qvMU0lTd3+lizmTgm/Kw/g7hTuj66g9dy/0p++JWweoWfRjFN7QASoz 2Uaav6hGGjENcBg280ArSG37Ee6ENFroXV/3CVLH1JQHZ5bvqDAaZKYEBTq8nv5kufYd KeHD21pX+tojIyWTN3rJN8rKOEbG00wownwClmlakE2ZYrBGSsKIw69V9zko2ryuE77u OB08+2bI1S0WQTcV0nqjgX4AxViFM7d4Ovkj3tkdi/2ul5hm+of1aHhKfa2FTzEFy5ce 0dXXKzI0EyqQyuddzpgUM50rLKt3ae3j3dBNQ+0A3Kq+A/ngt6+W1A2jn+tLRrOgDMFC tg== Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by mx0a-002c1b01.pphosted.com with ESMTP id 2xex13rptg-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 10 Jan 2020 16:40:50 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AuVWeIJl8QRCftUy1I2a78OCLFBTw3Vd8UdveU62lll6mGwOcLEukN0goF5IDz5KvRh6lDVkpbAlvxoXPgM3sOj1l0laSP9dru6iQi6pMFaSjfmgBZerJ9+nBE9lZDvVo0hZ5HZA+yR+YUrzFd0lQEdOkb9uwBnie+HjAMDJ27j4iMbUF7IMX1s2SZUbGrNKA6PyaV9EizWi75C5uDj4Ma87ZbRNxUIpsq4zaLZJ1VbmS+M5XisHTlv+1YPQ8h9a6keG3uuVew+ZnJj7deSCIXX9i+tu3EzGvU9equ/Bj18ITYbAuRrnumTdc46rblTeTwyKtqtKjh77eeKO+kBSUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OB+Lnyv0PEDtL+i1xbt2oQaODzIpfRBbDHKk08n/RPg=; b=EXhkeEg6r/9Ms0v6elmKI1dfeVHgIChLQxexiTOTebS3nKWcrCJ7ctgH6ylBr0MzeR308mWyMOFwAHjU10OnYQnAVbTwkAik3XcDDjWdVQXdWdrBAkvGdByEd1DjJqZZBryLJUQBaesIqKaAg5Ud5fOFVDMd6q1yp/qNCrKpn+lvdMjZtqBYplldxuQo0cgW/ZxaAwqYrJwaWHtBXhP9LlP6daNtB4UMEYnWf6BSVO3wHSHahi6fYWDMy3Ue0R3mqIxaLDnDAtiI+rcPrsR968vm5zhpQONU4/omAeoJUcEX5xGe6uup9/g5Wd+25M1ypgu3ysJLz4vxxDGznpwUzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none Received: from BYAPR02MB4614.namprd02.prod.outlook.com (52.135.238.212) by BYAPR02MB5608.namprd02.prod.outlook.com (20.177.229.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11; Sat, 11 Jan 2020 00:40:50 +0000 Received: from BYAPR02MB4614.namprd02.prod.outlook.com ([fe80::c08e:617f:5b69:a4d3]) by BYAPR02MB4614.namprd02.prod.outlook.com ([fe80::c08e:617f:5b69:a4d3%6]) with mapi id 15.20.2602.019; Sat, 11 Jan 2020 00:40:49 +0000 Received: from localhost.localdomain (192.146.154.3) by BY5PR04CA0016.namprd04.prod.outlook.com (2603:10b6:a03:1d0::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2623.9 via Frontend Transport; Sat, 11 Jan 2020 00:40:49 +0000 From: Manoj Sharma To: "ovs-dev@openvswitch.org" Thread-Topic: [PATCH v2 ovn 3/3] Forwarding group to load balance l2 traffic with liveness detection Thread-Index: AQHVyBfFxQCV/q/Qbkq+EtyJ1u8w+A== Date: Sat, 11 Jan 2020 00:40:49 +0000 Message-ID: <20200111004027.21707-4-manoj.sharma@nutanix.com> References: <20200111004027.21707-1-manoj.sharma@nutanix.com> In-Reply-To: <20200111004027.21707-1-manoj.sharma@nutanix.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BY5PR04CA0016.namprd04.prod.outlook.com (2603:10b6:a03:1d0::26) To BYAPR02MB4614.namprd02.prod.outlook.com (2603:10b6:a03:5b::20) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.2 (Apple Git-113) x-originating-ip: [192.146.154.3] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0fde1f6e-1782-432d-e152-08d7962ee79d x-ms-traffictypediagnostic: BYAPR02MB5608: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-proofpoint-crosstenant: true x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 0279B3DD0D x-forefront-antispam-report: SFV:SPM; SFS:(10019020)(346002)(136003)(366004)(39860400002)(396003)(376002)(199004)(189003)(66574012)(6506007)(5660300002)(52116002)(71200400001)(6916009)(2616005)(8676002)(86362001)(1076003)(8936002)(186003)(26005)(316002)(16526019)(81156014)(81166006)(44832011)(478600001)(4326008)(66446008)(66946007)(64756008)(956004)(66476007)(6512007)(6486002)(69590400006)(36756003)(2906002)(66556008)(107886003)(64030200002); DIR:OUT; SFP:1501; SCL:5; SRVR:BYAPR02MB5608; H:BYAPR02MB4614.namprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nutanix.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: n5Nuo6kmejW0YHJAF4cKNu8zf2BuY0yGLaERNHpfBr2lYqISpTurlXBFjwxoewoMh0BlKYXAk8/M7R7ckyktFnqWrvhoiub6qyv63KyDEeXkJxj6ns0IWywu4GprAW402QH6HjWUKk+9i9fPSu1aVrhYHeWhXPIQDorPmUM3FD5btuc8XRnhtk/BUK3c+mFUSvmsEkmnPgb32DYdfeXZ2nxibt15pMJEY5DZxEZWv8KwuHwirZw7nIA6UXErdqxQstxjEz2hjDpd3D659MR+AxP/OGrFgijcEatBT1RPcouTT1eVpBdBNgA8njU1VsgqbXE2w0os/qrPWk5IRe69F00aNn5COHGt78XjOtyr5bQxjhqbuMQ0dVafSvaknoLUoCoRJHVRnyf82G/qFKbj3HfLAMlw/L9kNROeBQpLKnCROr1vcTbLMsjlpx5M/KAESSlGSCXzAxfzeejnaqPpLP3kVTI3mHJC2hF+8+I5fPk5mZ97mFAtYmoqV9cfVDrcmNNxkJE86YD8dT7zp+PQ4VyEhzZmxDZM8O4GS6UmNPns9J1G3ajaAbgDmt0GqJ4C3Qf4ikmEmfjsOytmGN+N0JwuJLv87O1kjk/J6LnPQxJyGJhg5uAO17f6/5yV39BJNgNmUJ9mk02K4/311VJc89X825Y6blZtZI3O6eXE9wZD7EfdvrsncQLsJ930xaYScRgAaVk0BytQYn/CWhPtaWXx//PzMXZhAkh7Fd8wHPAyROsT1VlRFtu1MKhxO8kVkUQ4wfC4igBH1wV6lLiSz5h4EDhH5H2Y+i5tfYDi3kPSwgep6kf0TXWXSn4Luu/f MIME-Version: 1.0 X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0fde1f6e-1782-432d-e152-08d7962ee79d X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jan 2020 00:40:49.8568 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: H2Quohqz6/hkcSLeuRA1fKKX9TN3lRSCqnNAVlA9vwSZraEyBJIW5F2lHBgQJpkk+0lq+HhK3TIh69bGKYFh1hjW7w6BhmC5YEczbWJBB7Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR02MB5608 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-01-10_04:2020-01-10, 2020-01-10 signatures=0 X-Proofpoint-Spam-Reason: safe Subject: [ovs-dev] [PATCH v2 ovn 3/3] Forwarding group to load balance l2 traffic with liveness detection X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Unit tests for forwarding group Signed-off-by: Manoj Sharma --- tests/ovn-nbctl.at | 37 ++++++++++++++++ tests/ovn.at | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index 2679f1f..077c41e 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -1735,6 +1735,43 @@ $SW1P2 AT_CHECK([ovn-nbctl pg-del pg1], [0], [ignore]) AT_CHECK([ovn-nbctl list port_group], [0], []) ]) +dnl --------------------------------------------------------------------- + +OVN_NBCTL_TEST([ovn_nbctl_fwd_groups], [fwd groups], [ + +dnl Add fwd-group to a non-existent logical switch +AT_CHECK([ovn-nbctl fwd-group-add fwd_grp1 ls0 10.1.1.11 00:11:22:33:44:55 lsp1 lsp2], [1], [], + [ovn-nbctl: ls0: switch name not found +]) + +AT_CHECK([ovn-nbctl ls-add ls0]) + +dnl Add fwd-group with non-existent logical switch ports +AT_CHECK([ovn-nbctl fwd-group-add fwd_grp1 ls0 10.1.1.11 00:11:22:33:44:55 lsp1 lsp2], [1], [], + [ovn-nbctl: lsp1: logical switch port does not exist +]) + +AT_CHECK([ovn-nbctl lsp-add ls0 lsp1]) +AT_CHECK([ovn-nbctl lsp-add ls0 lsp2]) +AT_CHECK([ovn-nbctl fwd-group-add fwd_grp1 ls0 10.1.1.11 00:11:22:33:44:55 lsp1 lsp2]) +AT_CHECK([ovn-nbctl fwd-group-list ls0], [0], [dnl +FWD_GROUP LS VIP VMAC CHILD_PORTS +fwd_grp1 ls0 10.1.1.11 00:11:22:33:44:55 lsp1 lsp2 +]) +AT_CHECK([ovn-nbctl --bare --columns=name list forwarding_group], [0], +[fwd_grp1 +]) + +dnl Add duplicate fwd-group +AT_CHECK([ovn-nbctl fwd-group-add fwd_grp1 ls0 10.1.1.11 00:11:22:33:44:55 lsp1 lsp2], [1], [], + [ovn-nbctl: fwd_grp1: a forwarding group by this name already exists +]) + +dnl Delete fwd-group +AT_CHECK([ovn-nbctl fwd-group-del fwd_grp1], [0], [ignore]) +AT_CHECK([ovn-nbctl list forwarding_group], [0], []) + +]) AT_SETUP([ovn-nbctl - daemon retry connection]) OVN_NBCTL_TEST_START daemon diff --git a/tests/ovn.at b/tests/ovn.at index 411b768..b8e8eba 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -17338,3 +17338,127 @@ OVS_WAIT_UNTIL([ OVN_CLEANUP([hv1]) AT_CLEANUP + +AT_SETUP([ovn -- forwarding group: 3 HVs, 1 LR, 2 LS]) +AT_KEYWORDS([forwarding-group]) +ovn_start + +# Logical network: +# One LR - R1 has a logical switch ls1 and ls2 connected to it. +# Logical switch ls1 has one port while ls2 has two logical switch ports as +# child ports. +ovn-nbctl lr-add R1 +ovn-nbctl ls-add ls1 +ovn-nbctl ls-add ls2 + +# Logical switch ls1 to R1 connectivity +ovn-nbctl lrp-add R1 R1-ls1 00:00:00:01:02:f1 192.168.1.1/24 +ovn-nbctl lsp-add ls1 ls1-R1 -- set Logical_Switch_Port ls1-R1 \ + type=router options:router-port=R1-ls1 -- lsp-set-addresses ls1-R1 router +ovn-nbctl lsp-add ls1 lsp11 \ + -- lsp-set-addresses lsp11 "00:00:00:01:02:01 192.168.1.2" + +# Logical switch ls2 to R1 connectivity +ovn-nbctl lrp-add R1 R1-ls2 00:00:00:01:02:f2 172.16.1.1/24 +ovn-nbctl lsp-add ls2 ls2-R1 -- set Logical_Switch_Port ls2-R1 \ + type=router options:router-port=R1-ls2 -- lsp-set-addresses ls2-R1 router +ovn-nbctl lsp-add ls2 lsp21 \ + -- lsp-set-addresses lsp21 "00:00:00:01:02:01 172.16.1.2" +ovn-nbctl lsp-add ls2 lsp22 \ + -- lsp-set-addresses lsp22 "00:00:00:01:02:02 172.16.1.3" + +# Create a network +net_add n1 + +# Create hypervisor hv1 connected to n1 +sim_add hv1 +as hv1 +ovs-vsctl add-br br-phys +ovn_attach n1 br-phys 192.168.0.1 +ovs-vsctl add-port br-int vif1 -- set Interface vif1 external-ids:iface-id=lsp11 options:tx_pcap=hv1/vif1-tx.pcap options:rxq_pcap=hv1/vif1-rx.pcap ofport-request=1 + +# Create hypervisor hv2 connected to n1 +sim_add hv2 +as hv2 +ovs-vsctl add-br br-phys +ovn_attach n1 br-phys 192.168.0.2 +ovs-vsctl add-port br-int vif2 -- set Interface vif2 external-ids:iface-id=lsp21 options:tx_pcap=hv2/vif2-tx.pcap options:rxq_pcap=hv2/vif2-rx.pcap ofport-request=1 + +# Create hypervisor hv3 connected to n1 +sim_add hv3 +as hv3 +ovs-vsctl add-br br-phys +ovn_attach n1 br-phys 192.168.0.3 +ovs-vsctl add-port br-int vif3 -- set Interface vif3 external-ids:iface-id=lsp22 options:tx_pcap=hv3/vif3-tx.pcap options:rxq_pcap=hv3/vif3-rx.pcap ofport-request=1 + +# Add a forwarding group on ls2 with lsp21 and lsp22 as child ports +# virtual IP - 172.16.1.11, virtual MAC - 00:11:de:ad:be:ef +ovn-nbctl fwd-group-add fwd_grp1 ls2 172.16.1.11 00:11:de:ad:be:ef lsp21 lsp22 + +# Allow some time for ovn-northd and ovn-controller to catch up. +sleep 1 + +# Check logical flow +AT_CHECK([ovn-sbctl dump-flows | grep ls_in_l2_lkup | grep fwd_group | wc -l], [0], [dnl +1 +]) + +# Check openflow rule with "group" on hypervisor +AT_CHECK([as hv1 ovs-ofctl dump-flows br-int | \ + grep "dl_dst=00:11:de:ad:be:ef actions=group" | wc -l], [0], [dnl +1 +]) + +# Verify openflow group members +for child_port in lsp21 lsp22; do + tunnel_key=`ovn-sbctl --bare --column tunnel_key find port_binding logical_port=$child_port` + AT_CHECK([as hv1 ovs-ofctl -O OpenFlow13 dump-groups br-int | \ + grep "bucket=actions=load:0x"$tunnel_key | wc -l], [0], [dnl +1 +]) +done + +# Send a packet to virtual IP +src_mac=00:00:00:01:02:01 +dst_mac=00:00:00:01:02:f1 +src_ip=192.168.1.2 +dst_ip=172.16.1.11 +packet="inport==\"lsp11\" && eth.src==$src_mac && eth.dst==$dst_mac && + ip4 && ip.ttl==64 && ip4.src==$src_ip && ip4.dst==$dst_ip && + udp && udp.src==53 && udp.dst==4369" +as hv1 ovs-appctl -t ovn-controller inject-pkt "$packet" + +# Check if the packet hit the forwarding group policy +AT_CHECK([as hv1 ovs-ofctl dump-flows br-int | \ + grep "dl_dst=00:11:de:ad:be:ef actions=group" | \ + grep "n_packets=1" | wc -l], [0], [dnl +1 +]) + +# Delete the forwarding group +ovn-nbctl fwd-group-del fwd_grp1 + +# Add a forwarding group with liveness on ls2 with lsp21 and lsp22 as child +# ports virtual IP - 172.16.1.11, virtual MAC - 00:11:de:ad:be:ef +ovn-nbctl --liveness fwd-group-add fwd_grp1 ls2 172.16.1.11 00:11:de:ad:be:ef lsp21 lsp22 + +# Allow some time for ovn-northd and ovn-controller to catch up. +sleep 1 + +# Verify openflow group members +ofport_lsp21=$(as hv1 ovs-vsctl --bare --columns ofport find Interface name=ovn-hv2-0) +tunnel_key=`ovn-sbctl --bare --column tunnel_key find port_binding logical_port=lsp21` +AT_CHECK([as hv1 ovs-ofctl -O OpenFlow13 dump-groups br-int | \ + grep "bucket=watch_port:$ofport_lsp21,actions=load:0x"$tunnel_key | wc -l], [0], [dnl +1 +]) + +ofport_lsp22=$(as hv1 ovs-vsctl --bare --columns ofport find Interface name=ovn-hv3-0) +tunnel_key=`ovn-sbctl --bare --column tunnel_key find port_binding logical_port=lsp22` +AT_CHECK([as hv1 ovs-ofctl -O OpenFlow13 dump-groups br-int | \ + grep "bucket=watch_port:$ofport_lsp22,actions=load:0x"$tunnel_key | wc -l], [0], [dnl +1 +]) + +OVN_CLEANUP([hv1], [hv2], [hv3]) +AT_CLEANUP