summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/console/trex_console.py
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2017-01-18 13:08:41 +0200
committerimarom <imarom@cisco.com>2017-01-18 13:08:41 +0200
commit951b09ef1b892594840f091f861f11ad274541ec (patch)
tree1fe935fb6cdbf22308971b081e7685fdb1f185bb /scripts/automation/trex_control_plane/stl/console/trex_console.py
parent9f72a19a6bb0edf7ad54129f7ad06e8e288a61d7 (diff)
many capture modes in Python console
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/console/trex_console.py')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/console/trex_console.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/scripts/automation/trex_control_plane/stl/console/trex_console.py b/scripts/automation/trex_control_plane/stl/console/trex_console.py
index b0ab70e0..bf543045 100755
--- a/scripts/automation/trex_control_plane/stl/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py
@@ -29,6 +29,8 @@ import string
import os
import sys
import tty, termios
+from threading import Lock
+import threading
try:
import stl_path
@@ -39,6 +41,7 @@ from trex_stl_lib.api import *
from trex_stl_lib.utils.text_opts import *
from trex_stl_lib.utils.common import user_input, get_current_user
from trex_stl_lib.utils import parsing_opts
+from .trex_capture import CaptureManager
try:
import trex_tui
@@ -172,6 +175,8 @@ class TRexConsole(TRexGeneralCmd):
def __init__(self, stateless_client, verbose = False):
+ self.cmd_lock = Lock()
+
self.stateless_client = stateless_client
TRexGeneralCmd.__init__(self)
@@ -184,8 +189,11 @@ class TRexConsole(TRexGeneralCmd):
self.intro = "\n-=TRex Console v{ver}=-\n".format(ver=__version__)
self.intro += "\nType 'help' or '?' for supported actions\n"
+ self.cap_mngr = CaptureManager(stateless_client, self.cmd_lock)
+
self.postcmd(False, "")
+
################### internal section ########################
@@ -231,6 +239,7 @@ class TRexConsole(TRexGeneralCmd):
lines = line.split(';')
try:
+ self.cmd_lock.acquire()
for line in lines:
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
@@ -238,10 +247,15 @@ class TRexConsole(TRexGeneralCmd):
return "quit"
return ""
+
except STLError as e:
print(e)
return ''
+ finally:
+ self.cmd_lock.release()
+
+
def postcmd(self, stop, line):
self.prompt = self.stateless_client.generate_prompt(prefix = 'trex')
@@ -349,7 +363,7 @@ class TRexConsole(TRexGeneralCmd):
@verify_connected
def do_capture (self, line):
'''Manage PCAP captures'''
- self.stateless_client.capture_line(line)
+ self.cap_mngr.parse_line(line)
def help_capture (self):
self.do_capture("-h")
@@ -443,7 +457,9 @@ class TRexConsole(TRexGeneralCmd):
def do_disconnect (self, line):
'''Disconnect from the server\n'''
-
+
+ # stop any monitors before disconnecting
+ self.cap_mngr.stop()
self.stateless_client.disconnect_line(line)
@@ -688,6 +704,7 @@ class TRexConsole(TRexGeneralCmd):
l=help.splitlines()
print("{:<30} {:<30}".format(cmd + " - ",l[0] ))
+
# a custorm cmdloop wrapper
def start(self):
while True:
@@ -702,6 +719,9 @@ class TRexConsole(TRexGeneralCmd):
self.intro = None
continue
+ finally:
+ self.cap_mngr.stop()
+
if self.terminal:
self.terminal.kill()
@@ -934,6 +954,8 @@ def main():
with stateless_client.logger.supress():
stateless_client.disconnect(stop_traffic = False)
+
+
if __name__ == '__main__':
main()