Skip to content

Commit 08445e0

Browse files
ccasconejnfoster
authored andcommitted
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
1 parent 3702109 commit 08445e0

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

utils/p4_mininet.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(self, name, sw_path = None, json_path = None,
6262
thrift_port = None,
6363
pcap_dump = False,
6464
log_console = False,
65+
log_file = None,
6566
verbose = False,
6667
device_id = None,
6768
enable_debugger = False,
@@ -87,6 +88,10 @@ def __init__(self, name, sw_path = None, json_path = None,
8788
self.pcap_dump = pcap_dump
8889
self.enable_debugger = enable_debugger
8990
self.log_console = log_console
91+
if log_file is not None:
92+
self.log_file = log_file
93+
else:
94+
self.log_file = "/tmp/p4s.{}.log".format(self.name)
9095
if device_id is not None:
9196
self.device_id = device_id
9297
P4Switch.device_id = max(P4Switch.device_id, device_id)
@@ -119,8 +124,7 @@ def start(self, controllers):
119124
if not intf.IP():
120125
args.extend(['-i', str(port) + "@" + intf.name])
121126
if self.pcap_dump:
122-
args.append("--pcap")
123-
# args.append("--useFiles")
127+
args.append("--pcap %s" % self.pcap_dump)
124128
if self.thrift_port:
125129
args.extend(['--thrift-port', str(self.thrift_port)])
126130
if self.nanomsg:
@@ -132,13 +136,12 @@ def start(self, controllers):
132136
args.append("--debugger")
133137
if self.log_console:
134138
args.append("--log-console")
135-
logfile = "/tmp/p4s.{}.log".format(self.name)
136139
info(' '.join(args) + "\n")
137140

138141
pid = None
139142
with tempfile.NamedTemporaryFile() as f:
140143
# self.cmd(' '.join(args) + ' > /dev/null 2>&1 &')
141-
self.cmd(' '.join(args) + ' >' + logfile + ' 2>&1 & echo $! >> ' + f.name)
144+
self.cmd(' '.join(args) + ' >' + self.log_file + ' 2>&1 & echo $! >> ' + f.name)
142145
pid = int(f.read())
143146
debug("P4 switch {} PID is {}.\n".format(self.name, pid))
144147
if not self.check_switch_started(pid):

utils/p4runtime_switch.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, name, sw_path = None, json_path = None,
3737
verbose = False,
3838
device_id = None,
3939
enable_debugger = False,
40+
log_file = None,
4041
**kwargs):
4142
Switch.__init__(self, name, **kwargs)
4243
assert (sw_path)
@@ -75,6 +76,10 @@ def __init__(self, name, sw_path = None, json_path = None,
7576
self.pcap_dump = pcap_dump
7677
self.enable_debugger = enable_debugger
7778
self.log_console = log_console
79+
if log_file is not None:
80+
self.log_file = log_file
81+
else:
82+
self.log_file = "/tmp/p4s.{}.log".format(self.name)
7883
if device_id is not None:
7984
self.device_id = device_id
8085
P4Switch.device_id = max(P4Switch.device_id, device_id)
@@ -99,7 +104,7 @@ def start(self, controllers):
99104
if not intf.IP():
100105
args.extend(['-i', str(port) + "@" + intf.name])
101106
if self.pcap_dump:
102-
args.append("--pcap")
107+
args.append("--pcap %s" % self.pcap_dump)
103108
if self.nanomsg:
104109
args.extend(['--nanolog', self.nanomsg])
105110
args.extend(['--device-id', str(self.device_id)])
@@ -119,10 +124,10 @@ def start(self, controllers):
119124
cmd = ' '.join(args)
120125
info(cmd + "\n")
121126

122-
logfile = "/tmp/p4s.{}.log".format(self.name)
127+
123128
pid = None
124129
with tempfile.NamedTemporaryFile() as f:
125-
self.cmd(cmd + ' >' + logfile + ' 2>&1 & echo $! >> ' + f.name)
130+
self.cmd(cmd + ' >' + self.log_file + ' 2>&1 & echo $! >> ' + f.name)
126131
pid = int(f.read())
127132
debug("P4 switch {} PID is {}.\n".format(self.name, pid))
128133
if not self.check_switch_started(pid):

utils/run_exercise.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def do_net_cli(self):
357357
print('Welcome to the BMV2 Mininet CLI!')
358358
print('======================================================================')
359359
print('Your P4 program is installed into the BMV2 software switch')
360-
print('and your initial configuration is loaded. You can interact')
360+
print('and your initial runtime configuration is loaded. You can interact')
361361
print('with the network using the mininet CLI below.')
362362
print('')
363363
if self.switch_json:
@@ -371,6 +371,11 @@ def do_net_cli(self):
371371
print('To view the switch output pcap, check the pcap files in %s:' % self.pcap_dir)
372372
print(' for example run: sudo tcpdump -xxx -r s1-eth1.pcap')
373373
print('')
374+
if 'grpc' in self.bmv2_exe:
375+
print('To view the P4Runtime requests sent to the switch, check the')
376+
print('corresponding txt file in %s:' % self.log_dir)
377+
print(' for example run: cat %s/s1-p4runtime-requests.txt' % self.log_dir)
378+
print('')
374379

375380
CLI(self.net)
376381

0 commit comments

Comments
 (0)