@@ -6,6 +6,7 @@ extern "C" {
6
6
7
7
#include " swss/logger.h"
8
8
#include " sairedis.h"
9
+ #include " sai_redis.h"
9
10
#include " meta/saiserialize.h"
10
11
11
12
#include < map>
@@ -99,13 +100,97 @@ sai_object_id_t create_dummy_object_id(
99
100
return (((sai_object_id_t )objecttype) << 48 ) | ++index ;
100
101
}
101
102
103
+ void test_bulk_next_hop_group_member_create ()
104
+ {
105
+ SWSS_LOG_ENTER ();
106
+
107
+ swss::Logger::getInstance ().setMinPrio (swss::Logger::SWSS_NOTICE);
108
+
109
+ meta_init_db ();
110
+ redis_clear_switch_ids ();
111
+
112
+ swss::Logger::getInstance ().setMinPrio (swss::Logger::SWSS_DEBUG);
113
+
114
+ sai_status_t status;
115
+
116
+ sai_next_hop_group_api_t *sai_next_hop_group_api = NULL ;
117
+ sai_switch_api_t *sai_switch_api = NULL ;
118
+
119
+ sai_api_query (SAI_API_NEXT_HOP_GROUP, (void **)&sai_next_hop_group_api);
120
+ sai_api_query (SAI_API_SWITCH, (void **)&sai_switch_api);
121
+
122
+ uint32_t count = 3 ;
123
+
124
+ std::vector<sai_route_entry_t > routes;
125
+ std::vector<sai_attribute_t > attrs;
126
+
127
+ sai_attribute_t swattr;
128
+
129
+ swattr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
130
+ swattr.value .booldata = true ;
131
+
132
+ sai_object_id_t switch_id;
133
+ status = sai_switch_api->create_switch (&switch_id, 1 , &swattr);
134
+
135
+ ASSERT_SUCCESS (" Failed to create switch" );
136
+
137
+ std::vector<std::vector<sai_attribute_t >> nhgm_attrs;
138
+ std::vector<sai_attribute_t *> nhgm_attrs_array;
139
+ std::vector<uint32_t > nhgm_attrs_count;
140
+
141
+ // next hop group
142
+ sai_object_id_t hopgroup = create_dummy_object_id (SAI_OBJECT_TYPE_NEXT_HOP_GROUP);
143
+ object_reference_insert (hopgroup);
144
+ sai_object_meta_key_t meta_key_hopgruop = { .objecttype = SAI_OBJECT_TYPE_NEXT_HOP_GROUP, .objectkey = { .key = { .object_id = hopgroup } } };
145
+ std::string hopgroup_key = sai_serialize_object_meta_key (meta_key_hopgruop);
146
+ ObjectAttrHash[hopgroup_key] = { };
147
+
148
+ for (uint32_t i = 0 ; i < count; ++i)
149
+ {
150
+ // next hop
151
+ sai_object_id_t hop = create_dummy_object_id (SAI_OBJECT_TYPE_NEXT_HOP);
152
+ object_reference_insert (hop);
153
+ sai_object_meta_key_t meta_key_hop = { .objecttype = SAI_OBJECT_TYPE_NEXT_HOP, .objectkey = { .key = { .object_id = hop } } };
154
+ std::string hop_key = sai_serialize_object_meta_key (meta_key_hop);
155
+ ObjectAttrHash[hop_key] = { };
156
+
157
+ std::vector<sai_attribute_t > list (2 );
158
+ sai_attribute_t &attr1 = list[0 ];
159
+ sai_attribute_t &attr2 = list[1 ];
160
+
161
+ attr1.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID;
162
+ attr1.value .oid = hopgroup;
163
+ attr2.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID;
164
+ attr2.value .oid = hop;
165
+ nhgm_attrs.push_back (list);
166
+ nhgm_attrs_count.push_back (2 );
167
+ }
168
+
169
+ for (size_t j = 0 ; j < nhgm_attrs.size (); j++)
170
+ {
171
+ nhgm_attrs_array.push_back (nhgm_attrs[j].data ());
172
+ }
173
+
174
+ std::vector<sai_status_t > statuses (count);
175
+ std::vector<sai_object_id_t > object_id (count);
176
+ redis_bulk_object_create_next_hop_group_members (switch_id, count, nhgm_attrs_count.data (), nhgm_attrs_array.data ()
177
+ , SAI_BULK_OP_TYPE_INGORE_ERROR, object_id.data (), statuses.data ());
178
+ ASSERT_SUCCESS (" Failed to create nhgm" );
179
+ for (size_t j = 0 ; j < statuses.size (); j++)
180
+ {
181
+ status = statuses[j];
182
+ ASSERT_SUCCESS (" Failed to create nhgm # %zu" , j);
183
+ }
184
+ }
185
+
102
186
void test_bulk_route_set ()
103
187
{
104
188
SWSS_LOG_ENTER ();
105
189
106
190
swss::Logger::getInstance ().setMinPrio (swss::Logger::SWSS_NOTICE);
107
191
108
192
meta_init_db ();
193
+ redis_clear_switch_ids ();
109
194
110
195
swss::Logger::getInstance ().setMinPrio (swss::Logger::SWSS_DEBUG);
111
196
@@ -130,7 +215,6 @@ void test_bulk_route_set()
130
215
swattr.value .booldata = true ;
131
216
132
217
sai_object_id_t switch_id;
133
-
134
218
status = sai_switch_api->create_switch (&switch_id, 1 , &swattr);
135
219
136
220
ASSERT_SUCCESS (" Failed to create switch" );
@@ -183,9 +267,14 @@ void test_bulk_route_set()
183
267
}
184
268
185
269
std::vector<sai_status_t > statuses (count);
186
- sai_bulk_create_route_entry (count, routes.data (), route_attrs_count.data (), route_attrs_array.data ()
270
+ status = sai_bulk_create_route_entry (count, routes.data (), route_attrs_count.data (), route_attrs_array.data ()
187
271
, SAI_BULK_OP_TYPE_INGORE_ERROR, statuses.data ());
188
272
ASSERT_SUCCESS (" Failed to create route" );
273
+ for (size_t j = 0 ; j < statuses.size (); j++)
274
+ {
275
+ status = statuses[j];
276
+ ASSERT_SUCCESS (" Failed to create route # %zu" , j);
277
+ }
189
278
190
279
for (uint32_t i = index ; i < index + count; ++i)
191
280
{
@@ -242,6 +331,8 @@ int main()
242
331
243
332
test_enable_recording ();
244
333
334
+ test_bulk_next_hop_group_member_create ();
335
+
245
336
test_bulk_route_set ();
246
337
247
338
sai_api_uninitialize ();
0 commit comments