forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sairedis] Add support for client server architecture (sonic-net#838)
With this feature libsairedis will have ability to act as a client and server, for example as client (pbhorch) can connect to existing server (OA) and call SAI api in server scope. Client connects over zmq channel and can be running in separate docker, connecting over ipc pipe or tcp.
- Loading branch information
Showing
24 changed files
with
4,575 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,259 @@ | ||
#pragma once | ||
|
||
#include "SaiInterface.h" | ||
|
||
#include <memory> | ||
#include <mutex> | ||
|
||
#define SAIREDIS_CLIENTSERVERSAI_DECLARE_REMOVE_ENTRY(ot) \ | ||
virtual sai_status_t remove( \ | ||
_In_ const sai_ ## ot ## _t* ot) override; | ||
|
||
#define SAIREDIS_CLIENTSERVERSAI_DECLARE_CREATE_ENTRY(ot) \ | ||
virtual sai_status_t create( \ | ||
_In_ const sai_ ## ot ## _t* ot, \ | ||
_In_ uint32_t attr_count, \ | ||
_In_ const sai_attribute_t *attr_list) override; | ||
|
||
#define SAIREDIS_CLIENTSERVERSAI_DECLARE_SET_ENTRY(ot) \ | ||
virtual sai_status_t set( \ | ||
_In_ const sai_ ## ot ## _t* ot, \ | ||
_In_ const sai_attribute_t *attr) override; | ||
|
||
#define SAIREDIS_CLIENTSERVERSAI_DECLARE_GET_ENTRY(ot) \ | ||
virtual sai_status_t get( \ | ||
_In_ const sai_ ## ot ## _t* ot, \ | ||
_In_ uint32_t attr_count, \ | ||
_Out_ sai_attribute_t *attr_list) override; | ||
|
||
#define SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_CREATE_ENTRY(ot) \ | ||
virtual sai_status_t bulkCreate( \ | ||
_In_ uint32_t object_count, \ | ||
_In_ const sai_ ## ot ## _t *ot, \ | ||
_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) override; | ||
|
||
#define SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_REMOVE_ENTRY(ot) \ | ||
virtual sai_status_t bulkRemove( \ | ||
_In_ uint32_t object_count, \ | ||
_In_ const sai_ ## ot ## _t *ot, \ | ||
_In_ sai_bulk_op_error_mode_t mode, \ | ||
_Out_ sai_status_t *object_statuses) override; | ||
|
||
#define SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_SET_ENTRY(ot) \ | ||
virtual sai_status_t bulkSet( \ | ||
_In_ uint32_t object_count, \ | ||
_In_ const sai_ ## ot ## _t *ot, \ | ||
_In_ const sai_attribute_t *attr_list, \ | ||
_In_ sai_bulk_op_error_mode_t mode, \ | ||
_Out_ sai_status_t *object_statuses) override; | ||
|
||
namespace sairedis | ||
{ | ||
class ClientServerSai: | ||
public sairedis::SaiInterface | ||
{ | ||
public: | ||
|
||
ClientServerSai(); | ||
|
||
virtual ~ClientServerSai(); | ||
|
||
public: | ||
|
||
sai_status_t initialize( | ||
_In_ uint64_t flags, | ||
_In_ const sai_service_method_table_t *service_method_table) override; | ||
|
||
sai_status_t uninitialize(void) override; | ||
|
||
public: // SAI interface overrides | ||
|
||
virtual sai_status_t create( | ||
_In_ sai_object_type_t objectType, | ||
_Out_ sai_object_id_t* objectId, | ||
_In_ sai_object_id_t switchId, | ||
_In_ uint32_t attr_count, | ||
_In_ const sai_attribute_t *attr_list) override; | ||
|
||
virtual sai_status_t remove( | ||
_In_ sai_object_type_t objectType, | ||
_In_ sai_object_id_t objectId) override; | ||
|
||
virtual sai_status_t set( | ||
_In_ sai_object_type_t objectType, | ||
_In_ sai_object_id_t objectId, | ||
_In_ const sai_attribute_t *attr) override; | ||
|
||
virtual sai_status_t get( | ||
_In_ sai_object_type_t objectType, | ||
_In_ sai_object_id_t objectId, | ||
_In_ uint32_t attr_count, | ||
_Inout_ sai_attribute_t *attr_list) override; | ||
|
||
public: // create ENTRY | ||
|
||
SAIREDIS_CLIENTSERVERSAI_DECLARE_CREATE_ENTRY(fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_CREATE_ENTRY(inseg_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_CREATE_ENTRY(ipmc_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_CREATE_ENTRY(l2mc_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_CREATE_ENTRY(mcast_fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_CREATE_ENTRY(neighbor_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_CREATE_ENTRY(route_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_CREATE_ENTRY(nat_entry); | ||
|
||
public: // remove ENTRY | ||
|
||
SAIREDIS_CLIENTSERVERSAI_DECLARE_REMOVE_ENTRY(fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_REMOVE_ENTRY(inseg_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_REMOVE_ENTRY(ipmc_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_REMOVE_ENTRY(l2mc_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_REMOVE_ENTRY(mcast_fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_REMOVE_ENTRY(neighbor_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_REMOVE_ENTRY(route_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_REMOVE_ENTRY(nat_entry); | ||
|
||
public: // set ENTRY | ||
|
||
SAIREDIS_CLIENTSERVERSAI_DECLARE_SET_ENTRY(fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_SET_ENTRY(inseg_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_SET_ENTRY(ipmc_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_SET_ENTRY(l2mc_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_SET_ENTRY(mcast_fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_SET_ENTRY(neighbor_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_SET_ENTRY(route_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_SET_ENTRY(nat_entry); | ||
|
||
public: // get ENTRY | ||
|
||
SAIREDIS_CLIENTSERVERSAI_DECLARE_GET_ENTRY(fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_GET_ENTRY(inseg_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_GET_ENTRY(ipmc_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_GET_ENTRY(l2mc_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_GET_ENTRY(mcast_fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_GET_ENTRY(neighbor_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_GET_ENTRY(route_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_GET_ENTRY(nat_entry); | ||
|
||
public: // bulk QUAD oid | ||
|
||
virtual sai_status_t bulkCreate( | ||
_In_ sai_object_type_t object_type, | ||
_In_ sai_object_id_t switch_id, | ||
_In_ uint32_t object_count, | ||
_In_ const uint32_t *attr_count, | ||
_In_ const sai_attribute_t **attr_list, | ||
_In_ sai_bulk_op_error_mode_t mode, | ||
_Out_ sai_object_id_t *object_id, | ||
_Out_ sai_status_t *object_statuses) override; | ||
|
||
virtual sai_status_t bulkRemove( | ||
_In_ sai_object_type_t object_type, | ||
_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) override; | ||
|
||
virtual sai_status_t bulkSet( | ||
_In_ sai_object_type_t object_type, | ||
_In_ uint32_t object_count, | ||
_In_ const sai_object_id_t *object_id, | ||
_In_ const sai_attribute_t *attr_list, | ||
_In_ sai_bulk_op_error_mode_t mode, | ||
_Out_ sai_status_t *object_statuses) override; | ||
|
||
public: // bulk create ENTRY | ||
|
||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_CREATE_ENTRY(fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_CREATE_ENTRY(inseg_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_CREATE_ENTRY(nat_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_CREATE_ENTRY(route_entry); | ||
|
||
public: // bulk remove ENTRY | ||
|
||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_REMOVE_ENTRY(fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_REMOVE_ENTRY(inseg_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_REMOVE_ENTRY(nat_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_REMOVE_ENTRY(route_entry); | ||
|
||
public: // bulk set ENTRY | ||
|
||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_SET_ENTRY(fdb_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_SET_ENTRY(inseg_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_SET_ENTRY(nat_entry); | ||
SAIREDIS_CLIENTSERVERSAI_DECLARE_BULK_SET_ENTRY(route_entry); | ||
|
||
public: // stats API | ||
|
||
virtual sai_status_t getStats( | ||
_In_ sai_object_type_t object_type, | ||
_In_ sai_object_id_t object_id, | ||
_In_ uint32_t number_of_counters, | ||
_In_ const sai_stat_id_t *counter_ids, | ||
_Out_ uint64_t *counters) override; | ||
|
||
virtual sai_status_t getStatsExt( | ||
_In_ sai_object_type_t object_type, | ||
_In_ sai_object_id_t object_id, | ||
_In_ uint32_t number_of_counters, | ||
_In_ const sai_stat_id_t *counter_ids, | ||
_In_ sai_stats_mode_t mode, | ||
_Out_ uint64_t *counters) override; | ||
|
||
virtual sai_status_t clearStats( | ||
_In_ sai_object_type_t object_type, | ||
_In_ sai_object_id_t object_id, | ||
_In_ uint32_t number_of_counters, | ||
_In_ const sai_stat_id_t *counter_ids) override; | ||
|
||
public: // non QUAD API | ||
|
||
virtual sai_status_t flushFdbEntries( | ||
_In_ sai_object_id_t switchId, | ||
_In_ uint32_t attrCount, | ||
_In_ const sai_attribute_t *attrList) override; | ||
|
||
public: // SAI API | ||
|
||
virtual sai_status_t objectTypeGetAvailability( | ||
_In_ sai_object_id_t switchId, | ||
_In_ sai_object_type_t objectType, | ||
_In_ uint32_t attrCount, | ||
_In_ const sai_attribute_t *attrList, | ||
_Out_ uint64_t *count) override; | ||
|
||
virtual sai_status_t queryAttributeCapability( | ||
_In_ sai_object_id_t switch_id, | ||
_In_ sai_object_type_t object_type, | ||
_In_ sai_attr_id_t attr_id, | ||
_Out_ sai_attr_capability_t *capability) override; | ||
|
||
virtual sai_status_t queryAattributeEnumValuesCapability( | ||
_In_ sai_object_id_t switch_id, | ||
_In_ sai_object_type_t object_type, | ||
_In_ sai_attr_id_t attr_id, | ||
_Inout_ sai_s32_list_t *enum_values_capability) override; | ||
|
||
virtual sai_object_type_t objectTypeQuery( | ||
_In_ sai_object_id_t objectId) override; | ||
|
||
virtual sai_object_id_t switchIdQuery( | ||
_In_ sai_object_id_t objectId) override; | ||
|
||
virtual sai_status_t logSet( | ||
_In_ sai_api_t api, | ||
_In_ sai_log_level_t log_level) override; | ||
|
||
private: | ||
|
||
bool m_apiInitialized; | ||
|
||
std::recursive_mutex m_apimutex; | ||
|
||
sai_service_method_table_t m_service_method_table; | ||
|
||
std::shared_ptr<SaiInterface> m_sai; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.