Skip to content

Commit

Permalink
* Removed pipeline id from template for tc backend
Browse files Browse the repository at this point in the history
* Removed pipeline id from introspection.json for tc backend
* Updated the testcases outputs
  • Loading branch information
Sosutha committed Feb 27, 2024
1 parent aa39f9f commit 5804d33
Show file tree
Hide file tree
Showing 142 changed files with 472 additions and 123 deletions.
1 change: 0 additions & 1 deletion backends/tc/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ void ConvertToBackendIR::postorder(const IR::P4Table *t) {
void ConvertToBackendIR::postorder(const IR::P4Program *p) {
if (p != nullptr) {
tcPipeline->setPipelineName(pipelineName);
tcPipeline->setPipelineId(TC::DEFAULT_PIPELINE_ID);
tcPipeline->setNumTables(tableCount);
}
}
Expand Down
41 changes: 38 additions & 3 deletions backends/tc/ebpfCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ void PNAEbpfGenerator::emitCommonPreamble(EBPF::CodeBuilder *builder) const {
}

void PNAEbpfGenerator::emitInternalStructures(EBPF::CodeBuilder *builder) const {
builder->appendLine("struct p4tc_filter_fields p4tc_filter_fields;");
builder->newline();
builder->appendLine(
"struct internal_metadata {\n"
" __u16 pkt_ether_type;\n"
Expand Down Expand Up @@ -97,6 +99,37 @@ void PNAEbpfGenerator::emitGlobalHeadersMetadata(EBPF::CodeBuilder *builder) con
builder->newline();
}

void PNAEbpfGenerator::emitP4TCFilterFields(EBPF::CodeBuilder *builder) const {
builder->append("struct p4tc_filter_fields ");
builder->blockStart();

builder->emitIndent();
builder->appendFormat("__u32 pipeid");
builder->endOfStatement(true);
builder->emitIndent();
builder->appendFormat("__u32 handle");
builder->endOfStatement(true);
builder->emitIndent();
builder->appendFormat("__u32 classid");
builder->endOfStatement(true);
builder->emitIndent();
builder->appendFormat("__u32 chain");
builder->endOfStatement(true);
builder->emitIndent();
builder->appendFormat("__u32 blockid");
builder->endOfStatement(true);
builder->emitIndent();
builder->appendFormat("__be16 proto");
builder->endOfStatement(true);
builder->emitIndent();
builder->appendFormat("__u16 prio");
builder->endOfStatement(true);

builder->blockEnd(false);
builder->endOfStatement(true);
builder->newline();
}

void PNAEbpfGenerator::emitPipelineInstances(EBPF::CodeBuilder *builder) const {
pipeline->parser->emitValueSetInstances(builder);
pipeline->deparser->emitDigestInstances(builder);
Expand Down Expand Up @@ -165,6 +198,8 @@ void PNAArchTC::emitParser(EBPF::CodeBuilder *builder) const {
builder->appendFormat("#include \"%s\"", headerFile);
builder->newline();
builder->newline();
builder->appendLine("struct p4tc_filter_fields p4tc_filter_fields;");
builder->newline();
pipeline->name = "tc-parse";
pipeline->sectionName = "p4tc/parse";
pipeline->functionName = pipeline->name.replace("-", "_") + "_func";
Expand All @@ -183,7 +218,7 @@ void PNAArchTC::emitHeader(EBPF::CodeBuilder *builder) const {
PNAErrorCodesGen errorGen(builder);
pipeline->program->apply(errorGen);
emitGlobalHeadersMetadata(builder);
builder->newline();
emitP4TCFilterFields(builder);
// BPF map definitions.
emitInstances(builder);
EBPFHashAlgorithmTypeFactoryPNA::instance()->emitGlobals(builder);
Expand Down Expand Up @@ -1360,7 +1395,7 @@ void ControlBodyTranslatorPNA::processFunction(const P4::ExternFunction *functio
builder->appendLine(
"struct p4tc_table_entry_create_bpf_params__local update_params = {");
builder->emitIndent();
builder->appendLine(" .pipeid = 1,");
builder->appendLine(" .pipeid = p4tc_filter_fields.pipeid,");
builder->emitIndent();
auto controlName = control->controlBlock->getName().originalName;
/* Table instanceName is control_block_name + "_" + original table name.
Expand Down Expand Up @@ -1415,7 +1450,7 @@ void ControlBodyTranslatorPNA::processApply(const P4::ApplyMethod *method) {
builder->emitIndent();
builder->appendLine("struct p4tc_table_entry_act_bpf_params__local params = {");
builder->emitIndent();
builder->appendLine(" .pipeid = 1,");
builder->appendLine(" .pipeid = p4tc_filter_fields.pipeid,");
builder->emitIndent();
auto tblId = tcIR->getTableId(method->object->getName().originalName);
BUG_CHECK(tblId != 0, "Table ID not found");
Expand Down
1 change: 1 addition & 0 deletions backends/tc/ebpfCodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class PNAEbpfGenerator : public EBPF::EbpfCodeGenerator {
void emitTypes(EBPF::CodeBuilder *builder) const override;
void emitGlobalHeadersMetadata(EBPF::CodeBuilder *builder) const override;
void emitPipelineInstances(EBPF::CodeBuilder *builder) const override;
void emitP4TCFilterFields(EBPF::CodeBuilder *builder) const;
cstring getProgramName() const;
};

Expand Down
1 change: 0 additions & 1 deletion backends/tc/introspection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ const Util::JsonObject *IntrospectionGenerator::genIntrospectionJson() {
introspec.initIntrospectionInfo(tcPipeline);
json->emplace("schema_version", introspec.schemaVersion);
json->emplace("pipeline_name", introspec.pipelineName);
json->emplace("id", introspec.pipelineId);
genTableJson(tablesJson);
json->emplace("tables", tablesJson);
return json;
Expand Down
3 changes: 0 additions & 3 deletions backends/tc/introspection.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ namespace TC {
struct IntrospectionInfo {
cstring schemaVersion;
cstring pipelineName;
unsigned int pipelineId;
IntrospectionInfo() {
schemaVersion = nullptr;
pipelineName = nullptr;
pipelineId = 0;
}
void initIntrospectionInfo(IR::TCPipeline *tcPipeline) {
schemaVersion = "1.0.0";
pipelineName = tcPipeline->pipelineName;
pipelineId = tcPipeline->pipelineId;
}
};

Expand Down
7 changes: 1 addition & 6 deletions backends/tc/tc.def
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ class TCTable {

class TCPipeline {
cstring pipelineName;
unsigned pipelineId;
unsigned numTables;
safe_vector<TCAction> actionDefs;
safe_vector<TCTable> tableDefs;
Expand All @@ -335,9 +334,6 @@ class TCPipeline {
void setPipelineName(cstring pName) {
pipelineName = pName;
}
void setPipelineId(unsigned p) {
pipelineId = p;
}
void setNumTables(unsigned n) {
numTables = n;
}
Expand Down Expand Up @@ -365,8 +361,7 @@ class TCPipeline {
std::string tcCode = "#!/bin/bash -x\n";
tcCode += "\nset -e\n";
tcCode += "\nTC=\"tc\"";
tcCode += "\n$TC p4template create pipeline/" + pipelineName + " pipeid ";
tcCode += Util::toString(pipelineId);
tcCode += "\n$TC p4template create pipeline/" + pipelineName;
tcCode += " numtables ";
tcCode += Util::toString(numTables);
if (!actionDefs.empty()) {
Expand Down
1 change: 0 additions & 1 deletion backends/tc/tc_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ inline constexpr auto DEFAULT_TABLE_ENTRIES = 2048;
inline constexpr auto DEFAULT_KEY_MASK = 8;
inline constexpr auto PORTID_BITWIDTH = 32;
inline constexpr auto DEFAULT_KEY_ID = 1;
inline constexpr auto DEFAULT_PIPELINE_ID = 1;
inline constexpr auto DEFAULT_METADATA_ID = 1;
inline constexpr auto BITWIDTH = 32;

Expand Down
1 change: 0 additions & 1 deletion testdata/p4tc_samples_outputs/calculator.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"schema_version" : "1.0.0",
"pipeline_name" : "calculator",
"id" : 1,
"tables" : [
{
"name" : "MainControlImpl/calculate",
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4tc_samples_outputs/calculator.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

TC="tc"
$TC p4template create pipeline/calculator pipeid 1 numtables 1
$TC p4template create pipeline/calculator numtables 1

$TC p4template create action/calculator/MainControlImpl/operation_add actid 1
$TC p4template update action/calculator/MainControlImpl/operation_add state active
Expand Down
4 changes: 3 additions & 1 deletion testdata/p4tc_samples_outputs/calculator_control_blocks.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "calculator_parser.h"
struct p4tc_filter_fields p4tc_filter_fields;

struct internal_metadata {
__u16 pkt_ether_type;
} __attribute__((aligned(4)));
Expand Down Expand Up @@ -65,7 +67,7 @@ if (/* hdr->p4calc.isValid() */
{
/* construct key */
struct p4tc_table_entry_act_bpf_params__local params = {
.pipeid = 1,
.pipeid = p4tc_filter_fields.pipeid,
.tblid = 1
};
struct MainControlImpl_calculate_key key = {};
Expand Down
2 changes: 2 additions & 0 deletions testdata/p4tc_samples_outputs/calculator_parser.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "calculator_parser.h"

struct p4tc_filter_fields p4tc_filter_fields;

static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
9 changes: 9 additions & 0 deletions testdata/p4tc_samples_outputs/calculator_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ struct hdr_md {
__u8 __hook;
};

struct p4tc_filter_fields {
__u32 pipeid;
__u32 handle;
__u32 classid;
__u32 chain;
__u32 blockid;
__be16 proto;
__u16 prio;
};

REGISTER_START()
REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2)
Expand Down
1 change: 0 additions & 1 deletion testdata/p4tc_samples_outputs/checksum.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"schema_version" : "1.0.0",
"pipeline_name" : "checksum",
"id" : 1,
"tables" : [
{
"name" : "ingress/nh_table",
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4tc_samples_outputs/checksum.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

TC="tc"
$TC p4template create pipeline/checksum pipeid 1 numtables 1
$TC p4template create pipeline/checksum numtables 1

$TC p4template create action/checksum/ingress/send_nh actid 1 \
param port_id type dev \
Expand Down
4 changes: 3 additions & 1 deletion testdata/p4tc_samples_outputs/checksum_control_blocks.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "checksum_parser.h"
struct p4tc_filter_fields p4tc_filter_fields;

struct internal_metadata {
__u16 pkt_ether_type;
} __attribute__((aligned(4)));
Expand Down Expand Up @@ -53,7 +55,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head
{
/* construct key */
struct p4tc_table_entry_act_bpf_params__local params = {
.pipeid = 1,
.pipeid = p4tc_filter_fields.pipeid,
.tblid = 1
};
struct ingress_nh_table_key key = {};
Expand Down
2 changes: 2 additions & 0 deletions testdata/p4tc_samples_outputs/checksum_parser.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "checksum_parser.h"

struct p4tc_filter_fields p4tc_filter_fields;

static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
9 changes: 9 additions & 0 deletions testdata/p4tc_samples_outputs/checksum_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ struct hdr_md {
__u8 __hook;
};

struct p4tc_filter_fields {
__u32 pipeid;
__u32 handle;
__u32 classid;
__u32 chain;
__u32 blockid;
__be16 proto;
__u16 prio;
};

REGISTER_START()
REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"schema_version" : "1.0.0",
"pipeline_name" : "const_entries_range_mask",
"id" : 1,
"tables" : [
{
"name" : "MainControlImpl/t_range",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

TC="tc"
$TC p4template create pipeline/const_entries_range_mask pipeid 1 numtables 1
$TC p4template create pipeline/const_entries_range_mask numtables 1

$TC p4template create action/const_entries_range_mask/MainControlImpl/a actid 1
$TC p4template update action/const_entries_range_mask/MainControlImpl/a state active
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "const_entries_range_mask_parser.h"
struct p4tc_filter_fields p4tc_filter_fields;

struct internal_metadata {
__u16 pkt_ether_type;
} __attribute__((aligned(4)));
Expand Down Expand Up @@ -51,7 +53,7 @@ static __always_inline int process(struct __sk_buff *skb, struct Header_t *h, st
{
/* construct key */
struct p4tc_table_entry_act_bpf_params__local params = {
.pipeid = 1,
.pipeid = p4tc_filter_fields.pipeid,
.tblid = 1
};
struct MainControlImpl_t_range_key key = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "const_entries_range_mask_parser.h"

struct p4tc_filter_fields p4tc_filter_fields;

static __always_inline int run_parser(struct __sk_buff *skb, struct Header_t *h, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ struct hdr_md {
__u8 __hook;
};

struct p4tc_filter_fields {
__u32 pipeid;
__u32 handle;
__u32 classid;
__u32 chain;
__u32 blockid;
__be16 proto;
__u16 prio;
};

REGISTER_START()
REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2)
Expand Down
1 change: 0 additions & 1 deletion testdata/p4tc_samples_outputs/default_action_example.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"schema_version" : "1.0.0",
"pipeline_name" : "default_action_example",
"id" : 1,
"tables" : [
{
"name" : "MainControlImpl/ipv4_tbl_1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

TC="tc"
$TC p4template create pipeline/default_action_example pipeid 1 numtables 2
$TC p4template create pipeline/default_action_example numtables 2

$TC p4template create action/default_action_example/MainControlImpl/next_hop actid 1 \
param vport type bit32
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "default_action_example_parser.h"
struct p4tc_filter_fields p4tc_filter_fields;

struct internal_metadata {
__u16 pkt_ether_type;
} __attribute__((aligned(4)));
Expand Down Expand Up @@ -75,7 +77,7 @@ if (/* hdr->ipv4.isValid() */
{
/* construct key */
struct p4tc_table_entry_act_bpf_params__local params = {
.pipeid = 1,
.pipeid = p4tc_filter_fields.pipeid,
.tblid = 1
};
struct MainControlImpl_ipv4_tbl_1_key key = {};
Expand Down Expand Up @@ -123,7 +125,7 @@ if (/* hdr->ipv4.isValid() */
{
/* construct key */
struct p4tc_table_entry_act_bpf_params__local params = {
.pipeid = 1,
.pipeid = p4tc_filter_fields.pipeid,
.tblid = 2
};
struct MainControlImpl_ipv4_tbl_2_key key = {};
Expand Down
2 changes: 2 additions & 0 deletions testdata/p4tc_samples_outputs/default_action_example_parser.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "default_action_example_parser.h"

struct p4tc_filter_fields p4tc_filter_fields;

static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
9 changes: 9 additions & 0 deletions testdata/p4tc_samples_outputs/default_action_example_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ struct hdr_md {
__u8 __hook;
};

struct p4tc_filter_fields {
__u32 pipeid;
__u32 handle;
__u32 classid;
__u32 chain;
__u32 blockid;
__be16 proto;
__u16 prio;
};

REGISTER_START()
REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2)
Expand Down
Loading

0 comments on commit 5804d33

Please sign in to comment.