From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 49410A045E for ; Fri, 31 May 2019 05:38:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 93EEC1B96E; Fri, 31 May 2019 05:38:41 +0200 (CEST) Received: from tama50.ecl.ntt.co.jp (tama50.ecl.ntt.co.jp [129.60.39.147]) by dpdk.org (Postfix) with ESMTP id 8B51A1B94A for ; Fri, 31 May 2019 05:38:39 +0200 (CEST) Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x4V3ccTE023656; Fri, 31 May 2019 12:38:38 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 586296395DA; Fri, 31 May 2019 12:38:38 +0900 (JST) Received: from localhost.localdomain (lobster.nslab.ecl.ntt.co.jp [129.60.13.95]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 50E5C6395E4; Fri, 31 May 2019 12:38:38 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Date: Fri, 31 May 2019 12:36:02 +0900 Message-Id: <1559273765-26130-9-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559273765-26130-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> References: <1559273765-26130-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [spp] [PATCH 08/11] shared/sec: refactor func for updating cls table X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: spp-bounces@dpdk.org Sender: "spp" From: Yasufumi Ogawa This update is to rename file local `spp_update_classifier_table()` to `update_cls_table()` to be simple, and revise var names, comments and log messages for refactoring. Signed-off-by: Yasufumi Ogawa --- .../secondary/spp_worker_th/cmd_runner.c | 71 +++++++++---------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c index 420e19c..f7476c4 100644 --- a/src/shared/secondary/spp_worker_th/cmd_runner.c +++ b/src/shared/secondary/spp_worker_th/cmd_runner.c @@ -122,85 +122,82 @@ is_port_flushed(enum port_type iface_type, int iface_no) /* Update classifier table with given action, add or del. */ static int -spp_update_classifier_table( - enum sppwk_action wk_action, +update_cls_table(enum sppwk_action wk_action, enum spp_classifier_type type __attribute__ ((unused)), - int vid, - const char *mac_addr_str, + int vid, const char *mac_str, const struct sppwk_port_idx *port) { - struct sppwk_port_info *port_info = NULL; - int64_t ret_mac = 0; - uint64_t mac_addr = 0; + /** + * Use two types of mac addr in int64_t and uint64_t because first + * one is checked if converted value from string is negative for error. + * If it is invalid, convert it to uint64_t. + */ + int64_t mac_int64; + uint64_t mac_uint64; + struct sppwk_port_info *port_info; - RTE_LOG(DEBUG, APP, "update_classifier_table " - "( type = mac, mac addr = %s, port = %d:%d )\n", - mac_addr_str, port->iface_type, port->iface_no); + RTE_LOG(DEBUG, APP, "Called update_cls_table with " + "type `mac`, mac_addr `%s`, and port `%d:%d`.\n", + mac_str, port->iface_type, port->iface_no); - ret_mac = sppwk_convert_mac_str_to_int64(mac_addr_str); - if (unlikely(ret_mac == -1)) { - RTE_LOG(ERR, APP, "MAC address format error. ( mac = %s )\n", - mac_addr_str); + mac_int64 = sppwk_convert_mac_str_to_int64(mac_str); + if (unlikely(mac_int64 == -1)) { + RTE_LOG(ERR, APP, "Invalid MAC address `%s`.\n", mac_str); return SPP_RET_NG; } - mac_addr = (uint64_t)ret_mac; + mac_uint64 = (uint64_t)mac_int64; port_info = get_sppwk_port(port->iface_type, port->iface_no); if (unlikely(port_info == NULL)) { - RTE_LOG(ERR, APP, "No port. ( port = %d:%d )\n", + RTE_LOG(ERR, APP, "Failed to get port %d:%d.\n", port->iface_type, port->iface_no); return SPP_RET_NG; } if (unlikely(port_info->iface_type == UNDEF)) { - RTE_LOG(ERR, APP, "Port not added. ( port = %d:%d )\n", + RTE_LOG(ERR, APP, "Port %d:%d doesn't exist.\n", port->iface_type, port->iface_no); return SPP_RET_NG; } if (wk_action == SPPWK_ACT_DEL) { - /* Delete */ if ((port_info->cls_attrs.vlantag.vid != 0) && - unlikely(port_info->cls_attrs.vlantag.vid != - vid)) { - RTE_LOG(ERR, APP, "VLAN ID is different. " - "( vid = %d )\n", vid); + port_info->cls_attrs.vlantag.vid != vid) { + RTE_LOG(ERR, APP, "Unexpected VLAN ID `%d`.\n", vid); return SPP_RET_NG; } if ((port_info->cls_attrs.mac_addr != 0) && - unlikely(port_info->cls_attrs.mac_addr != - mac_addr)) { - RTE_LOG(ERR, APP, "MAC address is different. " - "( mac = %s )\n", mac_addr_str); + port_info->cls_attrs.mac_addr != mac_uint64) { + RTE_LOG(ERR, APP, "Unexpected MAC %s.\n", mac_str); return SPP_RET_NG; } + /* Initialize deleted attributes again. */ port_info->cls_attrs.vlantag.vid = ETH_VLAN_ID_MAX; - port_info->cls_attrs.mac_addr = 0; + port_info->cls_attrs.mac_addr = 0; memset(port_info->cls_attrs.mac_addr_str, 0x00, SPP_MIN_STR_LEN); - } else if (wk_action == SPPWK_ACT_ADD) { - /* Setting */ if (unlikely(port_info->cls_attrs.vlantag.vid != ETH_VLAN_ID_MAX)) { - RTE_LOG(ERR, APP, "Port in used. " - "( port = %d:%d, vlan = %d != %d )\n", + /* TODO(yasufum) why two vids are required in msg ? */ + RTE_LOG(ERR, APP, "Used port %d:%d, vid %d != %d.\n", port->iface_type, port->iface_no, port_info->cls_attrs.vlantag.vid, vid); return SPP_RET_NG; } if (unlikely(port_info->cls_attrs.mac_addr != 0)) { - RTE_LOG(ERR, APP, "Port in used. " - "( port = %d:%d, mac = %s != %s )\n", + /* TODO(yasufum) why two macs are required in msg ? */ + RTE_LOG(ERR, APP, "Used port %d:%d, mac %s != %s.\n", port->iface_type, port->iface_no, port_info->cls_attrs.mac_addr_str, - mac_addr_str); + mac_str); return SPP_RET_NG; } + /* Update attrs with validated params. */ port_info->cls_attrs.vlantag.vid = vid; - port_info->cls_attrs.mac_addr = mac_addr; - strcpy(port_info->cls_attrs.mac_addr_str, mac_addr_str); + port_info->cls_attrs.mac_addr = mac_uint64; + strcpy(port_info->cls_attrs.mac_addr_str, mac_str); } set_component_change_port(port_info, SPP_PORT_RXTX_TX); @@ -733,7 +730,7 @@ execute_command(const struct spp_command *command) case SPPWK_CMDTYPE_CLS_VLAN: RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute classifier_table command.\n"); - ret = spp_update_classifier_table( + ret = update_cls_table( command->spec.cls_table.wk_action, command->spec.cls_table.type, command->spec.cls_table.vid, -- 2.17.1