From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 35668A046B for ; Thu, 25 Jul 2019 13:26:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2D2731BF6B; Thu, 25 Jul 2019 13:26:23 +0200 (CEST) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by dpdk.org (Postfix) with ESMTP id 48C451BF6B for ; Thu, 25 Jul 2019 13:26:21 +0200 (CEST) Received: by mail-pf1-f173.google.com with SMTP id r7so22612266pfl.3 for ; Thu, 25 Jul 2019 04:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=/ntgpOrLeuXuVlMkh0/FOhrrIklmnSeNLOhL9I7rpoU=; b=UhcUdUPlxNxWRIKDn0QZGKdv1j+UmBJqjwAgsMu1JuzAMotRk5LzuYFsqqXQusZ8rF +0qiIekbCe+VzYmirLhAhwtsmqh5Xx3xMa12FoyAregLfQREosM9+R0ZtqANDH8DGezP CxcfuyxH71diF7C4jbWOWoVAXQD14dXnJcHkwqek+EL+eouLNubSi6rw+1XsWvxgjTNw a2MFWrKlPjJyierbFEITFyIQ6LJaxBK3SfJQ6qEAFbwt3MvnAw/YxNboPqMX4XajJEq0 NvNSMVXwLbvDuRjJJa5FMiwN4D67JnUQwqNkkNfc4IreEK5xBunEPxFnmxsl2GwwLwhe Q6jQ== 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; bh=/ntgpOrLeuXuVlMkh0/FOhrrIklmnSeNLOhL9I7rpoU=; b=enIglLaAloKMHsIuHXRysOCnpdZDhzZ5GPLKD26wkC6BFNCvnmnXKgB9WQ+oZJNUJ5 9gkMLJuWc9kaTeZ83WW/tPBpcHX5F/zot7heIfAslJtV9O0SEuPNAfPcyLum1U8CIcmV 1/oXpDXH497GNHYJQHxu4rZb770cbZWCvt+ZhIbhc1VCFV7+Hha0nYckuwSqK6VdxQtT RLdYMsR3We5MlOnfoEkWVoDvSaV7aeXH51Hf9y7qvC+Go125+67uUUuIltnQ+3XW2U+A PxYSOotCDmVEXt4XiUw2D+NVrYUDVng425Plo0Ayb0LpySJ5N+uU8mOJm8eXMz2SmgHF PirQ== X-Gm-Message-State: APjAAAUgkJNPSKN8QtIGx0SZijklNTTHaVXdXd3poX0ZlxKox2USIHLK erQKkAO/nc+GQrxyBacLGTe1mULl X-Google-Smtp-Source: APXvYqxCyxVqtxdrJSXawzjEJ0JgVjq5aW3f2rT2r+QRoTj73qwc5uxQLSxTKFCb1I5Z1j2PSMrExA== X-Received: by 2002:a63:89c2:: with SMTP id v185mr84874912pgd.241.1564053980349; Thu, 25 Jul 2019 04:26:20 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id m101sm39673822pjb.7.2019.07.25.04.26.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jul 2019 04:26:19 -0700 (PDT) From: yasufum.o@gmail.com To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Thu, 25 Jul 2019 20:26:12 +0900 Message-Id: <20190725112612.27492-1-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [spp] [PATCH] controller: avoid launch with duplicated IDs 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 If secondary processes are launched with the same ID, it should be uncontrollable. To avoid such a situation, this patch adds checking secondary ID for `pri; launch` command. Signed-off-by: Yasufumi Ogawa --- src/controller/commands/pri.py | 23 ++++++++++++++++++++--- src/controller/spp_common.py | 6 +++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/controller/commands/pri.py b/src/controller/commands/pri.py index eaf3d09..5ad0539 100644 --- a/src/controller/commands/pri.py +++ b/src/controller/commands/pri.py @@ -347,18 +347,27 @@ class SppPrimary(object): elif len(tokens) == 4 and tokens[1] == 'launch': if 'max_secondary' in cli_config.keys(): - max_secondary = int(cli_config['max_secondary']['val']) + max_secondary = int( + cli_config['max_secondary']['val']) if tokens[2] in spp_common.SEC_TYPES: + used_ids = spp_common.used_sec_ids candidates = [ - str(i+1) for i in range(max_secondary)] + str(i+1) for i in range(max_secondary) + if str(i+1) not in used_ids] else: logger.error( 'Error: max_secondary is not defined in config') candidates = [] elif len(tokens) == 5 and tokens[1] == 'launch': - candidates = self._setup_launch_opts(tokens, cli_config) + # Do not show candidate if given sec ID is already used. + # Sec ID is contained as the third entry in tokens. Here is an + # example of tokens. + # ['pri;', 'launch', 'nfv', '1', ''] + if tokens[3] not in spp_common.used_sec_ids: + candidates = self._setup_launch_opts( + tokens, cli_config) if not text: completions = candidates @@ -517,6 +526,12 @@ class SppPrimary(object): else: opts['app']['--client-id'] = sec_id + # Check if sec ID is already used. + if sec_id in spp_common.used_sec_ids: + print('Secondary ID {sid} is already used!'.format( + sid=sec_id)) + return None + logger.debug('launch, {}'.format(opts)) # Send request for launch secondary. @@ -529,6 +544,8 @@ class SppPrimary(object): print('Send request to launch {ptype}:{sid}.'.format( ptype=proc_type, sid=sec_id)) + # Add used ID to avoid to launch with duplicated ID. + spp_common.used_sec_ids.append(sec_id) elif res.status_code in error_codes: pass else: diff --git a/src/controller/spp_common.py b/src/controller/spp_common.py index 6bf8b1f..5ddca46 100644 --- a/src/controller/spp_common.py +++ b/src/controller/spp_common.py @@ -5,14 +5,18 @@ import logging import os +# Type definitions. PORT_TYPES = ['phy', 'ring', 'vhost', 'pcap', 'nullpmd'] - SEC_TYPES = ['nfv', 'vf', 'mirror', 'pcap'] LOGFILE = 'spp_cli.log' # name of logfile under `/src/controller/log/` +# Current server under management of SPP CLI. cur_server_addr = None +# Entry of used secondary IDs to avoid to launch duplicated ID. +used_sec_ids = [] + # Setup logger object logger = logging.getLogger(__name__) # handler = logging.StreamHandler() -- 2.17.1