From: Yasufumi Ogawa <yasufum.o@gmail.com> As more virtual network interfaces, such as memif or af_xdp, which have good performance are supported in DPDK, or considering container usecase, it has got been common usecases using several DPDK apps on the same host. It means that using `--file-prefix` is more general than before. This series of patches is to add file prefix in startup scripts. It also make a change to `launch` command in SPP CLI to launch secondary processes with the option. SPP CLI expects that the option is defined as an environmental `SPP_FILE_PREFIX`. Yasufumi Ogawa (6): cli: add env command cli: add file prefix opt for launch cmd bin: add SPP_FILE_PREFIX env variable readme: update example of config.sh docs: add desc for env command docs: add file prefix option in usecases README.md | 17 ++++-- bin/sample/config.sh | 4 +- bin/spp_pri.sh | 7 ++- bin/start.sh | 6 ++- docs/guides/commands/common.rst | 17 ++++++ docs/guides/gsg/howto_use.rst | 84 ++++++++++++++++++++--------- docs/guides/usecases/spp_mirror.rst | 5 ++ docs/guides/usecases/spp_pcap.rst | 5 ++ docs/guides/usecases/spp_vf.rst | 5 ++ src/cli/commands/help_msg.py | 10 ++++ src/cli/commands/pri.py | 21 ++++++-- src/cli/shell.py | 11 ++++ 12 files changed, 154 insertions(+), 38 deletions(-) -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> Add `env` command for displaying environmental variables. It displays env variables starts with given keyword, or all variables if it is not given. It is mainly used for finding variables related to SPP. # show variables starts with `SPP` spp > env SPP SPP_CTL_IP: 127.0.0.1 SPP_FILE_PREFIX: spp Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- src/cli/commands/help_msg.py | 10 ++++++++++ src/cli/shell.py | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/cli/commands/help_msg.py b/src/cli/commands/help_msg.py index f303547..4cf2a1f 100644 --- a/src/cli/commands/help_msg.py +++ b/src/cli/commands/help_msg.py @@ -8,6 +8,16 @@ cmds = { spp > status """, + 'env': + """Show environmental variables. + + # show all env varibles. + spp > env + + # show env varibles starts with `SPP`. + spp > env SPP + """, + 'record': """Save commands as a recipe file. diff --git a/src/cli/shell.py b/src/cli/shell.py index 0de6176..cfc343c 100644 --- a/src/cli/shell.py +++ b/src/cli/shell.py @@ -317,6 +317,17 @@ class Shell(cmd.Cmd, object): """Print help message of status command.""" print(help_msg.cmds['status']) + def do_env(self, key): + """Display environmental variables.""" + + for k, v in sorted(os.environ.items()): + if k.startswith(key): + print("{}: {}".format(k, v)) + + def help_env(self): + """Print help message of env command.""" + print(help_msg.cmds['env']) + def do_pri(self, command): """Send a command to primary process.""" -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> `--file-prefix` is an EAL option for running several DPDK applications by naming shared data file other than default one. However, it should be the same name among processes if it is implemented as a multi-process app. This update is to add `--file-prefix` in completed launch command. SPP CLI expects that the prefix is defined as an environment variable `SPP_FILE_PREFIX`. It completes `--file-prefix` with the variable, or does not complete this option itself if the variable is not defined. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- src/cli/commands/pri.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cli/commands/pri.py b/src/cli/commands/pri.py index bee0d81..9212897 100644 --- a/src/cli/commands/pri.py +++ b/src/cli/commands/pri.py @@ -4,6 +4,7 @@ from .. import spp_common from ..shell_lib import common from ..spp_common import logger +import os import time @@ -21,6 +22,8 @@ class SppPrimary(object): PRI_CMDS = ['status', 'add', 'del', 'forward', 'stop', 'patch', 'launch', 'clear'] + ENV_FILE_PREF = 'SPP_FILE_PREFIX' + def __init__(self, spp_ctl_cli): self.spp_ctl_cli = spp_ctl_cli @@ -29,9 +32,14 @@ class SppPrimary(object): # Default args for `pri; launch`, used if given cli_config is invalid + # used for secondary's --file-prefix option if defined + file_prefix = os.getenv(self.ENV_FILE_PREF) + # Setup template of args for `pri; launch` temp = "-l {m_lcore},{s_lcores} " temp = temp + "{mem} " + if file_prefix: + temp = temp + "--file-prefix {} ".format(file_prefix) temp = temp + "-- " temp = temp + "{opt_sid} {sid} " # '-n 1' or '--client-id 1' temp = temp + "-s {sec_addr} " # '-s 192.168.1.100:6666' @@ -166,7 +174,7 @@ class SppPrimary(object): print(' - slave: {}'.format(json_obj['lcores'][1])) else: lcores = ', '.join([str(i) - for i in json_obj['lcores'][1:]]) + for i in json_obj['lcores'][1:]]) print(' - slaves: [{}]'.format(lcores)) sep = ' ' @@ -197,8 +205,10 @@ class SppPrimary(object): temp = '{s6}{portid:2} {rx:10} {tx:10} {tx_d:10} {eth}' for pports in json_obj['phy_ports']: print(temp.format(s6=sep*6, - portid=pports['id'], rx=pports['rx'], tx=pports['tx'], - tx_d=pports['tx_drop'], eth=pports['eth'])) + portid=pports['id'], rx=pports['rx'], + tx=pports['tx'], + tx_d=pports['tx_drop'], + eth=pports['eth'])) if 'ring_ports' in json_obj: print(' - ring ports:') @@ -207,7 +217,7 @@ class SppPrimary(object): temp = '{s6}{rid:2} {rx:10} {tx:10} {rx_d:10} {tx_d:10}' for rports in json_obj['ring_ports']: print(temp.format(s6=sep*6, - rid=rports['id'], rx=rports['rx'], tx=rports['tx'], + rid=rports['id'], rx=rports['rx'], tx=rports['tx'], rx_d=rports['rx_drop'], tx_d=rports['tx_drop'])) except KeyError as e: @@ -461,7 +471,8 @@ class SppPrimary(object): if has_invalid_param is False: candidates = [self.launch_template.format( m_lcore=master_lcore, s_lcores=slave_lcores, - mem=sec_mem, opt_sid=opt_sid, sid=sid, + mem=sec_mem, + opt_sid=opt_sid, sid=sid, sec_addr=server_addr, vhost_cli=vhost_client)] else: -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> Add environmental variable SPP_FILE_PREFIX in startup scripts for launching all of SPP processes with the same file prefix. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- bin/sample/config.sh | 4 +++- bin/spp_pri.sh | 7 ++++++- bin/start.sh | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bin/sample/config.sh b/bin/sample/config.sh index 6dfd89d..e797956 100644 --- a/bin/sample/config.sh +++ b/bin/sample/config.sh @@ -1,7 +1,9 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2019 Nippon Telegraph and Telephone Corporation -SPP_HOST_IP=127.0.0.1 +SPP_CTL_IP=127.0.0.1 +SPP_FILE_PREFIX=spp # used for --file-prefix option + SPP_HUGEPAGES=/dev/hugepages # spp_primary options diff --git a/bin/spp_pri.sh b/bin/spp_pri.sh index f08a178..5e21572 100644 --- a/bin/spp_pri.sh +++ b/bin/spp_pri.sh @@ -55,6 +55,10 @@ function setup_vdevs() { function spp_pri() { SPP_PRI_BIN=${SPP_DIR}/src/primary/${RTE_TARGET}/spp_primary + if [ ${SPP_FILE_PREFIX} ]; then + FILE_PREFIX_OPT="--file-prefix ${SPP_FILE_PREFIX}" + fi + cmd="sudo ${SPP_PRI_BIN} \ -l ${PRI_CORE_LIST} \ -n ${PRI_MEMCHAN} \ @@ -62,6 +66,7 @@ function spp_pri() { --huge-dir ${SPP_HUGEPAGES} \ --proc-type primary \ --base-virtaddr 0x100000000 \ + ${FILE_PREFIX_OPT} \ --log-level ${LOGLEVEL} \ ${SPP_PRI_VHOST} \ ${SPP_PRI_RING} \ @@ -70,7 +75,7 @@ function spp_pri() { -- \ -p ${PRI_PORTMASK} \ -n ${NUM_RINGS} \ - -s ${SPP_HOST_IP}:5555" + -s ${SPP_CTL_IP}:5555" if [ ${DRY_RUN} ]; then echo ${cmd} diff --git a/bin/start.sh b/bin/start.sh index 2f4e31a..ce3ce26 100755 --- a/bin/start.sh +++ b/bin/start.sh @@ -29,7 +29,7 @@ do done function start_spp_ctl() { - cmd="python3 ${SPP_DIR}/src/spp-ctl/spp-ctl -b ${SPP_HOST_IP}" + cmd="python3 ${SPP_DIR}/src/spp-ctl/spp-ctl -b ${SPP_CTL_IP}" if [ ${DRY_RUN} ]; then echo ${cmd} else @@ -65,5 +65,7 @@ start_spp_pri if [ ! ${DRY_RUN} ]; then sleep 1 # wait for spp-ctl is ready - python3 ${SPP_DIR}/src/spp.py -b ${SPP_HOST_IP} --wait-pri + SPP_CTL_IP=${SPP_CTL_IP} \ + SPP_FILE_PREFIX=${SPP_FILE_PREFIX} \ + python3 ${SPP_DIR}/src/spp.py -b ${SPP_CTL_IP} --wait-pri fi -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> As file prefix option is supprted in startup scripts, update example of params in config.sh. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e1085e0..51e89ee 100644 --- a/README.md +++ b/README.md @@ -145,17 +145,28 @@ If you do not have physical NICs on your server, activate physical. ```sh -SPP_HOST_IP=127.0.0.1 +SPP_CTL_IP=127.0.0.1 +SPP_FILE_PREFIX=spp # used for --file-prefix option + SPP_HUGEPAGES=/dev/hugepages # spp_primary options LOGLEVEL=7 # change to 8 if you refer debug messages. -PRI_CORE_LIST=0 # required one lcore usually. +PRI_CORE_LIST=0,1 # required one lcore usually. PRI_MEM=1024 PRI_MEMCHAN=4 # change for your memory channels. NUM_RINGS=8 PRI_PORTMASK=0x03 # total num of ports of spp_primary. -#PRI_VHOST_IDS=(11 12) # you use if you have no phy ports. + +# Vdevs of spp_primary +#PRI_VHOST_VDEVS=(11 12) # IDs of `eth_vhost` +#PRI_RING_VDEVS=(1 2) # IDs of `net_ring` +#PRI_TAP_VDEVS=(1 2) # IDs of `net_tap` +# You can give whole of vdev options here. +#PRI_VDEVS=( +#eth_vhost11,iface=/tmp/sock13,queues=1 +#eth_vhost12,iface=/tmp/sock14,queues=1 +#) ``` After you edit configuration, you can launch `spp-ctl`, -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> This update is to add description for env command in `Common Commands` section. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- docs/guides/commands/common.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/guides/commands/common.rst b/docs/guides/commands/common.rst index cfa4eaf..d3b8262 100644 --- a/docs/guides/commands/common.rst +++ b/docs/guides/commands/common.rst @@ -230,6 +230,23 @@ You cannot unregister node under the control, or switch to other one before. Cannot del server "1" in use! +.. _commands_common_env: + +env +--- + +Show environmental variables. It is mainly used to find variables related to +SPP. + +.. code-block:: console + + # show all env varibles. + spp > env + + # show env varibles starts with `SPP`. + spp > env SPP + + .. _commands_common_pwd: pwd -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> This update is to add examples of usage of `--file-prefix` option in `Use Cases` chapter. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- docs/guides/gsg/howto_use.rst | 84 ++++++++++++++++++++--------- docs/guides/usecases/spp_mirror.rst | 5 ++ docs/guides/usecases/spp_pcap.rst | 5 ++ docs/guides/usecases/spp_vf.rst | 5 ++ 4 files changed, 73 insertions(+), 26 deletions(-) diff --git a/docs/guides/gsg/howto_use.rst b/docs/guides/gsg/howto_use.rst index b0824d4..8520de5 100644 --- a/docs/guides/gsg/howto_use.rst +++ b/docs/guides/gsg/howto_use.rst @@ -15,6 +15,21 @@ You should keep in mind the order of launching processes if you do it manually, or you can use startup script. This start script is for launching ``spp-ctl``, ``spp_primary`` and SPP CLI. +Before starting, you should define environmental variable ``SPP_FILE_PREFIX`` +for using the same prefix among SPP processes. ``--file-prefix`` is an EAL +option for using a different shared data file prefix for a DPDK process. + +.. code-block:: console + + $ export SPP_FILE_PREFIX=spp + +This option is used for running several DPDK processes because it is not +allowed different processes to have the same name of share data file, although +each process of multi-process application should have the same prefix on the +contrary. +Even if you do not run several DPDK applications, you do not need to define +actually. However, it is a good practice because SPP is used for connecting +DPDK applications in actual usecases. .. _spp_gsg_howto_quick_start: @@ -53,22 +68,30 @@ Confirm that the status is ``running``. Now you are ready to launch secondary processes from ``pri; launch`` command, or another terminal. Here is an example for launching ``spp_nfv`` -with options from ``pri; launch``. Log file of this process is created as -``log/spp_nfv1.log``. +with options from ``pri; launch``. +Log file of this process is created as ``log/spp_nfv1.log``. .. code-block:: none - spp > pri; launch nfv 1 -l 1,2 -m 512 -- -n 1 -s 127.0.0.1:6666 + spp > pri; launch nfv 1 -l 1,2 -m 512 --file-prefix spp -- -n 1 -s ... This ``launch`` command supports TAB completion. Parameters for ``spp_nfv`` are completed after secondary ID ``1``. +You might notice ``--file-prefix spp`` which should be the same value among +primary and secondary processes. SPP CLI expects that this value can be +referred as environmental variable ``SPP_FILE_PREFIX``, and spp_primary is +launched with the same ``--file-prefix spp``. +If you run SPP from ``bin/start.sh``, you do no need to define the variable +by yourself because it is defined in ``bin/config.sh`` so that spp_primary is +launched with the prefix. + .. code-block:: none spp > pri; launch nfv 1 # Press TAB - spp > pri; launch nfv 1 -l 1,2 -m 512 -- -n 1 -s 127.0.0.1:6666 + spp > pri; launch nfv 1 -l 1,2 -m 512 --file-prefix spp -- -n 1 -s ... It is same as following options launching from terminal. @@ -78,6 +101,7 @@ It is same as following options launching from terminal. $ sudo ./src/nfv/x86_64-native-linuxapp-gcc/spp_nfv \ -l 1,2 -n 4 -m 512 \ --proc-type secondary \ + --file-prefix spp \ -- \ -n 1 \ -s 127.0.0.1:6666 @@ -100,8 +124,8 @@ If you just patch two DPDK applications on host, it is enough to use one .. code-block:: none - spp > pri; launch nfv 2 -l 1,3 -m 512 -- -n 2 -s 127.0.0.1:6666 - spp > pri; launch vf 3 -l 1,4,5,6 -m 512 -- -n 3 -s 127.0.0.1:6666 + spp > pri; launch nfv 2 -l 1,3 -m 512 --file-prefix spp -- -n 2 -s ... + spp > pri; launch vf 3 -l 1,4,5,6 -m 512 --file-prefix spp -- -n 3 -s ... ... If you launch processes by yourself, ``spp_primary`` must be launched @@ -339,6 +363,7 @@ To launch SPP primary, run ``spp_primary`` with specific options. --socket-mem 512,512 \ --huge-dir /dev/hugepages \ --proc-type primary \ + --file-prefix $SPP_FILE_PREFIX \ --base-virtaddr 0x100000000 -- \ -p 0x03 \ @@ -385,6 +410,7 @@ Here is an example for launching ``spp_primary`` with monitor thread. --socket-mem 512,512 \ --huge-dir /dev/hugepages \ --proc-type primary \ + --file-prefix $SPP_FILE_PREFIX \ --base-virtaddr 0x100000000 -- \ -p 0x03 \ @@ -409,6 +435,7 @@ secondary processes. --vdev eth_vhost1,iface=/tmp/sock1 # used as 1st phy port --vdev eth_vhost2,iface=/tmp/sock2 # used as 2nd phy port --proc-type=primary \ + --file-prefix $SPP_FILE_PREFIX \ --base-virtaddr 0x100000000 -- \ -p 0x03 \ @@ -455,6 +482,7 @@ as ``l2fwd``. $ sudo ./src/nfv/x86_64-native-linuxapp-gcc/spp_nfv \ -l 2-3 -n 4 \ --proc-type secondary \ + --file-prefix $SPP_FILE_PREFIX \ -- \ -n 1 \ -s 192.168.1.100:6666 @@ -487,12 +515,13 @@ spp_vf .. code-block:: console $ sudo ./src/vf/x86_64-native-linuxapp-gcc/spp_vf \ - -l 2-13 -n 4 \ - --proc-type secondary \ - -- \ - --client-id 1 \ - -s 192.168.1.100:6666 \ - --vhost-client + -l 2-13 -n 4 \ + --proc-type secondary \ + --file-prefix $SPP_FILE_PREFIX \ + -- \ + --client-id 1 \ + -s 192.168.1.100:6666 \ + --vhost-client EAL options are the same as primary process. Here is a list of application options of ``spp_vf``. @@ -511,12 +540,13 @@ and options are same as ``spp_vf``. .. code-block:: console $ sudo ./src/mirror/x86_64-native-linuxapp-gcc/spp_mirror \ - -l 2,3 -n 4 \ - --proc-type secondary \ - -- \ - --client-id 1 \ - -s 192.168.1.100:6666 \ - --vhost-client + -l 2,3 -n 4 \ + --proc-type secondary \ + --file-prefix $SPP_FILE_PREFIX \ + -- \ + --client-id 1 \ + -s 192.168.1.100:6666 \ + --vhost-client EAL options are the same as primary process. Here is a list of application options of ``spp_mirror``. @@ -537,14 +567,15 @@ SPP provides ``spp_pcap`` for capturing comparatively heavy traffic. .. code-block:: console $ sudo ./src/pcap/x86_64-native-linuxapp-gcc/spp_pcap \ - -l 2-5 -n 4 \ - --proc-type secondary \ - -- \ - --client-id 1 \ - -s 192.168.1.100:6666 \ - -c phy:0 \ - --out-dir /path/to/dir \ - --fsize 107374182 + -l 2-5 -n 4 \ + --proc-type secondary \ + --file-prefix $SPP_FILE_PREFIX \ + -- \ + --client-id 1 \ + -s 192.168.1.100:6666 \ + -c phy:0 \ + --out-dir /path/to/dir \ + --fsize 107374182 EAL options are the same as primary process. Here is a list of application options of ``spp_pcap``. @@ -758,6 +789,7 @@ launching DPDK processes. --huge-dir=/dev/hugepages \ --proc-type=primary \ --base-virtaddr 0x100000000 + --file-prefix $SPP_FILE_PREFIX \ -- \ -p 0x03 \ -n 6 \ diff --git a/docs/guides/usecases/spp_mirror.rst b/docs/guides/usecases/spp_mirror.rst index 3830820..4164a16 100644 --- a/docs/guides/usecases/spp_mirror.rst +++ b/docs/guides/usecases/spp_mirror.rst @@ -7,6 +7,11 @@ spp_mirror ========== +.. note:: + + ``--file-prefix`` option is not required in this section because there is + not DPDK application other than SPP. + Duplicate Packets ----------------- diff --git a/docs/guides/usecases/spp_pcap.rst b/docs/guides/usecases/spp_pcap.rst index 9149a43..543538d 100644 --- a/docs/guides/usecases/spp_pcap.rst +++ b/docs/guides/usecases/spp_pcap.rst @@ -7,6 +7,11 @@ spp_pcap ======== +.. note:: + + ``--file-prefix`` option is not required in this section because there is + not DPDK application other than SPP. + Packet Capture -------------- diff --git a/docs/guides/usecases/spp_vf.rst b/docs/guides/usecases/spp_vf.rst index f17c0dc..ee18439 100644 --- a/docs/guides/usecases/spp_vf.rst +++ b/docs/guides/usecases/spp_vf.rst @@ -10,6 +10,11 @@ spp_vf ``spp_vf`` is a secondary process for providing L2 classification as a simple pusedo SR-IOV features. +.. note:: + + ``--file-prefix`` option is not required in this section because there is + not DPDK application other than SPP. + .. _spp_usecases_vf_cls_icmp: Classify ICMP Packets -- 2.17.1