From patchwork Fri Apr 28 09:01:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 756273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wDnsP5LBrz9s89 for ; Fri, 28 Apr 2017 19:03:05 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 366BDB80; Fri, 28 Apr 2017 09:01:45 +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 3E9A7B5F for ; Fri, 28 Apr 2017 09:01:41 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B271A18D for ; Fri, 28 Apr 2017 09:01:40 +0000 (UTC) Received: by mail-pg0-f65.google.com with SMTP id v20so1938101pgn.0 for ; Fri, 28 Apr 2017 02:01:40 -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:content-transfer-encoding; bh=qQ04eMHOpSGDIx5nyyfCZOojP+4Sfk42BE2WMeEtUlA=; b=mEBiCr5+RXbgzu0J1CCo+v7NgLEiDp7eaK2ieu3CNUIDEydAiGv6RHIMkNVaBxXAR5 nermc/tQkbIwHQADUct9HReFxou+Fjy6Y1tjgqDTe4b1IYp2L8JeuyXUbrkbxZCW0iDL psAI86xyKkK3nj/PT1Hr0PpI9kt/8tQibkjJu684pUBkfJWkdvglGBvNK9jA+qU01/zo 14y/W723BTquurqmlrLS9F2zhWv92cHYo6/1fQ5QmHrOfvw6p9FRjaI6Q/8Jsxwyw9YK xKXW70yyuI+58gVtamO3FcBvl9AraFtr4sKQ96s5r8/h8Id/KWltfs4yjpapghFvSH/8 L0sw== X-Gm-Message-State: AN3rC/5uP3gwV1tMEYuD9BgVlnCvojPubFus1SvJp/eaFSYa4rnESBVO x4/NiwTg8B1BBIfZ X-Received: by 10.84.128.99 with SMTP id 90mr13470731pla.166.1493370100199; Fri, 28 Apr 2017 02:01:40 -0700 (PDT) Received: from centos.hsd1.ca.comcast.net. ([2601:647:4280:45d0:d6be:d9ff:fe69:1f8d]) by smtp.gmail.com with ESMTPSA id s68sm9307944pfj.77.2017.04.28.02.01.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Apr 2017 02:01:39 -0700 (PDT) From: Andy Zhou To: dev@openvswitch.org Date: Fri, 28 Apr 2017 02:01:21 -0700 Message-Id: <1493370083-7385-3-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1493370083-7385-1-git-send-email-azhou@ovn.org> References: <1493370083-7385-1-git-send-email-azhou@ovn.org> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [action upcall meter v2 3/5] ofproto: Support action upcall meters 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 Allow action upcall meters, i.e. slowpath and controller meters, to be added and displayed. Keep track of datapath meter ID of those action upcall meters in ofproto to aid action translation. Later patches will make use of them. Signed-off-by: Andy Zhou Acked-by: Jarno Rajahalme --- v1->v2: change "ALL" to "all" --- lib/ofp-print.c | 33 +++++++++++++++++++++++++++--- ofproto/ofproto-provider.h | 4 ++++ ofproto/ofproto.c | 50 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/lib/ofp-print.c b/lib/ofp-print.c index a8cdfcbf20b1..10ac053ae54b 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -1333,11 +1333,36 @@ ofp_print_meter_band(struct ds *s, uint16_t flags, } static void +ofp_print_meter_id(struct ds *s, uint32_t meter_id, char seperator) +{ + if (meter_id <= OFPM13_MAX) { + ds_put_format(s, "meter%c%"PRIu32, seperator, meter_id); + } else { + const char *name; + switch (meter_id) { + case OFPM13_SLOWPATH: + name = "slowpath"; + break; + case OFPM13_CONTROLLER: + name = "controller"; + break; + case OFPM13_ALL: + name = "all"; + break; + default: + name = "unknown"; + } + ds_put_format(s, "meter%c%s", seperator, name); + } +} + +static void ofp_print_meter_stats(struct ds *s, const struct ofputil_meter_stats *ms) { uint16_t i; - ds_put_format(s, "meter:%"PRIu32" ", ms->meter_id); + ofp_print_meter_id(s, ms->meter_id, ':'); + ds_put_char(s, ' '); ds_put_format(s, "flow_count:%"PRIu32" ", ms->flow_count); ds_put_format(s, "packet_in_count:%"PRIu64" ", ms->packet_in_count); ds_put_format(s, "byte_in_count:%"PRIu64" ", ms->byte_in_count); @@ -1358,7 +1383,8 @@ ofp_print_meter_config(struct ds *s, const struct ofputil_meter_config *mc) { uint16_t i; - ds_put_format(s, "meter=%"PRIu32" ", mc->meter_id); + ofp_print_meter_id(s, mc->meter_id, '='); + ds_put_char(s, ' '); ofp_print_meter_flags(s, mc->flags); @@ -1412,8 +1438,9 @@ ofp_print_meter_stats_request(struct ds *s, const struct ofp_header *oh) uint32_t meter_id; ofputil_decode_meter_request(oh, &meter_id); + ds_put_char(s, ' '); - ds_put_format(s, " meter=%"PRIu32, meter_id); + ofp_print_meter_id(s, meter_id, '='); } static const char * diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h index 000326d7f79d..688a9e5d32eb 100644 --- a/ofproto/ofproto-provider.h +++ b/ofproto/ofproto-provider.h @@ -112,6 +112,10 @@ struct ofproto { /* Meter table. */ struct ofputil_meter_features meter_features; struct hmap meters; /* uint32_t indexed 'struct meter *'. */ + uint32_t slowpath_meter_id; /* Datapath slowpath meter. UINT32_MAX + if not defined. */ + uint32_t controller_meter_id; /* Datapath controller meter. UINT32_MAX + if not defined. */ /* OpenFlow connections. */ struct connmgr *connmgr; diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 5397afa3163d..a7b62507aa3a 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -568,6 +568,8 @@ ofproto_create(const char *datapath_name, const char *datapath_type, memset(&ofproto->meter_features, 0, sizeof ofproto->meter_features); } hmap_init(&ofproto->meters); + ofproto->slowpath_meter_id = UINT32_MAX; + ofproto->controller_meter_id = UINT32_MAX; /* Set the initial tables version. */ ofproto_bump_tables_version(ofproto); @@ -6236,9 +6238,33 @@ ofproto_get_meter(const struct ofproto *ofproto, uint32_t meter_id) return NULL; } +static uint32_t * +ofproto_upcall_meter_ptr(struct ofproto *ofproto, uint32_t meter_id) +{ + switch(meter_id) { + case OFPM13_SLOWPATH: + return &ofproto->slowpath_meter_id; + break; + case OFPM13_CONTROLLER: + return &ofproto->controller_meter_id; + break; + case OFPM13_ALL: + OVS_NOT_REACHED(); + default: + return NULL; + } +} + static void ofproto_add_meter(struct ofproto *ofproto, struct meter *meter) { + uint32_t *upcall_meter_ptr = ofproto_upcall_meter_ptr(ofproto, meter->id); + + /* Cache datapath meter IDs of special meters. */ + if (upcall_meter_ptr) { + *upcall_meter_ptr = meter->provider_meter_id.uint32; + } + hmap_insert(&ofproto->meters, &meter->node, hash_int(meter->id, 0)); } @@ -6310,6 +6336,12 @@ static void meter_destroy(struct ofproto *ofproto, struct meter *meter) OVS_REQUIRES(ofproto_mutex) { + uint32_t *upcall_meter_ptr; + upcall_meter_ptr = ofproto_upcall_meter_ptr(ofproto, meter->id); + if (upcall_meter_ptr) { + *upcall_meter_ptr = UINT32_MAX; + } + if (!ovs_list_is_empty(&meter->rules)) { struct rule_collection rules; struct rule *rule; @@ -6442,12 +6474,24 @@ handle_meter_mod(struct ofconn *ofconn, const struct ofp_header *oh) if (mm.command != OFPMC13_DELETE) { /* Fails also when meters are not implemented by the provider. */ - if (meter_id == 0 || meter_id > OFPM13_MAX) { + if (ofproto->meter_features.max_meters == 0) { error = OFPERR_OFPMMFC_INVALID_METER; goto exit_free_bands; - } else if (meter_id > ofproto->meter_features.max_meters) { - error = OFPERR_OFPMMFC_OUT_OF_METERS; + } + + if (meter_id == 0) { + error = OFPERR_OFPMMFC_INVALID_METER; goto exit_free_bands; + } else if (meter_id > OFPM13_MAX) { + switch(meter_id) { + case OFPM13_SLOWPATH: + case OFPM13_CONTROLLER: + break; + case OFPM13_ALL: + default: + error = OFPERR_OFPMMFC_INVALID_METER; + goto exit_free_bands; + } } if (mm.meter.n_bands > ofproto->meter_features.max_bands) { error = OFPERR_OFPMMFC_OUT_OF_BANDS;