Fixed location of pcaps and bmv2 logs (#161)

* Fixed location of pcaps and bmv2 logs

Also added reference to P4Runtime request logs to welcome message

* Fixed pcap/log location for Thrift/CLI-based switch class
This commit is contained in:
Carmelo Cascone 2018-06-01 11:15:39 -07:00 committed by Nate Foster
parent 37021092df
commit 08445e0b18
3 changed files with 21 additions and 8 deletions

View File

@ -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):

View File

@ -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):

View File

@ -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)