Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dash-p4] Create macro for creating direct counters #523

Merged
merged 1 commit into from
Feb 28, 2024
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
24 changes: 23 additions & 1 deletion dash-pipeline/bmv2/dash_arch_specific.p4
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#ifdef TARGET_BMV2_V1MODEL

#include <v1model.p4>

// Counters
#define DEFINE_TABLE_COUNTER(counter_name) direct_counter(CounterType.packets_and_bytes) counter_name;
#define ATTACH_TABLE_COUNTER(counter_name) counters = counter_name;
#define DIRECT_COUNTER_TABLE_PROPERTY counters

// DBC (Design By Contract) macros
Expand All @@ -14,7 +18,25 @@
#ifdef TARGET_DPDK_PNA

#include <pna.p4>
#define DIRECT_COUNTER_TABLE_PROPERTY pna_direct_counter

// Counters
#ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
// Omit all direct counters for tables with ternary match keys,
// because the latest version of p4c-dpdk as of 2023-Jan-26 does
// not support this combination of features. If you try to
// compile it with this code enabled, the error message looks like
// this:
//
// [--Werror=target-error] error: Direct counters and direct meters are unsupported for wildcard match table outbound_acl_stage1:dash_acl_rule|dash_acl
//
// This p4c issue is tracking this feature gap in p4c-dpdk:
// https://github.com/p4lang/p4c/issues/3868
#define DEFINE_TABLE_COUNTER(counter_name) DirectCounter<bit<64>>(PNA_CounterType_t.PACKETS_AND_BYTES) counter_name;
#define ATTACH_TABLE_COUNTER(counter_name) pna_direct_counter = counter_name;
#else
#define DEFINE_TABLE_COUNTER(counter_name)
#define ATTACH_TABLE_COUNTER(counter_name)
#endif

// DBC (Design By Contract) macros
// NOTE: PNA doesn't support assert, hence all macros are defined as empty
Expand Down
36 changes: 4 additions & 32 deletions dash-pipeline/bmv2/dash_outbound.p4
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@
control outbound(inout headers_t hdr,
inout metadata_t meta)
{
#ifdef TARGET_BMV2_V1MODEL
direct_counter(CounterType.packets_and_bytes) routing_counter;
#elif TARGET_DPDK_PNA // TARGET_BMV2_V1MODEL
#ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
// See the #ifdef with same preprocessor symbol in dash_pipeline.p4
DirectCounter<bit<64>>(PNA_CounterType_t.PACKETS_AND_BYTES) routing_counter;
#endif // DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
#endif // TARGET_DPDK_PNA
DEFINE_TABLE_COUNTER(routing_counter)

@SaiTable[name = "outbound_routing", api = "dash_outbound_routing"]
table routing {
Expand All @@ -35,24 +28,10 @@ control outbound(inout headers_t hdr,
}
const default_action = drop(meta);

#ifdef TARGET_BMV2_V1MODEL
counters = routing_counter;
#endif // TARGET_BMV2_V1MODEL
#ifdef TARGET_DPDK_PNA
#ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
pna_direct_counter = routing_counter;
#endif // DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
#endif // TARGET_DPDK_PNA
ATTACH_TABLE_COUNTER(routing_counter)
}

#ifdef TARGET_BMV2_V1MODEL
direct_counter(CounterType.packets_and_bytes) ca_to_pa_counter;
#endif // TARGET_BMV2_V1MODEL
#ifdef TARGET_DPDK_PNA
#ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
DirectCounter<bit<64>>(PNA_CounterType_t.PACKETS_AND_BYTES) ca_to_pa_counter;
#endif // DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
#endif // TARGET_DPDK_PNA
DEFINE_TABLE_COUNTER(ca_to_pa_counter)

@SaiTable[name = "outbound_ca_to_pa", api = "dash_outbound_ca_to_pa"]
table ca_to_pa {
Expand All @@ -70,14 +49,7 @@ control outbound(inout headers_t hdr,
}
const default_action = drop(meta);

#ifdef TARGET_BMV2_V1MODEL
counters = ca_to_pa_counter;
#endif // TARGET_BMV2_V1MODEL
#ifdef TARGET_DPDK_PNA
#ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
pna_direct_counter = ca_to_pa_counter;
#endif // DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
#endif // TARGET_DPDK_PNA
ATTACH_TABLE_COUNTER(ca_to_pa_counter)
}

action set_vnet_attrs(bit<24> vni) {
Expand Down
28 changes: 2 additions & 26 deletions dash-pipeline/bmv2/dash_pipeline.p4
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,7 @@ control dash_ingress(
const default_action = deny;
}

#ifdef TARGET_BMV2_V1MODEL
direct_counter(CounterType.packets_and_bytes) eni_counter;
#endif // TARGET_BMV2_V1MODEL
#ifdef TARGET_DPDK_PNA
#ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
// Omit all direct counters for tables with ternary match keys,
// because the latest version of p4c-dpdk as of 2023-Jan-26 does
// not support this combination of features. If you try to
// compile it with this code enabled, the error message looks like
// this:
//
// [--Werror=target-error] error: Direct counters and direct meters are unsupported for wildcard match table outbound_acl_stage1:dash_acl_rule|dash_acl
//
// This p4c issue is tracking this feature gap in p4c-dpdk:
// https://github.com/p4lang/p4c/issues/3868
DirectCounter<bit<64>>(PNA_CounterType_t.PACKETS_AND_BYTES) eni_counter;
#endif // DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
#endif // TARGET_DPDK_PNA
DEFINE_TABLE_COUNTER(eni_counter)

@SaiTable[ignored = "true"]
table eni_meter {
Expand All @@ -217,14 +200,7 @@ control dash_ingress(

actions = { NoAction; }

#ifdef TARGET_BMV2_V1MODEL
counters = eni_counter;
#endif // TARGET_BMV2_V1MODEL
#ifdef TARGET_DPDK_PNA
#ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
pna_direct_counter = eni_counter;
#endif // DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
#endif // TARGET_DPDK_PNA
ATTACH_TABLE_COUNTER(eni_counter)
}

action permit() {
Expand Down
Loading