diff options
8 files changed, 66 insertions, 18 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_port.py b/scripts/automation/trex_control_plane/client/trex_port.py index 4f82e86a..0934313f 100644 --- a/scripts/automation/trex_control_plane/client/trex_port.py +++ b/scripts/automation/trex_control_plane/client/trex_port.py @@ -18,7 +18,7 @@ class Port(object): STATE_PAUSE: "PAUSE"} - def __init__ (self, port_id, speed, driver, user, comm_link): + def __init__ (self, port_id, speed, driver, user, comm_link, session_id): self.port_id = port_id self.state = self.STATE_IDLE self.handler = None @@ -30,6 +30,7 @@ class Port(object): self.speed = speed self.streams = {} self.profile = None + self.session_id = session_id self.port_stats = trex_stats.CPortStats(self) @@ -47,6 +48,7 @@ class Port(object): def acquire(self, force = False): params = {"port_id": self.port_id, "user": self.user, + "session_id": self.session_id, "force": force} command = RpcCmdData("acquire", params) diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py index 899805cf..0d52359d 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -46,11 +46,11 @@ class CTRexStatelessClient(object): """docstring for CTRexStatelessClient""" # verbose levels - VERBOSE_SILENCE = 0 + VERBOSE_QUIET = 0 VERBOSE_REGULAR = 1 VERBOSE_HIGH = 2 - def __init__(self, username, server="localhost", sync_port = 5050, async_port = 4500, virtual=False): + def __init__(self, username, server="localhost", sync_port = 5050, async_port = 4500, quiet = False, virtual = False): super(CTRexStatelessClient, self).__init__() self.user = username @@ -58,7 +58,10 @@ class CTRexStatelessClient(object): self.comm_link = CTRexStatelessClient.CCommLink(server, sync_port, virtual, self.prn_func) # default verbose level - self.verbose = self.VERBOSE_REGULAR + if not quiet: + self.verbose = self.VERBOSE_REGULAR + else: + self.verbose = self.VERBOSE_QUIET self.ports = {} self._connection_info = {"server": server, @@ -79,7 +82,7 @@ class CTRexStatelessClient(object): self.events = [] - + self.session_id = random.getrandbits(32) self.read_only = False self.connected = False @@ -90,9 +93,15 @@ class CTRexStatelessClient(object): return self.ports.get(port_id, None) - def get_server (self): + # connection server ip + def get_server_ip (self): return self.comm_link.get_server() + # connection server port + def get_server_port (self): + return self.comm_link.get_port() + + ################# events handler ###################### def add_event_log (self, msg, ev_type, show = False): @@ -107,7 +116,7 @@ class CTRexStatelessClient(object): if show: self.prn_func(format_text("\n{:^8} - {:}".format(prefix, format_text(msg, 'bold')))) - + def handle_async_stats_update(self, dump_data): global_stats = {} @@ -185,8 +194,16 @@ class CTRexStatelessClient(object): # port was stolen... elif (type == 5): + session_id = data['session_id'] + + # false alarm, its us + if session_id == self.session_id: + return + port_id = int(data['port_id']) - ev = "Port {0} was forcely taken".format(port_id) + who = data['who'] + + ev = "Port {0} was forcely taken by '{1}'".format(port_id, who) # call the handler self.async_event_port_forced_acquired(port_id) @@ -335,7 +352,7 @@ class CTRexStatelessClient(object): speed = self.system_info['ports'][port_id]['speed'] driver = self.system_info['ports'][port_id]['driver'] - self.ports[port_id] = Port(port_id, speed, driver, self.user, self.comm_link) + self.ports[port_id] = Port(port_id, speed, driver, self.user, self.comm_link, self.session_id) # sync the ports @@ -689,6 +706,7 @@ class CTRexStatelessClient(object): # reset def cmd_reset(self): + #self.release(self.get_acquired_ports()) rc = self.acquire(force = True) rc.annotate("Force acquiring all ports:") @@ -1176,6 +1194,9 @@ class CTRexStatelessClient(object): def get_server (self): return self.server + def get_port (self): + return self.port + def set_verbose(self, mode): self.verbose = mode return self.rpc_link.set_verbose(mode) diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index 325ba514..fe6dfe12 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -172,7 +172,7 @@ class TRexConsole(TRexGeneralCmd): def get_console_identifier(self): return "{context}_{server}".format(context=self.__class__.__name__, - server=self.stateless_client.get_server()) + server=self.stateless_client.get_server_ip()) def register_main_console_methods(self): main_names = set(self.trex_console.get_names()).difference(set(dir(self.__class__))) @@ -450,6 +450,7 @@ class TRexConsole(TRexGeneralCmd): self.stateless_client.clear_events() print format_text("\n\nEvent log was cleared\n\n") + # tui @verify_connected def do_tui (self, line): @@ -465,15 +466,26 @@ class TRexConsole(TRexGeneralCmd): return if opts.xterm: - subprocess.Popen(['xterm', '-geometry', '105x40', '-e', './trex-console', '-t']) + exe = '' + if os.path.isfile('/usr/bin/wmctrl'): + exe += '/usr/bin/wmctrl -r trex_tui -b add,above;' + + exe += './trex-console -t -q -s {0} -p {1}'.format(self.stateless_client.get_server_ip(), self.stateless_client.get_server_port()) + + cmd = ['xterm', '-geometry', '105x40', '-title', 'trex_tui', '-e', exe] + subprocess.Popen(cmd) + return save_verbose = self.stateless_client.get_verbose() - self.stateless_client.set_verbose(self.stateless_client.VERBOSE_SILENCE) + self.stateless_client.set_verbose(self.stateless_client.VERBOSE_QUIET) self.tui.show() self.stateless_client.set_verbose(save_verbose) + def help_tui (self): + do_tui("-h") + # quit function def do_quit(self, line): '''Exit the client\n''' @@ -568,6 +580,11 @@ def setParserOptions(): action="store_true", help="Starts with TUI mode", default = False) + + parser.add_argument("-q", "--quiet", dest="quiet", + action="store_true", help="Starts with all outputs suppressed", + default = False) + return parser @@ -576,9 +593,10 @@ def main(): options = parser.parse_args() # Stateless client connection - stateless_client = CTRexStatelessClient(options.user, options.server, options.port, options.pub) + stateless_client = CTRexStatelessClient(options.user, options.server, options.port, options.pub, options.quiet) - print "\nlogged as {0}".format(format_text(options.user, 'bold')) + if not options.quiet: + print "\nlogged as {0}".format(format_text(options.user, 'bold')) # TUI or no acquire will give us READ ONLY mode if options.tui or not options.acquire: diff --git a/scripts/automation/trex_control_plane/console/trex_tui.py b/scripts/automation/trex_control_plane/console/trex_tui.py index 3a89097f..c8cdaa16 100644 --- a/scripts/automation/trex_control_plane/console/trex_tui.py +++ b/scripts/automation/trex_control_plane/console/trex_tui.py @@ -393,6 +393,7 @@ class TrexTUI(): def clear_screen (self): os.system('clear') + #sys.stderr.write("\x1b[2J\x1b[H") @@ -465,3 +466,4 @@ class TrexTUI(): def get_state (self): return self.state + diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index a2d4c284..a701f6db 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -236,12 +236,13 @@ TrexRpcCmdAcquire::_run(const Json::Value ¶ms, Json::Value &result) { const string &new_owner = parse_string(params, "user", result); bool force = parse_bool(params, "force", result); + uint32_t session_id = parse_uint32(params, "session_id", result); /* if not free and not you and not force - fail */ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); try { - port->acquire(new_owner, force); + port->acquire(new_owner, session_id, force); } catch (const TrexRpcException &ex) { generate_execute_err(result, ex.what()); } diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h index c22ef390..b9be1fbe 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -70,7 +70,7 @@ void get_hostname(std::string &hostname); * ownership */ TREX_RPC_CMD_DEFINE(TrexRpcCmdGetOwner, "get_owner", 1, false); -TREX_RPC_CMD_DEFINE(TrexRpcCmdAcquire, "acquire", 3, false); +TREX_RPC_CMD_DEFINE(TrexRpcCmdAcquire, "acquire", 4, false); TREX_RPC_CMD_DEFINE(TrexRpcCmdRelease, "release", 1, true); diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 9770c735..3a64f8c5 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -84,7 +84,7 @@ TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api * @param force */ void -TrexStatelessPort::acquire(const std::string &user, bool force) { +TrexStatelessPort::acquire(const std::string &user, uint32_t session_id, bool force) { /* if port is free - just take it */ if (get_owner().is_free()) { @@ -97,7 +97,11 @@ TrexStatelessPort::acquire(const std::string &user, bool force) { /* inform the other client of the steal... */ Json::Value data; + data["port_id"] = m_port_id; + data["who"] = user; + data["session_id"] = session_id; + get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_FORCE_ACQUIRED, data); } else { diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index 4988b46a..a529d38f 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -138,7 +138,7 @@ public: * acquire port * throws TrexException in case of an error */ - void acquire(const std::string &user, bool force = false); + void acquire(const std::string &user, uint32_t session_id, bool force = false); /** * release the port from the current user |