diff options
author | imarom <imarom@cisco.com> | 2017-01-25 13:54:51 +0200 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2017-01-25 13:54:51 +0200 |
commit | 3689edf311778c8cb921db61f293db6cd43a9b14 (patch) | |
tree | cf683e96d5de5cd1218060d6630f97c4052e1b62 /scripts | |
parent | 19df06349d311377ca1ef10f91ef1f786b41418b (diff) |
capture - personal code review
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/automation/trex_control_plane/stl/console/trex_capture.py | 18 | ||||
-rwxr-xr-x | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py | 19 |
2 files changed, 27 insertions, 10 deletions
diff --git a/scripts/automation/trex_control_plane/stl/console/trex_capture.py b/scripts/automation/trex_control_plane/stl/console/trex_capture.py index dfd7f0a4..aac685a1 100644 --- a/scripts/automation/trex_control_plane/stl/console/trex_capture.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_capture.py @@ -88,7 +88,10 @@ class CaptureMonitorWriterStdout(CaptureMonitorWriter): # class CaptureMonitorWriterPipe(CaptureMonitorWriter): def __init__ (self, logger): - self.logger = logger + self.logger = logger + self.fifo_name = None + self.fifo = None + self.start_ts = None def init (self, start_ts): self.start_ts = start_ts @@ -125,7 +128,14 @@ class CaptureMonitorWriterPipe(CaptureMonitorWriter): def deinit (self): try: - os.unlink(self.fifo_name) + if self.fifo: + os.close(self.fifo) + self.fifo = None + + if self.fifo_name: + os.unlink(self.fifo_name) + self.fifo_name = None + except OSError: pass @@ -207,7 +217,7 @@ class CaptureMonitor(object): with self.logger.supress(): - data = self.client.start_capture(tx_port_list, rx_port_list, limit = rate_pps) + data = self.client.start_capture(tx_port_list, rx_port_list, limit = rate_pps, mode = 'cyclic') self.capture_id = data['id'] self.start_ts = data['ts'] @@ -477,7 +487,7 @@ class CaptureManager(object): self.record_start_parser.formatted_error('please provide either --tx or --rx') return - rc = self.c.start_capture(opts.tx_port_list, opts.rx_port_list, opts.limit) + rc = self.c.start_capture(opts.tx_port_list, opts.rx_port_list, opts.limit, mode = 'fixed') self.logger.log(format_text("*** Capturing ID is set to '{0}' ***".format(rc['id']), 'bold')) self.logger.log(format_text("*** Please call 'capture record stop --id {0} -o <out.pcap>' when done ***\n".format(rc['id']), 'bold')) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py index d81765c6..654ceaf6 100755 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py @@ -3005,7 +3005,7 @@ class STLClient(object): @__api_check(True) - def start_capture (self, tx_ports, rx_ports, limit = 1000): + def start_capture (self, tx_ports, rx_ports, limit = 1000, mode = 'fixed'): """ Starts a capture to PCAP on port(s) @@ -3014,6 +3014,11 @@ class STLClient(object): rx_ports - on which ports to capture RX limit - limit how many packets will be written + mode - 'fixed': when full, future packets will be + dropped + 'cyclic: when full, oldest packets will be + dropped + :returns: returns a dictionary containing {'id: <new_id>, 'ts': <starting timestamp>} @@ -3023,6 +3028,7 @@ class STLClient(object): """ + # check arguments tx_ports = self._validate_port_list(tx_ports, allow_empty = True) rx_ports = self._validate_port_list(rx_ports, allow_empty = True) merge_ports = set(tx_ports + rx_ports) @@ -3030,28 +3036,29 @@ class STLClient(object): if not merge_ports: raise STLError("start_capture - must get at least one port to capture") - # check arguments validate_type('limit', limit, (int)) if limit <= 0: raise STLError("'limit' must be a positive value") + if mode not in ('fixed', 'cyclic'): + raise STLError("'mode' must be either 'fixed' or 'cyclic'") + + # verify service mode non_service_ports = list_difference(set(tx_ports + rx_ports), self.get_service_enabled_ports()) if non_service_ports: raise STLError("Port(s) {0} are not under service mode. PCAP capturing requires all ports to be in service mode".format(non_service_ports)) + # actual job self.logger.pre_cmd("Starting PCAP capturing up to {0} packets".format(limit)) - - rc = self._transmit("capture", params = {'command': 'start', 'limit': limit, 'tx': tx_ports, 'rx': rx_ports}) + rc = self._transmit("capture", params = {'command': 'start', 'limit': limit, 'mode': mode, 'tx': tx_ports, 'rx': rx_ports}) self.logger.post_cmd(rc) - if not rc: raise STLError(rc) return {'id': rc.data()['capture_id'], 'ts': rc.data()['start_ts']} - def __fetch_capture_packets (self, capture_id, output_filename, pkt_count): |