From 7c87489442a6a70ae8af31413d250c2e8ef6dde5 Mon Sep 17 00:00:00 2001 From: "Komal, Jain" Date: Thu, 3 Oct 2024 10:40:53 +0530 Subject: [PATCH] Align key components to the nearest 8-bit size Signed-off-by: Komal, Jain --- backends/ebpf/codeGen.cpp | 236 ++++++++++++++---- backends/ebpf/codeGen.h | 6 +- backends/ebpf/ebpfBackend.cpp | 2 +- backends/ebpf/ebpfType.cpp | 62 ++++- backends/ebpf/ebpfType.h | 17 +- backends/ebpf/psa/backend.cpp | 2 +- backends/ebpf/target.h | 4 + backends/tc/backend.cpp | 2 +- backends/tc/ebpfCodeGen.cpp | 37 +++ backends/tc/ebpfCodeGen.h | 1 + .../add_entry_1_example_control_blocks.c | 8 +- .../add_entry_1_example_parser.c | 2 +- .../add_entry_1_example_parser.h | 41 ++- .../add_entry_3_example_control_blocks.c | 8 +- .../add_entry_3_example_parser.c | 2 +- .../add_entry_3_example_parser.h | 41 ++- .../add_entry_example_parser.c | 2 +- .../add_entry_example_parser.h | 37 ++- .../calculator_control_blocks.c | 42 ++-- .../p4tc_samples_outputs/calculator_parser.c | 6 +- .../p4tc_samples_outputs/calculator_parser.h | 37 ++- .../checksum_control_blocks.c | 8 +- .../p4tc_samples_outputs/checksum_parser.c | 6 +- .../p4tc_samples_outputs/checksum_parser.h | 37 ++- .../const_entries_range_mask_control_blocks.c | 4 +- .../const_entries_range_mask_parser.h | 33 +++ .../default_action_example_01_parser.c | 2 +- .../default_action_example_01_parser.h | 37 ++- .../default_action_example_parser.c | 2 +- .../default_action_example_parser.h | 37 ++- ...ault_action_with_param_01_control_blocks.c | 2 +- .../default_action_with_param_01_parser.c | 2 +- .../default_action_with_param_01_parser.h | 37 ++- .../default_action_with_param_parser.c | 2 +- .../default_action_with_param_parser.h | 37 ++- .../default_hit_const_example_parser.c | 4 +- .../default_hit_const_example_parser.h | 37 ++- .../direct_counter_example_control_blocks.c | 8 +- .../direct_counter_example_parser.c | 2 +- .../direct_counter_example_parser.h | 37 ++- .../direct_meter_color_parser.c | 2 +- .../direct_meter_color_parser.h | 37 ++- .../direct_meter_parser.c | 2 +- .../direct_meter_parser.h | 37 ++- .../drop_packet_example_parser.c | 2 +- .../drop_packet_example_parser.h | 37 ++- .../global_action_example_01_control_blocks.c | 12 +- .../global_action_example_01_parser.c | 2 +- .../global_action_example_01_parser.h | 37 ++- .../global_action_example_02_control_blocks.c | 16 +- .../global_action_example_02_parser.c | 2 +- .../global_action_example_02_parser.h | 37 ++- .../hash1_control_blocks.c | 2 +- testdata/p4tc_samples_outputs/hash1_parser.c | 2 +- testdata/p4tc_samples_outputs/hash1_parser.h | 37 ++- ...direct_counter_01_example_control_blocks.c | 8 +- .../indirect_counter_01_example_parser.c | 2 +- .../indirect_counter_01_example_parser.h | 37 ++- .../p4tc_samples_outputs/matchtype_parser.c | 2 +- .../p4tc_samples_outputs/matchtype_parser.h | 37 ++- .../p4tc_samples_outputs/meter_color_parser.c | 2 +- .../p4tc_samples_outputs/meter_color_parser.h | 37 ++- testdata/p4tc_samples_outputs/meter_parser.c | 2 +- testdata/p4tc_samples_outputs/meter_parser.h | 37 ++- .../mix_matchtype_example_parser.c | 2 +- .../mix_matchtype_example_parser.h | 37 ++- .../multiple_tables_example_01_parser.c | 4 +- .../multiple_tables_example_01_parser.h | 37 ++- ...ultiple_tables_example_02_control_blocks.c | 6 +- .../multiple_tables_example_02_parser.c | 4 +- .../multiple_tables_example_02_parser.h | 37 ++- .../name_annotation_example_parser.c | 2 +- .../name_annotation_example_parser.h | 37 ++- .../no_table_example_control_blocks.c | 2 +- .../no_table_example_parser.c | 2 +- .../no_table_example_parser.h | 37 ++- .../noaction_example_01_parser.c | 2 +- .../noaction_example_01_parser.h | 37 ++- .../noaction_example_02_parser.c | 2 +- .../noaction_example_02_parser.h | 37 ++- .../nummask_annotation_example_parser.c | 4 +- .../nummask_annotation_example_parser.h | 37 ++- .../send_to_port_example_control_blocks.c | 2 +- .../send_to_port_example_parser.c | 2 +- .../send_to_port_example_parser.h | 37 ++- .../set_entry_timer_example_parser.c | 2 +- .../set_entry_timer_example_parser.h | 37 ++- .../simple_exact_example_control_blocks.c | 8 +- .../simple_exact_example_parser.c | 2 +- .../simple_exact_example_parser.h | 37 ++- .../simple_extern_example_control_blocks.c | 14 +- .../simple_extern_example_parser.c | 2 +- .../simple_extern_example_parser.h | 37 ++- .../simple_lpm_example_control_blocks.c | 8 +- .../simple_lpm_example_parser.c | 2 +- .../simple_lpm_example_parser.h | 37 ++- .../simple_ternary_example_control_blocks.c | 8 +- .../simple_ternary_example_parser.c | 2 +- .../simple_ternary_example_parser.h | 37 ++- .../size_param_example_parser.c | 2 +- .../size_param_example_parser.h | 37 ++- .../tc_may_override_example_01_parser.c | 2 +- .../tc_may_override_example_01_parser.h | 37 ++- .../tc_may_override_example_02_parser.c | 2 +- .../tc_may_override_example_02_parser.h | 37 ++- ...c_may_override_example_03_control_blocks.c | 2 +- .../tc_may_override_example_03_parser.c | 2 +- .../tc_may_override_example_03_parser.h | 37 ++- ...c_may_override_example_04_control_blocks.c | 6 +- .../tc_may_override_example_04_parser.c | 2 +- .../tc_may_override_example_04_parser.h | 37 ++- .../tc_may_override_example_05_parser.c | 2 +- .../tc_may_override_example_05_parser.h | 37 ++- .../tc_may_override_example_06_parser.c | 2 +- .../tc_may_override_example_06_parser.h | 37 ++- .../tc_may_override_example_07_parser.c | 2 +- .../tc_may_override_example_07_parser.h | 37 ++- .../tc_may_override_example_08_parser.c | 2 +- .../tc_may_override_example_08_parser.h | 37 ++- .../tc_may_override_example_09_parser.c | 2 +- .../tc_may_override_example_09_parser.h | 37 ++- ...c_type_annotation_example_control_blocks.c | 2 +- .../tc_type_annotation_example_parser.c | 2 +- .../tc_type_annotation_example_parser.h | 37 ++- .../test_ipv6_example_control_blocks.c | 2 +- .../test_ipv6_example_parser.c | 2 +- .../test_ipv6_example_parser.h | 39 ++- 127 files changed, 2145 insertions(+), 294 deletions(-) diff --git a/backends/ebpf/codeGen.cpp b/backends/ebpf/codeGen.cpp index 83b9459f2ba..dbf0376c663 100644 --- a/backends/ebpf/codeGen.cpp +++ b/backends/ebpf/codeGen.cpp @@ -351,7 +351,10 @@ void CodeGenInspector::emitAssignStatement(const IR::Type *ltype, const IR::Expr width = scalar->implementationWidthInBits(); memcpy = !EBPFScalarType::generatesScalar(width); } - + if (builder->target->name == "P4TC") { + emitTCAssignmentEndianessConversion(lexpr, rexpr, lpath, memcpy, scalar->bytesRequired()); + return; + } builder->emitIndent(); if (memcpy) { builder->append("__builtin_memcpy(&"); @@ -373,11 +376,7 @@ void CodeGenInspector::emitAssignStatement(const IR::Type *ltype, const IR::Expr builder->append(lpath); } builder->append(" = "); - if (builder->target->name == "P4TC") { - emitTCAssignmentEndianessConversion(lexpr, rexpr); - } else { - visit(rexpr); - } + visit(rexpr); } builder->endOfStatement(); } @@ -492,7 +491,9 @@ void CodeGenInspector::emitAndConvertByteOrder(const IR::Expression *expr, cstri } unsigned shift = loadSize - widthToEmit; builder->appendFormat("%s(", emit); - visit(expr); + bool primitive = isPrimitive(expr); + if (primitive) { visit(expr); + } else { getBitAlignment(expr); } if (shift != 0 && byte_order == "HOST") builder->appendFormat(" << %d", shift); builder->append(")"); } @@ -512,7 +513,9 @@ void CodeGenInspector::emitTCBinaryOperation(const IR::Operation_Binary *b, bool rByteOrder = tcTarget->getByteOrder(typeMap, action, rexpr); } if (lByteOrder == rByteOrder) { - visit(lexpr); + bool primitive = isPrimitive(lexpr); + if (primitive) { visit(lexpr); + } else { getBitAlignment(lexpr); } if (isScalar) { builder->spc(); builder->append(stringop); @@ -521,7 +524,9 @@ void CodeGenInspector::emitTCBinaryOperation(const IR::Operation_Binary *b, bool builder->append(", &"); } if (!b->is()) expressionPrecedence = b->getPrecedence() + 1; - visit(rexpr); + primitive = isPrimitive(rexpr); + if (primitive) { visit(rexpr); + } else { getBitAlignment(rexpr); } return; } if (lByteOrder == "NETWORK") { @@ -542,14 +547,18 @@ void CodeGenInspector::emitTCBinaryOperation(const IR::Operation_Binary *b, bool builder->append(", &"); } if (!b->is()) expressionPrecedence = b->getPrecedence() + 1; - visit(rexpr); + bool primitive = isPrimitive(rexpr); + if (primitive) { visit(rexpr); + } else { getBitAlignment(rexpr); } return; } else if (rByteOrder == "NETWORK") { // ConvertRight auto ftype = typeMap->getType(rexpr); auto et = EBPFTypeFactory::instance->create(ftype); unsigned width = dynamic_cast(et)->widthInBits(); - visit(lexpr); + bool primitive = isPrimitive(lexpr); + if (primitive) { visit(lexpr); + } else { getBitAlignment(lexpr); } if (isScalar) { builder->spc(); builder->append(stringop); @@ -568,46 +577,183 @@ void CodeGenInspector::emitTCBinaryOperation(const IR::Operation_Binary *b, bool } void CodeGenInspector::emitTCAssignmentEndianessConversion(const IR::Expression *lexpr, - const IR::Expression *rexpr) { - auto action = findContext(); - auto b = dynamic_cast(builder->target); - cstring lByteOrder = "HOST"_cs, rByteOrder = "HOST"_cs; - if (lexpr) { - lByteOrder = b->getByteOrder(typeMap, action, lexpr); + const IR::Expression *rexpr, + cstring lpath, bool memcpy, + unsigned width) { + builder->emitIndent(); + if (memcpy) { + builder->append("__builtin_memcpy(&"); + if (lexpr != nullptr) { + visit(lexpr); + } else { + builder->append(lpath); + } + builder->append(", &"); + if (rexpr->is()) { + builder->appendFormat("(u8[%u])", width); + } + visit(rexpr); + builder->appendFormat(", %d)", width); + } else { + if (lexpr != nullptr) { + bool primitive = isPrimitive(lexpr); + if (primitive) { + visit(lexpr); + } else { + storeBitAlignment(lexpr, rexpr); + return; + } + } else { + builder->append(lpath); + } + builder->append(" = "); + auto action = findContext(); + auto b = dynamic_cast(builder->target); + cstring lByteOrder = "HOST"_cs, rByteOrder = "HOST"_cs; + if (lexpr) { + lByteOrder = b->getByteOrder(typeMap, action, lexpr); + } + if (rexpr) { + rByteOrder = b->getByteOrder(typeMap, action, rexpr); + } + auto ftype = typeMap->getType(rexpr); + auto et = EBPFTypeFactory::instance->create(ftype); + unsigned width = dynamic_cast(et)->widthInBits(); + // TODO: + if (lByteOrder == rByteOrder) { + bool primitive = isPrimitive(rexpr); + if (primitive) { visit(rexpr); + } else { getBitAlignment(rexpr); } + return; + } + if (width <= 8) { + visit(rexpr); + return; + } + if (rByteOrder == "NETWORK") { + // If left side of assignment is not annotated field i.e host endian and right expression + // is annotated field i.e network endian, we need to convert rexp to host order. + // Example - + // select_0 = hdr.ipv4.diffserv + // select_0 = bntoh(hdr.ipv4.diffserv) + // + emitAndConvertByteOrder(rexpr, "HOST"_cs); + } + if (lByteOrder == "NETWORK") { + // If left side of assignment is annotated field i.e network endian, we need to convert + // right expression to network order. + // Example - + // hdr.opv4.diffserv = 0x1; + // hdr.opv4.diffserv = bhton(0x1) + // + emitAndConvertByteOrder(rexpr, "NETWORK"_cs); + } } - if (rexpr) { - rByteOrder = b->getByteOrder(typeMap, action, rexpr); + builder->endOfStatement(); + return; +} + +bool CodeGenInspector::isPrimitive(const IR::Expression* expression) { + if (!expression->is()) { return true; } + auto ftype = typeMap->getType(expression); + if (!ftype) { return true; } + auto tcTarget = dynamic_cast(builder->target); + auto ebpfType = EBPFTypeFactory::instance->create(ftype); + EBPFScalarType *scalar = nullptr; + if (ebpfType->is()) { + scalar = ebpfType->to(); + bool isPrimitive = tcTarget->isPrimitiveByteAligned(scalar->implementationWidthInBits()); + if (!isPrimitive) { + return false; + } } - if (lByteOrder == rByteOrder) { - visit(rexpr); + return true; +} + +void CodeGenInspector::getBitAlignment(const IR::Expression* expression) { + auto ftype = typeMap->getType(expression); + if (!ftype) { return; } + auto ebpfType = EBPFTypeFactory::instance->create(ftype); + EBPFScalarType *scalar = nullptr; + if (ebpfType->is()) { + scalar = ebpfType->to(); + if (scalar->implementationWidthInBits() < 32) { + builder->append("getPrimitive32("); + visit(expression); + builder->append(", "); + } else { + builder->append("getPrimitive64("); + visit(expression); + builder->appendFormat(", %d", scalar->implementationWidthInBits()); + } + builder->append(")"); return; } - auto ftype = typeMap->getType(rexpr); - auto et = EBPFTypeFactory::instance->create(ftype); - unsigned width = dynamic_cast(et)->widthInBits(); - if (width <= 8) { - visit(rexpr); + return; +} + +void CodeGenInspector::storeBitAlignment(const IR::Expression* lexpr, const IR::Expression* rexpr) { + auto tcTarget = dynamic_cast(builder->target); + auto ftype = typeMap->getType(lexpr); + if (!ftype) { return;} + auto ebpfType = EBPFTypeFactory::instance->create(ftype); + EBPFScalarType *scalar = nullptr; + if (ebpfType->is()) { + scalar = ebpfType->to(); + if (scalar->implementationWidthInBits() < 32) { + builder->append("storePrimitive32(&"); + visit(lexpr); + builder->append(", "); + } else { + builder->append("storePrimitive64(&"); + visit(lexpr); + builder->appendFormat(", %d, (" , scalar->implementationWidthInBits()); + } + auto action = findContext(); + cstring lByteOrder = "HOST"_cs, rByteOrder = "HOST"_cs; + if (lexpr) { + lByteOrder = tcTarget->getByteOrder(typeMap, action, lexpr); + } + if (rexpr) { + rByteOrder = tcTarget->getByteOrder(typeMap, action, rexpr); + } + auto ftype = typeMap->getType(rexpr); + auto et = EBPFTypeFactory::instance->create(ftype); + unsigned width = dynamic_cast(et)->widthInBits(); + // TODO: + if (lByteOrder == rByteOrder) { + bool primitive = isPrimitive(rexpr); + if (primitive) { visit(rexpr); + } else { getBitAlignment(rexpr); } + builder->append("));"); + return; + } + if (width <= 8) { + visit(rexpr); + builder->append("));"); + return; + } + if (rByteOrder == "NETWORK") { + // If left side of assignment is not annotated field i.e host endian and right expression + // is annotated field i.e network endian, we need to convert rexp to host order. + // Example - + // select_0 = hdr.ipv4.diffserv + // select_0 = bntoh(hdr.ipv4.diffserv) + // + emitAndConvertByteOrder(rexpr, "HOST"_cs); + } + if (lByteOrder == "NETWORK") { + // If left side of assignment is annotated field i.e network endian, we need to convert + // right expression to network order. + // Example - + // hdr.opv4.diffserv = 0x1; + // hdr.opv4.diffserv = bhton(0x1) + // + emitAndConvertByteOrder(rexpr, "NETWORK"_cs); + } + builder->append("));"); return; } - if (rByteOrder == "NETWORK") { - // If left side of assignment is not annotated field i.e host endian and right expression - // is annotated field i.e network endian, we need to convert rexp to host order. - // Example - - // select_0 = hdr.ipv4.diffserv - // select_0 = bntoh(hdr.ipv4.diffserv) - // - emitAndConvertByteOrder(rexpr, "HOST"_cs); - } - if (lByteOrder == "NETWORK") { - // If left side of assignment is annotated field i.e network endian, we need to convert - // right expression to network order. - // Example - - // hdr.opv4.diffserv = 0x1; - // hdr.opv4.diffserv = bhton(0x1) - // - emitAndConvertByteOrder(rexpr, "NETWORK"_cs); - } - return; } diff --git a/backends/ebpf/codeGen.h b/backends/ebpf/codeGen.h index ebc4b8eb40b..f55d8a8c5a1 100644 --- a/backends/ebpf/codeGen.h +++ b/backends/ebpf/codeGen.h @@ -129,7 +129,11 @@ class CodeGenInspector : public Inspector { void emitAndConvertByteOrder(const IR::Expression *expr, cstring byte_order); void emitTCBinaryOperation(const IR::Operation_Binary *b, bool isScalar); void emitTCAssignmentEndianessConversion(const IR::Expression *lexpr, - const IR::Expression *rexpr); + const IR::Expression *rexpr, + cstring lpath, bool memcpy, unsigned width); + void getBitAlignment(const IR::Expression* expression); + bool isPrimitive(const IR::Expression* expression); + void storeBitAlignment(const IR::Expression* lexpr, const IR::Expression* rexpr); }; class EBPFInitializerUtils { diff --git a/backends/ebpf/ebpfBackend.cpp b/backends/ebpf/ebpfBackend.cpp index 86477f45138..f9b074f0ed6 100644 --- a/backends/ebpf/ebpfBackend.cpp +++ b/backends/ebpf/ebpfBackend.cpp @@ -32,7 +32,7 @@ void emitFilterModel(const EbpfOptions &options, Target *target, const IR::Tople CodeBuilder c(target); CodeBuilder h(target); - EBPFTypeFactory::createFactory(typeMap); + EBPFTypeFactory::createFactory(typeMap, false); auto ebpfprog = new EBPFProgram(options, toplevel->getProgram(), refMap, typeMap, toplevel); if (!ebpfprog->build()) return; diff --git a/backends/ebpf/ebpfType.cpp b/backends/ebpf/ebpfType.cpp index c3a18d1ac81..b77f91ca51e 100644 --- a/backends/ebpf/ebpfType.cpp +++ b/backends/ebpf/ebpfType.cpp @@ -19,6 +19,7 @@ limitations under the License. namespace P4::EBPF { EBPFTypeFactory *EBPFTypeFactory::instance; +bool EBPFTypeFactory::isTC; EBPFType *EBPFTypeFactory::create(const IR::Type *type) { CHECK_NULL(type); @@ -27,7 +28,11 @@ EBPFType *EBPFTypeFactory::create(const IR::Type *type) { if (type->is()) { result = new EBPFBoolType(); } else if (auto bt = type->to()) { - result = new EBPFScalarType(bt); + if (EBPFTypeFactory::isTC) { + result = new EBPFScalarTypePNA(bt); + } else { + result = new EBPFScalarType(bt); + } } else if (auto st = type->to()) { result = new EBPFStructType(st); } else if (auto tt = type->to()) { @@ -384,4 +389,59 @@ void EBPFMethodDeclaration::emit(CodeBuilder *builder) { builder->newline(); } +unsigned EBPFScalarTypePNA::alignment() const { + if (width <= 8) + return 1; + else if (width <= 16) + return 2; + else if (width <= 24) + return 1; // compiled as u8* + else if (width <= 32) + return 4; + else if (width <= 56) + return 1; // compiled as u8* + else if (width <= 64) + return 8; + else + // compiled as u8* + return 1; +} + +void EBPFScalarTypePNA::declare(CodeBuilder *builder, cstring id, bool asPointer) { + if (generatesScalar(width) && isPrimitiveByteAligned == true) { + emit(builder); + if (asPointer) builder->append("*"); + builder->spc(); + builder->append(id); + } else { + if (asPointer) + builder->appendFormat("u8* %s", id.c_str()); + else + builder->appendFormat("u8 %s[%d]", id.c_str(), bytesRequired()); + } +} + +void EBPFScalarTypePNA::declareInit(CodeBuilder *builder, cstring id, bool asPointer) { + if (generatesScalar(width) && isPrimitiveByteAligned == true ) { + emit(builder); + if (asPointer) builder->append("*"); + builder->spc(); + id = id + cstring(" = 0"); + builder->append(id); + } else { + if (asPointer) + builder->appendFormat("u8* %s = NULL", id.c_str()); + else + builder->appendFormat("u8 %s[%d] = {0}", id.c_str(), bytesRequired()); + } +} + +void EBPFScalarTypePNA::emitInitializer(CodeBuilder *builder) { + if (generatesScalar(width) && isPrimitiveByteAligned == true) { + builder->append("0"); + } else { + builder->append("{ 0 }"); + } +} + } // namespace P4::EBPF diff --git a/backends/ebpf/ebpfType.h b/backends/ebpf/ebpfType.h index c3493b6affc..c8f07a6e54f 100644 --- a/backends/ebpf/ebpfType.h +++ b/backends/ebpf/ebpfType.h @@ -62,8 +62,10 @@ class EBPFTypeFactory { public: static EBPFTypeFactory *instance; - static void createFactory(const P4::TypeMap *typeMap) { + static bool isTC; + static void createFactory(const P4::TypeMap *typeMap, bool TC) { EBPFTypeFactory::instance = new EBPFTypeFactory(typeMap); + EBPFTypeFactory::isTC = TC; } virtual EBPFType *create(const IR::Type *type); }; @@ -223,6 +225,19 @@ class EBPFMethodDeclaration : public EBPFObject { DECLARE_TYPEINFO(EBPFMethodDeclaration, EBPFObject); }; +class EBPFScalarTypePNA : public EBPFScalarType { + bool isPrimitiveByteAligned = false; + public: + explicit EBPFScalarTypePNA(const IR::Type_Bits *bits) + : EBPFScalarType(bits) { + isPrimitiveByteAligned = (width <= 8 || width <= 16 || (width > 24 && width <= 32) || (width > 56 && width <=64)); + } + unsigned alignment() const; + void declare(CodeBuilder *builder, cstring id, bool asPointer); + void declareInit(CodeBuilder *builder, cstring id, bool asPointer); + void emitInitializer(CodeBuilder *builder); +}; + } // namespace P4::EBPF #endif /* BACKENDS_EBPF_EBPFTYPE_H_ */ diff --git a/backends/ebpf/psa/backend.cpp b/backends/ebpf/psa/backend.cpp index 03293b15908..4fb9c01fc87 100644 --- a/backends/ebpf/psa/backend.cpp +++ b/backends/ebpf/psa/backend.cpp @@ -61,7 +61,7 @@ void PSASwitchBackend::convert(const IR::ToplevelBlock *tlb) { main->apply(*parsePsaArch); program = toplevel->getProgram(); - EBPFTypeFactory::createFactory(typeMap); + EBPFTypeFactory::createFactory(typeMap, false); auto *convertToEbpfPSA = new ConvertToEbpfPSA(options, refMap, typeMap); PassManager toEBPF = { new P4::DiscoverStructure(&structure), diff --git a/backends/ebpf/target.h b/backends/ebpf/target.h index 3bc414514c5..c1dc870cc4c 100644 --- a/backends/ebpf/target.h +++ b/backends/ebpf/target.h @@ -237,6 +237,10 @@ class P4TCTarget : public KernelSamplesTarget { } return "HOST"_cs; } + + bool isPrimitiveByteAligned(int width) const { + return (width <= 8 || width <= 16 || (width > 24 && width <= 32) || (width > 56 && width <=64)); + } }; /// Target XDP. diff --git a/backends/tc/backend.cpp b/backends/tc/backend.cpp index ca7a8293696..6044d3b03a7 100644 --- a/backends/tc/backend.cpp +++ b/backends/tc/backend.cpp @@ -101,7 +101,7 @@ bool Backend::ebpfCodeGen(P4::ReferenceMap *refMapEBPF, P4::TypeMap *typeMapEBPF main->apply(*parsePnaArch); program = top->getProgram(); - EBPF::EBPFTypeFactory::createFactory(typeMapEBPF); + EBPF::EBPFTypeFactory::createFactory(typeMapEBPF, true); auto convertToEbpf = new ConvertToEbpfPNA(ebpfOption, refMapEBPF, typeMapEBPF, tcIR); PassManager toEBPF = { new P4::DiscoverStructure(&structure), diff --git a/backends/tc/ebpfCodeGen.cpp b/backends/tc/ebpfCodeGen.cpp index 962f29c1d29..3a0169199ef 100644 --- a/backends/tc/ebpfCodeGen.cpp +++ b/backends/tc/ebpfCodeGen.cpp @@ -212,6 +212,42 @@ void PNAArchTC::emitInstances(EBPF::CodeBuilder *builder) const { builder->newline(); } +void PNAArchTC::emitGlobalFunctions(EBPF::CodeBuilder *builder) const { + const char *code = "u32 getPrimitive32(u8 *a, int size) {\n" + " return ((a[2]<<16) | (a[1] << 8) | a[0]);\n" + "}\n" + "u64 getPrimitive64(u8 *a, int size) {\n" + " if(size < 40) {\n" + " return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]);\n" + " } else {\n" + " if(size < 48) {\n" + " return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]);\n" + " } else {\n" + " return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]);\n" + " }\n" + " }\n" + "}\n" + "void storePrimitive32(u8 *a, u32 value) {\n" + " a[0] = (u8)(value);\n" + " a[1] = (u8)(value >> 8);\n" + " a[2] = (u8)(value >> 16);\n" + "}\n" + "void storePrimitive64(u8 *a, int size, u64 value) {\n" + " a[0] = (u8)(value);\n" + " a[1] = (u8)(value >> 8);\n" + " a[2] = (u8)(value >> 16);\n" + " a[3] = (u8)(value >> 24);\n" + " a[4] = (u8)(value >> 32);\n" + " if (size < 48) {\n" + " a[5] = (u8)(value >> 40);\n" + " }\n" + " if (size < 56){\n" + " a[6] = (u8)(value >> 48);\n" + " }\n" + "}\n"; + builder->appendLine(code); +} + void PNAArchTC::emitParser(EBPF::CodeBuilder *builder) const { /** * Structure of a C Parser program for PNA @@ -248,6 +284,7 @@ void PNAArchTC::emitHeader(EBPF::CodeBuilder *builder) const { emitP4TCFilterFields(builder); // BPF map definitions. emitInstances(builder); + emitGlobalFunctions(builder); EBPFHashAlgorithmTypeFactoryPNA::instance()->emitGlobals(builder); } diff --git a/backends/tc/ebpfCodeGen.h b/backends/tc/ebpfCodeGen.h index f68df9b4a00..0f504370325 100644 --- a/backends/tc/ebpfCodeGen.h +++ b/backends/tc/ebpfCodeGen.h @@ -104,6 +104,7 @@ class PNAArchTC : public PNAEbpfGenerator { void emitParser(EBPF::CodeBuilder *builder) const override; void emitHeader(EBPF::CodeBuilder *builder) const override; void emitInstances(EBPF::CodeBuilder *builder) const override; + void emitGlobalFunctions(EBPF::CodeBuilder *builder) const; }; class TCIngressPipelinePNA : public EBPF::TCIngressPipeline { diff --git a/testdata/p4tc_samples_outputs/add_entry_1_example_control_blocks.c b/testdata/p4tc_samples_outputs/add_entry_1_example_control_blocks.c index 69860b00f75..25052582f85 100644 --- a/testdata/p4tc_samples_outputs/add_entry_1_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/add_entry_1_example_control_blocks.c @@ -26,8 +26,8 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { struct { } MainControlImpl_next_hop; struct __attribute__((__packed__)) { - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } MainControlImpl_send_nh; struct { } MainControlImpl_dflt_route_drop; @@ -114,8 +114,8 @@ if (/* hdr->ipv4.isValid() */ break; case MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_SEND_NH: { - hdr->ethernet.srcAddr = bpf_cpu_to_be64(value->u.MainControlImpl_send_nh.smac); - hdr->ethernet.dstAddr = ntohll(value->u.MainControlImpl_send_nh.dmac << 16); + storePrimitive64(&hdr->ethernet.srcAddr, 48, (bpf_cpu_to_be64(value->u.MainControlImpl_send_nh.smac))); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (ntohll(value->u.MainControlImpl_send_nh.dmac << 16))); } break; case MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DFLT_ROUTE_DROP: diff --git a/testdata/p4tc_samples_outputs/add_entry_1_example_parser.c b/testdata/p4tc_samples_outputs/add_entry_1_example_parser.c index 0b1c93f47e3..434cea5fa3f 100644 --- a/testdata/p4tc_samples_outputs/add_entry_1_example_parser.c +++ b/testdata/p4tc_samples_outputs/add_entry_1_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/add_entry_1_example_parser.h b/testdata/p4tc_samples_outputs/add_entry_1_example_parser.h index eb0351243ee..ff39f043554 100644 --- a/testdata/p4tc_samples_outputs/add_entry_1_example_parser.h +++ b/testdata/p4tc_samples_outputs/add_entry_1_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -39,8 +39,8 @@ struct headers_t { struct ipv4_t ipv4; /* ipv4_t */ }; struct tuple_0 { - u64 f0; /* bit<48> */ - u64 f1; /* bit<48> */ + u8 f0[6]; /* bit<48> */ + u8 f1[6]; /* bit<48> */ }; struct hdr_md { @@ -65,6 +65,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/add_entry_3_example_control_blocks.c b/testdata/p4tc_samples_outputs/add_entry_3_example_control_blocks.c index fb44998d93c..ef88b4c745a 100644 --- a/testdata/p4tc_samples_outputs/add_entry_3_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/add_entry_3_example_control_blocks.c @@ -26,8 +26,8 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { struct { } MainControlImpl_next_hop; struct __attribute__((__packed__)) { - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } MainControlImpl_send_nh; struct { } MainControlImpl_dflt_route_drop; @@ -114,8 +114,8 @@ if (/* hdr->ipv4.isValid() */ break; case MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_SEND_NH: { - hdr->ethernet.srcAddr = bpf_cpu_to_be64(value->u.MainControlImpl_send_nh.smac); - hdr->ethernet.dstAddr = ntohll(value->u.MainControlImpl_send_nh.dmac << 16); + storePrimitive64(&hdr->ethernet.srcAddr, 48, (bpf_cpu_to_be64(value->u.MainControlImpl_send_nh.smac))); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (ntohll(value->u.MainControlImpl_send_nh.dmac << 16))); } break; case MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DFLT_ROUTE_DROP: diff --git a/testdata/p4tc_samples_outputs/add_entry_3_example_parser.c b/testdata/p4tc_samples_outputs/add_entry_3_example_parser.c index 84e09a9ebba..6bb0e638a60 100644 --- a/testdata/p4tc_samples_outputs/add_entry_3_example_parser.c +++ b/testdata/p4tc_samples_outputs/add_entry_3_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/add_entry_3_example_parser.h b/testdata/p4tc_samples_outputs/add_entry_3_example_parser.h index eb0351243ee..ff39f043554 100644 --- a/testdata/p4tc_samples_outputs/add_entry_3_example_parser.h +++ b/testdata/p4tc_samples_outputs/add_entry_3_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -39,8 +39,8 @@ struct headers_t { struct ipv4_t ipv4; /* ipv4_t */ }; struct tuple_0 { - u64 f0; /* bit<48> */ - u64 f1; /* bit<48> */ + u8 f0[6]; /* bit<48> */ + u8 f1[6]; /* bit<48> */ }; struct hdr_md { @@ -65,6 +65,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/add_entry_example_parser.c b/testdata/p4tc_samples_outputs/add_entry_example_parser.c index 7ac5cd30ea5..8c3da71d1a1 100644 --- a/testdata/p4tc_samples_outputs/add_entry_example_parser.c +++ b/testdata/p4tc_samples_outputs/add_entry_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/add_entry_example_parser.h b/testdata/p4tc_samples_outputs/add_entry_example_parser.h index c3b7c46eb9b..3b3536a1907 100644 --- a/testdata/p4tc_samples_outputs/add_entry_example_parser.h +++ b/testdata/p4tc_samples_outputs/add_entry_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -65,6 +65,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/calculator_control_blocks.c b/testdata/p4tc_samples_outputs/calculator_control_blocks.c index 782ce636932..d1f7095b89d 100644 --- a/testdata/p4tc_samples_outputs/calculator_control_blocks.c +++ b/testdata/p4tc_samples_outputs/calculator_control_blocks.c @@ -64,7 +64,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, meta = &(hdrMd->cpumap_usermeta); { u8 hit; - u64 tmp_5 = 0; + u8 tmp_5[6] = {0}; { if (/* hdr->p4calc.isValid() */ hdr->p4calc.ebpf_valid) { @@ -96,10 +96,10 @@ if (/* hdr->p4calc.isValid() */ switch (value->action) { case MAINCONTROLIMPL_CALCULATE_ACT_MAINCONTROLIMPL_OPERATION_ADD: { - hdr->p4calc.res = (hdr->p4calc.operand_a + hdr->p4calc.operand_b); - tmp_5 = hdr->ethernet.dstAddr; - hdr->ethernet.dstAddr = hdr->ethernet.srcAddr; - hdr->ethernet.srcAddr = tmp_5; + hdr->p4calc.res = (hdr->p4calc.operand_a + hdr->p4calc.operand_b) + tmp_5 = getPrimitive64(hdr->ethernet.dstAddr, 48) + storePrimitive64(&hdr->ethernet.dstAddr, 48, (getPrimitive64(hdr->ethernet.srcAddr, 48))); + storePrimitive64(&hdr->ethernet.srcAddr, 48, (tmp_5)); /* send_to_port(skb->ifindex) */ compiler_meta__->drop = false; send_to_port(skb->ifindex); @@ -107,10 +107,10 @@ if (/* hdr->p4calc.isValid() */ break; case MAINCONTROLIMPL_CALCULATE_ACT_MAINCONTROLIMPL_OPERATION_SUB: { - hdr->p4calc.res = (hdr->p4calc.operand_a - hdr->p4calc.operand_b); - tmp_5 = hdr->ethernet.dstAddr; - hdr->ethernet.dstAddr = hdr->ethernet.srcAddr; - hdr->ethernet.srcAddr = tmp_5; + hdr->p4calc.res = (hdr->p4calc.operand_a - hdr->p4calc.operand_b) + tmp_5 = getPrimitive64(hdr->ethernet.dstAddr, 48) + storePrimitive64(&hdr->ethernet.dstAddr, 48, (getPrimitive64(hdr->ethernet.srcAddr, 48))); + storePrimitive64(&hdr->ethernet.srcAddr, 48, (tmp_5)); /* send_to_port(skb->ifindex) */ compiler_meta__->drop = false; send_to_port(skb->ifindex); @@ -118,10 +118,10 @@ if (/* hdr->p4calc.isValid() */ break; case MAINCONTROLIMPL_CALCULATE_ACT_MAINCONTROLIMPL_OPERATION_AND: { - hdr->p4calc.res = (hdr->p4calc.operand_a & hdr->p4calc.operand_b); - tmp_5 = hdr->ethernet.dstAddr; - hdr->ethernet.dstAddr = hdr->ethernet.srcAddr; - hdr->ethernet.srcAddr = tmp_5; + hdr->p4calc.res = (hdr->p4calc.operand_a & hdr->p4calc.operand_b) + tmp_5 = getPrimitive64(hdr->ethernet.dstAddr, 48) + storePrimitive64(&hdr->ethernet.dstAddr, 48, (getPrimitive64(hdr->ethernet.srcAddr, 48))); + storePrimitive64(&hdr->ethernet.srcAddr, 48, (tmp_5)); /* send_to_port(skb->ifindex) */ compiler_meta__->drop = false; send_to_port(skb->ifindex); @@ -129,10 +129,10 @@ if (/* hdr->p4calc.isValid() */ break; case MAINCONTROLIMPL_CALCULATE_ACT_MAINCONTROLIMPL_OPERATION_OR: { - hdr->p4calc.res = (hdr->p4calc.operand_a | hdr->p4calc.operand_b); - tmp_5 = hdr->ethernet.dstAddr; - hdr->ethernet.dstAddr = hdr->ethernet.srcAddr; - hdr->ethernet.srcAddr = tmp_5; + hdr->p4calc.res = (hdr->p4calc.operand_a | hdr->p4calc.operand_b) + tmp_5 = getPrimitive64(hdr->ethernet.dstAddr, 48) + storePrimitive64(&hdr->ethernet.dstAddr, 48, (getPrimitive64(hdr->ethernet.srcAddr, 48))); + storePrimitive64(&hdr->ethernet.srcAddr, 48, (tmp_5)); /* send_to_port(skb->ifindex) */ compiler_meta__->drop = false; send_to_port(skb->ifindex); @@ -140,10 +140,10 @@ if (/* hdr->p4calc.isValid() */ break; case MAINCONTROLIMPL_CALCULATE_ACT_MAINCONTROLIMPL_OPERATION_XOR: { - hdr->p4calc.res = (hdr->p4calc.operand_a ^ hdr->p4calc.operand_b); - tmp_5 = hdr->ethernet.dstAddr; - hdr->ethernet.dstAddr = hdr->ethernet.srcAddr; - hdr->ethernet.srcAddr = tmp_5; + hdr->p4calc.res = (hdr->p4calc.operand_a ^ hdr->p4calc.operand_b) + tmp_5 = getPrimitive64(hdr->ethernet.dstAddr, 48) + storePrimitive64(&hdr->ethernet.dstAddr, 48, (getPrimitive64(hdr->ethernet.srcAddr, 48))); + storePrimitive64(&hdr->ethernet.srcAddr, 48, (tmp_5)); /* send_to_port(skb->ifindex) */ compiler_meta__->drop = false; send_to_port(skb->ifindex); diff --git a/testdata/p4tc_samples_outputs/calculator_parser.c b/testdata/p4tc_samples_outputs/calculator_parser.c index a9623807c5c..b11c6c2440c 100644 --- a/testdata/p4tc_samples_outputs/calculator_parser.c +++ b/testdata/p4tc_samples_outputs/calculator_parser.c @@ -140,8 +140,8 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h hdr_start = hdr_start_save; ebpf_packetOffsetInBits = ebpf_packetOffsetInBits_save; } - u32 select_0; - select_0 = (((((u32)(((u16)tmp_0.p << 8) | ((u16)tmp_2.four & 0xff)) << 8) & ((1 << 24) - 1)) | (((u32)tmp_4.ver & 0xff) & ((1 << 24) - 1))) & ((1 << 24) - 1)); + u8 select_0[3]; + select_0 = (((((u32)(((u16)tmp_0.p << 8) | ((u16)tmp_2.four & 0xff)) << 8) & ((1 << 24) - 1)) | (((u32)tmp_4.ver & 0xff) & ((1 << 24) - 1))) & ((1 << 24) - 1)) if (select_0 == 0x503401)goto parse_p4calc; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; @@ -203,7 +203,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_1; - select_1 = hdr->ethernet.etherType; + select_1 = hdr->ethernet.etherType if (select_1 == 0x1234)goto check_p4calc; if ((select_1 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/calculator_parser.h b/testdata/p4tc_samples_outputs/calculator_parser.h index ba89b9929a1..7809aaa28fe 100644 --- a/testdata/p4tc_samples_outputs/calculator_parser.h +++ b/testdata/p4tc_samples_outputs/calculator_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -56,6 +56,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/checksum_control_blocks.c b/testdata/p4tc_samples_outputs/checksum_control_blocks.c index 345bf2761ca..c653dd89996 100644 --- a/testdata/p4tc_samples_outputs/checksum_control_blocks.c +++ b/testdata/p4tc_samples_outputs/checksum_control_blocks.c @@ -23,8 +23,8 @@ struct __attribute__((__packed__)) ingress_nh_table_value { } _NoAction; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } ingress_send_nh; struct { } ingress_drop; @@ -84,8 +84,8 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head 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; + storePrimitive64(&hdr->ethernet.srcAddr, 48, (value->u.ingress_send_nh.smac)); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (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); diff --git a/testdata/p4tc_samples_outputs/checksum_parser.c b/testdata/p4tc_samples_outputs/checksum_parser.c index 7de687dae49..e55cbb7ab73 100644 --- a/testdata/p4tc_samples_outputs/checksum_parser.c +++ b/testdata/p4tc_samples_outputs/checksum_parser.c @@ -109,14 +109,14 @@ struct p4tc_ext_csum_params ck_0_csum = {}; ; tmp_0 = /* ck_0.get() */ (u16) bpf_p4tc_ext_csum_16bit_complement_get(&ck_0_csum, sizeof(ck_0_csum)); -;/* verify(hdr->ipv4.hdrChecksum == tmp_0, BadIPv4HeaderChecksum) */ +/* verify(hdr->ipv4.hdrChecksum == tmp_0, BadIPv4HeaderChecksum) */ if (!(hdr->ipv4.hdrChecksum == tmp_0)) { ebpf_errorCode = BadIPv4HeaderChecksum; goto reject; } ; hdr->ipv4.hdrChecksum = /* ck_0.get_state() */ -ck_0_state; goto accept; +ck_0_state goto accept; } start: { /* extract(hdr->ethernet) */ @@ -140,7 +140,7 @@ ck_0_state; goto accept; ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/checksum_parser.h b/testdata/p4tc_samples_outputs/checksum_parser.h index 3e5caec29fc..3126d92c7b7 100644 --- a/testdata/p4tc_samples_outputs/checksum_parser.h +++ b/testdata/p4tc_samples_outputs/checksum_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -79,6 +79,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/const_entries_range_mask_control_blocks.c b/testdata/p4tc_samples_outputs/const_entries_range_mask_control_blocks.c index 223fbb03d01..ab2da485e22 100644 --- a/testdata/p4tc_samples_outputs/const_entries_range_mask_control_blocks.c +++ b/testdata/p4tc_samples_outputs/const_entries_range_mask_control_blocks.c @@ -82,12 +82,12 @@ static __always_inline int process(struct __sk_buff *skb, struct Header_t *h, st switch (value->action) { case MAINCONTROLIMPL_T_RANGE_ACT_MAINCONTROLIMPL_A: { - h->h.e = 0; + h->h.e = 0 } break; case MAINCONTROLIMPL_T_RANGE_ACT_MAINCONTROLIMPL_A_WITH_CONTROL_PARAMS: { - h->h.t = value->u.MainControlImpl_a_with_control_params.x; + h->h.t = value->u.MainControlImpl_a_with_control_params.x } break; case MAINCONTROLIMPL_T_RANGE_ACT_NOACTION: diff --git a/testdata/p4tc_samples_outputs/const_entries_range_mask_parser.h b/testdata/p4tc_samples_outputs/const_entries_range_mask_parser.h index 9ec0cd912fe..f8362d3453b 100644 --- a/testdata/p4tc_samples_outputs/const_entries_range_mask_parser.h +++ b/testdata/p4tc_samples_outputs/const_entries_range_mask_parser.h @@ -47,6 +47,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/default_action_example_01_parser.c b/testdata/p4tc_samples_outputs/default_action_example_01_parser.c index cd9f245e208..007869f8744 100644 --- a/testdata/p4tc_samples_outputs/default_action_example_01_parser.c +++ b/testdata/p4tc_samples_outputs/default_action_example_01_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/default_action_example_01_parser.h b/testdata/p4tc_samples_outputs/default_action_example_01_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/default_action_example_01_parser.h +++ b/testdata/p4tc_samples_outputs/default_action_example_01_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/default_action_example_parser.c b/testdata/p4tc_samples_outputs/default_action_example_parser.c index 108a626cb77..c94209ba73c 100644 --- a/testdata/p4tc_samples_outputs/default_action_example_parser.c +++ b/testdata/p4tc_samples_outputs/default_action_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/default_action_example_parser.h b/testdata/p4tc_samples_outputs/default_action_example_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/default_action_example_parser.h +++ b/testdata/p4tc_samples_outputs/default_action_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/default_action_with_param_01_control_blocks.c b/testdata/p4tc_samples_outputs/default_action_with_param_01_control_blocks.c index 58467d1d1d5..aad11c113a4 100644 --- a/testdata/p4tc_samples_outputs/default_action_with_param_01_control_blocks.c +++ b/testdata/p4tc_samples_outputs/default_action_with_param_01_control_blocks.c @@ -79,7 +79,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, u8 hit; u32 z_0; { - z_0 = 4; + z_0 = 4 if (/* hdr->ipv4.isValid() */ hdr->ipv4.ebpf_valid) { /* ipv4_tbl.apply() */ diff --git a/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.c b/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.c index 5423435e2eb..1e3a2441852 100644 --- a/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.c +++ b/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.h b/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.h +++ b/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/default_action_with_param_parser.c b/testdata/p4tc_samples_outputs/default_action_with_param_parser.c index 7c7b9b1bf32..2d41e85e0d1 100644 --- a/testdata/p4tc_samples_outputs/default_action_with_param_parser.c +++ b/testdata/p4tc_samples_outputs/default_action_with_param_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/default_action_with_param_parser.h b/testdata/p4tc_samples_outputs/default_action_with_param_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/default_action_with_param_parser.h +++ b/testdata/p4tc_samples_outputs/default_action_with_param_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/default_hit_const_example_parser.c b/testdata/p4tc_samples_outputs/default_hit_const_example_parser.c index 0547d47bdb5..165807d8c11 100644 --- a/testdata/p4tc_samples_outputs/default_hit_const_example_parser.c +++ b/testdata/p4tc_samples_outputs/default_hit_const_example_parser.c @@ -77,7 +77,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u8 select_0; - select_0 = hdr->ipv4.protocol; + select_0 = hdr->ipv4.protocol if (select_0 == 6)goto parse_tcp; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; @@ -148,7 +148,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_1; - select_1 = hdr->eth.etherType; + select_1 = hdr->eth.etherType if (select_1 == 0x800)goto parse_ipv4; if ((select_1 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/default_hit_const_example_parser.h b/testdata/p4tc_samples_outputs/default_hit_const_example_parser.h index d0f8789a8f6..f8a4697204c 100644 --- a/testdata/p4tc_samples_outputs/default_hit_const_example_parser.h +++ b/testdata/p4tc_samples_outputs/default_hit_const_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -75,6 +75,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/direct_counter_example_control_blocks.c b/testdata/p4tc_samples_outputs/direct_counter_example_control_blocks.c index 81f840dfb8e..702164778c3 100644 --- a/testdata/p4tc_samples_outputs/direct_counter_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/direct_counter_example_control_blocks.c @@ -23,8 +23,8 @@ struct __attribute__((__packed__)) ingress_nh_table_value { } _NoAction; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } ingress_send_nh; struct { } ingress_drop; @@ -87,8 +87,8 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head 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; + storePrimitive64(&hdr->ethernet.srcAddr, 48, (value->u.ingress_send_nh.smac)); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (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); diff --git a/testdata/p4tc_samples_outputs/direct_counter_example_parser.c b/testdata/p4tc_samples_outputs/direct_counter_example_parser.c index 7e66b95a96c..49d764a0463 100644 --- a/testdata/p4tc_samples_outputs/direct_counter_example_parser.c +++ b/testdata/p4tc_samples_outputs/direct_counter_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/direct_counter_example_parser.h b/testdata/p4tc_samples_outputs/direct_counter_example_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/direct_counter_example_parser.h +++ b/testdata/p4tc_samples_outputs/direct_counter_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/direct_meter_color_parser.c b/testdata/p4tc_samples_outputs/direct_meter_color_parser.c index e6155b9909c..53fb1e4c2ab 100644 --- a/testdata/p4tc_samples_outputs/direct_meter_color_parser.c +++ b/testdata/p4tc_samples_outputs/direct_meter_color_parser.c @@ -101,7 +101,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/direct_meter_color_parser.h b/testdata/p4tc_samples_outputs/direct_meter_color_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/direct_meter_color_parser.h +++ b/testdata/p4tc_samples_outputs/direct_meter_color_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/direct_meter_parser.c b/testdata/p4tc_samples_outputs/direct_meter_parser.c index 93348cbf3a3..a281b71d8cb 100644 --- a/testdata/p4tc_samples_outputs/direct_meter_parser.c +++ b/testdata/p4tc_samples_outputs/direct_meter_parser.c @@ -101,7 +101,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/direct_meter_parser.h b/testdata/p4tc_samples_outputs/direct_meter_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/direct_meter_parser.h +++ b/testdata/p4tc_samples_outputs/direct_meter_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/drop_packet_example_parser.c b/testdata/p4tc_samples_outputs/drop_packet_example_parser.c index dc11f5f8b34..8354e916088 100644 --- a/testdata/p4tc_samples_outputs/drop_packet_example_parser.c +++ b/testdata/p4tc_samples_outputs/drop_packet_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/drop_packet_example_parser.h b/testdata/p4tc_samples_outputs/drop_packet_example_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/drop_packet_example_parser.h +++ b/testdata/p4tc_samples_outputs/drop_packet_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/global_action_example_01_control_blocks.c b/testdata/p4tc_samples_outputs/global_action_example_01_control_blocks.c index 9627bdb0090..dd274cab348 100644 --- a/testdata/p4tc_samples_outputs/global_action_example_01_control_blocks.c +++ b/testdata/p4tc_samples_outputs/global_action_example_01_control_blocks.c @@ -23,7 +23,7 @@ struct __attribute__((__packed__)) ingress_nh_table2_value { } _NoAction; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; + u8 dmac[6]; } ingress_send_nh; struct { } ingress_drop; @@ -47,8 +47,8 @@ struct __attribute__((__packed__)) ingress_nh_table_value { } _NoAction; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } _send_nh; struct { } ingress_drop; @@ -111,8 +111,8 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head /* send_to_port(value->u._send_nh.port_id) */ compiler_meta__->drop = false; send_to_port(value->u._send_nh.port_id); - hdr->ethernet.srcAddr = value->u._send_nh.smac; - hdr->ethernet.dstAddr = value->u._send_nh.dmac; + storePrimitive64(&hdr->ethernet.srcAddr, 48, (value->u._send_nh.smac)); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (value->u._send_nh.dmac)); } break; case INGRESS_NH_TABLE_ACT_INGRESS_DROP: @@ -158,7 +158,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head switch (value->action) { case INGRESS_NH_TABLE2_ACT_INGRESS_SEND_NH: { - hdr->ethernet.dstAddr = value->u.ingress_send_nh.dmac; + storePrimitive64(&hdr->ethernet.dstAddr, 48, (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); diff --git a/testdata/p4tc_samples_outputs/global_action_example_01_parser.c b/testdata/p4tc_samples_outputs/global_action_example_01_parser.c index aa24a846240..782406699d3 100644 --- a/testdata/p4tc_samples_outputs/global_action_example_01_parser.c +++ b/testdata/p4tc_samples_outputs/global_action_example_01_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/global_action_example_01_parser.h b/testdata/p4tc_samples_outputs/global_action_example_01_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/global_action_example_01_parser.h +++ b/testdata/p4tc_samples_outputs/global_action_example_01_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/global_action_example_02_control_blocks.c b/testdata/p4tc_samples_outputs/global_action_example_02_control_blocks.c index 7cb9c3452ee..2f21b6348c2 100644 --- a/testdata/p4tc_samples_outputs/global_action_example_02_control_blocks.c +++ b/testdata/p4tc_samples_outputs/global_action_example_02_control_blocks.c @@ -23,8 +23,8 @@ struct __attribute__((__packed__)) ingress_nh_table2_value { } _NoAction; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } ingress_send_nh; struct { } ingress_drop; @@ -48,8 +48,8 @@ struct __attribute__((__packed__)) ingress_nh_table_value { } _NoAction; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } ingress_send_nh; struct { } _drop; @@ -109,8 +109,8 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head 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; + storePrimitive64(&hdr->ethernet.srcAddr, 48, (value->u.ingress_send_nh.smac)); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (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); @@ -159,8 +159,8 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head switch (value->action) { case INGRESS_NH_TABLE2_ACT_INGRESS_SEND_NH: { - hdr->ethernet.srcAddr = value->u.ingress_send_nh.smac; - hdr->ethernet.dstAddr = value->u.ingress_send_nh.dmac; + storePrimitive64(&hdr->ethernet.srcAddr, 48, (value->u.ingress_send_nh.smac)); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (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); diff --git a/testdata/p4tc_samples_outputs/global_action_example_02_parser.c b/testdata/p4tc_samples_outputs/global_action_example_02_parser.c index 813e2865f0d..62c6bd8efa7 100644 --- a/testdata/p4tc_samples_outputs/global_action_example_02_parser.c +++ b/testdata/p4tc_samples_outputs/global_action_example_02_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/global_action_example_02_parser.h b/testdata/p4tc_samples_outputs/global_action_example_02_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/global_action_example_02_parser.h +++ b/testdata/p4tc_samples_outputs/global_action_example_02_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/hash1_control_blocks.c b/testdata/p4tc_samples_outputs/hash1_control_blocks.c index 7e851732e3d..a40822c1f7d 100644 --- a/testdata/p4tc_samples_outputs/hash1_control_blocks.c +++ b/testdata/p4tc_samples_outputs/hash1_control_blocks.c @@ -41,7 +41,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head crc16_update(&ingress_h_reg, (u8 *) &(hdr->crc.f4), 4, 0xA001); } hdr->crc.crc = /* h_0.get_hash({hdr->crc.f1, hdr->crc.f2, hdr->crc.f3, hdr->crc.f4}) */ -crc16_finalize(ingress_h_reg); +crc16_finalize(ingress_h_reg) } } { diff --git a/testdata/p4tc_samples_outputs/hash1_parser.c b/testdata/p4tc_samples_outputs/hash1_parser.c index 82d6243b676..5beb0798c01 100644 --- a/testdata/p4tc_samples_outputs/hash1_parser.c +++ b/testdata/p4tc_samples_outputs/hash1_parser.c @@ -79,7 +79,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/hash1_parser.h b/testdata/p4tc_samples_outputs/hash1_parser.h index 42a9f99a839..e446e3a19b6 100644 --- a/testdata/p4tc_samples_outputs/hash1_parser.h +++ b/testdata/p4tc_samples_outputs/hash1_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -78,6 +78,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) 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 index 9ad5fd5c2ee..5d9bd48bcf4 100644 --- a/testdata/p4tc_samples_outputs/indirect_counter_01_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/indirect_counter_01_example_control_blocks.c @@ -23,8 +23,8 @@ struct __attribute__((__packed__)) ingress_nh_table_value { } _NoAction; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } ingress_send_nh; struct { } ingress_drop; @@ -90,8 +90,8 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head 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; + storePrimitive64(&hdr->ethernet.srcAddr, 48, (value->u.ingress_send_nh.smac)); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (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); diff --git a/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.c b/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.c index aa8785b57e8..0298515db32 100644 --- a/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.c +++ b/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h b/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h +++ b/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/matchtype_parser.c b/testdata/p4tc_samples_outputs/matchtype_parser.c index 6bca9c633c7..44e8823d421 100644 --- a/testdata/p4tc_samples_outputs/matchtype_parser.c +++ b/testdata/p4tc_samples_outputs/matchtype_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/matchtype_parser.h b/testdata/p4tc_samples_outputs/matchtype_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/matchtype_parser.h +++ b/testdata/p4tc_samples_outputs/matchtype_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/meter_color_parser.c b/testdata/p4tc_samples_outputs/meter_color_parser.c index 640f850c17d..21825f5d2d0 100644 --- a/testdata/p4tc_samples_outputs/meter_color_parser.c +++ b/testdata/p4tc_samples_outputs/meter_color_parser.c @@ -101,7 +101,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/meter_color_parser.h b/testdata/p4tc_samples_outputs/meter_color_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/meter_color_parser.h +++ b/testdata/p4tc_samples_outputs/meter_color_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/meter_parser.c b/testdata/p4tc_samples_outputs/meter_parser.c index 974626ea3cf..63bb3257030 100644 --- a/testdata/p4tc_samples_outputs/meter_parser.c +++ b/testdata/p4tc_samples_outputs/meter_parser.c @@ -101,7 +101,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/meter_parser.h b/testdata/p4tc_samples_outputs/meter_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/meter_parser.h +++ b/testdata/p4tc_samples_outputs/meter_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.c b/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.c index 0e2e8079452..7c8e93fb6a0 100644 --- a/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.c +++ b/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.h b/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.h +++ b/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.c b/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.c index d765938d0c5..0060e4f79d9 100644 --- a/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.c +++ b/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.c @@ -77,7 +77,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u8 select_0; - select_0 = hdr->ipv4.protocol; + select_0 = hdr->ipv4.protocol if (select_0 == 6)goto parse_tcp; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; @@ -148,7 +148,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_1; - select_1 = hdr->ethernet.etherType; + select_1 = hdr->ethernet.etherType if (select_1 == 0x800)goto parse_ipv4; if ((select_1 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.h b/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.h index 5c8a19c1a88..3867a46d856 100644 --- a/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.h +++ b/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -75,6 +75,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/multiple_tables_example_02_control_blocks.c b/testdata/p4tc_samples_outputs/multiple_tables_example_02_control_blocks.c index f14364a20ce..3ecba578777 100644 --- a/testdata/p4tc_samples_outputs/multiple_tables_example_02_control_blocks.c +++ b/testdata/p4tc_samples_outputs/multiple_tables_example_02_control_blocks.c @@ -243,7 +243,7 @@ if (/* hdr->ipv4.isValid() */ switch (value->action) { case MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP: { - hdr->ipv4.version = 1; + hdr->ipv4.version = 1 /* send_to_port(value->u.MainControlImpl_next_hop.vport) */ compiler_meta__->drop = false; send_to_port(value->u.MainControlImpl_next_hop.vport); @@ -296,7 +296,7 @@ if (hdr->ipv4.protocol != 6) { switch (value->action) { case MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP: { - hdr->ipv4.version = 1; + hdr->ipv4.version = 1 /* send_to_port(value->u.MainControlImpl_next_hop.vport) */ compiler_meta__->drop = false; send_to_port(value->u.MainControlImpl_next_hop.vport); @@ -536,7 +536,7 @@ if (hdr->ipv4.protocol == 6 || ((hdr->ipv4.version > 1) && (hdr->ipv4.ihl <= 2)) switch (value->action) { case MAINCONTROLIMPL_SET_ALL_OPTIONS_ACT_MAINCONTROLIMPL_NEXT_HOP: { - hdr->ipv4.version = 1; + hdr->ipv4.version = 1 /* send_to_port(value->u.MainControlImpl_next_hop.vport) */ compiler_meta__->drop = false; send_to_port(value->u.MainControlImpl_next_hop.vport); diff --git a/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.c b/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.c index 866917aa245..598d39dda65 100644 --- a/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.c +++ b/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.c @@ -77,7 +77,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u8 select_0; - select_0 = hdr->ipv4.protocol; + select_0 = hdr->ipv4.protocol if (select_0 == 6)goto parse_tcp; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; @@ -148,7 +148,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_1; - select_1 = hdr->ethernet.etherType; + select_1 = hdr->ethernet.etherType if (select_1 == 0x800)goto parse_ipv4; if ((select_1 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.h b/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.h index 5c8a19c1a88..3867a46d856 100644 --- a/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.h +++ b/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -75,6 +75,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/name_annotation_example_parser.c b/testdata/p4tc_samples_outputs/name_annotation_example_parser.c index 0733cba3b7d..db9d3ce5d80 100644 --- a/testdata/p4tc_samples_outputs/name_annotation_example_parser.c +++ b/testdata/p4tc_samples_outputs/name_annotation_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/name_annotation_example_parser.h b/testdata/p4tc_samples_outputs/name_annotation_example_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/name_annotation_example_parser.h +++ b/testdata/p4tc_samples_outputs/name_annotation_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/no_table_example_control_blocks.c b/testdata/p4tc_samples_outputs/no_table_example_control_blocks.c index 1ed4181e435..9ebd71c223a 100644 --- a/testdata/p4tc_samples_outputs/no_table_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/no_table_example_control_blocks.c @@ -32,7 +32,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, u8 hit; { if ((u32)skb->ifindex == 4) { - hdr->udp.src_port = (hdr->udp.src_port + 1); } + hdr->udp.src_port = (hdr->udp.src_port + 1) } } } diff --git a/testdata/p4tc_samples_outputs/no_table_example_parser.c b/testdata/p4tc_samples_outputs/no_table_example_parser.c index 19bdd105c56..94d955c2469 100644 --- a/testdata/p4tc_samples_outputs/no_table_example_parser.c +++ b/testdata/p4tc_samples_outputs/no_table_example_parser.c @@ -123,7 +123,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/no_table_example_parser.h b/testdata/p4tc_samples_outputs/no_table_example_parser.h index b65ae62b59a..79673864da2 100644 --- a/testdata/p4tc_samples_outputs/no_table_example_parser.h +++ b/testdata/p4tc_samples_outputs/no_table_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -69,6 +69,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/noaction_example_01_parser.c b/testdata/p4tc_samples_outputs/noaction_example_01_parser.c index 4e0c2a54e70..0c2beced1ae 100644 --- a/testdata/p4tc_samples_outputs/noaction_example_01_parser.c +++ b/testdata/p4tc_samples_outputs/noaction_example_01_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/noaction_example_01_parser.h b/testdata/p4tc_samples_outputs/noaction_example_01_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/noaction_example_01_parser.h +++ b/testdata/p4tc_samples_outputs/noaction_example_01_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/noaction_example_02_parser.c b/testdata/p4tc_samples_outputs/noaction_example_02_parser.c index 03e9a9fcdac..e35c934f728 100644 --- a/testdata/p4tc_samples_outputs/noaction_example_02_parser.c +++ b/testdata/p4tc_samples_outputs/noaction_example_02_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/noaction_example_02_parser.h b/testdata/p4tc_samples_outputs/noaction_example_02_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/noaction_example_02_parser.h +++ b/testdata/p4tc_samples_outputs/noaction_example_02_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.c b/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.c index 6f59cc58fd1..c38de61e32d 100644 --- a/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.c +++ b/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.c @@ -77,7 +77,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u8 select_0; - select_0 = hdr->ipv4.protocol; + select_0 = hdr->ipv4.protocol if (select_0 == 6)goto parse_tcp; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; @@ -148,7 +148,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_1; - select_1 = hdr->eth.etherType; + select_1 = hdr->eth.etherType if (select_1 == 0x800)goto parse_ipv4; if ((select_1 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.h b/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.h index d0f8789a8f6..f8a4697204c 100644 --- a/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.h +++ b/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -75,6 +75,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) 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 7375df90426..095477b016d 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 @@ -103,7 +103,7 @@ if (/* hdr->ipv4.isValid() */ return TC_ACT_SHOT; ext_val = *ext_val_ptr; __builtin_memcpy(&val_0, ext_val.out_params, sizeof(u32 )); - val_0 = (val_0 + 10); + val_0 = (val_0 + 10) /* 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; diff --git a/testdata/p4tc_samples_outputs/send_to_port_example_parser.c b/testdata/p4tc_samples_outputs/send_to_port_example_parser.c index a21b8aeabf5..c54762ec8de 100644 --- a/testdata/p4tc_samples_outputs/send_to_port_example_parser.c +++ b/testdata/p4tc_samples_outputs/send_to_port_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/send_to_port_example_parser.h b/testdata/p4tc_samples_outputs/send_to_port_example_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/send_to_port_example_parser.h +++ b/testdata/p4tc_samples_outputs/send_to_port_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.c b/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.c index 72e7fa57bdc..72691731338 100644 --- a/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.c +++ b/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.h b/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.h +++ b/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/simple_exact_example_control_blocks.c b/testdata/p4tc_samples_outputs/simple_exact_example_control_blocks.c index 5216d83472f..03aacd44bb2 100644 --- a/testdata/p4tc_samples_outputs/simple_exact_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/simple_exact_example_control_blocks.c @@ -23,8 +23,8 @@ struct __attribute__((__packed__)) ingress_nh_table_value { } _NoAction; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } ingress_send_nh; struct { } ingress_drop; @@ -84,8 +84,8 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head 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; + storePrimitive64(&hdr->ethernet.srcAddr, 48, (value->u.ingress_send_nh.smac)); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (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); diff --git a/testdata/p4tc_samples_outputs/simple_exact_example_parser.c b/testdata/p4tc_samples_outputs/simple_exact_example_parser.c index b3f97935964..bfccb94574e 100644 --- a/testdata/p4tc_samples_outputs/simple_exact_example_parser.c +++ b/testdata/p4tc_samples_outputs/simple_exact_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/simple_exact_example_parser.h b/testdata/p4tc_samples_outputs/simple_exact_example_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/simple_exact_example_parser.h +++ b/testdata/p4tc_samples_outputs/simple_exact_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) 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 628bf01fe72..f829da90db2 100644 --- a/testdata/p4tc_samples_outputs/simple_extern_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/simple_extern_example_control_blocks.c @@ -27,8 +27,8 @@ struct __attribute__((__packed__)) ingress_nh_table_value { } ingress_ext_reg; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } ingress_send_nh; struct { } ingress_drop; @@ -66,8 +66,8 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head struct reg_val_t arg_val_0; __builtin_memset((void *) &arg_val_0, 0, sizeof(struct reg_val_t )); { - arg_val_0.protocol = hdr->ipv4.protocol; - arg_val_0.aux = 22; + arg_val_0.protocol = hdr->ipv4.protocol + arg_val_0.aux = 22 /* 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; @@ -117,7 +117,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head return TC_ACT_SHOT; ext_val = *ext_val_ptr; __builtin_memcpy(&val_0, ext_val.out_params, sizeof(u32 )); - val_0 = (val_0 + 10); + val_0 = (val_0 + 10) /* 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; @@ -135,8 +135,8 @@ ext_val = *ext_val_ptr; break; 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; + storePrimitive64(&hdr->ethernet.srcAddr, 48, (value->u.ingress_send_nh.smac)); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (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); diff --git a/testdata/p4tc_samples_outputs/simple_extern_example_parser.c b/testdata/p4tc_samples_outputs/simple_extern_example_parser.c index b18af2d1ba3..836642ce17a 100644 --- a/testdata/p4tc_samples_outputs/simple_extern_example_parser.c +++ b/testdata/p4tc_samples_outputs/simple_extern_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/simple_extern_example_parser.h b/testdata/p4tc_samples_outputs/simple_extern_example_parser.h index 808992488d7..bdab9c6429c 100644 --- a/testdata/p4tc_samples_outputs/simple_extern_example_parser.h +++ b/testdata/p4tc_samples_outputs/simple_extern_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -67,6 +67,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/simple_lpm_example_control_blocks.c b/testdata/p4tc_samples_outputs/simple_lpm_example_control_blocks.c index 606c218c12b..4328bd17378 100644 --- a/testdata/p4tc_samples_outputs/simple_lpm_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/simple_lpm_example_control_blocks.c @@ -23,8 +23,8 @@ struct __attribute__((__packed__)) ingress_nh_table_value { } _NoAction; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } ingress_send_nh; struct { } ingress_drop; @@ -84,8 +84,8 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head 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; + storePrimitive64(&hdr->ethernet.srcAddr, 48, (value->u.ingress_send_nh.smac)); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (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); diff --git a/testdata/p4tc_samples_outputs/simple_lpm_example_parser.c b/testdata/p4tc_samples_outputs/simple_lpm_example_parser.c index 073c8105072..049ea561786 100644 --- a/testdata/p4tc_samples_outputs/simple_lpm_example_parser.c +++ b/testdata/p4tc_samples_outputs/simple_lpm_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/simple_lpm_example_parser.h b/testdata/p4tc_samples_outputs/simple_lpm_example_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/simple_lpm_example_parser.h +++ b/testdata/p4tc_samples_outputs/simple_lpm_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/simple_ternary_example_control_blocks.c b/testdata/p4tc_samples_outputs/simple_ternary_example_control_blocks.c index f8bf4947570..b9bc4b91859 100644 --- a/testdata/p4tc_samples_outputs/simple_ternary_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/simple_ternary_example_control_blocks.c @@ -28,8 +28,8 @@ struct __attribute__((__packed__)) ingress_nh_table_value { } _NoAction; struct __attribute__((__packed__)) { u32 port_id; - u64 dmac; - u64 smac; + u8 dmac[6]; + u8 smac[6]; } ingress_send_nh; struct { } ingress_drop; @@ -90,8 +90,8 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head 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; + storePrimitive64(&hdr->ethernet.srcAddr, 48, (value->u.ingress_send_nh.smac)); + storePrimitive64(&hdr->ethernet.dstAddr, 48, (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); diff --git a/testdata/p4tc_samples_outputs/simple_ternary_example_parser.c b/testdata/p4tc_samples_outputs/simple_ternary_example_parser.c index 7a29aeb27f3..beb505e4fe4 100644 --- a/testdata/p4tc_samples_outputs/simple_ternary_example_parser.c +++ b/testdata/p4tc_samples_outputs/simple_ternary_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; else goto reject; diff --git a/testdata/p4tc_samples_outputs/simple_ternary_example_parser.h b/testdata/p4tc_samples_outputs/simple_ternary_example_parser.h index 7c722359cc5..13e39a9189a 100644 --- a/testdata/p4tc_samples_outputs/simple_ternary_example_parser.h +++ b/testdata/p4tc_samples_outputs/simple_ternary_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* bit<48> */ - u64 srcAddr; /* bit<48> */ + u8 dstAddr[6]; /* bit<48> */ + u8 srcAddr[6]; /* bit<48> */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/size_param_example_parser.c b/testdata/p4tc_samples_outputs/size_param_example_parser.c index 697c1199d51..5de1741ad1a 100644 --- a/testdata/p4tc_samples_outputs/size_param_example_parser.c +++ b/testdata/p4tc_samples_outputs/size_param_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/size_param_example_parser.h b/testdata/p4tc_samples_outputs/size_param_example_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/size_param_example_parser.h +++ b/testdata/p4tc_samples_outputs/size_param_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.c b/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.c index 16fbf526c82..142313fe35a 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.h index 7a99d4144a5..5ce76778c6d 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.c b/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.c index 704339bc654..5e610ea09aa 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_03_control_blocks.c b/testdata/p4tc_samples_outputs/tc_may_override_example_03_control_blocks.c index 13052c16716..bb665a40cd4 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_03_control_blocks.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_03_control_blocks.c @@ -79,7 +79,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, u8 hit; u32 z_0; { - z_0 = 4; + z_0 = 4 if (/* hdr->ipv4.isValid() */ hdr->ipv4.ebpf_valid) { /* ipv4_tbl.apply() */ diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.c b/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.c index dfa2d245d8f..99c74407498 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_04_control_blocks.c b/testdata/p4tc_samples_outputs/tc_may_override_example_04_control_blocks.c index 63e2fb8e6fb..7cca883f8d8 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_04_control_blocks.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_04_control_blocks.c @@ -113,14 +113,14 @@ if (/* hdr->ipv4.isValid() */ { if (value->is_default_miss_act) { - hdr->ipv4.dstAddr = p4tc_filter_fields.ipv4_tbl_1_next_hop_ipv4addr; + hdr->ipv4.dstAddr = p4tc_filter_fields.ipv4_tbl_1_next_hop_ipv4addr /* send_to_port(8) */ compiler_meta__->drop = false; send_to_port(8); } else { - hdr->ipv4.dstAddr = value->u.MainControlImpl_next_hop.ipv4addr; + hdr->ipv4.dstAddr = value->u.MainControlImpl_next_hop.ipv4addr /* send_to_port(8) */ compiler_meta__->drop = false; send_to_port(8); @@ -172,7 +172,7 @@ if (/* hdr->ipv4.isValid() */ switch (value->action) { case MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP: { - hdr->ipv4.dstAddr = value->u.MainControlImpl_next_hop.ipv4addr; + hdr->ipv4.dstAddr = value->u.MainControlImpl_next_hop.ipv4addr /* send_to_port(8) */ compiler_meta__->drop = false; send_to_port(8); diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.c b/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.c index 10ba238ba22..b639d8b636a 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.h index 743fd5363a3..3af86fb77a6 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -62,6 +62,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.c b/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.c index dcb5018eb10..4d7fee9f549 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.h index 3b6f75c5980..9e2bb579e93 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -62,6 +62,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.c b/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.c index ea7398e3bf4..13b5d05b592 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.h index d8475cf3118..6acb523b5ed 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.c b/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.c index aafa7c3dedc..2a7163a1a09 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.h index 7a99d4144a5..5ce76778c6d 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.c b/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.c index dcb5a694879..c1241e08eeb 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.h index 7a99d4144a5..5ce76778c6d 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -63,6 +63,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.c b/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.c index 6ee7f4bae87..bc1aab17aba 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.c +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.h index 90ff839fc9f..e308a7d590a 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -62,6 +62,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/tc_type_annotation_example_control_blocks.c b/testdata/p4tc_samples_outputs/tc_type_annotation_example_control_blocks.c index 0fd9258eb0c..375d07469db 100644 --- a/testdata/p4tc_samples_outputs/tc_type_annotation_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/tc_type_annotation_example_control_blocks.c @@ -110,7 +110,7 @@ if (/* hdr->ipv4.isValid() */ { /* drop_packet() */ drop_packet(); - hdr->ipv4.dstAddr = value->u.MainControlImpl_default_route_drop.ipv4addr; + hdr->ipv4.dstAddr = value->u.MainControlImpl_default_route_drop.ipv4addr } break; case MAINCONTROLIMPL_IPV4_TBL_1_ACT__NOACTION: diff --git a/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.c b/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.c index f4f20e29b1b..b1fb3ac40d6 100644 --- a/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.c +++ b/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.c @@ -100,7 +100,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x800)goto parse_ipv4; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.h b/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.h index 54a8b788e1b..02c684c97d5 100644 --- a/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.h +++ b/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -61,6 +61,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8) diff --git a/testdata/p4tc_samples_outputs/test_ipv6_example_control_blocks.c b/testdata/p4tc_samples_outputs/test_ipv6_example_control_blocks.c index 561e55eeb6f..c5e1f2aa9ce 100644 --- a/testdata/p4tc_samples_outputs/test_ipv6_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/test_ipv6_example_control_blocks.c @@ -80,7 +80,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, case MAINCONTROLIMPL_TBL_DEFAULT_ACT_MAINCONTROLIMPL_SET_DST: { __builtin_memcpy(&hdr->ipv6.dstAddr, &value->u.MainControlImpl_set_dst.addr6, 16); - hdr->ipv6.hopLimit = (hdr->ipv6.hopLimit + 255); + hdr->ipv6.hopLimit = (hdr->ipv6.hopLimit + 255) } break; case MAINCONTROLIMPL_TBL_DEFAULT_ACT__NOACTION: diff --git a/testdata/p4tc_samples_outputs/test_ipv6_example_parser.c b/testdata/p4tc_samples_outputs/test_ipv6_example_parser.c index 86f16611576..d1f8fdd89c2 100644 --- a/testdata/p4tc_samples_outputs/test_ipv6_example_parser.c +++ b/testdata/p4tc_samples_outputs/test_ipv6_example_parser.c @@ -118,7 +118,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h ; u16 select_0; - select_0 = hdr->ethernet.etherType; + select_0 = hdr->ethernet.etherType if (select_0 == 0x86dd)goto parse_ipv6; if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; else goto reject; diff --git a/testdata/p4tc_samples_outputs/test_ipv6_example_parser.h b/testdata/p4tc_samples_outputs/test_ipv6_example_parser.h index 2a658bc386b..d56c152502a 100644 --- a/testdata/p4tc_samples_outputs/test_ipv6_example_parser.h +++ b/testdata/p4tc_samples_outputs/test_ipv6_example_parser.h @@ -12,8 +12,8 @@ struct ethernet_t { - u64 dstAddr; /* EthernetAddress */ - u64 srcAddr; /* EthernetAddress */ + u8 dstAddr[6]; /* EthernetAddress */ + u8 srcAddr[6]; /* EthernetAddress */ u16 etherType; /* bit<16> */ u8 ebpf_valid; }; @@ -35,7 +35,7 @@ struct ipv4_t { struct ipv6_t { u8 version; /* bit<4> */ u8 trafficClass; /* bit<8> */ - u32 flowLabel; /* bit<20> */ + u8 flowLabel[3]; /* bit<20> */ u16 payloadLength; /* bit<16> */ u8 nextHeader; /* bit<8> */ u8 hopLimit; /* bit<8> */ @@ -72,6 +72,39 @@ 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() +u32 getPrimitive32(u8 *a, int size) { + return ((a[2]<<16) | (a[1] << 8) | a[0]); +} +u64 getPrimitive64(u8 *a, int size) { + if(size < 40) { + return ((a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + if(size < 48) { + return ((a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } else { + return ((a[6] << 48) | (a[5] << 40) | (a[4] << 32) | (a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]); + } + } +} +void storePrimitive32(u8 *a, u32 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); +} +void storePrimitive64(u8 *a, int size, u64 value) { + a[0] = (u8)(value); + a[1] = (u8)(value >> 8); + a[2] = (u8)(value >> 16); + a[3] = (u8)(value >> 24); + a[4] = (u8)(value >> 32); + if (size < 48) { + a[5] = (u8)(value >> 40); + } + if (size < 56){ + a[6] = (u8)(value >> 48); + } +} + static __always_inline void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { if (data_size <= 8)