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

Adds dash underlay routing functionality #402

Closed
wants to merge 7 commits into from
Closed
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 dash-pipeline/SAI/SAI
Submodule SAI updated 187 files
29 changes: 13 additions & 16 deletions dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
'sai_ip_addr_family_t': 'u32',
'sai_uint32_t': 'u32',
'sai_uint64_t': 'u64',
'sai_mac_t': 'mac',
'sai_ip_prefix_list_t': 'ipprefixlist'
'sai_mac_t': 'mac'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this removed ?

}

def p4_annotation_to_sai_attr(p4rt, sai_attr):
Expand Down Expand Up @@ -244,7 +243,6 @@ def get_sai_enums(program):
sai_enum = dict()
sai_enum['name'] = enum_name[:-2]
sai_enum['members'] = []
print(enum_name)
for enum_member in all_enums[enum_name][MEMBERS_TAG]:
member = dict()
member['sai_name'] = enum_member['name']
Expand Down Expand Up @@ -362,8 +360,11 @@ def write_sai_impl_files(sai_api):
env.add_extension('jinja2.ext.loopcontrols')
env.add_extension('jinja2.ext.do')
sai_impl_tm = env.get_template('/templates/saiapi.cpp.j2')
sai_impl_str = sai_impl_tm.render(tables = sai_api[TABLES_TAG], app_name = sai_api['app_name'])

if "dash" in sai_api['app_name']:
header_prefix = "experimental"
else:
header_prefix = ""
sai_impl_str = sai_impl_tm.render(tables = sai_api[TABLES_TAG], app_name = sai_api['app_name'], header_prefix = header_prefix)
with open('./lib/sai' + sai_api['app_name'].replace('_', '') + '.cpp', 'w') as o:
o.write(sai_impl_str)

Expand Down Expand Up @@ -507,25 +508,21 @@ def write_sai_files(sai_api):
for table_name in all_table_names:
if table_ref.endswith(table_name):
key[OBJECT_NAME_TAG] = table_name

# Write SAI dictionary into SAI API headers
write_sai_files(get_uniq_sai_api(sai_api))
if "dash" in sai_api['app_name']:
write_sai_files(get_uniq_sai_api(sai_api))

# Write SAI implementation
write_sai_impl_files(sai_api)
sai_api_name_list.append(sai_api['app_name'].replace('_', ''))
sai_api_full_name_list.append(sai_api['app_name'])

env = Environment(loader=FileSystemLoader('.'), trim_blocks=True, lstrip_blocks=True)
env.add_extension('jinja2.ext.loopcontrols')
env.add_extension('jinja2.ext.do')

final_sai_enums = []
with open('./SAI/experimental/saitypesextensions.h', 'r') as f:
content = f.read()
for enum in sai_enums:
if enum['name'] not in content:
final_sai_enums.append(enum)

sai_enums_tm = env.get_template('templates/saienums.j2')
sai_enums_str = sai_enums_tm.render(sai_enums = final_sai_enums)
sai_enums_str = sai_enums_tm.render(sai_enums = sai_enums)
sai_enums_lines = sai_enums_str.split('\n')

# The SAI object struct for entries
Expand All @@ -548,4 +545,4 @@ def write_sai_files(sai_api):
write_sai_fixed_api_files(sai_api_full_name_list)

if args.print_sai_lib:
print(json.dumps(sai_api, indent=2))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change this ?

print(json.dumps(sai_api, indent=2))
4 changes: 2 additions & 2 deletions dash-pipeline/SAI/templates/saiapi.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <grpcpp/grpcpp.h>
#include "p4/v1/p4runtime.grpc.pb.h"
#include "utils.h"
#include "saiexperimental{{ app_name | replace('_', '') }}.h"
#include "sai{{ header_prefix }}{{ app_name | replace('_', '') }}.h"
#include "saitypes.h"
#include "saistatus.h"
#include <fstream>
Expand Down Expand Up @@ -527,4 +527,4 @@ sai_{{ app_name }}_api_t sai_{{app_name }}_api_impl = {
.remove_{{ table.name | replace("entry", "entries") }} = sai_remove_{{ table.name | replace("entry", "entries") }},
{% endif %}
{% endfor %}
};
};
9 changes: 4 additions & 5 deletions dash-pipeline/SAI/templates/saifixedapis.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern "C" {
#include "saistatus.h"
#include "saitypes.h"
#include "saiextensions.h"
#include "sairoute.h" // TODO: Change to template generated values
}
#include <fstream>
#include <google/protobuf/text_format.h>
Expand Down Expand Up @@ -55,8 +56,8 @@ sai_status_t sai_create_switch_dummy(
#define DASH_BMV2_DEFAULT_1Q_BRIDGE_ID MAKE_OID(SAI_OBJECT_TYPE_BRIDGE,1)

sai_object_id_t port_list[DASH_BMV2_NUM_PORTS] = {
MAKE_OID(SAI_OBJECT_TYPE_PORT,1),
MAKE_OID(SAI_OBJECT_TYPE_PORT,2)
MAKE_OID(SAI_OBJECT_TYPE_PORT,0),
MAKE_OID(SAI_OBJECT_TYPE_PORT,1)
};

sai_status_t sai_get_switch_attribute(
Expand Down Expand Up @@ -250,8 +251,6 @@ sai_status_t sai_api_initialize(
_In_ uint64_t flags,
_In_ const sai_service_method_table_t *services) { return SAI_STATUS_SUCCESS; }

sai_status_t sai_api_uninitialize(void) { return SAI_STATUS_SUCCESS; }

sai_status_t sai_log_set(
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) { return SAI_STATUS_SUCCESS; }
_In_ sai_log_level_t log_level) { return SAI_STATUS_SUCCESS; }
25 changes: 16 additions & 9 deletions dash-pipeline/bmv2/dash_pipeline.p4
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "dash_outbound.p4"
#include "dash_inbound.p4"
#include "dash_conntrack.p4"
#include "underlay.p4"

control dash_ingress(
inout headers_t hdr
Expand Down Expand Up @@ -371,13 +372,8 @@ control dash_ingress(
set_dst_tag;
}
}

apply {

/* Send packet on same port it arrived (echo) by default */
#ifdef TARGET_BMV2_V1MODEL
standard_metadata.egress_spec = standard_metadata.ingress_port;
#endif // TARGET_BMV2_V1MODEL
#ifdef TARGET_DPDK_PNA
#ifdef DPDK_PNA_SEND_TO_PORT_FIX_MERGED
// As of 2023-Jan-26, the version of the pna.p4 header file
Expand Down Expand Up @@ -454,14 +450,25 @@ control dash_ingress(

src_tag.apply();
dst_tag.apply();


if (meta.direction == dash_direction_t.OUTBOUND) {
outbound.apply(hdr, meta);
} else if (meta.direction == dash_direction_t.INBOUND) {
inbound.apply(hdr, meta);
}

/* Underlay routing */
meta.dst_ip_addr = (bit<128>)hdr.ipv4.dst_addr;
underlay.apply(
hdr
, meta
#ifdef TARGET_BMV2_V1MODEL
, standard_metadata
#endif // TARGET_BMV2_V1MODEL
#ifdef TARGET_DPDK_PNA
, istd
#endif // TARGET_DPDK_PNA
);

if (meta.meter_policy_en == 1) {
meter_policy.apply();
meter_rule.apply();
Expand Down Expand Up @@ -502,4 +509,4 @@ control dash_ingress(
#endif // TARGET_BMV2_V1MODEL
#ifdef TARGET_DPDK_PNA
#include "dash_dpdk_pna.p4"
#endif // TARGET_DPDK_PNA
#endif // TARGET_DPDK_PNA
76 changes: 76 additions & 0 deletions dash-pipeline/bmv2/underlay.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <core.p4>
#include "dash_headers.p4"
#include "dash_metadata.p4"

control underlay(
inout headers_t hdr
, inout metadata_t meta
#ifdef TARGET_BMV2_V1MODEL
, inout standard_metadata_t standard_metadata
#endif // TARGET_BMV2_V1MODEL
#ifdef TARGET_DPDK_PNA
, in pna_main_input_metadata_t istd
#endif // TARGET_DPDK_PNA
)
{
action set_nhop(bit<9> next_hop_id) {
#ifdef TARGET_BMV2_V1MODEL
standard_metadata.egress_spec = next_hop_id;
#endif // TARGET_BMV2_V1MODEL

#ifdef TARGET_DPDK_PNA
#ifdef DPDK_PNA_SEND_TO_PORT_FIX_MERGED
// As of 2023-Jan-26, the version of the pna.p4 header file
// included with p4c defines send_to_port with a parameter
// that has no 'in' direction. The following commit in the
// public pna repo fixes this, but this fix has not yet been
// copied into the p4c repo.
// https://github.com/p4lang/pna/commit/b9fdfb888e5385472c34ff773914c72b78b63058
// Until p4c is updated with this fix, the following line will
// give a compile-time error.
istd.input_port = next_hop_id;
send_to_port(istd.input_port);
#endif // DPDK_PNA_SEND_TO_PORT_FIX_MERGED
#endif // TARGET_DPDK_PNA
}

action def_act() {
#ifdef TARGET_BMV2_V1MODEL
standard_metadata.egress_spec = standard_metadata.ingress_port;
#endif // TARGET_BMV2_V1MODEL

#ifdef TARGET_DPDK_PNA
#ifdef DPDK_PNA_SEND_TO_PORT_FIX_MERGED
// As of 2023-Jan-26, the version of the pna.p4 header file
// included with p4c defines send_to_port with a parameter
// that has no 'in' direction. The following commit in the
// public pna repo fixes this, but this fix has not yet been
// copied into the p4c repo.
// https://github.com/p4lang/pna/commit/b9fdfb888e5385472c34ff773914c72b78b63058
// Until p4c is updated with this fix, the following line will
// give a compile-time error.
send_to_port(istd.input_port);
#endif // DPDK_PNA_SEND_TO_PORT_FIX_MERGED
#endif // TARGET_DPDK_PNA
}

@name("route|route")
// TODO: To add structural annotations (example: @Sai[skipHeaderGen=true])
table underlay_routing {
key = {
meta.dst_ip_addr : lpm @name("meta.dst_ip_addr:destination");
}

actions = {
/* Send packet on different/same port it arrived based on routing */
set_nhop;

/* Send packet on same port it arrived (echo) by default */
@defaultonly def_act;
}
}

apply {
underlay_routing.apply();
}
}
Loading