Skip to content

Commit

Permalink
Fixed SAI thrift compilation. (#345)
Browse files Browse the repository at this point in the history
* Fixed compilation + refactored.

* Refactored according to the reviews.

* Fixed switch.py.

* Refactored according to the reviews.

* Fixed ACL, L2 and partially L3 group.
  • Loading branch information
Hnydyn Nazar authored and lguohan committed Jan 12, 2017
1 parent 8ffa66c commit ecc6e70
Show file tree
Hide file tree
Showing 7 changed files with 467 additions and 344 deletions.
89 changes: 53 additions & 36 deletions test/saithrift/src/saiserver.cpp
Expand Up @@ -13,6 +13,7 @@
#include <assert.h>
#include <signal.h>

#include <cstring>
#include <thread>

#include <sys/socket.h>
Expand All @@ -36,7 +37,10 @@ sai_switch_api_t* sai_switch_api;
std::map<std::string, std::string> gProfileMap;
std::map<std::set<int>, std::string> gPortMap;

void on_switch_state_change(_In_ sai_switch_oper_status_t switch_oper_status)
sai_object_id_t gSwitchId; ///< SAI switch global object ID.

void on_switch_state_change(_In_ sai_object_id_t switch_id,
_In_ sai_switch_oper_status_t switch_oper_status)//
{
}

Expand All @@ -50,31 +54,18 @@ void on_port_state_change(_In_ uint32_t count,
{
}

void on_port_event(_In_ uint32_t count,
_In_ sai_port_event_notification_t *data)
{
}

void on_shutdown_request()
void on_shutdown_request(_In_ sai_object_id_t switch_id)//
{
}

void on_packet_event(_In_ const void *buffer,
void on_packet_event(_In_ sai_object_id_t switch_id,
_In_ const void *buffer,
_In_ sai_size_t buffer_size,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list)
{
}

sai_switch_notification_t switch_notifications = {
on_switch_state_change,
on_fdb_event,
on_port_state_change,
on_port_event,
on_shutdown_request,
on_packet_event
};

// Profile services
/* Get variable value given its name */
const char* test_profile_get_value(
Expand Down Expand Up @@ -290,7 +281,10 @@ void handlePortMap(const std::string& portMapFile)

std::string fp_value = line.substr(0, pos);
std::string lanes = line.substr(pos + 1);
lanes.erase(lanes.begin(), std::find_if(lanes.begin(), lanes.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));

// ::isspace : C-Style white space predicate. Locale independent.
lanes.erase(std::remove_if(lanes.begin(), lanes.end(), ::isspace), lanes.end());

std::istringstream iss(lanes);
std::string lane_str;
std::set<int> lane_set;
Expand Down Expand Up @@ -327,7 +321,30 @@ main(int argc, char* argv[])
sai_api_initialize(0, (service_method_table_t *)&test_services);
sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api);

sai_status_t status = sai_switch_api->initialize_switch(0, (char *)"", (char *)"", &switch_notifications);
constexpr std::uint32_t attrSz = 6;

sai_attribute_t attr[attrSz];
std::memset(attr, '\0', sizeof(attr));

attr[0].id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr[0].value.booldata = true;

attr[1].id = SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY;
attr[1].value.ptr = reinterpret_cast<sai_pointer_t>(&on_switch_state_change);

attr[2].id = SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY;
attr[2].value.ptr = reinterpret_cast<sai_pointer_t>(&on_shutdown_request);

attr[3].id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY;
attr[3].value.ptr = reinterpret_cast<sai_pointer_t>(&on_fdb_event);

attr[4].id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
attr[4].value.ptr = reinterpret_cast<sai_pointer_t>(&on_port_state_change);

attr[5].id = SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY;
attr[5].value.ptr = reinterpret_cast<sai_pointer_t>(&on_packet_event);

sai_status_t status = sai_switch_api->create_switch(&gSwitchId, attrSz, attr);
if (status != SAI_STATUS_SUCCESS)
{
exit(EXIT_FAILURE);
Expand All @@ -342,23 +359,23 @@ main(int argc, char* argv[])

start_sai_thrift_rpc_server(SWITCH_SAI_THRIFT_RPC_SERVER_PORT);

sai_log_set(SAI_API_SWITCH, SAI_LOG_NOTICE);
sai_log_set(SAI_API_FDB, SAI_LOG_NOTICE);
sai_log_set(SAI_API_PORT, SAI_LOG_NOTICE);
sai_log_set(SAI_API_VLAN, SAI_LOG_NOTICE);
sai_log_set(SAI_API_ROUTE, SAI_LOG_NOTICE);
sai_log_set(SAI_API_VIRTUAL_ROUTER, SAI_LOG_NOTICE);
sai_log_set(SAI_API_ROUTER_INTERFACE, SAI_LOG_NOTICE);
sai_log_set(SAI_API_NEXT_HOP, SAI_LOG_NOTICE);
sai_log_set(SAI_API_NEXT_HOP_GROUP, SAI_LOG_NOTICE);
sai_log_set(SAI_API_NEIGHBOR, SAI_LOG_NOTICE);
sai_log_set(SAI_API_ACL, SAI_LOG_NOTICE);
sai_log_set(SAI_API_MIRROR, SAI_LOG_NOTICE);
sai_log_set(SAI_API_LAG, SAI_LOG_NOTICE);
sai_log_set(SAI_API_BUFFERS, SAI_LOG_NOTICE);
sai_log_set(SAI_API_POLICER, SAI_LOG_NOTICE);
sai_log_set(SAI_API_WRED, SAI_LOG_NOTICE);
sai_log_set(SAI_API_QOS_MAPS, SAI_LOG_NOTICE);
sai_log_set(SAI_API_SWITCH, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_FDB, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_PORT, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_VLAN, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_ROUTE, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_VIRTUAL_ROUTER, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_ROUTER_INTERFACE, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_NEXT_HOP, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_NEXT_HOP_GROUP, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_NEIGHBOR, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_ACL, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_MIRROR, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_LAG, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_BUFFERS, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_POLICER, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_WRED, SAI_LOG_LEVEL_NOTICE);
sai_log_set(SAI_API_QOS_MAPS, SAI_LOG_LEVEL_NOTICE);

while (1) pause();

Expand Down
25 changes: 17 additions & 8 deletions test/saithrift/src/switch_sai.thrift
Expand Up @@ -34,6 +34,15 @@ typedef i32 sai_thrift_port_stat_counter_t
typedef i32 sai_thrift_queue_stat_counter_t
typedef i32 sai_thrift_pg_stat_counter_t

struct sai_thrift_result_data_t {
1: sai_thrift_object_id_t oid;
}

struct sai_thrift_result_t {
1: sai_thrift_result_data_t data;
2: sai_thrift_status_t status;
}

struct sai_thrift_fdb_entry_t {
1: sai_thrift_mac_t mac_address;
2: sai_thrift_vlan_id_t vlan_id;
Expand Down Expand Up @@ -175,7 +184,7 @@ struct sai_thrift_attribute_t {
2: sai_thrift_attribute_value_t value;
}

struct sai_thrift_unicast_route_entry_t {
struct sai_thrift_route_entry_t {
1: sai_thrift_object_id_t vr_id;
2: sai_thrift_ip_prefix_t destination;
}
Expand Down Expand Up @@ -206,8 +215,8 @@ service switch_sai_rpc {
sai_thrift_status_t sai_thrift_flush_fdb_entries(1: list <sai_thrift_attribute_t> thrift_attr_list);

//vlan API
sai_thrift_status_t sai_thrift_create_vlan(1: sai_thrift_vlan_id_t vlan_id);
sai_thrift_status_t sai_thrift_delete_vlan(1: sai_thrift_vlan_id_t vlan_id);
sai_thrift_object_id_t sai_thrift_create_vlan(1: list<sai_thrift_attribute_t> thrift_attr_list);
sai_thrift_status_t sai_thrift_remove_vlan(1: sai_thrift_object_id_t vlan_oid);
list<i64> sai_thrift_get_vlan_stats(
1: sai_thrift_vlan_id_t vlan_id,
2: list<sai_thrift_vlan_stat_counter_t> counter_ids,
Expand All @@ -221,8 +230,8 @@ service switch_sai_rpc {
sai_thrift_status_t sai_thrift_remove_virtual_router(1: sai_thrift_object_id_t vr_id);

//route API
sai_thrift_status_t sai_thrift_create_route(1: sai_thrift_unicast_route_entry_t thrift_unicast_route_entry, 2: list<sai_thrift_attribute_t> thrift_attr_list);
sai_thrift_status_t sai_thrift_remove_route(1: sai_thrift_unicast_route_entry_t thrift_unicast_route_entry);
sai_thrift_status_t sai_thrift_create_route(1: sai_thrift_route_entry_t thrift_route_entry, 2: list<sai_thrift_attribute_t> thrift_attr_list);
sai_thrift_status_t sai_thrift_remove_route(1: sai_thrift_route_entry_t thrift_route_entry);

//router interface API
sai_thrift_object_id_t sai_thrift_create_router_interface(1: list<sai_thrift_attribute_t> thrift_attr_list);
Expand All @@ -235,8 +244,8 @@ service switch_sai_rpc {
//next hop group API
sai_thrift_object_id_t sai_thrift_create_next_hop_group(1: list<sai_thrift_attribute_t> thrift_attr_list);
sai_thrift_status_t sai_thrift_remove_next_hop_group(1: sai_thrift_object_id_t next_hop_group_id);
sai_thrift_status_t sai_thrift_add_next_hop_to_group(1: sai_thrift_object_id_t next_hop_group_id, 2: list<sai_thrift_object_id_t> thrift_nexthops);
sai_thrift_status_t sai_thrift_remove_next_hop_from_group(1: sai_thrift_object_id_t next_hop_group_id, 2: list<sai_thrift_object_id_t> thrift_nexthops);
sai_thrift_result_t sai_thrift_add_next_hop_to_group(1: list<sai_thrift_attribute_t> thrift_attr_list);
sai_thrift_status_t sai_thrift_remove_next_hop_from_group(1: sai_thrift_object_id_t next_hop_group_member_id);

//lag API
sai_thrift_object_id_t sai_thrift_create_lag(1: list<sai_thrift_attribute_t> thrift_attr_list);
Expand Down Expand Up @@ -270,7 +279,7 @@ service switch_sai_rpc {
sai_thrift_status_t sai_thrift_remove_hostif_trap_group(1: sai_thrift_object_id_t trap_group_id);
sai_thrift_status_t sai_thrift_create_hostif_trap(1: list<sai_thrift_attribute_t> thrift_attr_list);
sai_thrift_status_t sai_thrift_remove_hostif_trap(1: sai_thrift_hostif_trap_id_t trap_id);
sai_thrift_status_t sai_thrift_set_hostif_trap(1: sai_thrift_hostif_trap_id_t trap_id, 2: sai_thrift_attribute_t thrift_attr);
sai_thrift_status_t sai_thrift_set_hostif_trap(1: sai_thrift_object_id_t trap_id, 2: sai_thrift_attribute_t thrift_attr);
sai_thrift_status_t sai_thrift_set_hostif_trap_group(1: sai_thrift_object_id_t trap_group_id, 2: sai_thrift_attribute_t thrift_attr);

// ACL API
Expand Down

0 comments on commit ecc6e70

Please sign in to comment.