Skip to content

Commit 911a8ff

Browse files
committed
fix: -5 error, switch-id-NULL on neighbor/route create test
Signed-off-by: Nicholas Ching <nicholaslching@gmail.com>
1 parent b9b4fb0 commit 911a8ff

3 files changed

Lines changed: 61 additions & 4 deletions

File tree

meta/templates/sai_rpc_server_helper_functions.tt

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
}
3232
[%- END -%]
3333
[%- FOREACH struct IN apis.$api.structs %]
34-
34+
[%- NEXT IF struct.short_name == 'neighbor_entry' %]
35+
[%- NEXT IF struct.short_name == 'route_entry' %]
3536

3637
[%- PROCESS struct_helper_function_header %] {
3738

@@ -135,8 +136,57 @@ void sai_thrift_parse_[% struct.short_name %](const [% struct.thrift_name %] &th
135136
[%- ######################################################################## -%]
136137

137138
[%- BLOCK special_helper_functions -%]
139+
extern sai_object_id_t gSwitchId;
140+
extern sai_object_id_t switch_id;
141+
138142
void sai_thrift_parse_buffer(const std::string &thrift_buffer,
139143
void *buffer) {
140144
/* not supported yet */
141145
}
146+
147+
void sai_thrift_parse_neighbor_entry(const sai_thrift_neighbor_entry_t &thrift_neighbor_entry,
148+
sai_neighbor_entry_t *neighbor_entry)
149+
{
150+
if (neighbor_entry == NULL) {
151+
return;
152+
}
153+
154+
// OCP sai_test often omits switch_id on neighbor_entry; fall back to the
155+
// RPC-global switch_id (set by sai_thrift_create_switch) then gSwitchId.
156+
if (thrift_neighbor_entry.switch_id != 0) {
157+
neighbor_entry->switch_id = (sai_object_id_t)thrift_neighbor_entry.switch_id;
158+
} else if (switch_id != SAI_NULL_OBJECT_ID) {
159+
neighbor_entry->switch_id = switch_id;
160+
} else if (gSwitchId != SAI_NULL_OBJECT_ID) {
161+
neighbor_entry->switch_id = gSwitchId;
162+
} else {
163+
neighbor_entry->switch_id = SAI_NULL_OBJECT_ID;
164+
}
165+
166+
neighbor_entry->rif_id = (sai_object_id_t)thrift_neighbor_entry.rif_id;
167+
sai_thrift_ip_address_t_parse(thrift_neighbor_entry.ip_address,
168+
&neighbor_entry->ip_address);
169+
}
170+
171+
void sai_thrift_parse_route_entry(const sai_thrift_route_entry_t &thrift_route_entry,
172+
sai_route_entry_t *route_entry)
173+
{
174+
if (route_entry == NULL) {
175+
return;
176+
}
177+
178+
if (thrift_route_entry.switch_id != 0) {
179+
route_entry->switch_id = (sai_object_id_t)thrift_route_entry.switch_id;
180+
} else if (switch_id != SAI_NULL_OBJECT_ID) {
181+
route_entry->switch_id = switch_id;
182+
} else if (gSwitchId != SAI_NULL_OBJECT_ID) {
183+
route_entry->switch_id = gSwitchId;
184+
} else {
185+
route_entry->switch_id = SAI_NULL_OBJECT_ID;
186+
}
187+
188+
route_entry->vr_id = (sai_object_id_t)thrift_route_entry.vr_id;
189+
sai_thrift_ip_prefix_t_parse(thrift_route_entry.destination,
190+
&route_entry->destination);
191+
}
142192
[% END -%]

test/saithrift/src/switch_sai.thrift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ struct sai_thrift_route_entry_t {
198198
}
199199

200200
struct sai_thrift_neighbor_entry_t {
201-
1: sai_thrift_object_id_t rif_id;
202-
2: sai_thrift_ip_address_t ip_address;
201+
1: sai_thrift_object_id_t switch_id;
202+
2: sai_thrift_object_id_t rif_id;
203+
3: sai_thrift_ip_address_t ip_address;
203204
}
204205

205206
struct sai_thrift_attribute_list_t {

test/saithrift/src/switch_sai_rpc_server.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,13 @@ class switch_sai_rpcHandler : virtual public switch_sai_rpcIf {
241241
}
242242

243243
void sai_thrift_parse_neighbor_entry(const sai_thrift_neighbor_entry_t &thrift_neighbor_entry, sai_neighbor_entry_t *neighbor_entry) {
244-
neighbor_entry->switch_id = gSwitchId;
244+
// Python saithrift sends switch_id as field 1 (optional). Always fall back to
245+
// gSwitchId when the client omits it (OCP sai_test often only passes rif_id).
246+
if (thrift_neighbor_entry.switch_id != 0) {
247+
neighbor_entry->switch_id = (sai_object_id_t) thrift_neighbor_entry.switch_id;
248+
} else {
249+
neighbor_entry->switch_id = gSwitchId;
250+
}
245251
neighbor_entry->rif_id = (sai_object_id_t) thrift_neighbor_entry.rif_id;
246252
sai_thrift_parse_ip_address(thrift_neighbor_entry.ip_address, &neighbor_entry->ip_address);
247253
}

0 commit comments

Comments
 (0)