diff --git a/meta/templates/sai_rpc_server_helper_functions.tt b/meta/templates/sai_rpc_server_helper_functions.tt index 1ca1ad545..f5f9f729e 100644 --- a/meta/templates/sai_rpc_server_helper_functions.tt +++ b/meta/templates/sai_rpc_server_helper_functions.tt @@ -31,7 +31,8 @@ } [%- END -%] [%- FOREACH struct IN apis.$api.structs %] - + [%- NEXT IF struct.short_name == 'neighbor_entry' %] + [%- NEXT IF struct.short_name == 'route_entry' %] [%- PROCESS struct_helper_function_header %] { @@ -135,8 +136,52 @@ void sai_thrift_parse_[% struct.short_name %](const [% struct.thrift_name %] &th [%- ######################################################################## -%] [%- BLOCK special_helper_functions -%] +extern sai_object_id_t switch_id; + void sai_thrift_parse_buffer(const std::string &thrift_buffer, void *buffer) { /* not supported yet */ } + +void sai_thrift_parse_neighbor_entry(const sai_thrift_neighbor_entry_t &thrift_neighbor_entry, + sai_neighbor_entry_t *neighbor_entry) +{ + if (neighbor_entry == NULL) { + return; + } + + // OCP sai_test often omits switch_id on neighbor_entry; fall back to the + // RPC-global switch_id set by sai_thrift_create_switch. + if (thrift_neighbor_entry.switch_id != 0) { + neighbor_entry->switch_id = (sai_object_id_t)thrift_neighbor_entry.switch_id; + } else if (switch_id != SAI_NULL_OBJECT_ID) { + neighbor_entry->switch_id = switch_id; + } else { + neighbor_entry->switch_id = SAI_NULL_OBJECT_ID; + } + + neighbor_entry->rif_id = (sai_object_id_t)thrift_neighbor_entry.rif_id; + sai_thrift_ip_address_t_parse(thrift_neighbor_entry.ip_address, + &neighbor_entry->ip_address); +} + +void sai_thrift_parse_route_entry(const sai_thrift_route_entry_t &thrift_route_entry, + sai_route_entry_t *route_entry) +{ + if (route_entry == NULL) { + return; + } + + if (thrift_route_entry.switch_id != 0) { + route_entry->switch_id = (sai_object_id_t)thrift_route_entry.switch_id; + } else if (switch_id != SAI_NULL_OBJECT_ID) { + route_entry->switch_id = switch_id; + } else { + route_entry->switch_id = SAI_NULL_OBJECT_ID; + } + + route_entry->vr_id = (sai_object_id_t)thrift_route_entry.vr_id; + sai_thrift_ip_prefix_t_parse(thrift_route_entry.destination, + &route_entry->destination); +} [% END -%]