diff --git a/stub/Makefile.am b/stub/Makefile.am deleted file mode 100644 index 2957bad15..000000000 --- a/stub/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -# Makefile.am -- Process this file with automake to produce Makefile.in - -# note that order matters: make the lib first then use it - -SUBDIRS = src -DIST_SUBDIRS = src diff --git a/stub/README.md b/stub/README.md deleted file mode 100644 index 687fd429b..000000000 --- a/stub/README.md +++ /dev/null @@ -1,39 +0,0 @@ -Stub SAI implementation -============================ - -This folder contains SAI stub implementation. - -Compilation is done by : - 1. ./autogen.sh - 2. ./configure --enable-debug --prefix=/usr - 3. make - 4. make install - -The output result is SAI library, called libsai -User applications can then link with this library, in order to use the SAI stub implementation. - -The implementation contains most of the attributes, as where in master branch of github on May 26, except : - 1. few new attributes are missing for switch API - 2. only few attributes are implemented for host interface - 3. acl and qos are not implemented at all - -The output is written to syslog USER facility -Verbose output is written for every implemented attribute - -Most of the get attributes calls return default values -On create objects, an increasing static counter per object is used to return increasing object IDs. -Next hop group contains an almost full implementation in memory - -Extensive parameter checking is done. It includes : - 1. Checking the attribute is valid for the feature API - 2. Checking the operation is valid for the attribute (for example, doesn't allow set for RO attribute) - 3. Checking all mandatory attributes are passed to create - 4. Checking an attribute doesn't appear twice in attribute list - 5. Checking the value of attributes of type list is not NULL - 6. Additional specific checks per function - -All the stub sources are under Apache license - -Future enhancments : - 1. Use SAI schema for parameter checking (developed by MS) - 2. Have a storage layer to store the created object. Right now, the attributes of an object is not store. The GET/SET calls are either noop or return predefined values. diff --git a/stub/autoclean.sh b/stub/autoclean.sh deleted file mode 100755 index 46134a732..000000000 --- a/stub/autoclean.sh +++ /dev/null @@ -1,8 +0,0 @@ -rm -rf aclocal.m4 autom4te.cache stamp-h1 libtool configure config.* Makefile.in Makefile -rm -rf config/* - -for a in src -do - rm -rf $a/Makefile 2>&1 - rm -rf $a/Makefile.in 2>&1 -done diff --git a/stub/autogen.sh b/stub/autogen.sh deleted file mode 100755 index ea7b1fd6a..000000000 --- a/stub/autogen.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -# get two strings of version numbers -# parse the two strings and compare -function compare_versions() { - cat < /tmp/$$.awk -/[0-9]+\.[0-9]+(\.[0-9]+)?[ ]+[0-9]+\.[0-9]+(\.[0-9]+)?/{ - vb = "$2"; - nb = split(vb,b,"[.]"); - va = "$1"; - na = split(va,a,"[.]"); - for (i = na + 1; i < 4; i++) { - a[i] = 0; - } - for (i = nb + 1; i < 4; i++) { - b[i] = 0; - } - for (i = 1; i <= 3; i++) { - if (b[i] < a[i]) { -# print "FAIL:" va ">" vb " at index:" i; - exit(1); - } else if (b[i] > a[i]) { -# print "OK:" va "<" vb " at index:" i; - exit(0); - } - } -# print "OK:" va "==" vb; - exit(0); -} -{ - exit(1); -} -EOF - echo "$1 $2 " | awk -f /tmp/$$.awk - status=$? - rm /tmp/$$.awk - return $status -} - -cd ${0%*/*} - -# clean old autogen files -./autoclean.sh - -# make sure autoconf is up-to-date -ac_ver=`autoconf --version | head -n 1 | awk '{print $NF}'` -compare_versions 2.59 $ac_ver -if test $? = 1; then - echo Min autoconf version is 2.59 - exit 1 -fi - -# make sure automake is up-to-date -am_ver=`automake --version | head -n 1 | awk '{print $NF}'` -compare_versions 1.9.2 $am_ver -if test $? = 1; then - echo Min automake version is 1.9.2 - exit 1 -fi - -# make sure libtool is up-to-date -lt_ver=`libtoolize --version | head -n 1 | awk '{print $4}'` -compare_versions 2.4.2 $lt_ver -if test $? = 1; then - echo Min libtool version is 2.4.2 - exit 1 -fi - -# handle our own autoconf: -echo Visiting `pwd` -aclocal -I config 2>&1 | grep -v "Warning: underquoted definition of" -libtoolize --force --copy -autoheader -automake --add-missing --foreign --copy --force -autoconf diff --git a/stub/config/.gitignore b/stub/config/.gitignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/stub/configure.ac b/stub/configure.ac deleted file mode 100644 index ac61fd3b7..000000000 --- a/stub/configure.ac +++ /dev/null @@ -1,91 +0,0 @@ - -dnl Process this file with autoconf to produce a configure script. -AC_INIT([mlnx_sai], [3.0.0000]) -AC_CONFIG_SRCDIR([]) - -dnl use local config dir for extras -AC_CONFIG_AUX_DIR(config) - -dnl we use auto cheader -AM_CONFIG_HEADER(config.h) - -dnl Defines the Language - we need gcc linker ... -AC_LANG_C - -dnl Auto make -AM_INIT_AUTOMAKE - -dnl Provides control over re-making of all auto files -AM_MAINTAINER_MODE - -dnl Required for cases make defines a MAKE=make ??? Why -AC_PROG_MAKE_SET - -dnl Checks for programs. -AC_PROG_INSTALL -AC_PROG_LN_S -AC_PROG_CC - -dnl We will use libtool for making ... -AC_PROG_LIBTOOL - -dnl Checks for header files. -AC_HEADER_STDC -AC_CHECK_HEADERS([sys/types.h stdio.h stdlib.h string.h]) - -dnl Checks for typedefs, structures, and compiler characteristics. -AC_HEADER_STDBOOL -AC_C_CONST -AC_C_INLINE - -dnl Checks for library functions. -#AC_CHECK_FUNCS([strchr strstr strtol strtoull regcomp regexec]) - -dnl Define an input config option to control debug compile -AC_ARG_ENABLE(debug, -[ --enable-debug Turn on debugging], -[case "${enableval}" in - yes) debug=true ;; - no) debug=false ;; - *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;; -esac],[debug=false]) -AM_CONDITIONAL(DEBUG, test x$debug = xtrue) - -dnl Define an input config option to control complib path -AC_ARG_WITH(sxcomplib, -[ --with-sxcomplib= define SwitchX compatibility library directory], -AC_MSG_NOTICE(Using SwitchX compatibility library from:$with_sxcomplib), -with_sxcomplib="none") -SX_COMPLIB_PATH=/usr/local -if test "x$with_sxcomplib" != xnone; then - SX_COMPLIB_PATH=$with_sxcomplib -fi -AC_SUBST(SX_COMPLIB_PATH) - -dnl Define an input config option to control sxd lib path -AC_ARG_WITH(sxdlibs, -[ --with-sxdlibs= define SwitchX Driver libraries directory], -AC_MSG_NOTICE(Using SwitchX Driver libraries from:$with_sxdlibs), -with_sxdlibs="none") -SXD_LIBS_PATH=/usr/local -if test "x$with_sxdlibs" != xnone; then - SXD_LIBS_PATH=$with_sxdlibs -fi -AC_SUBST(SXD_LIBS_PATH) - -dnl Define an input config option to control applibs path -AC_ARG_WITH(applibs, -[ --with-applibs= define SwitchX Application libraries directory], -AC_MSG_NOTICE(Using SwitchX Application libraries from:$with_sxapplibs), -with_applibs="none") -APP_LIB_PATH=/usr/local -if test "x$with_applibs" != xnone; then - APP_LIB_PATH=$with_applibs -fi -AC_SUBST(APP_LIB_PATH) - -CFLAGS_SAI_INTERFACE_COMMON="-Wall -Wswitch -Wunused -Werror -fPIC -fno-strict-aliasing -Wextra -Wunused -Wno-unused-parameter" -AC_SUBST(CFLAGS_SAI_INTERFACE_COMMON) - -dnl Create the following Makefiles -AC_OUTPUT([Makefile src/Makefile]) diff --git a/stub/inc/stub_sai.h b/stub/inc/stub_sai.h deleted file mode 100644 index 0fe7acea2..000000000 --- a/stub/inc/stub_sai.h +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#if !defined (__STUBAI_H_) -#define __STUBSAI_H_ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern service_method_table_t g_services; -extern const sai_route_api_t route_api; -extern const sai_virtual_router_api_t router_api; -extern const sai_switch_api_t switch_api; -extern const sai_port_api_t port_api; -extern const sai_fdb_api_t fdb_api; -extern const sai_neighbor_api_t neighbor_api; -extern const sai_next_hop_api_t next_hop_api; -extern const sai_next_hop_group_api_t next_hop_group_api; -extern const sai_router_interface_api_t router_interface_api; -extern const sai_vlan_api_t vlan_api; -extern const sai_hostif_api_t host_interface_api; - -/* - * SAI operation type - * Values must start with 0 base and be without gaps - */ -typedef enum sai_operation_t { - SAI_OPERATION_CREATE, - SAI_OPERATION_REMOVE, - SAI_OPERATION_SET, - SAI_OPERATION_GET, - SAI_OPERATION_MAX -} sai_operation_t; - -/* - * Attribute value types - */ -typedef enum _sai_attribute_value_type_t { - SAI_ATTR_VAL_TYPE_UNDETERMINED, - SAI_ATTR_VAL_TYPE_BOOL, - SAI_ATTR_VAL_TYPE_CHARDATA, - SAI_ATTR_VAL_TYPE_U8, - SAI_ATTR_VAL_TYPE_S8, - SAI_ATTR_VAL_TYPE_U16, - SAI_ATTR_VAL_TYPE_S16, - SAI_ATTR_VAL_TYPE_U32, - SAI_ATTR_VAL_TYPE_S32, - SAI_ATTR_VAL_TYPE_U64, - SAI_ATTR_VAL_TYPE_S64, - SAI_ATTR_VAL_TYPE_MAC, - SAI_ATTR_VAL_TYPE_IPV4, - SAI_ATTR_VAL_TYPE_IPV6, - SAI_ATTR_VAL_TYPE_IPADDR, - SAI_ATTR_VAL_TYPE_OID, - SAI_ATTR_VAL_TYPE_OBJLIST, - SAI_ATTR_VAL_TYPE_U32LIST, - SAI_ATTR_VAL_TYPE_S32LIST, - SAI_ATTR_VAL_TYPE_VLANLIST, - SAI_ATTR_VAL_TYPE_ACLFIELD, - SAI_ATTR_VAL_TYPE_ACLACTION, - SAI_ATTR_VAL_TYPE_PORTBREAKOUT -} sai_attribute_value_type_t; -typedef struct _sai_attribute_entry_t { - sai_attr_id_t id; - bool mandatory_on_create; - bool valid_for_create; - bool valid_for_set; - bool valid_for_get; - const char *attrib_name; - sai_attribute_value_type_t type; -} sai_attribute_entry_t; -typedef struct _stub_object_id_t { - sai_uint8_t object_type; - sai_uint8_t reserved[3]; - sai_uint32_t data; -} stub_object_id_t; - -#define SAI_TYPE_CHECK_RANGE(type) (type < SAI_OBJECT_TYPE_MAX) - -#define SAI_TYPE_STR(type) SAI_TYPE_CHECK_RANGE(type) ? sai_type2str_arr[type] : "Unknown object type" - -static __attribute__((__used__)) const char *sai_type2str_arr[] = { - /* SAI_OBJECT_TYPE_NULL = 0 */ - "NULL type", - - /*SAI_OBJECT_TYPE_PORT = 1 */ - "Port type", - - /*SAI_OBJECT_TYPE_LAG = 2 */ - "LAG type", - - /*SAI_OBJECT_TYPE_VIRTUAL_ROUTER = 3 */ - "Virtual router type", - - /* SAI_OBJECT_TYPE_NEXT_HOP = 4 */ - "Next hop type", - - /* SAI_OBJECT_TYPE_NEXT_HOP_GROUP = 5 */ - "Next hop group type", - - /* SAI_OBJECT_TYPE_ROUTER_INTERFACE = 6 */ - "Router interface type", - - /* SAI_OBJECT_TYPE_ACL_TABLE = 7 */ - "ACL table type", - - /* SAI_OBJECT_TYPE_ACL_ENTRY = 8 */ - "ACL entry type", - - /* SAI_OBJECT_TYPE_ACL_COUNTER = 9 */ - "ACL counter type", - - /* SAI_OBJECT_TYPE_HOST_INTERFACE = 10 */ - "Host interface type", - - /* SAI_OBJECT_TYPE_MIRROR = 11 */ - "Mirror type", - - /* SAI_OBJECT_TYPE_SAMPLEPACKET = 12 */ - "Sample packet type", - - /* SAI_OBJECT_TYPE_STP_INSTANCE = 13 */ - "Stp instance type" - - /* SAI_OBJECT_TYPE_MAX = 14 */ -}; - -typedef union { - const sai_fdb_entry_t * fdb_entry; - const sai_neighbor_entry_t * neighbor_entry; - const sai_unicast_route_entry_t* unicast_route_entry; - const sai_vlan_id_t vlan_id; - const sai_object_id_t object_id; -} sai_object_key_t; -typedef sai_status_t (*sai_attribute_set_fn)(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, - void *arg); -typedef union { - int dummy; -} vendor_cache_t; -typedef sai_status_t (*sai_attribute_get_fn)(_In_ const sai_object_key_t *key, _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, _Inout_ vendor_cache_t *cache, void *arg); -typedef struct _sai_vendor_attribute_entry_t { - sai_attr_id_t id; - bool is_implemented[SAI_OPERATION_MAX]; - bool is_supported[SAI_OPERATION_MAX]; - sai_attribute_get_fn getter; - void *getter_arg; - sai_attribute_set_fn setter; - void *setter_arg; -} sai_vendor_attribute_entry_t; - -#define END_FUNCTIONALITY_ATTRIBS_ID 0xFFFFFFFF - -sai_status_t check_attribs_metadata(_In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list, - _In_ const sai_attribute_entry_t *functionality_attr, - _In_ const sai_vendor_attribute_entry_t *functionality_vendor_attr, - _In_ sai_operation_t oper); - -sai_status_t find_attrib_in_list(_In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list, - _In_ sai_attr_id_t attrib_id, - _Out_ const sai_attribute_value_t **attr_value, - _Out_ uint32_t *index); - -sai_status_t sai_set_attribute(_In_ const sai_object_key_t *key, - _In_ const char *key_str, - _In_ const sai_attribute_entry_t *functionality_attr, - _In_ const sai_vendor_attribute_entry_t *functionality_vendor_attr, - _In_ const sai_attribute_t *attr); - -sai_status_t sai_get_attributes(_In_ const sai_object_key_t *key, - _In_ const char *key_str, - _In_ const sai_attribute_entry_t *functionality_attr, - _In_ const sai_vendor_attribute_entry_t *functionality_vendor_attr, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list); - -#define MAX_KEY_STR_LEN 100 -#define MAX_VALUE_STR_LEN 100 -#define MAX_LIST_VALUE_STR_LEN 1000 - -#define PORT_NUMBER 32 - -sai_status_t sai_value_to_str(_In_ sai_attribute_value_t value, - _In_ sai_attribute_value_type_t type, - _In_ uint32_t max_length, - _Out_ char *value_str); -sai_status_t sai_attr_list_to_str(_In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list, - _In_ const sai_attribute_entry_t *functionality_attr, - _In_ uint32_t max_length, - _Out_ char *list_str); -sai_status_t sai_ipprefix_to_str(_In_ sai_ip_prefix_t value, _In_ uint32_t max_length, _Out_ char *value_str); -sai_status_t sai_ipaddr_to_str(_In_ sai_ip_address_t value, - _In_ uint32_t max_length, - _Out_ char *value_str, - _Out_ int *chars_written); -sai_status_t sai_nexthops_to_str(_In_ uint32_t next_hop_count, - _In_ const sai_object_id_t* nexthops, - _In_ uint32_t max_length, - _Out_ char *str); -sai_status_t stub_object_to_type(sai_object_id_t object_id, sai_object_type_t type, uint32_t *data); -sai_status_t stub_create_object(sai_object_type_t type, uint32_t data, sai_object_id_t *object_id); - -void db_init_next_hop_group(); -sai_status_t db_get_next_hop_group(_In_ uint32_t next_hop_group_id, _Out_ sai_object_list_t *next_hop_list); -void db_init_vlan(); - -sai_status_t stub_fill_objlist(sai_object_id_t *data, uint32_t count, sai_object_list_t *list); -sai_status_t stub_fill_u32list(uint32_t *data, uint32_t count, sai_u32_list_t *list); -sai_status_t stub_fill_s32list(int32_t *data, uint32_t count, sai_s32_list_t *list); -sai_status_t stub_fill_vlanlist(sai_vlan_id_t *data, uint32_t count, sai_vlan_list_t *list); - -void utils_log(const sai_log_level_t severity, const char *module_name, const char *p_str, ...); - -#define QUOTEME_(x) #x /* add "" to x */ -#define QUOTEME(x) QUOTEME_(x) - -#define STUB_ASSERT(exp) assert((exp)) - -#ifndef _WIN32 - -#define UNREFERENCED_PARAMETER(X) -#define UTILS_LOG(level, fmt, arg ...) \ - do { \ - utils_log(level, QUOTEME(__MODULE__), "%s[%d]- %s: " fmt, \ - __FILE__, __LINE__, __FUNCTION__, ## arg); \ - } while (0) - -#define STUB_LOG_ENTER() UTILS_LOG(SAI_LOG_DEBUG, "%s: [\n", __FUNCTION__) -#define STUB_LOG_EXIT() UTILS_LOG(SAI_LOG_DEBUG, "%s: ]\n", __FUNCTION__) -#define STUB_LOG_DBG(fmt, arg ...) UTILS_LOG(SAI_LOG_DEBUG, fmt, ## arg) -#define STUB_LOG_INF(fmt, arg ...) UTILS_LOG(SAI_LOG_INFO, fmt, ## arg) -#define STUB_LOG_WRN(fmt, arg ...) UTILS_LOG(SAI_LOG_WARN, fmt, ## arg) -#define STUB_LOG_ERR(fmt, arg ...) UTILS_LOG(SAI_LOG_ERROR, fmt, ## arg) -#define STUB_LOG_NTC(fmt, arg ...) UTILS_LOG(SAI_LOG_NOTICE, fmt, ## arg) - -#else /* WIN32 */ - -#define PRId64 "lld" -#include -#define UTILS_LOG(level, fmt, ...) \ - do { \ - utils_log(level, QUOTEME(__MODULE__), "%s[%d]- %s: " fmt, \ - __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); \ - } while (0) - -#define STUB_LOG_ENTER() UTILS_LOG(SAI_LOG_DEBUG, "%s: [\n", __FUNCTION__) -#define STUB_LOG_EXIT() UTILS_LOG(SAI_LOG_DEBUG, "%s: ]\n", __FUNCTION__) -#define STUB_LOG_DBG(fmt, ...) UTILS_LOG(SAI_LOG_DEBUG, fmt, __VA_ARGS__) -#define STUB_LOG_INF(fmt, ...) UTILS_LOG(SAI_LOG_INFO, fmt, __VA_ARGS__) -#define STUB_LOG_WRN(fmt, ...) UTILS_LOG(SAI_LOG_WARN, fmt, __VA_ARGS__) -#define STUB_LOG_ERR(fmt, ...) UTILS_LOG(SAI_LOG_ERROR, fmt, __VA_ARGS__) -#define STUB_LOG_NTC(fmt, ...) UTILS_LOG(SAI_LOG_NOTICE, fmt, __VA_ARGS__) - -#endif - -#endif /* __STUBSAI_H_ */ diff --git a/stub/sai_interface.ver b/stub/sai_interface.ver deleted file mode 100644 index 861a93fd0..000000000 --- a/stub/sai_interface.ver +++ /dev/null @@ -1,9 +0,0 @@ -# In this file we track the current API version -# of the SwitchX SDK libraries. -# The version is built of the following -# tree numbers: -# MAJOR:MINOR:REV -# MAJOR - API has completely changed -# MINOR - API changes require code fixing -# REV - API is compatible with previous versions -LIBVERSION=1:0:0 diff --git a/stub/src/Makefile.am b/stub/src/Makefile.am deleted file mode 100644 index cff9e760b..000000000 --- a/stub/src/Makefile.am +++ /dev/null @@ -1,39 +0,0 @@ -# Makefile.am -- Process this file with automake to produce Makefile.in - -INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/include -I$(srcdir) \ - -I$(srcdir)/../inc -I$(srcdir)/../../inc \ - -I$(APP_LIB_PATH)/include - -if DEBUG -DBGFLAGS = -ggdb -D_DEBUG_ -else -DBGFLAGS = -g -endif - -CFLAGS = @CFLAGS@ $(CFLAGS_SAI_INTERFACE_COMMON) $(DBGFLAGS) - -lib_LTLIBRARIES = libsai.la - -libsai_la_SOURCES = \ - stub_sai_fdb.c \ - stub_sai_interfacequery.c \ - stub_sai_neighbor.c \ - stub_sai_nexthop.c \ - stub_sai_nexthopgroup.c \ - stub_sai_port.c \ - stub_sai_route.c \ - stub_sai_router.c \ - stub_sai_switch.c \ - stub_sai_utils.c \ - stub_sai_vlan.c \ - stub_sai_rif.c \ - stub_sai_host_interface.c - -libsai_la_LIBADD = - -libsai_apiincludedir = $(includedir)/sai -libsai_apiinclude_HEADERS = $(top_srcdir)/../inc/*.h - - -libsai_api_version=$(shell grep LIBVERSION= $(top_srcdir)/sai_interface.ver | sed 's/LIBVERSION=//') -libsai_la_LDFLAGS = -version-info $(libsai_api_version) diff --git a/stub/src/stub_sai_fdb.c b/stub/src/stub_sai_fdb.c deleted file mode 100644 index 92e17bc68..000000000 --- a/stub/src/stub_sai_fdb.c +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" -#include "assert.h" - -#undef __MODULE__ -#define __MODULE__ SAI_FDB - -sai_status_t stub_fdb_type_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_fdb_port_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_fdb_action_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_fdb_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_fdb_port_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_fdb_action_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); - -static const sai_attribute_entry_t fdb_attribs[] = { - { SAI_FDB_ENTRY_ATTR_TYPE, true, true, true, true, - "FDB entry type", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_FDB_ENTRY_ATTR_PORT_ID, true, true, true, true, - "FDB entry port id", SAI_ATTR_VAL_TYPE_OID}, - { SAI_FDB_ENTRY_ATTR_PACKET_ACTION, true, true, true, true, - "FDB entry packet action", SAI_ATTR_VAL_TYPE_S32 }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED } -}; -static const sai_vendor_attribute_entry_t fdb_vendor_attribs[] = { - { SAI_FDB_ENTRY_ATTR_TYPE, - { true, false, true, true }, - { true, false, true, true }, - stub_fdb_type_get, NULL, - stub_fdb_type_set, NULL }, - { SAI_FDB_ENTRY_ATTR_PORT_ID, - { true, false, true, true }, - { true, false, true, true }, - stub_fdb_port_get, NULL, - stub_fdb_port_set, NULL }, - { SAI_FDB_ENTRY_ATTR_PACKET_ACTION, - { true, false, true, true }, - { true, false, true, true }, - stub_fdb_action_get, NULL, - stub_fdb_action_set, NULL } -}; -static void fdb_key_to_str(_In_ const sai_fdb_entry_t* fdb_entry, _Out_ char *key_str) -{ - snprintf(key_str, MAX_KEY_STR_LEN, "fdb entry mac [%02x:%02x:%02x:%02x:%02x:%02x] vlan %u", - fdb_entry->mac_address[0], - fdb_entry->mac_address[1], - fdb_entry->mac_address[2], - fdb_entry->mac_address[3], - fdb_entry->mac_address[4], - fdb_entry->mac_address[5], - fdb_entry->vlan_id); -} - -/* - * Routine Description: - * Create FDB entry - * - * Arguments: - * [in] fdb_entry - fdb entry - * [in] attr_count - number of attributes - * [in] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_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 status; - const sai_attribute_value_t *type, *action, *port; - uint32_t type_index, action_index, port_index, port_id; - char key_str[MAX_KEY_STR_LEN]; - char list_str[MAX_LIST_VALUE_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == fdb_entry) { - STUB_LOG_ERR("NULL fdb entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_STATUS_SUCCESS != - (status = - check_attribs_metadata(attr_count, attr_list, fdb_attribs, fdb_vendor_attribs, SAI_OPERATION_CREATE))) { - STUB_LOG_ERR("Failed attribs check\n"); - return status; - } - - fdb_key_to_str(fdb_entry, key_str); - sai_attr_list_to_str(attr_count, attr_list, fdb_attribs, MAX_LIST_VALUE_STR_LEN, list_str); - STUB_LOG_NTC("Create FDB entry %s\n", key_str); - STUB_LOG_NTC("Attribs %s\n", list_str); - - assert(SAI_STATUS_SUCCESS == find_attrib_in_list(attr_count, - attr_list, - SAI_FDB_ENTRY_ATTR_TYPE, - &type, - &type_index)); - assert(SAI_STATUS_SUCCESS == - find_attrib_in_list(attr_count, attr_list, SAI_FDB_ENTRY_ATTR_PACKET_ACTION, &action, &action_index)); - assert(SAI_STATUS_SUCCESS == - find_attrib_in_list(attr_count, attr_list, SAI_FDB_ENTRY_ATTR_PORT_ID, &port, &port_index)); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(port->oid, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Remove FDB entry - * - * Arguments: - * [in] fdb_entry - fdb entry - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_fdb_entry(_In_ const sai_fdb_entry_t* fdb_entry) -{ - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == fdb_entry) { - STUB_LOG_ERR("NULL fdb entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - fdb_key_to_str(fdb_entry, key_str); - STUB_LOG_NTC("Remove FDB entry %s\n", key_str); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Set fdb entry attribute value - * - * Arguments: - * [in] fdb_entry - fdb entry - * [in] attr - attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_fdb_entry_attribute(_In_ const sai_fdb_entry_t* fdb_entry, _In_ const sai_attribute_t *attr) -{ - const sai_object_key_t key = {.fdb_entry = fdb_entry }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == fdb_entry) { - STUB_LOG_ERR("NULL fdb entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - fdb_key_to_str(fdb_entry, key_str); - return sai_set_attribute(&key, key_str, fdb_attribs, fdb_vendor_attribs, attr); -} - -/* Set FDB entry type [sai_fdb_entry_type_t] */ -sai_status_t stub_fdb_type_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* FDB entry port id [sai_object_id_t] (MANDATORY_ON_CREATE|CREATE_AND_SET) - * The port id here can refer to a generic port object such as SAI port object id, - * SAI LAG object id and etc. on. */ -sai_status_t stub_fdb_port_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(value->oid, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Set FDB entry packet action [sai_packet_action_t] */ -sai_status_t stub_fdb_action_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Get fdb entry attribute value - * - * Arguments: - * [in] fdb_entry - fdb entry - * [in] attr_count - number of attributes - * [inout] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_fdb_entry_attribute(_In_ const sai_fdb_entry_t* fdb_entry, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - const sai_object_key_t key = { .fdb_entry = fdb_entry }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == fdb_entry) { - STUB_LOG_ERR("NULL fdb entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - fdb_key_to_str(fdb_entry, key_str); - return sai_get_attributes(&key, key_str, fdb_attribs, fdb_vendor_attribs, attr_count, attr_list); -} - -/* Get FDB entry type [sai_fdb_entry_type_t] */ -sai_status_t stub_fdb_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = SAI_FDB_ENTRY_STATIC; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* FDB entry port id [sai_object_id_t] (MANDATORY_ON_CREATE|CREATE_AND_SET) - * The port id here can refer to a generic port object such as SAI port object id, - * SAI LAG object id and etc. on. - * Port 0 is returned for entries with action = drop or action = trap - * Since port is irrelevant for these actions, even if actual port is set - * In case the action is changed from drop/trap to forward/log, need to also set port - */ -sai_status_t stub_fdb_port_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_PORT, 1, &value->oid))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Get FDB entry packet action [sai_packet_action_t] */ -sai_status_t stub_fdb_action_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = SAI_PACKET_ACTION_FORWARD; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Remove all FDB entries by attribute set in sai_fdb_flush_attr - * - * Arguments: - * [in] attr_count - number of attributes - * [in] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_flush_fdb_entries(_In_ uint32_t attr_count, _In_ const sai_attribute_t *attr_list) -{ - sai_status_t status; - const sai_attribute_value_t *port, *vlan, *type; - uint32_t port_index, vlan_index, type_index; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS == - (status = - find_attrib_in_list(attr_count, attr_list, SAI_FDB_FLUSH_ATTR_PORT_ID, - &port, &port_index))) { - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(port->oid, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - } - - if (SAI_STATUS_SUCCESS == - (status = - find_attrib_in_list(attr_count, attr_list, SAI_FDB_FLUSH_ATTR_VLAN_ID, - &vlan, &vlan_index))) { - } - - if (SAI_STATUS_SUCCESS == - (status = - find_attrib_in_list(attr_count, attr_list, SAI_FDB_FLUSH_ATTR_ENTRY_TYPE, - &type, &type_index))) { - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -const sai_fdb_api_t fdb_api = { - stub_create_fdb_entry, - stub_remove_fdb_entry, - stub_set_fdb_entry_attribute, - stub_get_fdb_entry_attribute, - stub_flush_fdb_entries -}; diff --git a/stub/src/stub_sai_host_interface.c b/stub/src/stub_sai_host_interface.c deleted file mode 100644 index 2b413ea75..000000000 --- a/stub/src/stub_sai_host_interface.c +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" -#include "assert.h" -#ifndef _WIN32 -#include -#endif - -#undef __MODULE__ -#define __MODULE__ SAI_HOST_INTERFACE - -static const sai_attribute_entry_t host_interface_attribs[] = { - { SAI_HOSTIF_ATTR_TYPE, true, true, false, true, - "Host interface type", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_HOSTIF_ATTR_RIF_OR_PORT_ID, false, true, false, true, - "Host interface associated port or router interface", SAI_ATTR_VAL_TYPE_OID }, - { SAI_HOSTIF_ATTR_NAME, true, true, true, true, - "Host interface name", SAI_ATTR_VAL_TYPE_CHARDATA }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED } -}; - -sai_status_t stub_host_interface_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_host_interface_rif_port_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_host_interface_name_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_host_interface_name_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); - -static const sai_vendor_attribute_entry_t host_interface_vendor_attribs[] = { - { SAI_HOSTIF_ATTR_TYPE, - { true, false, false, true }, - { true, false, false, true }, - stub_host_interface_type_get, NULL, - NULL, NULL }, - { SAI_HOSTIF_ATTR_RIF_OR_PORT_ID, - { true, false, false, true }, - { true, false, false, true }, - stub_host_interface_rif_port_get, NULL, - NULL, NULL }, - { SAI_HOSTIF_ATTR_NAME, - { true, false, true, true }, - { true, false, true, true }, - stub_host_interface_name_get, NULL, - stub_host_interface_name_set, NULL }, -}; -static void host_interface_key_to_str(_In_ sai_object_id_t hif_id, _Out_ char *key_str) -{ - uint32_t hif_data; - - if (SAI_STATUS_SUCCESS != stub_object_to_type(hif_id, SAI_OBJECT_TYPE_HOST_INTERFACE, &hif_data)) { - snprintf(key_str, MAX_KEY_STR_LEN, "invalid host interface"); - } else { - snprintf(key_str, MAX_KEY_STR_LEN, "host interface %u", hif_data); - } -} - -/* - * Routine Description: - * Create host interface. - * - * Arguments: - * [out] hif_id - host interface id - * [in] attr_count - number of attributes - * [in] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_create_host_interface(_Out_ sai_object_id_t * hif_id, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) -{ - sai_status_t status; - int ret; - const sai_attribute_value_t *type, *rif_port, *name; - uint32_t type_index, rif_port_index, name_index, rif_data; - char key_str[MAX_KEY_STR_LEN]; - char list_str[MAX_LIST_VALUE_STR_LEN]; - static uint32_t next_id = 0; - char system_cmd[1024]; - - STUB_LOG_ENTER(); - - if (NULL == hif_id) { - STUB_LOG_ERR("NULL host interface ID param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_STATUS_SUCCESS != - (status = - check_attribs_metadata(attr_count, attr_list, host_interface_attribs, host_interface_vendor_attribs, - SAI_OPERATION_CREATE))) { - STUB_LOG_ERR("Failed attribs check\n"); - return status; - } - - sai_attr_list_to_str(attr_count, attr_list, host_interface_attribs, MAX_LIST_VALUE_STR_LEN, list_str); - STUB_LOG_NTC("Create host interface, %s\n", list_str); - - assert(SAI_STATUS_SUCCESS == - find_attrib_in_list(attr_count, attr_list, SAI_HOSTIF_ATTR_TYPE, &type, &type_index)); - assert(SAI_STATUS_SUCCESS == - find_attrib_in_list(attr_count, attr_list, SAI_HOSTIF_ATTR_NAME, &name, &name_index)); - - if (SAI_HOSTIF_TYPE_NETDEV == type->s32) { - if (SAI_STATUS_SUCCESS != - (status = - find_attrib_in_list(attr_count, attr_list, SAI_HOSTIF_ATTR_RIF_OR_PORT_ID, &rif_port, - &rif_port_index))) { - STUB_LOG_ERR("Missing mandatory attribute rif port id on create of host if netdev type\n"); - return SAI_STATUS_MANDATORY_ATTRIBUTE_MISSING; - } - - if (SAI_OBJECT_TYPE_ROUTER_INTERFACE == sai_object_type_query(rif_port->oid)) { - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(rif_port->oid, SAI_OBJECT_TYPE_ROUTER_INTERFACE, &rif_data))) { - return status; - } - } else if (SAI_OBJECT_TYPE_PORT == sai_object_type_query(rif_port->oid)) { - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(rif_port->oid, SAI_OBJECT_TYPE_PORT, &rif_data))) { - return status; - } - } else { - STUB_LOG_ERR("Invalid rif port object type %s", SAI_TYPE_STR(sai_object_type_query(rif_port->oid))); - return SAI_STATUS_INVALID_ATTR_VALUE_0 + rif_port_index; - } - snprintf(system_cmd, sizeof(system_cmd), "ip link add name %s type dummy", name->chardata); - ret = system(system_cmd); - if (0 != ret) { - STUB_LOG_INF("Error on attempt to create dummy interface. Possibly interface already exists"); - return SAI_STATUS_SUCCESS; - } - - } else if (SAI_HOSTIF_TYPE_FD == type->s32) { - } else { - STUB_LOG_ERR("Invalid host interface type %d\n", type->s32); - return SAI_STATUS_INVALID_ATTR_VALUE_0 + type_index; - } - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_HOST_INTERFACE, next_id++, hif_id))) { - return status; - } - host_interface_key_to_str(*hif_id, key_str); - STUB_LOG_NTC("Created host interface %s\n", key_str); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Remove host interface - * - * Arguments: - * [in] hif_id - host interface id - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_host_interface(_In_ sai_object_id_t hif_id) -{ - char key_str[MAX_KEY_STR_LEN]; - uint32_t hif_data; - sai_status_t status; - - STUB_LOG_ENTER(); - - host_interface_key_to_str(hif_id, key_str); - STUB_LOG_NTC("Remove host interface %s\n", key_str); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(hif_id, SAI_OBJECT_TYPE_HOST_INTERFACE, &hif_data))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Set host interface attribute - * - * Arguments: - * [in] hif_id - host interface id - * [in] attr - attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_host_interface_attribute(_In_ sai_object_id_t hif_id, _In_ const sai_attribute_t *attr) -{ - const sai_object_key_t key = { .object_id = hif_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - host_interface_key_to_str(hif_id, key_str); - return sai_set_attribute(&key, key_str, host_interface_attribs, host_interface_vendor_attribs, attr); -} - -/* - * Routine Description: - * Get host interface attribute - * - * Arguments: - * [in] hif_id - host interface id - * [in] attr_count - number of attributes - * [inout] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_host_interface_attribute(_In_ sai_object_id_t hif_id, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - const sai_object_key_t key = { .object_id = hif_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - host_interface_key_to_str(hif_id, key_str); - return sai_get_attributes(&key, - key_str, - host_interface_attribs, - host_interface_vendor_attribs, - attr_count, - attr_list); -} - -/* Type [sai_host_interface_type_t] */ -sai_status_t stub_host_interface_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = SAI_HOSTIF_TYPE_NETDEV; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Assosiated port or router interface [sai_object_id_t] */ -sai_status_t stub_host_interface_rif_port_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_PORT, 1, &value->oid))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Name [char[HOST_INTERFACE_NAME_SIZE]] (MANDATORY_ON_CREATE) - * The maximum number of charactars for the name is HOST_INTERFACE_NAME_SIZE - 1 since - * it needs the terminating null byte ('\0') at the end. */ -sai_status_t stub_host_interface_name_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - uint32_t hif_id; - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_HOST_INTERFACE, &hif_id))) { - return status; - } - - strncpy(value->chardata, "name", HOSTIF_NAME_SIZE); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Name [char[HOST_INTERFACE_NAME_SIZE]] - * The maximum number of charactars for the name is HOST_INTERFACE_NAME_SIZE - 1 since - * it needs the terminating null byte ('\0') at the end. */ -sai_status_t stub_host_interface_name_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - uint32_t hif_id; - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_HOST_INTERFACE, &hif_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -sai_status_t stub_set_host_interface_trap_attribute(_In_ sai_hostif_trap_type_t hostif_trapid, - _In_ const sai_attribute_t *attr) -{ - STUB_LOG_ENTER(); - STUB_LOG_EXIT(); - - return SAI_STATUS_SUCCESS; -} - - -const sai_hostif_api_t host_interface_api = { - stub_create_host_interface, - stub_remove_host_interface, - stub_set_host_interface_attribute, - stub_get_host_interface_attribute, - NULL, - NULL, - NULL, - NULL, - stub_set_host_interface_trap_attribute, - NULL, - NULL, - NULL, - NULL, - NULL -}; diff --git a/stub/src/stub_sai_interfacequery.c b/stub/src/stub_sai_interfacequery.c deleted file mode 100644 index 51c6c8cf6..000000000 --- a/stub/src/stub_sai_interfacequery.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" - -service_method_table_t g_services; -bool g_initialized = false; - -/* - * Routine Description: - * Adapter module initialization call. This is NOT for SDK initialization. - * - * Arguments: - * [in] flags - reserved for future use, must be zero - * [in] services - methods table with services provided by adapter host - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t sai_api_initialize(_In_ uint64_t flags, _In_ const service_method_table_t* services) -{ - if ((NULL == services) || (NULL == services->profile_get_next_value) || (NULL == services->profile_get_value)) { - fprintf(stderr, "Invalid services handle passed to SAI API initialize\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - memcpy(&g_services, services, sizeof(g_services)); - - if (0 != flags) { - fprintf(stderr, "Invalid flags passed to SAI API initialize\n"); - - return SAI_STATUS_INVALID_PARAMETER; - } - - g_initialized = true; - - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Retrieve a pointer to the C-style method table for desired SAI - * functionality as specified by the given sai_api_id. - * - * Arguments: - * [in] sai_api_id - SAI api ID - * [out] api_method_table - Caller allocated method table - * The table must remain valid until the sai_api_uninitialize() is called - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t sai_api_query(_In_ sai_api_t sai_api_id, _Out_ void** api_method_table) -{ - if (NULL == api_method_table) { - fprintf(stderr, "NULL method table passed to SAI API initialize\n"); - - return SAI_STATUS_INVALID_PARAMETER; - } - if (!g_initialized) { - fprintf(stderr, "SAI API not initialized before calling API query\n"); - - return SAI_STATUS_UNINITIALIZED; - } - - switch (sai_api_id) { - case SAI_API_SWITCH: - *(const sai_switch_api_t**)api_method_table = &switch_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_PORT: - *(const sai_port_api_t**)api_method_table = &port_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_FDB: - *(const sai_fdb_api_t**)api_method_table = &fdb_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_VLAN: - *(const sai_vlan_api_t**)api_method_table = &vlan_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_VIRTUAL_ROUTER: - *(const sai_virtual_router_api_t**)api_method_table = &router_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_ROUTE: - *(const sai_route_api_t**)api_method_table = &route_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_NEXT_HOP: - *(const sai_next_hop_api_t**)api_method_table = &next_hop_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_NEXT_HOP_GROUP: - *(const sai_next_hop_group_api_t**)api_method_table = &next_hop_group_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_ROUTER_INTERFACE: - *(const sai_router_interface_api_t**)api_method_table = &router_interface_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_NEIGHBOR: - *(const sai_neighbor_api_t**)api_method_table = &neighbor_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_QOS_MAPS: - /* TODO : implement */ - return SAI_STATUS_NOT_IMPLEMENTED; - - case SAI_API_ACL: - /* TODO : implement */ - return SAI_STATUS_NOT_IMPLEMENTED; - - case SAI_API_HOST_INTERFACE: - *(const sai_hostif_api_t**)api_method_table = &host_interface_api; - return SAI_STATUS_SUCCESS; - - case SAI_API_MIRROR: - /* TODO : implement */ - return SAI_STATUS_NOT_IMPLEMENTED; - - case SAI_API_SAMPLEPACKET: - /* TODO : implement */ - return SAI_STATUS_NOT_IMPLEMENTED; - - case SAI_API_STP: - /* TODO : implement */ - return SAI_STATUS_NOT_IMPLEMENTED; - - case SAI_API_LAG: - /* TODO : implement */ - return SAI_STATUS_NOT_IMPLEMENTED; - - default: - fprintf(stderr, "Invalid API type %d\n", sai_api_id); - return SAI_STATUS_INVALID_PARAMETER; - } -} - -/* - * Routine Description: - * Uninitialization of the adapter module. SAI functionalities, retrieved via - * sai_api_query() cannot be used after this call. - * - * Arguments: - * None - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t sai_api_uninitialize(void) -{ - memset(&g_services, 0, sizeof(g_services)); - g_initialized = false; - - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Set log level for sai api module. The default log level is SAI_LOG_WARN. - * - * Arguments: - * [in] sai_api_id - SAI api ID - * [in] log_level - log level - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t sai_log_set(_In_ sai_api_t sai_api_id, _In_ sai_log_level_t log_level) -{ - switch (log_level) { - case SAI_LOG_DEBUG: - break; - - case SAI_LOG_INFO: - break; - - case SAI_LOG_NOTICE: - break; - - case SAI_LOG_WARN: - break; - - case SAI_LOG_ERROR: - break; - - case SAI_LOG_CRITICAL: - break; - - default: - fprintf(stderr, "Invalid log level %d\n", log_level); - return SAI_STATUS_INVALID_PARAMETER; - } - - switch (sai_api_id) { - case SAI_API_SWITCH: - break; - - case SAI_API_PORT: - break; - - case SAI_API_FDB: - break; - - case SAI_API_VLAN: - break; - - case SAI_API_VIRTUAL_ROUTER: - break; - - case SAI_API_ROUTE: - break; - - case SAI_API_NEXT_HOP: - break; - - case SAI_API_NEXT_HOP_GROUP: - break; - - case SAI_API_ROUTER_INTERFACE: - break; - - case SAI_API_NEIGHBOR: - break; - - case SAI_API_QOS_MAPS: - break; - - case SAI_API_ACL: - break; - - case SAI_API_HOST_INTERFACE: - break; - - case SAI_API_MIRROR: - break; - - case SAI_API_SAMPLEPACKET: - break; - - case SAI_API_STP: - break; - - case SAI_API_LAG: - break; - - default: - fprintf(stderr, "Invalid API type %d\n", sai_api_id); - return SAI_STATUS_INVALID_PARAMETER; - } - - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Query sai object type. - * - * Arguments: - * [in] sai_object_id_t - * - * Return Values: - * Return SAI_OBJECT_TYPE_NULL when sai_object_id is not valid. - * Otherwise, return a valid sai object type SAI_OBJECT_TYPE_XXX - */ -sai_object_type_t sai_object_type_query(_In_ sai_object_id_t sai_object_id) -{ - sai_object_type_t type = ((stub_object_id_t*)&sai_object_id)->object_type; - - if SAI_TYPE_CHECK_RANGE(type) { - return type; - } else { - fprintf(stderr, "Unknown type %d", type); - return SAI_OBJECT_TYPE_NULL; - } -} diff --git a/stub/src/stub_sai_neighbor.c b/stub/src/stub_sai_neighbor.c deleted file mode 100644 index 8e18789bb..000000000 --- a/stub/src/stub_sai_neighbor.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" -#include "assert.h" - -#undef __MODULE__ -#define __MODULE__ SAI_NEIGHBOR - -static const sai_attribute_entry_t neighbor_attribs[] = { - { SAI_NEIGHBOR_ATTR_DST_MAC_ADDRESS, true, true, true, true, - "Neighbor destination MAC", SAI_ATTR_VAL_TYPE_MAC }, - { SAI_NEIGHBOR_ATTR_PACKET_ACTION, false, true, true, true, - "Neighbor L3 forwarding action", SAI_ATTR_VAL_TYPE_S32 }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED } -}; - -sai_status_t stub_neighbor_mac_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_neighbor_action_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_neighbor_mac_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_neighbor_action_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); - -static const sai_vendor_attribute_entry_t neighbor_vendor_attribs[] = { - { SAI_NEIGHBOR_ATTR_DST_MAC_ADDRESS, - { true, false, true, true }, - { true, false, true, true }, - stub_neighbor_mac_get, NULL, - stub_neighbor_mac_set, NULL }, - { SAI_NEIGHBOR_ATTR_PACKET_ACTION, - { true, false, true, true }, - { true, false, true, true }, - stub_neighbor_action_get, NULL, - stub_neighbor_action_set, NULL }, -}; -static void neighbor_key_to_str(_In_ const sai_neighbor_entry_t* neighbor_entry, _Out_ char *key_str) -{ - int res1, res2; - uint32_t rifid; - - res1 = snprintf(key_str, MAX_KEY_STR_LEN, "neighbor ip "); - sai_ipaddr_to_str(neighbor_entry->ip_address, MAX_KEY_STR_LEN - res1, key_str + res1, &res2); - if (SAI_STATUS_SUCCESS != stub_object_to_type(neighbor_entry->rif_id, SAI_OBJECT_TYPE_ROUTER_INTERFACE, &rifid)) { - snprintf(key_str + res1 + res2, MAX_KEY_STR_LEN - res1 - res2, " invalid rif"); - } else { - snprintf(key_str + res1 + res2, MAX_KEY_STR_LEN - res1 - res2, " rif %u", rifid); - } -} - -/* - * Routine Description: - * Create neighbor entry - * - * Arguments: - * [in] neighbor_entry - neighbor entry - * [in] attr_count - number of attributes - * [in] attrs - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - * - * Note: IP address expected in Network Byte Order. - */ -sai_status_t stub_create_neighbor_entry(_In_ const sai_neighbor_entry_t* neighbor_entry, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) -{ - sai_status_t status; - uint32_t rif_data; - char key_str[MAX_KEY_STR_LEN]; - char list_str[MAX_LIST_VALUE_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == neighbor_entry) { - STUB_LOG_ERR("NULL neighbor entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_STATUS_SUCCESS != - (status = - check_attribs_metadata(attr_count, attr_list, neighbor_attribs, neighbor_vendor_attribs, - SAI_OPERATION_CREATE))) { - STUB_LOG_ERR("Failed attribs check\n"); - return status; - } - - neighbor_key_to_str(neighbor_entry, key_str); - sai_attr_list_to_str(attr_count, attr_list, neighbor_attribs, MAX_LIST_VALUE_STR_LEN, list_str); - STUB_LOG_NTC("Create neighbor entry %s\n", key_str); - STUB_LOG_NTC("Attribs %s\n", list_str); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(neighbor_entry->rif_id, SAI_OBJECT_TYPE_ROUTER_INTERFACE, &rif_data))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Remove neighbor entry - * - * Arguments: - * [in] neighbor_entry - neighbor entry - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - * - * Note: IP address expected in Network Byte Order. - */ -sai_status_t stub_remove_neighbor_entry(_In_ const sai_neighbor_entry_t* neighbor_entry) -{ - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == neighbor_entry) { - STUB_LOG_ERR("NULL neighbor entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - neighbor_key_to_str(neighbor_entry, key_str); - STUB_LOG_NTC("Remove neighbor entry %s\n", key_str); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Set neighbor attribute value - * - * Arguments: - * [in] neighbor_entry - neighbor entry - * [in] attr - attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_neighbor_attribute(_In_ const sai_neighbor_entry_t* neighbor_entry, - _In_ const sai_attribute_t *attr) -{ - const sai_object_key_t key = { .neighbor_entry = neighbor_entry }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == neighbor_entry) { - STUB_LOG_ERR("NULL neighbor entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - neighbor_key_to_str(neighbor_entry, key_str); - return sai_set_attribute(&key, key_str, neighbor_attribs, neighbor_vendor_attribs, attr); -} - -/* - * Routine Description: - * Get neighbor attribute value - * - * Arguments: - * [in] neighbor_entry - neighbor entry - * [in] attr_count - number of attributes - * [inout] attrs - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_neighbor_attribute(_In_ const sai_neighbor_entry_t* neighbor_entry, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - const sai_object_key_t key = { .neighbor_entry = neighbor_entry }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == neighbor_entry) { - STUB_LOG_ERR("NULL neighbor entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - neighbor_key_to_str(neighbor_entry, key_str); - return sai_get_attributes(&key, key_str, neighbor_attribs, neighbor_vendor_attribs, attr_count, attr_list); -} - -/* Destination mac address for the neighbor [sai_mac_t] */ -sai_status_t stub_neighbor_mac_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* L3 forwarding action for this neighbor [sai_packet_action_t] */ -sai_status_t stub_neighbor_action_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = SAI_PACKET_ACTION_DROP; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Destination mac address for the neighbor [sai_mac_t] */ -sai_status_t stub_neighbor_mac_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* L3 forwarding action for this neighbor [sai_packet_action_t] */ -sai_status_t stub_neighbor_action_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - - -/* - * Routine Description: - * Remove all neighbor entries - * - * Arguments: - * None - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_all_neighbor_entries(void) -{ - STUB_LOG_ENTER(); - - STUB_LOG_NTC("Remove all neighbor entries\n"); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -const sai_neighbor_api_t neighbor_api = { - stub_create_neighbor_entry, - stub_remove_neighbor_entry, - stub_set_neighbor_attribute, - stub_get_neighbor_attribute, - stub_remove_all_neighbor_entries -}; diff --git a/stub/src/stub_sai_nexthop.c b/stub/src/stub_sai_nexthop.c deleted file mode 100644 index 22bd96f99..000000000 --- a/stub/src/stub_sai_nexthop.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" -#include "assert.h" - -#undef __MODULE__ -#define __MODULE__ SAI_NEXT_HOP - -static const sai_attribute_entry_t next_hop_attribs[] = { - { SAI_NEXT_HOP_ATTR_TYPE, true, true, false, true, - "Next hop entry type", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_NEXT_HOP_ATTR_IP, true, true, false, true, - "Next hop entry IP address", SAI_ATTR_VAL_TYPE_IPADDR }, - { SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID, true, true, false, true, - "Next hop entry router interface ID", SAI_ATTR_VAL_TYPE_OID }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED } -}; - -sai_status_t stub_next_hop_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_next_hop_ip_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_next_hop_rif_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); - -static const sai_vendor_attribute_entry_t next_hop_vendor_attribs[] = { - { SAI_NEXT_HOP_ATTR_TYPE, - { true, false, false, true }, - { true, false, false, true }, - stub_next_hop_type_get, NULL, - NULL, NULL }, - { SAI_NEXT_HOP_ATTR_IP, - { true, false, false, true }, - { true, false, false, true }, - stub_next_hop_ip_get, NULL, - NULL, NULL }, - { SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID, - { true, false, false, true }, - { true, false, false, true }, - stub_next_hop_rif_get, NULL, - NULL, NULL }, -}; -static void next_hop_key_to_str(_In_ sai_object_id_t next_hop_id, _Out_ char *key_str) -{ - uint32_t nexthop_data; - - if (SAI_STATUS_SUCCESS != stub_object_to_type(next_hop_id, SAI_OBJECT_TYPE_NEXT_HOP, &nexthop_data)) { - snprintf(key_str, MAX_KEY_STR_LEN, "invalid next hop id"); - } else { - snprintf(key_str, MAX_KEY_STR_LEN, "next hop id %u", nexthop_data); - } -} - -/* - * Routine Description: - * Create next hop - * - * Arguments: - * [out] next_hop_id - next hop id - * [in] attr_count - number of attributes - * [in] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - * - * Note: IP address expected in Network Byte Order. - */ -sai_status_t stub_create_next_hop(_Out_ sai_object_id_t *next_hop_id, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) -{ - sai_status_t status; - const sai_attribute_value_t *type, *ip, *rif; - uint32_t type_index, ip_index, rif_index; - char list_str[MAX_LIST_VALUE_STR_LEN]; - char key_str[MAX_KEY_STR_LEN]; - static uint32_t next_id = 0; - - STUB_LOG_ENTER(); - - if (NULL == next_hop_id) { - STUB_LOG_ERR("NULL next hop id param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_STATUS_SUCCESS != - (status = - check_attribs_metadata(attr_count, attr_list, next_hop_attribs, next_hop_vendor_attribs, - SAI_OPERATION_CREATE))) { - STUB_LOG_ERR("Failed attribs check\n"); - return status; - } - - sai_attr_list_to_str(attr_count, attr_list, next_hop_attribs, MAX_LIST_VALUE_STR_LEN, list_str); - STUB_LOG_NTC("Create next hop, %s\n", list_str); - - assert(SAI_STATUS_SUCCESS == - find_attrib_in_list(attr_count, attr_list, SAI_NEXT_HOP_ATTR_TYPE, &type, &type_index)); - assert(SAI_STATUS_SUCCESS == find_attrib_in_list(attr_count, attr_list, SAI_NEXT_HOP_ATTR_IP, &ip, &ip_index)); - assert(SAI_STATUS_SUCCESS == - find_attrib_in_list(attr_count, attr_list, SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID, &rif, &rif_index)); - - if (SAI_NEXT_HOP_IP != type->s32) { - STUB_LOG_ERR("Invalid next hop type %d on create\n", type->s32); - return SAI_STATUS_INVALID_ATTR_VALUE_0 + type_index; - } - - if (SAI_IP_ADDR_FAMILY_IPV4 == ip->ipaddr.addr_family) { - } else if (SAI_IP_ADDR_FAMILY_IPV6 == ip->ipaddr.addr_family) { - } else { - STUB_LOG_ERR("Invalid ip addr family %d on create\n", ip->ipaddr.addr_family); - return SAI_STATUS_INVALID_ATTR_VALUE_0 + ip_index; - } - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_NEXT_HOP, next_id++, next_hop_id))) { - return status; - } - next_hop_key_to_str(*next_hop_id, key_str); - STUB_LOG_NTC("Created next hop %s\n", key_str); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Remove next hop - * - * Arguments: - * [in] next_hop_id - next hop id - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_next_hop(_In_ sai_object_id_t next_hop_id) -{ - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - next_hop_key_to_str(next_hop_id, key_str); - STUB_LOG_NTC("Remove next hop %s\n", key_str); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Set Next Hop attribute - * - * Arguments: - * [in] next_hop_id - next hop id - * [in] attr - attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_next_hop_attribute(_In_ sai_object_id_t next_hop_id, _In_ const sai_attribute_t *attr) -{ - const sai_object_key_t key = { .object_id = next_hop_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - next_hop_key_to_str(next_hop_id, key_str); - return sai_set_attribute(&key, key_str, next_hop_attribs, next_hop_vendor_attribs, attr); -} - - -/* - * Routine Description: - * Get Next Hop attribute - * - * Arguments: - * [in] next_hop_id - next hop id - * [in] attr_count - number of attributes - * [inout] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_next_hop_attribute(_In_ sai_object_id_t next_hop_id, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - const sai_object_key_t key = { .object_id = next_hop_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - next_hop_key_to_str(next_hop_id, key_str); - return sai_get_attributes(&key, key_str, next_hop_attribs, next_hop_vendor_attribs, attr_count, attr_list); -} - -/* Next hop entry type [sai_next_hop_type_t] */ -sai_status_t stub_next_hop_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = SAI_NEXT_HOP_IP; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Next hop entry ipv4 address [sai_ip_address_t] */ -sai_status_t stub_next_hop_ip_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - uint32_t nexthop_data; - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_NEXT_HOP, &nexthop_data))) { - return status; - } - - value->ipaddr.addr_family = SAI_IP_ADDR_FAMILY_IPV4; - value->ipaddr.addr.ip4 = 0; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Next hop entry router interface id [sai_object_id_t] (MANDATORY_ON_CREATE|CREATE_ONLY) */ -sai_status_t stub_next_hop_rif_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - uint32_t nexthop_data; - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_NEXT_HOP, &nexthop_data))) { - return status; - } - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_ROUTER_INTERFACE, 0, &value->oid))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -const sai_next_hop_api_t next_hop_api = { - stub_create_next_hop, - stub_remove_next_hop, - stub_set_next_hop_attribute, - stub_get_next_hop_attribute -}; diff --git a/stub/src/stub_sai_nexthopgroup.c b/stub/src/stub_sai_nexthopgroup.c deleted file mode 100644 index c1fd69d2b..000000000 --- a/stub/src/stub_sai_nexthopgroup.c +++ /dev/null @@ -1,682 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" -#include "assert.h" - -#undef __MODULE__ -#define __MODULE__ SAI_NEXT_HOP_GROUP - -static const sai_attribute_entry_t next_hop_group_attribs[] = { - { SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_COUNT, false, false, false, true, - "Next hop group entries count", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_NEXT_HOP_GROUP_ATTR_TYPE, true, true, false, true, - "Next hop group type", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_LIST, true, true, true, true, - "Next hop group hop list", SAI_ATTR_VAL_TYPE_OBJLIST }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED } -}; - -sai_status_t stub_next_hop_group_count_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_next_hop_group_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_next_hop_group_hop_list_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_next_hop_group_hop_list_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); - -static const sai_vendor_attribute_entry_t next_hop_group_vendor_attribs[] = { - { SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_COUNT, - { false, false, false, true }, - { false, false, false, true }, - stub_next_hop_group_count_get, NULL, - NULL, NULL }, - { SAI_NEXT_HOP_GROUP_ATTR_TYPE, - { true, false, false, true }, - { true, false, false, true }, - stub_next_hop_group_type_get, NULL, - NULL, NULL }, - { SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_LIST, - { true, false, true, true }, - { true, false, true, true }, - stub_next_hop_group_hop_list_get, NULL, - stub_next_hop_group_hop_list_set, NULL }, -}; - -/* State DB *************/ -#define ECMP_MAX_PATHS 64 - -typedef struct _stub_next_hop_group_t { - uint32_t next_hop_count; - sai_object_id_t next_hop_list[ECMP_MAX_PATHS]; - bool is_valid; -} stub_next_hop_group_t; - -#define MAX_NEXT_HOP_GROUP_NUMBER 1000 -static stub_next_hop_group_t next_hop_group_db[MAX_NEXT_HOP_GROUP_NUMBER]; - -void db_init_next_hop_group() -{ - memset(next_hop_group_db, 0, sizeof(next_hop_group_db)); -} - -sai_status_t db_get_next_hop_group(_In_ uint32_t next_hop_group_id, _Out_ sai_object_list_t *next_hop_list) -{ - if (NULL == next_hop_list) { - STUB_LOG_ERR("NULL next hop list param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if ((next_hop_group_id >= MAX_NEXT_HOP_GROUP_NUMBER) || - (!next_hop_group_db[next_hop_group_id].is_valid)) { - STUB_LOG_ERR("Invalid next hop group ID %u\n", next_hop_group_id); - return SAI_STATUS_INVALID_PARAMETER; - } - - next_hop_list->count = next_hop_group_db[next_hop_group_id].next_hop_count; - next_hop_list->list = next_hop_group_db[next_hop_group_id].next_hop_list; - - return SAI_STATUS_SUCCESS; -} - -static sai_status_t db_find_free_index(_Out_ uint32_t *free_index) -{ - uint32_t ii; - - for (ii = 0; ii < MAX_NEXT_HOP_GROUP_NUMBER; ii++) { - if (false == next_hop_group_db[ii].is_valid) { - *free_index = ii; - return SAI_STATUS_SUCCESS; - } - } - - STUB_LOG_ERR("Next hop group table full\n"); - return SAI_STATUS_TABLE_FULL; -} - -static sai_status_t validate_next_hop_list(_In_ uint32_t next_hop_count, - _In_ const sai_object_id_t* nexthops, - _In_ uint32_t param_index) -{ - uint32_t ii; - - for (ii = 0; ii < next_hop_count; ii++) { - if (SAI_OBJECT_TYPE_NEXT_HOP != sai_object_type_query(nexthops[ii])) { - STUB_LOG_ERR("Invalid next hop object type %s, index %u\n", - SAI_TYPE_STR(sai_object_type_query(nexthops[ii])), ii); - return SAI_STATUS_INVALID_ATTR_VALUE_0 + param_index; - } - } - - return SAI_STATUS_SUCCESS; -} - -static sai_status_t db_create_next_hop_group(_Out_ uint32_t *next_hop_group_id, - _In_ const sai_object_list_t *next_hop_list, - _In_ uint32_t param_index) -{ - sai_status_t status; - - if (NULL == next_hop_group_id) { - STUB_LOG_ERR("NULL next hop group id param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == next_hop_list) { - STUB_LOG_ERR("NULL next hop list param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (next_hop_list->count > ECMP_MAX_PATHS) { - STUB_LOG_ERR("Next hop count %u bigger than maximum %u\n", next_hop_list->count, ECMP_MAX_PATHS); - return SAI_STATUS_INVALID_ATTR_VALUE_0 + param_index; - } - - if (0 == next_hop_list->count) { - STUB_LOG_ERR("Can't create empty next hop group\n"); - return SAI_STATUS_INVALID_ATTR_VALUE_0 + param_index; - } - - if (SAI_STATUS_SUCCESS != - (status = db_find_free_index(next_hop_group_id))) { - return status; - } - - if (SAI_STATUS_SUCCESS != - (status = validate_next_hop_list(next_hop_list->count, next_hop_list->list, param_index))) { - return status; - } - - next_hop_group_db[*next_hop_group_id].next_hop_count = next_hop_list->count; - memcpy(next_hop_group_db[*next_hop_group_id].next_hop_list, - next_hop_list->list, - sizeof(sai_object_id_t) * next_hop_list->count); - next_hop_group_db[*next_hop_group_id].is_valid = true; - - return SAI_STATUS_SUCCESS; -} - -static sai_status_t db_remove_next_hop_group(_In_ uint32_t next_hop_group_id) -{ - if ((next_hop_group_id >= MAX_NEXT_HOP_GROUP_NUMBER) || - (!next_hop_group_db[next_hop_group_id].is_valid)) { - STUB_LOG_ERR("Invalid next hop group ID %u\n", next_hop_group_id); - return SAI_STATUS_INVALID_PARAMETER; - } - - next_hop_group_db[next_hop_group_id].is_valid = false; - - return SAI_STATUS_SUCCESS; -} - -sai_status_t db_update_next_hop_group_list(_In_ uint32_t next_hop_group_id, _In_ sai_object_list_t next_hop_list) -{ - sai_status_t status; - - if ((next_hop_group_id >= MAX_NEXT_HOP_GROUP_NUMBER) || - (!next_hop_group_db[next_hop_group_id].is_valid)) { - STUB_LOG_ERR("Invalid next hop group ID %u\n", next_hop_group_id); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (next_hop_list.count > ECMP_MAX_PATHS) { - STUB_LOG_ERR("Next hop count %u bigger than maximum %u\n", next_hop_list.count, ECMP_MAX_PATHS); - return SAI_STATUS_INVALID_ATTR_VALUE_0; - } - - if (SAI_STATUS_SUCCESS != - (status = validate_next_hop_list(next_hop_list.count, next_hop_list.list, 0))) { - return status; - } - - next_hop_group_db[next_hop_group_id].next_hop_count = next_hop_list.count; - memcpy(next_hop_group_db[next_hop_group_id].next_hop_list, - next_hop_list.list, - sizeof(sai_object_id_t) * next_hop_list.count); - - return SAI_STATUS_SUCCESS; -} - -sai_status_t db_add_members_next_hop_group_list(_In_ uint32_t next_hop_group_id, - _In_ uint32_t next_hop_count, - _In_ const sai_object_id_t* nexthops) -{ - stub_next_hop_group_t *group; - sai_status_t status; - - if ((next_hop_group_id >= MAX_NEXT_HOP_GROUP_NUMBER) || - (!next_hop_group_db[next_hop_group_id].is_valid)) { - STUB_LOG_ERR("Invalid next hop group ID %u\n", next_hop_group_id); - return SAI_STATUS_INVALID_PARAMETER; - } - - group = &next_hop_group_db[next_hop_group_id]; - - if (next_hop_count + group->next_hop_count > ECMP_MAX_PATHS) { - STUB_LOG_ERR("Next hop count %u bigger than maximum %u\n", - next_hop_count + group->next_hop_count, ECMP_MAX_PATHS); - return SAI_STATUS_INVALID_ATTR_VALUE_0; - } - - if (SAI_STATUS_SUCCESS != - (status = validate_next_hop_list(next_hop_count, nexthops, 0))) { - return status; - } - - memcpy(&group->next_hop_list[group->next_hop_count], - nexthops, - sizeof(sai_object_id_t) * next_hop_count); - group->next_hop_count += next_hop_count; - - return SAI_STATUS_SUCCESS; -} - -bool next_hop_in_list(sai_object_id_t nexthop, _In_ uint32_t next_hop_count, _In_ const sai_object_id_t* nexthops) -{ - uint32_t ii; - - for (ii = 0; ii < next_hop_count; ii++) { - if (nexthop == nexthops[ii]) { - return true; - } - } - - return false; -} - -sai_status_t db_remove_members_next_hop_group_list(_In_ uint32_t next_hop_group_id, - _In_ uint32_t next_hop_count, - _In_ const sai_object_id_t* nexthops) -{ - stub_next_hop_group_t *group; - uint32_t ii = 0; - - if ((next_hop_group_id >= MAX_NEXT_HOP_GROUP_NUMBER) || - (!next_hop_group_db[next_hop_group_id].is_valid)) { - STUB_LOG_ERR("Invalid next hop group ID %u\n", next_hop_group_id); - return SAI_STATUS_INVALID_PARAMETER; - } - - group = &next_hop_group_db[next_hop_group_id]; - - while (ii < group->next_hop_count) { - if (next_hop_in_list(group->next_hop_list[ii], next_hop_count, nexthops)) { - group->next_hop_count--; - group->next_hop_list[ii] = group->next_hop_list[group->next_hop_count]; - continue; - } - ii++; - } - - return SAI_STATUS_SUCCESS; -} - -/*************************/ - -static void next_hop_group_key_to_str(_In_ sai_object_id_t next_hop_group_id, _Out_ char *key_str) -{ - uint32_t groupid; - - if (SAI_STATUS_SUCCESS != stub_object_to_type(next_hop_group_id, SAI_OBJECT_TYPE_NEXT_HOP_GROUP, &groupid)) { - snprintf(key_str, MAX_KEY_STR_LEN, "invalid next hop group id"); - } else { - snprintf(key_str, MAX_KEY_STR_LEN, "next hop group id %u", groupid); - } -} - -/* - * Routine Description: - * Create next hop group - * - * Arguments: - * [out] next_hop_group_id - next hop group id - * [in] attr_count - number of attributes - * [in] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_create_next_hop_group(_Out_ sai_object_id_t * next_hop_group_id, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) -{ - sai_status_t status; - const sai_attribute_value_t *type, *hop_list; - uint32_t type_index, hop_list_index, group_id = 0; - char list_str[MAX_LIST_VALUE_STR_LEN]; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == next_hop_group_id) { - STUB_LOG_ERR("NULL next hop group id param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_STATUS_SUCCESS != - (status = - check_attribs_metadata(attr_count, attr_list, next_hop_group_attribs, next_hop_group_vendor_attribs, - SAI_OPERATION_CREATE))) { - STUB_LOG_ERR("Failed attribs check\n"); - return status; - } - - sai_attr_list_to_str(attr_count, attr_list, next_hop_group_attribs, MAX_LIST_VALUE_STR_LEN, list_str); - STUB_LOG_NTC("Create next hop group, %s\n", list_str); - - assert(SAI_STATUS_SUCCESS == - find_attrib_in_list(attr_count, attr_list, SAI_NEXT_HOP_GROUP_ATTR_TYPE, &type, &type_index)); - assert(SAI_STATUS_SUCCESS == - find_attrib_in_list(attr_count, - attr_list, - SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_LIST, - &hop_list, - &hop_list_index)); - - if (SAI_NEXT_HOP_GROUP_ECMP != type->s32) { - STUB_LOG_ERR("Invalid next hop group type %d on create\n", type->s32); - return SAI_STATUS_INVALID_ATTR_VALUE_0 + type_index; - } - - if (SAI_STATUS_SUCCESS != - (status = db_create_next_hop_group(&group_id, &(hop_list->objlist), hop_list_index))) { - return status; - } - - if (SAI_STATUS_SUCCESS != - (status = stub_create_object(SAI_OBJECT_TYPE_NEXT_HOP_GROUP, group_id, next_hop_group_id))) { - return status; - } - next_hop_group_key_to_str(*next_hop_group_id, key_str); - STUB_LOG_NTC("Created next hop group %s\n", key_str); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Remove next hop group - * - * Arguments: - * [in] next_hop_group_id - next hop group id - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_next_hop_group(_In_ sai_object_id_t next_hop_group_id) -{ - char key_str[MAX_KEY_STR_LEN]; - sai_status_t status; - uint32_t group_id; - - STUB_LOG_ENTER(); - - next_hop_group_key_to_str(next_hop_group_id, key_str); - STUB_LOG_NTC("Remove next hop group %s\n", key_str); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(next_hop_group_id, SAI_OBJECT_TYPE_NEXT_HOP_GROUP, &group_id))) { - return status; - } - - if (SAI_STATUS_SUCCESS != - (status = db_remove_next_hop_group(group_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Set Next Hop Group attribute - * - * Arguments: - * [in] sai_next_hop_group_id_t - next_hop_group_id - * [in] attr - attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_next_hop_group_attribute(_In_ sai_object_id_t next_hop_group_id, - _In_ const sai_attribute_t *attr) -{ - const sai_object_key_t key = { .object_id = next_hop_group_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - next_hop_group_key_to_str(next_hop_group_id, key_str); - return sai_set_attribute(&key, key_str, next_hop_group_attribs, next_hop_group_vendor_attribs, attr); -} - -/* - * Routine Description: - * Get Next Hop Group attribute - * - * Arguments: - * [in] sai_next_hop_group_id_t - next_hop_group_id - * [in] attr_count - number of attributes - * [inout] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_next_hop_group_attribute(_In_ sai_object_id_t next_hop_group_id, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - const sai_object_key_t key = { .object_id = next_hop_group_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - next_hop_group_key_to_str(next_hop_group_id, key_str); - return sai_get_attributes(&key, - key_str, - next_hop_group_attribs, - next_hop_group_vendor_attribs, - attr_count, - attr_list); -} - -/* Next hop group type [sai_next_hop_group_type_t] */ -sai_status_t stub_next_hop_group_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = SAI_NEXT_HOP_GROUP_ECMP; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Number of next hops in the group [uint32_t] */ -sai_status_t stub_next_hop_group_count_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t group_id; - sai_object_list_t hop_list; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_NEXT_HOP_GROUP, &group_id))) { - return status; - } - - if (SAI_STATUS_SUCCESS != - (status = db_get_next_hop_group(group_id, &hop_list))) { - return status; - } - - value->u32 = hop_list.count; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Next hop list [sai_object_list_t] */ -sai_status_t stub_next_hop_group_hop_list_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t group_id; - sai_object_list_t hop_list; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_NEXT_HOP_GROUP, &group_id))) { - return status; - } - - if (SAI_STATUS_SUCCESS != - (status = db_get_next_hop_group(group_id, &hop_list))) { - return status; - } - - if (SAI_STATUS_SUCCESS != (status = stub_fill_objlist(hop_list.list, hop_list.count, &value->objlist))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Next hop list [sai_object_list_t] */ -sai_status_t stub_next_hop_group_hop_list_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t group_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_NEXT_HOP_GROUP, &group_id))) { - return status; - } - - if (SAI_STATUS_SUCCESS != - (status = db_update_next_hop_group_list(group_id, value->objlist))) { - return status; - } - - /* TODO : update route with next hop list changes */ - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Add next hop to a group - * - * Arguments: - * [in] next_hop_group_id - next hop group id - * [in] next_hop_count - number of next hops - * [in] nexthops - array of next hops - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_add_next_hop_to_group(_In_ sai_object_id_t next_hop_group_id, - _In_ uint32_t next_hop_count, - _In_ const sai_object_id_t* nexthops) -{ - sai_status_t status; - char value[MAX_LIST_VALUE_STR_LEN]; - uint32_t group_id; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == nexthops) { - STUB_LOG_ERR("NULL nexthops param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - next_hop_group_key_to_str(next_hop_group_id, key_str); - sai_nexthops_to_str(next_hop_count, nexthops, MAX_LIST_VALUE_STR_LEN, value); - STUB_LOG_NTC("Add next hops {%s} to %s\n", value, key_str); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(next_hop_group_id, SAI_OBJECT_TYPE_NEXT_HOP_GROUP, &group_id))) { - return status; - } - - if (SAI_STATUS_SUCCESS != - (status = db_add_members_next_hop_group_list(group_id, next_hop_count, nexthops))) { - return status; - } - - /* TODO : update route with next hop list changes */ - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Remove next hop from a group - * - * Arguments: - * [in] next_hop_group_id - next hop group id - * [in] next_hop_count - number of next hops - * [in] nexthops - array of next hops - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_next_hop_from_group(_In_ sai_object_id_t next_hop_group_id, - _In_ uint32_t next_hop_count, - _In_ const sai_object_id_t* nexthops) -{ - sai_status_t status; - char value[MAX_LIST_VALUE_STR_LEN]; - uint32_t group_id; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == nexthops) { - STUB_LOG_ERR("NULL nexthops param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - next_hop_group_key_to_str(next_hop_group_id, key_str); - sai_nexthops_to_str(next_hop_count, nexthops, MAX_LIST_VALUE_STR_LEN, value); - STUB_LOG_NTC("Remove next hops {%s} from %s\n", value, key_str); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(next_hop_group_id, SAI_OBJECT_TYPE_NEXT_HOP_GROUP, &group_id))) { - return status; - } - - if (SAI_STATUS_SUCCESS != - (status = db_remove_members_next_hop_group_list(group_id, next_hop_count, nexthops))) { - return status; - } - - /* TODO : update route with next hop list changes */ - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -const sai_next_hop_group_api_t next_hop_group_api = { - stub_create_next_hop_group, - stub_remove_next_hop_group, - stub_set_next_hop_group_attribute, - stub_get_next_hop_group_attribute, - stub_add_next_hop_to_group, - stub_remove_next_hop_from_group -}; diff --git a/stub/src/stub_sai_port.c b/stub/src/stub_sai_port.c deleted file mode 100644 index c778e1253..000000000 --- a/stub/src/stub_sai_port.c +++ /dev/null @@ -1,1384 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" -#include "assert.h" - -#undef __MODULE__ -#define __MODULE__ SAI_PORT - -sai_status_t stub_port_fdb_violation_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_max_learned_addr_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_storm_control_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_update_dscp_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_state_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_media_type_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_default_vlan_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_default_vlan_prio_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_ingress_filter_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_drop_tags_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_internal_loopback_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_fdb_learning_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_mtu_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_speed_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_autoneg_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_port_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_state_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_max_learned_addr_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_fdb_violation_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_media_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_storm_control_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_update_dscp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_hw_lanes_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_supported_breakout_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_current_breakout_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_speed_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_autoneg_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_default_vlan_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_default_vlan_prio_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_ingress_filter_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_drop_tags_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_internal_loopback_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_fdb_learning_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_port_mtu_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); - -static const sai_attribute_entry_t port_attribs[] = { - { SAI_PORT_ATTR_TYPE, false, false, false, true, - "Port type", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_PORT_ATTR_OPER_STATUS, false, false, false, true, - "Port operational status", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_PORT_ATTR_HW_LANE_LIST, false, false, false, true, - "Port HW lane list", SAI_ATTR_VAL_TYPE_U32LIST }, - { SAI_PORT_ATTR_SUPPORTED_BREAKOUT_MODE, false, false, false, true, - "Port supported breakout modes", SAI_ATTR_VAL_TYPE_S32LIST }, - { SAI_PORT_ATTR_CURRENT_BREAKOUT_MODE, false, false, false, true, - "Port current breakout mode", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_PORT_ATTR_SPEED, false, false, true, true, - "Port speed", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_PORT_ATTR_AUTO_NEG_MODE, false, false, true, true, - "Port autoneg mode", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_PORT_ATTR_ADMIN_STATE, false, false, true, true, - "Port admin state", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_PORT_ATTR_MEDIA_TYPE, false, false, true, true, - "Port media type", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_PORT_ATTR_PORT_VLAN_ID, false, false, true, true, - "Port default vlan", SAI_ATTR_VAL_TYPE_U16 }, - { SAI_PORT_ATTR_DEFAULT_VLAN_PRIORITY, false, false, true, true, - "Port default vlan priority", SAI_ATTR_VAL_TYPE_U8 }, - { SAI_PORT_ATTR_INGRESS_FILTERING, false, false, true, true, - "Port ingress filtering", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_PORT_ATTR_DROP_UNTAGGED, false, false, true, true, - "Port drop untageed", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_PORT_ATTR_DROP_TAGGED, false, false, true, true, - "Port drop tageed", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_PORT_ATTR_INTERNAL_LOOPBACK, false, false, true, true, - "Port internal loopback", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_PORT_ATTR_FDB_LEARNING, false, false, true, true, - "Port fdb learning", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_PORT_ATTR_UPDATE_DSCP, false, false, true, true, - "Port update DSCP", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_PORT_ATTR_MTU, false, false, true, true, - "Port mtu", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_PORT_ATTR_FLOOD_STORM_CONTROL_POLICER_ID, false, false, true, true, - "Port flood storm control", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_PORT_ATTR_BROADCAST_STORM_CONTROL_POLICER_ID, false, false, true, true, - "Port broadcast storm control", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_PORT_ATTR_MULTICAST_STORM_CONTROL_POLICER_ID, false, false, true, true, - "Port multicast storm control", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL, false, false, true, true, - "Port global flow control", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_PORT_ATTR_MAX_LEARNED_ADDRESSES, false, false, true, true, - "Port max learned addresses", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_PORT_ATTR_FDB_LEARNING_LIMIT_VIOLATION, false, false, true, true, - "Port fdb learning limit violation", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_PORT_ATTR_INGRESS_MIRROR_SESSION, false, false, true, true, - "Port ingress mirror session", SAI_ATTR_VAL_TYPE_OBJLIST }, - { SAI_PORT_ATTR_EGRESS_MIRROR_SESSION, false, false, true, true, - "Port egress mirror session", SAI_ATTR_VAL_TYPE_OBJLIST }, - { SAI_PORT_ATTR_INGRESS_SAMPLEPACKET_ENABLE, false, false, true, true, - "Port ingress samplepacket enable", SAI_ATTR_VAL_TYPE_OID }, - { SAI_PORT_ATTR_EGRESS_SAMPLEPACKET_ENABLE, false, false, true, true, - "Port egress samplepacket enable", SAI_ATTR_VAL_TYPE_OID }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED } -}; -static const sai_vendor_attribute_entry_t port_vendor_attribs[] = { - { SAI_PORT_ATTR_TYPE, - { false, false, false, true }, - { false, false, false, true }, - stub_port_type_get, NULL, - NULL, NULL }, - { SAI_PORT_ATTR_OPER_STATUS, - { false, false, false, true }, - { false, false, false, true }, - stub_port_state_get, (void*)SAI_PORT_ATTR_OPER_STATUS, - NULL, NULL }, - { SAI_PORT_ATTR_HW_LANE_LIST, - { false, false, false, true }, - { false, false, false, true }, - stub_port_hw_lanes_get, NULL, - NULL, NULL }, - { SAI_PORT_ATTR_SUPPORTED_BREAKOUT_MODE, - { false, false, false, true }, - { false, false, false, true }, - stub_port_supported_breakout_get, NULL, - NULL, NULL }, - { SAI_PORT_ATTR_CURRENT_BREAKOUT_MODE, - { false, false, false, true }, - { false, false, false, true }, - stub_port_current_breakout_get, NULL, - NULL, NULL }, - { SAI_PORT_ATTR_SPEED, - { false, false, true, true }, - { false, false, true, true }, - stub_port_speed_get, NULL, - stub_port_speed_set, NULL }, - { SAI_PORT_ATTR_AUTO_NEG_MODE, - { false, false, true, true }, - { false, false, true, true }, - stub_port_autoneg_get, NULL, - stub_port_autoneg_set, NULL }, - { SAI_PORT_ATTR_ADMIN_STATE, - { false, false, true, true }, - { false, false, true, true }, - stub_port_state_get, (void*)SAI_PORT_ATTR_ADMIN_STATE, - stub_port_state_set, NULL }, - { SAI_PORT_ATTR_MEDIA_TYPE, - { false, false, true, true }, - { false, false, true, true }, - stub_port_media_type_get, NULL, - stub_port_media_type_set, NULL }, - { SAI_PORT_ATTR_PORT_VLAN_ID, - { false, false, true, true }, - { false, false, true, true }, - stub_port_default_vlan_get, NULL, - stub_port_default_vlan_set, NULL }, - { SAI_PORT_ATTR_DEFAULT_VLAN_PRIORITY, - { false, false, true, true }, - { false, false, true, true }, - stub_port_default_vlan_prio_get, NULL, - stub_port_default_vlan_prio_set, NULL }, - { SAI_PORT_ATTR_INGRESS_FILTERING, - { false, false, true, true }, - { false, false, true, true }, - stub_port_ingress_filter_get, NULL, - stub_port_ingress_filter_set, NULL }, - { SAI_PORT_ATTR_DROP_UNTAGGED, - { false, false, true, true }, - { false, false, true, true }, - stub_port_drop_tags_get, (void*)SAI_PORT_ATTR_DROP_UNTAGGED, - stub_port_drop_tags_set, (void*)SAI_PORT_ATTR_DROP_UNTAGGED }, - { SAI_PORT_ATTR_DROP_TAGGED, - { false, false, true, true }, - { false, false, true, true }, - stub_port_drop_tags_get, (void*)SAI_PORT_ATTR_DROP_TAGGED, - stub_port_drop_tags_set, (void*)SAI_PORT_ATTR_DROP_TAGGED }, - { SAI_PORT_ATTR_INTERNAL_LOOPBACK, - { false, false, true, true }, - { false, false, true, true }, - stub_port_internal_loopback_get, NULL, - stub_port_internal_loopback_set, NULL }, - { SAI_PORT_ATTR_FDB_LEARNING, - { false, false, true, true }, - { false, false, true, true }, - stub_port_fdb_learning_get, NULL, - stub_port_fdb_learning_set, NULL }, - { SAI_PORT_ATTR_UPDATE_DSCP, - { false, false, true, true }, - { false, false, true, true }, - stub_port_update_dscp_get, NULL, - stub_port_update_dscp_set, NULL }, - { SAI_PORT_ATTR_MTU, - { false, false, true, true }, - { false, false, true, true }, - stub_port_mtu_get, NULL, - stub_port_mtu_set, NULL }, - { SAI_PORT_ATTR_FLOOD_STORM_CONTROL_POLICER_ID, - { false, false, true, true }, - { false, false, true, true }, - stub_port_storm_control_get, (void*)SAI_PORT_ATTR_FLOOD_STORM_CONTROL_POLICER_ID, - stub_port_storm_control_set, (void*)SAI_PORT_ATTR_FLOOD_STORM_CONTROL_POLICER_ID }, - { SAI_PORT_ATTR_BROADCAST_STORM_CONTROL_POLICER_ID, - { false, false, true, true }, - { false, false, true, true }, - stub_port_storm_control_get, (void*)SAI_PORT_ATTR_BROADCAST_STORM_CONTROL_POLICER_ID, - stub_port_storm_control_set, (void*)SAI_PORT_ATTR_BROADCAST_STORM_CONTROL_POLICER_ID }, - { SAI_PORT_ATTR_MULTICAST_STORM_CONTROL_POLICER_ID, - { false, false, true, true }, - { false, false, true, true }, - stub_port_storm_control_get, (void*)SAI_PORT_ATTR_MULTICAST_STORM_CONTROL_POLICER_ID, - stub_port_storm_control_set, (void*)SAI_PORT_ATTR_MULTICAST_STORM_CONTROL_POLICER_ID }, - { SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_PORT_ATTR_MAX_LEARNED_ADDRESSES, - { false, false, true, true }, - { false, false, true, true }, - stub_port_max_learned_addr_get, NULL, - stub_port_max_learned_addr_set, NULL }, - { SAI_PORT_ATTR_FDB_LEARNING_LIMIT_VIOLATION, - { false, false, false, false }, - { false, false, true, true }, - stub_port_fdb_violation_get, NULL, - stub_port_fdb_violation_set, NULL }, - { SAI_PORT_ATTR_INGRESS_MIRROR_SESSION, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_PORT_ATTR_EGRESS_MIRROR_SESSION, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_PORT_ATTR_INGRESS_SAMPLEPACKET_ENABLE, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_PORT_ATTR_EGRESS_SAMPLEPACKET_ENABLE, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL } -}; - -/* Admin Mode [bool] */ -sai_status_t stub_port_state_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Update DSCP of outgoing packets [bool] */ -sai_status_t stub_port_update_dscp_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* [bool] (default to FALSE) */ -sai_status_t stub_port_storm_control_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Action for packets with unknown source mac address - * when FDB learning limit is reached. - * [sai_packet_action_t] (default to SAI_PACKET_ACTION_DROP) */ -sai_status_t stub_port_fdb_violation_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Maximum number of learned MAC addresses [uint32_t] */ -sai_status_t stub_port_max_learned_addr_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Media Type [sai_port_media_type_t] */ -sai_status_t stub_port_media_type_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default VLAN [sai_vlan_id_t] - * Untagged ingress frames are tagged with default VLAN - */ -sai_status_t stub_port_default_vlan_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default VLAN Priority [uint8_t] - * (default to 0) */ -sai_status_t stub_port_default_vlan_prio_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Ingress Filtering (Drop Frames with Unknown VLANs) [bool] */ -sai_status_t stub_port_ingress_filter_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Dropping of untagged frames on ingress [bool] */ -/* Dropping of tagged frames on ingress [bool] */ -sai_status_t stub_port_drop_tags_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - assert((SAI_PORT_ATTR_DROP_UNTAGGED == (int64_t)arg) || (SAI_PORT_ATTR_DROP_TAGGED == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Internal loopback control [sai_port_loopback_mode_t] */ -sai_status_t stub_port_internal_loopback_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - switch (value->s32) { - case SAI_PORT_INTERNAL_LOOPBACK_NONE: - break; - - case SAI_PORT_INTERNAL_LOOPBACK_PHY: - break; - - case SAI_PORT_INTERNAL_LOOPBACK_MAC: - break; - - default: - STUB_LOG_ERR("Invalid port internal loopback value %d\n", value->s32); - return SAI_STATUS_INVALID_ATTR_VALUE_0; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* FDB Learning mode [sai_port_fdb_learning_mode_t] */ -sai_status_t stub_port_fdb_learning_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - switch (value->s32) { - case SAI_PORT_LEARN_MODE_DISABLE: - break; - - case SAI_PORT_LEARN_MODE_HW: - break; - - case SAI_PORT_LEARN_MODE_DROP: - case SAI_PORT_LEARN_MODE_CPU_TRAP: - case SAI_PORT_LEARN_MODE_CPU_LOG: - break; - - default: - STUB_LOG_ERR("Invalid port fdb learning mode %d\n", value->s32); - return SAI_STATUS_INVALID_ATTR_VALUE_0; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* MTU [uint32_t] */ -sai_status_t stub_port_mtu_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Speed in Mbps [uint32_t] */ -sai_status_t stub_port_speed_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Autoneg mode [bool] */ -sai_status_t stub_port_autoneg_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Port type [sai_port_type_t] */ -sai_status_t stub_port_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->s32 = SAI_PORT_TYPE_LOGICAL; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Maximum number of learned MAC addresses [uint32_t] */ -sai_status_t stub_port_max_learned_addr_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->u32 = 100000; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Action for packets with unknown source mac address - * when FDB learning limit is reached. - * [sai_packet_action_t] (default to SAI_PACKET_ACTION_DROP) */ -sai_status_t stub_port_fdb_violation_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->s32 = SAI_PACKET_ACTION_DROP; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Media Type [sai_port_media_type_t] */ -sai_status_t stub_port_media_type_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->s32 = SAI_PORT_MEDIA_TYPE_QSFP_COPPER; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Update DSCP of outgoing packets [bool] */ -sai_status_t stub_port_update_dscp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->booldata = false; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* [bool] (default to FALSE) */ -sai_status_t stub_port_storm_control_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->booldata = false; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Operational Status [sai_port_oper_status_t] */ -/* Admin Mode [bool] */ -sai_status_t stub_port_state_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - assert((SAI_PORT_ATTR_OPER_STATUS == (int64_t)arg) || (SAI_PORT_ATTR_ADMIN_STATE == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - if (SAI_PORT_ATTR_OPER_STATUS == (int64_t)arg) { - value->s32 = SAI_PORT_OPER_STATUS_UP; - } else { - value->booldata = true; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Hardware Lane list [sai_u32_list_t] */ -sai_status_t stub_port_hw_lanes_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - uint32_t hw_lane; - - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - hw_lane = port_id; - - status = stub_fill_u32list(&hw_lane, 1, &value->u32list); - - STUB_LOG_EXIT(); - return status; -} - -/* Breakout mode(s) supported [sai_s32_list_t] */ -sai_status_t stub_port_supported_breakout_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Current breakout mode [sai_port_breakout_mode_type_t] */ -sai_status_t stub_port_current_breakout_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->s32 = SAI_PORT_BREAKOUT_MODE_4_LANE; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Speed in Mbps [uint32_t] */ -sai_status_t stub_port_speed_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->u32 = 40000; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Autoneg mode [bool] */ -sai_status_t stub_port_autoneg_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->booldata = false; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default VLAN [sai_vlan_id_t] - * Untagged ingress frames are tagged with default VLAN - */ -sai_status_t stub_port_default_vlan_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->u16 = 1; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default VLAN Priority [uint8_t] - * (default to 0) */ -sai_status_t stub_port_default_vlan_prio_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->u8 = 0; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Ingress Filtering (Drop Frames with Unknown VLANs) [bool] */ -sai_status_t stub_port_ingress_filter_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->booldata = false; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Dropping of untagged frames on ingress [bool] */ -/* Dropping of tagged frames on ingress [bool] */ -sai_status_t stub_port_drop_tags_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - assert((SAI_PORT_ATTR_DROP_UNTAGGED == (int64_t)arg) || (SAI_PORT_ATTR_DROP_TAGGED == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->booldata = false; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Internal loopback control [sai_port_internal_loopback_mode_t] */ -sai_status_t stub_port_internal_loopback_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->s32 = SAI_PORT_INTERNAL_LOOPBACK_NONE; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* FDB Learning mode [sai_port_fdb_learning_mode_t] */ -sai_status_t stub_port_fdb_learning_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->s32 = SAI_PORT_LEARN_MODE_HW; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* MTU [uint32_t] */ -sai_status_t stub_port_mtu_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t port_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &port_id))) { - return status; - } - - value->u32 = 1514; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -static void port_key_to_str(_In_ sai_object_id_t port_id, _Out_ char *key_str) -{ - uint32_t port; - - if (SAI_STATUS_SUCCESS != stub_object_to_type(port_id, SAI_OBJECT_TYPE_PORT, &port)) { - snprintf(key_str, MAX_KEY_STR_LEN, "invalid port"); - } else { - snprintf(key_str, MAX_KEY_STR_LEN, "port %x", port); - } -} - -/* - * Routine Description: - * Set port attribute value. - * - * Arguments: - * [in] port_id - port id - * [in] attr - attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_port_attribute(_In_ sai_object_id_t port_id, _In_ const sai_attribute_t *attr) -{ - const sai_object_key_t key = { .object_id = port_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - port_key_to_str(port_id, key_str); - return sai_set_attribute(&key, key_str, port_attribs, port_vendor_attribs, attr); -} - - -/* - * Routine Description: - * Get port attribute value. - * - * Arguments: - * [in] port_id - port id - * [in] attr_count - number of attributes - * [inout] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_port_attribute(_In_ sai_object_id_t port_id, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - const sai_object_key_t key = { .object_id = port_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - port_key_to_str(port_id, key_str); - return sai_get_attributes(&key, key_str, port_attribs, port_vendor_attribs, attr_count, attr_list); -} - -/* - * Routine Description: - * Get port statistics counters. - * - * Arguments: - * [in] port_id - port id - * [in] counter_ids - specifies the array of counter ids - * [in] number_of_counters - number of counters in the array - * [out] counters - array of resulting counter values. - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_port_stats(_In_ sai_object_id_t port_id, - _In_ const sai_port_stat_counter_t *counter_ids, - _In_ uint32_t number_of_counters, - _Out_ uint64_t *counters) -{ - sai_status_t status; - uint32_t ii, port_data; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - port_key_to_str(port_id, key_str); - STUB_LOG_NTC("Get port stats %s\n", key_str); - - if (NULL == counter_ids) { - STUB_LOG_ERR("NULL counter ids array param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == counters) { - STUB_LOG_ERR("NULL counters array param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(port_id, SAI_OBJECT_TYPE_PORT, &port_data))) { - return status; - } - - for (ii = 0; ii < number_of_counters; ii++) { - switch (counter_ids[ii]) { - case SAI_PORT_STAT_IF_IN_OCTETS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_IN_UCAST_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_IN_DISCARDS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_IN_ERRORS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_IN_BROADCAST_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_IN_MULTICAST_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_OUT_OCTETS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_OUT_UCAST_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_OUT_DISCARDS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_OUT_ERRORS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_OUT_BROADCAST_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_OUT_MULTICAST_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_MULTICAST_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_UNDERSIZE_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_FRAGMENTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_PKTS_64_OCTETS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_PKTS_65_TO_127_OCTETS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_PKTS_128_TO_255_OCTETS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_PKTS_256_TO_511_OCTETS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_PKTS_512_TO_1023_OCTETS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_PKTS_1024_TO_1518_OCTETS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_JABBERS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_OCTETS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_PKTS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_COLLISIONS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_ETHER_STATS_CRC_ALIGN_ERRORS: - counters[ii] = 0; - break; - - case SAI_PORT_STAT_IF_IN_VLAN_DISCARDS: - case SAI_PORT_STAT_IF_OUT_QLEN: - case SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS: - case SAI_PORT_STAT_ETHER_TX_OVERSIZE_PKTS: - case SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS: - case SAI_PORT_STAT_ETHER_STATS_RX_NO_ERRORS: - case SAI_PORT_STAT_IP_IN_RECEIVES: - case SAI_PORT_STAT_IP_IN_OCTETS: - case SAI_PORT_STAT_IP_IN_UCAST_PKTS: - case SAI_PORT_STAT_IP_IN_NON_UCAST_PKTS: - case SAI_PORT_STAT_IP_IN_DISCARDS: - case SAI_PORT_STAT_IP_OUT_OCTETS: - case SAI_PORT_STAT_IP_OUT_UCAST_PKTS: - case SAI_PORT_STAT_IP_OUT_NON_UCAST_PKTS: - case SAI_PORT_STAT_IP_OUT_DISCARDS: - case SAI_PORT_STAT_IPV6_IN_RECEIVES: - case SAI_PORT_STAT_IPV6_IN_OCTETS: - case SAI_PORT_STAT_IPV6_IN_UCAST_PKTS: - case SAI_PORT_STAT_IPV6_IN_NON_UCAST_PKTS: - case SAI_PORT_STAT_IPV6_IN_MCAST_PKTS: - case SAI_PORT_STAT_IPV6_IN_DISCARDS: - case SAI_PORT_STAT_IPV6_OUT_OCTETS: - case SAI_PORT_STAT_IPV6_OUT_UCAST_PKTS: - case SAI_PORT_STAT_IPV6_OUT_NON_UCAST_PKTS: - case SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS: - case SAI_PORT_STAT_IPV6_OUT_DISCARDS: - counters[ii] = 0; - break; - - default: - STUB_LOG_ERR("Invalid port counter %d\n", counter_ids[ii]); - return SAI_STATUS_INVALID_PARAMETER; - } - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -const sai_port_api_t port_api = { - stub_set_port_attribute, - stub_get_port_attribute, - stub_get_port_stats, - NULL, - NULL -}; diff --git a/stub/src/stub_sai_rif.c b/stub/src/stub_sai_rif.c deleted file mode 100644 index 5c11bbac2..000000000 --- a/stub/src/stub_sai_rif.c +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" -#include "assert.h" - -#undef __MODULE__ -#define __MODULE__ SAI_RIF - -static const sai_attribute_entry_t rif_attribs[] = { - { SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID, true, true, false, true, - "Router interface virtual router ID", SAI_ATTR_VAL_TYPE_OID }, - { SAI_ROUTER_INTERFACE_ATTR_TYPE, true, true, false, true, - "Router interface type", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_ROUTER_INTERFACE_ATTR_PORT_ID, false, true, false, true, - "Router interface port ID", SAI_ATTR_VAL_TYPE_OID }, - { SAI_ROUTER_INTERFACE_ATTR_VLAN_ID, false, true, false, true, - "Router interface vlan ID", SAI_ATTR_VAL_TYPE_U16 }, - { SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS, false, true, true, true, - "Router interface source MAC address", SAI_ATTR_VAL_TYPE_MAC }, - { SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE, false, true, true, true, - "Router interface admin v4 state", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE, false, true, true, true, - "Router interface admin v6 state", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_ROUTER_INTERFACE_ATTR_MTU, false, true, true, true, - "Router interface mtu", SAI_ATTR_VAL_TYPE_U32 }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED } -}; - -sai_status_t stub_rif_attrib_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_rif_admin_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_rif_attrib_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_rif_admin_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); - -static const sai_vendor_attribute_entry_t rif_vendor_attribs[] = { - { SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID, - { true, false, false, true }, - { true, false, false, true }, - stub_rif_attrib_get, (void*)SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID, - NULL, NULL }, - { SAI_ROUTER_INTERFACE_ATTR_TYPE, - { true, false, false, true }, - { true, false, false, true }, - stub_rif_attrib_get, (void*)SAI_ROUTER_INTERFACE_ATTR_TYPE, - NULL, NULL }, - { SAI_ROUTER_INTERFACE_ATTR_PORT_ID, - { true, false, false, true }, - { true, false, false, true }, - stub_rif_attrib_get, (void*)SAI_ROUTER_INTERFACE_ATTR_PORT_ID, - NULL, NULL }, - { SAI_ROUTER_INTERFACE_ATTR_VLAN_ID, - { true, false, false, true }, - { true, false, false, true }, - stub_rif_attrib_get, (void*)SAI_ROUTER_INTERFACE_ATTR_VLAN_ID, - NULL, NULL }, - { SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS, - { true, false, true, true }, - { true, false, true, true }, - stub_rif_attrib_get, (void*)SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS, - stub_rif_attrib_set, (void*)SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS }, - { SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE, - { true, false, true, true }, - { true, false, true, true }, - stub_rif_admin_get, (void*)SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE, - stub_rif_admin_set, (void*)SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE }, - { SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE, - { true, false, true, true }, - { true, false, true, true }, - stub_rif_admin_get, (void*)SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE, - stub_rif_admin_set, (void*)SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE }, - { SAI_ROUTER_INTERFACE_ATTR_MTU, - { true, false, true, true }, - { true, false, true, true }, - stub_rif_attrib_get, (void*)SAI_ROUTER_INTERFACE_ATTR_MTU, - stub_rif_attrib_set, (void*)SAI_ROUTER_INTERFACE_ATTR_MTU } -}; -static void rif_key_to_str(_In_ sai_object_id_t rif_id, _Out_ char *key_str) -{ - uint32_t rifid; - - if (SAI_STATUS_SUCCESS != stub_object_to_type(rif_id, SAI_OBJECT_TYPE_ROUTER_INTERFACE, &rifid)) { - snprintf(key_str, MAX_KEY_STR_LEN, "invalid rif"); - } else { - snprintf(key_str, MAX_KEY_STR_LEN, "rif %u", rifid); - } -} - -/* - * Routine Description: - * Create router interface. - * - * Arguments: - * [out] rif_id - router interface id - * [in] attr_count - number of attributes - * [in] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_create_router_interface(_Out_ sai_object_id_t* rif_id, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) -{ - sai_status_t status; - const sai_attribute_value_t *type, *vrid, *port, *vlan; - uint32_t type_index, vrid_index, port_index, vlan_index, vrid_data, port_data; - char list_str[MAX_LIST_VALUE_STR_LEN]; - char key_str[MAX_KEY_STR_LEN]; - static uint32_t next_id = 0; - - STUB_LOG_ENTER(); - - if (NULL == rif_id) { - STUB_LOG_ERR("NULL rif id param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_STATUS_SUCCESS != - (status = - check_attribs_metadata(attr_count, attr_list, rif_attribs, rif_vendor_attribs, SAI_OPERATION_CREATE))) { - STUB_LOG_ERR("Failed attribs check\n"); - return status; - } - - sai_attr_list_to_str(attr_count, attr_list, rif_attribs, MAX_LIST_VALUE_STR_LEN, list_str); - STUB_LOG_NTC("Create rif, %s\n", list_str); - - assert(SAI_STATUS_SUCCESS == - find_attrib_in_list(attr_count, attr_list, SAI_ROUTER_INTERFACE_ATTR_TYPE, &type, &type_index)); - assert(SAI_STATUS_SUCCESS == - find_attrib_in_list(attr_count, attr_list, SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID, &vrid, - &vrid_index)); - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(vrid->oid, SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &vrid_data))) { - return status; - } - - if (SAI_ROUTER_INTERFACE_TYPE_VLAN == type->s32) { - if (SAI_STATUS_SUCCESS != - (status = - find_attrib_in_list(attr_count, attr_list, SAI_ROUTER_INTERFACE_ATTR_VLAN_ID, &vlan, &vlan_index))) { - STUB_LOG_ERR("Missing mandatory attribute vlan id on create\n"); - return SAI_STATUS_MANDATORY_ATTRIBUTE_MISSING; - } - if (SAI_STATUS_ITEM_NOT_FOUND != - (status = - find_attrib_in_list(attr_count, attr_list, SAI_ROUTER_INTERFACE_ATTR_PORT_ID, &port, &port_index))) { - STUB_LOG_ERR("Invalid attribute port id for rif vlan on create\n"); - return SAI_STATUS_INVALID_ATTRIBUTE_0 + port_index; - } - } else if (SAI_ROUTER_INTERFACE_TYPE_PORT == type->s32) { - if (SAI_STATUS_SUCCESS != - (status = - find_attrib_in_list(attr_count, attr_list, SAI_ROUTER_INTERFACE_ATTR_PORT_ID, &port, &port_index))) { - STUB_LOG_ERR("Missing mandatory attribute port id on create\n"); - return SAI_STATUS_MANDATORY_ATTRIBUTE_MISSING; - } - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(port->oid, SAI_OBJECT_TYPE_PORT, &port_data))) { - return status; - } - if (SAI_STATUS_ITEM_NOT_FOUND != - (status = - find_attrib_in_list(attr_count, attr_list, SAI_ROUTER_INTERFACE_ATTR_VLAN_ID, &vlan, &vlan_index))) { - STUB_LOG_ERR("Invalid attribute vlan id for rif port on create\n"); - return SAI_STATUS_INVALID_ATTRIBUTE_0 + vlan_index; - } - } else { - STUB_LOG_ERR("Invalid router interface type %d\n", type->s32); - return SAI_STATUS_INVALID_ATTR_VALUE_0 + type_index; - } - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_ROUTER_INTERFACE, next_id++, rif_id))) { - return status; - } - rif_key_to_str(*rif_id, key_str); - STUB_LOG_NTC("Created rif %s\n", key_str); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Remove router interface - * - * Arguments: - * [in] rif_id - router interface id - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_router_interface(_In_ sai_object_id_t rif_id) -{ - sai_status_t status; - uint32_t data; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - rif_key_to_str(rif_id, key_str); - STUB_LOG_NTC("Remove rif %s\n", key_str); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(rif_id, SAI_OBJECT_TYPE_ROUTER_INTERFACE, &data))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Set router interface attribute - * - * Arguments: - * [in] rif_id - router interface id - * [in] attr - attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_router_interface_attribute(_In_ sai_object_id_t rif_id, _In_ const sai_attribute_t *attr) -{ - const sai_object_key_t key = { .object_id = rif_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - rif_key_to_str(rif_id, key_str); - return sai_set_attribute(&key, key_str, rif_attribs, rif_vendor_attribs, attr); -} - -/* - * Routine Description: - * Get router interface attribute - * - * Arguments: - * [in] rif_id - router interface id - * [in] attr_count - number of attributes - * [inout] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_router_interface_attribute(_In_ sai_object_id_t rif_id, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - const sai_object_key_t key = { .object_id = rif_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - rif_key_to_str(rif_id, key_str); - return sai_get_attributes(&key, key_str, rif_attribs, rif_vendor_attribs, attr_count, attr_list); -} - -/* MAC Address [sai_mac_t] */ -/* MTU [uint32_t] */ -sai_status_t stub_rif_attrib_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - uint32_t data; - sai_status_t status; - - STUB_LOG_ENTER(); - - assert((SAI_ROUTER_INTERFACE_ATTR_MTU == (int64_t)arg) || - (SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_ROUTER_INTERFACE, &data))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Admin State V4, V6 [bool] */ -sai_status_t stub_rif_admin_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - sai_status_t status; - uint32_t data; - - STUB_LOG_ENTER(); - - assert((SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE == (int64_t)arg) || - (SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_ROUTER_INTERFACE, &data))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Virtual router id [sai_object_id_t] */ -/* Type [sai_router_interface_type_t] */ -/* Assosiated Port or Lag object id [sai_object_id_t] */ -/* Assosiated Vlan [sai_vlan_id_t] */ -/* MAC Address [sai_mac_t] */ -/* MTU [uint32_t] */ -sai_status_t stub_rif_attrib_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t data; - - STUB_LOG_ENTER(); - - assert((SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID == (int64_t)arg) || - (SAI_ROUTER_INTERFACE_ATTR_TYPE == (int64_t)arg) || - (SAI_ROUTER_INTERFACE_ATTR_PORT_ID == (int64_t)arg) || (SAI_ROUTER_INTERFACE_ATTR_VLAN_ID == (int64_t)arg) || - (SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS == (int64_t)arg) || - (SAI_ROUTER_INTERFACE_ATTR_MTU == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_ROUTER_INTERFACE, &data))) { - return status; - } - - switch ((int64_t)arg) { - case SAI_ROUTER_INTERFACE_ATTR_PORT_ID: - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_PORT, 0, &value->oid))) { - return status; - } - break; - - case SAI_ROUTER_INTERFACE_ATTR_VLAN_ID: - value->u16 = 1; - break; - - case SAI_ROUTER_INTERFACE_ATTR_MTU: - value->u32 = 1514; - break; - - case SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS: - break; - - case SAI_ROUTER_INTERFACE_ATTR_TYPE: - value->s32 = SAI_ROUTER_INTERFACE_TYPE_PORT; - break; - - case SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID: - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_VIRTUAL_ROUTER, - 0, &value->oid))) { - return status; - } - break; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Admin State V4, V6 [bool] */ -sai_status_t stub_rif_admin_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t data; - - STUB_LOG_ENTER(); - - assert((SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE == (int64_t)arg) || - (SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_ROUTER_INTERFACE, &data))) { - return status; - } - - value->booldata = true; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -const sai_router_interface_api_t router_interface_api = { - stub_create_router_interface, - stub_remove_router_interface, - stub_set_router_interface_attribute, - stub_get_router_interface_attribute, -}; diff --git a/stub/src/stub_sai_route.c b/stub/src/stub_sai_route.c deleted file mode 100644 index cccd52011..000000000 --- a/stub/src/stub_sai_route.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" - -#undef __MODULE__ -#define __MODULE__ SAI_ROUTE - -static const sai_attribute_entry_t route_attribs[] = { - { SAI_ROUTE_ATTR_PACKET_ACTION, false, true, true, true, - "Route packet action", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_ROUTE_ATTR_TRAP_PRIORITY, false, true, true, true, - "Route trap priority", SAI_ATTR_VAL_TYPE_U8 }, - { SAI_ROUTE_ATTR_NEXT_HOP_ID, false, true, true, true, - "Route next hop ID", SAI_ATTR_VAL_TYPE_OID }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED } -}; - -sai_status_t stub_route_packet_action_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_route_trap_priority_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_route_next_hop_id_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_route_packet_action_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_route_trap_priority_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_route_next_hop_id_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); - -static const sai_vendor_attribute_entry_t route_vendor_attribs[] = { - { SAI_ROUTE_ATTR_PACKET_ACTION, - { true, false, true, true }, - { true, false, true, true }, - stub_route_packet_action_get, NULL, - stub_route_packet_action_set, NULL }, - { SAI_ROUTE_ATTR_TRAP_PRIORITY, - { true, false, true, true }, - { true, false, true, true }, - stub_route_trap_priority_get, NULL, - stub_route_trap_priority_set, NULL }, - { SAI_ROUTE_ATTR_NEXT_HOP_ID, - { true, false, true, true }, - { true, false, true, true }, - stub_route_next_hop_id_get, NULL, - stub_route_next_hop_id_set, NULL }, -}; -static void route_key_to_str(_In_ const sai_unicast_route_entry_t* unicast_route_entry, _Out_ char *key_str) -{ - int res; - - res = snprintf(key_str, MAX_KEY_STR_LEN, "route "); - sai_ipprefix_to_str(unicast_route_entry->destination, MAX_KEY_STR_LEN - res, key_str + res); -} - -/* - * Routine Description: - * Create Route - * - * Arguments: - * [in] unicast_route_entry - route entry - * [in] attr_count - number of attributes - * [in] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - * - * Note: IP prefix/mask expected in Network Byte Order. - * - */ -sai_status_t stub_create_route(_In_ const sai_unicast_route_entry_t* unicast_route_entry, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) -{ - sai_status_t status; - char list_str[MAX_LIST_VALUE_STR_LEN]; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == unicast_route_entry) { - STUB_LOG_ERR("NULL unicast_route_entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_STATUS_SUCCESS != - (status = - check_attribs_metadata(attr_count, attr_list, route_attribs, route_vendor_attribs, - SAI_OPERATION_CREATE))) { - STUB_LOG_ERR("Failed attribs check\n"); - return status; - } - - route_key_to_str(unicast_route_entry, key_str); - sai_attr_list_to_str(attr_count, attr_list, route_attribs, MAX_LIST_VALUE_STR_LEN, list_str); - STUB_LOG_NTC("Create route %s\n", key_str); - STUB_LOG_NTC("Attribs %s\n", list_str); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Remove Route - * - * Arguments: - * [in] unicast_route_entry - route entry - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - * - * Note: IP prefix/mask expected in Network Byte Order. - */ -sai_status_t stub_remove_route(_In_ const sai_unicast_route_entry_t* unicast_route_entry) -{ - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == unicast_route_entry) { - STUB_LOG_ERR("NULL unicast_route_entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - route_key_to_str(unicast_route_entry, key_str); - STUB_LOG_NTC("Remove route %s\n", key_str); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Set route attribute value - * - * Arguments: - * [in] unicast_route_entry - route entry - * [in] attr - attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_route_attribute(_In_ const sai_unicast_route_entry_t* unicast_route_entry, - _In_ const sai_attribute_t *attr) -{ - const sai_object_key_t key = { .unicast_route_entry = unicast_route_entry }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == unicast_route_entry) { - STUB_LOG_ERR("NULL unicast_route_entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - route_key_to_str(unicast_route_entry, key_str); - return sai_set_attribute(&key, key_str, route_attribs, route_vendor_attribs, attr); -} - -/* - * Routine Description: - * Get route attribute value - * - * Arguments: - * [in] unicast_route_entry - route entry - * [in] attr_count - number of attributes - * [inout] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_route_attribute(_In_ const sai_unicast_route_entry_t* unicast_route_entry, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - const sai_object_key_t key = { .unicast_route_entry = unicast_route_entry }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == unicast_route_entry) { - STUB_LOG_ERR("NULL unicast_route_entry param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - route_key_to_str(unicast_route_entry, key_str); - return sai_get_attributes(&key, key_str, route_attribs, route_vendor_attribs, attr_count, attr_list); -} - -/* Packet action [sai_packet_action_t] */ -sai_status_t stub_route_packet_action_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = SAI_PACKET_ACTION_DROP; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Packet priority for trap/log actions [uint8_t] */ -sai_status_t stub_route_trap_priority_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->u8 = 0; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Next hop or next hop group id for the packet [sai_object_id_t] - * The next hop id can be a generic next hop object, such as next hop, - * next hop group. */ -sai_status_t stub_route_next_hop_id_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_NEXT_HOP, 0, &value->oid))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Packet action [sai_packet_action_t] */ -sai_status_t stub_route_packet_action_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Packet priority for trap/log actions [uint8_t] */ -sai_status_t stub_route_trap_priority_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Next hop or next hop group id for the packet [sai_object_id_t] - * The next hop id can be a generic next hop object, such as next hop, - * next hop group. */ -sai_status_t stub_route_next_hop_id_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -const sai_route_api_t route_api = { - stub_create_route, - stub_remove_route, - stub_set_route_attribute, - stub_get_route_attribute, -}; diff --git a/stub/src/stub_sai_router.c b/stub/src/stub_sai_router.c deleted file mode 100644 index 67387c158..000000000 --- a/stub/src/stub_sai_router.c +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" -#include "assert.h" - -#undef __MODULE__ -#define __MODULE__ SAI_ROUTER - -static const sai_attribute_entry_t router_attribs[] = { - { SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE, false, true, true, true, - "Router admin V4 state", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE, false, true, true, true, - "Router admin V6 state", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS, false, true, true, true, - "Router source MAC address", SAI_ATTR_VAL_TYPE_MAC }, - { SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_ACTION, false, true, true, true, - "Router action for TTL0/1", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS, false, true, true, true, - "Router action for IP options", SAI_ATTR_VAL_TYPE_S32 }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED } -}; - -sai_status_t stub_router_admin_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_router_admin_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_router_mac_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_router_mac_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_router_violation_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_router_violation_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); - -static const sai_vendor_attribute_entry_t router_vendor_attribs[] = { - { SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE, - { true, false, true, true }, - { true, false, true, true }, - stub_router_admin_get, (void*)SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE, - stub_router_admin_set, (void*)SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE }, - { SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE, - { true, false, true, true }, - { true, false, true, true }, - stub_router_admin_get, (void*)SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE, - stub_router_admin_set, (void*)SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE }, - { SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS, - { false, false, true, true }, - { false, false, true, true }, - stub_router_mac_get, NULL, - stub_router_mac_set, NULL }, - { SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_ACTION, - { false, false, true, true }, - { false, false, true, true }, - stub_router_violation_get, (void*)SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_ACTION, - stub_router_violation_set, (void*)SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_ACTION }, - { SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS, - { false, false, true, true }, - { false, false, true, true }, - stub_router_violation_get, (void*)SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS, - stub_router_violation_set, (void*)SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS } -}; -static void router_key_to_str(_In_ sai_object_id_t vr_id, _Out_ char *key_str) -{ - uint32_t vrid; - - if (SAI_STATUS_SUCCESS != stub_object_to_type(vr_id, SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &vrid)) { - snprintf(key_str, MAX_KEY_STR_LEN, "Invalid vr ID"); - } else { - snprintf(key_str, MAX_KEY_STR_LEN, "vr ID %u", vrid); - } -} - -/* - * Routine Description: - * Set virtual router attribute Value - * - * Arguments: - * [in] vr_id - virtual router id - * [in] attr - attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_virtual_router_attribute(_In_ sai_object_id_t vr_id, _In_ const sai_attribute_t *attr) -{ - const sai_object_key_t key = { .object_id = vr_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - router_key_to_str(vr_id, key_str); - return sai_set_attribute(&key, key_str, router_attribs, router_vendor_attribs, attr); -} - -/* - * Routine Description: - * Get virtual router attribute Value - * - * Arguments: - * [in] vr_id - virtual router id - * [in] attr_count - number of attributes - * [in] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_virtual_router_attribute(_In_ sai_object_id_t vr_id, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - const sai_object_key_t key = { .object_id = vr_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - router_key_to_str(vr_id, key_str); - return sai_get_attributes(&key, key_str, router_attribs, router_vendor_attribs, attr_count, attr_list); -} - -/* Admin V4, V6 State [bool] */ -sai_status_t stub_router_admin_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t router_id; - - STUB_LOG_ENTER(); - - assert((SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE == (int64_t)arg) || - (SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &router_id))) { - return status; - } - - value->booldata = true; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Admin V4, V6 State [bool] */ -sai_status_t stub_router_admin_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t router_id; - - STUB_LOG_ENTER(); - - assert((SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE == (int64_t)arg) || - (SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &router_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* MAC Address [sai_mac_t] */ -sai_status_t stub_router_mac_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t router_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &router_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* MAC Address [sai_mac_t] */ -sai_status_t stub_router_mac_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - sai_status_t status; - uint32_t router_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &router_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Action for Packets with TTL 0 or 1 [sai_packet_action_t] - * Action for Packets with IP options [sai_packet_action_t] - * (default to SAI_PACKET_ACTION_TRAP) */ -sai_status_t stub_router_violation_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - uint32_t router_id; - - STUB_LOG_ENTER(); - - assert((SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS == (int64_t)arg) || - (SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_ACTION == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &router_id))) { - return status; - } - - value->s32 = SAI_PACKET_ACTION_TRAP; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Action for Packets with TTL 0 or 1 [sai_packet_action_t] - * Action for Packets with IP options [sai_packet_action_t] - * (default to SAI_PACKET_ACTION_TRAP) */ -sai_status_t stub_router_violation_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - sai_status_t status; - uint32_t router_id; - - STUB_LOG_ENTER(); - - assert((SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS == (int64_t)arg) || - (SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_ACTION == (int64_t)arg)); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(key->object_id, SAI_OBJECT_TYPE_PORT, &router_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} -/* - * Routine Description: - * Create virtual router - * - * Arguments: - * [out] vr_id - virtual router id - * [in] attr_count - number of attributes - * [in] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_create_virtual_router(_Out_ sai_object_id_t *vr_id, - _In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list) -{ - sai_status_t status; - char list_str[MAX_LIST_VALUE_STR_LEN]; - char key_str[MAX_KEY_STR_LEN]; - static uint32_t next_id = 0; - - STUB_LOG_ENTER(); - - if (NULL == vr_id) { - STUB_LOG_ERR("NULL vr_id param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_STATUS_SUCCESS != - (status = - check_attribs_metadata(attr_count, attr_list, router_attribs, router_vendor_attribs, - SAI_OPERATION_CREATE))) { - STUB_LOG_ERR("Failed attribs check\n"); - return status; - } - - sai_attr_list_to_str(attr_count, attr_list, router_attribs, MAX_LIST_VALUE_STR_LEN, list_str); - STUB_LOG_NTC("Create router, %s\n", list_str); - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_VIRTUAL_ROUTER, next_id++, vr_id))) { - return status; - } - router_key_to_str(*vr_id, key_str); - STUB_LOG_NTC("Created router %s\n", key_str); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Remove virtual router - * - * Arguments: - * [in] vr_id - virtual router id - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_virtual_router(_In_ sai_object_id_t vr_id) -{ - sai_status_t status; - uint32_t data; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - router_key_to_str(vr_id, key_str); - STUB_LOG_NTC("Remove router %s\n", key_str); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(vr_id, SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &data))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -const sai_virtual_router_api_t router_api = { - stub_create_virtual_router, - stub_remove_virtual_router, - stub_set_virtual_router_attribute, - stub_get_virtual_router_attribute -}; diff --git a/stub/src/stub_sai_switch.c b/stub/src/stub_sai_switch.c deleted file mode 100644 index 971e750c2..000000000 --- a/stub/src/stub_sai_switch.c +++ /dev/null @@ -1,1233 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" - -#undef __MODULE__ -#define __MODULE__ SAI_SWITCH - -sai_switch_notification_t g_notification_callbacks; -uint32_t gh_sdk = 0; - -sai_status_t stub_switch_port_number_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_port_list_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_cpu_port_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_max_vr_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_fdb_size_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_max_num_sensors_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_temp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_max_temp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_average_temp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_default_stp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_on_link_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_oper_status_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_acl_table_min_prio_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_acl_table_max_prio_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_acl_entry_min_prio_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_acl_entry_max_prio_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_mode_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_default_port_vlan_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_src_mac_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_aging_time_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_ecmp_hash_seed_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_ecmp_hash_algo_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_ecmp_hash_fields_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_counter_refresh_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_default_trap_channel_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_default_trap_channel_fd_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_default_trap_group_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_switch_mode_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_switch_default_port_vlan_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_switch_aging_time_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_switch_ecmp_hash_seed_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_switch_ecmp_hash_algo_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_switch_ecmp_hash_fields_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_switch_counter_refresh_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_switch_default_trap_channel_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_switch_default_trap_channel_fd_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_switch_default_trap_group_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); - -static const sai_attribute_entry_t switch_attribs[] = { - { SAI_SWITCH_ATTR_PORT_NUMBER, false, false, false, true, - "Switch ports number", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_PORT_LIST, false, false, false, true, - "Switch ports list", SAI_ATTR_VAL_TYPE_OBJLIST }, - { SAI_SWITCH_ATTR_CPU_PORT, false, false, false, true, - "Switch CPU port", SAI_ATTR_VAL_TYPE_OID }, - { SAI_SWITCH_ATTR_MAX_VIRTUAL_ROUTERS, false, false, false, true, - "Switch max virtual routers", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_FDB_TABLE_SIZE, false, false, false, true, - "Switch FDB table size", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_ON_LINK_ROUTE_SUPPORTED, false, false, false, true, - "Switch on link route supported", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_SWITCH_ATTR_OPER_STATUS, false, false, false, true, - "Switch operational status", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_SWITCH_ATTR_MAX_NUMBER_OF_TEMP_SENSORS, false, false, false, true, - "Switch Maximum sensors", SAI_ATTR_VAL_TYPE_U8 }, - { SAI_SWITCH_ATTR_TEMP_LIST, false, false, false, true, - "Switch temperature list", SAI_ATTR_VAL_TYPE_S32LIST}, - { SAI_SWITCH_ATTR_MAX_TEMP, false, false, false, true, - "Switch maximum temperature", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_SWITCH_ATTR_AVERAGE_TEMP, false, false, false, true, - "Switch current temperature", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_SWITCH_ATTR_ACL_TABLE_MINIMUM_PRIORITY, false, false, false, true, - "Switch ACL table min prio", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_ACL_TABLE_MAXIMUM_PRIORITY, false, false, false, true, - "Switch ACL table max prio", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_ACL_ENTRY_MINIMUM_PRIORITY, false, false, false, true, - "Switch ACL entry min prio", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_ACL_ENTRY_MAXIMUM_PRIORITY, false, false, false, true, - "Switch ACL entry max prio", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_DEFAULT_STP_INST_ID, false, false, false, true, - "Switch maximum temperature", SAI_ATTR_VAL_TYPE_OID }, - { SAI_SWITCH_ATTR_SWITCHING_MODE, false, false, true, true, - "Switch switching mode", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_SWITCH_ATTR_BCAST_CPU_FLOOD_ENABLE, false, false, true, true, - "Switch broadcast flood control to cpu", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_SWITCH_ATTR_MCAST_CPU_FLOOD_ENABLE, false, false, true, true, - "Switch multicast flood control to cpu", SAI_ATTR_VAL_TYPE_BOOL }, - { SAI_SWITCH_ATTR_SRC_MAC_ADDRESS, false, false, true, true, - "Switch source MAC address", SAI_ATTR_VAL_TYPE_MAC }, - { SAI_SWITCH_ATTR_MAX_LEARNED_ADDRESSES, false, false, true, true, - "Switch maximum number of learned MAC addresses", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_FDB_AGING_TIME, false, false, true, true, - "Switch FDB aging time", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_FDB_UNICAST_MISS_ACTION, false, false, true, true, - "Switch flood control for unknown unicast address", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_SWITCH_ATTR_FDB_BROADCAST_MISS_ACTION, false, false, true, true, - "Switch flood control for unknown broadcast address", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_SWITCH_ATTR_FDB_MULTICAST_MISS_ACTION, false, false, true, true, - "Switch flood control for unknown multicast address", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED, false, false, true, true, - "Switch LAG hash seed", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM, false, false, true, true, - "Switch LAG hash algorithm", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_SWITCH_ATTR_LAG_HASH, false, false, true, true, - "Switch LAG hash fields", SAI_ATTR_VAL_TYPE_S32LIST }, - { SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED, false, false, true, true, - "Switch ECMP hash seed", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM, false, false, true, true, - "Switch ECMP hash algorithm", SAI_ATTR_VAL_TYPE_S32 }, - { SAI_SWITCH_ATTR_ECMP_HASH, false, false, true, true, - "Switch ECMP hash fields", SAI_ATTR_VAL_TYPE_S32LIST }, - { SAI_SWITCH_ATTR_COUNTER_REFRESH_INTERVAL, false, false, true, true, - "Switch counter refresh interval", SAI_ATTR_VAL_TYPE_U32 }, - { SAI_SWITCH_ATTR_DEFAULT_TRAP_GROUP, false, false, true, true, - "Switch default trap group", SAI_ATTR_VAL_TYPE_OID }, - { SAI_SWITCH_ATTR_PORT_BREAKOUT, false, false, true, false, - "Switch port breakout mode", SAI_ATTR_VAL_TYPE_OID }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED } -}; -static const sai_vendor_attribute_entry_t switch_vendor_attribs[] = { - { SAI_SWITCH_ATTR_PORT_NUMBER, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_port_number_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_PORT_LIST, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_port_list_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_CPU_PORT, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_cpu_port_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_MAX_VIRTUAL_ROUTERS, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_max_vr_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_FDB_TABLE_SIZE, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_fdb_size_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_ON_LINK_ROUTE_SUPPORTED, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_on_link_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_OPER_STATUS, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_oper_status_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_MAX_NUMBER_OF_TEMP_SENSORS, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_max_num_sensors_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_TEMP_LIST, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_temp_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_MAX_TEMP, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_max_temp_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_AVERAGE_TEMP, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_average_temp_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_ACL_TABLE_MINIMUM_PRIORITY, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_acl_table_min_prio_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_ACL_TABLE_MAXIMUM_PRIORITY, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_acl_table_max_prio_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_ACL_ENTRY_MINIMUM_PRIORITY, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_acl_entry_min_prio_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_ACL_ENTRY_MAXIMUM_PRIORITY, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_acl_entry_max_prio_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_DEFAULT_STP_INST_ID, - { false, false, false, true }, - { false, false, false, true }, - stub_switch_default_stp_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_SWITCHING_MODE, - { false, false, true, true }, - { false, false, true, true }, - stub_switch_mode_get, NULL, - stub_switch_mode_set, NULL }, - { SAI_SWITCH_ATTR_BCAST_CPU_FLOOD_ENABLE, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_MCAST_CPU_FLOOD_ENABLE, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_SRC_MAC_ADDRESS, - { false, false, false, true }, - { false, false, true, true }, - stub_switch_src_mac_get, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_MAX_LEARNED_ADDRESSES, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_FDB_AGING_TIME, - { false, false, true, true }, - { false, false, true, true }, - stub_switch_aging_time_get, NULL, - stub_switch_aging_time_set, NULL }, - { SAI_SWITCH_ATTR_FDB_UNICAST_MISS_ACTION, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_FDB_BROADCAST_MISS_ACTION, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_FDB_MULTICAST_MISS_ACTION, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_LAG_HASH, - { false, false, false, false }, - { false, false, true, true }, - NULL, NULL, - NULL, NULL }, - { SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED, - { false, false, true, true }, - { false, false, true, true }, - stub_switch_ecmp_hash_seed_get, NULL, - stub_switch_ecmp_hash_seed_set, NULL }, - { SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM, - { false, false, true, true }, - { false, false, true, true }, - stub_switch_ecmp_hash_algo_get, NULL, - stub_switch_ecmp_hash_algo_set, NULL }, - { SAI_SWITCH_ATTR_ECMP_HASH, - { false, false, true, true }, - { false, false, true, true }, - stub_switch_ecmp_hash_fields_get, NULL, - stub_switch_ecmp_hash_fields_set, NULL }, - { SAI_SWITCH_ATTR_COUNTER_REFRESH_INTERVAL, - { false, false, true, true }, - { false, false, true, true }, - stub_switch_counter_refresh_get, NULL, - stub_switch_counter_refresh_set, NULL }, - { SAI_SWITCH_ATTR_DEFAULT_TRAP_GROUP, - { false, false, true, true }, - { false, false, true, true }, - stub_switch_default_trap_group_get, NULL, - stub_switch_default_trap_group_set, NULL }, - { SAI_SWITCH_ATTR_PORT_BREAKOUT, - { false, false, false, false }, - { false, false, true, false }, - NULL, NULL, - NULL, NULL }, -}; - - -/* - * Routine Description: - * SDK initialization. After the call the capability attributes should be - * ready for retrieval via sai_get_switch_attribute(). - * - * Arguments: - * [in] profile_id - Handle for the switch profile. - * [in] switch_hardware_id - Switch hardware ID to open - * [in/opt] firmware_path_name - Vendor specific path name of the firmware - * to load - * [in] switch_notifications - switch notification table - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_initialize_switch(_In_ sai_switch_profile_id_t profile_id, - _In_reads_z_(SAI_MAX_HARDWARE_ID_LEN) char * switch_hardware_id, - _In_reads_opt_z_(SAI_MAX_FIRMWARE_PATH_NAME_LEN) char* firmware_path_name, - _In_ sai_switch_notification_t * switch_notifications) -{ - if (NULL == switch_hardware_id) { - fprintf(stderr, "NULL switch hardware ID passed to SAI switch initialize\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == switch_notifications) { - fprintf(stderr, "NULL switch notifications passed to SAI switch initialize\n"); - - return SAI_STATUS_INVALID_PARAMETER; - } - - gh_sdk = 1; - memcpy(&g_notification_callbacks, switch_notifications, sizeof(g_notification_callbacks)); - -#ifndef _WIN32 - openlog("SAI", 0, LOG_USER); -#endif - - STUB_LOG_NTC("Initialize switch\n"); - - db_init_vlan(); - db_init_next_hop_group(); - - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Release all resources associated with currently opened switch - * - * Arguments: - * [in] warm_restart_hint - hint that indicates controlled warm restart. - * Since warm restart can be caused by crash - * (therefore there are no guarantees for this call), - * this hint is really a performance optimization. - * - * Return Values: - * None - */ -void stub_shutdown_switch(_In_ bool warm_restart_hint) -{ - STUB_LOG_NTC("Shutdown switch\n"); - gh_sdk = 0; -} - -/* - * Routine Description: - * SDK connect. This API connects library to the initialized SDK. - * After the call the capability attributes should be ready for retrieval - * via sai_get_switch_attribute(). - * - * Arguments: - * [in] profile_id - Handle for the switch profile. - * [in] switch_hardware_id - Switch hardware ID to open - * [in] switch_notifications - switch notification table - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_connect_switch(_In_ sai_switch_profile_id_t profile_id, - _In_reads_z_(SAI_MAX_HARDWARE_ID_LEN) char* switch_hardware_id, - _In_ sai_switch_notification_t * switch_notifications) -{ - if (NULL == switch_hardware_id) { - fprintf(stderr, "NULL switch hardware ID passed to SAI switch connect\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == switch_notifications) { - fprintf(stderr, "NULL switch notifications passed to SAI switch connect\n"); - - return SAI_STATUS_INVALID_PARAMETER; - } - - memcpy(&g_notification_callbacks, switch_notifications, sizeof(g_notification_callbacks)); - - /* Open an handle if not done already on init for init agent */ - if (0 == gh_sdk) { -#ifndef _WIN32 - openlog("SAI", 0, LOG_USER); -#endif - } - - db_init_next_hop_group(); - - STUB_LOG_NTC("Connect switch\n"); - - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Disconnect this SAI library from the SDK. - * - * Arguments: - * None - * Return Values: - * None - */ -void stub_disconnect_switch(void) -{ - STUB_LOG_NTC("Disconnect switch\n"); - - memset(&g_notification_callbacks, 0, sizeof(g_notification_callbacks)); -} - -/* - * Routine Description: - * Set switch attribute value - * - * Arguments: - * [in] attr - switch attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_switch_attribute(_In_ const sai_attribute_t *attr) -{ - STUB_LOG_ENTER(); - - return sai_set_attribute(NULL, "", switch_attribs, switch_vendor_attribs, attr); -} - -/* Switching mode [sai_switch_switching_mode_t] - * (default to SAI_SWITCHING_MODE_STORE_AND_FORWARD) */ -sai_status_t stub_switch_mode_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - STUB_LOG_ENTER(); - - switch (value->s32) { - case SAI_SWITCHING_MODE_CUT_THROUGH: - break; - - case SAI_SWITCHING_MODE_STORE_AND_FORWARD: - break; - - default: - STUB_LOG_ERR("Invalid rif port object type %s", "aa"); - /* STUB_LOG_ERR("Invalid switching mode value %d\n", value->s32); */ - return SAI_STATUS_INVALID_ATTR_VALUE_0; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default VlanID for ports that are not members of -* any vlans [sai_vlan_id_t] (default to vlan 1)*/ -sai_status_t stub_switch_default_port_vlan_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Dynamic FDB entry aging time in seconds [uint32_t] - * Zero means aging is disabled. - * (default to zero) - */ -sai_status_t stub_switch_aging_time_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* ECMP hashing seed [uint32_t] */ -sai_status_t stub_switch_ecmp_hash_seed_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Hash algorithm for all ECMP in the switch[sai_switch_hash_algo_t] */ -sai_status_t stub_switch_ecmp_hash_algo_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - switch (value->s32) { - case SAI_HASH_ALGORITHM_XOR: - break; - - case SAI_HASH_ALGORITHM_CRC: - break; - - case SAI_HASH_ALGORITHM_RANDOM: - break; - - default: - STUB_LOG_ERR("Invalid hash type value %d\n", value->s32); - return SAI_STATUS_INVALID_ATTR_VALUE_0; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Hash fields for all ECMP in the switch[sai_s32_list_t] */ -sai_status_t stub_switch_ecmp_hash_fields_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - uint32_t ii; - - STUB_LOG_ENTER(); - - for (ii = 0; ii < value->s32list.count; ii++) { - switch (value->s32list.list[ii]) { - case SAI_NATIVE_HASH_FIELD_SRC_IP: - break; - - case SAI_NATIVE_HASH_FIELD_DST_IP: - break; - - case SAI_NATIVE_HASH_FIELD_VLAN_ID: - break; - - case SAI_NATIVE_HASH_FIELD_IP_PROTOCOL: - break; - - case SAI_NATIVE_HASH_FIELD_ETHERTYPE: - break; - - case SAI_NATIVE_HASH_FIELD_L4_SRC_PORT: - break; - - case SAI_NATIVE_HASH_FIELD_L4_DST_PORT: - break; - - case SAI_NATIVE_HASH_FIELD_SRC_MAC: - break; - - case SAI_NATIVE_HASH_FIELD_DST_MAC: - break; - - case SAI_NATIVE_HASH_FIELD_IN_PORT: - break; - - default: - STUB_LOG_ERR("Invalid ecmp hash field , element %d, value %d\n", ii, value->s32list.list[ii]); - return SAI_STATUS_INVALID_ATTR_VALUE_0; - } - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* The SDK can - * 1 - Read the counters directly from HW (or) - * 2 - Cache the counters in SW. Caching is typically done if - * retrieval of counters directly from HW for each counter - * read is CPU intensive - * This setting can be used to - * 1 - Move from HW based to SW based or Vice versa - * 2 - Configure the SW counter cache refresh rate - * Setting a value of 0 enables direct HW based counter read. A - * non zero value enables the SW cache based and the counter - * refresh rate. - * A NPU may support both or one of the option. It would return - * error for unsupported options. [uint32_t] - */ -sai_status_t stub_switch_counter_refresh_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default trap channel [sai_hostif_trap_channel_t] */ -sai_status_t stub_switch_default_trap_channel_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default file descriptor for SAI_HOSTIF_TRAP_CHANNEL_FD [sai_object_id_t] */ -sai_status_t stub_switch_default_trap_channel_fd_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default trap group [sai_object_id_t] */ -sai_status_t stub_switch_default_trap_group_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} -/* - * Routine Description: - * Get switch attribute value - * - * Arguments: - * [in] attr_count - number of switch attributes - * [inout] attr_list - array of switch attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_switch_attribute(_In_ uint32_t attr_count, _Inout_ sai_attribute_t *attr_list) -{ - STUB_LOG_ENTER(); - - return sai_get_attributes(NULL, "", switch_attribs, switch_vendor_attribs, attr_count, attr_list); -} - -/* The number of ports on the switch [uint32_t] */ -sai_status_t stub_switch_port_number_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->u32 = PORT_NUMBER; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Get the port list [sai_object_list_t] */ -sai_status_t stub_switch_port_list_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_object_id_t ports[PORT_NUMBER]; - uint32_t ii; - sai_status_t status; - - STUB_LOG_ENTER(); - - for (ii = 0; ii < PORT_NUMBER; ii++) { - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_PORT, ii, &ports[ii]))) { - return status; - } - } - - status = stub_fill_objlist(ports, PORT_NUMBER, &value->objlist); - - STUB_LOG_EXIT(); - - return status; -} - -/* Get the CPU Port [sai_object_id_t] */ -sai_status_t stub_switch_cpu_port_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_PORT, 1, &value->oid))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Max number of virtual routers supported [uint32_t] */ -sai_status_t stub_switch_max_vr_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->u32 = 0; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* The size of the FDB Table in bytes [uint32_t] */ -sai_status_t stub_switch_fdb_size_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->u32 = 100000; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* The Maximum number of temperature sensors available */ -sai_status_t stub_switch_max_num_sensors_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->u8 = 1; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* List of temperature readings from all sensors in Celsius [int32_t] */ -sai_status_t stub_switch_temp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - int32_t temp; - - STUB_LOG_ENTER(); - - temp = 50; - status = stub_fill_s32list(&temp, 1, &value->s32list); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* The current value of the maximum temperature - * retrieved from the switch sensors, in Celsius [int32_t] */ -sai_status_t stub_switch_max_temp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = 50; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* The average value of the temperature - * retrieved from the switch sensors, in Celsius [int32_t] */ -sai_status_t stub_switch_average_temp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = 50; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default SAI STP instance ID [sai_object_id_t] */ -sai_status_t stub_switch_default_stp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_STP_INSTANCE, 1, &value->oid))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* - * Local subnet routing supported [bool] - * Routes with next hop set to "on-link" - */ -sai_status_t stub_switch_on_link_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->booldata = true; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Oper state [sai_switch_oper_status_t] */ -sai_status_t stub_switch_oper_status_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = SAI_SWITCH_OPER_STATUS_UP; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* minimum priority for ACL table [sai_uint32_t] */ -sai_status_t stub_switch_acl_table_min_prio_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* maximum priority for ACL table [sai_uint32_t] */ -sai_status_t stub_switch_acl_table_max_prio_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* minimum priority for ACL entry [sai_uint32_t] */ -sai_status_t stub_switch_acl_entry_min_prio_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* maximum priority for ACL entry [sai_uint32_t] */ -sai_status_t stub_switch_acl_entry_max_prio_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Switching mode [sai_switch_switching_mode_t] - * (default to SAI_SWITCHING_MODE_STORE_AND_FORWARD) */ -sai_status_t stub_switch_mode_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = SAI_SWITCHING_MODE_CUT_THROUGH; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default VlanID for ports that are not members of -* any vlans [sai_vlan_id_t] (default to vlan 1)*/ -sai_status_t stub_switch_default_port_vlan_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->u16 = 1; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default switch MAC Address [sai_mac_t] */ -sai_status_t stub_switch_src_mac_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Dynamic FDB entry aging time in seconds [uint32_t] - * Zero means aging is disabled. - * (default to zero) - */ -sai_status_t stub_switch_aging_time_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->u32 = 0; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* ECMP hashing seed [uint32_t] */ -sai_status_t stub_switch_ecmp_hash_seed_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->u32 = 0; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Hash algorithm for all ECMP in the switch[sai_switch_hash_algo_t] */ -sai_status_t stub_switch_ecmp_hash_algo_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->s32 = SAI_HASH_ALGORITHM_XOR; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Hash fields for all ECMP in the switch [sai_s32_list_t] */ -sai_status_t stub_switch_ecmp_hash_fields_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* The SDK can - * 1 - Read the counters directly from HW (or) - * 2 - Cache the counters in SW. Caching is typically done if - * retrieval of counters directly from HW for each counter - * read is CPU intensive - * This setting can be used to - * 1 - Move from HW based to SW based or Vice versa - * 2 - Configure the SW counter cache refresh rate - * Setting a value of 0 enables direct HW based counter read. A - * non zero value enables the SW cache based and the counter - * refresh rate. - * A NPU may support both or one of the option. It would return - * error for unsupported options. [uint32_t] - */ -sai_status_t stub_switch_counter_refresh_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default trap channel [sai_hostif_trap_channel_t] */ -sai_status_t stub_switch_default_trap_channel_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default file descriptor for SAI_HOSTIF_TRAP_CHANNEL_FD [sai_object_id_t] */ -sai_status_t stub_switch_default_trap_channel_fd_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Default trap group [sai_object_id_t] */ -sai_status_t stub_switch_default_trap_group_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -const sai_switch_api_t switch_api = { - stub_initialize_switch, - stub_shutdown_switch, - stub_connect_switch, - stub_disconnect_switch, - stub_set_switch_attribute, - stub_get_switch_attribute, -}; diff --git a/stub/src/stub_sai_utils.c b/stub/src/stub_sai_utils.c deleted file mode 100644 index 2ffa03b9e..000000000 --- a/stub/src/stub_sai_utils.c +++ /dev/null @@ -1,869 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" -#include "assert.h" -#include "inttypes.h" -#include -#include -#ifndef WIN32 -#include -#else -#include -#endif - -#undef __MODULE__ -#define __MODULE__ SAI_UTILS - -static sai_status_t find_functionality_attrib_index(_In_ const sai_attr_id_t id, - _In_ const sai_attribute_entry_t *functionality_attr, - _Out_ uint32_t *index) -{ - uint32_t curr_index; - - STUB_LOG_ENTER(); - - if (NULL == functionality_attr) { - STUB_LOG_ERR("NULL value functionality attrib\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == index) { - STUB_LOG_ERR("NULL value index\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - for (curr_index = 0; END_FUNCTIONALITY_ATTRIBS_ID != functionality_attr[curr_index].id; curr_index++) { - if (id == functionality_attr[curr_index].id) { - *index = curr_index; - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; - } - } - - STUB_LOG_EXIT(); - return SAI_STATUS_ITEM_NOT_FOUND; -} - - -sai_status_t check_attribs_metadata(_In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list, - _In_ const sai_attribute_entry_t *functionality_attr, - _In_ const sai_vendor_attribute_entry_t *functionality_vendor_attr, - _In_ sai_operation_t oper) -{ - uint32_t functionality_attr_count, ii, index; - bool *attr_present; - - STUB_LOG_ENTER(); - - if ((attr_count) && (NULL == attr_list)) { - STUB_LOG_ERR("NULL value attr list\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == functionality_attr) { - STUB_LOG_ERR("NULL value functionality attrib\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == functionality_vendor_attr) { - STUB_LOG_ERR("NULL value functionality vendor attrib\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_OPERATION_MAX <= oper) { - STUB_LOG_ERR("Invalid operation %d\n", oper); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (SAI_OPERATION_REMOVE == oper) { - /* No attributes expected for remove at this point */ - return SAI_STATUS_NOT_IMPLEMENTED; - } - - if (SAI_OPERATION_SET == oper) { - if (1 != attr_count) { - STUB_LOG_ERR("Set operation supports only single attribute\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - } - - for (functionality_attr_count = 0; - END_FUNCTIONALITY_ATTRIBS_ID != functionality_attr[functionality_attr_count].id; - functionality_attr_count++) { - if (functionality_attr[functionality_attr_count].id != - functionality_vendor_attr[functionality_attr_count].id) { - STUB_LOG_ERR("Mismatch between functionality attribute and vendor attribute index %u %u %u\n", - functionality_attr_count, functionality_attr[functionality_attr_count].id, - functionality_vendor_attr[functionality_attr_count].id); - return SAI_STATUS_FAILURE; - } - } - - attr_present = (bool*)calloc(functionality_attr_count, sizeof(bool)); - if (NULL == attr_present) { - STUB_LOG_ERR("Can't allocate memory\n"); - return SAI_STATUS_NO_MEMORY; - } - - for (ii = 0; ii < attr_count; ii++) { - if (SAI_STATUS_SUCCESS != find_functionality_attrib_index(attr_list[ii].id, functionality_attr, &index)) { - STUB_LOG_ERR("Invalid attribute %d\n", attr_list[ii].id); - free(attr_present); - return SAI_STATUS_UNKNOWN_ATTRIBUTE_0 + ii; - } - - if ((SAI_OPERATION_CREATE == oper) && - (!(functionality_attr[index].valid_for_create))) { - STUB_LOG_ERR("Invalid attribute %s for create\n", functionality_attr[index].attrib_name); - free(attr_present); - return SAI_STATUS_INVALID_ATTRIBUTE_0 + ii; - } - - if ((SAI_OPERATION_SET == oper) && - (!(functionality_attr[index].valid_for_set))) { - STUB_LOG_ERR("Invalid attribute %s for set\n", functionality_attr[index].attrib_name); - free(attr_present); - return SAI_STATUS_INVALID_ATTRIBUTE_0 + ii; - } - - if ((SAI_OPERATION_GET == oper) && - (!(functionality_attr[index].valid_for_get))) { - STUB_LOG_ERR("Invalid attribute %s for get\n", functionality_attr[index].attrib_name); - free(attr_present); - return SAI_STATUS_INVALID_ATTRIBUTE_0 + ii; - } - - if (!(functionality_vendor_attr[index].is_supported[oper])) { - STUB_LOG_ERR("Not supported attribute %s\n", functionality_attr[index].attrib_name); - free(attr_present); - return SAI_STATUS_ATTR_NOT_SUPPORTED_0 + ii; - } - - if (!(functionality_vendor_attr[index].is_implemented[oper])) { - STUB_LOG_ERR("Not implemented attribute %s\n", functionality_attr[index].attrib_name); - free(attr_present); - return SAI_STATUS_ATTR_NOT_IMPLEMENTED_0 + ii; - } - - if (attr_present[index]) { - STUB_LOG_ERR("Attribute %s appears twice in attribute list at index %d\n", - functionality_attr[index].attrib_name, - ii); - free(attr_present); - return SAI_STATUS_INVALID_ATTRIBUTE_0 + ii; - } - - if (((SAI_ATTR_VAL_TYPE_OBJLIST == functionality_attr[index].type) && - (NULL == attr_list[ii].value.objlist.list)) || - ((SAI_ATTR_VAL_TYPE_U32LIST == functionality_attr[index].type) && - (NULL == attr_list[ii].value.u32list.list)) || - ((SAI_ATTR_VAL_TYPE_S32LIST == functionality_attr[index].type) && - (NULL == attr_list[ii].value.s32list.list)) || - ((SAI_ATTR_VAL_TYPE_VLANLIST == functionality_attr[index].type) && - (NULL == attr_list[ii].value.vlanlist.list))) { - STUB_LOG_ERR("Null list attribute %s at index %d\n", - functionality_attr[index].attrib_name, - ii); - free(attr_present); - return SAI_STATUS_INVALID_ATTR_VALUE_0 + ii; - } - - attr_present[index] = true; - } - - if (SAI_OPERATION_CREATE == oper) { - for (ii = 0; ii < functionality_attr_count; ii++) { - if ((functionality_attr[ii].mandatory_on_create) && - (!attr_present[ii])) { - STUB_LOG_ERR("Missing mandatory attribute %s on create\n", functionality_attr[ii].attrib_name); - free(attr_present); - return SAI_STATUS_MANDATORY_ATTRIBUTE_MISSING; - } - } - } - - free(attr_present); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -static sai_status_t set_dispatch_attrib_handler(_In_ const sai_attribute_t *attr, - _In_ const sai_attribute_entry_t *functionality_attr, - _In_ const sai_vendor_attribute_entry_t *functionality_vendor_attr, - _In_ const sai_object_key_t *key, - _In_ const char *key_str) -{ - uint32_t index; - sai_status_t err; - char value_str[MAX_VALUE_STR_LEN]; - - STUB_LOG_ENTER(); - - if (NULL == attr) { - STUB_LOG_ERR("NULL value attr\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == functionality_attr) { - STUB_LOG_ERR("NULL value functionality attrib\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == functionality_vendor_attr) { - STUB_LOG_ERR("NULL value functionality vendor attrib\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - assert(SAI_STATUS_SUCCESS == find_functionality_attrib_index(attr->id, functionality_attr, &index)); - - if (!functionality_vendor_attr[index].setter) { - STUB_LOG_ERR("Attribute %s not implemented on set and defined incorrectly\n", - functionality_attr[index].attrib_name); - return SAI_STATUS_ATTR_NOT_IMPLEMENTED_0; - } - - sai_value_to_str(attr->value, functionality_attr[index].type, MAX_VALUE_STR_LEN, value_str); - STUB_LOG_NTC("Set %s, key:%s, val:%s\n", functionality_attr[index].attrib_name, key_str, value_str); - err = functionality_vendor_attr[index].setter(key, &(attr->value), functionality_vendor_attr[index].setter_arg); - - STUB_LOG_EXIT(); - return err; -} - -static sai_status_t get_dispatch_attribs_handler(_In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list, - _In_ const sai_attribute_entry_t *functionality_attr, - _In_ const sai_vendor_attribute_entry_t *functionality_vendor_attr, - _In_ const sai_object_key_t *key, - _In_ const char *key_str) -{ - uint32_t ii, index; - vendor_cache_t cache; - sai_status_t status; - char value_str[MAX_VALUE_STR_LEN]; - - if ((attr_count) && (NULL == attr_list)) { - STUB_LOG_ERR("NULL value attr list\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == functionality_attr) { - STUB_LOG_ERR("NULL value functionality attrib\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == functionality_vendor_attr) { - STUB_LOG_ERR("NULL value functionality vendor attrib\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - memset(&cache, 0, sizeof(cache)); - - for (ii = 0; ii < attr_count; ii++) { - assert(SAI_STATUS_SUCCESS == find_functionality_attrib_index(attr_list[ii].id, functionality_attr, &index)); - - if (!functionality_vendor_attr[index].getter) { - STUB_LOG_ERR("Attribute %s not implemented on get and defined incorrectly\n", - functionality_attr[index].attrib_name); - return SAI_STATUS_ATTR_NOT_IMPLEMENTED_0 + ii; - } - - if (SAI_STATUS_SUCCESS != - (status = - functionality_vendor_attr[index].getter(key, &(attr_list[ii].value), ii, &cache, - functionality_vendor_attr[index].getter_arg))) { - STUB_LOG_ERR("Failed getting attrib %s\n", functionality_attr[index].attrib_name); - return status; - } - sai_value_to_str(attr_list[ii].value, functionality_attr[index].type, MAX_VALUE_STR_LEN, value_str); - STUB_LOG_NTC("Got #%u, %s, key:%s, val:%s\n", ii, functionality_attr[index].attrib_name, key_str, value_str); - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -sai_status_t find_attrib_in_list(_In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list, - _In_ sai_attr_id_t attrib_id, - _Out_ const sai_attribute_value_t **attr_value, - _Out_ uint32_t *index) -{ - uint32_t ii; - - STUB_LOG_ENTER(); - - if ((attr_count) && (NULL == attr_list)) { - STUB_LOG_ERR("NULL value attr list\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == attr_value) { - STUB_LOG_ERR("NULL value attr value\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == index) { - STUB_LOG_ERR("NULL value index\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - for (ii = 0; ii < attr_count; ii++) { - if (attr_list[ii].id == attrib_id) { - *attr_value = &(attr_list[ii].value); - *index = ii; - return SAI_STATUS_SUCCESS; - } - } - - STUB_LOG_EXIT(); - return SAI_STATUS_ITEM_NOT_FOUND; -} - -sai_status_t sai_set_attribute(_In_ const sai_object_key_t *key, - _In_ const char *key_str, - _In_ const sai_attribute_entry_t *functionality_attr, - _In_ const sai_vendor_attribute_entry_t *functionality_vendor_attr, - _In_ const sai_attribute_t *attr) -{ - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != - (status = check_attribs_metadata(1, attr, functionality_attr, functionality_vendor_attr, SAI_OPERATION_SET))) { - STUB_LOG_ERR("Failed attribs check, key:%s\n", key_str); - return status; - } - - if (SAI_STATUS_SUCCESS != - (status = set_dispatch_attrib_handler(attr, functionality_attr, functionality_vendor_attr, key, key_str))) { - STUB_LOG_ERR("Failed set attrib dispatch\n"); - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -sai_status_t sai_get_attributes(_In_ const sai_object_key_t *key, - _In_ const char *key_str, - _In_ const sai_attribute_entry_t *functionality_attr, - _In_ const sai_vendor_attribute_entry_t *functionality_vendor_attr, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != - (status = - check_attribs_metadata(attr_count, attr_list, functionality_attr, functionality_vendor_attr, - SAI_OPERATION_GET))) { - STUB_LOG_ERR("Failed attribs check, key:%s\n", key_str); - return status; - } - - if (SAI_STATUS_SUCCESS != - (status = - get_dispatch_attribs_handler(attr_count, attr_list, functionality_attr, functionality_vendor_attr, key, - key_str))) { - STUB_LOG_ERR("Failed attribs dispatch\n"); - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -static sai_status_t sai_ipv4_to_str(_In_ sai_ip4_t value, - _In_ uint32_t max_length, - _Out_ char *value_str, - _Out_ int *chars_written) -{ - inet_ntop(AF_INET, &value, value_str, max_length); - - if (NULL != chars_written) { - *chars_written = (int)strlen(value_str); - } - - return SAI_STATUS_SUCCESS; -} - -static sai_status_t sai_ipv6_to_str(_In_ sai_ip6_t value, - _In_ uint32_t max_length, - _Out_ char *value_str, - _Out_ int *chars_written) -{ - inet_ntop(AF_INET6, &value, value_str, max_length); - - if (NULL != chars_written) { - *chars_written = (int)strlen(value_str); - } - - return SAI_STATUS_SUCCESS; -} - -sai_status_t sai_ipaddr_to_str(_In_ sai_ip_address_t value, - _In_ uint32_t max_length, - _Out_ char *value_str, - _Out_ int *chars_written) -{ - int res; - - if (SAI_IP_ADDR_FAMILY_IPV4 == value.addr_family) { - sai_ipv4_to_str(value.addr.ip4, max_length, value_str, chars_written); - } else if (SAI_IP_ADDR_FAMILY_IPV6 == value.addr_family) { - sai_ipv6_to_str(value.addr.ip6, max_length, value_str, chars_written); - } else { - res = snprintf(value_str, max_length, "Invalid ipaddr family %d", value.addr_family); - if (NULL != chars_written) { - *chars_written = res; - } - return SAI_STATUS_INVALID_PARAMETER; - } - - return SAI_STATUS_SUCCESS; -} - -sai_status_t sai_ipprefix_to_str(_In_ sai_ip_prefix_t value, _In_ uint32_t max_length, _Out_ char *value_str) -{ - int chars_written; - uint32_t pos = 0; - - if (SAI_IP_ADDR_FAMILY_IPV4 == value.addr_family) { - sai_ipv4_to_str(value.addr.ip4, max_length, value_str, &chars_written); - pos += chars_written; - if (pos > max_length) { - return SAI_STATUS_SUCCESS; - } - pos += snprintf(value_str + pos, max_length - pos, " "); - if (pos > max_length) { - return SAI_STATUS_SUCCESS; - } - sai_ipv4_to_str(value.mask.ip4, max_length - pos, value_str + pos, &chars_written); - } else if (SAI_IP_ADDR_FAMILY_IPV6 == value.addr_family) { - sai_ipv6_to_str(value.addr.ip6, max_length, value_str, &chars_written); - pos += chars_written; - if (pos > max_length) { - return SAI_STATUS_SUCCESS; - } - pos += snprintf(value_str + pos, max_length - pos, " "); - if (pos > max_length) { - return SAI_STATUS_SUCCESS; - } - sai_ipv6_to_str(value.mask.ip6, max_length - pos, value_str + pos, &chars_written); - } else { - snprintf(value_str, max_length, "Invalid addr family %d", value.addr_family); - return SAI_STATUS_INVALID_PARAMETER; - } - - return SAI_STATUS_SUCCESS; -} - -sai_status_t sai_nexthops_to_str(_In_ uint32_t next_hop_count, - _In_ const sai_object_id_t* nexthops, - _In_ uint32_t max_length, - _Out_ char *str) -{ - uint32_t ii; - uint32_t pos = 0; - uint32_t nexthop_id; - sai_status_t status; - - pos += snprintf(str, max_length, "%u hops : [", next_hop_count); - if (pos > max_length) { - return SAI_STATUS_SUCCESS; - } - for (ii = 0; ii < next_hop_count; ii++) { - if (SAI_STATUS_SUCCESS != - (status = stub_object_to_type(nexthops[ii], SAI_OBJECT_TYPE_NEXT_HOP, &nexthop_id))) { - snprintf(str + pos, max_length - pos, " invalid next hop]"); - return status; - } - - pos += snprintf(str + pos, max_length - pos, " %u", nexthop_id); - if (pos > max_length) { - return SAI_STATUS_SUCCESS; - } - } - snprintf(str + pos, max_length - pos, "]"); - - return SAI_STATUS_SUCCESS; -} - -sai_status_t sai_value_to_str(_In_ sai_attribute_value_t value, - _In_ sai_attribute_value_type_t type, - _In_ uint32_t max_length, - _Out_ char *value_str) -{ - uint32_t ii; - uint32_t pos = 0; - uint32_t count; - stub_object_id_t *stub_object_id; - - if (NULL == value_str) { - STUB_LOG_ERR("NULL value str"); - return SAI_STATUS_INVALID_PARAMETER; - } - - *value_str = '\0'; - - switch (type) { - case SAI_ATTR_VAL_TYPE_BOOL: - snprintf(value_str, max_length, "%u", value.booldata); - break; - - case SAI_ATTR_VAL_TYPE_CHARDATA: - snprintf(value_str, max_length, "%s", value.chardata); - break; - - case SAI_ATTR_VAL_TYPE_U8: - snprintf(value_str, max_length, "%u", value.u8); - break; - - case SAI_ATTR_VAL_TYPE_S8: - snprintf(value_str, max_length, "%d", value.s8); - break; - - case SAI_ATTR_VAL_TYPE_U16: - snprintf(value_str, max_length, "%u", value.u16); - break; - - case SAI_ATTR_VAL_TYPE_S16: - snprintf(value_str, max_length, "%d", value.s16); - break; - - case SAI_ATTR_VAL_TYPE_U32: - snprintf(value_str, max_length, "%u", value.u32); - break; - - case SAI_ATTR_VAL_TYPE_S32: - snprintf(value_str, max_length, "%d", value.s32); - break; - - case SAI_ATTR_VAL_TYPE_U64: - snprintf(value_str, max_length, "%" PRIu64, value.u64); - break; - - case SAI_ATTR_VAL_TYPE_S64: - snprintf(value_str, max_length, "%" PRId64, value.s64); - break; - - case SAI_ATTR_VAL_TYPE_MAC: - snprintf(value_str, max_length, "[%02x:%02x:%02x:%02x:%02x:%02x]", - value.mac[0], - value.mac[1], - value.mac[2], - value.mac[3], - value.mac[4], - value.mac[5]); - break; - - /* IP is in network order */ - case SAI_ATTR_VAL_TYPE_IPV4: - sai_ipv4_to_str(value.ip4, max_length, value_str, NULL); - break; - - case SAI_ATTR_VAL_TYPE_IPV6: - sai_ipv6_to_str(value.ip6, max_length, value_str, NULL); - break; - - case SAI_ATTR_VAL_TYPE_IPADDR: - sai_ipaddr_to_str(value.ipaddr, max_length, value_str, NULL); - break; - - case SAI_ATTR_VAL_TYPE_OID: - stub_object_id = (stub_object_id_t*)&value.oid; - snprintf(value_str, max_length, "%s %x", - SAI_TYPE_STR(sai_object_type_query(value.oid)), stub_object_id->data); - break; - - case SAI_ATTR_VAL_TYPE_OBJLIST: - case SAI_ATTR_VAL_TYPE_U32LIST: - case SAI_ATTR_VAL_TYPE_S32LIST: - case SAI_ATTR_VAL_TYPE_VLANLIST: - case SAI_ATTR_VAL_TYPE_PORTBREAKOUT: - if (SAI_ATTR_VAL_TYPE_PORTBREAKOUT == type) { - pos += snprintf(value_str, max_length, "breakout mode %d.", value.portbreakout.breakout_mode); - } - if (pos > max_length) { - return SAI_STATUS_SUCCESS; - } - - count = (SAI_ATTR_VAL_TYPE_OBJLIST == type) ? value.objlist.count : - (SAI_ATTR_VAL_TYPE_U32LIST == type) ? value.u32list.count : - (SAI_ATTR_VAL_TYPE_S32LIST == type) ? value.s32list.count : - (SAI_ATTR_VAL_TYPE_VLANLIST == type) ? value.vlanlist.count : - value.portbreakout.port_list.count; - pos += snprintf(value_str + pos, max_length - pos, "%u : [", count); - if (pos > max_length) { - return SAI_STATUS_SUCCESS; - } - - for (ii = 0; ii < count; ii++) { - if (SAI_ATTR_VAL_TYPE_OBJLIST == type) { - pos += snprintf(value_str + pos, max_length - pos, " %" PRIx64, value.objlist.list[ii]); - } else if (SAI_ATTR_VAL_TYPE_U32LIST == type) { - pos += snprintf(value_str + pos, max_length - pos, " %u", value.u32list.list[ii]); - } else if (SAI_ATTR_VAL_TYPE_S32LIST == type) { - pos += snprintf(value_str + pos, max_length - pos, " %d", value.s32list.list[ii]); - } else if (SAI_ATTR_VAL_TYPE_VLANLIST == type) { - pos += snprintf(value_str + pos, max_length - pos, " %u", value.vlanlist.list[ii]); - } else { - pos += snprintf(value_str + pos, max_length - pos, " %" PRIx64, value.portbreakout.port_list.list[ii]); - } - if (pos > max_length) { - return SAI_STATUS_SUCCESS; - } - } - snprintf(value_str + pos, max_length - pos, "]"); - break; - - - case SAI_ATTR_VAL_TYPE_ACLFIELD: - case SAI_ATTR_VAL_TYPE_ACLACTION: - /* TODO : implement if in case it is used */ - snprintf(value_str, max_length, "Not implemented value type %d", type); - return SAI_STATUS_NOT_IMPLEMENTED; - - case SAI_ATTR_VAL_TYPE_UNDETERMINED: - default: - snprintf(value_str, max_length, "Invalid/Unsupported value type %d", type); - return SAI_STATUS_INVALID_PARAMETER; - } - - return SAI_STATUS_SUCCESS; -} - -sai_status_t sai_attr_list_to_str(_In_ uint32_t attr_count, - _In_ const sai_attribute_t *attr_list, - _In_ const sai_attribute_entry_t *functionality_attr, - _In_ uint32_t max_length, - _Out_ char *list_str) -{ - uint32_t ii, index, pos = 0; - char value_str[MAX_VALUE_STR_LEN]; - - if ((attr_count) && (NULL == attr_list)) { - STUB_LOG_ERR("NULL value attr list\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == functionality_attr) { - STUB_LOG_ERR("NULL value functionality attrib\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == list_str) { - STUB_LOG_ERR("NULL value str"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (0 == attr_count) { - snprintf(list_str, max_length, "empty list"); - return SAI_STATUS_SUCCESS; - } - - for (ii = 0; ii < attr_count; ii++) { - assert(SAI_STATUS_SUCCESS == find_functionality_attrib_index(attr_list[ii].id, functionality_attr, &index)); - - sai_value_to_str(attr_list[ii].value, functionality_attr[index].type, MAX_VALUE_STR_LEN, value_str); - pos += snprintf(list_str + pos, - max_length - pos, - "#%u %s val:%s ", - ii, - functionality_attr[index].attrib_name, - value_str); - if (pos > max_length) { - break; - } - } - - return SAI_STATUS_SUCCESS; -} - -sai_status_t stub_object_to_type(sai_object_id_t object_id, sai_object_type_t type, uint32_t *data) -{ - stub_object_id_t *stub_object_id = (stub_object_id_t*)&object_id; - - if (NULL == data) { - STUB_LOG_ERR("NULL data value\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (type != stub_object_id->object_type) { - STUB_LOG_ERR("Expected object %s got %s\n", SAI_TYPE_STR(type), SAI_TYPE_STR(stub_object_id->object_type)); - return SAI_STATUS_INVALID_PARAMETER; - } - - *data = stub_object_id->data; - return SAI_STATUS_SUCCESS; -} - -sai_status_t stub_create_object(sai_object_type_t type, uint32_t data, sai_object_id_t *object_id) -{ - stub_object_id_t *stub_object_id = (stub_object_id_t*)object_id; - - if (NULL == object_id) { - STUB_LOG_ERR("NULL object id value\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (type >= SAI_OBJECT_TYPE_MAX) { - STUB_LOG_ERR("Unknown object type %d\n", type); - return SAI_STATUS_INVALID_PARAMETER; - } - - memset(stub_object_id, 0, sizeof(*stub_object_id)); - stub_object_id->data = data; - stub_object_id->object_type = type; - return SAI_STATUS_SUCCESS; -} - -static sai_status_t stub_fill_genericlist(size_t element_size, void *data, uint32_t count, void *list) -{ - /* all list objects have same field count in the beginning of the object, and then different data, - * so can be casted to one type */ - sai_object_list_t *objlist = list; - - if (NULL == data) { - STUB_LOG_ERR("NULL data value\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == list) { - STUB_LOG_ERR("NULL list value\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (0 == element_size) { - STUB_LOG_ERR("Zero element size\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (count > objlist->count) { - STUB_LOG_ERR("Insufficient list buffer size. Allocated %u needed %u\n", - objlist->count, count); - objlist->count = count; - return SAI_STATUS_BUFFER_OVERFLOW; - } - - objlist->count = count; - memcpy(objlist->list, data, count * element_size); - - return SAI_STATUS_SUCCESS; -} - -sai_status_t stub_fill_objlist(sai_object_id_t *data, uint32_t count, sai_object_list_t *list) -{ - return stub_fill_genericlist(sizeof(sai_object_id_t), (void*)data, count, (void*)list); -} - -sai_status_t stub_fill_u32list(uint32_t *data, uint32_t count, sai_u32_list_t *list) -{ - return stub_fill_genericlist(sizeof(uint32_t), (void*)data, count, (void*)list); -} - -sai_status_t stub_fill_s32list(int32_t *data, uint32_t count, sai_s32_list_t *list) -{ - return stub_fill_genericlist(sizeof(int32_t), (void*)data, count, (void*)list); -} - -sai_status_t stub_fill_vlanlist(sai_vlan_id_t *data, uint32_t count, sai_vlan_list_t *list) -{ - return stub_fill_genericlist(sizeof(sai_vlan_id_t), (void*)data, count, (void*)list); -} - -#define LOG_ENTRY_SIZE_MAX 1024 - -#ifndef _WIN32 -void sai_log_cb(sai_log_level_t severity, const char *module_name, char *msg) -{ - int level; - char *level_str; - - /* translate SDK log level to syslog level */ - switch (severity) { - case SAI_LOG_NOTICE: - level = LOG_NOTICE; - level_str = "NOTICE"; - break; - - case SAI_LOG_INFO: - level = LOG_INFO; - level_str = "INFO"; - break; - - case SAI_LOG_ERROR: - level = LOG_ERR; - level_str = "ERR"; - break; - - case SAI_LOG_WARN: - level = LOG_WARNING; - level_str = "WARNING"; - break; - - case SAI_LOG_DEBUG: - level = LOG_DEBUG; - level_str = "DEBUG"; - break; - - default: - level = LOG_DEBUG; - level_str = "DEBUG"; - break; - } - - syslog(level, "[%s.%s] %s", module_name, level_str, msg); -} -#else -void sai_log_cb(sai_log_level_t severity, const char *module_name, char *msg) -{ - UNREFERENCED_PARAMETER(severity); - UNREFERENCED_PARAMETER(module_name); - UNREFERENCED_PARAMETER(msg); -} -#endif - -void utils_log_vprint(const sai_log_level_t severity, const char *module_name, const char *p_str, va_list args) -{ - char buffer[LOG_ENTRY_SIZE_MAX]; - - vsnprintf(buffer, LOG_ENTRY_SIZE_MAX, p_str, args); - - sai_log_cb(severity, module_name, buffer); -} - -void utils_log(const sai_log_level_t severity, const char *module_name, const char *p_str, ...) -{ - va_list args; - - if (severity < SAI_LOG_INFO) { - return; - } - - va_start(args, p_str); - utils_log_vprint(severity, module_name, p_str, args); - va_end(args); -} diff --git a/stub/src/stub_sai_vlan.c b/stub/src/stub_sai_vlan.c deleted file mode 100644 index 878b19999..000000000 --- a/stub/src/stub_sai_vlan.c +++ /dev/null @@ -1,527 +0,0 @@ -/* - * Copyright (C) 2014. Mellanox Technologies, Ltd. ALL RIGHTS RESERVED. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT - * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS - * FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - * - * See the Apache Version 2.0 License for specific language governing - * permissions and limitations under the License. - * - */ - -#include "sai.h" -#include "stub_sai.h" - -#undef __MODULE__ -#define __MODULE__ SAI_VLAN - -#define vlan_id_range_ok(vlan_id) ((vlan_id)>=1 && (vlan_id)<=4095) - - -/* Storage layer data structures / variables to store the states */ -static int number_of_vlans; -struct __vlan* vlans = NULL; - -struct __vlan { - sai_vlan_id_t id; - int number_of_ports; - sai_vlan_port_t* port_list; -}; - - -static const sai_attribute_entry_t vlan_attribs[] = { - { SAI_VLAN_ATTR_MAX_LEARNED_ADDRESSES, false, false, true, true, - "Vlan Maximum number of learned MAC addresses", SAI_ATTR_VAL_TYPE_U32 - }, - { SAI_VLAN_ATTR_STP_INSTANCE, false, false, true, true, - "Vlan associated STP instance", SAI_ATTR_VAL_TYPE_U64 - }, - { END_FUNCTIONALITY_ATTRIBS_ID, false, false, false, false, - "", SAI_ATTR_VAL_TYPE_UNDETERMINED - } -}; - -sai_status_t stub_vlan_max_learned_addr_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_vlan_max_learned_addr_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); -sai_status_t stub_vlan_stp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg); -sai_status_t stub_vlan_stp_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg); - -static const sai_vendor_attribute_entry_t vlan_vendor_attribs[] = { - { SAI_VLAN_ATTR_MAX_LEARNED_ADDRESSES, - { false, false, true, true }, - { false, false, true, true }, - stub_vlan_max_learned_addr_get, NULL, - stub_vlan_max_learned_addr_set, NULL - }, - { SAI_VLAN_ATTR_STP_INSTANCE, - { false, false, true, true }, - { false, false, true, true }, - stub_vlan_stp_get, NULL, - stub_vlan_stp_set, NULL - }, -}; - -/* - * Routine Description: - * Create default VLAN and add all port into it. - */ -void db_init_vlan() -{ - int ii; - sai_object_id_t port; - - if (NULL != vlans) { - free(vlans); - } - - vlans = malloc(sizeof(struct __vlan)); - STUB_ASSERT(NULL != vlans); - - vlans[0].id = 1; - vlans[0].number_of_ports = PORT_NUMBER; - vlans[0].port_list = malloc(sizeof(sai_vlan_port_t) * PORT_NUMBER); - - for (ii = 0; ii < PORT_NUMBER; ++ii) { - stub_create_object(SAI_OBJECT_TYPE_PORT, ii, &port); - vlans[0].port_list[ii].port_id = port; - vlans[0].port_list[ii].tagging_mode = SAI_VLAN_PORT_UNTAGGED; - } - - number_of_vlans = 1; -} - -static void vlan_key_to_str(_In_ sai_vlan_id_t vlan_id, _Out_ char *key_str) -{ - snprintf(key_str, MAX_KEY_STR_LEN, "vlan %u", vlan_id); -} - -/* - * Routine Description: - * Set VLAN attribute Value - * - * Arguments: - * [in] vlan_id - VLAN id - * [in] attr - attribute - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_set_vlan_attribute(_In_ sai_vlan_id_t vlan_id, _In_ const sai_attribute_t *attr) -{ - const sai_object_key_t key = { .vlan_id = vlan_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - vlan_key_to_str(vlan_id, key_str); - return sai_set_attribute(&key, key_str, vlan_attribs, vlan_vendor_attribs, attr); -} - - -/* - * Routine Description: - * Get VLAN attribute Value - * - * Arguments: - * [in] vlan_id - VLAN id - * [in] attr_count - number of attributes - * [inout] attr_list - array of attributes - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_vlan_attribute(_In_ sai_vlan_id_t vlan_id, - _In_ uint32_t attr_count, - _Inout_ sai_attribute_t *attr_list) -{ - const sai_object_key_t key = { .vlan_id = vlan_id }; - char key_str[MAX_KEY_STR_LEN]; - - STUB_LOG_ENTER(); - - vlan_key_to_str(vlan_id, key_str); - return sai_get_attributes(&key, key_str, vlan_attribs, vlan_vendor_attribs, attr_count, attr_list); -} - - -/* - * Routine Description: - * Remove VLAN configuration (remove all VLANs). - * - * Arguments: - * None - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_all_vlans(void) -{ - STUB_LOG_NTC("Remove all vlan\n"); - - return SAI_STATUS_SUCCESS; -} - - -/* - * Routine Description: - * Create a VLAN - * - * Arguments: - * [in] vlan_id - VLAN id - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_create_vlan(_In_ sai_vlan_id_t vlan_id) -{ - char key_str[MAX_KEY_STR_LEN]; - int i; - - vlan_key_to_str(vlan_id, key_str); - STUB_LOG_NTC("Create vlan %s\n", key_str); - - // make sure the given vlan_id satisfies the spec - if (!vlan_id_range_ok(vlan_id)) { - STUB_LOG_ERR("vlan_id (%d) must satisfy 1 <= vlan_id <= 4094\n", vlan_id); - return SAI_STATUS_INVALID_VLAN_ID; - } - - // make sure the given vlan_id is available - for (i = 0; i < number_of_vlans; i++) { - if (vlans[i].id == vlan_id) { - STUB_LOG_WRN("Warning: given vlan_id (%d) already exsits.\n", vlan_id); - return SAI_STATUS_INVALID_VLAN_ID; - } - } - - // add new vlan - number_of_vlans++; - vlans = realloc(vlans, number_of_vlans * sizeof(struct __vlan)); - - if (vlans == NULL) { - STUB_LOG_ERR("Error: memory allocation for creating a new vlan failed.\n"); - return SAI_STATUS_NO_MEMORY; - } - - struct __vlan* v = &(vlans[number_of_vlans - 1]); - v->id = vlan_id; - v->number_of_ports = 0; - v->port_list = NULL; - - return SAI_STATUS_SUCCESS; -} - - -/* - * Routine Description: - * Remove a VLAN - * - * Arguments: - * [in] vlan_id - VLAN id - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_vlan(_In_ sai_vlan_id_t vlan_id) -{ - char key_str[MAX_KEY_STR_LEN]; - int i, index_removed_vlan = -1; - - vlan_key_to_str(vlan_id, key_str); - - // make sure the given vlan_id exists - for (i = 0; i < number_of_vlans; i++) { - if (vlans[i].id == vlan_id) { - index_removed_vlan = i; - break; - } - } - if (index_removed_vlan == -1) { - STUB_LOG_NTC("the given vlan id (%d) does not exist.\n", vlan_id); - return SAI_STATUS_INVALID_VLAN_ID; - } - - // delete the vlans[index_removed_vlan] - for (i = 0; i < number_of_vlans; i++) { - if (i > index_removed_vlan) { - vlans[i - 1] = vlans[i]; - } - } - number_of_vlans--; - vlans = realloc(vlans, sizeof(struct __vlan) * number_of_vlans); - // Note: realloc(ptr, 0) returns NULL, which is not an error - if (vlans == NULL && number_of_vlans > 0) { - STUB_LOG_ERR("Error: memory allocation for removing a vlan failed.\n"); - return SAI_STATUS_NO_MEMORY; - } - - STUB_LOG_NTC("Remove vlan %s\n", key_str); - - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Add Port to VLAN - * - * Arguments: - * [in] vlan_id - VLAN id - * [in] port_count - number of ports - * [in] port_list - pointer to membership structures - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_add_ports_to_vlan(_In_ sai_vlan_id_t vlan_id, - _In_ uint32_t port_count, - _In_ const sai_vlan_port_t* port_list) -{ - STUB_LOG_ENTER(); - - char key_str[MAX_KEY_STR_LEN]; - int i, index_target_vlan = -1; - - vlan_key_to_str(vlan_id, key_str); - - for (i = 0; i < number_of_vlans; i++) { - if (vlans[i].id == vlan_id) { - index_target_vlan = i; - break; - } - } - - if (index_target_vlan == -1) { - STUB_LOG_WRN("the given vlan id (%d) does not exist.\n", vlan_id); - return SAI_STATUS_INVALID_VLAN_ID; - } - - struct __vlan* v = &vlans[index_target_vlan]; - int old_size = v->number_of_ports, new_size = old_size + port_count; - v->port_list = realloc(v->port_list, new_size * sizeof(sai_vlan_port_t)); - - if (v->port_list == NULL) { - STUB_LOG_ERR("Error: memory allocation for removing a vlan failed.\n"); - return SAI_STATUS_NO_MEMORY; - } - - v->number_of_ports = new_size; - memcpy(v->port_list + old_size, port_list, port_count * sizeof(sai_vlan_port_t)); - - return SAI_STATUS_SUCCESS; -} - -static int remove_a_port_from_vlan(struct __vlan* v, sai_vlan_port_t port) -{ - int i, j; - int deleted = 0; - - for (i = 0; i < v->number_of_ports; i++) { - if (port.port_id == v->port_list[i].port_id) { - // delete this port - deleted = 1; - - for (j = i + 1; j < v->number_of_ports; j++) { - v->port_list[j - 1] = v->port_list[j]; - } - - (v->number_of_ports)--; - v->port_list = realloc(v->port_list, sizeof(sai_vlan_port_t) * v->number_of_ports); - - break; - } - } - - return deleted; -} - -/* - * Routine Description: - * Remove Port from VLAN - * - * Arguments: - * [in] vlan_id - VLAN id - * [in] port_count - number of ports - * [in] port_list - pointer to membership structures - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_remove_ports_from_vlan(_In_ sai_vlan_id_t vlan_id, - _In_ uint32_t port_count, - _In_ const sai_vlan_port_t* port_list) -{ - STUB_LOG_ENTER(); - - char key_str[MAX_KEY_STR_LEN]; - struct __vlan* v = NULL; - int i; - - vlan_key_to_str(vlan_id, key_str); - - for (i = 0; i < number_of_vlans; i++) { - if (vlans[i].id == vlan_id) { - v = &vlans[i]; - break; - } - } - - if (v == NULL) { - STUB_LOG_WRN("the given vlan id (%d) does not exist.\n", vlan_id); - return SAI_STATUS_INVALID_VLAN_ID; - } - - for (i = 0; i < (int)port_count; i++) { - int ret = remove_a_port_from_vlan(v, port_list[i]); - if (ret == 0) { - STUB_LOG_NTC("the given port (%d) does not belong to the given vlan (%d)\n", port_list[i].port_id, vlan_id); - } - } - - return SAI_STATUS_SUCCESS; -} - -/* - * Routine Description: - * Get vlan statistics counters. - * - * Arguments: - * [in] vlan_id - VLAN id - * [in] counter_ids - specifies the array of counter ids - * [in] number_of_counters - number of counters in the array - * [out] counters - array of resulting counter values. - * - * Return Values: - * SAI_STATUS_SUCCESS on success - * Failure status code on error - */ -sai_status_t stub_get_vlan_stats(_In_ sai_vlan_id_t vlan_id, - _In_ const sai_vlan_stat_counter_t *counter_ids, - _In_ uint32_t number_of_counters, - _Out_ uint64_t * counters) -{ - uint32_t ii; - - UNREFERENCED_PARAMETER(vlan_id); - UNREFERENCED_PARAMETER(number_of_counters); - - STUB_LOG_ENTER(); - - if (NULL == counter_ids) { - STUB_LOG_ERR("NULL counter ids array param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - if (NULL == counters) { - STUB_LOG_ERR("NULL counters array param\n"); - return SAI_STATUS_INVALID_PARAMETER; - } - - for (ii = 0; ii < number_of_counters; ii++) { - counters[ii] = 0; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Maximum number of learned MAC addresses [uint32_t] - * zero means learning limit disable. (default to zero). */ -sai_status_t stub_vlan_max_learned_addr_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - STUB_LOG_ENTER(); - - value->u32 = 0; - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* Maximum number of learned MAC addresses [uint32_t] - * zero means learning limit disable. (default to zero). */ -sai_status_t stub_vlan_max_learned_addr_set(_In_ const sai_object_key_t *key, - _In_ const sai_attribute_value_t *value, - void *arg) -{ - STUB_LOG_ENTER(); - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* STP Instance that the VLAN is associated to [sai_object_id_t] - * (default to default stp instance id)*/ -sai_status_t stub_vlan_stp_get(_In_ const sai_object_key_t *key, - _Inout_ sai_attribute_value_t *value, - _In_ uint32_t attr_index, - _Inout_ vendor_cache_t *cache, - void *arg) -{ - sai_status_t status; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_create_object(SAI_OBJECT_TYPE_STP_INSTANCE, 1, &value->oid))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -/* STP Instance that the VLAN is associated to [sai_object_id_t] - * (default to default stp instance id)*/ -sai_status_t stub_vlan_stp_set(_In_ const sai_object_key_t *key, _In_ const sai_attribute_value_t *value, void *arg) -{ - sai_status_t status; - uint32_t stp_id; - - STUB_LOG_ENTER(); - - if (SAI_STATUS_SUCCESS != (status = stub_object_to_type(value->oid, SAI_OBJECT_TYPE_STP_INSTANCE, &stp_id))) { - return status; - } - - STUB_LOG_EXIT(); - return SAI_STATUS_SUCCESS; -} - -const sai_vlan_api_t vlan_api = { - stub_create_vlan, - stub_remove_vlan, - stub_set_vlan_attribute, - stub_get_vlan_attribute, - stub_add_ports_to_vlan, - stub_remove_ports_from_vlan, - stub_remove_all_vlans, - stub_get_vlan_stats, - NULL -};