From patchwork Thu May 16 16:05:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1100649 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 454brp5NjJz9s6w for ; Fri, 17 May 2019 02:06:34 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A2B80C58; Thu, 16 May 2019 16:05:57 +0000 (UTC) X-Original-To: ovs-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 5FF61C3E for ; Thu, 16 May 2019 16:05:56 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 52B758AC for ; Thu, 16 May 2019 16:05:55 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id f8so2628738wrt.1 for ; Thu, 16 May 2019 09:05:55 -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:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a5YkLwJQuS1zMCaZkAe4Z4SxAf9BP/zl6RwBnI9cvqc=; b=Xiqs4fs12XOoZHFI9076HG7irVtHVhfIWNaEMCP+6oumCPWFQosZxJWt4cotGH1n2L GONicwxcLMG+cj40d3QtmMBYxsxqyRHMlI04tecHEW7CVRBYJnYXYC9vRTep7T/uNKeF U+5DNNaso+7nE0z+Lvz3e2OmaMrL60nR5Bj2dXgfQ7jnEAvaxGb2Q92u/QnDIf8frN7K +yar1WkBo3x6MxR7Bl7e+9O4QaPC0A6lwGERyg+6yskev0x5NJLU6ova4sg+H8hTUUci 7uJ7/+fUnKAcFvME+E4354R8KYsa8QQAldIx3YUbEK2B/uE41tguWb4fKh1Ruw5YH5PQ o5NA== X-Gm-Message-State: APjAAAUQuL0gmLDFb2u8WEjYyrEdBYTtm/3m0+weX0BjycoVDypH0+dC ZquEK4bUpb4hEPu/nfuxHuJLT+gPQgQ= X-Google-Smtp-Source: APXvYqw4XpRwNw1Ja+FCcmp+XQxDudOGf7Kf3KQorL5jmOWhkjDvFaM7SKq0oRrTLHQn3NiGAN8L/A== X-Received: by 2002:adf:ebd2:: with SMTP id v18mr12239788wrn.108.1558022753655; Thu, 16 May 2019 09:05:53 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id s10sm4751362wrt.66.2019.05.16.09.05.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 16 May 2019 09:05:49 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Thu, 16 May 2019 18:05:24 +0200 Message-Id: <0b49e766325c79cb22444bf26ba843bf101e8718.1558021382.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 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] [RFC 1/3] OVN: introduce Controller_Event table 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Add Controller_Event table to OVN SBDB in order to report CMS related event. Introduce event_table hashmap array and controller_event related structures to ovn-controller in order to track pending events forwarded by ovs-vswitchd. Moreover integrate event_table hashmap array with event_table ovn-sbdb table Signed-off-by: Mark Michelson Co-authored-by: Mark Michelson Signed-off-by: Lorenzo Bianconi --- include/ovn/logical-fields.h | 17 +++++ ovn/controller/ovn-controller.c | 2 + ovn/controller/pinctrl.c | 130 ++++++++++++++++++++++++++++++++ ovn/controller/pinctrl.h | 2 + ovn/ovn-sb.ovsschema | 16 +++- ovn/ovn-sb.xml | 33 ++++++++ 6 files changed, 197 insertions(+), 3 deletions(-) diff --git a/include/ovn/logical-fields.h b/include/ovn/logical-fields.h index 164b338b5..431ad03d0 100644 --- a/include/ovn/logical-fields.h +++ b/include/ovn/logical-fields.h @@ -20,6 +20,23 @@ struct shash; +enum ovn_controller_event { + OVN_EVENT_EMPTY_LB_BACKENDS = 0, + OVN_EVENT_MAX, +}; + +static inline char * +event_to_string(enum ovn_controller_event event) +{ + switch (event) { + case OVN_EVENT_EMPTY_LB_BACKENDS: + return "empty_lb_backends"; + case OVN_EVENT_MAX: + default: + return ""; + } +} + /* Logical fields. * * These values are documented in ovn-architecture(7), please update the diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c index 69eeee5dc..d6494590b 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -765,6 +765,8 @@ main(int argc, char *argv[]) sbrec_port_binding_by_name, sbrec_mac_binding_by_lport_ip, sbrec_dns_table_get(ovnsb_idl_loop.idl), + sbrec_controller_event_table_get( + ovnsb_idl_loop.idl), br_int, chassis, &local_datapaths, &active_tunnels); update_ct_zones(&local_lports, &local_datapaths, &ct_zones, diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c index 8ae1f9bd6..ca191d961 100644 --- a/ovn/controller/pinctrl.c +++ b/ovn/controller/pinctrl.c @@ -223,6 +223,132 @@ static bool may_inject_pkts(void); COVERAGE_DEFINE(pinctrl_drop_put_mac_binding); COVERAGE_DEFINE(pinctrl_drop_buffered_packets_map); +COVERAGE_DEFINE(pinctrl_drop_controller_event); + +struct empty_lb_backends_event { + struct hmap_node hmap_node; + char *vip; + char *protocol; + char *load_balancer; +}; + +static struct hmap event_table[OVN_EVENT_MAX]; + +static void init_event_table(void) +{ + for (size_t i = 0; i < OVN_EVENT_MAX; i++) { + hmap_init(&event_table[i]); + } +} + +static void +empty_lb_backends_event_flush(void) +{ + struct empty_lb_backends_event *ce; + HMAP_FOR_EACH_POP (ce, hmap_node, + &event_table[OVN_EVENT_EMPTY_LB_BACKENDS]) { + free(ce->vip); + free(ce->protocol); + free(ce->load_balancer); + free(ce); + } +} + +static void event_table_flush(void) +{ + empty_lb_backends_event_flush(); +} + +static void event_table_destroy(void) +{ + event_table_flush(); + for (size_t i = 0; i < OVN_EVENT_MAX; i++) { + hmap_destroy(&event_table[i]); + } +} + +static struct empty_lb_backends_event * +pinctrl_find_empty_lb_backends_event(char *vip, char *protocol, + char *load_balancer, uint32_t hash) +{ + struct empty_lb_backends_event *ce; + HMAP_FOR_EACH_WITH_HASH (ce, hmap_node, hash, + &event_table[OVN_EVENT_EMPTY_LB_BACKENDS]) { + if (!strcmp(ce->vip, vip) && + !strcmp(ce->protocol, protocol) && + !strcmp(ce->load_balancer, load_balancer)) { + return ce; + } + } + return NULL; +} + +static const struct sbrec_controller_event * +empty_lb_backends_lookup(struct empty_lb_backends_event *event, + const struct sbrec_controller_event_table *ce_table) +{ + const struct sbrec_controller_event *sbrec_event; + const char *event_type = event_to_string(OVN_EVENT_EMPTY_LB_BACKENDS); + SBREC_CONTROLLER_EVENT_TABLE_FOR_EACH (sbrec_event, ce_table) { + if (strcmp(sbrec_event->event_type, event_type)) { + continue; + } + + const char *vip = smap_get(&sbrec_event->event_info, "vip"); + const char *protocol = smap_get(&sbrec_event->event_info, "protocol"); + const char *load_balancer = smap_get(&sbrec_event->event_info, + "load_balancer"); + + if (!strcmp(event->vip, vip) && + !strcmp(event->protocol, protocol) && + !strcmp(event->load_balancer, load_balancer)) { + return sbrec_event; + } + } + + return NULL; +} + +static void +controller_event_run(struct ovsdb_idl_txn *ovnsb_idl_txn, + const struct sbrec_controller_event_table *ce_table) + OVS_REQUIRES(pinctrl_mutex) +{ + if (!ovnsb_idl_txn) { + return; + } + + struct empty_lb_backends_event *empty_lbs; + HMAP_FOR_EACH (empty_lbs, hmap_node, + &event_table[OVN_EVENT_EMPTY_LB_BACKENDS]) { + const struct sbrec_controller_event *event; + + event = empty_lb_backends_lookup(empty_lbs, ce_table); + if (!event) { + struct smap event_info = SMAP_INITIALIZER(&event_info); + + smap_add(&event_info, "vip", empty_lbs->vip); + smap_add(&event_info, "protocol", empty_lbs->protocol); + smap_add(&event_info, "load_balancer", empty_lbs->load_balancer); + + event = sbrec_controller_event_insert(ovnsb_idl_txn); + sbrec_controller_event_set_event_type(event, + event_to_string(OVN_EVENT_EMPTY_LB_BACKENDS)); + sbrec_controller_event_set_event_info(event, &event_info); + sbrec_controller_event_set_handled(event, false); + } + } + event_table_flush(); + + const struct sbrec_controller_event *cur_event, *next_event; + /* flush 'handled' rows */ + SBREC_CONTROLLER_EVENT_TABLE_FOR_EACH_SAFE (cur_event, next_event, + ce_table) { + if (cur_event->handled) { + sbrec_controller_event_delete(cur_event); + } + } +} void pinctrl_init(void) @@ -231,6 +357,7 @@ pinctrl_init(void) init_send_garps(); init_ipv6_ras(); init_buffered_packets_map(); + init_event_table(); pinctrl.br_int_name = NULL; pinctrl_handler_seq = seq_create(); pinctrl_main_seq = seq_create(); @@ -1891,6 +2018,7 @@ pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_port_binding_by_name, struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, const struct sbrec_dns_table *dns_table, + const struct sbrec_controller_event_table *ce_table, const struct ovsrec_bridge *br_int, const struct sbrec_chassis *chassis, const struct hmap *local_datapaths, @@ -1916,6 +2044,7 @@ pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, prepare_ipv6_ras(sbrec_port_binding_by_datapath, sbrec_port_binding_by_name, local_datapaths); sync_dns_cache(dns_table); + controller_event_run(ovnsb_idl_txn, ce_table); run_buffered_binding(sbrec_port_binding_by_datapath, sbrec_mac_binding_by_lport_ip, local_datapaths); @@ -2264,6 +2393,7 @@ pinctrl_destroy(void) destroy_send_garps(); destroy_ipv6_ras(); destroy_buffered_packets_map(); + event_table_destroy(); destroy_put_mac_bindings(); destroy_dns_cache(); seq_destroy(pinctrl_main_seq); diff --git a/ovn/controller/pinctrl.h b/ovn/controller/pinctrl.h index f61d7056e..fdef27a6d 100644 --- a/ovn/controller/pinctrl.h +++ b/ovn/controller/pinctrl.h @@ -29,6 +29,7 @@ struct ovsdb_idl_txn; struct ovsrec_bridge; struct sbrec_chassis; struct sbrec_dns_table; +struct sbrec_controller_event_table; void pinctrl_init(void); void pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, @@ -38,6 +39,7 @@ void pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_port_binding_by_name, struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, const struct sbrec_dns_table *, + const struct sbrec_controller_event_table *, const struct ovsrec_bridge *, const struct sbrec_chassis *, const struct hmap *local_datapaths, const struct sset *active_tunnels); diff --git a/ovn/ovn-sb.ovsschema b/ovn/ovn-sb.ovsschema index 2b543c6f5..2a481b625 100644 --- a/ovn/ovn-sb.ovsschema +++ b/ovn/ovn-sb.ovsschema @@ -1,7 +1,7 @@ { "name": "OVN_Southbound", - "version": "2.3.0", - "cksum": "3092285199 17409", + "version": "2.4.0", + "cksum": "674838740 17844", "tables": { "SB_Global": { "columns": { @@ -349,4 +349,14 @@ "type": {"key": "string", "value": "string", "min": 0, "max": "unlimited"}}}, "indexes": [["name"]], - "isRoot": true}}} + "isRoot": true}, + "Controller_Event": { + "columns": { + "event_type": {"type": {"key": {"type": "string", + "enum": ["set", ["empty_lb_backends"]]}}}, + "event_info": {"type": {"key": "string", "value": "string", + "min": 0, "max": "unlimited"}}, + "handled": {"type": "boolean"} + }, + "isRoot": true + }}} diff --git a/ovn/ovn-sb.xml b/ovn/ovn-sb.xml index 1a2bc1da9..ae5225e18 100644 --- a/ovn/ovn-sb.xml +++ b/ovn/ovn-sb.xml @@ -3474,4 +3474,37 @@ tcp.flags = RST; + +

+ Database table used by ovn-controller to report CMS related + events +

+ + Event type occurred + + +

+ Key-value pairs used to spcify evento info to the CMS. + Possible values are: +

+
    +
  • + vip: VIP reported for the empty_lb_backends + event +
  • +
  • + protocol: Transport protocol reported for the + empty_lb_backends event +
  • +
  • + load_balancer: UUID fo the load balancer reported for + the empty_lb_backends event +
  • +
+
+ + Value used to indicate if the event has been consumed by the CMS + +