-
Notifications
You must be signed in to change notification settings - Fork 20
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
Added guide to add table entries in P4 dpdk using native control plan… #116
Open
Vineet1101
wants to merge
5
commits into
p4lang:main
Choose a base branch
from
Vineet1101:vineet-work
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b8d2ab1
Added guide to add table entries in P4 dpdk using native control plan…
Vineet1101 08515d3
Moved files to new folder and updated the guide
Vineet1101 4fb9ac7
Made some minor changes
Vineet1101 3ee1c85
Added makefile
Vineet1101 707b998
Updated the makefile
Vineet1101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
/* -*- P4_16 -*- */ | ||
#include <core.p4> | ||
#include <dpdk/psa.p4> | ||
|
||
typedef bit<48> MacAddr; | ||
typedef bit<32> IPv4Addr; | ||
typedef bit<16> PortId_t; | ||
|
||
// Headers | ||
header ethernet_t { | ||
MacAddr dstAddr; | ||
MacAddr srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
header ipv4_t { | ||
bit<4> version; | ||
bit<4> ihl; | ||
bit<8> diffserv; | ||
bit<16> totalLen; | ||
bit<16> identification; | ||
bit<3> flags; | ||
bit<13> fragOffset; | ||
bit<8> ttl; | ||
bit<8> protocol; | ||
bit<16> hdrChecksum; | ||
IPv4Addr srcAddr; | ||
IPv4Addr dstAddr; | ||
} | ||
|
||
// Parser and struct definitions | ||
struct headers_t { | ||
ethernet_t ethernet; | ||
ipv4_t ipv4; | ||
} | ||
|
||
struct metadata_t { | ||
// Empty for now | ||
} | ||
|
||
// Parser | ||
parser IngressParserImpl( | ||
packet_in buffer, | ||
out headers_t headers, | ||
inout metadata_t meta, | ||
in psa_ingress_parser_input_t istd, | ||
in empty_t resubmit_meta, | ||
in empty_t recirculate_meta) { | ||
|
||
state start { | ||
buffer.extract(headers.ethernet); | ||
transition select(headers.ethernet.etherType) { | ||
0x0800: parse_ipv4; | ||
default: accept; | ||
} | ||
} | ||
|
||
state parse_ipv4 { | ||
buffer.extract(headers.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
parser EgressParserImpl( | ||
packet_in buffer, | ||
out headers_t headers, | ||
inout metadata_t meta, | ||
in psa_egress_parser_input_t istd, | ||
in empty_t normal_meta, | ||
in empty_t clone_i2e_meta, | ||
in empty_t clone_e2e_meta) { | ||
|
||
state start { | ||
buffer.extract(headers.ethernet); | ||
transition select(headers.ethernet.etherType) { | ||
0x0800: parse_ipv4; | ||
default: accept; | ||
} | ||
} | ||
|
||
state parse_ipv4 { | ||
buffer.extract(headers.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
// Main control block | ||
control IngressImpl( | ||
inout headers_t headers, | ||
inout metadata_t meta, | ||
in psa_ingress_input_t istd, | ||
inout psa_ingress_output_t ostd) { | ||
|
||
// Action to modify source MAC | ||
action modify_src_mac(MacAddr new_src_mac) { | ||
headers.ethernet.srcAddr = new_src_mac; | ||
} | ||
|
||
// Action to modify destination MAC | ||
action modify_dst_mac(MacAddr new_dst_mac) { | ||
headers.ethernet.dstAddr = new_dst_mac; | ||
} | ||
|
||
// Exact match table for source MAC modification | ||
table exact_match_table { | ||
key = { | ||
headers.ethernet.dstAddr: exact; | ||
headers.ethernet.srcAddr: exact; | ||
headers.ipv4.protocol: exact; | ||
} | ||
actions = { | ||
modify_src_mac; | ||
NoAction; | ||
} | ||
default_action = NoAction(); | ||
size = 1024; | ||
} | ||
|
||
// Ternary match table for destination MAC modification | ||
table ternary_match_table { | ||
key = { | ||
headers.ipv4.srcAddr: ternary; | ||
headers.ipv4.dstAddr: ternary; | ||
headers.ipv4.protocol: ternary; | ||
} | ||
actions = { | ||
modify_dst_mac; | ||
NoAction; | ||
} | ||
default_action = NoAction(); | ||
size = 1024; | ||
} | ||
|
||
apply { | ||
if (headers.ipv4.isValid()) { | ||
exact_match_table.apply(); | ||
ternary_match_table.apply(); | ||
} | ||
|
||
// Send out packet on the same port it came in | ||
send_to_port(ostd, (PortId_t)istd.ingress_port); | ||
} | ||
} | ||
|
||
control EgressImpl( | ||
inout headers_t headers, | ||
inout metadata_t meta, | ||
in psa_egress_input_t istd, | ||
inout psa_egress_output_t ostd) { | ||
apply { } | ||
} | ||
|
||
// Deparser | ||
control IngressDeparserImpl( | ||
packet_out packet, | ||
out empty_t clone_i2e_meta, | ||
out empty_t resubmit_meta, | ||
out empty_t normal_meta, | ||
inout headers_t headers, | ||
in metadata_t meta, | ||
in psa_ingress_output_t istd) { | ||
apply { | ||
packet.emit(headers.ethernet); | ||
packet.emit(headers.ipv4); | ||
} | ||
} | ||
|
||
control EgressDeparserImpl( | ||
packet_out packet, | ||
out empty_t clone_e2e_meta, | ||
out empty_t recirculate_meta, | ||
inout headers_t headers, | ||
in metadata_t meta, | ||
in psa_egress_output_t istd, | ||
in psa_egress_deparser_input_t edstd) { | ||
apply { | ||
packet.emit(headers.ethernet); | ||
packet.emit(headers.ipv4); | ||
} | ||
} | ||
|
||
// Instantiate the PSA switch | ||
IngressParserImpl() ip; | ||
IngressImpl() ingress; | ||
IngressDeparserImpl() id; | ||
EgressParserImpl() ep; | ||
EgressImpl() egress; | ||
EgressDeparserImpl() ed; | ||
|
||
PSA_Switch(ip, ingress, id, ep, egress, ed) main; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move the P4 to examples directory