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

Improve PNA system library organization with smaller usable components #4752

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,13 @@ set (OTHER_HEADERS
add_custom_target(update_includes ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/*.p4 ${P4C_BINARY_DIR}/p4include
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include/pna
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include/pna/v0_5
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/pna/v0_5/*.p4 ${P4C_BINARY_DIR}/p4include/pna/v0_5
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include/pna/v0_7
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/pna/v0_7/*.p4 ${P4C_BINARY_DIR}/p4include/pna/v0_7
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include/pna/dev
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/pna/dev/*.p4 ${P4C_BINARY_DIR}/p4include/pna/dev
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include/bmv2
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/bmv2/psa.p4 ${P4C_BINARY_DIR}/p4include/bmv2
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include/dpdk
Expand Down
3 changes: 2 additions & 1 deletion backends/tc/ebpfCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,8 @@ const PNAEbpfGenerator *ConvertToEbpfPNA::build(const IR::ToplevelBlock *tlb) {
!d->is<IR::Type_Error>()) {
if (d->srcInfo.isValid()) {
auto sourceFile = d->srcInfo.getSourceFile();
if (sourceFile.endsWith("/pna.p4")) {
if (sourceFile.endsWith("/pna.p4") ||
(sourceFile.find("p4include/pna/") != nullptr)) {
// do not generate standard PNA types
continue;
}
Expand Down
117 changes: 2 additions & 115 deletions p4include/dpdk/pna.p4
Original file line number Diff line number Diff line change
Expand Up @@ -554,85 +554,7 @@ enum PNA_Direction_t {
HOST_TO_NET
}

// BEGIN:Metadata_types
enum PNA_PacketPath_t {
// TBD if this type remains, whether it should be an enum or
// several separate fields representing the same cases in a
// different form.
FROM_NET_PORT,
FROM_NET_LOOPEDBACK,
FROM_NET_RECIRCULATED,
FROM_HOST,
FROM_HOST_LOOPEDBACK,
FROM_HOST_RECIRCULATED
}

struct pna_pre_input_metadata_t {
PortId_t input_port;
ParserError_t parser_error;
PNA_Direction_t direction;
PassNumber_t pass;
bool loopedback;
}

struct pna_pre_output_metadata_t {
bool decrypt; // TBD: or use said==0 to mean no decrypt?

// The following things are stored internally within the decrypt
// block, in a table indexed by said:

// + The decryption algorithm, e.g. AES256, etc.
// + The decryption key
// + Any read-modify-write state in the data plane used to
// implement anti-replay attack detection.

SecurityAssocId_t said;
bit<16> decrypt_start_offset; // in bytes?

// TBD whether it is important to explicitly pass information to a
// decryption extern in a way visible to a P4 program about where
// headers were parsed and found. An alternative is to assume
// that the architecture saves the pre parser results somewhere,
// in a way not visible to the P4 program.
}

struct pna_main_parser_input_metadata_t {
// common fields initialized for all packets that are input to main
// parser, regardless of direction.
PNA_Direction_t direction;
PassNumber_t pass;
bool loopedback;
// If this packet has direction NET_TO_HOST, input_port contains
// the id of the network port on which the packet arrived.
// If this packet has direction HOST_TO_NET, input_port contains
// the id of the vport from which the packet came
PortId_t input_port; // network port id
}

struct pna_main_input_metadata_t {
// common fields initialized for all packets that are input to main
// parser, regardless of direction.
PNA_Direction_t direction;
PassNumber_t pass;
bool loopedback;
Timestamp_t timestamp;
ParserError_t parser_error;
ClassOfService_t class_of_service;
// See comments for field input_port in struct
// pna_main_parser_input_metadata_t
PortId_t input_port;
}

// BEGIN:Metadata_main_output
struct pna_main_output_metadata_t {
// common fields used by the architecture to decide what to do with
// the packet next, after the main parser, control, and deparser
// have finished executing one pass, regardless of the direction.
ClassOfService_t class_of_service; // 0
}
// END:Metadata_main_output
// END:Metadata_types

#include <pna/v0_5/types_metadata.p4>

// The following extern functions are "forwarding" functions -- they
// all set the destination of the packet. Calling one of them
Expand Down Expand Up @@ -740,41 +662,6 @@ extern T SelectByDirection<T>(
in T n2h_value,
in T h2n_value);




// BEGIN:Programmable_blocks
control PreControlT<PH, PM>(
in PH pre_hdr,
inout PM pre_user_meta,
in pna_pre_input_metadata_t istd,
inout pna_pre_output_metadata_t ostd);

parser MainParserT<MH, MM>(
packet_in pkt,
//in PM pre_user_meta,
out MH main_hdr,
inout MM main_user_meta,
in pna_main_parser_input_metadata_t istd);

control MainControlT<MH, MM>(
//in PM pre_user_meta,
inout MH main_hdr,
inout MM main_user_meta,
in pna_main_input_metadata_t istd,
inout pna_main_output_metadata_t ostd);

control MainDeparserT<MH, MM>(
packet_out pkt,
in MH main_hdr,
in MM main_user_meta,
in pna_main_output_metadata_t ostd);

package PNA_NIC<PH, PM, MH, MM>(
MainParserT<MH, MM> main_parser,
PreControlT<PH, PM> pre_control,
MainControlT<MH, MM> main_control,
MainDeparserT<MH, MM> main_deparser);
// END:Programmable_blocks
#include <pna/v0_5/blocks.p4>

#endif // __PNA_P4__
117 changes: 2 additions & 115 deletions p4include/pna.p4
Original file line number Diff line number Diff line change
Expand Up @@ -480,85 +480,7 @@ enum PNA_Direction_t {
HOST_TO_NET
}

// BEGIN:Metadata_types
enum PNA_PacketPath_t {
// TBD if this type remains, whether it should be an enum or
// several separate fields representing the same cases in a
// different form.
FROM_NET_PORT,
FROM_NET_LOOPEDBACK,
FROM_NET_RECIRCULATED,
FROM_HOST,
FROM_HOST_LOOPEDBACK,
FROM_HOST_RECIRCULATED
}

struct pna_pre_input_metadata_t {
PortId_t input_port;
ParserError_t parser_error;
PNA_Direction_t direction;
PassNumber_t pass;
bool loopedback;
}

struct pna_pre_output_metadata_t {
bool decrypt; // TBD: or use said==0 to mean no decrypt?

// The following things are stored internally within the decrypt
// block, in a table indexed by said:

// + The decryption algorithm, e.g. AES256, etc.
// + The decryption key
// + Any read-modify-write state in the data plane used to
// implement anti-replay attack detection.

SecurityAssocId_t said;
bit<16> decrypt_start_offset; // in bytes?

// TBD whether it is important to explicitly pass information to a
// decryption extern in a way visible to a P4 program about where
// headers were parsed and found. An alternative is to assume
// that the architecture saves the pre parser results somewhere,
// in a way not visible to the P4 program.
}

struct pna_main_parser_input_metadata_t {
// common fields initialized for all packets that are input to main
// parser, regardless of direction.
PNA_Direction_t direction;
PassNumber_t pass;
bool loopedback;
// If this packet has direction NET_TO_HOST, input_port contains
// the id of the network port on which the packet arrived.
// If this packet has direction HOST_TO_NET, input_port contains
// the id of the vport from which the packet came
PortId_t input_port; // network port id
}

struct pna_main_input_metadata_t {
// common fields initialized for all packets that are input to main
// parser, regardless of direction.
PNA_Direction_t direction;
PassNumber_t pass;
bool loopedback;
Timestamp_t timestamp;
ParserError_t parser_error;
ClassOfService_t class_of_service;
// See comments for field input_port in struct
// pna_main_parser_input_metadata_t
PortId_t input_port;
}

// BEGIN:Metadata_main_output
struct pna_main_output_metadata_t {
// common fields used by the architecture to decide what to do with
// the packet next, after the main parser, control, and deparser
// have finished executing one pass, regardless of the direction.
ClassOfService_t class_of_service; // 0
}
// END:Metadata_main_output
// END:Metadata_types

#include <pna/v0_5/types_metadata.p4>

// The following extern functions are "forwarding" functions -- they
// all set the destination of the packet. Calling one of them
Expand Down Expand Up @@ -666,41 +588,6 @@ extern T SelectByDirection<T>(
in T n2h_value,
in T h2n_value);




// BEGIN:Programmable_blocks
control PreControlT<PH, PM>(
in PH pre_hdr,
inout PM pre_user_meta,
in pna_pre_input_metadata_t istd,
inout pna_pre_output_metadata_t ostd);

parser MainParserT<MH, MM>(
packet_in pkt,
//in PM pre_user_meta,
out MH main_hdr,
inout MM main_user_meta,
in pna_main_parser_input_metadata_t istd);

control MainControlT<MH, MM>(
//in PM pre_user_meta,
inout MH main_hdr,
inout MM main_user_meta,
in pna_main_input_metadata_t istd,
inout pna_main_output_metadata_t ostd);

control MainDeparserT<MH, MM>(
packet_out pkt,
in MH main_hdr,
in MM main_user_meta,
in pna_main_output_metadata_t ostd);

package PNA_NIC<PH, PM, MH, MM>(
MainParserT<MH, MM> main_parser,
PreControlT<PH, PM> pre_control,
MainControlT<MH, MM> main_control,
MainDeparserT<MH, MM> main_deparser);
// END:Programmable_blocks
#include <pna/v0_5/blocks.p4>

#endif // __PNA_P4__
24 changes: 24 additions & 0 deletions p4include/pna/dev/blocks.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// BEGIN:Programmable_blocks
parser MainParserT<MH, MM>(
packet_in pkt,
out MH main_hdr,
inout MM main_user_meta,
in pna_main_parser_input_metadata_t istd);

control MainControlT<MH, MM>(
inout MH main_hdr,
inout MM main_user_meta,
in pna_main_input_metadata_t istd,
inout pna_main_output_metadata_t ostd);

control MainDeparserT<MH, MM>(
packet_out pkt,
inout MH main_hdr,
in MM main_user_meta,
in pna_main_output_metadata_t ostd);

package PNA_NIC<MH, MM>(
MainParserT<MH, MM> main_parser,
MainControlT<MH, MM> main_control,
MainDeparserT<MH, MM> main_deparser);
// END:Programmable_blocks
31 changes: 31 additions & 0 deletions p4include/pna/v0_5/blocks.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// BEGIN:Programmable_blocks
control PreControlT<PH, PM>(
in PH pre_hdr,
inout PM pre_user_meta,
in pna_pre_input_metadata_t istd,
inout pna_pre_output_metadata_t ostd);

parser MainParserT<MH, MM>(
packet_in pkt,
out MH main_hdr,
inout MM main_user_meta,
in pna_main_parser_input_metadata_t istd);

control MainControlT<MH, MM>(
inout MH main_hdr,
inout MM main_user_meta,
in pna_main_input_metadata_t istd,
inout pna_main_output_metadata_t ostd);

control MainDeparserT<MH, MM>(
packet_out pkt,
in MH main_hdr,
in MM main_user_meta,
in pna_main_output_metadata_t ostd);

package PNA_NIC<PH, PM, MH, MM>(
MainParserT<MH, MM> main_parser,
PreControlT<PH, PM> pre_control,
MainControlT<MH, MM> main_control,
MainDeparserT<MH, MM> main_deparser);
// END:Programmable_blocks
Loading
Loading