Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backends/dpdk/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const cstring tdiSchemaVersion = "0.1";
#define CRC3 3
#define CRC4 4
#define JHASH5 5

#define TOEPLITZ 6
// Initial values for group_id and member_id for action selector and action profile tables
const unsigned initial_member_id = 0;
const unsigned initial_group_id = 0xFFFFFFFF;
Expand Down
8 changes: 8 additions & 0 deletions backends/dpdk/dpdk.def
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,15 @@ class DpdkChecksumClearStatement : DpdkAsmStatement, IDPDKNode {
#nodbprint
}

class DpdkHashDeclStatement: DpdkAsmStatement {
cstring hash;
std::ostream& toSpec(std::ostream& out) const override;
#nodbprint
}


class DpdkGetHashStatement : DpdkAsmStatement, IDPDKNode {
cstring instr;
cstring hash;
Expression fields;
Expression dst;
Expand Down
5 changes: 5 additions & 0 deletions backends/dpdk/dpdkArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ class CollectExternDeclaration : public Inspector {
::error(ErrorType::ERR_EXPECTED,
"%1%: expected size and optionally init_val as arguments", d);
}
} else if (externTypeName == "Hash") {
if (d->arguments->size() != 1) {
::error(ErrorType::ERR_EXPECTED,
"%1%: expected hash algorithm as the only argument", d);
}
} else {
// unsupported extern type
return false;
Expand Down
16 changes: 11 additions & 5 deletions backends/dpdk/dpdkHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,24 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) {
auto di = e->object->to<IR::Declaration_Instance>();
auto declArgs = di->arguments;
if (declArgs->size() == 0) {
::error(ErrorType::ERR_UNEXPECTED, "Expected atleast 1 argument for %1%",
::error(ErrorType::ERR_UNEXPECTED, "Expected 1 argument for %1%",
e->object->getName());
return false;
}
auto hash_alg = declArgs->at(0)->expression;
unsigned hashAlgValue = 0;
unsigned hashAlgValue = CRC1;
cstring hashInstr = "hash";
if (hash_alg->is<IR::Constant>())
hashAlgValue = hash_alg->to<IR::Constant>()->asUnsigned();
cstring hashAlgName = "";
cstring hashAlgName = "crc32";
if (hashAlgValue == JHASH0 || hashAlgValue == JHASH5)
hashAlgName = "jhash";
else if (hashAlgValue >= CRC1 && hashAlgValue <= CRC4)
hashAlgName = "crc32";
else if (hashAlgValue == TOEPLITZ) {
hashAlgName = e->object->getName().name;
hashInstr = "rss";
}

IR::Vector<IR::Expression> components;
IR::ListExpression *listExp = nullptr;
Expand Down Expand Up @@ -287,7 +292,7 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) {
processHashParams(field, components);
}
listExp = new IR::ListExpression(components);
i = new IR::DpdkGetHashStatement(hashAlgName, listExp, left);
i = new IR::DpdkGetHashStatement(hashInstr, hashAlgName, listExp, left);
} else if (e->expr->arguments->size() == 3) {
auto maxValue = 0;
auto base = (*e->expr->arguments)[0];
Expand Down Expand Up @@ -335,7 +340,7 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) {
}
listExp = new IR::ListExpression(components);
auto bs = base->expression->to<IR::Expression>();
add_instr(new IR::DpdkGetHashStatement(hashAlgName, listExp, left));
add_instr(new IR::DpdkGetHashStatement(hashInstr, hashAlgName, listExp, left));
add_instr(new IR::DpdkAndStatement(left, left, new IR::Constant(maxValue - 1)));
i = new IR::DpdkAddStatement(left, left, bs);
}
Expand Down Expand Up @@ -706,6 +711,7 @@ bool ConvertStatementToDpdk::checkIfBelongToSameHdrMdStructure(const IR::Argumen
sName = getHdrMdStrName(exp);
}
}

if (hdrStrName == "")
hdrStrName = sName;
else if (hdrStrName != sName)
Expand Down
28 changes: 25 additions & 3 deletions backends/dpdk/spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std::ostream &IR::DpdkAsmProgram::toSpec(std::ostream &out) const {
}
for (auto s : externDeclarations) {
add_comment(out, s->name.toString());
s->toSpec(out) << std::endl;
s->toSpec(out);
}
for (auto a : actions) {
add_comment(out, a->name.toString());
Expand Down Expand Up @@ -70,7 +70,23 @@ std::ostream &IR::DpdkDeclaration::toSpec(std::ostream &out) const {
}

std::ostream &IR::DpdkExternDeclaration::toSpec(std::ostream &out) const {
if (DPDK::toStr(getType()) == "Register") {
if (DPDK::toStr(getType()) == "Hash") {
auto args = arguments;
if (args->size() == 0) {
::error(ErrorType::ERR_INVALID,
"Hash extern declaration %1% must contain hash algorithm \n", Name());
} else {
auto hashAlg = args->at(0)->expression;
unsigned hashAlgValue = CRC1;
if (hashAlg->is<IR::Constant>())
hashAlgValue = hashAlg->to<IR::Constant>()->asUnsigned();
if (hashAlgValue == TOEPLITZ) {
auto hashDecl = new IR::DpdkHashDeclStatement(Name());
hashDecl->toSpec(out) << std::endl;
}
}

} else if (DPDK::toStr(getType()) == "Register") {
auto args = arguments;
if (args->size() == 0) {
::error(ErrorType::ERR_INVALID,
Expand Down Expand Up @@ -552,8 +568,14 @@ std::ostream &IR::DpdkChecksumClearStatement::toSpec(std::ostream &out) const {
return out;
}

std::ostream &IR::DpdkHashDeclStatement::toSpec(std::ostream &out) const {
add_comment(out, hash);
out << "rss " << hash;
return out;
}

std::ostream &IR::DpdkGetHashStatement::toSpec(std::ostream &out) const {
out << "hash " << hash << " " << DPDK::toStr(dst) << " ";
out << instr << " " << hash << " " << DPDK::toStr(dst) << " ";
if (auto l = fields->to<IR::ListExpression>()) {
if (l->components.size() == 1) {
out << " " << DPDK::toStr(l->components.at(0));
Expand Down
7 changes: 7 additions & 0 deletions p4include/dpdk/pna.p4
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ match_kind {
// BEGIN:Hash_algorithms
enum PNA_HashAlgorithm_t {
// TBD what this type's values will be for PNA
IDENTITY,
CRC32,
CRC32_CUSTOM,
CRC16,
CRC16_CUSTOM,
ONES_COMPLEMENT16, /// One's complement 16-bit sum used for IPv4 headers,
TOEPLITZ,
TARGET_DEFAULT /// target implementation defined
}
// END:Hash_algorithms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ pna-example-ipsec-err3.p4(144): [--Werror=type-error] error: ipsec.set_sa_index
ipsec.set_sa_index<bit<32>, bit<8>>(sa_index);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
---- Actual error:
pna.p4(516): set_sa_index: 1 type parameters expected, but 2 type arguments supplied
pna.p4(523): set_sa_index: 1 type parameters expected, but 2 type arguments supplied
void set_sa_index<T>(in T sa_index);
^^^^^^^^^^^^
---- Originating from:
pna.p4(516): Function type 'set_sa_index' does not match invocation type '<Method call>'
pna.p4(523): Function type 'set_sa_index' does not match invocation type '<Method call>'
void set_sa_index<T>(in T sa_index);
^^^^^^^^^^^^
pna-example-ipsec-err3.p4(144)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pna.p4(393): [--Werror=unexpected] error: count method of per_prefix_pkt_bytes_count extern can only be invoked from within action of ownertable
pna.p4(400): [--Werror=unexpected] error: count method of per_prefix_pkt_bytes_count extern can only be invoked from within action of ownertable
void count(in bit<32> pkt_len);
^^^^^
120 changes: 120 additions & 0 deletions testdata/p4_16_samples/pna-dpdk-toeplitz-hash-1.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
Copyright 2023 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <core.p4>
#include <dpdk/pna.p4>


typedef bit<48> EthernetAddress;

header ethernet_t {
EthernetAddress dstAddr;
EthernetAddress srcAddr;
bit<16> etherType;
}

header ipv4_t {
bit<4> version;
bit<4> ihl;
bit<8> diffserv;
bit<16> totalLen;
bit<16> identification;
bit<3> flags;
bit<13> fragOffset;
bit<8> ttl;
bit<8> protocol;
bit<16> hdrChecksum;
bit<32> srcAddr;
bit<32> dstAddr;
}

struct main_metadata_t {
bit<32> port;
bit<32> hash;
}

// User-defined struct containing all of those headers parsed in the
// main parser.
struct headers_t {
ethernet_t ethernet;
ipv4_t ipv4;
}

control PreControlImpl(
in headers_t hdr,
inout main_metadata_t meta,
in pna_pre_input_metadata_t istd,
inout pna_pre_output_metadata_t ostd)
{
apply {
}
}

parser MainParserImpl(
packet_in pkt,
out headers_t hdr,
inout main_metadata_t main_meta,
in pna_main_parser_input_metadata_t istd)
{
state start {
pkt.extract(hdr.ethernet);
transition select(hdr.ethernet.etherType) {
0x0800: parse_ipv4;
default: accept;
}
}
state parse_ipv4 {
pkt.extract(hdr.ipv4);
transition accept;
}
}

Hash<bit<32>>(PNA_HashAlgorithm_t.CRC32) rss0;

control MainControlImpl(
inout headers_t hdr, // from main parser
inout main_metadata_t main_meta, // from main parser, to "next block"
in pna_main_input_metadata_t istd,
inout pna_main_output_metadata_t ostd)
{
apply {
main_meta.hash = rss0.get_hash({hdr.ipv4.srcAddr, hdr.ipv4.dstAddr});
main_meta.hash = main_meta.hash & 3;
main_meta.port = main_meta.hash;
}
}

control MainDeparserImpl(
packet_out pkt,
in headers_t hdr, // from main control
in main_metadata_t user_meta, // from main control
in pna_main_output_metadata_t ostd)
{
apply {
pkt.emit(hdr.ethernet);
pkt.emit(hdr.ipv4);
}
}

PNA_NIC(
MainParserImpl(),
PreControlImpl(),
MainControlImpl(),
MainDeparserImpl()
// Hoping to make this optional parameter later, but not supported
// by p4c yet.
//, PreParserImpl()
) main;
Loading