Add option to run Trex with --force parameter to start 03/25203/3
authorMaros Mullner <maros.mullner@pantheon.tech>
Mon, 17 Feb 2020 12:01:00 +0000 (13:01 +0100)
committerPeter Mikus <pmikus@cisco.com>
Tue, 18 Feb 2020 07:34:22 +0000 (07:34 +0000)
regardless of ports state.

Signed-off-by: Maros Mullner <maros.mullner@pantheon.tech>
Change-Id: Iaafb5ff3a53a290ca79506bdb559a32d39570482

resources/libraries/python/Constants.py
resources/libraries/python/TrafficGenerator.py
resources/tools/trex/trex_stateless_profile.py

index 99c1e87..9a58ed1 100644 (file)
@@ -196,6 +196,9 @@ class Constants:
     # TRex number of cores
     TREX_CORE_COUNT = get_int_from_env(u"TREX_CORE_COUNT", 7)
 
+    # Trex force start regardles ports state
+    TREX_SEND_FORCE = get_pessimistic_bool_from_env(u"TREX_SEND_FORCE")
+
     # TRex extra commandline arguments
     TREX_EXTRA_CMDLINE = get_str_from_env(u"TREX_EXTRA_CMDLINE", u"")
 
index 1b519d5..f48792d 100644 (file)
@@ -519,17 +519,19 @@ class TrafficGenerator(AbstractMeasurer):
             warmup_time = float(warmup_time)
         command = f"sh -c \"" \
             f"{Constants.REMOTE_FW_DIR}/resources/tools/trex/" \
-            f"trex_stateless_profile.py" \
-            f" --profile {Constants.REMOTE_FW_DIR}/resources/" \
-            f"traffic_profiles/trex/{traffic_profile}.py" \
-            f" --duration {duration!r} --frame_size {frame_size} " \
+            f"trex_stateless_profile.py " \
+            f"--profile {Constants.REMOTE_FW_DIR}/resources/" \
+            f"traffic_profiles/trex/{traffic_profile}.py " \
+            f"--duration {duration!r} --frame_size {frame_size} " \
             f"--rate {rate!r} --warmup_time {warmup_time!r} " \
-            f"--port_0 {p_0} --port_1 {p_1}" \
-            f" --traffic_directions {traffic_directions}"
+            f"--port_0 {p_0} --port_1 {p_1} " \
+            f"--traffic_directions {traffic_directions}"
         if async_call:
             command += u" --async_start"
         if latency:
             command += u" --latency"
+        if Constants.TREX_SEND_FORCE:
+            command += u" --force"
         command += u"\""
 
         stdout, _ = exec_cmd_no_error(
index 9323d8a..edb0b8d 100755 (executable)
@@ -61,7 +61,7 @@ def fmt_latency(lat_min, lat_avg, lat_max, hdrh):
 
 def simple_burst(
         profile_file, duration, framesize, rate, warmup_time, port_0, port_1,
-        latency, async_start=False, traffic_directions=2):
+        latency, async_start=False, traffic_directions=2, force=False):
     """Send traffic and measure packet loss and latency.
 
     Procedure:
@@ -89,6 +89,7 @@ def simple_burst(
     :param latency: With latency stats.
     :param async_start: Start the traffic and exit.
     :param traffic_directions: Bidirectional (2) or unidirectional (1) traffic.
+    :param force: Force start regardless of ports state.
     :type profile_file: str
     :type framesize: int or str
     :type duration: float
@@ -99,6 +100,7 @@ def simple_burst(
     :type latency: bool
     :type async_start: bool
     :type traffic_directions: int
+    :type force: bool
     """
     client = None
     total_rcvd = 0
@@ -160,7 +162,8 @@ def simple_burst(
 
             # Choose rate and start traffic:
             time_start = time.time()
-            client.start(ports=ports, mult=rate, duration=warmup_time)
+            client.start(ports=ports, mult=rate, duration=warmup_time,
+                         force=force)
 
             # Block until done:
             client.wait_on_traffic(ports=ports, timeout=warmup_time+30)
@@ -192,7 +195,7 @@ def simple_burst(
 
         # Choose rate and start traffic:
         time_start = time.time()
-        client.start(ports=ports, mult=rate, duration=duration)
+        client.start(ports=ports, mult=rate, duration=duration, force=force)
 
         if async_start:
             # For async stop, we need to export the current snapshot.
@@ -311,6 +314,10 @@ def main():
         u"--traffic_directions", type=int, default=2,
         help=u"Send bi- (2) or uni- (1) directional traffic."
     )
+    parser.add_argument(
+        u"--force", action=u"store_true", default=False,
+        help=u"Force start regardless of ports state."
+    )
 
     args = parser.parse_args()
 
@@ -323,7 +330,7 @@ def main():
         profile_file=args.profile, duration=args.duration, framesize=framesize,
         rate=args.rate, warmup_time=args.warmup_time, port_0=args.port_0,
         port_1=args.port_1, latency=args.latency, async_start=args.async_start,
-        traffic_directions=args.traffic_directions
+        traffic_directions=args.traffic_directions, force=args.force
     )