From b0ee63d0f10d452ed08545b40d70a17ffce2dcf3 Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Wed, 8 Apr 2020 13:59:41 +0200 Subject: [PATCH] [syncd] [vs] [sairedis] Add support for bulk api in init view (#591) * [syncd] [vs] [sairedis] Add support for bulk api in init view * Fix spelling --- lib/src/Makefile.am | 10 +- lib/src/RedisRemoteSaiInterface.cpp | 19 ++- syncd/Syncd.cpp | 59 ++++++++- syncd/Syncd.h | 6 + syncd/TimerWatchdog.h | 5 +- syncd/lanemap.ini | 34 ++++++ syncd/testprofile.ini | 4 + syncd/tests.cpp | 179 ++++++++++++++++++++++++++-- vslib/src/Makefile.am | 11 +- 9 files changed, 302 insertions(+), 25 deletions(-) create mode 100644 syncd/lanemap.ini create mode 100644 syncd/testprofile.ini diff --git a/lib/src/Makefile.am b/lib/src/Makefile.am index 70f10fe2f3d3..b8b1ceedba06 100644 --- a/lib/src/Makefile.am +++ b/lib/src/Makefile.am @@ -8,7 +8,8 @@ endif lib_LTLIBRARIES = libsairedis.la -libsairedis_la_SOURCES = \ +noinst_LIBRARIES = libSaiRedis.a +libSaiRedis_a_SOURCES = \ Context.cpp \ ContextConfigContainer.cpp \ ContextConfig.cpp \ @@ -31,7 +32,9 @@ libsairedis_la_SOURCES = \ Recorder.cpp \ RedisRemoteSaiInterface.cpp \ Utils.cpp \ - SkipRecordAttrContainer.cpp \ + SkipRecordAttrContainer.cpp + +libsairedis_la_SOURCES = \ sai_redis_acl.cpp \ sai_redis_bfd.cpp \ sai_redis_bmtor.cpp \ @@ -77,9 +80,10 @@ libsairedis_la_SOURCES = \ sai_redis_vlan.cpp \ sai_redis_wred.cpp +libSaiRedis_a_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) libsairedis_la_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) -libsairedis_la_LIBADD = -lhiredis -lswsscommon +libsairedis_la_LIBADD = -lhiredis -lswsscommon libSaiRedis.a bin_PROGRAMS = tests diff --git a/lib/src/RedisRemoteSaiInterface.cpp b/lib/src/RedisRemoteSaiInterface.cpp index c457b52db4ac..56bc91157891 100644 --- a/lib/src/RedisRemoteSaiInterface.cpp +++ b/lib/src/RedisRemoteSaiInterface.cpp @@ -1064,6 +1064,8 @@ sai_status_t RedisRemoteSaiInterface::bulkRemove( // value: object_attrs std::string key = serializedObjectType + ":" + std::to_string(entries.size()); + m_recorder->recordBulkGenericRemove(serializedObjectType, entries); + m_redisChannel->set(key, entries, REDIS_ASIC_STATE_COMMAND_BULK_REMOVE); return waitForBulkResponse(SAI_COMMON_API_BULK_REMOVE, (uint32_t)serialized_object_ids.size(), object_statuses); @@ -1291,7 +1293,11 @@ sai_status_t RedisRemoteSaiInterface::bulkSet( * with previous */ - std::string key = sai_serialize_object_type(object_type) + ":" + std::to_string(entries.size()); + auto serializedObjectType = sai_serialize_object_type(object_type); + + std::string key = serializedObjectType + ":" + std::to_string(entries.size()); + + m_recorder->recordBulkGenericSet(serializedObjectType, entries); m_redisChannel->set(key, entries, REDIS_ASIC_STATE_COMMAND_BULK_SET); @@ -1364,6 +1370,15 @@ sai_status_t RedisRemoteSaiInterface::bulkCreate( { auto entry = SaiAttributeList::serialize_attr_list(object_type, attr_count[idx], attr_list[idx], false); + if (entry.empty()) + { + // make sure that we put object into db + // even if there are no attributes set + swss::FieldValueTuple null("NULL", "NULL"); + + entry.push_back(null); + } + std::string str_attr = joinFieldValues(entry); swss::FieldValueTuple fvtNoStatus(serialized_object_ids[idx] , str_attr); @@ -1381,7 +1396,7 @@ sai_status_t RedisRemoteSaiInterface::bulkCreate( // value: object_attrs std::string key = str_object_type + ":" + std::to_string(entries.size()); - // TODO record + m_recorder->recordBulkGenericCreate(str_object_type, entries); m_redisChannel->set(key, entries, REDIS_ASIC_STATE_COMMAND_BULK_CREATE); diff --git a/syncd/Syncd.cpp b/syncd/Syncd.cpp index 9ed2cd2fd84a..08b576b89b26 100644 --- a/syncd/Syncd.cpp +++ b/syncd/Syncd.cpp @@ -573,12 +573,6 @@ sai_status_t Syncd::processBulkQuadEvent( { SWSS_LOG_ENTER(); - if (isInitViewMode()) - { - SWSS_LOG_THROW("bulk api (%s) is not supported in init view mode, FIXME", - sai_serialize_common_api(api).c_str()); - } - const std::string& key = kfvKey(kco); // objectType:count std::string strObjectType = key.substr(0, key.find(":")); @@ -644,6 +638,11 @@ sai_status_t Syncd::processBulkQuadEvent( } } + if (isInitViewMode()) + { + return processBulkQuadEventInInitViewMode(objectType, objectIds, api, attributes); + } + auto info = sai_metadata_get_object_type_info(objectType); if (info->isobjectid) @@ -656,6 +655,54 @@ sai_status_t Syncd::processBulkQuadEvent( } } +sai_status_t Syncd::processBulkQuadEventInInitViewMode( + _In_ sai_object_type_t objectType, + _In_ const std::vector &object_ids, + _In_ sai_common_api_t api, + _In_ const std::vector> &attributes) +{ + SWSS_LOG_ENTER(); + + auto info = sai_metadata_get_object_type_info(objectType); + + switch (api) + { + case SAI_COMMON_API_BULK_CREATE: + case SAI_COMMON_API_BULK_REMOVE: + case SAI_COMMON_API_BULK_SET: + + if (info->isnonobjectid) + { + sendApiResponse(api, SAI_STATUS_SUCCESS); + return SAI_STATUS_SUCCESS; + } + + switch (objectType) + { + case SAI_OBJECT_TYPE_SWITCH: + case SAI_OBJECT_TYPE_PORT: + case SAI_OBJECT_TYPE_SCHEDULER_GROUP: + case SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP: + + SWSS_LOG_THROW("%s is not supported in init view mode", + sai_serialize_object_type(objectType).c_str()); + + default: + + sendApiResponse(api, SAI_STATUS_SUCCESS); + return SAI_STATUS_SUCCESS; + } + + case SAI_COMMON_API_BULK_GET: + SWSS_LOG_THROW("GET bulk api is not implemented in init view mode, FIXME"); + + default: + + SWSS_LOG_THROW("common bulk api (%s) is not implemented in init view mode", + sai_serialize_common_api(api).c_str()); + } +} + sai_status_t Syncd::processBulkEntry( _In_ sai_object_type_t objectType, _In_ const std::vector &objectIds, diff --git a/syncd/Syncd.h b/syncd/Syncd.h index 96d6258a45c5..47977ee83743 100644 --- a/syncd/Syncd.h +++ b/syncd/Syncd.h @@ -155,6 +155,12 @@ namespace syncd _In_ sai_common_api_t api, _In_ const std::vector> &attributes); + sai_status_t processBulkQuadEventInInitViewMode( + _In_ sai_object_type_t objectType, + _In_ const std::vector &object_ids, + _In_ sai_common_api_t api, + _In_ const std::vector> &attributes); + sai_status_t processOid( _In_ sai_object_type_t objectType, _In_ const std::string &strObjectId, diff --git a/syncd/TimerWatchdog.h b/syncd/TimerWatchdog.h index 79eebbac8394..0e891f56c619 100644 --- a/syncd/TimerWatchdog.h +++ b/syncd/TimerWatchdog.h @@ -1,5 +1,4 @@ -#ifndef __TIMER_WATCHDOG_H__ -#define __TIMER_WATCHDOG_H__ +#pragma once #include #include @@ -56,5 +55,3 @@ class TimerWatchdog Callback m_callback; }; - -#endif // __TIMER_WATCHDOG_H__ diff --git a/syncd/lanemap.ini b/syncd/lanemap.ini new file mode 100644 index 000000000000..a59777233667 --- /dev/null +++ b/syncd/lanemap.ini @@ -0,0 +1,34 @@ +; comment +# comment +eth0:29,30,31,32 +eth1:25,26,27,28 +eth2:37,38,39,40 +eth3:33,34,35,36 +eth4:41,42,43,44 +eth5:45,46,47,48 +eth6:5,6,7,8 +eth7:1,2,3,4 +eth8:9,10,11,12 +eth9:13,14,15,16 +eth10:21,22,23,24 +eth11:17,18,19,20 +eth12:249,50,51,52 +eth13:353,54,55,56 +eth14:461,62,63,64 +eth15:557,58,59,60 +eth16:665,66,67,68 +eth17:769,70,71,72 +eth18:877,78,79,80 +eth19:973,74,75,76 +eth20:105,106,107,108 +eth21:109,110,111,112 +eth22:117,118,119,120 +eth23:113,114,115,116 +eth24:121,122,123,124 +eth25:125,126,127,128 +eth26:85,86,87,88 +eth27:81,82,83,84 +eth28:89,90,91,92 +eth29:93,94,95,96 +eth30:97,98,99,100 +eth31:101,102,103,104 diff --git a/syncd/testprofile.ini b/syncd/testprofile.ini new file mode 100644 index 000000000000..34c43a62f561 --- /dev/null +++ b/syncd/testprofile.ini @@ -0,0 +1,4 @@ +SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin +SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin +SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 +SAI_VS_INTERFACE_LANE_MAP_FILE=lanemap.ini diff --git a/syncd/tests.cpp b/syncd/tests.cpp index c2d8f70bf4d4..c3ce27c7482d 100644 --- a/syncd/tests.cpp +++ b/syncd/tests.cpp @@ -1,9 +1,13 @@ #include +#include extern "C" { #include } +#include "../lib/inc/Sai.h" +#include "Syncd.h" +#include "MetadataLogger.h" #include "sairedis.h" #include "sairediscommon.h" @@ -26,6 +30,9 @@ extern "C" { #include #include +using namespace syncd; + + // TODO remove when SAI will introduce bulk APIs to those objects sai_status_t sai_bulk_create_fdb_entry( _In_ uint32_t object_count, @@ -225,13 +232,11 @@ void test_bulk_next_hop_group_member_create() { SWSS_LOG_ENTER(); - swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); sai_reinit(); // auto consumerThreads = new std::thread(bulk_nhgm_consumer_worker); - swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); sai_status_t status; @@ -337,11 +342,9 @@ void test_bulk_fdb_create() { SWSS_LOG_ENTER(); - swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); sai_reinit(); - swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); sai_status_t status; @@ -466,11 +469,9 @@ void test_bulk_route_set() { SWSS_LOG_ENTER(); - swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); sai_reinit(); - swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); sai_status_t status; @@ -610,13 +611,177 @@ void test_bulk_route_set() ASSERT_SUCCESS("Failed to bulk remove route entry"); } +#define CHECK_STATUS(x) \ + if (status != SAI_STATUS_SUCCESS) { exit(1); } + +void syncdThread() +{ + SWSS_LOG_ENTER(); + + MetadataLogger::initialize(); + + auto vendorSai = std::make_shared(); + + bool isWarmStart = false; + + auto commandLineOptions = std::make_shared(); + + commandLineOptions->m_enableTempView = true; + commandLineOptions->m_enableUnittests = false; + commandLineOptions->m_disableExitSleep = true; + commandLineOptions->m_profileMapFile = "testprofile.ini"; + + auto syncd = std::make_shared(vendorSai, commandLineOptions, isWarmStart); + + SWSS_LOG_WARN("starting run"); + syncd->run(); +} + +void test_bulk_route_create() +{ + SWSS_LOG_ENTER(); + + clearDB(); + + auto syncd = std::make_shared(syncdThread); + + sleep(2); + + auto sairedis = std::make_shared(); + + sai_status_t status = sairedis->initialize(0, &test_services); + + CHECK_STATUS(status); + + sai_object_id_t switchId; + + sai_attribute_t attrs[1]; + + // enable recording + + attrs[0].id = SAI_REDIS_SWITCH_ATTR_RECORD; + attrs[0].value.booldata = true; + + status = sairedis->set(SAI_OBJECT_TYPE_SWITCH, SAI_NULL_OBJECT_ID, attrs); + CHECK_STATUS(status); + + // init view + + attrs[0].id = SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD; + attrs[0].value.s32 = SAI_REDIS_NOTIFY_SYNCD_INIT_VIEW; + + status = sairedis->set(SAI_OBJECT_TYPE_SWITCH, SAI_NULL_OBJECT_ID, attrs); + CHECK_STATUS(status); + + // apply view + + attrs[0].id = SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD; + attrs[0].value.s32 = SAI_REDIS_NOTIFY_SYNCD_APPLY_VIEW; + + status = sairedis->set(SAI_OBJECT_TYPE_SWITCH, SAI_NULL_OBJECT_ID, attrs); + CHECK_STATUS(status); + + // init view + + attrs[0].id = SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD; + attrs[0].value.s32 = SAI_REDIS_NOTIFY_SYNCD_INIT_VIEW; + + status = sairedis->set(SAI_OBJECT_TYPE_SWITCH, SAI_NULL_OBJECT_ID, attrs); + CHECK_STATUS(status); + + // create switch + + attrs[0].id = SAI_SWITCH_ATTR_INIT_SWITCH; + attrs[0].value.booldata = true; + + status = sairedis->create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, attrs); + CHECK_STATUS(status); + + attrs[0].id = SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID; + status = sairedis->get(SAI_OBJECT_TYPE_SWITCH, switchId, 1, attrs); + CHECK_STATUS(status); + + sai_object_id_t vr = attrs[0].value.oid; + + // create routes bulk routes in init view mode + + std::vector> route_attrs; + std::vector route_attrs_array; + std::vector route_attrs_count; + std::vector routes; + //std::vector attrs; + + uint32_t count = 3; + + for (uint32_t i = 0; i < count; ++i) + { + sai_route_entry_t route_entry; + + route_entry.destination.addr_family = SAI_IP_ADDR_FAMILY_IPV4; + route_entry.destination.addr.ip4 = htonl(0x0a000000 | i); + route_entry.destination.mask.ip4 = htonl(0xffffffff); + route_entry.vr_id = vr; + route_entry.switch_id = switchId; + route_entry.destination.addr_family = SAI_IP_ADDR_FAMILY_IPV4; + + routes.push_back(route_entry); + + std::vector list; // no attributes + + route_attrs.push_back(list); + route_attrs_count.push_back(0); + } + + for (size_t j = 0; j < route_attrs.size(); j++) + { + route_attrs_array.push_back(route_attrs[j].data()); + } + + std::vector statuses(count); + + status = sairedis->bulkCreate( + count, + routes.data(), + route_attrs_count.data(), + route_attrs_array.data(), + SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, + statuses.data()); + + CHECK_STATUS(status); + + // create single route in init view + + sai_route_entry_t route; + route.destination.addr_family = SAI_IP_ADDR_FAMILY_IPV4; + route.destination.addr.ip4 = htonl(0x0b000000); + route.destination.mask.ip4 = htonl(0xffffffff); + route.vr_id = vr; + route.switch_id = switchId; + route.destination.addr_family = SAI_IP_ADDR_FAMILY_IPV4; + + status = sairedis->create(&route, 0, nullptr); + CHECK_STATUS(status); + + // apply view + + attrs[0].id = SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD; + attrs[0].value.s32 = SAI_REDIS_NOTIFY_SYNCD_APPLY_VIEW; + + status = sairedis->set(SAI_OBJECT_TYPE_SWITCH, SAI_NULL_OBJECT_ID, attrs); + CHECK_STATUS(status); + + SWSS_LOG_ERROR("sleep"); + + sleep(10000); +} + int main() { swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); SWSS_LOG_ENTER(); -// swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_INFO); + swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); try { diff --git a/vslib/src/Makefile.am b/vslib/src/Makefile.am index 39814f4919b7..5a7b3648d9a4 100644 --- a/vslib/src/Makefile.am +++ b/vslib/src/Makefile.am @@ -8,7 +8,8 @@ endif lib_LTLIBRARIES = libsaivs.la -libsaivs_la_SOURCES = \ +noinst_LIBRARIES = libSaiVS.a +libSaiVS_a_SOURCES = \ ../../lib/src/NotificationFdbEvent.cpp \ ../../lib/src/Notification.cpp \ ../../lib/src/NotificationPortStateChange.cpp \ @@ -44,7 +45,9 @@ libsaivs_la_SOURCES = \ SelectableFd.cpp \ SwitchState.cpp \ SwitchBCM56850.cpp \ - SwitchMLNX2700.cpp \ + SwitchMLNX2700.cpp + +libsaivs_la_SOURCES = \ sai_vs_fdb.cpp \ sai_vs_hostintf.cpp \ sai_vs_interfacequery.cpp \ @@ -91,8 +94,10 @@ libsaivs_la_SOURCES = \ sai_vs_vlan.cpp \ sai_vs_wred.cpp +libSaiVS_a_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) + libsaivs_la_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) -libsaivs_la_LIBADD = -lhiredis -lswsscommon +libsaivs_la_LIBADD = -lhiredis -lswsscommon libSaiVS.a bin_PROGRAMS = tests