diff --git a/lib/src/sai_redis_route.cpp b/lib/src/sai_redis_route.cpp index 982116e0dab6..4121742fc5a0 100644 --- a/lib/src/sai_redis_route.cpp +++ b/lib/src/sai_redis_route.cpp @@ -134,6 +134,21 @@ sai_status_t sai_bulk_create_route_entry( object_statuses); } +sai_status_t redis_dummy_remove_route_entry( + _In_ const sai_route_entry_t *route_entry) +{ + SWSS_LOG_ENTER(); + + /* + * Since we are using validation for each route in bulk operations, we + * can't execute actual REMOVE, we need to do dummy remove and then introduce + * internal bulk_remove operation that will only touch redis db only once. + * So we are returning success here. + */ + + return SAI_STATUS_SUCCESS; +} + sai_status_t sai_bulk_remove_route_entry( _In_ uint32_t object_count, _In_ const sai_route_entry_t *route_entry, @@ -144,6 +159,41 @@ sai_status_t sai_bulk_remove_route_entry( SWSS_LOG_ENTER(); + if (object_count < 1) + { + SWSS_LOG_ERROR("expected at least 1 object to create"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (route_entry == NULL) + { + SWSS_LOG_ERROR("route_entry is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + switch (mode) + { + case SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR: + case SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR: + // ok + break; + + default: + + SWSS_LOG_ERROR("invalid bulk operation mode %d", mode); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (object_statuses == NULL) + { + SWSS_LOG_ERROR("object_statuses is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + std::vector serialized_object_ids; for (uint32_t idx = 0; idx < object_count; ++idx) @@ -158,6 +208,31 @@ sai_status_t sai_bulk_remove_route_entry( sai_serialize_route_entry(route_entry[idx])); } + for (uint32_t idx = 0; idx < object_count; ++idx) + { + sai_status_t status = + meta_sai_remove_route_entry( + &route_entry[idx], + &redis_dummy_remove_route_entry); + + object_statuses[idx] = status; + + if (status != SAI_STATUS_SUCCESS) + { + // TODO add attr id and value + + SWSS_LOG_ERROR("failed on index %u: %s", + idx, + serialized_object_ids[idx].c_str()); + + if (mode == SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR) + { + SWSS_LOG_NOTICE("stop on error since previous operation failed"); + break; + } + } + } + return internal_redis_bulk_generic_remove(SAI_OBJECT_TYPE_ROUTE_ENTRY, serialized_object_ids, object_statuses); } diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index db5fcf0fbfa1..9038a7220941 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -2917,6 +2917,10 @@ sai_status_t processEvent( { return processBulkEvent((sai_common_api_t)SAI_COMMON_API_BULK_CREATE, kco); } + else if (op == "bulkremove") + { + return processBulkEvent((sai_common_api_t)SAI_COMMON_API_BULK_REMOVE, kco); + } else if (op == "notify") { return notifySyncd(key);