Skip to content

Commit

Permalink
Clean sairedis.h header (sonic-net#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Dec 5, 2019
1 parent 9851730 commit 3fbd0c5
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 206 deletions.
154 changes: 0 additions & 154 deletions lib/inc/sairedis.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ extern "C" {
#include "sai.h"
}

#define SYNCD_INIT_VIEW "INIT_VIEW"
#define SYNCD_APPLY_VIEW "APPLY_VIEW"
#define SYNCD_INSPECT_ASIC "SYNCD_INSPECT_ASIC"
#define ASIC_STATE_TABLE "ASIC_STATE"
#define TEMP_PREFIX "TEMP_"

// Messages for processing queries from libsairedis to syncd
const std::string attrEnumValuesCapabilityQuery("attr_enum_values_capability_query");
const std::string attrEnumValuesCapabilityResponse("attr_enum_values_capability_response");
const std::string objectTypeGetAvailabilityQuery("object_type_get_availability_query");
const std::string objectTypeGetAvailabilityResponse("object_type_get_availability_response");

typedef enum _sai_redis_notify_syncd_t
{
SAI_REDIS_NOTIFY_SYNCD_INIT_VIEW,
Expand Down Expand Up @@ -125,146 +113,4 @@ typedef enum _sai_redis_switch_attr_t

} sai_redis_switch_attr_t;

/*
* Those bulk APIs are provided as static functions since current SAI 0.9.4
* doesn't support bulk API. Also note that SDK don't support bulk route API
* yet, so those APIs are introduced here to reduce number of calls to redis,
* in syncd bulk API will be splitted to separate call's until proper SDK
* support will be added.
*
* Currently bulk operation type is skipped, and all operation must end with
* success.
*/

#ifndef SAI_STATUS_NOT_EXECUTED
#define SAI_STATUS_NOT_EXECUTED SAI_STATUS_CODE(0x00000017L)
#endif

#ifndef SAI_COMMON_API_BULK_SET
#define SAI_COMMON_API_BULK_CREATE 4
#define SAI_COMMON_API_BULK_REMOVE 5
#define SAI_COMMON_API_BULK_SET 6
#define SAI_COMMON_API_BULK_GET 7
#endif

/**
* @brief Bulk create route entry
*
* @param[in] object_count Number of objects to create
* @param[in] route_entry List of object to create
* @param[in] attr_count List of attr_count. Caller passes the number
* of attribute for each object to create.
* @param[in] attr_list List of attributes for every object.
* @param[in] mode Bulk operation error handling mode
* @param[out] object_statuses List of status for every object. Caller needs to
* allocate the buffer
*
* @return #SAI_STATUS_SUCCESS on success when all objects are created or
* #SAI_STATUS_FAILURE when any of the objects fails to create. When there is
* failure, Caller is expected to go through the list of returned statuses to
* find out which fails and which succeeds.
*/
sai_status_t sai_bulk_create_route_entry(
_In_ uint32_t object_count,
_In_ const sai_route_entry_t *route_entry,
_In_ const uint32_t *attr_count,
_In_ const sai_attribute_t **attr_list,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);

/**
* @brief Bulk remove route entry
*
* @param[in] object_count Number of objects to remove
* @param[in] route_entry List of objects to remove
* @param[in] mode Bulk operation error handling mode
* @param[out] object_statuses List of status for every object. Caller needs to
* allocate the buffer
*
* @return #SAI_STATUS_SUCCESS on success when all objects are removed or
* #SAI_STATUS_FAILURE when any of the objects fails to remove. When there is
* failure, Caller is expected to go through the list of returned statuses to
* find out which fails and which succeeds.
*/
sai_status_t sai_bulk_remove_route_entry(
_In_ uint32_t object_count,
_In_ const sai_route_entry_t *route_entry,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);

/**
* @brief Bulk set attribute on route entry
*
* @param[in] object_count Number of objects to set attribute
* @param[in] route_entry List of objects to set attribute
* @param[in] attr_list List of attributes to set on objects, one attribute per object
* @param[in] mode Bulk operation error handling mode
* @param[out] object_statuses List of status for every object. Caller needs to
* allocate the buffer
*
* @return #SAI_STATUS_SUCCESS on success when all objects are removed or
* #SAI_STATUS_FAILURE when any of the objects fails to remove. When there is
* failure, Caller is expected to go through the list of returned statuses to
* find out which fails and which succeeds.
*/
sai_status_t sai_bulk_set_route_entry_attribute(
_In_ uint32_t object_count,
_In_ const sai_route_entry_t *route_entry,
_In_ const sai_attribute_t *attr_list,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);

/**
* @brief Bulk get attribute on route entry
*
* @param[in] object_count Number of objects to set attribute
* @param[in] route_entry List of objects to set attribute
* @param[in] attr_count List of attr_count. Caller passes the number
* of attribute for each object to get
* @param[inout] attr_list List of attributes to set on objects, one attribute per object
* @param[in] mode Bulk operation error handling mode
* @param[out] object_statuses List of status for every object. Caller needs to
* allocate the buffer
*
* @return #SAI_STATUS_SUCCESS on success when all objects are removed or
* #SAI_STATUS_FAILURE when any of the objects fails to remove. When there is
* failure, Caller is expected to go through the list of returned statuses to
* find out which fails and which succeeds.
*/
sai_status_t sai_bulk_get_route_entry_attribute(
_In_ uint32_t object_count,
_In_ const sai_route_entry_t *route_entry,
_In_ const uint32_t *attr_count,
_Inout_ sai_attribute_t **attr_list,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);

sai_status_t sai_bulk_create_next_hop_group_members(
_In_ sai_object_id_t switch_id,
_In_ uint32_t object_count,
_In_ const uint32_t *attr_count,
_In_ const sai_attribute_t **attrs,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_object_id_t *object_id,
_Out_ sai_status_t *object_statuses);

sai_status_t sai_bulk_remove_next_hop_group_members(
_In_ uint32_t object_count,
_In_ const sai_object_id_t *object_id,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);

sai_status_t sai_bulk_create_fdb_entry(
_In_ uint32_t object_count,
_In_ const sai_fdb_entry_t *fdb_entry,
_In_ const uint32_t *attr_count,
_In_ const sai_attribute_t *const *attr_list,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);

sai_status_t sai_bulk_remove_fdb_entry(
_In_ uint32_t object_count,
_In_ const sai_fdb_entry_t *fdb_entry,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);
#endif // __SAIREDIS__
18 changes: 18 additions & 0 deletions lib/inc/sairediscommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef __SAIREDISCOMMON__
#define __SAIREDISCOMMON__

// TODO those defines are shared via syncd and sairedis

#define SYNCD_INIT_VIEW "INIT_VIEW"
#define SYNCD_APPLY_VIEW "APPLY_VIEW"
#define SYNCD_INSPECT_ASIC "SYNCD_INSPECT_ASIC"
#define ASIC_STATE_TABLE "ASIC_STATE"
#define TEMP_PREFIX "TEMP_"

// Messages for processing queries from libsairedis to syncd
#define STRING_ATTR_ENUM_VALUES_CAPABILITY_QUERY "attr_enum_values_capability_query"
#define STRING_ATTR_ENUM_VALUES_CAPABILITY_RESPONSE "attr_enum_values_capability_response"
#define STRING_OBJECT_TYPE_GET_AVAILABILITY_QUERY "object_type_get_availability_query"
#define STRING_OBJECT_TYPE_GET_AVAILABILITY_RESPONSE "object_type_get_availability_response"

#endif // __SAIREDISCOMMON__
4 changes: 2 additions & 2 deletions lib/src/sai_redis_fdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ sai_status_t redis_dummy_create_fdb_entry(
return SAI_STATUS_SUCCESS;
}

sai_status_t sai_bulk_create_fdb_entry(
sai_status_t redis_bulk_create_fdb_entry(
_In_ uint32_t object_count,
_In_ const sai_fdb_entry_t *fdb_entry,
_In_ const uint32_t *attr_count,
Expand Down Expand Up @@ -251,7 +251,7 @@ sai_status_t sai_bulk_create_fdb_entry(
object_statuses);
}

sai_status_t sai_bulk_remove_fdb_entry(
sai_status_t redis_bulk_remove_fdb_entry(
_In_ uint32_t object_count,
_In_ const sai_fdb_entry_t *fdb_entry,
_In_ sai_bulk_op_error_mode_t mode,
Expand Down
9 changes: 5 additions & 4 deletions lib/src/sai_redis_interfacequery.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "sai_redis.h"
#include "sairedis.h"
#include "sairediscommon.h"

#include "meta/sai_serialize.h"
#include "meta/saiattributelist.h"
Expand Down Expand Up @@ -308,7 +309,7 @@ sai_status_t sai_query_attribute_enum_values_capability(

// This query will not put any data into the ASIC view, just into the
// message queue
g_asicState->set(switch_id_str, query_arguments, attrEnumValuesCapabilityQuery);
g_asicState->set(switch_id_str, query_arguments, STRING_ATTR_ENUM_VALUES_CAPABILITY_QUERY);

swss::Select callback;
callback.addSelectable(g_redisGetConsumer.get());
Expand All @@ -333,7 +334,7 @@ sai_status_t sai_query_attribute_enum_values_capability(
SWSS_LOG_DEBUG("Received response: op = %s, key = %s", message_type.c_str(), status_str.c_str());

// Ignore messages that are not in response to our query
if (message_type != attrEnumValuesCapabilityResponse)
if (message_type != STRING_ATTR_ENUM_VALUES_CAPABILITY_RESPONSE)
{
continue;
}
Expand Down Expand Up @@ -449,7 +450,7 @@ sai_status_t sai_object_type_get_availability(

// This query will not put any data into the ASIC view, just into the
// message queue
g_asicState->set(switch_id_str, query_arguments, objectTypeGetAvailabilityQuery);
g_asicState->set(switch_id_str, query_arguments, STRING_OBJECT_TYPE_GET_AVAILABILITY_QUERY);

swss::Select callback;
callback.addSelectable(g_redisGetConsumer.get());
Expand All @@ -474,7 +475,7 @@ sai_status_t sai_object_type_get_availability(
SWSS_LOG_DEBUG("Received response: op = %s, key = %s", message_type.c_str(), status_str.c_str());

// Ignore messages that are not in response to our query
if (message_type != objectTypeGetAvailabilityResponse)
if (message_type != STRING_OBJECT_TYPE_GET_AVAILABILITY_RESPONSE)
{
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/sai_redis_nexthopgroup.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "sai_redis.h"

sai_status_t sai_bulk_create_next_hop_group_members(
sai_status_t redis_bulk_create_next_hop_group_members(
_In_ sai_object_id_t switch_id,
_In_ uint32_t object_count,
_In_ const uint32_t *attr_count,
Expand All @@ -23,7 +23,7 @@ sai_status_t sai_bulk_create_next_hop_group_members(
object_statuses);
}

sai_status_t sai_bulk_remove_next_hop_group_members(
sai_status_t redis_bulk_remove_next_hop_group_members(
_In_ uint32_t object_count,
_In_ const sai_object_id_t *object_id,
_In_ sai_bulk_op_error_mode_t mode,
Expand All @@ -48,6 +48,6 @@ const sai_next_hop_group_api_t redis_next_hop_group_api = {
REDIS_GENERIC_QUAD_API(next_hop_group)
REDIS_GENERIC_QUAD_API(next_hop_group_member)

sai_bulk_create_next_hop_group_members,
sai_bulk_remove_next_hop_group_members,
redis_bulk_create_next_hop_group_members,
redis_bulk_remove_next_hop_group_members,
};
16 changes: 8 additions & 8 deletions lib/src/sai_redis_route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sai_status_t redis_dummy_create_route_entry(
return SAI_STATUS_SUCCESS;
}

sai_status_t sai_bulk_create_route_entry(
sai_status_t redis_bulk_create_route_entry(
_In_ uint32_t object_count,
_In_ const sai_route_entry_t *route_entry,
_In_ const uint32_t *attr_count,
Expand Down Expand Up @@ -149,7 +149,7 @@ sai_status_t redis_dummy_remove_route_entry(
return SAI_STATUS_SUCCESS;
}

sai_status_t sai_bulk_remove_route_entry(
sai_status_t redis_bulk_remove_route_entry(
_In_ uint32_t object_count,
_In_ const sai_route_entry_t *route_entry,
_In_ sai_bulk_op_error_mode_t mode,
Expand Down Expand Up @@ -252,7 +252,7 @@ sai_status_t redis_dummy_set_route_entry(
return SAI_STATUS_SUCCESS;
}

sai_status_t sai_bulk_set_route_entry_attribute(
sai_status_t redis_bulk_set_route_entry_attribute(
_In_ uint32_t object_count,
_In_ const sai_route_entry_t *route_entry,
_In_ const sai_attribute_t *attr_list,
Expand Down Expand Up @@ -355,7 +355,7 @@ sai_status_t sai_bulk_set_route_entry_attribute(
object_statuses);
}

sai_status_t sai_bulk_get_route_entry_attribute(
sai_status_t redis_bulk_get_route_entry_attribute(
_In_ uint32_t object_count,
_In_ const sai_route_entry_t *route_entry,
_In_ const uint32_t *attr_count,
Expand All @@ -376,8 +376,8 @@ const sai_route_api_t redis_route_api = {

REDIS_GENERIC_QUAD_API(route_entry)

sai_bulk_create_route_entry,
sai_bulk_remove_route_entry,
sai_bulk_set_route_entry_attribute,
sai_bulk_get_route_entry_attribute,
redis_bulk_create_route_entry,
redis_bulk_remove_route_entry,
redis_bulk_set_route_entry_attribute,
redis_bulk_get_route_entry_attribute,
};
1 change: 1 addition & 0 deletions lib/src/sai_redis_switch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "sai_redis.h"
#include "sairedis.h"
#include "sairediscommon.h"

#include "meta/sai_serialize.h"

Expand Down
2 changes: 1 addition & 1 deletion saidump/saidump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C" {

#include "swss/table.h"
#include "meta/sai_serialize.h"
#include "sairedis.h"
#include "sairediscommon.h"

#include <getopt.h>

Expand Down
Loading

0 comments on commit 3fbd0c5

Please sign in to comment.