[spp] [PATCH 3/8] spp-ctl: add launch command support for REST API

ogawa.yasufumi at lab.ntt.co.jp ogawa.yasufumi at lab.ntt.co.jp
Tue Jan 29 13:21:56 CET 2019


From: Yasufumi Ogawa <ogawa.yasufumi at lab.ntt.co.jp>

This update is to add REST API support of launch command for
spp_primary. This launch API of PUT accepts a name of secondary
process, secondary ID and all args of the application. Here is an
example.

  $ curl -X PUT -d '{"client_id":1,"proc_name":"spp_nfv","eal":...}' \
    http://127.0.0.1:7777/v1/primary/launch

This launch API supports only spp_nfv currently. Other secondaries can
be launched, but have no components and do not work correctly.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
---
 src/spp-ctl/spp_proc.py   | 113 ++++++++++++++++++++++++++++++++++++++++++++++
 src/spp-ctl/spp_webapi.py |  11 +++++
 2 files changed, 124 insertions(+)

diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index 19a5e53..a2d2adf 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -18,6 +18,76 @@ TYPE_NFV = "nfv"
 TYPE_MIRROR = "mirror"
 TYPE_PCAP = "pcap"
 
+EAL_OPTS = [
+        # Lcore-related options
+        '-c',  # core mask
+        '-l',  # core list
+        '--lcores',  # core map
+        '--master-lcore',  # is used as master
+        '-s',  # Hex bitmask of cores used as service cores
+        # Device-related options
+        '-b', '--pci-blacklist',  # Blacklist of PCI devs
+        '-w', '--pci-whitelist',  # Blacklist of PCI devs
+        '--vdev',  # Add a virtual device
+        '-d',  # Load external drivers
+        '--no-pci',  # Disable PCI bus.
+        # Multiprocessing-related options
+        '--proc-type',  # primamry, secondary or auto
+        # Memory-related options
+        '-n',  # number of memory channels
+        '-r',  # number of memory ranks
+        '-m',  # Amount of memory to preallocate at startup
+        '--in-memory',  # not create shared data and run entirely in memory
+        '--iova-mode',  # Force IOVA mode to a specific value
+        # Debugging options
+        '--no-shconf',  # No shared files created (no sec)
+        '--no-huge',  # Use anonymous memory instead of hugepages (no sec)
+        '--log-level',   # Specify log level, e.g. '--log-level eal:8'
+        '--file-prefix',  # Use different shared file prefix for a DPDK process
+        # Linux-specific EAL parameters
+        '--create-uio-dev',  # Create /dev/uioX bound to igb_uio
+        '--vmware-tsc-map',  # Use VMware TSC map instead of native RDTSC
+        '--no-hpet',  # Do not use the HPET timer
+        '--vfio-intr',  # Use specified interrupt mode for devs bound to VFIO
+        '--base-virtaddr',  # use different addr for all memmaps of primary
+        '--legacy-mem',  # Use legacy DPDK memory allocation mode
+        '--socket-mem',  # Preallocate memory per socket
+        '--socket-limit',  # Place a per-socket upper limit on memory
+        '--single-file-segments',  # Create fewer files in hugetlbfs
+        '--huge-dir',  # Use specified hugetlbfs instead of autodetected
+        '--huge-unlink',  # Unlink hugepage files after creating
+        '--match-allocations',  # Free hugepages back as original
+        '--syslog'  # syslog facility
+        ]
+
+APP_OPTS = {
+        'spp_nfv':
+        [
+            '-n',  # sec ID
+            '-s',  # address and port
+            '--vhost-client'  # enable client mode
+            ],
+        'spp_vf':
+        [
+            '--client-id',  # sec ID
+            '-s',  # address nd port
+            '--vhost-client'  # enable client mode
+            ],
+        'spp_mirror':
+        [
+            '--client-id',  # sec ID
+            '-s',  # address nd port
+            '--vhost-client'  # enable client mode
+            ],
+        'spp_pcap':
+        [
+            '--client-id',  # sec ID
+            '-s',  # address nd port
+            '-i',
+            '--output',
+            '--limit_file_size'
+            ]}
+
 
 def exec_command(func):
     """Decorator for Sending command and receiving reply.
@@ -227,6 +297,49 @@ class PrimaryProc(SppProc):
         return "clear"
 
     @exec_command
+    def do_launch_sec_proc(self, args):
+        proc_name = args['proc_name']
+        sec_id = args['client_id']
+
+        eal_opts = []
+        app_opts = []
+
+        # EAL options
+        # Check mandatory options
+        mandatory = False
+        for key in ['-c', '-l', '--lcores']:
+            if key in args['eal'].keys():
+                mandatory = True
+                break
+        if mandatory is False:
+            return None
+
+        if '--proc-type' not in args['eal'].keys():
+            return None
+
+        for opt in EAL_OPTS:
+            if opt in args['eal'].keys():
+                eal_opts.append(opt)
+                val = args['eal'][opt]
+                if (val is not None) and (val != ''):
+                    eal_opts.append(str(val))
+
+        if proc_name in APP_OPTS.keys():
+            for opt in APP_OPTS[proc_name]:
+                if opt in args['app'].keys():
+                    app_opts.append(opt)
+                    val = args['app'][opt]
+                    if (val is not None) and (val != ''):
+                        app_opts.append(str(val))
+
+        query = "launch {} {} {} -- {}".format(
+                sec_id, proc_name, ' '.join(eal_opts), ' '.join(app_opts))
+
+        LOG.info("Query: {}".format(query))
+
+        return query
+
+    @exec_command
     def do_exit(self):
         return "exit"
 
diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
index 0fd2f2a..10b4098 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -436,10 +436,13 @@ class V1PrimaryHandler(BaseHandler):
         self.set_route()
 
         self.install(self.make_response)
+        self.install(self.get_body)
 
     def set_route(self):
         self.route('/status', 'GET', callback=self.get_status)
         self.route('/status', 'DELETE', callback=self.clear_status)
+        self.route('/launch', 'PUT',
+                   callback=self.launch_sec_proc)
         self.route('/', 'DELETE', callback=self.pri_exit)
 
     def _get_proc(self):
@@ -464,6 +467,14 @@ class V1PrimaryHandler(BaseHandler):
         proc = self._get_proc()
         proc.clear()
 
+    def launch_sec_proc(self, body):  # the arg should be "body"
+        for key in ['client_id', 'proc_name', 'eal', 'app']:
+            if key not in body:
+                raise KeyRequired(key)
+
+        proc = self._get_proc()
+        proc.do_launch_sec_proc(body)
+
     def pri_exit(self):
         proc = self._get_proc()
         self.ctrl.do_exit(proc.type, proc.id)
-- 
2.7.4



More information about the spp mailing list