Running p4lang tutorials with no logs and no pcaps generated

Normally when debugging P4 code with the BMv2 software switch, you want to generate the detailed trace logs, and sometimes you also want to record pcap files of all packets arriving to switches on input ports, and all packets sent by the switch on output ports.

I had a question recently where someone asked me how to run a tutorial in the GitHub - p4lang/tutorials: P4 language tutorials repository while generating no logs, and while they did not specify that they wanted no pcap files to be recorded, I guessed that they might also want that capability.

Attached is a patch that can be applied to the latest code in the GitHub - p4lang/tutorials: P4 language tutorials repository as of 2023-Nov-04 that disables these things when you run a tutorial with make run.

diff --git a/utils/run_exercise.py b/utils/run_exercise.py
index 44c8ff6..3cf9a34 100755
--- a/utils/run_exercise.py
+++ b/utils/run_exercise.py
@@ -86,7 +86,7 @@ class ExerciseTopo(Topo):
                 switchClass = configureP4Switch(
                         sw_path=bmv2_exe,
                         json_path=params["program"],
-                        log_console=True,
+                        log_console=False,
                         pcap_dump=pcap_dir)
             else:
                 # add default switch
@@ -176,6 +176,8 @@ class ExerciseRunner:
 
         # Ensure all the needed directories exist and are directories
         for dir_name in [log_dir, pcap_dir]:
+            if dir_name is None:
+                continue
             if not os.path.isdir(dir_name):
                 if os.path.exists(dir_name):
                     raise Exception("'%s' exists and is not a directory!" % dir_name)
@@ -248,7 +250,7 @@ class ExerciseRunner:
         defaultSwitchClass = configureP4Switch(
                                 sw_path=self.bmv2_exe,
                                 json_path=self.switch_json,
-                                log_console=True,
+                                log_console=False,
                                 pcap_dump=self.pcap_dir)
 
         self.topo = ExerciseTopo(self.hosts, self.switches, self.links, self.log_dir, self.bmv2_exe, self.pcap_dir)
@@ -362,7 +364,7 @@ class ExerciseRunner:
 def get_args():
     cwd = os.getcwd()
     default_logs = os.path.join(cwd, 'logs')
-    default_pcaps = os.path.join(cwd, 'pcaps')
+    default_pcaps = None
     parser = argparse.ArgumentParser()
     parser.add_argument('-q', '--quiet', help='Suppress log messages.',
                         action='store_true', required=False, default=False)