jafingerhut / p4-guide

Guide to p4lang repositories and some other public info about P4
530 stars 155 forks source link

ModuleNotFoundError when running p4testgen for demo1 #75

Closed fengkeyleaf closed 3 weeks ago

fengkeyleaf commented 1 month ago

Hi there,

I was running demo1 with p4testgen as showed in README-p4testgen.md using the command line, ./p4testgen-runptf.sh.

But I got the error, ModuleNotFoundError: No module named 'base_test', after running the command. Also, I could run p4testgen to automatically generate test cases, and the VM image I'm using is Ubuntu 24.04 published on 2024-Aug-01. And here are the full logs:

` (p4dev-python-venv) p4@p4:~/p4-guide/demo1$ ./p4testgen-runptf.sh realpath: /home/p4/p4c/tools/ptf: No such file or directory P is: + p4c --target bmv2 --arch v1model --p4runtime-files demo1.p4_16.p4info.txtpb demo1.p4_16.p4 + /bin/rm -f ss-log.txt + echo ''

+ echo 'Started simple_switch_grpc. Waiting 2 seconds before starting PTF test ...' Started simple_switch_grpc. Waiting 2 seconds before starting PTF test ... + sleep 2 + sudo simple_switch_grpc --log-file ss-log --log-flush --dump-packet-data 10000 -i 0@veth0 -i 1@veth2 -i 2@veth4 -i 3@veth6 -i 4@veth8 -i 5@veth10 -i 6@veth12 -i 7@veth14 --no-p4 Calling target program-options parser Adding interface veth0 as port 0 Adding interface veth2 as port 1 Adding interface veth4 as port 2 Adding interface veth6 as port 3 Adding interface veth8 as port 4 Adding interface veth10 as port 5 Adding interface veth12 as port 6 Adding interface veth14 as port 7 Server listening on 0.0.0.0:9559 ++ which ptf + sudo PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python /home/p4/p4dev-python-venv/bin/ptf --pypath '' -i 0@veth1 -i 1@veth3 -i 2@veth5 -i 3@veth7 -i 4@veth9 -i 5@veth11 -i 6@veth13 -i 7@veth15 '--test-params=grpcaddr='\''localhost:9559'\'';p4info='\''demo1.p4_16.p4info.txtpb'\'';config='\''demo1.p4_16.json'\''' --test-dir out-p4testgen Using packet manipulation module: ptf.packet_scapy Traceback (most recent call last): File "/home/p4/p4dev-python-venv/bin/ptf", line 718, in test_modules = load_test_modules(config) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/p4/p4dev-python-venv/bin/ptf", line 555, in load_test_modules mod = import_module(root, modname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/p4/p4dev-python-venv/bin/ptf", line 112, in import_module return module_specs.loader.load_module() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 649, in _check_name_wrapper File "", line 1176, in load_module File "", line 1000, in load_module
File "", line 537, in _load_module_shim
File "", line 966, in _load File "", line 935, in _load_unlocked File "", line 995, in exec_module File "", line 488, in _call_with_frames_removed File "/home/p4/p4-guide/demo1/out-p4testgen/demo1.py", line 12, in import base_test as bt ModuleNotFoundError: No module named 'base_test' + echo ''

+ echo 'PTF test finished. Waiting 2 seconds before killing simple_switch_grpc ...' PTF test finished. Waiting 2 seconds before killing simple_switch_grpc ... + sleep 2 + sudo pkill --signal 9 --list-name simple_switch + echo ''

+ echo 'Verifying that there are no simple_switch_grpc processes running any longer in 4 seconds ...' Verifying that there are no simple_switch_grpc processes running any longer in 4 seconds ... + sleep 4 ./p4testgen-runptf.sh: line 66: 2551 Killed sudo simple_switch_grpc --log-file ss-log --log-flush --dump-packet-data 10000 -i 0@veth0 -i 1@veth2 -i 2@veth4 -i 3@veth6 -i 4@veth8 -i 5@veth10 -i 6@veth12 -i 7@veth14 --no-p4 + grep simple_switch + ps axguwww p4 2623 0.0 0.0 6676 2304 pts/0 S+ 16:00 0:00 grep simple_switch `

And I wonder if there are any instructions or documents that I could refer to about how to use p4testgen in details? For example, how do I feed arguments for the command line if I want to test on a different p4 target, like Tofino?

Regards,

jafingerhut commented 4 weeks ago

I have just committed a change to the p4testgen-runptf.sh script that adds some extra checks about assumptions it has on where certain files are installed, and prints hopefully clear error messages about what you should do if those files are not present. Please update to the latest version and try again.

fengkeyleaf commented 4 weeks ago

I have just committed a change to the p4testgen-runptf.sh script that adds some extra checks about assumptions it has on where certain files are installed, and prints hopefully clear error messages about what you should do if those files are not present. Please update to the latest version and try again.

Hi jafingerhut,

Thanks for your help, I updated to the latest version, and ran it again, but a new error occurred, OSError: [Errno 19] No such device, and here is the full log:

(p4dev-python-venv) p4@p4:~/p4-guide/demo1$ ./p4testgen-runptf.sh Found p4c base_test.py package: /home/p4/p4c/tools/ptf/base_test.py Found p4testgen output directory: out-p4testgen + p4c --target bmv2 --arch v1model --p4runtime-files demo1.p4_16.p4info.txtpb demo1.p4_16.p4 + /bin/rm -f ss-log.txt + echo ''

+ echo 'Started simple_switch_grpc. Waiting 2 seconds before starting PTF test ...' Started simple_switch_grpc. Waiting 2 seconds before starting PTF test ... + sleep 2 + sudo simple_switch_grpc --log-file ss-log --log-flush --dump-packet-data 10000 -i 0@veth0 -i 1@veth2 -i 2@veth4 -i 3@veth6 -i 4@veth8 -i 5@veth10 -i 6@veth12 -i 7@veth14 --no-p4 Calling target program-options parser Adding interface veth0 as port 0 Adding interface veth2 as port 1 Adding interface veth4 as port 2 Adding interface veth6 as port 3 Adding interface veth8 as port 4 Adding interface veth10 as port 5 Adding interface veth12 as port 6 Adding interface veth14 as port 7 Server listening on 0.0.0.0:9559 ++ which ptf + sudo PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python /home/p4/p4dev-python-venv/bin/ptf --pypath /home/p4/p4c/tools/ptf -i 0@veth1 -i 1@veth3 -i 2@veth5 -i 3@veth7 -i 4@veth9 -i 5@veth11 -i 6@veth13 -i 7@veth15 '--test-params=grpcaddr='\''localhost:9559'\'';p4info='\''demo1.p4_16.p4info.txtpb'\'';config='\''demo1.p4_16.json'\''' --test-dir out-p4testgen Using packet manipulation module: ptf.packet_scapy Traceback (most recent call last): File "/home/p4/p4dev-python-venv/bin/ptf", line 865, in ptf.dataplane_instance.port_add(ifname, device, port) File "/home/p4/p4dev-python-venv/lib/python3.12/site-packages/ptf/dataplane.py", line 685, in port_add self.ports[port_id] = self.dppclass( ^^^^^^^^^^^^^^ File "/home/p4/p4dev-python-venv/lib/python3.12/site-packages/ptf/dataplane.py", line 145, in init self.socket.bind((interface_name, self.ETH_P_ALL)) OSError: [Errno 19] No such device ^C+ echo ''

+ echo 'PTF test finished. Waiting 2 seconds before killing simple_switch_grpc ...' PTF test finished. Waiting 2 seconds before killing simple_switch_grpc ... + sleep 2 + sudo pkill --signal 9 --list-name simple_switch + echo ''

+ echo 'Verifying that there are no simple_switch_grpc processes running any longer in 4 seconds ...' Verifying that there are no simple_switch_grpc processes running any longer in 4 seconds ... + sleep 4 ^C

i wonder if there is something wrong with my environment or something else going wrong?

regards,

jafingerhut commented 4 weeks ago

All of the README's in the demo directories should link to this common one: https://github.com/jafingerhut/p4-guide/blob/master/README-using-bmv2.md

I know it isn't terribly early in that document, but it does mention running a script called veth_setup.sh in order to create veth interfaces over which packets can be sent and received between the BMv2 software switch and other programs.

fengkeyleaf commented 4 weeks ago

Thanks a lot, I successfully ran the test after adding the virtual interfaces, and I have one more question:

Are there any instructions or documents that I could refer to about how to use p4testgen in details? For example, how do I feed arguments for the command line if I want to test on a different p4 target, like Tofino? I searched online and didn't find anything useful, and only your guide mentions how to use p4testgen with a concrete example.

Regards,

jafingerhut commented 4 weeks ago

The sample p4testgen command line in my instructions has --target and --arch command line options to specify those things, e.g.:

p4testgen --target bmv2 --arch v1model --max-tests 10 --out-dir out-p4testgen --test-backend ptf demo1.p4_16.p4

I do not know whether the open source version of p4testgen supports Tofino or not, but if it does, it would probably be with command line options like this:

p4testgen --target tofino --arch tna --max-tests 10 --out-dir out-p4testgen --test-backend ptf some_tofino_program.p4

Note: demo1.p4_16.p4 is NOT written using the architecture tna, so even if open source p4testgen supports --target tofino --arch tna, you would need a different P4 program to test it with. One such public example can be found in this repository: https://github.com/p4lang/p4app-switchML

fengkeyleaf commented 3 weeks ago

The sample p4testgen command line in my instructions has --target and --arch command line options to specify those things, e.g.:

p4testgen --target bmv2 --arch v1model --max-tests 10 --out-dir out-p4testgen --test-backend ptf demo1.p4_16.p4

I do not know whether the open source version of p4testgen supports Tofino or not, but if it does, it would probably be with command line options like this:

p4testgen --target tofino --arch tna --max-tests 10 --out-dir out-p4testgen --test-backend ptf some_tofino_program.p4

Note: demo1.p4_16.p4 is NOT written using the architecture tna, so even if open source p4testgen supports --target tofino --arch tna, you would need a different P4 program to test it with. One such public example can be found in this repository: https://github.com/p4lang/p4app-switchML

Thanks, I tried with the command, but it seems that the p4testgen doesn't support tofino:

error: Unsupported target device: tofino

Maybe, I need to contact the authors to see if I can access the version supporting tofino.

regards,

fengkeyleaf commented 3 weeks ago

No more questions at this point.