Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS = meta lib vslib python
SUBDIRS = meta lib vslib python pyext

if SYNCD
SUBDIRS += syncd saiplayer saidump saidiscovery saisdkdump saiasiccmp tests
Expand Down
12 changes: 12 additions & 0 deletions meta/sai_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,18 @@ void sai_deserialize_object_meta_key(
_In_ const std::string &s,
_Out_ sai_object_meta_key_t& meta_key);

void sai_deserialize_ip_address(
_In_ const std::string& s,
_Out_ sai_ip_address_t& ipaddr);

void sai_deserialize_ip_prefix(
_In_ const std::string &s,
_Out_ sai_ip_prefix_t &ip_prefix);

void sai_deserialize_mac(
_In_ const std::string& s,
_Out_ sai_mac_t& mac);

// deserialize notifications

void sai_deserialize_fdb_event_ntf(
Expand Down
27 changes: 27 additions & 0 deletions pyext/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

all: _pysairedis.so

INCLUDE=-I../SAI/inc -I../SAI/meta -I../SAI/experimental -I../lib/inc -I../

pysairedis_wrap.cpp: pysairedis.i pysairedis.h pysairedis.cpp *.h
swig -Wall -c++ -python -keyword -DSWIGWORDSIZE64 $(INCLUDE) -I. -o pysairedis_wrap.cpp pysairedis.i

top_srcdir=../

_pysairedis.so: pysairedis_wrap.cpp pysairedis.cpp
g++ -fPIC -c pysairedis_wrap.cpp pysairedis.cpp -std=c++11 $(INCLUDE) -I../../common -I/usr/include/python2.7 -shared -fPIC
g++ -shared \
-lhiredis -lswsscommon -lpthread \
-L$(top_srcdir)/lib/src/.libs -lsairedis \
-L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta \
-lzmq \
pysairedis.o pysairedis_wrap.o -o _pysairedis.so

check:
true

.PHONY: clean

clean:
rm -f pysairedis_wrap.cpp _pysairedis.so pysairedis.py *.o *.so .*swp .*swo *~ .*~ sairedis.rec *.pyc

57 changes: 57 additions & 0 deletions pyext/fdb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

// TODO auto generate

typedef struct _sai_fdb_api_t
{
sai_status_t create_fdb_entry(
_In_ const sai_fdb_entry_t *fdb_entry,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

sai_status_t remove_fdb_entry(
_In_ const sai_fdb_entry_t *fdb_entry);

sai_status_t set_fdb_entry_attribute(
_In_ const sai_fdb_entry_t *fdb_entry,
_In_ const sai_attribute_t *attr);

sai_status_t get_fdb_entry_attribute(
_In_ const sai_fdb_entry_t *fdb_entry,
_In_ uint32_t attr_count,
_Inout_ sai_attribute_t *attr_list);

sai_status_t flush_fdb_entries(
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

sai_status_t create_fdb_entries(
_In_ uint32_t object_count,
_In_ const sai_fdb_entry_t *fdb_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);

sai_status_t remove_fdb_entries(
_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);

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

sai_status_t get_fdb_entries_attribute(
_In_ uint32_t object_count,
_In_ const sai_fdb_entry_t *fdb_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_fdb_api_t;
10 changes: 10 additions & 0 deletions pyext/getapi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

// need to be extern C

sai_status_t sai_get_switch_api(sai_switch_api_t* out);
sai_status_t sai_get_lag_api(sai_lag_api_t* out);
sai_status_t sai_get_router_interface_api(sai_router_interface_api_t* out);
sai_status_t sai_get_next_hop_api(sai_next_hop_api_t* out);
sai_status_t sai_get_route_api(sai_route_api_t* out);
sai_status_t sai_get_vlan_api(sai_vlan_api_t* out);
sai_status_t sai_get_fdb_api(sai_fdb_api_t* out);
57 changes: 57 additions & 0 deletions pyext/lag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

// TODO auto generate

typedef struct _sai_lag_api_t
{
sai_status_t create_lag(
_Out_ sai_object_id_t *lag_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

sai_status_t remove_lag(
_In_ sai_object_id_t lag_id);

sai_status_t set_lag_attribute(
_In_ sai_object_id_t lag_id,
_In_ const sai_attribute_t *attr);

sai_status_t get_lag_attribute(
_In_ sai_object_id_t lag_id,
_In_ uint32_t attr_count,
_Inout_ sai_attribute_t *attr_list);

sai_status_t create_lag_member(
_Out_ sai_object_id_t *lag_member_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

sai_status_t remove_lag_member(
_In_ sai_object_id_t lag_member_id);

sai_status_t set_lag_member_attribute(
_In_ sai_object_id_t lag_member_id,
_In_ const sai_attribute_t *attr);

sai_status_t get_lag_member_attribute(
_In_ sai_object_id_t lag_member_id,
_In_ uint32_t attr_count,
_Inout_ sai_attribute_t *attr_list);

sai_status_t create_lag_members(
_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);

sai_status_t remove_lag_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_lag_api_t;
25 changes: 25 additions & 0 deletions pyext/nexthop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

// TODO auto generate

typedef struct _sai_next_hop_api_t
{
sai_status_t create_next_hop(
_Out_ sai_object_id_t *next_hop_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

sai_status_t remove_next_hop(
_In_ sai_object_id_t next_hop_id);

sai_status_t set_next_hop_attribute(
_In_ sai_object_id_t next_hop_id,
_In_ const sai_attribute_t *attr);

sai_status_t get_next_hop_attribute(
_In_ sai_object_id_t next_hop_id,
_In_ uint32_t attr_count,
_Inout_ sai_attribute_t *attr_list);

} sai_next_hop_api_t;

192 changes: 192 additions & 0 deletions pyext/pysairedis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#include "pysairedis.h"

#include <cstddef>

#include "lib/inc/sairedis.h"
#include "swss/logger.h"

#include "meta/sai_serialize.h"

static std::map<std::string, std::string> g_profileMap;
static std::map<std::string, std::string>::iterator g_profileMapIterator = g_profileMap.begin();

static const char *profile_get_value (
_In_ sai_switch_profile_id_t profile_id,
_In_ const char *variable)
{
SWSS_LOG_ENTER();

auto it = g_profileMap.find(variable);

if (it == g_profileMap.end())
return NULL;
return it->second.c_str();
}

static int profile_get_next_value (
_In_ sai_switch_profile_id_t profile_id,
_Out_ const char **variable,
_Out_ const char **value)
{
SWSS_LOG_ENTER();

if (value == NULL)
{
// Restarts enumeration
g_profileMapIterator = g_profileMap.begin();
}
else if (g_profileMapIterator == g_profileMap.end())
{
return -1;
}
else
{
*variable = g_profileMapIterator->first.c_str();
*value = g_profileMapIterator->second.c_str();
g_profileMapIterator++;
}

if (g_profileMapIterator != g_profileMap.end())
return 0;

return -1;
}

static const sai_service_method_table_t g_smt = {
profile_get_value,
profile_get_next_value
};

sai_status_t sai_api_initialize(
_In_ uint64_t flags,
_In_ const std::map<std::string, std::string>& profileMap)
{
g_profileMap = profileMap;
g_profileMapIterator = g_profileMap.begin();

return sai_api_initialize(flags, &g_smt);
}

sai_status_t sai_get_switch_api(sai_switch_api_t* out)
{
sai_switch_api_t* api;

sai_status_t status = sai_api_query(SAI_API_SWITCH, (void**)&api);

if (status == SAI_STATUS_SUCCESS)
{
*out = *api;
}

return status;
}

sai_status_t sai_get_lag_api(sai_lag_api_t* out)
{
sai_lag_api_t* api;

sai_status_t status = sai_api_query(SAI_API_LAG, (void**)&api);

if (status == SAI_STATUS_SUCCESS)
{
*out = *api;
}

return status;
}

sai_status_t sai_get_router_interface_api(sai_router_interface_api_t* out)
{
sai_router_interface_api_t* api;

sai_status_t status = sai_api_query(SAI_API_ROUTER_INTERFACE, (void**)&api);

if (status == SAI_STATUS_SUCCESS)
{
*out = *api;
}

return status;
}

sai_status_t sai_get_next_hop_api(sai_next_hop_api_t* out)
{
sai_next_hop_api_t* api;

sai_status_t status = sai_api_query(SAI_API_NEXT_HOP, (void**)&api);

if (status == SAI_STATUS_SUCCESS)
{
*out = *api;
}

return status;
}

sai_status_t sai_get_route_api(sai_route_api_t* out)
{
sai_route_api_t* api;

sai_status_t status = sai_api_query(SAI_API_ROUTE, (void**)&api);

if (status == SAI_STATUS_SUCCESS)
{
*out = *api;
}

return status;
}

sai_status_t sai_get_vlan_api(sai_vlan_api_t* out)
{
sai_vlan_api_t* api;

sai_status_t status = sai_api_query(SAI_API_VLAN, (void**)&api);

if (status == SAI_STATUS_SUCCESS)
{
*out = *api;
}

return status;
}

sai_status_t sai_get_fdb_api(sai_fdb_api_t* out)
{
sai_fdb_api_t* api;

sai_status_t status = sai_api_query(SAI_API_FDB, (void**)&api);

if (status == SAI_STATUS_SUCCESS)
{
*out = *api;
}

return status;
}

sai_mac_t* sai_mac_t_from_string(const std::string& s)
{
sai_mac_t *mac = (sai_mac_t*)calloc(1, sizeof(sai_mac_t));

sai_deserialize_mac(s, *mac);

return mac;
}

sai_ip_address_t* sai_ip_address_t_from_string(const std::string& s)
{
sai_ip_address_t* ip = (sai_ip_address_t*)calloc(1, sizeof(sai_ip_address_t));

sai_deserialize_ip_address(s, *ip);
return ip;
}

sai_ip_prefix_t* sai_ip_prefix_t_from_string(const std::string& s)
{
sai_ip_prefix_t* ip = (sai_ip_prefix_t*)calloc(1, sizeof(sai_ip_prefix_t));

sai_deserialize_ip_prefix(s, *ip);

return ip;
}
Loading