Skip to content

Commit c20887f

Browse files
kcudniklguohan
authored andcommitted
Add Virtual Switch skeleton (sonic-net#54)
1 parent 0fbe937 commit c20887f

35 files changed

+6098
-1
lines changed

configure.ac

+6-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ AM_COND_IF([SAITHRIFT], [
4545
CFLAGS_COMMON="-std=c++11 -Wall -fPIC -Wno-write-strings"
4646
AC_SUBST(CFLAGS_COMMON)
4747

48-
AC_OUTPUT(Makefile lib/Makefile lib/src/Makefile syncd/Makefile)
48+
AC_OUTPUT(Makefile
49+
lib/Makefile
50+
lib/src/Makefile
51+
vslib/Makefile
52+
vslib/src/Makefile
53+
syncd/Makefile)

vslib/Makefile.am

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SUBDIRS = src
2+
3+
ACLOCAL_AMFLAGS=-I m4

vslib/inc/sai_vs.h

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#ifndef __SAI_VS__
2+
#define __SAI_VS__
3+
4+
#include <mutex>
5+
#include <unordered_map>
6+
7+
#include "stdint.h"
8+
#include "stdio.h"
9+
10+
extern "C" {
11+
#include "sai.h"
12+
}
13+
#include "saiserialize.h"
14+
#include "saiattributelist.h"
15+
16+
#include "swss/logger.h"
17+
18+
extern service_method_table_t g_services;
19+
20+
extern uint64_t g_real_id;
21+
22+
typedef std::unordered_map<std::string, std::string> AttrHash;
23+
typedef std::unordered_map<std::string, AttrHash> ObjectHash;
24+
25+
// first key is serialized object ID (object id, vlan, route, neighbor, fdb)
26+
// value is hash containing attributes
27+
// second key is serialized attribute ID for given object
28+
// value is serialized attribute value
29+
extern ObjectHash g_objectHash;
30+
31+
extern std::recursive_mutex g_recursive_mutex;
32+
33+
extern const sai_acl_api_t vs_acl_api;
34+
extern const sai_buffer_api_t vs_buffer_api;
35+
extern const sai_fdb_api_t vs_fdb_api;
36+
extern const sai_hash_api_t vs_hash_api;
37+
extern const sai_hostif_api_t vs_host_interface_api;
38+
extern const sai_lag_api_t vs_lag_api;
39+
extern const sai_mirror_api_t vs_mirror_api;
40+
extern const sai_neighbor_api_t vs_neighbor_api;
41+
extern const sai_next_hop_api_t vs_next_hop_api;
42+
extern const sai_next_hop_group_api_t vs_next_hop_group_api;
43+
extern const sai_policer_api_t vs_policer_api;
44+
extern const sai_port_api_t vs_port_api;
45+
extern const sai_qos_map_api_t vs_qos_map_api;
46+
extern const sai_queue_api_t vs_queue_api;
47+
extern const sai_route_api_t vs_route_api;
48+
extern const sai_router_interface_api_t vs_router_interface_api;
49+
extern const sai_samplepacket_api_t vs_samplepacket_api;
50+
extern const sai_scheduler_api_t vs_scheduler_api;
51+
extern const sai_scheduler_group_api_t vs_scheduler_group_api;
52+
extern const sai_stp_api_t vs_stp_api;
53+
extern const sai_switch_api_t vs_switch_api;
54+
extern const sai_tunnel_api_t vs_tunnel_api;
55+
extern const sai_udf_api_t vs_udf_api;
56+
extern const sai_virtual_router_api_t vs_router_api;
57+
extern const sai_vlan_api_t vs_vlan_api;
58+
extern const sai_wred_api_t vs_wred_api;
59+
60+
extern sai_switch_notification_t vs_switch_notifications;
61+
62+
#define UNREFERENCED_PARAMETER(X)
63+
64+
void translate_rid_to_vid(
65+
_In_ sai_object_type_t object_type,
66+
_In_ uint32_t attr_count,
67+
_In_ sai_attribute_t *attr_list);
68+
69+
// separate methods are needed for vlan to not confuse with object_id
70+
71+
sai_status_t vs_generic_create(
72+
_In_ sai_object_type_t object_type,
73+
_Out_ sai_object_id_t* object_id,
74+
_In_ uint32_t attr_count,
75+
_In_ const sai_attribute_t *attr_list);
76+
77+
sai_status_t vs_generic_create(
78+
_In_ sai_object_type_t object_type,
79+
_In_ const sai_fdb_entry_t *fdb_entry,
80+
_In_ uint32_t attr_count,
81+
_In_ const sai_attribute_t *attr_list);
82+
83+
sai_status_t vs_generic_create(
84+
_In_ sai_object_type_t object_type,
85+
_In_ const sai_neighbor_entry_t* neighbor_entry,
86+
_In_ uint32_t attr_count,
87+
_In_ const sai_attribute_t *attr_list);
88+
89+
sai_status_t vs_generic_create(
90+
_In_ sai_object_type_t object_type,
91+
_In_ const sai_unicast_route_entry_t* unicast_route_entry,
92+
_In_ uint32_t attr_count,
93+
_In_ const sai_attribute_t *attr_list);
94+
95+
sai_status_t vs_generic_create_vlan(
96+
_In_ sai_object_type_t object_type,
97+
_In_ sai_vlan_id_t vlan_id);
98+
99+
100+
sai_status_t vs_generic_remove(
101+
_In_ sai_object_type_t object_type,
102+
_In_ sai_object_id_t object_id);
103+
104+
sai_status_t vs_generic_remove(
105+
_In_ sai_object_type_t object_type,
106+
_In_ const sai_fdb_entry_t* fdb_entry);
107+
108+
sai_status_t vs_generic_remove(
109+
_In_ sai_object_type_t object_type,
110+
_In_ const sai_neighbor_entry_t* neighbor_entry);
111+
112+
sai_status_t vs_generic_remove(
113+
_In_ sai_object_type_t object_type,
114+
_In_ const sai_unicast_route_entry_t* unicast_route_entry);
115+
116+
sai_status_t vs_generic_remove_vlan(
117+
_In_ sai_object_type_t object_type,
118+
_In_ sai_vlan_id_t vlan_id);
119+
120+
121+
sai_status_t vs_generic_set(
122+
_In_ sai_object_type_t object_type,
123+
_In_ sai_object_id_t object_id,
124+
_In_ const sai_attribute_t *attr);
125+
126+
sai_status_t vs_generic_set(
127+
_In_ sai_object_type_t object_type,
128+
_In_ const sai_fdb_entry_t *fdb_entry,
129+
_In_ const sai_attribute_t *attr);
130+
131+
sai_status_t vs_generic_set(
132+
_In_ sai_object_type_t object_type,
133+
_In_ const sai_neighbor_entry_t* neighbor_entry,
134+
_In_ const sai_attribute_t *attr);
135+
136+
sai_status_t vs_generic_set(
137+
_In_ sai_object_type_t object_type,
138+
_In_ const sai_unicast_route_entry_t* unicast_route_entry,
139+
_In_ const sai_attribute_t *attr);
140+
141+
sai_status_t vs_generic_set_vlan(
142+
_In_ sai_object_type_t object_type,
143+
_In_ sai_vlan_id_t vlan_id,
144+
_In_ const sai_attribute_t *attr);
145+
146+
147+
sai_status_t vs_generic_get(
148+
_In_ sai_object_type_t object_type,
149+
_In_ sai_object_id_t object_id,
150+
_In_ uint32_t attr_count,
151+
_Out_ sai_attribute_t *attr_list);
152+
153+
sai_status_t vs_generic_get(
154+
_In_ sai_object_type_t object_type,
155+
_In_ const sai_fdb_entry_t *fdb_entry,
156+
_In_ uint32_t attr_count,
157+
_Out_ sai_attribute_t *attr_list);
158+
159+
sai_status_t vs_generic_get(
160+
_In_ sai_object_type_t object_type,
161+
_In_ const sai_neighbor_entry_t* neighbor_entry,
162+
_In_ uint32_t attr_count,
163+
_Out_ sai_attribute_t *attr_list);
164+
165+
sai_status_t vs_generic_get(
166+
_In_ sai_object_type_t object_type,
167+
_In_ const sai_unicast_route_entry_t* unicast_route_entry,
168+
_In_ uint32_t attr_count,
169+
_Out_ sai_attribute_t *attr_list);
170+
171+
sai_status_t vs_generic_get_vlan(
172+
_In_ sai_object_type_t object_type,
173+
_In_ sai_vlan_id_t vlan_id,
174+
_In_ uint32_t attr_count,
175+
_Out_ sai_attribute_t *attr_list);
176+
177+
// notifications
178+
179+
void handle_notification(
180+
_In_ const std::string &notification,
181+
_In_ const std::string &data,
182+
_In_ const std::vector<swss::FieldValueTuple> &values);
183+
184+
#endif // __SAI_VS__

vslib/src/Makefile.am

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Makefile.am -- Process this file with automake to produce Makefile.in
2+
3+
AM_CPPFLAGS =
4+
AM_CPPFLAGS += -I/usr/include/sai -I/usr/include/swss -I$(top_srcdir)/common
5+
AM_CPPFLAGS += -I../inc
6+
7+
if DEBUG
8+
DBGFLAGS = -ggdb -D_DEBUG_
9+
else
10+
DBGFLAGS = -g
11+
endif
12+
13+
lib_LTLIBRARIES = libsaivs.la
14+
15+
libsaivs_la_SOURCES = sai_vs_acl.cpp \
16+
sai_vs_buffer.cpp \
17+
sai_vs_fdb.cpp \
18+
sai_vs_hash.cpp \
19+
sai_vs_hostintf.cpp \
20+
sai_vs_interfacequery.cpp \
21+
sai_vs_lag.cpp \
22+
sai_vs_mirror.cpp \
23+
sai_vs_neighbor.cpp \
24+
sai_vs_nexthop.cpp \
25+
sai_vs_nexthopgroup.cpp \
26+
sai_vs_policer.cpp \
27+
sai_vs_port.cpp \
28+
sai_vs_qosmaps.cpp \
29+
sai_vs_queue.cpp \
30+
sai_vs_route.cpp \
31+
sai_vs_router.cpp \
32+
sai_vs_routerintf.cpp \
33+
sai_vs_samplepacket.cpp \
34+
sai_vs_scheduler.cpp \
35+
sai_vs_schedulergroup.cpp \
36+
sai_vs_stp.cpp \
37+
sai_vs_switch.cpp \
38+
sai_vs_tunnel.cpp \
39+
sai_vs_udf.cpp \
40+
sai_vs_vlan.cpp \
41+
sai_vs_wred.cpp \
42+
sai_vs_generic_create.cpp \
43+
sai_vs_generic_remove.cpp \
44+
sai_vs_generic_set.cpp \
45+
sai_vs_generic_get.cpp \
46+
../../common/saiserialize.cpp \
47+
../../common/saiattributelist.cpp
48+
49+
50+
libsaivs_la_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON)
51+
52+
libsaivs_la_LIBADD = -lhiredis -lswsscommon

0 commit comments

Comments
 (0)