Skip to content

Commit

Permalink
Split SAI API (#201)
Browse files Browse the repository at this point in the history
Make APIs compatible with SONiC bulk infra

Signed-off-by: Marian Pritsak <marianp@mellanox.com>
  • Loading branch information
marian-pritsak authored Sep 7, 2022
1 parent e2c1101 commit 2cd5b44
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
8 changes: 5 additions & 3 deletions dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def write_sai_impl_files(sai_api):
with open('./lib/sai' + sai_api['app_name'].replace('_', '') + '.cpp', 'w') as o:
o.write(sai_impl_str)

def write_sai_makefile(sai_api_name_list):
def write_sai_makefile(sai_api_name_list, sai_api_full_name_list):
env = Environment(loader=FileSystemLoader('.'))
makefile_tm = env.get_template('/templates/Makefile.j2')
makefile_str = makefile_tm.render(api_names = sai_api_name_list)
Expand All @@ -281,7 +281,7 @@ def write_sai_makefile(sai_api_name_list):

env = Environment(loader=FileSystemLoader('.'), trim_blocks=True, lstrip_blocks=True)
sai_impl_tm = env.get_template('/templates/utils.cpp.j2')
sai_impl_str = sai_impl_tm.render(tables = sai_api[TABLES_TAG], app_name = sai_api['app_name'])
sai_impl_str = sai_impl_tm.render(tables = sai_api[TABLES_TAG], app_name = sai_api['app_name'], api_names = sai_api_full_name_list)

with open('./lib/utils.cpp', 'w') as o:
o.write(sai_impl_str)
Expand Down Expand Up @@ -393,6 +393,7 @@ def write_sai_files(sai_api):
sai_apis, all_table_names = generate_sai_apis(json_program, args.ignore_tables.split(','))

sai_api_name_list = []
sai_api_full_name_list = []
for sai_api in sai_apis:
# Update object name reference for action params
for table in sai_api[TABLES_TAG]:
Expand All @@ -415,8 +416,9 @@ def write_sai_files(sai_api):
write_sai_files(sai_api)
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'])

write_sai_makefile(sai_api_name_list)
write_sai_makefile(sai_api_name_list, sai_api_full_name_list)

if args.print_sai_lib:
print(json.dumps(sai_api, indent=2))
22 changes: 7 additions & 15 deletions dash-pipeline/SAI/templates/utils.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,11 @@ sai_switch_api_t sai_switch_api_impl = {
};


/* TODO [cs] This should be auto-generated or part of per-API, auto-generated include file */
extern sai_dash_api_t sai_dash_api_impl;
extern sai_dash_vnet_api_t sai_dash_vnet_api_impl;
extern sai_dash_acl_api_t sai_dash_acl_api_impl;
{% for api in api_names %}
extern sai_{{ api }}_api_t sai_{{ api }}_api_impl;
{% endfor %}


/* TODO [cs] This should be auto-generated */
sai_status_t sai_api_query(
_In_ sai_api_t api,
_Out_ void **api_method_table) {
Expand All @@ -260,18 +258,12 @@ sai_status_t sai_api_query(
*api_method_table = (void *)&sai_switch_api_impl;
break;

case SAI_API_DASH:
*api_method_table = (void *)&sai_dash_api_impl;
{% for api in api_names %}
case SAI_API_{{ api | upper }}:
*api_method_table = (void *)&sai_{{ api }}_api_impl;
break;

case SAI_API_DASH_ACL:
*api_method_table = (void *)&sai_dash_acl_api_impl;
break;

case SAI_API_DASH_VNET:
*api_method_table = (void *)&sai_dash_vnet_api_impl;
break;

{% endfor %}
default:
return SAI_STATUS_NOT_SUPPORTED;

Expand Down
4 changes: 2 additions & 2 deletions dash-pipeline/bmv2/dash_outbound.p4
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ control outbound(inout headers_t hdr,

direct_counter(CounterType.packets_and_bytes) routing_counter;

@name("outbound_routing|dash_vnet")
@name("outbound_routing|dash_outbound_routing")
table routing {
key = {
meta.eni_id : exact @name("meta.eni_id:eni_id");
Expand Down Expand Up @@ -61,7 +61,7 @@ control outbound(inout headers_t hdr,

direct_counter(CounterType.packets_and_bytes) ca_to_pa_counter;

@name("outbound_ca_to_pa|dash_vnet")
@name("outbound_ca_to_pa|dash_outbound_ca_to_pa")
table ca_to_pa {
key = {
/* Flow for express route */
Expand Down
12 changes: 6 additions & 6 deletions dash-pipeline/bmv2/dash_pipeline.p4
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ control dash_ingress(inout headers_t hdr,
action accept() {
}

@name("vip|dash")
@name("vip|dash_vip")
table vip {
key = {
hdr.ipv4.dst_addr : exact @name("hdr.ipv4.dst_addr:VIP");
Expand All @@ -53,7 +53,7 @@ control dash_ingress(inout headers_t hdr,
meta.direction = direction_t.OUTBOUND;
}

@name("direction_lookup|dash")
@name("direction_lookup|dash_direction_lookup")
table direction_lookup {
key = {
hdr.vxlan.vni : exact @name("hdr.vxlan.vni:VNI");
Expand Down Expand Up @@ -132,7 +132,7 @@ control dash_ingress(inout headers_t hdr,
}
}

@name("eni|dash")
@name("eni|dash_eni")
table eni {
key = {
meta.eni_id : exact @name("meta.eni_id:eni_id");
Expand Down Expand Up @@ -166,7 +166,7 @@ control dash_ingress(inout headers_t hdr,
meta.vnet_id = src_vnet_id;
}

@name("pa_validation|dash_vnet")
@name("pa_validation|dash_pa_validation")
table pa_validation {
key = {
meta.vnet_id: exact @name("meta.vnet_id:vnet_id");
Expand All @@ -181,7 +181,7 @@ control dash_ingress(inout headers_t hdr,
const default_action = deny;
}

@name("inbound_routing|dash_vnet")
@name("inbound_routing|dash_inbound_routing")
table inbound_routing {
key = {
meta.eni_id: exact @name("meta.eni_id:eni_id");
Expand All @@ -201,7 +201,7 @@ control dash_ingress(inout headers_t hdr,
meta.eni_id = eni_id;
}

@name("eni_ether_address_map|dash")
@name("eni_ether_address_map|dash_eni")
table eni_ether_address_map {
key = {
meta.eni_addr : exact @name("meta.eni_addr:address");
Expand Down
3 changes: 3 additions & 0 deletions dash-pipeline/tests/libsai/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Call make in each subdirectory
.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS += -e
SUBDIRS := $(wildcard */.)


Expand Down
2 changes: 0 additions & 2 deletions dash-pipeline/tests/libsai/vnet_out/vnet_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ extern sai_status_t sai_create_dash_acl_group(
extern sai_status_t sai_remove_dash_acl_group(
_In_ sai_object_id_t eni_id);

extern sai_dash_api_t sai_dash_api_impl;

int main(int argc, char **argv)
{
sai_object_id_t switch_id = SAI_NULL_OBJECT_ID;
Expand Down

0 comments on commit 2cd5b44

Please sign in to comment.