-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dpdk] shorten label names and header instance type (#3436)
- Loading branch information
1 parent
bd2a4d0
commit 1617792
Showing
10 changed files
with
793 additions
and
3 deletions.
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
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,171 @@ | ||
/* | ||
Copyright 2022 Intel Corporation | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
#include <core.p4> | ||
#include "pna.p4" | ||
|
||
|
||
typedef bit<48> EthernetAddress; | ||
|
||
header ethernet_t { | ||
EthernetAddress dstAddr; | ||
EthernetAddress srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
header ipv4_dddddddddddddddddddddddddddddddddddddddddd_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; | ||
bit<32> srcAddr; | ||
bit<32> dstAddr; | ||
} | ||
|
||
struct empty_metadata_t { | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// Struct types for holding user-defined collections of headers and | ||
// metadata in the P4 developer's program. | ||
// | ||
// Note: The names of these struct types are completely up to the P4 | ||
// developer, as are their member fields, with the only restriction | ||
// being that the structs intended to contain headers should only | ||
// contain members whose types are header, header stack, or | ||
// header_union. | ||
////////////////////////////////////////////////////////////////////// | ||
struct main_metadata_t { | ||
// empty for this skeleton | ||
} | ||
|
||
// User-defined struct containing all of those headers parsed in the | ||
// main parser. | ||
struct headers_t { | ||
ethernet_t ethernet; | ||
ipv4_dddddddddddddddddddddddddddddddddddddddddd_t ipv4; | ||
ethernet_t ethernet1; | ||
} | ||
|
||
void copy_header_ethernet(inout ethernet_t hdr, in ethernet_t outer_hdr) { | ||
hdr.dstAddr = outer_hdr.dstAddr; | ||
hdr.srcAddr = outer_hdr.srcAddr; | ||
hdr.etherType = outer_hdr.etherType; | ||
} | ||
|
||
control PreControlImpl( | ||
in headers_t hdr, | ||
inout main_metadata_t meta, | ||
in pna_pre_input_metadata_t istd, | ||
inout pna_pre_output_metadata_t ostd) | ||
{ | ||
|
||
apply { | ||
} | ||
|
||
} | ||
|
||
parser MainParserImpl( | ||
packet_in pkt, | ||
out headers_t hdr, | ||
inout main_metadata_t main_meta, | ||
in pna_main_parser_input_metadata_t istd) | ||
{ | ||
|
||
state start { | ||
pkt.extract(hdr.ethernet); | ||
transition select(hdr.ethernet.etherType) { | ||
0x0800: parse_ipv4_dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd; | ||
default: accept; | ||
} | ||
} | ||
state parse_ipv4_dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd { | ||
pkt.extract(hdr.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
control MainControlImpl( | ||
inout headers_t hdr, // from main parser | ||
inout main_metadata_t user_meta, // from main parser, to "next block" | ||
in pna_main_input_metadata_t istd, | ||
inout pna_main_output_metadata_t ostd) | ||
{ | ||
bit<32> tmpDir; | ||
ethernet_t eth; | ||
action next_hop(PortId_t vport) { | ||
eth = hdr.ethernet; | ||
hdr.ethernet1 = eth; | ||
send_to_port(vport); | ||
} | ||
|
||
action default_route_drop() { | ||
drop_packet(); | ||
copy_header_ethernet(hdr.ethernet, hdr.ethernet1); | ||
} | ||
table ipv4_da_lpm { | ||
key = { | ||
tmpDir :lpm @name ("ipv4_addr"); | ||
|
||
} | ||
actions = { | ||
next_hop; | ||
default_route_drop; | ||
} | ||
const default_action = default_route_drop; | ||
} | ||
apply { | ||
|
||
if (PNA_Direction_t.NET_TO_HOST == istd.direction) { | ||
tmpDir = hdr.ipv4.srcAddr; | ||
} else { | ||
tmpDir = hdr.ipv4.dstAddr; | ||
} | ||
if (hdr.ipv4.isValid()) { | ||
ipv4_da_lpm.apply(); | ||
} | ||
} | ||
} | ||
|
||
control MainDeparserImpl( | ||
packet_out pkt, | ||
in headers_t hdr, // from main control | ||
in main_metadata_t user_meta, // from main control | ||
in pna_main_output_metadata_t ostd) | ||
{ | ||
apply { | ||
pkt.emit(hdr.ethernet); | ||
pkt.emit(hdr.ipv4); | ||
} | ||
} | ||
|
||
// BEGIN:Package_Instantiation_Example | ||
PNA_NIC( | ||
MainParserImpl(), | ||
PreControlImpl(), | ||
MainControlImpl(), | ||
MainDeparserImpl() | ||
// Hoping to make this optional parameter later, but not supported | ||
// by p4c yet. | ||
//, PreParserImpl() | ||
) main; | ||
// END:Package_Instantiation_Example | ||
|
104 changes: 104 additions & 0 deletions
104
testdata/p4_16_samples_outputs/pna-too-big-label-name-dpdk-first.p4
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,104 @@ | ||
#include <core.p4> | ||
#include <pna.p4> | ||
|
||
typedef bit<48> EthernetAddress; | ||
header ethernet_t { | ||
EthernetAddress dstAddr; | ||
EthernetAddress srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
header ipv4_dddddddddddddddddddddddddddddddddddddddddd_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; | ||
bit<32> srcAddr; | ||
bit<32> dstAddr; | ||
} | ||
|
||
struct empty_metadata_t { | ||
} | ||
|
||
struct main_metadata_t { | ||
} | ||
|
||
struct headers_t { | ||
ethernet_t ethernet; | ||
ipv4_dddddddddddddddddddddddddddddddddddddddddd_t ipv4; | ||
ethernet_t ethernet1; | ||
} | ||
|
||
void copy_header_ethernet(inout ethernet_t hdr, in ethernet_t outer_hdr) { | ||
hdr.dstAddr = outer_hdr.dstAddr; | ||
hdr.srcAddr = outer_hdr.srcAddr; | ||
hdr.etherType = outer_hdr.etherType; | ||
} | ||
control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { | ||
apply { | ||
} | ||
} | ||
|
||
parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { | ||
state start { | ||
pkt.extract<ethernet_t>(hdr.ethernet); | ||
transition select(hdr.ethernet.etherType) { | ||
16w0x800: parse_ipv4_dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd; | ||
default: accept; | ||
} | ||
} | ||
state parse_ipv4_dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd { | ||
pkt.extract<ipv4_dddddddddddddddddddddddddddddddddddddddddd_t>(hdr.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { | ||
bit<32> tmpDir; | ||
ethernet_t eth; | ||
action next_hop(PortId_t vport) { | ||
eth = hdr.ethernet; | ||
hdr.ethernet1 = eth; | ||
send_to_port(vport); | ||
} | ||
action default_route_drop() { | ||
drop_packet(); | ||
copy_header_ethernet(hdr.ethernet, hdr.ethernet1); | ||
} | ||
table ipv4_da_lpm { | ||
key = { | ||
tmpDir: lpm @name("ipv4_addr") ; | ||
} | ||
actions = { | ||
next_hop(); | ||
default_route_drop(); | ||
} | ||
const default_action = default_route_drop(); | ||
} | ||
apply { | ||
if (PNA_Direction_t.NET_TO_HOST == istd.direction) { | ||
tmpDir = hdr.ipv4.srcAddr; | ||
} else { | ||
tmpDir = hdr.ipv4.dstAddr; | ||
} | ||
if (hdr.ipv4.isValid()) { | ||
ipv4_da_lpm.apply(); | ||
} | ||
} | ||
} | ||
|
||
control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { | ||
apply { | ||
pkt.emit<ethernet_t>(hdr.ethernet); | ||
pkt.emit<ipv4_dddddddddddddddddddddddddddddddddddddddddd_t>(hdr.ipv4); | ||
} | ||
} | ||
|
||
PNA_NIC<headers_t, main_metadata_t, headers_t, main_metadata_t>(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; | ||
|
Oops, something went wrong.