From 804690815db1d38a6ec35a3ccf9bd2d5be0fcbd8 Mon Sep 17 00:00:00 2001 From: Oleksandr Ivantsiv Date: Wed, 13 Sep 2023 14:25:14 -0700 Subject: [PATCH 1/6] [CRM][DASH] Add the possibility of querying availability for OIDs. (#1245) - Add support for DASH resource availability to VirtualSwitchSaiInterface. --- meta/Meta.cpp | 7 +++++++ unittest/meta/TestMetaDash.cpp | 26 ++++++++++++++++++++++++++ vslib/VirtualSwitchSaiInterface.cpp | 13 +++++++++++++ 3 files changed, 46 insertions(+) diff --git a/meta/Meta.cpp b/meta/Meta.cpp index b844c6f7a..62d374fca 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -801,6 +801,13 @@ sai_status_t Meta::objectTypeGetAvailability( break; + case SAI_ATTR_VALUE_TYPE_OBJECT_ID: + { + sai_object_type_t ot = objectTypeQuery(attrList[idx].value.oid); + PARAMETER_CHECK_OBJECT_TYPE_VALID(ot); + PARAMETER_CHECK_OID_EXISTS(attrList[idx].value.oid, ot); + break; + } default: META_LOG_THROW(*mdp, "value type %s not supported yet, FIXME!", diff --git a/unittest/meta/TestMetaDash.cpp b/unittest/meta/TestMetaDash.cpp index 2a25c1b50..5fec7d475 100644 --- a/unittest/meta/TestMetaDash.cpp +++ b/unittest/meta/TestMetaDash.cpp @@ -138,6 +138,26 @@ static void remove_eni(Meta &m, sai_object_id_t eni) EXPECT_EQ(SAI_STATUS_SUCCESS, m.remove((sai_object_type_t)SAI_OBJECT_TYPE_ENI, eni)); } +TEST(Meta, dash_get_availability) +{ + Meta m(std::make_shared()); + + sai_object_id_t switchid = create_switch(m); + + sai_attribute_t attr; + attr.id = SAI_DASH_ACL_RULE_ATTR_DASH_ACL_GROUP_ID; + attr.value.oid = 0; + + uint64_t count = 0; + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.objectTypeGetAvailability(switchid, (sai_object_type_t)SAI_OBJECT_TYPE_DASH_ACL_RULE, 1, &attr, &count)); + + attr.id = SAI_DASH_ACL_RULE_ATTR_DASH_ACL_GROUP_ID; + attr.value.oid = 0xFFFFFFF; + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.objectTypeGetAvailability(switchid, (sai_object_type_t)SAI_OBJECT_TYPE_DASH_ACL_RULE, 1, &attr, &count)); +} + + TEST(Meta, quad_dash_direction_lookup) { Meta m(std::make_shared()); @@ -714,6 +734,12 @@ TEST(Meta, quad_dash_acl_rule) attr.value.s32 = SAI_DASH_ACL_RULE_ACTION_DENY_AND_CONTINUE; EXPECT_EQ(SAI_STATUS_SUCCESS, m.set((sai_object_type_t)SAI_OBJECT_TYPE_DASH_ACL_RULE, acl, &attr)); + attr.id = SAI_DASH_ACL_RULE_ATTR_DASH_ACL_GROUP_ID; + attr.value.oid = acl; + uint64_t count = 0; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.objectTypeGetAvailability(switchid, (sai_object_type_t)SAI_OBJECT_TYPE_DASH_ACL_RULE, 1, &attr, &count)); + EXPECT_EQ(SAI_STATUS_SUCCESS, m.remove((sai_object_type_t)SAI_OBJECT_TYPE_DASH_ACL_RULE, acl)); remove_counter(m, counter); EXPECT_EQ(SAI_STATUS_SUCCESS, m.remove((sai_object_type_t)SAI_OBJECT_TYPE_DASH_ACL_GROUP, group)); diff --git a/vslib/VirtualSwitchSaiInterface.cpp b/vslib/VirtualSwitchSaiInterface.cpp index 99583b3db..050cb106e 100644 --- a/vslib/VirtualSwitchSaiInterface.cpp +++ b/vslib/VirtualSwitchSaiInterface.cpp @@ -847,6 +847,19 @@ sai_status_t VirtualSwitchSaiInterface::objectTypeGetAvailability( *count = 512; return SAI_STATUS_SUCCESS; } + else if ((objectType == (sai_object_type_t)SAI_OBJECT_TYPE_VNET) || + (objectType == (sai_object_type_t)SAI_OBJECT_TYPE_ENI) || + (objectType == (sai_object_type_t)SAI_OBJECT_TYPE_ENI_ETHER_ADDRESS_MAP_ENTRY) || + (objectType == (sai_object_type_t)SAI_OBJECT_TYPE_INBOUND_ROUTING_ENTRY) || + (objectType == (sai_object_type_t)SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY) || + (objectType == (sai_object_type_t)SAI_OBJECT_TYPE_PA_VALIDATION_ENTRY) || + (objectType == (sai_object_type_t)SAI_OBJECT_TYPE_OUTBOUND_CA_TO_PA_ENTRY) || + (objectType == (sai_object_type_t)SAI_OBJECT_TYPE_DASH_ACL_GROUP) || + (objectType == (sai_object_type_t)SAI_OBJECT_TYPE_DASH_ACL_RULE)) + { + *count = 100000; + return SAI_STATUS_SUCCESS; + } return SAI_STATUS_NOT_SUPPORTED; } From cfa8da4c6221170de6601d5edc25d9d3e23c4947 Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Sat, 16 Sep 2023 13:08:05 +0200 Subject: [PATCH 2/6] Add extra parameter to pass vendor LDFLAGS for libsai.so (#1291) Since vendor libsai.so may require some extra libs we need to pass this as a param for linker --- configure.ac | 7 ++++++- saidiscovery/Makefile.am | 2 +- saisdkdump/Makefile.am | 2 +- syncd/Makefile.am | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index b8ab35c0a..c3bc259a3 100644 --- a/configure.ac +++ b/configure.ac @@ -207,12 +207,17 @@ CXXFLAGS="$SAVED_FLAGS" AC_SUBST(CXXFLAGS_COMMON) +AC_ARG_WITH(extra-libsai-ldflags, +[ --with-extra-libsai-ldflags=FLAGS + extra libsai.so flags for vendor library], +[AC_SUBST(EXTRA_LIBSAI_LDFLAGS, "${withval}")]) + AC_SUBST(SAIINC, "-I\$(top_srcdir)/SAI/inc -I\$(top_srcdir)/SAI/experimental -I\$(top_srcdir)/SAI/meta") AM_COND_IF([SYNCD], [ AM_COND_IF([SAIVS], [], [ SAVED_FLAGS="$CXXFLAGS" -CXXFLAGS="-Xlinker --no-as-needed -lsai -I$srcdir/SAI/inc -I$srcdir/SAI/experimental -I$srcdir/SAI/meta" +CXXFLAGS="-Xlinker --no-as-needed -lsai -I$srcdir/SAI/inc -I$srcdir/SAI/experimental -I$srcdir/SAI/meta $EXTRA_LIBSAI_LDFLAGS" AC_CHECK_FUNCS(sai_query_api_version, [ AC_MSG_CHECKING([SAI headers API version and library version check]) AC_TRY_RUN([ diff --git a/saidiscovery/Makefile.am b/saidiscovery/Makefile.am index cfb055bb8..3e2515faa 100644 --- a/saidiscovery/Makefile.am +++ b/saidiscovery/Makefile.am @@ -13,4 +13,4 @@ saidiscovery_SOURCES = saidiscovery.cpp saidiscovery_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) saidiscovery_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) saidiscovery_LDADD = -lhiredis -lswsscommon $(top_srcdir)/syncd/libSyncd.a $(SAILIB) -lpthread \ - -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) + -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) $(EXTRA_LIBSAI_LDFLAGS) diff --git a/saisdkdump/Makefile.am b/saisdkdump/Makefile.am index 3ad9ed882..07618ad88 100644 --- a/saisdkdump/Makefile.am +++ b/saisdkdump/Makefile.am @@ -11,4 +11,4 @@ endif saisdkdump_SOURCES = saisdkdump.cpp saisdkdump_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) saisdkdump_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) -saisdkdump_LDADD = -lhiredis -lswsscommon $(SAILIB) -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) +saisdkdump_LDADD = -lhiredis -lswsscommon $(SAILIB) -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) $(EXTRA_LIBSAI_LDFLAGS) diff --git a/syncd/Makefile.am b/syncd/Makefile.am index c0d15b9eb..d34131156 100644 --- a/syncd/Makefile.am +++ b/syncd/Makefile.am @@ -68,7 +68,7 @@ endif syncd_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) syncd_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) $(CFLAGS_ASAN) syncd_LDADD = libSyncd.a $(top_srcdir)/lib/libSaiRedis.a -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta \ - -ldl -lhiredis -lswsscommon $(SAILIB) -lpthread -lzmq $(CODE_COVERAGE_LIBS) + -ldl -lhiredis -lswsscommon $(SAILIB) -lpthread -lzmq $(CODE_COVERAGE_LIBS) $(EXTRA_LIBSAI_LDFLAGS) syncd_LDFLAGS = $(LDFLAGS_ASAN) -rdynamic if SAITHRIFT From edf6597d1056a2d0b268fbfec4c73bebb6964522 Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Wed, 20 Sep 2023 00:33:12 +0200 Subject: [PATCH 3/6] [submodule] Update SAI submodule to v1.13 (#1292) Add needed changes and new files required by new SAI version --- SAI | 2 +- lib/Makefile.am | 4 +++- lib/sai_redis.h | 2 ++ lib/sai_redis_acl.cpp | 2 ++ lib/sai_redis_dash_meter.cpp | 28 ++++++++++++++++++++++++++++ lib/sai_redis_interfacequery.cpp | 2 ++ lib/sai_redis_nexthop.cpp | 2 ++ lib/sai_redis_port.cpp | 2 ++ lib/sai_redis_router_interface.cpp | 2 ++ lib/sai_redis_twamp.cpp | 9 +++++++++ meta/Meta.cpp | 6 ++++++ meta/SaiSerialize.cpp | 12 ++++++++++++ syncd/SwitchNotifications.h | 3 +++ tests/BCM56850.pl | 9 +++++++++ tests/BCM56850/relaxed.rec | 14 ++++++++++++++ unittest/meta/TestSaiSerialize.cpp | 3 +++ vslib/Makefile.am | 4 +++- vslib/sai_vs.h | 2 ++ vslib/sai_vs_acl.cpp | 2 ++ vslib/sai_vs_dash_meter.cpp | 28 ++++++++++++++++++++++++++++ vslib/sai_vs_interfacequery.cpp | 2 ++ vslib/sai_vs_nexthop.cpp | 2 ++ vslib/sai_vs_port.cpp | 2 ++ vslib/sai_vs_router_interface.cpp | 2 ++ vslib/sai_vs_twamp.cpp | 9 +++++++++ 25 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 lib/sai_redis_dash_meter.cpp create mode 100644 lib/sai_redis_twamp.cpp create mode 100644 tests/BCM56850/relaxed.rec create mode 100644 vslib/sai_vs_dash_meter.cpp create mode 100644 vslib/sai_vs_twamp.cpp diff --git a/SAI b/SAI index 1761e2f72..7f7a7587d 160000 --- a/SAI +++ b/SAI @@ -1 +1 @@ -Subproject commit 1761e2f721ecc5295898b457465cf3abc3adaf96 +Subproject commit 7f7a7587debf6b393118b29ca71c2d00722bb885 diff --git a/lib/Makefile.am b/lib/Makefile.am index ba6594d88..46471b89b 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -88,7 +88,9 @@ libsairedis_la_SOURCES = \ sai_redis_ipsec.cpp \ sai_redis_my_mac.cpp \ sai_redis_ars.cpp \ - sai_redis_ars_profile.cpp + sai_redis_ars_profile.cpp \ + sai_redis_twamp.cpp \ + sai_redis_dash_meter.cpp libSaiRedis_a_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) libSaiRedis_a_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) diff --git a/lib/sai_redis.h b/lib/sai_redis.h index eb03c331d..061ef280b 100644 --- a/lib/sai_redis.h +++ b/lib/sai_redis.h @@ -72,6 +72,8 @@ PRIVATE extern const sai_vlan_api_t redis_vlan_api; PRIVATE extern const sai_wred_api_t redis_wred_api; PRIVATE extern const sai_my_mac_api_t redis_my_mac_api; PRIVATE extern const sai_ipsec_api_t redis_ipsec_api; +PRIVATE extern const sai_twamp_api_t redis_twamp_api; +PRIVATE extern const sai_dash_meter_api_t redis_dash_meter_api; PRIVATE extern std::shared_ptr redis_sai; diff --git a/lib/sai_redis_acl.cpp b/lib/sai_redis_acl.cpp index 576358fff..9c1ebf7d8 100644 --- a/lib/sai_redis_acl.cpp +++ b/lib/sai_redis_acl.cpp @@ -6,6 +6,7 @@ REDIS_GENERIC_QUAD(ACL_COUNTER,acl_counter); REDIS_GENERIC_QUAD(ACL_RANGE,acl_range); REDIS_GENERIC_QUAD(ACL_TABLE_GROUP,acl_table_group); REDIS_GENERIC_QUAD(ACL_TABLE_GROUP_MEMBER,acl_table_group_member); +REDIS_GENERIC_QUAD(ACL_TABLE_CHAIN_GROUP,acl_table_chain_group) const sai_acl_api_t redis_acl_api = { @@ -15,4 +16,5 @@ const sai_acl_api_t redis_acl_api = { REDIS_GENERIC_QUAD_API(acl_range) REDIS_GENERIC_QUAD_API(acl_table_group) REDIS_GENERIC_QUAD_API(acl_table_group_member) + REDIS_GENERIC_QUAD_API(acl_table_chain_group) }; diff --git a/lib/sai_redis_dash_meter.cpp b/lib/sai_redis_dash_meter.cpp new file mode 100644 index 000000000..5b22e7f27 --- /dev/null +++ b/lib/sai_redis_dash_meter.cpp @@ -0,0 +1,28 @@ +#include "sai_redis.h" + +REDIS_GENERIC_QUAD(METER_BUCKET, meter_bucket); +REDIS_BULK_CREATE(METER_BUCKET, meter_buckets); +REDIS_BULK_REMOVE(METER_BUCKET, meter_buckets); + +REDIS_GENERIC_QUAD(METER_BUCKET, meter_policy); +REDIS_BULK_CREATE(METER_BUCKET, meter_policys); +REDIS_BULK_REMOVE(METER_BUCKET, meter_policys); + +REDIS_GENERIC_QUAD(METER_BUCKET, meter_rule); +REDIS_BULK_CREATE(METER_BUCKET, meter_rules); +REDIS_BULK_REMOVE(METER_BUCKET, meter_rules); + +const sai_dash_meter_api_t redis_dash_meter_api = { + + REDIS_GENERIC_QUAD_API(meter_bucket) + redis_bulk_create_meter_buckets, + redis_bulk_remove_meter_buckets, + + REDIS_GENERIC_QUAD_API(meter_policy) + redis_bulk_create_meter_policys, + redis_bulk_remove_meter_policys, + + REDIS_GENERIC_QUAD_API(meter_rule) + redis_bulk_create_meter_rules, + redis_bulk_remove_meter_rules, +}; diff --git a/lib/sai_redis_interfacequery.cpp b/lib/sai_redis_interfacequery.cpp index 5c5a1057c..e18c084e0 100644 --- a/lib/sai_redis_interfacequery.cpp +++ b/lib/sai_redis_interfacequery.cpp @@ -82,11 +82,13 @@ static sai_apis_t redis_apis = { API(generic_programmable), API(ars), API(ars_profile), + API(twamp), API(bmtor), API(dash_acl), API(dash_direction_lookup), API(dash_eni), API(dash_inbound_routing), + API(dash_meter), API(dash_outbound_ca_to_pa), API(dash_outbound_routing), API(dash_vnet), diff --git a/lib/sai_redis_nexthop.cpp b/lib/sai_redis_nexthop.cpp index 21dcca47d..4d7a91399 100644 --- a/lib/sai_redis_nexthop.cpp +++ b/lib/sai_redis_nexthop.cpp @@ -1,8 +1,10 @@ #include "sai_redis.h" REDIS_GENERIC_QUAD(NEXT_HOP,next_hop); +REDIS_BULK_QUAD(NEXT_HOP,next_hop); const sai_next_hop_api_t redis_next_hop_api = { REDIS_GENERIC_QUAD_API(next_hop) + REDIS_BULK_QUAD_API(next_hop) }; diff --git a/lib/sai_redis_port.cpp b/lib/sai_redis_port.cpp index a4b220dff..f6c28f35b 100644 --- a/lib/sai_redis_port.cpp +++ b/lib/sai_redis_port.cpp @@ -15,6 +15,7 @@ REDIS_GENERIC_QUAD(PORT_CONNECTOR,port_connector); REDIS_GENERIC_STATS(PORT,port); REDIS_GENERIC_STATS(PORT_POOL,port_pool); REDIS_BULK_QUAD(PORT, ports); +REDIS_BULK_QUAD(PORT_SERDES, port_serdeses); const sai_port_api_t redis_port_api = { @@ -28,4 +29,5 @@ const sai_port_api_t redis_port_api = { REDIS_GENERIC_QUAD_API(port_connector) REDIS_GENERIC_QUAD_API(port_serdes) REDIS_BULK_QUAD_API(ports) + REDIS_BULK_QUAD_API(port_serdeses) }; diff --git a/lib/sai_redis_router_interface.cpp b/lib/sai_redis_router_interface.cpp index feab7584e..1e77427e7 100644 --- a/lib/sai_redis_router_interface.cpp +++ b/lib/sai_redis_router_interface.cpp @@ -2,9 +2,11 @@ REDIS_GENERIC_QUAD(ROUTER_INTERFACE,router_interface); REDIS_GENERIC_STATS(ROUTER_INTERFACE,router_interface); +REDIS_BULK_QUAD(ROUTER_INTERFACE,router_interfaces); const sai_router_interface_api_t redis_router_interface_api = { REDIS_GENERIC_QUAD_API(router_interface) REDIS_GENERIC_STATS_API(router_interface) + REDIS_BULK_QUAD_API(router_interfaces) }; diff --git a/lib/sai_redis_twamp.cpp b/lib/sai_redis_twamp.cpp new file mode 100644 index 000000000..83e1c4cf4 --- /dev/null +++ b/lib/sai_redis_twamp.cpp @@ -0,0 +1,9 @@ +#include "sai_redis.h" + +REDIS_GENERIC_QUAD(TWAMP_SESSION,twamp_session); +REDIS_GENERIC_STATS(TWAMP_SESSION,twamp_session); + +const sai_twamp_api_t redis_twamp_api = { + REDIS_GENERIC_QUAD_API(twamp_session) + REDIS_GENERIC_STATS_API(twamp_session) +}; diff --git a/meta/Meta.cpp b/meta/Meta.cpp index 62d374fca..db1c6cc71 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -3800,6 +3800,12 @@ sai_status_t Meta::meta_generic_validation_create( // maybe we can let it go here? if (attrs.find(md.attrid) != attrs.end()) { + if (md.isconditionrelaxed) + { + META_LOG_WARN(md, "conditional, but condition was not met, this attribute is not required, but passed (relaxed condition)"); + continue; + } + META_LOG_ERROR(md, "conditional, but condition was not met, this attribute is not required, but passed"); return SAI_STATUS_INVALID_PARAMETER; diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index 5d6f36c04..af039526f 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -489,6 +489,18 @@ sai_status_t transfer_attribute( RETURN_ON_ERROR(transfer_list(src_attr.value.ipprefixlist, dst_attr.value.ipprefixlist, countOnly)); break; + case SAI_ATTR_VALUE_TYPE_PORT_FREQUENCY_OFFSET_PPM_LIST: + RETURN_ON_ERROR(transfer_list(src_attr.value.portfrequencyoffsetppmlist, dst_attr.value.portfrequencyoffsetppmlist, countOnly)); + break; + + case SAI_ATTR_VALUE_TYPE_PORT_SNR_LIST: + RETURN_ON_ERROR(transfer_list(src_attr.value.portsnrlist, dst_attr.value.portsnrlist, countOnly)); + break; + + case SAI_ATTR_VALUE_TYPE_ACL_CHAIN_LIST: + RETURN_ON_ERROR(transfer_list(src_attr.value.aclchainlist, dst_attr.value.aclchainlist, countOnly)); + break; + default: SWSS_LOG_THROW("sai attr value %s is not implemented, FIXME", sai_serialize_attr_value_type(serialization_type).c_str()); } diff --git a/syncd/SwitchNotifications.h b/syncd/SwitchNotifications.h index e5789e241..afc64c9e6 100644 --- a/syncd/SwitchNotifications.h +++ b/syncd/SwitchNotifications.h @@ -89,11 +89,14 @@ namespace syncd .on_ipsec_sa_status_change = nullptr, .on_nat_event = &Slot::onNatEvent, .on_packet_event = nullptr, + .on_port_host_tx_ready = nullptr, .on_port_state_change = &Slot::onPortStateChange, .on_queue_pfc_deadlock = &Slot::onQueuePfcDeadlock, + .on_switch_asic_sdk_health_event = nullptr, .on_switch_shutdown_request = &Slot::onSwitchShutdownRequest, .on_switch_state_change = &Slot::onSwitchStateChange, .on_tam_event = nullptr, + .on_twamp_session_event = nullptr, }) { } virtual ~Slot() {} diff --git a/tests/BCM56850.pl b/tests/BCM56850.pl index b3b371568..7e5eab90c 100755 --- a/tests/BCM56850.pl +++ b/tests/BCM56850.pl @@ -811,8 +811,17 @@ sub test_acl_counter_match } } +sub test_relaxed +{ + fresh_start; + + play "relaxed.rec"; + play "relaxed.rec", 0; +} + # RUN TESTS +test_relaxed; test_acl_counter_match; test_neighbor_lag; test_lag_member; diff --git a/tests/BCM56850/relaxed.rec b/tests/BCM56850/relaxed.rec new file mode 100644 index 000000000..db5c08e58 --- /dev/null +++ b/tests/BCM56850/relaxed.rec @@ -0,0 +1,14 @@ +2018-11-14.19:34:17.416379|a|INIT_VIEW +2018-11-14.19:34:17.419035|A|SAI_STATUS_SUCCESS +2018-11-14.19:34:17.420345|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true +2018-11-14.19:34:17.420634|g|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID=oid:0x0 +2018-11-14.19:34:26.138403|G|SAI_STATUS_SUCCESS|SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID=oid:0x3000000000022 +2018-11-14.19:34:26.138714|c|SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x600000000058a|SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID=oid:0x3000000000022|SAI_ROUTER_INTERFACE_ATTR_TYPE=SAI_ROUTER_INTERFACE_TYPE_LOOPBACK +2018-11-14.19:34:26.147205|g|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_PORT_LIST=32:oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0 +2018-11-14.19:34:26.151676|G|SAI_STATUS_SUCCESS|SAI_SWITCH_ATTR_PORT_LIST=32:oid:0x1000000000002,oid:0x1000000000003,oid:0x1000000000004,oid:0x1000000000005,oid:0x1000000000006,oid:0x1000000000007,oid:0x1000000000008,oid:0x1000000000009,oid:0x100000000000a,oid:0x100000000000b,oid:0x100000000000c,oid:0x100000000000d,oid:0x100000000000e,oid:0x100000000000f,oid:0x1000000000010,oid:0x1000000000011,oid:0x1000000000012,oid:0x1000000000013,oid:0x1000000000014,oid:0x1000000000015,oid:0x1000000000016,oid:0x1000000000017,oid:0x1000000000018,oid:0x1000000000019,oid:0x100000000001a,oid:0x100000000001b,oid:0x100000000001c,oid:0x100000000001d,oid:0x100000000001e,oid:0x100000000001f,oid:0x1000000000020,oid:0x1000000000021 +2018-11-14.19:34:27.462885|c|SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x60000000005d7|SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID=oid:0x3000000000022|SAI_ROUTER_INTERFACE_ATTR_TYPE=SAI_ROUTER_INTERFACE_TYPE_LOOPBACK +2018-11-14.19:34:27.463151|c|SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000005d8|SAI_TUNNEL_ATTR_TYPE=SAI_TUNNEL_TYPE_IPINIP|SAI_TUNNEL_ATTR_OVERLAY_INTERFACE=oid:0x60000000005d7|SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE=oid:0x600000000058a|SAI_TUNNEL_ATTR_DECAP_ECN_MODE=SAI_TUNNEL_DECAP_ECN_MODE_COPY_FROM_OUTER|SAI_TUNNEL_ATTR_DECAP_TTL_MODE=SAI_TUNNEL_TTL_MODE_PIPE_MODEL|SAI_TUNNEL_ATTR_DECAP_DSCP_MODE=SAI_TUNNEL_DSCP_MODE_PIPE_MODEL +2018-11-14.19:34:27.463380|c|SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b0000000005d9|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID=oid:0x3000000000022|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE=SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2MP|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE=SAI_TUNNEL_TYPE_IPINIP|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID=oid:0x2a0000000005d8|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP=10.0.0.0|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP=0.0.0.0 +2018-11-14.19:34:27.463380|c|SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b0000000005da|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID=oid:0x3000000000022|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE=SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_MP2MP|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE=SAI_TUNNEL_TYPE_IPINIP|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID=oid:0x2a0000000005d8|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP=10.0.0.0|SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP=0.0.0.0 +2018-11-14.19:34:26.317753|a|APPLY_VIEW +2018-11-14.19:34:26.319120|A|SAI_STATUS_SUCCESS diff --git a/unittest/meta/TestSaiSerialize.cpp b/unittest/meta/TestSaiSerialize.cpp index fc68cf7dc..5fec3b436 100644 --- a/unittest/meta/TestSaiSerialize.cpp +++ b/unittest/meta/TestSaiSerialize.cpp @@ -123,6 +123,9 @@ TEST(SaiSerialize, sai_serialize_attr_value) case SAI_ATTR_VALUE_TYPE_SEGMENT_LIST: case SAI_ATTR_VALUE_TYPE_TLV_LIST: case SAI_ATTR_VALUE_TYPE_MAP_LIST: + case SAI_ATTR_VALUE_TYPE_PORT_FREQUENCY_OFFSET_PPM_LIST: + case SAI_ATTR_VALUE_TYPE_PORT_SNR_LIST: + case SAI_ATTR_VALUE_TYPE_ACL_CHAIN_LIST: continue; default: diff --git a/vslib/Makefile.am b/vslib/Makefile.am index 9c24689c9..c498acad2 100644 --- a/vslib/Makefile.am +++ b/vslib/Makefile.am @@ -121,7 +121,9 @@ libsaivs_la_SOURCES = \ sai_vs_my_mac.cpp \ sai_vs_ipsec.cpp \ sai_vs_ars.cpp \ - sai_vs_ars_profile.cpp + sai_vs_ars_profile.cpp \ + sai_vs_twamp.cpp \ + sai_vs_dash_meter.cpp libSaiVS_a_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) libSaiVS_a_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) diff --git a/vslib/sai_vs.h b/vslib/sai_vs.h index 58aea859a..485f9a559 100644 --- a/vslib/sai_vs.h +++ b/vslib/sai_vs.h @@ -72,6 +72,8 @@ PRIVATE extern const sai_vlan_api_t vs_vlan_api; PRIVATE extern const sai_wred_api_t vs_wred_api; PRIVATE extern const sai_my_mac_api_t vs_my_mac_api; PRIVATE extern const sai_ipsec_api_t vs_ipsec_api; +PRIVATE extern const sai_twamp_api_t vs_twamp_api; +PRIVATE extern const sai_dash_meter_api_t vs_dash_meter_api; PRIVATE extern std::shared_ptr vs_sai; diff --git a/vslib/sai_vs_acl.cpp b/vslib/sai_vs_acl.cpp index 0b75400ad..2fea15e0b 100644 --- a/vslib/sai_vs_acl.cpp +++ b/vslib/sai_vs_acl.cpp @@ -6,6 +6,7 @@ VS_GENERIC_QUAD(ACL_COUNTER,acl_counter); VS_GENERIC_QUAD(ACL_RANGE,acl_range); VS_GENERIC_QUAD(ACL_TABLE_GROUP,acl_table_group); VS_GENERIC_QUAD(ACL_TABLE_GROUP_MEMBER,acl_table_group_member); +VS_GENERIC_QUAD(ACL_TABLE_CHAIN_GROUP,acl_table_chain_group) const sai_acl_api_t vs_acl_api = { @@ -15,4 +16,5 @@ const sai_acl_api_t vs_acl_api = { VS_GENERIC_QUAD_API(acl_range) VS_GENERIC_QUAD_API(acl_table_group) VS_GENERIC_QUAD_API(acl_table_group_member) + VS_GENERIC_QUAD_API(acl_table_chain_group) }; diff --git a/vslib/sai_vs_dash_meter.cpp b/vslib/sai_vs_dash_meter.cpp new file mode 100644 index 000000000..2773e1f5a --- /dev/null +++ b/vslib/sai_vs_dash_meter.cpp @@ -0,0 +1,28 @@ +#include "sai_vs.h" + +VS_GENERIC_QUAD(METER_BUCKET, meter_bucket); +VS_BULK_CREATE(METER_BUCKET, meter_buckets); +VS_BULK_REMOVE(METER_BUCKET, meter_buckets); + +VS_GENERIC_QUAD(METER_BUCKET, meter_policy); +VS_BULK_CREATE(METER_BUCKET, meter_policys); +VS_BULK_REMOVE(METER_BUCKET, meter_policys); + +VS_GENERIC_QUAD(METER_BUCKET, meter_rule); +VS_BULK_CREATE(METER_BUCKET, meter_rules); +VS_BULK_REMOVE(METER_BUCKET, meter_rules); + +const sai_dash_meter_api_t vs_dash_meter_api = { + + VS_GENERIC_QUAD_API(meter_bucket) + vs_bulk_create_meter_buckets, + vs_bulk_remove_meter_buckets, + + VS_GENERIC_QUAD_API(meter_policy) + vs_bulk_create_meter_policys, + vs_bulk_remove_meter_policys, + + VS_GENERIC_QUAD_API(meter_rule) + vs_bulk_create_meter_rules, + vs_bulk_remove_meter_rules, +}; diff --git a/vslib/sai_vs_interfacequery.cpp b/vslib/sai_vs_interfacequery.cpp index 5a7167a61..338e0298c 100644 --- a/vslib/sai_vs_interfacequery.cpp +++ b/vslib/sai_vs_interfacequery.cpp @@ -80,11 +80,13 @@ static sai_apis_t vs_apis = { API(generic_programmable), API(ars), API(ars_profile), + API(twamp), API(bmtor), API(dash_acl), API(dash_direction_lookup), API(dash_eni), API(dash_inbound_routing), + API(dash_meter), API(dash_outbound_ca_to_pa), API(dash_outbound_routing), API(dash_vnet), diff --git a/vslib/sai_vs_nexthop.cpp b/vslib/sai_vs_nexthop.cpp index 914233532..fdab7ab0e 100644 --- a/vslib/sai_vs_nexthop.cpp +++ b/vslib/sai_vs_nexthop.cpp @@ -1,8 +1,10 @@ #include "sai_vs.h" VS_GENERIC_QUAD(NEXT_HOP,next_hop); +VS_BULK_QUAD(NEXT_HOP,next_hop); const sai_next_hop_api_t vs_next_hop_api = { VS_GENERIC_QUAD_API(next_hop) + VS_BULK_QUAD_API(next_hop) }; diff --git a/vslib/sai_vs_port.cpp b/vslib/sai_vs_port.cpp index b75e7e985..54e4a7116 100644 --- a/vslib/sai_vs_port.cpp +++ b/vslib/sai_vs_port.cpp @@ -15,6 +15,7 @@ VS_GENERIC_QUAD(PORT_SERDES,port_serdes); VS_GENERIC_STATS(PORT,port); VS_GENERIC_STATS(PORT_POOL,port_pool); VS_BULK_QUAD(PORT,ports); +VS_BULK_QUAD(PORT_SERDES, port_serdeses); const sai_port_api_t vs_port_api = { @@ -30,4 +31,5 @@ const sai_port_api_t vs_port_api = { VS_GENERIC_QUAD_API(port_serdes) VS_BULK_QUAD_API(ports) + VS_BULK_QUAD_API(port_serdeses) }; diff --git a/vslib/sai_vs_router_interface.cpp b/vslib/sai_vs_router_interface.cpp index 810813683..df8bfeaa2 100644 --- a/vslib/sai_vs_router_interface.cpp +++ b/vslib/sai_vs_router_interface.cpp @@ -2,9 +2,11 @@ VS_GENERIC_QUAD(ROUTER_INTERFACE,router_interface); VS_GENERIC_STATS(ROUTER_INTERFACE,router_interface); +VS_BULK_QUAD(ROUTER_INTERFACE,router_interfaces); const sai_router_interface_api_t vs_router_interface_api = { VS_GENERIC_QUAD_API(router_interface) VS_GENERIC_STATS_API(router_interface) + VS_BULK_QUAD_API(router_interfaces) }; diff --git a/vslib/sai_vs_twamp.cpp b/vslib/sai_vs_twamp.cpp new file mode 100644 index 000000000..5a62b790a --- /dev/null +++ b/vslib/sai_vs_twamp.cpp @@ -0,0 +1,9 @@ +#include "sai_vs.h" + +VS_GENERIC_QUAD(TWAMP_SESSION,twamp_session); +VS_GENERIC_STATS(TWAMP_SESSION,twamp_session); + +const sai_twamp_api_t vs_twamp_api = { + VS_GENERIC_QUAD_API(twamp_session) + VS_GENERIC_STATS_API(twamp_session) +}; From 31bd92a32f940f263314ddf9578929529af1dbce Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Thu, 21 Sep 2023 17:57:01 +0200 Subject: [PATCH 4/6] Add log for git revision (#1293) Will help debugging and identification of specific version --- configure.ac | 8 ++++++++ lib/RedisRemoteSaiInterface.cpp | 4 ++++ syncd/Syncd.cpp | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/configure.ac b/configure.ac index c3bc259a3..6f5854b93 100644 --- a/configure.ac +++ b/configure.ac @@ -264,6 +264,14 @@ AC_CHECK_FUNCS(sai_bulk_object_clear_stats sai_bulk_object_get_stats) CXXFLAGS="$SAVED_FLAGS" ]) +AC_DEFINE([SAIREDIS_GIT_REVISION], + "[m4_esyscmd([echo -n $(git rev-parse --short HEAD || echo 0000000)])]", + [sairedis git revision information]) + +AC_DEFINE([SAI_GIT_REVISION], + "[m4_esyscmd([echo -n $(cd SAI && git rev-parse --short HEAD || echo 0000000)])]", + [SAI git revision information]) + AC_OUTPUT(Makefile meta/Makefile lib/Makefile diff --git a/lib/RedisRemoteSaiInterface.cpp b/lib/RedisRemoteSaiInterface.cpp index 4e0e284b9..a789235e4 100644 --- a/lib/RedisRemoteSaiInterface.cpp +++ b/lib/RedisRemoteSaiInterface.cpp @@ -14,6 +14,8 @@ #include "meta/PerformanceIntervalTimer.h" #include "meta/Globals.h" +#include "config.h" + #include using namespace sairedis; @@ -37,6 +39,8 @@ RedisRemoteSaiInterface::RedisRemoteSaiInterface( { SWSS_LOG_ENTER(); + SWSS_LOG_NOTICE("sairedis git revision %s, SAI git revision: %s", SAIREDIS_GIT_REVISION, SAI_GIT_REVISION); + m_initialized = false; initialize(0, nullptr); diff --git a/syncd/Syncd.cpp b/syncd/Syncd.cpp index 103d8820a..2e560d5d1 100644 --- a/syncd/Syncd.cpp +++ b/syncd/Syncd.cpp @@ -28,6 +28,8 @@ #include "vslib/saivs.h" +#include "config.h" + #include #include @@ -63,6 +65,8 @@ Syncd::Syncd( { SWSS_LOG_ENTER(); + SWSS_LOG_NOTICE("sairedis git revision %s, SAI git revision: %s", SAIREDIS_GIT_REVISION, SAI_GIT_REVISION); + setSaiApiLogLevel(); SWSS_LOG_NOTICE("command line: %s", m_commandLineOptions->getCommandLineString().c_str()); From c22b76b09c5818a5c887e7255dd233f0cdad6580 Mon Sep 17 00:00:00 2001 From: JunhongMao <134556118+JunhongMao@users.noreply.github.com> Date: Mon, 25 Sep 2023 06:23:08 -0400 Subject: [PATCH 5/6] [VOQ][saidump] Enhance saidump with new option -r to parser the JSON file and displays/format the right output (#1288) Why I did it Fix issue: sonic-net/sonic-buildimage#13561 The existing saidump use https://github.com/sonic-net/sonic-swss-common/blob/master/common/table_dump.lua script which loops the ASIC_DB more than 5 seconds and blocks other processes access. This solution uses the redis-db SAVE option to save the snapshot of DB each time and recover later, instead of looping through each entry in the table. Related PRs: sonic-net/sonic-utilities#2972 sonic-net/sonic-buildimage#16466 --- saidump/saidump.cpp | 214 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 209 insertions(+), 5 deletions(-) diff --git a/saidump/saidump.cpp b/saidump/saidump.cpp index 6a3321e58..4677f48aa 100644 --- a/saidump/saidump.cpp +++ b/saidump/saidump.cpp @@ -2,6 +2,10 @@ #include #include #include +#include +#include +#include +#include extern "C" { #include @@ -10,32 +14,44 @@ extern "C" { #include "swss/table.h" #include "meta/sai_serialize.h" #include "sairediscommon.h" +#include #include // TODO split to multiple cpp using namespace swss; +using json = nlohmann::json; + +// Default value: 100 MB +constexpr int64_t RDB_JSON_MAX_SIZE = 1024 * 1024 * 100; struct CmdOptions { bool skipAttributes; bool dumpTempView; bool dumpGraph; + std::string rdbJsonFile; + uint64_t rdbJSonSizeLimit; }; -CmdOptions g_cmdOptions; -std::map g_oid_map; + +static CmdOptions g_cmdOptions; +static std::map g_oid_map; void printUsage() { SWSS_LOG_ENTER(); - std::cout << "Usage: saidump [-t] [-g] [-h]" << std::endl; + std::cout << "Usage: saidump [-t] [-g] [-r] [-m] [-h]" << std::endl; std::cout << " -t --tempView:" << std::endl; std::cout << " Dump temp view" << std::endl; std::cout << " -g --dumpGraph:" << std::endl; std::cout << " Dump current graph" << std::endl; + std::cout << " -r --rdb:" << std::endl; + std::cout << " Dump by parsing the RDB JSON file, which is created by rdbtools based on Redis dump.rdb that is generated by Redis SAVE command" << std::endl; + std::cout << " -m --max:" << std::endl; + std::cout << " Config the the RDB JSON file's max size in MB, which is optional with default value 100MB" << std::endl; std::cout << " -h --help:" << std::endl; std::cout << " Print out this message" << std::endl; } @@ -48,8 +64,10 @@ CmdOptions handleCmdLine(int argc, char **argv) options.dumpTempView = false; options.dumpGraph = false; + options.rdbJSonSizeLimit = RDB_JSON_MAX_SIZE; - const char* const optstring = "gth"; + const char* const optstring = "gtr:m:h"; + uint64_t result = 0; while (true) { @@ -57,6 +75,8 @@ CmdOptions handleCmdLine(int argc, char **argv) { { "dumpGraph", no_argument, 0, 'g' }, { "tempView", no_argument, 0, 't' }, + { "rdb", required_argument, 0, 'r' }, + { "max", required_argument, 0, 'm' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 } }; @@ -82,6 +102,33 @@ CmdOptions handleCmdLine(int argc, char **argv) options.dumpTempView = true; break; + case 'r': + SWSS_LOG_NOTICE("Dumping from %s", optarg); + options.rdbJsonFile = std::string(optarg); + break; + + case 'm': + if(!regex_match(optarg, std::regex(R"([+]?\d+)"))) //only positive numeric chars are valid, such as 3984, +3232, etc. + { + SWSS_LOG_WARN("invalid option -m %s", optarg); + printUsage(); + exit(EXIT_SUCCESS); + } + + result = strtoull(optarg, NULL, 0); + + if((errno == ERANGE && result == ULLONG_MAX) || result == 0 || result >= INT_MAX) + { + SWSS_LOG_WARN("invalid option -m %s", optarg); + printUsage(); + exit(EXIT_SUCCESS); + } + + options.rdbJSonSizeLimit = result * 1024 * 1024; + SWSS_LOG_NOTICE("Configure the RDB JSON MAX size to %llu MB", options.rdbJSonSizeLimit / 1024 / 1024); + + break; + case 'h': printUsage(); exit(EXIT_SUCCESS); @@ -399,7 +446,153 @@ void dumpGraph(const TableDump& td) std::cout << "}" << std::endl; } -int main(int argc, char ** argv) +#define SWSS_LOG_ERROR_AND_STDERR(format, ...) { fprintf(stderr, format"\n", ##__VA_ARGS__); SWSS_LOG_ERROR(format, ##__VA_ARGS__); } + +/** + * @brief Process the input JSON file to make sure it's a valid JSON file for the JSON library. + */ +static sai_status_t preProcessFile(const std::string file_name) +{ + SWSS_LOG_ENTER(); + + std::ifstream input_file(file_name); + + if (!input_file.is_open()) + { + SWSS_LOG_ERROR_AND_STDERR("Failed to open the input file %s.", file_name.c_str()); + return SAI_STATUS_FAILURE; + } + + input_file.seekg(0, std::ios::end); // Move to the end of the file + uint64_t file_size = input_file.tellg(); // Get the current position + SWSS_LOG_NOTICE("Get %s's size %" PRIu64 " Bytes, limit: %" PRIu64 " MB.", file_name.c_str(), file_size, g_cmdOptions.rdbJSonSizeLimit / 1024 / 1024); + + if (file_size >= g_cmdOptions.rdbJSonSizeLimit) + { + SWSS_LOG_ERROR_AND_STDERR("Get %s's size failure or its size %" PRIu64 " >= %" PRIu64 " MB.", file_name.c_str(), file_size, g_cmdOptions.rdbJSonSizeLimit / 1024 / 1024); + return SAI_STATUS_FAILURE; + } + + input_file.seekg(0); // Move to the begin of the file + + // Read the content of the input file into a string + std::string content((std::istreambuf_iterator(input_file)), + std::istreambuf_iterator()); + + content = regex_replace(content, std::regex("\\},\\{\\r"), ","); + + std::ofstream outputFile(file_name); + + if (!outputFile.is_open()) + { + SWSS_LOG_ERROR_AND_STDERR("Failed to open the output file %s.", file_name.c_str()); + return SAI_STATUS_FAILURE; + } + + //Remove the 1st and last char to make sure its format is same as previous output + if (content.size() >= 2 && content[0] == '[' && content[content.length()-1] == ']') + { + outputFile << content.substr(1, content.size()-2); + } + else + { + outputFile << content; + } + + return SAI_STATUS_SUCCESS; +} + +static sai_status_t dumpFromRedisRdbJson(const std::string file_name) +{ + SWSS_LOG_ENTER(); + + std::ifstream input_file(file_name); + + if (!input_file.is_open()) + { + SWSS_LOG_ERROR_AND_STDERR("The file %s does not exist for dumping from Redis RDB JSON file.", file_name.c_str()); + return SAI_STATUS_FAILURE; + } + + try + { + // Parse the JSON data from the file (validation) + nlohmann::json jsonData; + input_file >> jsonData; + + SWSS_LOG_DEBUG("JSON file is valid."); + + for (json::iterator it = jsonData.begin(); it != jsonData.end(); ++it) + { + json jj_key = it.key(); + + std::string keystr = jj_key; + std::string item_name = keystr; + size_t pos = keystr.find_first_of(":"); + + if (pos != std::string::npos) + { + if(ASIC_STATE_TABLE != keystr.substr(0, pos)) // filter out non ASIC_STATE + { + continue; + } + + item_name = keystr.substr(pos + 1); + + if (item_name.find(":") != std::string::npos) + { + item_name.replace(item_name.find_first_of(":"), 1, " "); + } + } + else + { + continue; + } + + std::cout << item_name << " " << std::endl; + + json jj = it.value(); + + if (!it->is_object()) + { + continue; + } + + TableMap map; + + for (json::iterator itt = jj.begin(); itt != jj.end(); ++itt) + { + if (itt.key() != "NULL") + { + map[itt.key()] = itt.value(); + } + } + + constexpr size_t LINE_IDENT = 4; + size_t max_len = get_max_attr_len(map); + std::string str_indent = pad_string("", LINE_IDENT); + + for (const auto&field: map) + { + std::cout << str_indent << pad_string(field.first, max_len) << " : "; + std::cout << field.second << std::endl; + } + + std::cout << std::endl; + } + + return SAI_STATUS_SUCCESS; + } + catch (std::exception &ex) + { + SWSS_LOG_ERROR_AND_STDERR("JSON file %s is invalid.", file_name.c_str()); + SWSS_LOG_ERROR_AND_STDERR("JSON parsing error: %s.", ex.what()); + } + + return SAI_STATUS_FAILURE; +} + +int main(int argc, char **argv) { swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); @@ -411,6 +604,17 @@ int main(int argc, char ** argv) g_cmdOptions = handleCmdLine(argc, argv); + + if (g_cmdOptions.rdbJsonFile.size() > 0) + { + if (SAI_STATUS_FAILURE == preProcessFile(g_cmdOptions.rdbJsonFile)) + { + return EXIT_FAILURE; + } + + return dumpFromRedisRdbJson(g_cmdOptions.rdbJsonFile); + } + swss::DBConnector db("ASIC_DB", 0); std::string table = ASIC_STATE_TABLE; From 9263397112a16808e026a29bc4940f2bdd0c9058 Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Fri, 29 Sep 2023 10:15:22 +0200 Subject: [PATCH 6/6] [syncd] Change sai discovery log priority to info (#1296) When multiple asic are present and multiple ports are created then those log lines willpollute logs for no reason --- syncd/SaiDiscovery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncd/SaiDiscovery.cpp b/syncd/SaiDiscovery.cpp index a241fabdb..7ac75abca 100644 --- a/syncd/SaiDiscovery.cpp +++ b/syncd/SaiDiscovery.cpp @@ -313,7 +313,7 @@ void SaiDiscovery::setApiLogLevel( if (status == SAI_STATUS_SUCCESS) { - SWSS_LOG_NOTICE("Setting SAI loglevel %s on %s", + SWSS_LOG_INFO("setting SAI loglevel %s on %s", sai_serialize_log_level(logLevel).c_str(), sai_serialize_api((sai_api_t)api).c_str()); }