p4lang / p4-hlir

Apache License 2.0
32 stars 40 forks source link

Trying the README instruction #2

Closed anubhavnidhi closed 9 years ago

anubhavnidhi commented 9 years ago

Hi, I tried the instruction given in your README file and was able to do the steps till "h = HLIR()". But when I try this instruction I get a "NameError". I am attaching the output which I get when following the instruction below


mininet@ubuntu:~/p4/p4-hlir$ p4-validate tests/stateful.p4 WARNING: No error rule is defined for exclusive state 'pragma' WARNING: Token 'DIVIDE' defined, but not used WARNING: Token 'PPHASH' defined, but not used WARNING: Token 'MOD' defined, but not used WARNING: There are 3 unused tokens parsing successful Semantic warning: register 'reg1' is not reachable and will be removed semantic checking successful Header type standard_metadata_t not byte-aligned, adding padding Header type routing_metadata_t not byte-aligned, adding padding validating: True validating: True mininet@ubuntu:~/p4/p4-hlir$ p4-shell tests/stateful.p4 WARNING: No error rule is defined for exclusive state 'pragma' WARNING: Token 'DIVIDE' defined, but not used WARNING: Token 'PPHASH' defined, but not used WARNING: Token 'MOD' defined, but not used WARNING: There are 3 unused tokens parsing successful Semantic warning: register 'reg1' is not reachable and will be removed semantic checking successful Header type standard_metadata_t not byte-aligned, adding padding Header type routing_metadata_t not byte-aligned, adding padding validating: True validating: True HLIR successfully constructed, access with variable 'h' Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) from p4_hlir.main import HLIR
h = HLIR(tests/stateful.p4) Traceback (most recent call last): File "", line 1, in NameError: name 'tests' is not defined h = HLIR(stateful.p4) Traceback (most recent call last): File "", line 1, in NameError: name 'stateful' is not defined

Do you know what changes I need to do to make it work?

Thanks.

antoninbas commented 9 years ago

Hi,

I think you just forgot the quotes: h = HLIR("tests/stateful.p4")

Also, note that when you start in shell mode like this, the HLIR object h has already been built for you, as you can tell by the output: "HLIR successfully constructed, access with variable 'h'". Which means you can directly access the HLIR objects:

antonin@antonin-torpille:~/Documents/Barefoot/p4lang/p4-hlir$ p4-shell simple_router.p4 
WARNING: No error rule is defined for exclusive state 'pragma'
WARNING: Token 'DIVIDE' defined, but not used
WARNING: Token 'PPHASH' defined, but not used
WARNING: Token 'MOD' defined, but not used
WARNING: There are 3 unused tokens
parsing successful
semantic checking successful
Header type standard_metadata_t not byte-aligned, adding padding
validating:  True
validating:  True
validating:  True
validating:  True
HLIR successfully constructed, access with variable 'h'
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> for header in h.p4_header_instances: print header
... 
standard_metadata
ethernet
ipv4
routing_metadata
>>> 
anubhavnidhi commented 9 years ago

Hi, Thanks for the reply. Ihad a few more questions on p4

  1. I was also wondering do you have any code/repository which generates the JSON version of the P4 compiler output?
  2. I just want to make sure I understand how the table entries work. Right now the example given in simple router here says that to enter a rule like drop packet with ip.dest = A1, I need to manually enter a entry in a table e.g. add_entry table1 10.0.0.10 32 _drop. Is the manually entering the table entry true? If that is the case and I need to enter the action-name (name given in action specification) manually in the table, then what is the purpose of mentioning the possible actions used?

Thanks