Example #1
0
    def start_trex(self, trex_launch_path, trex_cmd, zmq_port):
        self.set_status(TRexStatus.Starting)
        logger.info("TRex running state changed to 'Starting'.")
        self.set_verbose_status('TRex is starting (data is not available yet)')

        if not self.zmq_monitor:
            logger.info('Starting ZMQ monitor on port %s' % zmq_port)
            self.zmq_monitor = ZmqMonitorSession(self, zmq_port)
            self.zmq_monitor.start()
        else:
            if not self.zmq_monitor.is_alive(
            ) or self.zmq_monitor.zmq_port != zmq_port:
                if not self.zmq_monitor.is_alive():
                    logger.info('Old ZMQ monitor is dead, starting new')
                else:
                    logger.info(
                        'ZMQ port is changed to %s, starting new monitor' %
                        zmq_port)
                self.zmq_monitor.join()
                self.zmq_monitor = ZmqMonitorSession(self, zmq_port)
                self.zmq_monitor.start()

        self.zmq_monitor.first_dump = True
        self.errcode = None
        self.session = AsynchronousTRexSession(self, trex_launch_path,
                                               trex_cmd)
        self.session.start()
        self.expect_trex.set()
Example #2
0
    def __init__(self, trex_path, trex_files_path, trex_host = socket.gethostname(), trex_daemon_port = 8090, trex_zmq_port = 4500):
        """ 
        Parameters
        ----------
        trex_host : str
            a string of the t-rex ip address or hostname.
            default value: machine hostname as fetched from socket.gethostname()
        trex_daemon_port : int
            the port number on which the trex-daemon server can be reached
            default value: 8090
        trex_zmq_port : int
            the port number on which trex's zmq module will interact with daemon server
            default value: 4500

        Instatiate a T-Rex client object, and connecting it to listening daemon-server
        """
        self.TREX_PATH          = os.path.abspath(os.path.dirname(trex_path+'/'))
        self.trex_files_path    = os.path.abspath(os.path.dirname(trex_files_path+'/'))
        self.__check_trex_path_validity()
        self.__check_files_path_validity()
        self.trex               = CTRex()
        self.trex_host          = trex_host
        self.trex_daemon_port   = trex_daemon_port
        self.trex_zmq_port      = trex_zmq_port
        self.trex_server_path   = "http://{hostname}:{port}".format( hostname = trex_host, port = trex_daemon_port )
        self.start_lock         = threading.Lock()
        self.__reservation      = None
        self.zmq_monitor        = ZmqMonitorSession(self.trex, self.trex_zmq_port)    # intiate single ZMQ monitor thread for server usage
Example #3
0
    def __init__(self,
                 trex_path,
                 trex_files_path,
                 trex_host='0.0.0.0',
                 trex_daemon_port=8090,
                 trex_zmq_port=4500,
                 trex_nice=-19):
        """ 
        Parameters
        ----------
        trex_host : str
            a string of the TRex ip address or hostname.
            default value: machine hostname as fetched from socket.gethostname()
        trex_daemon_port : int
            the port number on which the trex-daemon server can be reached
            default value: 8090
        trex_zmq_port : int
            the port number on which trex's zmq module will interact with daemon server
            default value: 4500
        nice: int
            priority of the TRex process

        Instantiate a TRex client object, and connecting it to listening daemon-server
        """
        self.TREX_PATH = os.path.abspath(os.path.dirname(trex_path + '/'))
        self.trex_files_path = os.path.abspath(
            os.path.dirname(trex_files_path + '/'))
        self.__check_trex_path_validity()
        self.__check_files_path_validity()
        self.trex = CTRex()
        self.trex_version = None
        self.trex_host = trex_host
        self.trex_daemon_port = trex_daemon_port
        self.trex_zmq_port = trex_zmq_port
        self.trex_server_path = "http://{hostname}:{port}".format(
            hostname=trex_host, port=trex_daemon_port)
        self.start_lock = threading.Lock()
        self.__reservation = None
        self.zmq_monitor = ZmqMonitorSession(
            self.trex, self.trex_zmq_port
        )  # intiate single ZMQ monitor thread for server usage
        self.trex_nice = int(trex_nice)
        if self.trex_nice < -20 or self.trex_nice > 19:
            err = "Parameter 'nice' should be integer in range [-20, 19]"
            print(err)
            logger.error(err)
            raise Exception(err)