P4ELTE / t4p4s

Retargetable compiler for the P4 language
http://p4.elte.hu/
Apache License 2.0
119 stars 42 forks source link

compilation error in p4 program #19

Open mc36 opened 4 years ago

mc36 commented 4 years ago

hi,

i'm maintaining a p4 router that fails to compile with p4elte but compiles with p4lang/p4c and with some platform specific modifications with barefoot/tofino. can you give me some advise on how to compile it with p4elte?

the sources can be found at http://sources.nop.hu/misc/p4lang/

here is the compiler output:

root@e586c8f1dda9:~/t4p4s# ./t4p4s.sh ./router.p4 [COMPILE P4-16] ./router.p4 @std Error during the compilation of None Traceback (most recent call last): File "src/compiler.py", line 471, in main() File "src/compiler.py", line 466, in main print_with_backtrace(sys.exc_info(), current_compilation['from'] if current_compilation else "(no compiled file)") File "src/compiler.py", line 452, in main hlir = load_from_p4(args, cache_dir_name) File "/root/t4p4s/src/compiler_load_p4.py", line 244, in load_from_p4 hlir = load_hlir(filename, cache_dir_name) File "/root/t4p4s/src/compiler_load_p4.py", line 163, in load_hlir return continue_stages(stages, stage_idx, data) File "/root/t4p4s/src/compiler_load_p4.py", line 132, in continue_stages new_data = loader(None, data) File "/root/t4p4s/src/compiler_load_p4.py", line 167, in return ([], lambda file, data: pickle.load(file) if file is not None else no_cache_loader(data) if data is not None else None) File "/root/t4p4s/src/compiler_load_p4.py", line 204, in 'loaders': [cache_loader(lambda hlir: set_additional_attrs(hlir, args['p4v']))], File "/root/t4p4s/src/hlir16/hlir16_attrs.py", line 883, in set_additional_attrs attrfun(hlir16) File "/root/t4p4s/src/hlir16/hlir16_attrs.py", line 516, in attrs_controls_tables set_table_key_attrs(hlir16, table) File "/root/t4p4s/src/hlir16/hlir16_attrs.py", line 423, in set_table_key_attrs k.id = 'fieldinstance' + k.headername + '' + k.field_name File "/root/t4p4s/src/hlir16/p4node.py", line 239, in getattr return self.dict[key] KeyError: 'header_name'

Error: P4 to C compilation failed (error code: 1) root@e586c8f1dda9:~/t4p4s#

thanks, csaba

mc36 commented 4 years ago

hi sorry for the spam... found out that header stack (a list with [x] in the header) is not supported by the compiler but i used it for the mpls headers.... for now, i've removed it from my code, but now, having a different error from the compiler:

root@df34ca928050:~/t4p4s# ./t4p4s.sh ./router.p4 [COMPILE P4-16] ./router.p4 @std Exception: 'name' Traceback (most recent call last): File "src/compiler.py", line 315, in generate_code exec(code, localvars, localvars) File "", line 167, in File "/root/t4p4s/src/hlir16/p4node.py", line 239, in getattr return self.dict[key] KeyError: 'name' Error during the compilation of {'to': './build/router@std/srcgen/dataplane.c', 'from': 'src/hardware_indep/dataplane.c.py'} Traceback (most recent call last): File "src/compiler.py", line 471, in main() File "src/compiler.py", line 466, in main print_with_backtrace(sys.exc_info(), current_compilation['from'] if current_compilation else "(no compiled file)") File "src/compiler.py", line 453, in main generate_files() File "src/compiler.py", line 442, in generate_files generate_desugared_c(filename, os.path.join(base, filename)) File "src/compiler.py", line 363, in generate_desugared_c code = generate_code(filepath, genfile, {'hlir16': hlir}) File "src/compiler.py", line 315, in generate_code exec(code, localvars, localvars) File "", line 167, in File "/root/t4p4s/src/hlir16/p4node.py", line 239, in getattr return self.dict[key] KeyError: 'name'

Error: P4 to C compilation failed (error code: 1) root@df34ca928050:~/t4p4s#

thanks, cs

mc36 commented 4 years ago

just a last message regading the things, here is how you can reproduce this:

mc36@ubi16:~$ sudo docker run -i -t t4p4s /bin/bash root@90017edd5b73:~# wget freerouter.nop.hu/rtr.zip root@90017edd5b73:~# mv misc/p4lang/* t4p4s/ root@90017edd5b73:~# cd t4p4s root@90017edd5b73:~/t4p4s# ./t4p4s.sh ./router.p4 root@90017edd5b73:~/t4p4s# ./t4p4s.sh ./router.p4

VPetyaa commented 4 years ago

Hi!

I've tried to compile your code and it failed for me as well, but with a different error. One of my colleagues who works on the compiler will have an answer to that issue soon.

The steps I did: 1, added the following line to examples.cfg: router @nic @l2 2, ./t4p4s.sh examples/router.p4

`Exception: 'is_metadata' Traceback (most recent call last): File "src/compiler.py", line 315, in generate_code exec(code, localvars, localvars) File "", line 150, in File "/home/vpetya/t4p4s-root/t4p4s/src/utils/codegen.py", line 1366, in format_statement ret = gen_format_statement(stmt) ## src/utils/codegen.sugar.py:1232 File "/home/vpetya/t4p4s-root/t4p4s/src/utils/codegen.py", line 538, in gen_format_statement generated_code += str( gen_format_statement_fieldref(dst, src)) ## src/utils/codegen.sugar.py:441 File "/home/vpetya/t4p4s-root/t4p4s/src/utils/codegen.py", line 453, in gen_format_statement_fieldref generated_code += str( gen_format_statement_fieldref_wide(dst, src, dst_width, dst_is_vw, dst_bytewidth, dst_name, dst_header_id, dst_field_id)) ## src/utils/codegen.sugar.py:362 File "/home/vpetya/t4p4s-root/t4p4s/src/utils/codegen.py", line 361, in gen_format_statement_fieldref_wide hdrinst = 'all_metadatas' if src.expr.type.is_metadata else src.expr.member ## src/utils/codegen.sugar.py:277 File "/home/vpetya/t4p4s-root/t4p4s/src/hlir16/p4node.py", line 239, in getattr return self.dict[key] KeyError: 'is_metadata' Error during the compilation of {'to': './build/router@std/srcgen/actions.c', 'from': 'src/hardware_indep/actions.c.py'} Traceback (most recent call last): File "src/compiler.py", line 471, in main() File "src/compiler.py", line 466, in main print_with_backtrace(sys.exc_info(), current_compilation['from'] if current_compilation else "(no compiled file)") File "src/compiler.py", line 453, in main generate_files() File "src/compiler.py", line 442, in generate_files generate_desugared_c(filename, os.path.join(base, filename)) File "src/compiler.py", line 363, in generate_desugared_c code = generate_code(filepath, genfile, {'hlir16': hlir}) File "src/compiler.py", line 315, in generate_code exec(code, localvars, localvars) File "", line 150, in File "/home/vpetya/t4p4s-root/t4p4s/src/utils/codegen.py", line 1366, in format_statement ret = gen_format_statement(stmt) ## src/utils/codegen.sugar.py:1232 File "/home/vpetya/t4p4s-root/t4p4s/src/utils/codegen.py", line 538, in gen_format_statement generated_code += str( gen_format_statement_fieldref(dst, src)) ## src/utils/codegen.sugar.py:441 File "/home/vpetya/t4p4s-root/t4p4s/src/utils/codegen.py", line 453, in gen_format_statement_fieldref generated_code += str( gen_format_statement_fieldref_wide(dst, src, dst_width, dst_is_vw, dst_bytewidth, dst_name, dst_header_id, dst_field_id)) ## src/utils/codegen.sugar.py:362 File "/home/vpetya/t4p4s-root/t4p4s/src/utils/codegen.py", line 361, in gen_format_statement_fieldref_wide hdrinst = 'all_metadatas' if src.expr.type.is_metadata else src.expr.member ## src/utils/codegen.sugar.py:277 File "/home/vpetya/t4p4s-root/t4p4s/src/hlir16/p4node.py", line 239, in getattr return self.dict[key] KeyError: 'is_metadata'

Error: P4 to C compilation failed (error code: 1)`

mc36 commented 4 years ago

hi, done a test not in the container but on the host and got the same error as you, so waiting for your findings! thanks in advance, cs

mc36@ubi16:~/t4p4s$ ./t4p4s.sh examples/router.p4 [COMPILE P4-16] examples/router.p4 @std Exception: 'name' Traceback (most recent call last): File "src/compiler.py", line 315, in generate_code exec(code, localvars, localvars) File "", line 167, in File "/home/mc36/t4p4s/src/hlir16/p4node.py", line 239, in getattr return self.dict[key] KeyError: 'name' Error during the compilation of {'to': './build/router@std/srcgen/dataplane.c', 'from': 'src/hardware_indep/dataplane.c.py'} Traceback (most recent call last): File "src/compiler.py", line 471, in main() File "src/compiler.py", line 466, in main print_with_backtrace(sys.exc_info(), current_compilation['from'] if current_compilation else "(no compiled file)") File "src/compiler.py", line 453, in main generate_files() File "src/compiler.py", line 442, in generate_files generate_desugared_c(filename, os.path.join(base, filename)) File "src/compiler.py", line 363, in generate_desugared_c code = generate_code(filepath, genfile, {'hlir16': hlir}) File "src/compiler.py", line 315, in generate_code exec(code, localvars, localvars) File "", line 167, in File "/home/mc36/t4p4s/src/hlir16/p4node.py", line 239, in getattr return self.dict[key] KeyError: 'name'

Error: P4 to C compilation failed (error code: 1) mc36@ubi16:~/t4p4s$