diff --git a/backends/tc/backend.cpp b/backends/tc/backend.cpp index 93793c0eede..30faa11bb25 100644 --- a/backends/tc/backend.cpp +++ b/backends/tc/backend.cpp @@ -1037,9 +1037,14 @@ void ConvertToBackendIR::postorder(const IR::Declaration_Instance *decl) { if (iterator == externsInfo.end()) { struct ExternBlock *eb = new struct ExternBlock(); if (eName == "DirectCounter") { - eb->externId = 101; + eb->externId = "0x1A000000"_cs; + } else if (eName == "Counter") { + eb->externId = "0x19000000"_cs; } else { - eb->externId = ++externCount; + externCount += 1; + std::stringstream value; + value << "0x" << std::hex << externCount; + eb->externId = value.str(); } eb->permissions = processExternPermission(extn); eb->no_of_instances += 1; @@ -1200,11 +1205,11 @@ unsigned ConvertToBackendIR::getActionId(cstring actionName) const { return 0; } -unsigned ConvertToBackendIR::getExternId(cstring externName) const { +cstring ConvertToBackendIR::getExternId(cstring externName) const { for (auto e : externsInfo) { if (e.first == externName) return e.second->externId; } - return 0; + return ""_cs; } unsigned ConvertToBackendIR::getExternInstanceId(cstring externName, cstring instanceName) const { diff --git a/backends/tc/backend.h b/backends/tc/backend.h index 935a0f72756..9b707306216 100644 --- a/backends/tc/backend.h +++ b/backends/tc/backend.h @@ -55,7 +55,7 @@ class ConvertToBackendIR : public Inspector { int num_elements; }; struct ExternBlock { - unsigned externId; + cstring externId; cstring control_name; unsigned no_of_instances; cstring permissions; @@ -119,7 +119,7 @@ class ConvertToBackendIR : public Inspector { unsigned getTcType(const IR::StringLiteral *sl); unsigned getTableId(cstring tableName) const; unsigned getActionId(cstring actionName) const; - unsigned getExternId(cstring externName) const; + cstring getExternId(cstring externName) const; unsigned getExternInstanceId(cstring externName, cstring instanceName) const; cstring processExternPermission(const IR::Type_Extern *ext); unsigned getTableKeysize(unsigned tableId) const; diff --git a/backends/tc/ebpfCodeGen.cpp b/backends/tc/ebpfCodeGen.cpp index cc6506416c2..57787cbf43f 100644 --- a/backends/tc/ebpfCodeGen.cpp +++ b/backends/tc/ebpfCodeGen.cpp @@ -1456,6 +1456,10 @@ bool ConvertToEBPFControlPNA::preorder(const IR::ExternBlock *instance) { } else if (typeName == "DirectCounter") { control->addExternDeclaration = true; return false; + } else if (typeName == "Counter") { + control->addExternDeclaration = true; + auto ctr = new EBPFCounterPNA(program, di, name, control->codeGen); + control->counters.emplace(name, ctr); } else { ::error(ErrorType::ERR_UNEXPECTED, "Unexpected block %s nested within control", instance); } @@ -1940,6 +1944,11 @@ void ControlBodyTranslatorPNA::processMethod(const P4::ExternMethod *method) { reg->emitRegisterRead(builder, method, this, nullptr); } return; + } else if (declType->name.name == "Counter") { + auto counterMap = control->getCounter(name); + auto pna_ctr = dynamic_cast(counterMap); + pna_ctr->emitMethodInvocation(builder, method, this); + return; } else if (declType->name.name == "Hash") { auto hash = control->to()->getHash(name); hash->processMethod(builder, method->method->name.name, method->expr, this); diff --git a/backends/tc/introspection.h b/backends/tc/introspection.h index 1a2d72a3084..ab40c256ee3 100644 --- a/backends/tc/introspection.h +++ b/backends/tc/introspection.h @@ -133,7 +133,7 @@ struct ExternInstancesAttributes { struct ExternAttributes { cstring name; cstring permissions; - unsigned int id; + cstring id; safe_vector instances; ExternAttributes() { name = nullptr; diff --git a/backends/tc/tc.def b/backends/tc/tc.def index 804d58108e6..ad2701d4a93 100644 --- a/backends/tc/tc.def +++ b/backends/tc/tc.def @@ -529,11 +529,11 @@ class TCExtern { cstring externName; cstring pipelineName; cstring acl_permisson; - unsigned externID; + cstring externID; unsigned numinstances; safe_vector externInstances; bool has_exec_method; - TCExtern(unsigned eId, cstring eN, cstring pN, unsigned inst, cstring p, bool exec_method) { + TCExtern(cstring eId, cstring eN, cstring pN, unsigned inst, cstring p, bool exec_method) { externID = eId; externName = eN; pipelineName = pN; @@ -556,7 +556,7 @@ class TCExtern { std::string tcExtern = ""; tcExtern += "\n$TC p4template create extern/"; tcExtern += "root/" + externName; - tcExtern += " extid " + Util::toString(externID); + tcExtern += " extid " + externID; tcExtern += " numinstances " + Util::toString(numinstances); tcExtern += " tc_acl " + acl_permisson; if (has_exec_method) { diff --git a/backends/tc/tcExterns.cpp b/backends/tc/tcExterns.cpp index 4b92c2bac5d..08dbb369160 100644 --- a/backends/tc/tcExterns.cpp +++ b/backends/tc/tcExterns.cpp @@ -28,8 +28,8 @@ void EBPFRegisterPNA::emitInitializer(EBPF::CodeBuilder *builder, const P4::Exte builder->appendLine("ext_params.pipe_id = p4tc_filter_fields.pipeid;"); builder->emitIndent(); auto extId = translator->tcIR->getExternId(externName); - BUG_CHECK(extId != 0, "Extern ID not found"); - builder->appendFormat("ext_params.ext_id = %d;", extId); + BUG_CHECK(!extId.isNullOrEmpty(), "Extern ID not found"); + builder->appendFormat("ext_params.ext_id = %s;", extId); builder->newline(); builder->emitIndent(); auto instId = translator->tcIR->getExternInstanceId(externName, this->instanceName); @@ -126,4 +126,57 @@ void EBPFCounterPNA::emitCounterUpdate(EBPF::CodeBuilder *builder, const Convert } } +void EBPFCounterPNA::emitMethodInvocation(EBPF::CodeBuilder *builder, + const P4::ExternMethod *method, + ControlBodyTranslatorPNA *translator) { + if (method->method->name.name != "count") { + ::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1%", method->expr); + return; + } + BUG_CHECK(!isDirect, "DirectCounter used outside of table"); + BUG_CHECK(method->expr->arguments->size() == 1, "Expected just 1 argument for %1%", + method->expr); + emitCount(builder, method, translator); +} + +void EBPFCounterPNA::emitCount(EBPF::CodeBuilder *builder, const P4::ExternMethod *method, + ControlBodyTranslatorPNA *translator) { + builder->emitIndent(); + builder->appendLine("__builtin_memset(&ext_params, 0, sizeof(struct p4tc_ext_bpf_params));"); + builder->emitIndent(); + builder->appendLine("ext_params.pipe_id = p4tc_filter_fields.pipeid;"); + auto externName = method->originalExternType->name.name; + auto instanceName = di->toString(); + auto index = method->expr->arguments->at(0)->expression; + builder->emitIndent(); + auto extId = translator->tcIR->getExternId(externName); + BUG_CHECK(!extId.isNullOrEmpty(), "Extern ID not found"); + builder->appendFormat("ext_params.ext_id = %s;", extId); + builder->newline(); + builder->emitIndent(); + auto instId = translator->tcIR->getExternInstanceId(externName, instanceName); + BUG_CHECK(instId != 0, "Extern instance ID not found"); + builder->appendFormat("ext_params.inst_id = %d;", instId); + builder->newline(); + builder->emitIndent(); + builder->append("ext_params.index = "); + translator->visit(index); + builder->endOfStatement(true); + builder->newline(); + builder->emitIndent(); + builder->appendLine("ext_params.flags = P4TC_EXT_CNT_INDIRECT;"); + builder->emitIndent(); + + if (type == CounterType::BYTES) { + builder->append( + "bpf_p4tc_extern_count_bytes(skb, &ext_params, sizeof(ext_params), NULL, 0)"); + } else if (type == CounterType::PACKETS) { + builder->append( + "bpf_p4tc_extern_count_pkts(skb, &ext_params, sizeof(ext_params), NULL, 0)"); + } else if (type == CounterType::PACKETS_AND_BYTES) { + builder->append( + "bpf_p4tc_extern_count_pktsnbytes(skb, &ext_params, sizeof(ext_params), NULL, 0)"); + } +} + } // namespace TC diff --git a/backends/tc/tcExterns.h b/backends/tc/tcExterns.h index 5fcce427760..6910b42e07f 100644 --- a/backends/tc/tcExterns.h +++ b/backends/tc/tcExterns.h @@ -25,6 +25,7 @@ class ControlBodyTranslatorPNA; class ConvertToBackendIR; class EBPFCounterPNA : public EBPF::EBPFCounterPSA { + const IR::Declaration_Instance *di; cstring tblname; public: @@ -32,10 +33,21 @@ class EBPFCounterPNA : public EBPF::EBPFCounterPSA { cstring name, EBPF::CodeGenInspector *codeGen, cstring tblname) : EBPF::EBPFCounterPSA(program, di, name, codeGen) { this->tblname = tblname; + this->di = di; } + EBPFCounterPNA(const EBPF::EBPFProgram *program, const IR::Declaration_Instance *di, + cstring name, EBPF::CodeGenInspector *codeGen) + : EBPF::EBPFCounterPSA(program, di, name, codeGen) { + this->di = di; + } + void emitDirectMethodInvocation(EBPF::CodeBuilder *builder, const P4::ExternMethod *method, const ConvertToBackendIR *tcIR); + void emitMethodInvocation(EBPF::CodeBuilder *builder, const P4::ExternMethod *method, + ControlBodyTranslatorPNA *translator); virtual void emitCounterUpdate(EBPF::CodeBuilder *builder, const ConvertToBackendIR *tcIR); + virtual void emitCount(EBPF::CodeBuilder *builder, const P4::ExternMethod *method, + ControlBodyTranslatorPNA *translator); }; class EBPFRegisterPNA : public EBPF::EBPFTableBase { diff --git a/p4include/tc/pna.p4 b/p4include/tc/pna.p4 index 84f422e52a0..e7cb518ce8a 100644 --- a/p4include/tc/pna.p4 +++ b/p4include/tc/pna.p4 @@ -437,13 +437,19 @@ enum PNA_CounterType_t { /// Indirect counter with n_counters independent counter values, where /// every counter value has a data plane size specified by type W. -@noWarn("unused") +@noWarn("unused") @tc_acl("RP:RUXP") extern Counter { - Counter(bit<32> n_counters, PNA_CounterType_t type); - void count(in S index); + Counter(@tc_numel bit<32> n_counters, PNA_CounterType_t type); + @tc_md_exec void count(in S index); } // END:Counter_extern +struct tc_ControlPath_Counter { + @tc_key S index; + @tc_data W pkts; + @tc_data W bytes; +} + // BEGIN:DirectCounter_extern @noWarn("unused") @tc_acl("RP:RUXP") extern DirectCounter { diff --git a/testdata/p4tc_samples/indirect_counter_01_example.p4 b/testdata/p4tc_samples/indirect_counter_01_example.p4 new file mode 100644 index 00000000000..764d6fa31ac --- /dev/null +++ b/testdata/p4tc_samples/indirect_counter_01_example.p4 @@ -0,0 +1,130 @@ +/* -*- P4_16 -*- */ + +#include +#include + +#define PORT_TABLE_SIZE 2048 + +/* + * Standard ethernet header + */ +header ethernet_t { + @tc_type ("macaddr") bit<48> dstAddr; + @tc_type ("macaddr") bit<48> 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; + bit<32> srcAddr; + bit<32> dstAddr; +} + +struct my_ingress_headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +/****** G L O B A L I N G R E S S M E T A D A T A *********/ + +struct my_ingress_metadata_t { +} + +struct empty_metadata_t { +} + +/*********************** P A R S E R **************************/ + +parser Ingress_Parser( + packet_in pkt, + out my_ingress_headers_t hdr, + inout my_ingress_metadata_t meta, + in pna_main_parser_input_metadata_t istd) +{ + const bit<16> ETHERTYPE_IPV4 = 0x0800; + + state start { + transition parse_ethernet; + } + state parse_ethernet { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + ETHERTYPE_IPV4 : parse_ipv4; + default : reject; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + transition accept; + } +} + +/***************** M A T C H - A C T I O N *********************/ + +typedef bit<64> PacketByteCounter_t; + +control ingress( + inout my_ingress_headers_t hdr, + inout my_ingress_metadata_t meta, + in pna_main_input_metadata_t istd, + inout pna_main_output_metadata_t ostd +) +{ + Counter, bit<32>>(2048, PNA_CounterType_t.PACKETS) global_counter; + + action send_nh(@tc_type("dev") PortId_t port_id, @tc_type("macaddr") bit<48> dmac, @tc_type("macaddr") bit<48> smac) { + hdr.ethernet.srcAddr = smac; + hdr.ethernet.dstAddr = dmac; + send_to_port(port_id); + global_counter.count(3); + } + action drop() { + drop_packet(); + } + @tc_acl("CRUDPS:RX") table nh_table { + key = { + hdr.ipv4.srcAddr : exact @tc_type ("ipv4"); + } + actions = { + send_nh; + drop; + } + size = PORT_TABLE_SIZE; + const default_action = drop; + } + + apply { + nh_table.apply(); + } +} + +/********************* D E P A R S E R ************************/ + +control Ingress_Deparser( + packet_out pkt, + inout my_ingress_headers_t hdr, + in my_ingress_metadata_t meta, + in pna_main_output_metadata_t ostd) +{ + apply { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + } +} + +/************ F I N A L P A C K A G E ******************************/ + +PNA_NIC( + Ingress_Parser(), + ingress(), + Ingress_Deparser() +) main; diff --git a/testdata/p4tc_samples_outputs/direct_counter_example.json b/testdata/p4tc_samples_outputs/direct_counter_example.json index c80d2914497..90663fcd660 100644 --- a/testdata/p4tc_samples_outputs/direct_counter_example.json +++ b/testdata/p4tc_samples_outputs/direct_counter_example.json @@ -4,7 +4,7 @@ "externs" : [ { "name" : "DirectCounter", - "id" : 101, + "id" : "0x1A000000", "permissions" : "0x1136", "instances" : [ { diff --git a/testdata/p4tc_samples_outputs/direct_counter_example.template b/testdata/p4tc_samples_outputs/direct_counter_example.template index 1ab7be637ad..5e8ca0d323f 100755 --- a/testdata/p4tc_samples_outputs/direct_counter_example.template +++ b/testdata/p4tc_samples_outputs/direct_counter_example.template @@ -14,7 +14,7 @@ $TC p4template update action/direct_counter_example/ingress/send_nh state active $TC p4template create action/direct_counter_example/ingress/drop actid 2 $TC p4template update action/direct_counter_example/ingress/drop state active -$TC p4template create extern/root/DirectCounter extid 101 numinstances 1 tc_acl 0x1136 has_exec_method +$TC p4template create extern/root/DirectCounter extid 0x1A000000 numinstances 1 tc_acl 0x1136 has_exec_method $TC p4template create extern_inst/direct_counter_example/DirectCounter/ingress.global_counter instid 1 \ tc_numel 2048 tbl_bindable constructor param type ptype bit32 0 \ diff --git a/testdata/p4tc_samples_outputs/indirect_counter_01_example.json b/testdata/p4tc_samples_outputs/indirect_counter_01_example.json new file mode 100644 index 00000000000..3b551ac7405 --- /dev/null +++ b/testdata/p4tc_samples_outputs/indirect_counter_01_example.json @@ -0,0 +1,91 @@ +{ + "schema_version" : "1.0.0", + "pipeline_name" : "indirect_counter_01_example", + "externs" : [ + { + "name" : "Counter", + "id" : "0x19000000", + "permissions" : "0x1136", + "instances" : [ + { + "inst_name" : "ingress.global_counter", + "inst_id" : 1, + "params" : [ + { + "id" : 1, + "name" : "index", + "type" : "bit32", + "attr" : "tc_key", + "bitwidth" : 32 + }, + { + "id" : 2, + "name" : "pkts", + "type" : "bit64", + "attr" : "param", + "bitwidth" : 64 + } + ] + } + ] + } + ], + "tables" : [ + { + "name" : "ingress/nh_table", + "id" : 1, + "tentries" : 2048, + "permissions" : "0x3da4", + "nummask" : 8, + "keysize" : 32, + "keyfields" : [ + { + "id" : 1, + "name" : "hdr.ipv4.srcAddr", + "type" : "ipv4", + "match_type" : "exact", + "bitwidth" : 32 + } + ], + "actions" : [ + { + "id" : 1, + "name" : "ingress/send_nh", + "action_scope" : "TableAndDefault", + "annotations" : [], + "params" : [ + { + "id" : 1, + "name" : "port_id", + "type" : "dev", + "bitwidth" : 32 + }, + { + "id" : 2, + "name" : "dmac", + "type" : "macaddr", + "bitwidth" : 48 + }, + { + "id" : 3, + "name" : "smac", + "type" : "macaddr", + "bitwidth" : 48 + } + ], + "default_hit_action" : false, + "default_miss_action" : false + }, + { + "id" : 2, + "name" : "ingress/drop", + "action_scope" : "TableAndDefault", + "annotations" : [], + "params" : [], + "default_hit_action" : false, + "default_miss_action" : true + } + ] + } + ] +} \ No newline at end of file diff --git a/testdata/p4tc_samples_outputs/indirect_counter_01_example.p4-stderr b/testdata/p4tc_samples_outputs/indirect_counter_01_example.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4tc_samples_outputs/indirect_counter_01_example.template b/testdata/p4tc_samples_outputs/indirect_counter_01_example.template new file mode 100755 index 00000000000..c3260c7dd94 --- /dev/null +++ b/testdata/p4tc_samples_outputs/indirect_counter_01_example.template @@ -0,0 +1,30 @@ +#!/bin/bash -x + +set -e + +TC="tc" +$TC p4template create pipeline/indirect_counter_01_example numtables 1 + +$TC p4template create action/indirect_counter_01_example/ingress/send_nh actid 1 \ + param port_id type dev \ + param dmac type macaddr \ + param smac type macaddr +$TC p4template update action/indirect_counter_01_example/ingress/send_nh state active + +$TC p4template create action/indirect_counter_01_example/ingress/drop actid 2 +$TC p4template update action/indirect_counter_01_example/ingress/drop state active + +$TC p4template create extern/root/Counter extid 0x19000000 numinstances 1 tc_acl 0x1136 has_exec_method + +$TC p4template create extern_inst/indirect_counter_01_example/Counter/ingress.global_counter instid 1 \ +tc_numel 2048 constructor param type ptype bit32 0 \ +control_path tc_key index ptype bit32 id 1 param pkts ptype bit64 id 2 + +$TC p4template create table/indirect_counter_01_example/ingress/nh_table \ + tblid 1 \ + type exact \ + keysz 32 nummasks 8 permissions 0x3da4 tentries 2048 \ + table_acts act name indirect_counter_01_example/ingress/send_nh \ + act name indirect_counter_01_example/ingress/drop +$TC p4template update table/indirect_counter_01_example/ingress/nh_table default_miss_action permissions 0x1024 action indirect_counter_01_example/ingress/drop +$TC p4template update pipeline/indirect_counter_01_example state ready \ No newline at end of file diff --git a/testdata/p4tc_samples_outputs/indirect_counter_01_example_control_blocks.c b/testdata/p4tc_samples_outputs/indirect_counter_01_example_control_blocks.c new file mode 100644 index 00000000000..94b76ecd9fa --- /dev/null +++ b/testdata/p4tc_samples_outputs/indirect_counter_01_example_control_blocks.c @@ -0,0 +1,308 @@ +#include "indirect_counter_01_example_parser.h" +struct p4tc_filter_fields p4tc_filter_fields; + +struct internal_metadata { + __u16 pkt_ether_type; +} __attribute__((aligned(4))); + +struct __attribute__((__packed__)) ingress_nh_table_key { + u32 keysz; + u32 maskid; + u32 field0; /* hdr.ipv4.srcAddr */ +} __attribute__((aligned(8))); +#define INGRESS_NH_TABLE_ACT_INGRESS_SEND_NH 1 +#define INGRESS_NH_TABLE_ACT_INGRESS_DROP 2 +#define INGRESS_NH_TABLE_ACT_NOACTION 0 +struct __attribute__((__packed__)) ingress_nh_table_value { + unsigned int action; + u32 hit:1, + is_default_miss_act:1, + is_default_hit_act:1; + union { + struct { + } _NoAction; + struct __attribute__((__packed__)) { + u32 port_id; + u64 dmac; + u64 smac; + } ingress_send_nh; + struct { + } ingress_drop; + } u; +}; +struct ingress_global_counter_value { + u64 packets; +}; + +static __always_inline int process(struct __sk_buff *skb, struct my_ingress_headers_t *hdr, struct pna_global_metadata *compiler_meta__) +{ + struct hdr_md *hdrMd; + + unsigned ebpf_packetOffsetInBits_save = 0; + ParserError_t ebpf_errorCode = NoError; + void* pkt = ((void*)(long)skb->data); + u8* hdr_start = pkt; + void* ebpf_packetEnd = ((void*)(long)skb->data_end); + u32 ebpf_zero = 0; + u32 ebpf_one = 1; + unsigned char ebpf_byte; + u32 pkt_len = skb->len; + + struct my_ingress_metadata_t *meta; + hdrMd = BPF_MAP_LOOKUP_ELEM(hdr_md_cpumap, &ebpf_zero); + if (!hdrMd) + return TC_ACT_SHOT; + unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits; + hdr_start = pkt + BYTES(ebpf_packetOffsetInBits); + hdr = &(hdrMd->cpumap_hdr); + meta = &(hdrMd->cpumap_usermeta); +{ + struct p4tc_ext_bpf_params ext_params = {}; + struct p4tc_ext_bpf_val ext_val = {}; + struct p4tc_ext_bpf_val *ext_val_ptr; + u8 hit; + { +/* nh_table_0.apply() */ + { + /* construct key */ + struct p4tc_table_entry_act_bpf_params__local params = { + .pipeid = p4tc_filter_fields.pipeid, + .tblid = 1 + }; + struct ingress_nh_table_key key; + __builtin_memset(&key, 0, sizeof(key)); + key.keysz = 32; + key.field0 = bpf_htonl(hdr->ipv4.srcAddr); + struct p4tc_table_entry_act_bpf *act_bpf; + /* value */ + struct ingress_nh_table_value *value = NULL; + /* perform lookup */ + act_bpf = bpf_p4tc_tbl_read(skb, ¶ms, sizeof(params), &key, sizeof(key)); + value = (struct ingress_nh_table_value *)act_bpf; + if (value == NULL) { + /* miss; find default action */ + hit = 0; + } else { + hit = value->hit; + } + if (value != NULL) { + /* run action */ + switch (value->action) { + case INGRESS_NH_TABLE_ACT_INGRESS_SEND_NH: + { + hdr->ethernet.srcAddr = value->u.ingress_send_nh.smac; + hdr->ethernet.dstAddr = value->u.ingress_send_nh.dmac; + /* send_to_port(value->u.ingress_send_nh.port_id) */ + compiler_meta__->drop = false; + send_to_port(value->u.ingress_send_nh.port_id); + /* global_counter_0.count(3) */ + __builtin_memset(&ext_params, 0, sizeof(struct p4tc_ext_bpf_params)); + ext_params.pipe_id = p4tc_filter_fields.pipeid; + ext_params.ext_id = 0x19000000; + ext_params.inst_id = 1; + ext_params.index = 3; + + ext_params.flags = P4TC_EXT_CNT_INDIRECT; + bpf_p4tc_extern_count_pkts(skb, &ext_params, sizeof(ext_params), NULL, 0); + } + break; + case INGRESS_NH_TABLE_ACT_INGRESS_DROP: + { +/* drop_packet() */ + drop_packet(); + } + break; + case INGRESS_NH_TABLE_ACT_NOACTION: + { + } + break; + } + } else { + } + } +; + } + } + { +{ +; + ; + } + + if (compiler_meta__->drop) { + return TC_ACT_SHOT; + } + int outHeaderLength = 0; + if (hdr->ethernet.ebpf_valid) { + outHeaderLength += 112; + } +; if (hdr->ipv4.ebpf_valid) { + outHeaderLength += 160; + } +; + int outHeaderOffset = BYTES(outHeaderLength) - (hdr_start - (u8*)pkt); + if (outHeaderOffset != 0) { + int returnCode = 0; + returnCode = bpf_skb_adjust_room(skb, outHeaderOffset, 1, 0); + if (returnCode) { + return TC_ACT_SHOT; + } + } + pkt = ((void*)(long)skb->data); + ebpf_packetEnd = ((void*)(long)skb->data_end); + ebpf_packetOffsetInBits = 0; + if (hdr->ethernet.ebpf_valid) { + if (ebpf_packetEnd < pkt + BYTES(ebpf_packetOffsetInBits + 112)) { + return TC_ACT_SHOT; + } + + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[4]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 4, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[5]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 5, (ebpf_byte)); + ebpf_packetOffsetInBits += 48; + + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[4]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 4, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[5]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 5, (ebpf_byte)); + ebpf_packetOffsetInBits += 48; + + hdr->ethernet.etherType = bpf_htons(hdr->ethernet.etherType); + ebpf_byte = ((char*)(&hdr->ethernet.etherType))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.etherType))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_packetOffsetInBits += 16; + + } +; if (hdr->ipv4.ebpf_valid) { + if (ebpf_packetEnd < pkt + BYTES(ebpf_packetOffsetInBits + 160)) { + return TC_ACT_SHOT; + } + + ebpf_byte = ((char*)(&hdr->ipv4.version))[0]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0, 4, 4, (ebpf_byte >> 0)); + ebpf_packetOffsetInBits += 4; + + ebpf_byte = ((char*)(&hdr->ipv4.ihl))[0]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0, 4, 0, (ebpf_byte >> 0)); + ebpf_packetOffsetInBits += 4; + + ebpf_byte = ((char*)(&hdr->ipv4.diffserv))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_packetOffsetInBits += 8; + + hdr->ipv4.totalLen = bpf_htons(hdr->ipv4.totalLen); + ebpf_byte = ((char*)(&hdr->ipv4.totalLen))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.totalLen))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_packetOffsetInBits += 16; + + hdr->ipv4.identification = bpf_htons(hdr->ipv4.identification); + ebpf_byte = ((char*)(&hdr->ipv4.identification))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.identification))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_packetOffsetInBits += 16; + + ebpf_byte = ((char*)(&hdr->ipv4.flags))[0]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0, 3, 5, (ebpf_byte >> 0)); + ebpf_packetOffsetInBits += 3; + + hdr->ipv4.fragOffset = bpf_htons(hdr->ipv4.fragOffset << 3); + ebpf_byte = ((char*)(&hdr->ipv4.fragOffset))[0]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0, 5, 0, (ebpf_byte >> 3)); + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0 + 1, 3, 5, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.fragOffset))[1]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 1, 5, 0, (ebpf_byte >> 3)); + ebpf_packetOffsetInBits += 13; + + ebpf_byte = ((char*)(&hdr->ipv4.ttl))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_packetOffsetInBits += 8; + + ebpf_byte = ((char*)(&hdr->ipv4.protocol))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_packetOffsetInBits += 8; + + hdr->ipv4.hdrChecksum = bpf_htons(hdr->ipv4.hdrChecksum); + ebpf_byte = ((char*)(&hdr->ipv4.hdrChecksum))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.hdrChecksum))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_packetOffsetInBits += 16; + + hdr->ipv4.srcAddr = htonl(hdr->ipv4.srcAddr); + ebpf_byte = ((char*)(&hdr->ipv4.srcAddr))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.srcAddr))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.srcAddr))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.srcAddr))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_packetOffsetInBits += 32; + + hdr->ipv4.dstAddr = htonl(hdr->ipv4.dstAddr); + ebpf_byte = ((char*)(&hdr->ipv4.dstAddr))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.dstAddr))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.dstAddr))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.dstAddr))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_packetOffsetInBits += 32; + + } +; + } + return -1; +} +SEC("p4tc/main") +int tc_ingress_func(struct __sk_buff *skb) { + struct pna_global_metadata *compiler_meta__ = (struct pna_global_metadata *) skb->cb; + if (compiler_meta__->pass_to_kernel == true) return TC_ACT_OK; + if (!compiler_meta__->recirculated) { + compiler_meta__->mark = 153; + struct internal_metadata *md = (struct internal_metadata *)(unsigned long)skb->data_meta; + if ((void *) ((struct internal_metadata *) md + 1) <= (void *)(long)skb->data) { + __u16 *ether_type = (__u16 *) ((void *) (long)skb->data + 12); + if ((void *) ((__u16 *) ether_type + 1) > (void *) (long) skb->data_end) { + return TC_ACT_SHOT; + } + *ether_type = md->pkt_ether_type; + } + } + struct hdr_md *hdrMd; + struct my_ingress_headers_t *hdr; + int ret = -1; + ret = process(skb, (struct my_ingress_headers_t *) hdr, compiler_meta__); + if (ret != -1) { + return ret; + } + if (!compiler_meta__->drop && compiler_meta__->egress_port == 0) { + compiler_meta__->pass_to_kernel = true; + return bpf_redirect(skb->ifindex, BPF_F_INGRESS); + } + return bpf_redirect(compiler_meta__->egress_port, 0); +} +char _license[] SEC("license") = "GPL"; diff --git a/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.c b/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.c new file mode 100644 index 00000000000..aa8785b57e8 --- /dev/null +++ b/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.c @@ -0,0 +1,136 @@ +#include "indirect_counter_01_example_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; + + unsigned ebpf_packetOffsetInBits_save = 0; + ParserError_t ebpf_errorCode = NoError; + void* pkt = ((void*)(long)skb->data); + u8* hdr_start = pkt; + void* ebpf_packetEnd = ((void*)(long)skb->data_end); + u32 ebpf_zero = 0; + u32 ebpf_one = 1; + unsigned char ebpf_byte; + u32 pkt_len = skb->len; + + struct my_ingress_metadata_t *meta; + + hdrMd = BPF_MAP_LOOKUP_ELEM(hdr_md_cpumap, &ebpf_zero); + if (!hdrMd) + return TC_ACT_SHOT; + __builtin_memset(hdrMd, 0, sizeof(struct hdr_md)); + + unsigned ebpf_packetOffsetInBits = 0; + hdr = &(hdrMd->cpumap_hdr); + meta = &(hdrMd->cpumap_usermeta); + { + goto start; + parse_ipv4: { +/* extract(hdr->ipv4) */ + if ((u8*)ebpf_packetEnd < hdr_start + BYTES(160 + 0)) { + ebpf_errorCode = PacketTooShort; + goto reject; + } + + hdr->ipv4.version = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)) >> 4) & EBPF_MASK(u8, 4)); + ebpf_packetOffsetInBits += 4; + + hdr->ipv4.ihl = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits))) & EBPF_MASK(u8, 4)); + ebpf_packetOffsetInBits += 4; + + hdr->ipv4.diffserv = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 8; + + hdr->ipv4.totalLen = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 16; + + hdr->ipv4.identification = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 16; + + hdr->ipv4.flags = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)) >> 5) & EBPF_MASK(u8, 3)); + ebpf_packetOffsetInBits += 3; + + hdr->ipv4.fragOffset = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits))) & EBPF_MASK(u16, 13)); + ebpf_packetOffsetInBits += 13; + + hdr->ipv4.ttl = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 8; + + hdr->ipv4.protocol = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 8; + + hdr->ipv4.hdrChecksum = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 16; + + hdr->ipv4.srcAddr = (u32)((load_word(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 32; + + hdr->ipv4.dstAddr = (u32)((load_word(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 32; + + + hdr->ipv4.ebpf_valid = 1; + hdr_start += BYTES(160); + +; + goto accept; + } + start: { +/* extract(hdr->ethernet) */ + if ((u8*)ebpf_packetEnd < hdr_start + BYTES(112 + 0)) { + ebpf_errorCode = PacketTooShort; + goto reject; + } + + __builtin_memcpy(&hdr->ethernet.dstAddr, pkt + BYTES(ebpf_packetOffsetInBits), 6); + ebpf_packetOffsetInBits += 48; + + __builtin_memcpy(&hdr->ethernet.srcAddr, pkt + BYTES(ebpf_packetOffsetInBits), 6); + ebpf_packetOffsetInBits += 48; + + hdr->ethernet.etherType = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 16; + + + hdr->ethernet.ebpf_valid = 1; + hdr_start += BYTES(112); + +; + u16 select_0; + select_0 = hdr->ethernet.etherType; + if (select_0 == 0x800)goto parse_ipv4; + if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; + else goto reject; + } + + reject: { + if (ebpf_errorCode == 0) { + return TC_ACT_SHOT; + } + compiler_meta__->parser_error = ebpf_errorCode; + goto accept; + } + + } + + accept: + hdrMd->ebpf_packetOffsetInBits = ebpf_packetOffsetInBits; + return -1; +} + +SEC("p4tc/parse") +int tc_parse_func(struct __sk_buff *skb) { + struct pna_global_metadata *compiler_meta__ = (struct pna_global_metadata *) skb->cb; + struct hdr_md *hdrMd; + struct my_ingress_headers_t *hdr; + int ret = -1; + ret = run_parser(skb, (struct my_ingress_headers_t *) hdr, compiler_meta__); + if (ret != -1) { + return ret; + } + return TC_ACT_PIPE; + } +char _license[] SEC("license") = "GPL"; diff --git a/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h b/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h new file mode 100644 index 00000000000..a67ccde435a --- /dev/null +++ b/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h @@ -0,0 +1,165 @@ +#include "ebpf_kernel.h" + +#include +#include +#include "pna.h" + +#define EBPF_MASK(t, w) ((((t)(1)) << (w)) - (t)1) +#define BYTES(w) ((w) / 8) +#define write_partial(a, w, s, v) do { *((u8*)a) = ((*((u8*)a)) & ~(EBPF_MASK(u8, w) << s)) | (v << s) ; } while (0) +#define write_byte(base, offset, v) do { *(u8*)((base) + (offset)) = (v); } while (0) +#define bpf_trace_message(fmt, ...) + + +struct ethernet_t { + u64 dstAddr; /* bit<48> */ + u64 srcAddr; /* bit<48> */ + u16 etherType; /* bit<16> */ + u8 ebpf_valid; +}; +struct ipv4_t { + u8 version; /* bit<4> */ + u8 ihl; /* bit<4> */ + u8 diffserv; /* bit<8> */ + u16 totalLen; /* bit<16> */ + u16 identification; /* bit<16> */ + u8 flags; /* bit<3> */ + u16 fragOffset; /* bit<13> */ + u8 ttl; /* bit<8> */ + u8 protocol; /* bit<8> */ + u16 hdrChecksum; /* bit<16> */ + u32 srcAddr; /* bit<32> */ + u32 dstAddr; /* bit<32> */ + u8 ebpf_valid; +}; +struct my_ingress_headers_t { + struct ethernet_t ethernet; /* ethernet_t */ + struct ipv4_t ipv4; /* ipv4_t */ +}; +struct my_ingress_metadata_t { +}; +struct empty_metadata_t { +}; + +struct hdr_md { + struct my_ingress_headers_t cpumap_hdr; + struct my_ingress_metadata_t cpumap_usermeta; + unsigned ebpf_packetOffsetInBits; + __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) +BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) +REGISTER_END() + +static __always_inline +void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { + if (data_size <= 8) + data += data_size - 1; + #pragma clang loop unroll(full) + for (u16 i = 0; i < data_size; i++) { + bpf_trace_message("CRC16: data byte: %x\n", *data); + *reg ^= *data; + for (u8 bit = 0; bit < 8; bit++) { + *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; + } + if (data_size <= 8) + data--; + else + data++; + } +} +static __always_inline u16 crc16_finalize(u16 reg) { + return reg; +} +static __always_inline +void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { + u32* current = (u32*) data; + u32 index = 0; + u32 lookup_key = 0; + u32 lookup_value = 0; + u32 lookup_value1 = 0; + u32 lookup_value2 = 0; + u32 lookup_value3 = 0; + u32 lookup_value4 = 0; + u32 lookup_value5 = 0; + u32 lookup_value6 = 0; + u32 lookup_value7 = 0; + u32 lookup_value8 = 0; + u16 tmp = 0; + if (crc32_table != NULL) { + for (u16 i = data_size; i >= 8; i -= 8) { + /* Vars one and two will have swapped byte order if data_size == 8 */ + if (data_size == 8) current = (u32 *)(data + 4); + bpf_trace_message("CRC32: data dword: %x\n", *current); + u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; + bpf_trace_message("CRC32: data dword: %x\n", *current); + u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); + lookup_key = (one & 0x000000FF); + lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; + lookup_key = (one >> 8) & 0x000000FF; + lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; + lookup_key = (one >> 16) & 0x000000FF; + lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; + lookup_key = one >> 24; + lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; + lookup_key = (two & 0x000000FF); + lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; + lookup_key = (two >> 8) & 0x000000FF; + lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; + lookup_key = (two >> 16) & 0x000000FF; + lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; + lookup_key = two >> 24; + lookup_value1 = crc32_table[(u8)(lookup_key)]; + *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ + lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; + tmp += 8; + } + volatile int std_algo_lookup_key = 0; + if (data_size < 8) { + unsigned char *currentChar = (unsigned char *) current; + currentChar += data_size - 1; + for (u16 i = tmp; i < data_size; i++) { + bpf_trace_message("CRC32: data byte: %x\n", *currentChar); + std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); + if (std_algo_lookup_key >= 0) { + lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; + } + *reg = ((*reg) >> 8) ^ lookup_value; + } + } else { + /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ + unsigned char *currentChar = (unsigned char *) current; + for (u16 i = tmp; i < data_size; i++) { + bpf_trace_message("CRC32: data byte: %x\n", *currentChar); + std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); + if (std_algo_lookup_key >= 0) { + lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; + } + *reg = ((*reg) >> 8) ^ lookup_value; + } + } + } +} +static __always_inline u32 crc32_finalize(u32 reg) { + return reg ^ 0xFFFFFFFF; +} +inline u16 csum16_add(u16 csum, u16 addend) { + u16 res = csum; + res += addend; + return (res + (res < addend)); +} +inline u16 csum16_sub(u16 csum, u16 addend) { + return csum16_add(csum, ~addend); +} diff --git a/testdata/p4tc_samples_outputs/send_to_port_example.json b/testdata/p4tc_samples_outputs/send_to_port_example.json index 0d9c5274517..cbfb752d1f5 100644 --- a/testdata/p4tc_samples_outputs/send_to_port_example.json +++ b/testdata/p4tc_samples_outputs/send_to_port_example.json @@ -4,7 +4,7 @@ "externs" : [ { "name" : "Register", - "id" : 1, + "id" : "0x1", "permissions" : "0x19b6", "instances" : [ { diff --git a/testdata/p4tc_samples_outputs/send_to_port_example.template b/testdata/p4tc_samples_outputs/send_to_port_example.template index d51ece49745..a0a99bc461d 100755 --- a/testdata/p4tc_samples_outputs/send_to_port_example.template +++ b/testdata/p4tc_samples_outputs/send_to_port_example.template @@ -12,7 +12,7 @@ $TC p4template update action/send_to_port_example/MainControlImpl/next_hop state $TC p4template create action/send_to_port_example/MainControlImpl/default_route_drop actid 2 $TC p4template update action/send_to_port_example/MainControlImpl/default_route_drop state active -$TC p4template create extern/root/Register extid 1 numinstances 1 tc_acl 0x19b6 +$TC p4template create extern/root/Register extid 0x1 numinstances 1 tc_acl 0x19b6 $TC p4template create extern_inst/send_to_port_example/Register/MainControlImpl.reg1 instid 1 \ tc_numel 10 diff --git a/testdata/p4tc_samples_outputs/send_to_port_example_control_blocks.c b/testdata/p4tc_samples_outputs/send_to_port_example_control_blocks.c index 13b382f7c7d..78b53fbb411 100644 --- a/testdata/p4tc_samples_outputs/send_to_port_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/send_to_port_example_control_blocks.c @@ -94,7 +94,7 @@ if (/* hdr->ipv4.isValid() */ { __builtin_memset(&ext_params, 0, sizeof(struct p4tc_ext_bpf_params)); ext_params.pipe_id = p4tc_filter_fields.pipeid; - ext_params.ext_id = 1; + ext_params.ext_id = 0x1; ext_params.inst_id = 1; ext_params.index = value->u.MainControlImpl_next_hop.vport; @@ -107,7 +107,7 @@ ext_val = *ext_val_ptr; /* reg1_0.write(value->u.MainControlImpl_next_hop.vport, val_0) */ __builtin_memset(&ext_params, 0, sizeof(struct p4tc_ext_bpf_params)); ext_params.pipe_id = p4tc_filter_fields.pipeid; - ext_params.ext_id = 1; + ext_params.ext_id = 0x1; ext_params.inst_id = 1; ext_params.index = value->u.MainControlImpl_next_hop.vport; diff --git a/testdata/p4tc_samples_outputs/simple_extern_example.json b/testdata/p4tc_samples_outputs/simple_extern_example.json index a30413b0d3d..76e60b73b3e 100644 --- a/testdata/p4tc_samples_outputs/simple_extern_example.json +++ b/testdata/p4tc_samples_outputs/simple_extern_example.json @@ -4,7 +4,7 @@ "externs" : [ { "name" : "Register", - "id" : 1, + "id" : "0x1", "permissions" : "0x19b6", "instances" : [ { diff --git a/testdata/p4tc_samples_outputs/simple_extern_example.template b/testdata/p4tc_samples_outputs/simple_extern_example.template index 32f1c45b392..a7d0ec32784 100755 --- a/testdata/p4tc_samples_outputs/simple_extern_example.template +++ b/testdata/p4tc_samples_outputs/simple_extern_example.template @@ -18,7 +18,7 @@ $TC p4template update action/simple_extern_example/ingress/ext_reg state active $TC p4template create action/simple_extern_example/ingress/drop actid 3 $TC p4template update action/simple_extern_example/ingress/drop state active -$TC p4template create extern/root/Register extid 1 numinstances 2 tc_acl 0x19b6 +$TC p4template create extern/root/Register extid 0x1 numinstances 2 tc_acl 0x19b6 $TC p4template create extern_inst/simple_extern_example/Register/ingress.reg1 instid 1 \ tc_numel 10 diff --git a/testdata/p4tc_samples_outputs/simple_extern_example_control_blocks.c b/testdata/p4tc_samples_outputs/simple_extern_example_control_blocks.c index af0d4ec8a43..95ec76300de 100644 --- a/testdata/p4tc_samples_outputs/simple_extern_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/simple_extern_example_control_blocks.c @@ -71,7 +71,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head /* reg3_0.write(2, arg_val_0) */ __builtin_memset(&ext_params, 0, sizeof(struct p4tc_ext_bpf_params)); ext_params.pipe_id = p4tc_filter_fields.pipeid; - ext_params.ext_id = 1; + ext_params.ext_id = 0x1; ext_params.inst_id = 2; ext_params.index = 2; @@ -108,7 +108,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head { __builtin_memset(&ext_params, 0, sizeof(struct p4tc_ext_bpf_params)); ext_params.pipe_id = p4tc_filter_fields.pipeid; - ext_params.ext_id = 1; + ext_params.ext_id = 0x1; ext_params.inst_id = 1; ext_params.index = value->u.ingress_ext_reg.port_id; @@ -121,7 +121,7 @@ ext_val = *ext_val_ptr; /* reg1_0.write(value->u.ingress_ext_reg.port_id, val_0) */ __builtin_memset(&ext_params, 0, sizeof(struct p4tc_ext_bpf_params)); ext_params.pipe_id = p4tc_filter_fields.pipeid; - ext_params.ext_id = 1; + ext_params.ext_id = 0x1; ext_params.inst_id = 1; ext_params.index = value->u.ingress_ext_reg.port_id;