Skip to content

Commit fffbfa1

Browse files
author
Myron Sosyak
committed
Add Thrift 0.14.1 compatibility
1 parent 4cc02bd commit fffbfa1

File tree

4 files changed

+52
-34
lines changed

4 files changed

+52
-34
lines changed

test/saithrift/Makefile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ CXX = $(CROSS_COMPILE)g++
33
SAI_PREFIX = /usr
44
SAI_HEADER_DIR ?= $(SAI_PREFIX)/include/sai
55
SAI_HEADERS = $(SAI_HEADER_DIR)/sai*.h
6-
CFLAGS = -I$(SAI_HEADER_DIR) -I. -std=c++11 -DFORCE_BOOST_SMART_PTR
6+
CFLAGS = -I$(SAI_HEADER_DIR) -I. -std=c++11
77
ifeq ($(DEBUG),1)
88
CFLAGS += -O0 -ggdb
99
endif
1010

11+
# Detect THRIFT_VERSION
12+
THRIFT_VERSION = $(shell thrift -version | cut -d ' ' -f3)
13+
ifeq ($(shell dpkg --compare-versions $(THRIFT_VERSION) "le" 0.11.0 && echo True), True)
14+
CFLAGS += -DFORCE_BOOST_SMART_PTR
15+
endif
16+
1117
ifeq ($(platform),MLNX)
1218
CDEFS = -DMLNXSAI
1319
else
@@ -21,8 +27,8 @@ CDEFS = -DBRCMSAI
2127
endif
2228
endif
2329
endif
24-
DEPS = switch_sai_constants.h switch_sai_rpc.h switch_sai_types.h
25-
OBJS = switch_sai_constants.o switch_sai_rpc.o switch_sai_types.o
30+
DEPS = switch_sai_rpc.h switch_sai_types.h
31+
OBJS = switch_sai_rpc.o switch_sai_types.o
2632

2733
ODIR = ./src/obj
2834
SAIDIR = ./include
@@ -42,8 +48,6 @@ endif
4248
SAI_LIBRARY_DIR ?= $(SAI_PREFIX)/lib
4349
LDFLAGS = -L$(SAI_LIBRARY_DIR) -Wl,-rpath=$(SAI_LIBRARY_DIR)
4450
CPP_SOURCES = \
45-
src/gen-cpp/switch_sai_constants.cpp \
46-
src/gen-cpp/switch_sai_constants.h \
4751
src/gen-cpp/switch_sai_rpc.cpp \
4852
src/gen-cpp/switch_sai_rpc.h \
4953
src/gen-cpp/switch_sai_types.cpp \
@@ -63,6 +67,15 @@ SAI_PY_HEADERS = \
6367
MKDIR_P = mkdir -p
6468
INSTALL := /usr/bin/install
6569

70+
ifeq ($(shell dpkg --compare-versions $(THRIFT_VERSION) "lt" 0.14.1 && echo True), True)
71+
DEPS += switch_sai_constants.h
72+
OBJS += switch_sai_constants.o
73+
CPP_SOURCES += src/gen-cpp/switch_sai_constants.cpp \
74+
src/gen-cpp/switch_sai_constants.h
75+
76+
CONSTANS_OBJ = $(ODIR)/switch_sai_constants.o
77+
endif
78+
6679
all: directories $(ODIR)/librpcserver.a saiserver clientlib
6780

6881
directories:
@@ -89,8 +102,8 @@ $(ODIR)/switch_sai_rpc_server.o: src/switch_sai_rpc_server.cpp
89102
$(ODIR)/saiserver.o: src/saiserver.cpp
90103
$(CXX) $(CFLAGS) -c $^ -o $@ $(CFLAGS) $(CDEFS) -I$(SRC)/gen-cpp -I$(SRC)
91104

92-
$(ODIR)/librpcserver.a: $(ODIR)/switch_sai_rpc.o $(ODIR)/switch_sai_types.o $(ODIR)/switch_sai_constants.o $(ODIR)/switch_sai_rpc_server.o
93-
ar rcs $(ODIR)/librpcserver.a $(ODIR)/switch_sai_rpc.o $(ODIR)/switch_sai_types.o $(ODIR)/switch_sai_constants.o $(ODIR)/switch_sai_rpc_server.o
105+
$(ODIR)/librpcserver.a: $(ODIR)/switch_sai_rpc.o $(ODIR)/switch_sai_types.o $(ODIR)/switch_sai_rpc_server.o $(CONSTANS_OBJ)
106+
ar rcs $(ODIR)/librpcserver.a $(ODIR)/switch_sai_rpc.o $(ODIR)/switch_sai_types.o $(ODIR)/switch_sai_rpc_server.o $(CONSTANS_OBJ)
94107

95108
saiserver: $(ODIR)/saiserver.o $(ODIR)/librpcserver.a
96109
$(CXX) $(LDFLAGS) $(ODIR)/switch_sai_rpc_server.o $(ODIR)/saiserver.o -o $@ \

test/saithrift/src/saiserver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <unistd.h>
66
#include <sys/queue.h>
77
#include <sys/types.h>
8+
#include <algorithm>
89
#include <fstream>
910
#include <sstream>
1011
#include <set>

test/saithrift/src/switch_sai.thrift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct sai_thrift_vlan_port_t {
4848
2: sai_thrift_vlan_tagging_mode_t tagging_mode;
4949
}
5050

51-
union sai_thrift_ip_t {
51+
struct sai_thrift_ip_t {
5252
1: sai_thrift_ip4_t ip4;
5353
2: sai_thrift_ip6_t ip6;
5454
}
@@ -79,7 +79,7 @@ struct sai_thrift_s32_list_t {
7979
2: list<i32> s32list;
8080
}
8181

82-
union sai_thrift_acl_mask_t {
82+
struct sai_thrift_acl_mask_t {
8383
1: byte u8;
8484
2: byte s8;
8585
3: i16 u16;
@@ -91,7 +91,7 @@ union sai_thrift_acl_mask_t {
9191
9: sai_thrift_ip6_t ip6;
9292
}
9393

94-
union sai_thrift_acl_data_t {
94+
struct sai_thrift_acl_data_t {
9595
1: byte u8;
9696
2: byte s8;
9797
3: i16 u16;
@@ -112,7 +112,7 @@ struct sai_thrift_acl_field_data_t
112112
3: sai_thrift_acl_data_t data;
113113
}
114114

115-
union sai_thrift_acl_parameter_t {
115+
struct sai_thrift_acl_parameter_t {
116116
1: byte u8;
117117
2: byte s8;
118118
3: i16 u16;
@@ -161,7 +161,7 @@ struct sai_thrift_fdb_values_t {
161161
2: sai_thrift_fdb_entry_t thrift_fdb_entry;
162162
}
163163

164-
union sai_thrift_attribute_value_t {
164+
struct sai_thrift_attribute_value_t {
165165
1: bool booldata;
166166
2: string chardata;
167167
3: byte u8;
@@ -207,7 +207,7 @@ struct sai_thrift_attribute_list_t {
207207
2: i32 attr_count; // redundant
208208
}
209209

210-
union sai_thrift_result_data_t {
210+
struct sai_thrift_result_data_t {
211211
1: sai_thrift_object_list_t objlist;
212212
2: sai_thrift_object_id_t oid;
213213
3: i16 u16;

test/saithrift/src/switch_sai_rpc_server.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ using namespace ::apache::thrift::protocol;
7474
using namespace ::apache::thrift::transport;
7575
using namespace ::apache::thrift::server;
7676

77+
#ifdef FORCE_BOOST_SMART_PTR
7778
using boost::shared_ptr;
79+
#else
80+
using std::shared_ptr;
81+
#endif
7882

7983
using namespace ::switch_sai;
8084

@@ -128,7 +132,7 @@ class switch_sai_rpcHandler : virtual public switch_sai_rpcIf {
128132
sprintf(macstr, "%02x:%02x:%02x:%02x:%02x:%02x", m[0], m[1], m[2], m[3], m[4], m[5]);
129133
return(macstr);
130134
}
131-
135+
132136
void sai_thrift_string_to_v4_ip(const std::string s, unsigned int *m) {
133137
unsigned char r=0;
134138
unsigned int i;
@@ -762,36 +766,36 @@ class switch_sai_rpcHandler : virtual public switch_sai_rpcIf {
762766
free(attr_list);
763767
return status;
764768
}
765-
//listing all the fdb entries from map
769+
//listing all the fdb entries from map
766770
void sai_thrift_get_fdb_entries (sai_thrift_attribute_list_t& thrift_attr_list){
767771
sai_mac_t mac_address;
768-
sai_object_id_t bv_id;
772+
sai_object_id_t bv_id;
769773
sai_object_id_t bport_id;
770-
sai_fdb_entry_t fdb_entry;
771-
774+
sai_fdb_entry_t fdb_entry;
775+
772776
thrift_attr_list.attr_count = gFdbMap.size();
773-
777+
774778
sai_fdb_entry_t fdb_m;
775779
sai_object_id_t b_id;
776-
780+
777781
for (auto it = gFdbMap.begin(); it != gFdbMap.end(); it++){
778782
fdb_m = it->first;
779-
b_id = it->second;
780-
781-
sai_thrift_fdb_values_t fdb_value;
783+
b_id = it->second;
784+
785+
sai_thrift_fdb_values_t fdb_value;
782786
fdb_value.bport_id=b_id;
783787
fdb_value.thrift_fdb_entry.bv_id=fdb_m.bv_id;
784788
fdb_value.thrift_fdb_entry.mac_address=mac_to_sai_thrift_string(fdb_m.mac_address);
785-
786-
sai_thrift_attribute_t thrift_fdb_attributes;
789+
790+
sai_thrift_attribute_t thrift_fdb_attributes;
787791
thrift_fdb_attributes.id = SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID;
788792
thrift_fdb_attributes.value.fdb_values = fdb_value;
789-
793+
790794
thrift_attr_list.attr_list.push_back(thrift_fdb_attributes);
791-
}
795+
}
792796
return;
793797
}
794-
798+
795799
void sai_thrift_parse_vlan_attributes(const std_sai_thrift_attr_vctr_t &thrift_attr_list, sai_attribute_t *attr_list) {
796800
SAI_THRIFT_LOG_DBG("Called.");
797801

@@ -1131,7 +1135,7 @@ class switch_sai_rpcHandler : virtual public switch_sai_rpcIf {
11311135
return status;
11321136
}
11331137

1134-
sai_thrift_status_t sai_thrift_create_route(const sai_thrift_route_entry_t &thrift_route_entry, const std::vector<sai_thrift_attribute_t> & thrift_attr_list)
1138+
sai_thrift_status_t sai_thrift_create_route(const sai_thrift_route_entry_t &thrift_route_entry, const std::vector<sai_thrift_attribute_t> & thrift_attr_list)
11351139
{
11361140
printf("sai_thrift_create_route\n");
11371141
sai_status_t status = SAI_STATUS_SUCCESS;
@@ -1626,15 +1630,15 @@ class switch_sai_rpcHandler : virtual public switch_sai_rpcIf {
16261630
case SAI_SWITCH_ATTR_FDB_AGING_TIME:
16271631
attr->value.u32 = thrift_attr.value.u32;
16281632
break;
1629-
1633+
16301634
case SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED:
1631-
attr->value.u32 = thrift_attr.value.u32;
1635+
attr->value.u32 = thrift_attr.value.u32;
16321636
break;
1633-
1637+
16341638
case SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED:
16351639
attr->value.u32 = thrift_attr.value.u32;
16361640
break;
1637-
1641+
16381642
default:
16391643
printf("unknown thrift_attr id: %d\n", thrift_attr.id);
16401644
}
@@ -3252,7 +3256,7 @@ class switch_sai_rpcHandler : virtual public switch_sai_rpcIf {
32523256
lane_list.push_back((uint32_t) lane_list_num->list[index]);
32533257
}
32543258
attr_list.push_back(thrift_port_hw_lane);
3255-
free(port_hw_lane.value.u32list.list);
3259+
free(port_hw_lane.value.u32list.list);
32563260

32573261
sai_attribute_t port_oper_status_attribute;
32583262
sai_thrift_attribute_t thrift_port_status;

0 commit comments

Comments
 (0)