Skip to content

Commit

Permalink
[sairedis] Add support for client server architecture (sonic-net#838)
Browse files Browse the repository at this point in the history
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
kcudnik authored Jun 15, 2021
1 parent 0e2105a commit 9aed2ff
Show file tree
Hide file tree
Showing 24 changed files with 4,575 additions and 23 deletions.
394 changes: 394 additions & 0 deletions lib/inc/ClientSai.h

Large diffs are not rendered by default.

259 changes: 259 additions & 0 deletions lib/inc/ClientServerSai.h
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;
};
}
10 changes: 6 additions & 4 deletions lib/inc/RedisRemoteSaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,14 @@ namespace sairedis
sai_switch_notifications_t processNotification(
_In_ std::shared_ptr<Notification> notification);

std::string getHardwareInfo(
_In_ uint32_t attrCount,
_In_ const sai_attribute_t *attrList) const;

void refreshTableDump();

public:

static std::string getHardwareInfo(
_In_ uint32_t attrCount,
_In_ const sai_attribute_t *attrList);

private:

std::shared_ptr<ContextConfig> m_contextConfig;
Expand Down
1 change: 0 additions & 1 deletion lib/inc/Sai.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "RedisRemoteSaiInterface.h"
#include "Notification.h"
#include "Recorder.h"
#include "Context.h"
Expand Down
Loading

0 comments on commit 9aed2ff

Please sign in to comment.