diff options
Diffstat (limited to 'scripts')
13 files changed, 158 insertions, 195 deletions
diff --git a/scripts/automation/regression/functional_tests/stl_basic_tests.py b/scripts/automation/regression/functional_tests/stl_basic_tests.py index dbbf2530..863307f1 100644 --- a/scripts/automation/regression/functional_tests/stl_basic_tests.py +++ b/scripts/automation/regression/functional_tests/stl_basic_tests.py @@ -119,9 +119,9 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): def run_sim (self, yaml, output, options = "", silent = False, obj = None): if output: - user_cmd = "-f {0} -o {1} {2}".format(yaml, output, options) + user_cmd = "-f {0} -o {1} {2} -p {3}".format(yaml, output, options, self.scripts_path) else: - user_cmd = "-f {0} {1}".format(yaml, options) + user_cmd = "-f {0} {1} -p {2}".format(yaml, options, self.scripts_path) if silent: user_cmd += " --silent" diff --git a/scripts/automation/regression/setups/trex17/benchmark.yaml b/scripts/automation/regression/setups/trex17/benchmark.yaml index c6f588e6..3e1f7c9b 100644 --- a/scripts/automation/regression/setups/trex17/benchmark.yaml +++ b/scripts/automation/regression/setups/trex17/benchmark.yaml @@ -23,7 +23,7 @@ test_routing_imix_64: test_static_routing_imix_asymmetric: - multiplier : 0.8 + multiplier : 0.7 cores : 1 bw_per_core : 9.635 diff --git a/scripts/automation/regression/trex_unit_test.py b/scripts/automation/regression/trex_unit_test.py index 0762fc95..83650164 100755 --- a/scripts/automation/regression/trex_unit_test.py +++ b/scripts/automation/regression/trex_unit_test.py @@ -203,11 +203,10 @@ class CTRexTestConfiguringPlugin(Plugin): print('Could not restart TRex daemon server') sys.exit(-1) - trex_cmds = CTRexScenario.trex.get_trex_cmds() - if trex_cmds: - if self.kill_running: - CTRexScenario.trex.kill_all_trexes() - else: + if self.kill_running: + CTRexScenario.trex.kill_all_trexes() + else: + if CTRexScenario.trex.get_trex_cmds(): print('TRex is already running') sys.exit(-1) @@ -238,11 +237,11 @@ class CTRexTestConfiguringPlugin(Plugin): if self.stateful: CTRexScenario.trex = None if self.stateless: - if not self.no_daemon: + if self.no_daemon: + if CTRexScenario.stl_trex and CTRexScenario.stl_trex.is_connected(): + CTRexScenario.stl_trex.disconnect() + else: CTRexScenario.trex.force_kill(False) - if CTRexScenario.stl_trex and CTRexScenario.stl_trex.is_connected(): - CTRexScenario.stl_trex.disconnect() - #time.sleep(3) CTRexScenario.stl_trex = None diff --git a/scripts/automation/trex_control_plane/server/singleton_daemon.py b/scripts/automation/trex_control_plane/server/singleton_daemon.py index 7cfbc3bc..8fdedc6e 100755 --- a/scripts/automation/trex_control_plane/server/singleton_daemon.py +++ b/scripts/automation/trex_control_plane/server/singleton_daemon.py @@ -6,10 +6,12 @@ import tempfile import types from subprocess import Popen from time import sleep +import outer_packages +import jsonrpclib # uses Unix sockets for determine running process. # (assumes used daemons will register proper socket) -# all daemons should use -p argument as listening tcp port +# all daemons should use -p argument as listening tcp port and check_connectivity RPC method class SingletonDaemon(object): # run_cmd can be function of how to run daemon or a str to run at subprocess @@ -28,14 +30,14 @@ class SingletonDaemon(object): # returns True if daemon is running def is_running(self): - lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) try: - lock_socket.bind('\0' + self.tag) # the check is ~200000 faster and more reliable than checking via 'netstat' or 'ps' etc. + lock_socket = register_socket(self.tag) # the check is ~200000 faster and more reliable than checking via 'netstat' or 'ps' etc. + lock_socket.shutdown(socket.SHUT_RDWR) lock_socket.close() except socket.error: # Unix socket in use return True # Unix socket is not used, but maybe it's old version of daemon not using socket - return bool(self.get_pid()) + return bool(self.get_pid_by_listening_port()) # get pid of running daemon by registered Unix socket (most robust way) @@ -73,7 +75,7 @@ class SingletonDaemon(object): # kill daemon - def kill(self, timeout = 5): + def kill(self, timeout = 10): pid = self.get_pid() if not pid: return False @@ -88,17 +90,27 @@ class SingletonDaemon(object): ret_code, stdout, stderr = run_command('kill -9 %s' % pid) # unconditional kill if ret_code: raise Exception('Failed to run kill -9 command for %s: %s' % (self.name, [ret_code, stdout, stderr])) - poll_rate = 0.1 - for i in range(inr(timeout / poll_rate)): + for i in range(int(timeout / poll_rate)): if not self.is_running(): return True sleep(poll_rate) raise Exception('Could not kill %s, even with -9' % self.name) + # try connection as RPC client, return True upon success, False if fail + def check_connectivity(self, timeout = 5): + daemon = jsonrpclib.Server('http://127.0.0.1:%s/' % self.port) + poll_rate = 0.1 + for i in range(int(timeout/poll_rate)): + try: + daemon.check_connectivity() + return True + except socket.error: # daemon is not up yet + sleep(poll_rate) + return False # start daemon # returns True if success, False if already running - def start(self, timeout = 5): + def start(self, timeout = 20): if self.is_running(): raise Exception('%s is already running' % self.name) if not self.run_cmd: @@ -112,6 +124,8 @@ class SingletonDaemon(object): if timeout > 0: poll_rate = 0.1 for i in range(int(timeout/poll_rate)): + if self.is_running(): + break sleep(poll_rate) if bool(proc.poll()): # process ended with error stdout_file.seek(0) @@ -120,7 +134,9 @@ class SingletonDaemon(object): elif proc.poll() == 0: # process runs other process, and ended break if self.is_running(): - return True + if self.check_connectivity(): + return True + raise Exception('Daemon process is running, but no connectivity') raise Exception('%s failed to run.' % self.name) # restart the daemon @@ -136,8 +152,9 @@ def register_socket(tag): lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) try: lock_socket.bind('\0%s' % tag) + return lock_socket except socket.error: - raise Exception('Error: process with tag %s is already running.' % tag) + raise socket.error('Error: process with tag %s is already running.' % tag) # runs command def run_command(command, timeout = 15, cwd = None): @@ -153,6 +170,8 @@ def run_command(command, timeout = 15, cwd = None): if proc.poll() is None: proc.kill() # timeout return (errno.ETIME, '', 'Timeout on running: %s' % command) + else: + proc.wait() stdout_file.seek(0) stderr_file.seek(0) return (proc.returncode, stdout_file.read().decode(errors = 'replace'), stderr_file.read().decode(errors = 'replace')) diff --git a/scripts/automation/trex_control_plane/server/trex_launch_thread.py b/scripts/automation/trex_control_plane/server/trex_launch_thread.py index 74ce1750..82a7f996 100755 --- a/scripts/automation/trex_control_plane/server/trex_launch_thread.py +++ b/scripts/automation/trex_control_plane/server/trex_launch_thread.py @@ -6,6 +6,7 @@ import signal import socket
from common.trex_status_e import TRexStatus
import subprocess
+import shlex
import time
import threading
import logging
@@ -32,7 +33,7 @@ class AsynchronousTRexSession(threading.Thread): with open(os.devnull, 'w') as DEVNULL:
self.time_stamps['start'] = self.time_stamps['run_time'] = time.time()
- self.session = subprocess.Popen("exec "+self.cmd, cwd = self.launch_path, shell=True, stdin = DEVNULL, stderr = subprocess.PIPE, preexec_fn=os.setsid)
+ self.session = subprocess.Popen(shlex.split(self.cmd), cwd = self.launch_path, stdin = DEVNULL, stderr = subprocess.PIPE, preexec_fn=os.setsid, close_fds = True)
logger.info("TRex session initialized successfully, Parent process pid is {pid}.".format( pid = self.session.pid ))
while self.session.poll() is None: # subprocess is NOT finished
time.sleep(0.5)
diff --git a/scripts/automation/trex_control_plane/server/trex_server.py b/scripts/automation/trex_control_plane/server/trex_server.py index 45ef9ac1..8f7e99f0 100755 --- a/scripts/automation/trex_control_plane/server/trex_server.py +++ b/scripts/automation/trex_control_plane/server/trex_server.py @@ -30,9 +30,9 @@ import shlex import tempfile try: - from .singleton_daemon import register_socket + from .singleton_daemon import register_socket, run_command except: - from singleton_daemon import register_socket + from singleton_daemon import register_socket, run_command # setup the logger @@ -134,6 +134,7 @@ class CTRexServer(object): self.server.register_function(self.add) self.server.register_function(self.cancel_reservation) self.server.register_function(self.connectivity_check) + self.server.register_function(self.connectivity_check, 'check_connectivity') # alias self.server.register_function(self.force_trex_kill) self.server.register_function(self.get_file) self.server.register_function(self.get_files_list) @@ -164,16 +165,6 @@ class CTRexServer(object): self.server.shutdown() #self.server.server_close() - def _run_command(self, command, timeout = 15, cwd = None): - if timeout: - command = 'timeout %s %s' % (timeout, command) - # pipes might stuck, even with timeout - with tempfile.TemporaryFile() as stdout_file, tempfile.TemporaryFile() as stderr_file: - proc = subprocess.Popen(shlex.split(command), stdout=stdout_file, stderr=stderr_file, cwd = cwd) - proc.wait() - stdout_file.seek(0) - stderr_file.seek(0) - return (proc.returncode, stdout_file.read().decode(errors = 'replace'), stderr_file.read().decode(errors = 'replace')) # get files from Trex server and return their content (mainly for logs) @staticmethod @@ -234,7 +225,7 @@ class CTRexServer(object): try: logger.info("Processing get_trex_version() command.") if not self.trex_version: - ret_code, stdout, stderr = self._run_command('./t-rex-64 --help', cwd = self.TREX_PATH, timeout = 0) + ret_code, stdout, stderr = run_command('./t-rex-64 --help', cwd = self.TREX_PATH) search_result = re.search('\n\s*(Version\s*:.+)', stdout, re.DOTALL) if not search_result: raise Exception('Could not determine version from ./t-rex-64 --help') @@ -383,7 +374,7 @@ class CTRexServer(object): # returns list of tuples (pid, command line) of running TRex(es) def get_trex_cmds(self): logger.info('Processing get_trex_cmds() command.') - ret_code, stdout, stderr = self._run_command('ps -u root --format pid,comm,cmd') + ret_code, stdout, stderr = run_command('ps -u root --format pid,comm,cmd') if ret_code: raise Exception('Failed to determine running processes, stderr: %s' % stderr) trex_cmds_list = [] @@ -403,12 +394,12 @@ class CTRexServer(object): return False for pid, cmd in trex_cmds_list: logger.info('Killing process %s %s' % (pid, cmd)) - self._run_command('kill %s' % pid) - ret_code_ps, _, _ = self._run_command('ps -p %s' % pid) + run_command('kill %s' % pid) + ret_code_ps, _, _ = run_command('ps -p %s' % pid) if not ret_code_ps: logger.info('Killing with -9.') - self._run_command('kill -9 %s' % pid) - ret_code_ps, _, _ = self._run_command('ps -p %s' % pid) + run_command('kill -9 %s' % pid) + ret_code_ps, _, _ = run_command('ps -p %s' % pid) if not ret_code_ps: logger.info('Could not kill process.') raise Exception('Could not kill process %s %s' % (pid, cmd)) diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py b/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py index eae0f18b..98af6134 100644 --- a/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py +++ b/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py @@ -39,14 +39,12 @@ def inject_pcap (pcap_file, server, port, loop_count, ipg_usec, use_vm, remove_f c.reset(ports = [port]) c.clear_stats() - d = c.push_pcap(pcap_file, + c.push_pcap(pcap_file, ipg_usec = ipg_usec, count = loop_count, vm = vm, packet_hook = packet_hook) - STLSim().run(d, outfile = 'test.cap') - c.wait_on_traffic() diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py index 11e80b9a..62724e64 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py @@ -40,18 +40,11 @@ class BpSimException(Exception): # stateless simulation class STLSim(object): - def __init__ (self, bp_sim_path = None, handler = 0, port_id = 0, api_h = "dummy"): + def __init__ (self, bp_sim_path, handler = 0, port_id = 0, api_h = "dummy"): - if not bp_sim_path: - # auto find scripts - m = re.match(".*/trex-core", os.getcwd()) - if not m: - raise STLError('cannot find BP sim path, please provide it') - - self.bp_sim_path = os.path.join(m.group(0), 'scripts') - - else: - self.bp_sim_path = bp_sim_path + self.bp_sim_path = os.path.abspath(bp_sim_path) + if not os.path.exists(self.bp_sim_path): + raise STLError('BP sim path %s does not exist' % self.bp_sim_path) # dummies self.handler = handler diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py index 94a45577..0ec98a0d 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py @@ -1020,19 +1020,20 @@ class CLatencyStats(CTRexStats): output[int_pg_id]['err_cntrs'] = current_pg['err_cntrs'] output[int_pg_id]['latency'] = {} - output[int_pg_id]['latency']['last_max'] = current_pg['latency']['last_max'] - output[int_pg_id]['latency']['jitter'] = current_pg['latency']['jitter'] - if current_pg['latency']['h'] != "": - output[int_pg_id]['latency']['average'] = current_pg['latency']['h']['s_avg'] - output[int_pg_id]['latency']['total_max'] = current_pg['latency']['h']['max_usec'] - output[int_pg_id]['latency']['histogram'] = {elem['key']: elem['val'] - for elem in current_pg['latency']['h']['histogram']} - zero_count = current_pg['latency']['h']['cnt'] - current_pg['latency']['h']['high_cnt'] - if zero_count != 0: - output[int_pg_id]['latency']['total_min'] = 1 - output[int_pg_id]['latency']['histogram'][0] = zero_count - elif output[int_pg_id]['latency']['histogram']: - output[int_pg_id]['latency']['total_min'] = min(output[int_pg_id]['latency']['histogram'].keys()) + if 'latency' in current_pg: + for field in ['jitter', 'average', 'total_max', 'last_max']: + if field in current_pg['latency']: + output[int_pg_id]['latency'][field] = current_pg['latency'][field] + else: + output[int_pg_id]['latency'][field] = StatNotAvailable(field) + + if 'histogram' in current_pg['latency']: + output[int_pg_id]['latency']['histogram'] = {int(elem): current_pg['latency']['histogram'][elem] + for elem in current_pg['latency']['histogram']} + min_val = min(output[int_pg_id]['latency']['histogram'].keys()) + if min_val == 0: + min_val = 2 + output[int_pg_id]['latency']['total_min'] = min_val else: output[int_pg_id]['latency']['total_min'] = StatNotAvailable('total_min') diff --git a/scripts/external_libs/scapy-2.3.1/python2/scapy/arch/linux.py b/scripts/external_libs/scapy-2.3.1/python2/scapy/arch/linux.py index 32f0a2d1..729ab3fd 100644 --- a/scripts/external_libs/scapy-2.3.1/python2/scapy/arch/linux.py +++ b/scripts/external_libs/scapy-2.3.1/python2/scapy/arch/linux.py @@ -69,13 +69,14 @@ RTF_REJECT = 0x0200 LOOPBACK_NAME="lo" -with os.popen("tcpdump -V 2> /dev/null") as _f: - if _f.close() >> 8 == 0x7f: - log_loading.warning("Failed to execute tcpdump. Check it is installed and in the PATH") - TCPDUMP=0 - else: - TCPDUMP=1 -del(_f) +#with os.popen("tcpdump -V 2> /dev/null") as _f: +# if _f.close() >> 8 == 0x7f: +# log_loading.warning("Failed to execute tcpdump. Check it is installed and in the PATH") +# TCPDUMP=0 +# else: +# TCPDUMP=1 +#del(_f) +TCPDUMP=0 def get_if_raw_hwaddr(iff): diff --git a/scripts/external_libs/scapy-2.3.1/python3/scapy/arch/linux.py b/scripts/external_libs/scapy-2.3.1/python3/scapy/arch/linux.py index 3eab16c6..40ff9e35 100644 --- a/scripts/external_libs/scapy-2.3.1/python3/scapy/arch/linux.py +++ b/scripts/external_libs/scapy-2.3.1/python3/scapy/arch/linux.py @@ -71,13 +71,14 @@ PCAP_ERRBUF_SIZE=256 LOOPBACK_NAME="lo" -with os.popen("tcpdump -V 2> /dev/null") as _f: - if _f.close() >> 8 == 0x7f: - log_loading.warning("Failed to execute tcpdump. Check it is installed and in the PATH") - TCPDUMP=0 - else: - TCPDUMP=1 -del(_f) +#with os.popen("tcpdump -V 2> /dev/null") as _f: +# if _f.close() >> 8 == 0x7f: +# log_loading.warning("Failed to execute tcpdump. Check it is installed and in the PATH") +# TCPDUMP=0 +# else: +# TCPDUMP=1 +#del(_f) +TCPDUMP=0 def get_if_raw_hwaddr(iff): diff --git a/scripts/ko/src/igb_uio.c b/scripts/ko/src/igb_uio.c index faeb0b68..27bec6a3 100755 --- a/scripts/ko/src/igb_uio.c +++ b/scripts/ko/src/igb_uio.c @@ -31,6 +31,7 @@ #include <linux/io.h> #include <linux/msi.h> #include <linux/version.h> +#include <linux/slab.h> #ifdef CONFIG_XEN_DOM0 #include <xen/xen.h> @@ -39,15 +40,6 @@ #include "compat.h" -#ifdef RTE_PCI_CONFIG -#define PCI_SYS_FILE_BUF_SIZE 10 -#define PCI_DEV_CAP_REG 0xA4 -#define PCI_DEV_CTRL_REG 0xA8 -#define PCI_DEV_CAP_EXT_TAG_MASK 0x20 -#define PCI_DEV_CTRL_EXT_TAG_SHIFT 8 -#define PCI_DEV_CTRL_EXT_TAG_MASK (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT) -#endif - /** * A structure describing the private information for a uio device. */ @@ -57,22 +49,15 @@ struct rte_uio_pci_dev { enum rte_intr_mode mode; }; -static char *intr_mode = NULL; +static char *intr_mode; static enum rte_intr_mode igbuio_intr_mode_preferred = RTE_INTR_MODE_MSIX; -static inline struct rte_uio_pci_dev * -igbuio_get_uio_pci_dev(struct uio_info *info) -{ - return container_of(info, struct rte_uio_pci_dev, info); -} - /* sriov sysfs */ static ssize_t show_max_vfs(struct device *dev, struct device_attribute *attr, char *buf) { - return snprintf(buf, 10, "%u\n", - pci_num_vf(container_of(dev, struct pci_dev, dev))); + return snprintf(buf, 10, "%u\n", dev_num_vf(dev)); } static ssize_t @@ -81,7 +66,7 @@ store_max_vfs(struct device *dev, struct device_attribute *attr, { int err = 0; unsigned long max_vfs; - struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); + struct pci_dev *pdev = to_pci_dev(dev); if (0 != kstrtoul(buf, 0, &max_vfs)) return -EINVAL; @@ -100,19 +85,9 @@ store_max_vfs(struct device *dev, struct device_attribute *attr, static ssize_t show_extended_tag(struct device *dev, struct device_attribute *attr, char *buf) { - struct pci_dev *pci_dev = container_of(dev, struct pci_dev, dev); - uint32_t val = 0; - - pci_read_config_dword(pci_dev, PCI_DEV_CAP_REG, &val); - if (!(val & PCI_DEV_CAP_EXT_TAG_MASK)) /* Not supported */ - return snprintf(buf, PCI_SYS_FILE_BUF_SIZE, "%s\n", "invalid"); - - val = 0; - pci_bus_read_config_dword(pci_dev->bus, pci_dev->devfn, - PCI_DEV_CTRL_REG, &val); + dev_info(dev, "Deprecated\n"); - return snprintf(buf, PCI_SYS_FILE_BUF_SIZE, "%s\n", - (val & PCI_DEV_CTRL_EXT_TAG_MASK) ? "on" : "off"); + return 0; } static ssize_t @@ -121,36 +96,9 @@ store_extended_tag(struct device *dev, const char *buf, size_t count) { - struct pci_dev *pci_dev = container_of(dev, struct pci_dev, dev); - uint32_t val = 0, enable; - - if (strncmp(buf, "on", 2) == 0) - enable = 1; - else if (strncmp(buf, "off", 3) == 0) - enable = 0; - else - return -EINVAL; - - pci_cfg_access_lock(pci_dev); - pci_bus_read_config_dword(pci_dev->bus, pci_dev->devfn, - PCI_DEV_CAP_REG, &val); - if (!(val & PCI_DEV_CAP_EXT_TAG_MASK)) { /* Not supported */ - pci_cfg_access_unlock(pci_dev); - return -EPERM; - } - - val = 0; - pci_bus_read_config_dword(pci_dev->bus, pci_dev->devfn, - PCI_DEV_CTRL_REG, &val); - if (enable) - val |= PCI_DEV_CTRL_EXT_TAG_MASK; - else - val &= ~PCI_DEV_CTRL_EXT_TAG_MASK; - pci_bus_write_config_dword(pci_dev->bus, pci_dev->devfn, - PCI_DEV_CTRL_REG, val); - pci_cfg_access_unlock(pci_dev); + dev_info(dev, "Deprecated\n"); - return count; + return 0; } static ssize_t @@ -158,10 +106,9 @@ show_max_read_request_size(struct device *dev, struct device_attribute *attr, char *buf) { - struct pci_dev *pci_dev = container_of(dev, struct pci_dev, dev); - int val = pcie_get_readrq(pci_dev); + dev_info(dev, "Deprecated\n"); - return snprintf(buf, PCI_SYS_FILE_BUF_SIZE, "%d\n", val); + return 0; } static ssize_t @@ -170,18 +117,9 @@ store_max_read_request_size(struct device *dev, const char *buf, size_t count) { - struct pci_dev *pci_dev = container_of(dev, struct pci_dev, dev); - unsigned long size = 0; - int ret; - - if (0 != kstrtoul(buf, 0, &size)) - return -EINVAL; - - ret = pcie_set_readrq(pci_dev, (int)size); - if (ret < 0) - return ret; + dev_info(dev, "Deprecated\n"); - return count; + return 0; } #endif @@ -243,7 +181,7 @@ igbuio_msix_mask_irq(struct msi_desc *desc, int32_t state) static int igbuio_pci_irqcontrol(struct uio_info *info, s32 irq_state) { - struct rte_uio_pci_dev *udev = igbuio_get_uio_pci_dev(info); + struct rte_uio_pci_dev *udev = info->priv; struct pci_dev *pdev = udev->pdev; pci_cfg_access_lock(pdev); @@ -253,8 +191,13 @@ igbuio_pci_irqcontrol(struct uio_info *info, s32 irq_state) else if (udev->mode == RTE_INTR_MODE_MSIX) { struct msi_desc *desc; +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)) list_for_each_entry(desc, &pdev->msi_list, list) igbuio_msix_mask_irq(desc, irq_state); +#else + list_for_each_entry(desc, &pdev->dev.msi_list, list) + igbuio_msix_mask_irq(desc, irq_state); +#endif } pci_cfg_access_unlock(pdev); @@ -268,7 +211,7 @@ igbuio_pci_irqcontrol(struct uio_info *info, s32 irq_state) static irqreturn_t igbuio_pci_irqhandler(int irq, struct uio_info *info) { - struct rte_uio_pci_dev *udev = igbuio_get_uio_pci_dev(info); + struct rte_uio_pci_dev *udev = info->priv; /* Legacy mode need to mask in hardware */ if (udev->mode == RTE_INTR_MODE_LEGACY && @@ -333,7 +276,7 @@ igbuio_pci_setup_iomem(struct pci_dev *dev, struct uio_info *info, unsigned long addr, len; void *internal_addr; - if (sizeof(info->mem) / sizeof(info->mem[0]) <= n) + if (n >= ARRAY_SIZE(info->mem)) return -EINVAL; addr = pci_resource_start(dev, pci_bar); @@ -358,7 +301,7 @@ igbuio_pci_setup_ioport(struct pci_dev *dev, struct uio_info *info, { unsigned long addr, len; - if (sizeof(info->port) / sizeof(info->port[0]) <= n) + if (n >= ARRAY_SIZE(info->port)) return -EINVAL; addr = pci_resource_start(dev, pci_bar); @@ -403,7 +346,7 @@ igbuio_setup_bars(struct pci_dev *dev, struct uio_info *info) iom = 0; iop = 0; - for (i = 0; i != sizeof(bar_names) / sizeof(bar_names[0]); i++) { + for (i = 0; i < ARRAY_SIZE(bar_names); i++) { if (pci_resource_len(dev, i) != 0 && pci_resource_start(dev, i) != 0) { flags = pci_resource_flags(dev, i); @@ -562,23 +505,17 @@ fail_free: static void igbuio_pci_remove(struct pci_dev *dev) { - struct uio_info *info = pci_get_drvdata(dev); - struct rte_uio_pci_dev *udev = igbuio_get_uio_pci_dev(info); - - if (info->priv == NULL) { - pr_notice("Not igbuio device\n"); - return; - } + struct rte_uio_pci_dev *udev = pci_get_drvdata(dev); sysfs_remove_group(&dev->dev.kobj, &dev_attr_grp); - uio_unregister_device(info); - igbuio_pci_release_iomem(info); + uio_unregister_device(&udev->info); + igbuio_pci_release_iomem(&udev->info); if (udev->mode == RTE_INTR_MODE_MSIX) pci_disable_msix(dev); pci_release_regions(dev); pci_disable_device(dev); pci_set_drvdata(dev, NULL); - kfree(info); + kfree(udev); } static int diff --git a/scripts/master_daemon.py b/scripts/master_daemon.py index 0b1b7363..390db0a3 100755 --- a/scripts/master_daemon.py +++ b/scripts/master_daemon.py @@ -9,6 +9,7 @@ from collections import OrderedDict from argparse import * from time import time, sleep from glob import glob +import signal sys.path.append(os.path.join('automation', 'trex_control_plane', 'server')) import outer_packages @@ -16,7 +17,7 @@ from singleton_daemon import SingletonDaemon, register_socket, run_command from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer import termstyle -logging.basicConfig(level = logging.FATAL) # keep quiet +logger = logging.getLogger('Master daemon') ### Server functions ### @@ -83,33 +84,52 @@ def start_master_daemon(): proc.start() for i in range(50): if master_daemon.is_running(): - print(termstyle.green('Master daemon is started')) + print(termstyle.green('Master daemon is started.')) os._exit(0) sleep(0.1) - fail(termstyle.red('Master daemon failed to run')) - + fail(termstyle.red('Master daemon failed to run. Please look in log: %s' % logging_file)) + +def set_logger(): + if os.path.exists(logging_file): + if os.path.exists(logging_file_bu): + os.unlink(logging_file_bu) + os.rename(logging_file, logging_file_bu) + hdlr = logging.FileHandler(logging_file) + formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s', datefmt = '%Y-%m-%d %H:%M:%S') + hdlr.setFormatter(formatter) + logger.addHandler(hdlr) + logger.setLevel(logging.INFO) def start_master_daemon_func(): - register_socket(master_daemon.tag) - server = SimpleJSONRPCServer(('0.0.0.0', master_daemon.port)) - print('Started master daemon (port %s)' % master_daemon.port) - server.register_function(add) - server.register_function(check_connectivity) - server.register_function(get_trex_path) - server.register_function(update_trex) - # trex_daemon_server - server.register_function(trex_daemon_server.is_running, 'is_trex_daemon_running') - server.register_function(trex_daemon_server.restart, 'restart_trex_daemon') - server.register_function(trex_daemon_server.start, 'start_trex_daemon') - server.register_function(trex_daemon_server.stop, 'stop_trex_daemon') - # stl rpc proxy - server.register_function(stl_rpc_proxy.is_running, 'is_stl_rpc_proxy_running') - server.register_function(stl_rpc_proxy.restart, 'restart_stl_rpc_proxy') - server.register_function(stl_rpc_proxy.start, 'start_stl_rpc_proxy') - server.register_function(stl_rpc_proxy.stop, 'stop_stl_rpc_proxy') - server.register_function(server.funcs.keys, 'get_methods') # should be last - server.serve_forever() + try: + set_logger() + register_socket(master_daemon.tag) + server = SimpleJSONRPCServer(('0.0.0.0', master_daemon.port)) + logger.info('Started master daemon (port %s)' % master_daemon.port) + server.register_function(add) + server.register_function(check_connectivity) + server.register_function(get_trex_path) + server.register_function(update_trex) + # trex_daemon_server + server.register_function(trex_daemon_server.is_running, 'is_trex_daemon_running') + server.register_function(trex_daemon_server.restart, 'restart_trex_daemon') + server.register_function(trex_daemon_server.start, 'start_trex_daemon') + server.register_function(trex_daemon_server.stop, 'stop_trex_daemon') + # stl rpc proxy + server.register_function(stl_rpc_proxy.is_running, 'is_stl_rpc_proxy_running') + server.register_function(stl_rpc_proxy.restart, 'restart_stl_rpc_proxy') + server.register_function(stl_rpc_proxy.start, 'start_stl_rpc_proxy') + server.register_function(stl_rpc_proxy.stop, 'stop_stl_rpc_proxy') + server.register_function(server.funcs.keys, 'get_methods') # should be last + signal.signal(signal.SIGTSTP, stop_handler) + signal.signal(signal.SIGTERM, stop_handler) + server.serve_forever() + except Exception as e: + logger.error('Closing due to error: %s' % e) +def stop_handler(*args, **kwargs): + logger.info('Got killed explicitly.') + sys.exit(0) # returns True if given path is under current dir or /tmp def _check_path_under_current_or_temp(path): @@ -170,8 +190,9 @@ stl_rpc_proxy = SingletonDaemon('Stateless RPC proxy', 'trex_stl_rpc_proxy' trex_daemon_server = SingletonDaemon('TRex daemon server', 'trex_daemon_server', args.trex_daemon_port, './trex_daemon_server start', args.trex_dir) master_daemon = SingletonDaemon('Master daemon', 'trex_master_daemon', args.master_port, start_master_daemon) # add ourself for easier check if running, kill etc. -daemons_by_name = {} tmp_dir = '/tmp/trex-tmp' +logging_file = '/var/log/trex/master_daemon.log' +logging_file_bu = '/var/log/trex/master_daemon.log_bu' if not _check_path_under_current_or_temp(args.trex_dir): raise Exception('Only allowed to use path under /tmp or current directory') @@ -182,6 +203,7 @@ if not os.path.exists(args.trex_dir): os.makedirs(args.trex_dir) os.chmod(args.trex_dir, 0o777) elif args.allow_update: + print('Due to allow updates flag, setting mode 777 on given directory') os.chmod(args.trex_dir, 0o777) if not os.path.exists(tmp_dir): |