diff --git a/utils/p4_mininet.py b/utils/p4_mininet.py index b7fbbcd..d70322a 100644 --- a/utils/p4_mininet.py +++ b/utils/p4_mininet.py @@ -62,6 +62,7 @@ class P4Switch(Switch): thrift_port = None, pcap_dump = False, log_console = False, + log_file = None, verbose = False, device_id = None, enable_debugger = False, @@ -87,6 +88,10 @@ class P4Switch(Switch): self.pcap_dump = pcap_dump self.enable_debugger = enable_debugger self.log_console = log_console + if log_file is not None: + self.log_file = log_file + else: + self.log_file = "/tmp/p4s.{}.log".format(self.name) if device_id is not None: self.device_id = device_id P4Switch.device_id = max(P4Switch.device_id, device_id) @@ -119,8 +124,7 @@ class P4Switch(Switch): if not intf.IP(): args.extend(['-i', str(port) + "@" + intf.name]) if self.pcap_dump: - args.append("--pcap") - # args.append("--useFiles") + args.append("--pcap %s" % self.pcap_dump) if self.thrift_port: args.extend(['--thrift-port', str(self.thrift_port)]) if self.nanomsg: @@ -132,13 +136,12 @@ class P4Switch(Switch): args.append("--debugger") if self.log_console: args.append("--log-console") - logfile = "/tmp/p4s.{}.log".format(self.name) info(' '.join(args) + "\n") pid = None with tempfile.NamedTemporaryFile() as f: # self.cmd(' '.join(args) + ' > /dev/null 2>&1 &') - self.cmd(' '.join(args) + ' >' + logfile + ' 2>&1 & echo $! >> ' + f.name) + self.cmd(' '.join(args) + ' >' + self.log_file + ' 2>&1 & echo $! >> ' + f.name) pid = int(f.read()) debug("P4 switch {} PID is {}.\n".format(self.name, pid)) if not self.check_switch_started(pid): diff --git a/utils/p4runtime_switch.py b/utils/p4runtime_switch.py index 44ecbf5..a3b8bcf 100644 --- a/utils/p4runtime_switch.py +++ b/utils/p4runtime_switch.py @@ -37,6 +37,7 @@ class P4RuntimeSwitch(P4Switch): verbose = False, device_id = None, enable_debugger = False, + log_file = None, **kwargs): Switch.__init__(self, name, **kwargs) assert (sw_path) @@ -75,6 +76,10 @@ class P4RuntimeSwitch(P4Switch): self.pcap_dump = pcap_dump self.enable_debugger = enable_debugger self.log_console = log_console + if log_file is not None: + self.log_file = log_file + else: + self.log_file = "/tmp/p4s.{}.log".format(self.name) if device_id is not None: self.device_id = device_id P4Switch.device_id = max(P4Switch.device_id, device_id) @@ -99,7 +104,7 @@ class P4RuntimeSwitch(P4Switch): if not intf.IP(): args.extend(['-i', str(port) + "@" + intf.name]) if self.pcap_dump: - args.append("--pcap") + args.append("--pcap %s" % self.pcap_dump) if self.nanomsg: args.extend(['--nanolog', self.nanomsg]) args.extend(['--device-id', str(self.device_id)]) @@ -119,10 +124,10 @@ class P4RuntimeSwitch(P4Switch): cmd = ' '.join(args) info(cmd + "\n") - logfile = "/tmp/p4s.{}.log".format(self.name) + pid = None with tempfile.NamedTemporaryFile() as f: - self.cmd(cmd + ' >' + logfile + ' 2>&1 & echo $! >> ' + f.name) + self.cmd(cmd + ' >' + self.log_file + ' 2>&1 & echo $! >> ' + f.name) pid = int(f.read()) debug("P4 switch {} PID is {}.\n".format(self.name, pid)) if not self.check_switch_started(pid): diff --git a/utils/run_exercise.py b/utils/run_exercise.py index 5fd3cc8..07aeac1 100755 --- a/utils/run_exercise.py +++ b/utils/run_exercise.py @@ -357,7 +357,7 @@ class ExerciseRunner: print('Welcome to the BMV2 Mininet CLI!') print('======================================================================') print('Your P4 program is installed into the BMV2 software switch') - print('and your initial configuration is loaded. You can interact') + print('and your initial runtime configuration is loaded. You can interact') print('with the network using the mininet CLI below.') print('') if self.switch_json: @@ -371,6 +371,11 @@ class ExerciseRunner: print('To view the switch output pcap, check the pcap files in %s:' % self.pcap_dir) print(' for example run: sudo tcpdump -xxx -r s1-eth1.pcap') print('') + if 'grpc' in self.bmv2_exe: + print('To view the P4Runtime requests sent to the switch, check the') + print('corresponding txt file in %s:' % self.log_dir) + print(' for example run: cat %s/s1-p4runtime-requests.txt' % self.log_dir) + print('') CLI(self.net)