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

Submit python model #426

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Conversation

saad-mzhr
Copy link
Collaborator

This is an attempt to translate P4 model to python so that Stateful Features (firewall, metering, ST) and Complex Match Types (ternary/range list) can be implemented.

Current State:
This model incorporates all the features in the existing P4 model and adds on top of it:

  • ACL Table including Ternary and Range List types
  • ACL Pipeline logic as required in the spec
  • Flow Table for holding the active connections
  • Flow Timer for evicting the active connection

Note that P4 model is not rewritten from scratch. Instead, it is translated word to word so as to preserve all the effort that has been put in the P4 model.

Directory/File Structure:
There is only a single folder (python_model) that directly holds all the files needed at runtime. There is a sub-directory called "python_model/tests" that stores regression tests used during development. This sub-directory is not used at runtime.
Main directory (python_model) has 2 types of files:

  1. Names starting with "dash_": They are almost an identical copy of their P4 counterparts (e.g dash_vxlan.p4, dash_pipeline.p4).
  2. Names starting with "__" (double underscore). They include framework logic that was originally implemented in BMv2. For example implementation of Match-Action tables, Counters etc

Testing:

Right now, mostly white box testing is being done over debugger for better visibility.

Steps to run:

  1. Make sure you have:
    Python 3.10.12
    VSCODE 1.81.1
    Python dev extensions in VSCODE
  2. Open VSCODE in the "python_model" directory
  3. Open file named unit_test.py
  4. Hit debug button and follow the packet flow through the pipeline

This program tests basic Stateful Firewall functionality. It configures inbound/outbound tables with appropriate values.
It also creates 2 ACL groups for inbound and outbound. Outbound ACLs have "Allow All" policy. Inbound ACLs have "Deny All" policy. The program first sends an outbound UDP packet. It is allowed by the firewall. Pipeline returns a transformed version of the packet (Use debugger to follow the packet flow).
Next, the program sends a corresponding inbound packet (UDP response). Even though the Inbound ACL has a "Deny All" policy, but this response packet will still be allowed in because of the flow table.
Also, if you send the response packet after a long enough interval (>5 seconds), response packet will be dropped because the connection has timed out.

Some points about the code:

  • Most of the P4 constructs (tables, counters) are emulated perfectly. I did not make an abstraction for P4 "control blocks" as it seemed unnecessary. Instead, Everything (functions, tables, counters) is out in the open.
  • Simplicity and functional correctness were the main objectives rather than performance and memory efficiency.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 25, 2023

CLA Not Signed

@KrisNey-MSFT
Copy link
Collaborator

hi @saad-mzhr - did you want me to keep this Open in the DASH Community?
Thank you, Kristina

@KrisNey-MSFT
Copy link
Collaborator

hi @saad-mzhr - did you want me to keep this Open in the DASH Community?
Thank you, Kristina

@KrisNey-MSFT
Copy link
Collaborator

no update here 10/9/2024

@KrisNey-MSFT
Copy link
Collaborator

hi @FarhatUllah999 - did you want to pick up this PR from Saad? Let me know, thank you - Kristina

@FarhatUllah999
Copy link
Collaborator

hi @FarhatUllah999 - did you want to pick up this PR from Saad? Let me know, thank you - Kristina

Hi @KrisNey-MSFT - Yes I have picked up this task from Saad. I have few priority tasks that's why I couldn't work on this PR. Let me prioritize this work soon.

@KrisNey-MSFT
Copy link
Collaborator

KrisNey-MSFT commented Oct 25, 2024 via email

@KrisNey-MSFT
Copy link
Collaborator

hi @FarhatUllah999 - are you still looking for a review for this one? Thx!

@FarhatUllah999
Copy link
Collaborator

hi @FarhatUllah999 - are you still looking for a review for this one? Thx!

Yes. I am working with Saad on this. Thanks

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

Successfully merging this pull request may close these issues.

3 participants