Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you show me the range match P4 and its controller example #45

Open
Nano5e opened this issue Jul 15, 2023 · 3 comments
Open

Can you show me the range match P4 and its controller example #45

Nano5e opened this issue Jul 15, 2023 · 3 comments

Comments

@Nano5e
Copy link

Nano5e commented Jul 15, 2023

There seem to be bugs when attempting to add range match entries to tables. Specifically, I have been unable to successfully add such entries via controller.py , as the range match never seems to hit.

@edgar-costa
Copy link
Contributor

Hi @Nano5e

Can you show me how do you add it? Also, can you look at the switch logs and dump the table entries after you added it?

@Nano5e
Copy link
Author

Nano5e commented Jul 25, 2023

Sorry for not being able to get back to you in time.

A demo based on MPLS

I implement a demo based on MPLS to test range match in P4 language. but I fail, it seems that I can't add range match entries to the table via runtime_api.

main files:

network.py : Building the network
basic.p4 : p4 file for switches other than s4
basic_digest.p4 : p4 file for switch s4, peform packet counting and sending count numbers to control plane.
controller.py : runtime_api add entries to tables.
controller_get_digest.py : get the number send to control plane.

Some details

mac_learn counts packets coming into s4 and sends them to the control plane via digest. The counter is cleared every 15 counts. mac_learn and smac table is in basic_digest.p4:

key = {                             
standard_metadata.ingress_port : range;                         
 }                       
actions = {                              
mac_learn;                              
NoAction;                          
}                      
size =256;                      
default_action = NoAction;           
} 

There are four ports: 1,2,3,4. Incoming packets are counted on every port of s4 switch. (This can be accomplished using exact match, but I want to test range match.)
I added range match entry to smac table via p4runtime_API in controller.py

controller.table_add('smac','mac_learn', ['0x0001..0x0004']) 

However, this does not work.

However if I add const entries in P4 file (basic_digest.p4)

table smac {         
    key = {            
        standard_metadata.ingress_port : range;         
       }
   actions = {                      
mac_learn;                     
 NoAction;                  
}              
size =256;              
default_action = NoAction;       
const entries = {                      0x0001..0x0004 : mac_learn();                  }          
} 

It works.

@edgar-costa
Copy link
Contributor

Hi,

Sorry for the very late reply. I did not see this.

This is how the range entries are parsed:
https://github.com/nsg-ethz/p4-utils/blob/master/p4utils/utils/thrift_API.py#L639C28-L639C50

That means you have to do it as "start->end".

you could have checked the CLI output logs, probably it complained with the following message:

"Invalid range value {}, use '->' to separate range start "
                    "and range end"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants