├── .artifactignore ├── .azure-pipelines ├── build-docker-sonic-vs-template.yml ├── build-swss-template.yml ├── build-template.yml ├── build_and_install_module.sh ├── docker-sonic-vs │ ├── Dockerfile │ └── start.sh └── test-docker-sonic-vs-template.yml ├── .github ├── codeql │ └── codeql-config.yml └── workflows │ ├── codeql-analysis.yml │ └── semgrep.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── Makefile.am ├── README.md ├── autoclean.sh ├── autogen.sh ├── azsyslog.conf ├── azure-pipelines.yml ├── configure.ac ├── debian ├── changelog ├── compat ├── control ├── libsaimetadata-dev.dirs ├── libsaimetadata-dev.install ├── libsaimetadata-dev.links ├── libsaimetadata.dirs ├── libsaimetadata.install ├── libsairedis-dev.dirs ├── libsairedis-dev.install ├── libsairedis-dev.links ├── libsairedis.dirs ├── libsairedis.install ├── libsaivs-dev.dirs ├── libsaivs-dev.install ├── libsaivs-dev.links ├── libsaivs.dirs ├── libsaivs.install ├── python-pysairedis.dirs ├── python-pysairedis.install ├── python3-pysairedis.dirs ├── python3-pysairedis.install ├── rules ├── syncd-rpc.dirs ├── syncd-rpc.init ├── syncd-rpc.install ├── syncd-vs.dirs ├── syncd-vs.init ├── syncd-vs.install ├── syncd.dirs ├── syncd.init ├── syncd.install └── syncd.links ├── lgtm.yml ├── lib ├── Channel.cpp ├── Channel.h ├── ClientConfig.cpp ├── ClientConfig.h ├── ClientSai.cpp ├── ClientSai.h ├── ClientServerSai.cpp ├── ClientServerSai.h ├── Context.cpp ├── Context.h ├── ContextConfig.cpp ├── ContextConfig.h ├── ContextConfigContainer.cpp ├── ContextConfigContainer.h ├── Makefile.am ├── OidIndexGenerator.h ├── Recorder.cpp ├── Recorder.h ├── RedisChannel.cpp ├── RedisChannel.h ├── RedisRemoteSaiInterface.cpp ├── RedisRemoteSaiInterface.h ├── RedisVidIndexGenerator.cpp ├── RedisVidIndexGenerator.h ├── RemoteSaiInterface.h ├── Sai.cpp ├── Sai.h ├── SaiInternal.h ├── ServerConfig.cpp ├── ServerConfig.h ├── ServerSai.cpp ├── ServerSai.h ├── SkipRecordAttrContainer.cpp ├── SkipRecordAttrContainer.h ├── Switch.cpp ├── Switch.h ├── SwitchConfig.cpp ├── SwitchConfig.h ├── SwitchConfigContainer.cpp ├── SwitchConfigContainer.h ├── SwitchContainer.cpp ├── SwitchContainer.h ├── Utils.cpp ├── Utils.h ├── VirtualObjectIdManager.cpp ├── VirtualObjectIdManager.h ├── ZeroMQChannel.cpp ├── ZeroMQChannel.h ├── client_config.json ├── context_config.json ├── sairedis.h ├── sairediscommon.h └── tests.cpp ├── m4 ├── ax_python3_devel.m4 └── python3.m4 ├── meta ├── AttrKeyMap.cpp ├── AttrKeyMap.h ├── DummySaiInterface.cpp ├── DummySaiInterface.h ├── Globals.cpp ├── Globals.h ├── Makefile.am ├── Meta.cpp ├── Meta.h ├── MetaKeyHasher.cpp ├── MetaKeyHasher.h ├── MetaTestSaiInterface.cpp ├── MetaTestSaiInterface.h ├── Notification.cpp ├── Notification.h ├── NotificationBfdSessionStateChange.cpp ├── NotificationBfdSessionStateChange.h ├── NotificationFactory.cpp ├── NotificationFactory.h ├── NotificationFdbEvent.cpp ├── NotificationFdbEvent.h ├── NotificationHaScopeEvent.cpp ├── NotificationHaScopeEvent.h ├── NotificationHaSetEvent.cpp ├── NotificationHaSetEvent.h ├── NotificationIcmpEchoSessionStateChange.cpp ├── NotificationIcmpEchoSessionStateChange.h ├── NotificationNatEvent.cpp ├── NotificationNatEvent.h ├── NotificationPortHostTxReadyEvent.cpp ├── NotificationPortHostTxReadyEvent.h ├── NotificationPortStateChange.cpp ├── NotificationPortStateChange.h ├── NotificationQueuePfcDeadlock.cpp ├── NotificationQueuePfcDeadlock.h ├── NotificationSwitchAsicSdkHealthEvent.cpp ├── NotificationSwitchAsicSdkHealthEvent.h ├── NotificationSwitchShutdownRequest.cpp ├── NotificationSwitchShutdownRequest.h ├── NotificationSwitchStateChange.cpp ├── NotificationSwitchStateChange.h ├── NotificationTamTelTypeConfigChange.cpp ├── NotificationTamTelTypeConfigChange.h ├── NotificationTwampSessionEvent.cpp ├── NotificationTwampSessionEvent.h ├── NumberOidIndexGenerator.cpp ├── NumberOidIndexGenerator.h ├── OidRefCounter.cpp ├── OidRefCounter.h ├── PerformanceIntervalTimer.cpp ├── PerformanceIntervalTimer.h ├── PortRelatedSet.cpp ├── PortRelatedSet.h ├── RedisSelectableChannel.cpp ├── RedisSelectableChannel.h ├── SaiAttrWrapper.cpp ├── SaiAttrWrapper.h ├── SaiAttributeList.cpp ├── SaiAttributeList.h ├── SaiInterface.cpp ├── SaiInterface.h ├── SaiObject.cpp ├── SaiObject.h ├── SaiObjectCollection.cpp ├── SaiObjectCollection.h ├── SaiOptions.h ├── SaiSerialize.cpp ├── SelectableChannel.cpp ├── SelectableChannel.h ├── ZeroMQSelectableChannel.cpp ├── ZeroMQSelectableChannel.h └── sai_serialize.h ├── package.cfg ├── proxylib ├── Makefile.am ├── Options.cpp ├── Options.h ├── Proxy.cpp ├── Proxy.h ├── Sai.cpp ├── Sai.h ├── SaiInternal.h └── saiproxy.h ├── pyext ├── Makefile.am ├── py2 │ ├── Makefile.am │ └── __init__.py ├── py3 │ ├── Makefile.am │ └── __init__.py ├── pysairedis.cpp ├── pysairedis.h ├── pysairedis.i └── test.py ├── saiasiccmp ├── AsicCmp.cpp ├── AsicCmp.h ├── CommandLineOptions.cpp ├── CommandLineOptions.h ├── CommandLineOptionsParser.cpp ├── CommandLineOptionsParser.h ├── Makefile.am ├── SaiSwitchAsic.cpp ├── SaiSwitchAsic.h ├── View.cpp ├── View.h ├── ViewCmp.cpp ├── ViewCmp.h ├── dump1.json ├── dump2.json ├── dump3.json ├── main.cpp └── test.sh ├── saidiscovery ├── Makefile.am └── saidiscovery.cpp ├── saidump ├── Makefile.am ├── SaiDump.cpp ├── SaiDump.h └── main.cpp ├── saiplayer ├── CommandLineOptions.cpp ├── CommandLineOptions.h ├── CommandLineOptionsParser.cpp ├── CommandLineOptionsParser.h ├── Makefile.am ├── SaiPlayer.cpp ├── SaiPlayer.h └── saiplayer_main.cpp ├── saisdkdump ├── Makefile.am └── saisdkdump.cpp ├── stub.pl ├── syncd ├── Asan.cpp ├── AsicOperation.cpp ├── AsicOperation.h ├── AsicView.cpp ├── AsicView.h ├── AttrVersionChecker.cpp ├── AttrVersionChecker.h ├── BestCandidateFinder.cpp ├── BestCandidateFinder.h ├── BreakConfig.cpp ├── BreakConfig.h ├── BreakConfigParser.cpp ├── BreakConfigParser.h ├── CommandLineOptions.cpp ├── CommandLineOptions.h ├── CommandLineOptionsParser.cpp ├── CommandLineOptionsParser.h ├── ComparisonLogic.cpp ├── ComparisonLogic.h ├── ConcurrentQueue.h ├── FlexCounter.cpp ├── FlexCounter.h ├── FlexCounterManager.cpp ├── FlexCounterManager.h ├── GlobalSwitchId.cpp ├── GlobalSwitchId.h ├── HardReiniter.cpp ├── HardReiniter.h ├── Makefile.am ├── MdioIpcClient.cpp ├── MdioIpcClient.h ├── MdioIpcCommon.h ├── MdioIpcServer.cpp ├── MdioIpcServer.h ├── MetadataLogger.cpp ├── MetadataLogger.h ├── NotificationHandler.cpp ├── NotificationHandler.h ├── NotificationProcessor.cpp ├── NotificationProcessor.h ├── NotificationProducerBase.h ├── NotificationQueue.cpp ├── NotificationQueue.h ├── PortMap.cpp ├── PortMap.h ├── PortMapParser.cpp ├── PortMapParser.h ├── PortStateChangeHandler.cpp ├── PortStateChangeHandler.h ├── RedisClient.cpp ├── RedisClient.h ├── RedisNotificationProducer.cpp ├── RedisNotificationProducer.h ├── RequestShutdown.cpp ├── RequestShutdown.h ├── RequestShutdownCommandLineOptions.cpp ├── RequestShutdownCommandLineOptions.h ├── RequestShutdownCommandLineOptionsParser.cpp ├── RequestShutdownCommandLineOptionsParser.h ├── SaiAttr.cpp ├── SaiAttr.h ├── SaiDiscovery.cpp ├── SaiDiscovery.h ├── SaiObj.cpp ├── SaiObj.h ├── SaiSwitch.cpp ├── SaiSwitch.h ├── SaiSwitchInterface.cpp ├── SaiSwitchInterface.h ├── SelectableEventHandler.h ├── ServiceMethodTable.cpp ├── ServiceMethodTable.h ├── SingleReiniter.cpp ├── SingleReiniter.h ├── SwitchNotifications.cpp ├── SwitchNotifications.h ├── Syncd.cpp ├── Syncd.h ├── TimerWatchdog.cpp ├── TimerWatchdog.h ├── VendorSai.cpp ├── VendorSai.h ├── VendorSaiOptions.h ├── VidManager.cpp ├── VidManager.h ├── VirtualOidTranslator.cpp ├── VirtualOidTranslator.h ├── WarmRestartTable.cpp ├── WarmRestartTable.h ├── WatchdogScope.cpp ├── WatchdogScope.h ├── Workaround.cpp ├── Workaround.h ├── ZeroMQNotificationProducer.cpp ├── ZeroMQNotificationProducer.h ├── lanemap.ini ├── main.cpp ├── profile.ini ├── scripts │ ├── brcm_common_config_ut.sh │ ├── gbsyncdmgrd │ ├── sai_failure_dump.sh │ ├── saidump.sh │ ├── syncd_init_common.sh │ └── syncd_start.sh ├── syncd_main.cpp ├── syncd_request_shutdown.cpp ├── testprofile.ini ├── tests.cpp └── tests │ ├── Makefile.am │ ├── TestSyncdBrcm.cpp │ ├── TestSyncdLib.cpp │ ├── TestSyncdLib.h │ ├── TestSyncdMlnx.cpp │ ├── TestSyncdNvdaBf.cpp │ ├── TestSyncdNvdaBf.h │ ├── brcm │ ├── lanemap.ini │ └── testprofile.ini │ ├── main.cpp │ ├── mlnx │ ├── lanemap.ini │ └── sai.profile │ └── nvda-bf │ ├── lanemap.ini │ └── sai.profile ├── tests ├── BCM56850.pl ├── BCM56850 │ ├── acl_counter.rec │ ├── acl_counter2.rec │ ├── acl_counter_match.rec │ ├── acl_limit.rec │ ├── acl_mask.rec │ ├── acl_pre_match_999.rec │ ├── acl_tables.rec │ ├── bbm.ini │ ├── bridge_create_1.rec │ ├── bridge_create_2.rec │ ├── buffer_profile_get_A.rec │ ├── buffer_profile_get_B.rec │ ├── bulk_fdb.rec │ ├── bulk_neighbor.rec │ ├── bulk_object.rec │ ├── bulk_route.rec │ ├── client_switch.rec │ ├── config_acl.rec │ ├── config_acl2.rec │ ├── ctx_multi.json │ ├── ctx_zmq.json │ ├── depreacated.rec │ ├── empty_lag_buffer_acl.rec │ ├── empty_sw.rec │ ├── full.rec │ ├── full_buffer.rec │ ├── full_buffer_second.rec │ ├── full_hostif_remove_segfault.rec │ ├── full_nhg_bug.rec │ ├── full_nhg_bug_prio_flow_bug.rec │ ├── full_nhg_bug_trap_group_create_fail.rec │ ├── full_no_queue.rec │ ├── full_no_queue_no_ipg.rec │ ├── full_no_queue_no_ipg_no_buffer_pfofile.rec │ ├── full_ntf.rec │ ├── full_queue_bug_null_buffer_profile.rec │ ├── full_second.rec │ ├── full_second_no_bridge.rec │ ├── full_testbed_config.rec │ ├── hostif.rec │ ├── ignore_attributes.rec │ ├── lag_comparison_logic.rec │ ├── lag_label_A.rec │ ├── lag_label_B.rec │ ├── lag_no_members.rec │ ├── lanemap.ini │ ├── lanemap_multi.ini │ ├── limits.ini │ ├── multi_switch_key.rec │ ├── neighbor_next_hop.rec │ ├── nhg_comparison_logic.rec │ ├── no_lag_label_A.rec │ ├── no_lag_label_B.rec │ ├── non_depreacated.rec │ ├── ntf1.rec │ ├── ntf2.rec │ ├── port_bulk_get.rec │ ├── qos_map_order.rec │ ├── query_attr_enum_values_capability.rec │ ├── query_object_type_get_availability.rec │ ├── relaxed.rec │ ├── remove_create_port.rec │ ├── remove_next_hop.rec │ ├── remove_port.rec │ ├── rif_loopback.rec │ ├── small_buffer.rec │ ├── speed_apply.rec │ ├── speed_init.rec │ ├── test_bulk_set_multiple_A.rec │ ├── test_bulk_set_multiple_B.rec │ ├── test_lag_member.rec │ ├── test_macsec_p2p_establishment.rec │ ├── test_neighbor_lag.rec │ ├── test_remove_port_serdes.rec │ ├── tunnel_map.rec │ ├── voq_switch_create.rec │ ├── vsprofile.ini │ ├── vsprofile_acl_limit.ini │ ├── vsprofile_ctx_multi.ini │ ├── vsprofile_ctx_zmq.ini │ ├── vxlan_default_router_mac.rec │ ├── wb_port_create_a.rec │ ├── wb_port_create_b.rec │ ├── wb_port_remove_a.rec │ ├── wb_port_remove_b.rec │ └── wred_queue.rec ├── BCM56971B0.pl ├── BCM56971B0 │ ├── acl_limit.rec │ ├── acl_prio.rec │ ├── break.ini │ ├── lanemap.ini │ ├── limits.ini │ ├── limits122.ini │ └── vsprofile.ini ├── MLNX2700.pl ├── MLNX2700 │ ├── empty.rec │ ├── empty_sw.rec │ ├── full.rec │ ├── full_nhg_member.rec │ ├── full_no_hostif_entry.rec │ ├── full_no_hostif_entry_second.rec │ ├── full_syncd_dies.rec │ ├── full_to_crash.rec │ ├── inspect_asic.rec │ └── vsprofile.ini ├── Makefile.am ├── NVDAMBF2H536C.pl ├── NVDAMBF2H536C │ ├── client_switch.rec │ ├── dashapis.rec │ └── vsprofile.ini ├── README.md ├── TestClient.cpp ├── TestClient.h ├── TestDash.cpp ├── TestDashEnv.cpp ├── TestDashEnv.h ├── TestDashMain.cpp ├── aspell.en.pws ├── aspellcheck.pl ├── checksaiapi.sh ├── checkwhitespace.sh ├── conflictnames.pl ├── findcrossinclude.sh ├── main.cpp ├── swsslogentercheck.pl ├── swsslogentercheck.sh ├── testclient_main.cpp ├── tests.cpp └── utils.pm ├── unittest ├── Makefile.am ├── lib │ ├── Makefile.am │ ├── MockSaiInterface.cpp │ ├── MockSaiInterface.h │ ├── TestClientConfig.cpp │ ├── TestClientSai.cpp │ ├── TestClientServerSai.cpp │ ├── TestContext.cpp │ ├── TestContextConfig.cpp │ ├── TestContextConfigContainer.cpp │ ├── TestRecorder.cpp │ ├── TestRedisChannel.cpp │ ├── TestRedisRemoteSaiInterface.cpp │ ├── TestRedisVidIndexGenerator.cpp │ ├── TestSai.cpp │ ├── TestServerConfig.cpp │ ├── TestServerSai.cpp │ ├── TestSkipRecordAttrContainer.cpp │ ├── TestSwitch.cpp │ ├── TestSwitchConfigContainer.cpp │ ├── TestSwitchContainer.cpp │ ├── TestUtils.cpp │ ├── TestVirtualObjectIdManager.cpp │ ├── TestZeroMQChannel.cpp │ ├── files │ │ ├── ccc_bad.txt │ │ ├── client_config_bad.txt │ │ ├── client_config_ok.txt │ │ ├── server_config_bad.json │ │ └── server_config_ok.json │ ├── main.cpp │ └── main_libsairedis.cpp ├── meta │ ├── Makefile.am │ ├── MockMeta.cpp │ ├── MockMeta.h │ ├── TestAttrKeyMap.cpp │ ├── TestDummySaiInterface.cpp │ ├── TestGlobals.cpp │ ├── TestLegacy.cpp │ ├── TestLegacy.h │ ├── TestLegacyFdbEntry.cpp │ ├── TestLegacyNeighborEntry.cpp │ ├── TestLegacyOther.cpp │ ├── TestLegacyRouteEntry.cpp │ ├── TestLegacyVlan.cpp │ ├── TestMeta.cpp │ ├── TestMetaDash.cpp │ ├── TestMetaKeyHasher.cpp │ ├── TestNotificationBfdSessionStateChange.cpp │ ├── TestNotificationFactory.cpp │ ├── TestNotificationFdbEvent.cpp │ ├── TestNotificationHaScopeEvent.cpp │ ├── TestNotificationHaSetEvent.cpp │ ├── TestNotificationIcmpEchoSessionStateChange.cpp │ ├── TestNotificationNatEvent.cpp │ ├── TestNotificationPortHostTxReadyEvent.cpp │ ├── TestNotificationPortStateChange.cpp │ ├── TestNotificationQueuePfcDeadlock.cpp │ ├── TestNotificationSwitchAsicSdkHealthEvent.cpp │ ├── TestNotificationSwitchShutdownRequest.cpp │ ├── TestNotificationSwitchStateChange.cpp │ ├── TestNotificationTam.cpp │ ├── TestOidRefCounter.cpp │ ├── TestPerformanceIntervalTimer.cpp │ ├── TestPortRelatedSet.cpp │ ├── TestSaiAttrWrapper.cpp │ ├── TestSaiAttributeList.cpp │ ├── TestSaiInterface.cpp │ ├── TestSaiObject.cpp │ ├── TestSaiObjectCollection.cpp │ ├── TestSaiSerialize.cpp │ ├── TestZeroMQSelectableChannel.cpp │ └── main.cpp ├── proxylib │ ├── Makefile.am │ ├── TestProxy.cpp │ ├── TestSai.cpp │ ├── config.ini │ ├── main.cpp │ └── main_libsaiproxy.cpp ├── saidump │ ├── Makefile.am │ ├── TestSaiDump.cpp │ ├── dump.json │ ├── err.json │ └── main.cpp ├── syncd │ ├── Makefile.am │ ├── MockHelper.cpp │ ├── MockHelper.h │ ├── MockableSaiInterface.cpp │ ├── MockableSaiInterface.h │ ├── MockableSaiSwitchInterface.cpp │ ├── MockableSaiSwitchInterface.h │ ├── TestAttrVersionChecker.cpp │ ├── TestBestCandidateFinder.cpp │ ├── TestCommandLineOptions.cpp │ ├── TestConcurrentQueue.cpp │ ├── TestFlexCounter.cpp │ ├── TestMdioIpcServer.cpp │ ├── TestNotificationHandler.cpp │ ├── TestNotificationProcessor.cpp │ ├── TestNotificationQueue.cpp │ ├── TestPortStateChangeHandler.cpp │ ├── TestSyncd.cpp │ ├── TestVendorSai.cpp │ ├── TestVirtualOidTranslator.cpp │ ├── TestWorkaround.cpp │ ├── main.cpp │ └── profile.ini └── vslib │ ├── Makefile.am │ ├── TestBuffer.cpp │ ├── TestContextConfigContainer.cpp │ ├── TestCorePortIndexMap.cpp │ ├── TestCorePortIndexMapContainer.cpp │ ├── TestCorePortIndexMapFileParser.cpp │ ├── TestEventPayloadNetLinkMsg.cpp │ ├── TestEventPayloadPacket.cpp │ ├── TestEventQueue.cpp │ ├── TestFdbInfo.cpp │ ├── TestHostInterfaceInfo.cpp │ ├── TestLaneMap.cpp │ ├── TestLaneMapContainer.cpp │ ├── TestLaneMapFileParser.cpp │ ├── TestMACsecAttr.cpp │ ├── TestMACsecEgressFilter.cpp │ ├── TestMACsecFilterStateGuard.cpp │ ├── TestMACsecForwarder.cpp │ ├── TestMACsecIngressFilter.cpp │ ├── TestMACsecManager.cpp │ ├── TestNetMsgRegistrar.cpp │ ├── TestRealObjectIdManager.cpp │ ├── TestResourceLimiter.cpp │ ├── TestResourceLimiterContainer.cpp │ ├── TestResourceLimiterParser.cpp │ ├── TestSai.cpp │ ├── TestSaiAttrWrap.cpp │ ├── TestSaiUnittests.cpp │ ├── TestSelectableFd.cpp │ ├── TestSignal.cpp │ ├── TestSwitch.cpp │ ├── TestSwitchBCM56850.cpp │ ├── TestSwitchBCM81724.cpp │ ├── TestSwitchConfig.cpp │ ├── TestSwitchConfigContainer.cpp │ ├── TestSwitchContainer.cpp │ ├── TestSwitchMLNX2700.cpp │ ├── TestSwitchNvdaMBF2H536C.cpp │ ├── TestSwitchStateBase.cpp │ ├── TestSwitchStateBaseMACsec.cpp │ ├── TestTAM.cpp │ ├── TestTrafficFilterPipes.cpp │ ├── TestTrafficForwarder.cpp │ ├── TestVirtualSwitchSaiInterface.cpp │ ├── files │ ├── bcm56850.warm.bin │ ├── bcm81724.warm.bin │ ├── context_config.bad.json │ ├── context_config.good.json │ ├── core_port_empty.txt │ ├── core_port_ok.txt │ ├── lane_map_empty.txt │ ├── lane_map_ok.txt │ ├── mlnx2700.warm.bin │ ├── resource_limiter_bad.txt │ └── resource_limiter_ok.txt │ ├── main.cpp │ └── main_libsaivs.cpp └── vslib ├── Buffer.cpp ├── Buffer.h ├── Context.cpp ├── Context.h ├── ContextConfig.cpp ├── ContextConfig.h ├── ContextConfigContainer.cpp ├── ContextConfigContainer.h ├── CorePortIndexMap.cpp ├── CorePortIndexMap.h ├── CorePortIndexMapContainer.cpp ├── CorePortIndexMapContainer.h ├── CorePortIndexMapFileParser.cpp ├── CorePortIndexMapFileParser.h ├── Event.cpp ├── Event.h ├── EventPayload.h ├── EventPayloadNetLinkMsg.cpp ├── EventPayloadNetLinkMsg.h ├── EventPayloadNotification.cpp ├── EventPayloadNotification.h ├── EventPayloadPacket.cpp ├── EventPayloadPacket.h ├── EventQueue.cpp ├── EventQueue.h ├── FdbInfo.cpp ├── FdbInfo.h ├── HostInterfaceInfo.cpp ├── HostInterfaceInfo.h ├── LaneMap.cpp ├── LaneMap.h ├── LaneMapContainer.cpp ├── LaneMapContainer.h ├── LaneMapFileParser.cpp ├── LaneMapFileParser.h ├── MACsecAttr.cpp ├── MACsecAttr.h ├── MACsecEgressFilter.cpp ├── MACsecEgressFilter.h ├── MACsecFilter.cpp ├── MACsecFilter.h ├── MACsecFilterStateGuard.cpp ├── MACsecFilterStateGuard.h ├── MACsecForwarder.cpp ├── MACsecForwarder.h ├── MACsecIngressFilter.cpp ├── MACsecIngressFilter.h ├── MACsecManager.cpp ├── MACsecManager.h ├── Makefile.am ├── NetMsgRegistrar.cpp ├── NetMsgRegistrar.h ├── RealObjectIdManager.cpp ├── RealObjectIdManager.h ├── ResourceLimiter.cpp ├── ResourceLimiter.h ├── ResourceLimiterContainer.cpp ├── ResourceLimiterContainer.h ├── ResourceLimiterParser.cpp ├── ResourceLimiterParser.h ├── Sai.cpp ├── Sai.h ├── SaiAttrWrap.cpp ├── SaiAttrWrap.h ├── SaiEventQueue.cpp ├── SaiFdbAging.cpp ├── SaiInternal.h ├── SaiUnittests.cpp ├── SelectableFd.cpp ├── SelectableFd.h ├── Signal.cpp ├── Signal.h ├── Switch.cpp ├── Switch.h ├── SwitchBCM56850.cpp ├── SwitchBCM56850.h ├── SwitchBCM56971B0.cpp ├── SwitchBCM56971B0.h ├── SwitchBCM81724.cpp ├── SwitchBCM81724.h ├── SwitchConfig.cpp ├── SwitchConfig.h ├── SwitchConfigContainer.cpp ├── SwitchConfigContainer.h ├── SwitchContainer.cpp ├── SwitchContainer.h ├── SwitchMLNX2700.cpp ├── SwitchMLNX2700.h ├── SwitchNvdaMBF2H536C.cpp ├── SwitchNvdaMBF2H536C.h ├── SwitchState.cpp ├── SwitchState.h ├── SwitchStateBase.cpp ├── SwitchStateBase.h ├── SwitchStateBaseFdb.cpp ├── SwitchStateBaseHostif.cpp ├── SwitchStateBaseMACsec.cpp ├── TrafficFilter.h ├── TrafficFilterPipes.cpp ├── TrafficFilterPipes.h ├── TrafficForwarder.cpp ├── TrafficForwarder.h ├── VirtualSwitchSaiInterface.cpp ├── VirtualSwitchSaiInterface.h ├── VirtualSwitchSaiInterfaceFdb.cpp ├── VirtualSwitchSaiInterfacePort.cpp ├── WarmBootState.h ├── saivs.h ├── tests.cpp └── vpp ├── BitResourcePool.h ├── IpVrfInfo.h ├── README.md ├── SaiObjectDB.cpp ├── SaiObjectDB.h ├── SwitchVpp.cpp ├── SwitchVpp.h ├── SwitchVppAcl.cpp ├── SwitchVppAcl.h ├── SwitchVppBfd.cpp ├── SwitchVppFdb.cpp ├── SwitchVppHostif.cpp ├── SwitchVppNbr.cpp ├── SwitchVppNexthop.cpp ├── SwitchVppNexthop.h ├── SwitchVppRif.cpp ├── SwitchVppRoute.cpp ├── SwitchVppSRv6.cpp ├── SwitchVppUtils.cpp ├── SwitchVppUtils.h ├── TunnelManager.cpp ├── TunnelManager.h └── vppxlate ├── SaiAclStats.c ├── SaiAclStats.h ├── SaiIntfStats.c ├── SaiIntfStats.h ├── SaiVppStats.c ├── SaiVppStats.h ├── SaiVppXlate.c └── SaiVppXlate.h /.artifactignore: -------------------------------------------------------------------------------- 1 | **/* 2 | !*.deb 3 | -------------------------------------------------------------------------------- /.github/codeql/codeql-config.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL config" 2 | queries: 3 | - uses: security-and-quality 4 | - uses: security-extended 5 | -------------------------------------------------------------------------------- /.github/workflows/semgrep.yml: -------------------------------------------------------------------------------- 1 | name: Semgrep 2 | 3 | on: 4 | pull_request: {} 5 | push: 6 | branches: 7 | - master 8 | - '201[7-9][0-1][0-9]' 9 | - '202[0-9][0-1][0-9]' 10 | 11 | jobs: 12 | semgrep: 13 | if: github.repository_owner == 'sonic-net' 14 | name: Semgrep 15 | runs-on: ubuntu-latest 16 | container: 17 | image: returntocorp/semgrep 18 | steps: 19 | - uses: actions/checkout@v3 20 | - run: semgrep ci 21 | env: 22 | SEMGREP_RULES: p/default 23 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "SAI"] 2 | path = SAI 3 | url = https://github.com/opencomputeproject/SAI.git 4 | ignore = dirty 5 | branch = v1.3 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 Microsoft, Inc. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = meta lib vslib proxylib pyext 2 | 3 | if SYNCD 4 | SUBDIRS += syncd saiplayer saidump saidiscovery saisdkdump saiasiccmp tests unittest 5 | endif 6 | 7 | ACLOCAL_AMFLAGS = -I m4 8 | -------------------------------------------------------------------------------- /autoclean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git clean -dfX 4 | 5 | (cd SAI && git clean -dfX) 6 | 7 | true 8 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | libtoolize --force --copy && 4 | autoreconf --force --install -I m4 5 | rm -Rf autom4te.cache 6 | 7 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | sonic (1.0.0) stable; urgency=medium 2 | 3 | * syncd-rpc is added 4 | 5 | -- Pavel Shirshov Wed, 12 Apr 2017 12:00:00 -0800 6 | 7 | sonic (1.0.0) stable; urgency=medium 8 | 9 | * Initial release. 10 | 11 | -- Kamil Cudnik Wed, 23 Mar 2016 12:00:00 -0800 12 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /debian/libsaimetadata-dev.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | usr/include 3 | -------------------------------------------------------------------------------- /debian/libsaimetadata-dev.install: -------------------------------------------------------------------------------- 1 | meta/sai*.h usr/include/sai 2 | meta/Sai*.h usr/include/sai 3 | meta/Meta.h usr/include/sai 4 | meta/AttrKeyMap.h usr/include/sai 5 | meta/MetaKeyHasher.h usr/include/sai 6 | meta/OidRefCounter.h usr/include/sai 7 | meta/PortRelatedSet.h usr/include/sai 8 | meta/Notification*.h usr/include/sai 9 | meta/Globals.h usr/include/sai 10 | SAI/meta/sai*.h usr/include/sai 11 | usr/lib/*/libsaimetadata.so 12 | usr/lib/*/libsaimeta.so 13 | -------------------------------------------------------------------------------- /debian/libsaimetadata-dev.links: -------------------------------------------------------------------------------- 1 | #! /usr/bin/dh-exec 2 | /usr/lib/${DEB_HOST_MULTIARCH}/libsaimetadata.so.0 /usr/lib/${DEB_HOST_MULTIARCH}/libsaimetadata.so 3 | /usr/lib/${DEB_HOST_MULTIARCH}/libsaimeta.so.0 /usr/lib/${DEB_HOST_MULTIARCH}/libsaimeta.so 4 | -------------------------------------------------------------------------------- /debian/libsaimetadata.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | -------------------------------------------------------------------------------- /debian/libsaimetadata.install: -------------------------------------------------------------------------------- 1 | usr/lib/*/libsaimetadata.so.* 2 | usr/lib/*/libsaimeta.so.* 3 | -------------------------------------------------------------------------------- /debian/libsairedis-dev.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | usr/include 3 | -------------------------------------------------------------------------------- /debian/libsairedis-dev.install: -------------------------------------------------------------------------------- 1 | lib/sairedis.h usr/include/sai 2 | usr/lib/*/libsairedis.so 3 | -------------------------------------------------------------------------------- /debian/libsairedis-dev.links: -------------------------------------------------------------------------------- 1 | #! /usr/bin/dh-exec 2 | /usr/lib/${DEB_HOST_MULTIARCH}/libsairedis.so.0 /usr/lib/${DEB_HOST_MULTIARCH}/libsairedis.so 3 | -------------------------------------------------------------------------------- /debian/libsairedis.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | -------------------------------------------------------------------------------- /debian/libsairedis.install: -------------------------------------------------------------------------------- 1 | usr/lib/*/libsairedis*.so.* 2 | -------------------------------------------------------------------------------- /debian/libsaivs-dev.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | usr/include 3 | -------------------------------------------------------------------------------- /debian/libsaivs-dev.install: -------------------------------------------------------------------------------- 1 | SAI/inc/sai*.h usr/include/sai/ 2 | SAI/experimental/sai*.h usr/include/sai/ 3 | vslib/saivs.h 4 | -------------------------------------------------------------------------------- /debian/libsaivs-dev.links: -------------------------------------------------------------------------------- 1 | #! /usr/bin/dh-exec 2 | /usr/lib/${DEB_HOST_MULTIARCH}/libsaivs.so.0 /usr/lib/${DEB_HOST_MULTIARCH}/libsaivs.so 3 | -------------------------------------------------------------------------------- /debian/libsaivs.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | -------------------------------------------------------------------------------- /debian/libsaivs.install: -------------------------------------------------------------------------------- 1 | usr/lib/*/libsaivs.so.* 2 | -------------------------------------------------------------------------------- /debian/python-pysairedis.dirs: -------------------------------------------------------------------------------- 1 | usr/lib/python2.7 2 | -------------------------------------------------------------------------------- /debian/python-pysairedis.install: -------------------------------------------------------------------------------- 1 | usr/lib/python2.7/dist-packages/sairedis/* 2 | -------------------------------------------------------------------------------- /debian/python3-pysairedis.dirs: -------------------------------------------------------------------------------- 1 | usr/lib/python3 2 | -------------------------------------------------------------------------------- /debian/python3-pysairedis.install: -------------------------------------------------------------------------------- 1 | usr/lib/python3/dist-packages/sairedis/* 2 | -------------------------------------------------------------------------------- /debian/syncd-rpc.dirs: -------------------------------------------------------------------------------- 1 | syncd.dirs -------------------------------------------------------------------------------- /debian/syncd-rpc.init: -------------------------------------------------------------------------------- 1 | syncd.init -------------------------------------------------------------------------------- /debian/syncd-rpc.install: -------------------------------------------------------------------------------- 1 | syncd.install -------------------------------------------------------------------------------- /debian/syncd-vs.dirs: -------------------------------------------------------------------------------- 1 | syncd.dirs -------------------------------------------------------------------------------- /debian/syncd-vs.init: -------------------------------------------------------------------------------- 1 | syncd.init -------------------------------------------------------------------------------- /debian/syncd-vs.install: -------------------------------------------------------------------------------- 1 | syncd.install -------------------------------------------------------------------------------- /debian/syncd.dirs: -------------------------------------------------------------------------------- 1 | usr/bin 2 | usr/lib 3 | -------------------------------------------------------------------------------- /debian/syncd.init: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ### BEGIN INIT INFO 4 | # Provides: syncd 5 | # Required-Start: 6 | # Required-Stop: 7 | # Default-Start: S 8 | # Default-Stop: 0 6 9 | # Short-Description: SONiC sync daemon 10 | # Description: Enable service syncd. 11 | ### END INIT INFO 12 | 13 | # Source the file that holds common code for systemd and supervisord 14 | . /usr/bin/syncd_init_common.sh 15 | 16 | # When starting as a service, we want our process to run as a daemon, in the background 17 | if [ $CMD == $CMD_DSSERVE ]; then 18 | CMD_ARGS="-d $CMD_ARGS" 19 | fi 20 | 21 | case "$1" in 22 | start) 23 | config_syncd 24 | start-stop-daemon --start --quiet --exec $CMD -- $CMD_ARGS 25 | ;; 26 | stop) 27 | start-stop-daemon --stop --quiet --exec $CMD 28 | ;; 29 | *) 30 | echo "Usage: service syncd {start|stop}" 31 | exit 1 32 | ;; 33 | esac 34 | 35 | exit 0 36 | 37 | -------------------------------------------------------------------------------- /debian/syncd.install: -------------------------------------------------------------------------------- 1 | usr/bin/saidump 2 | usr/bin/saiplayer 3 | usr/bin/saisdkdump 4 | usr/bin/saidiscovery 5 | usr/bin/saiasiccmp 6 | usr/bin/syncd* 7 | syncd/scripts/* usr/bin 8 | usr/lib/*/libMdioIpcClient.so.* 9 | -------------------------------------------------------------------------------- /debian/syncd.links: -------------------------------------------------------------------------------- 1 | #! /usr/bin/dh-exec 2 | /usr/lib/${DEB_HOST_MULTIARCH}/libMdioIpcClient.so.0 /usr/lib/${DEB_HOST_MULTIARCH}/libMdioIpcClient.so 3 | -------------------------------------------------------------------------------- /lgtm.yml: -------------------------------------------------------------------------------- 1 | extraction: 2 | cpp: 3 | prepare: 4 | packages: 5 | - libxml-simple-perl 6 | - aspell 7 | - aspell-en 8 | - libhiredis-dev 9 | - libnl-3-dev 10 | - libnl-genl-3-dev 11 | - libnl-route-3-dev 12 | - libnl-nf-3-dev 13 | - swig3.0 14 | - libpython2.7-dev 15 | - libgtest-dev 16 | - dh-exec 17 | - libzmq3-dev 18 | - libzmq5 19 | - autoconf-archive 20 | - libgtest-dev 21 | - libgmock-dev 22 | - uuid 23 | - uuid-dev 24 | - libyang-dev 25 | - libyang 26 | after_prepare: 27 | - ls -l 28 | - git clone https://github.com/Azure/sonic-swss-common; pushd sonic-swss-common; ./autogen.sh; fakeroot dpkg-buildpackage -us -uc -b; popd 29 | - dpkg-deb -x libswsscommon_1.0.0_amd64.deb $LGTM_WORKSPACE 30 | - dpkg-deb -x libswsscommon-dev_1.0.0_amd64.deb $LGTM_WORKSPACE 31 | configure: 32 | command: 33 | - ./autogen.sh 34 | - ./configure --prefix=/usr --with-sai=vs --with-swss-common-inc=$LGTM_WORKSPACE/usr/include --with-swss-common-lib=$LGTM_WORKSPACE/usr/lib/x86_64-linux-gnu 35 | -------------------------------------------------------------------------------- /lib/Channel.cpp: -------------------------------------------------------------------------------- 1 | #include "Channel.h" 2 | 3 | #include "sairedis.h" 4 | 5 | #include "swss/logger.h" 6 | 7 | using namespace sairedis; 8 | 9 | Channel::Channel( 10 | _In_ Callback callback): 11 | m_callback(callback), 12 | m_responseTimeoutMs(SAI_REDIS_DEFAULT_SYNC_OPERATION_RESPONSE_TIMEOUT) 13 | { 14 | SWSS_LOG_ENTER(); 15 | 16 | // empty 17 | } 18 | 19 | Channel::~Channel() 20 | { 21 | SWSS_LOG_ENTER(); 22 | 23 | // empty 24 | } 25 | 26 | void Channel::setResponseTimeout( 27 | _In_ uint64_t responseTimeout) 28 | { 29 | SWSS_LOG_ENTER(); 30 | 31 | m_responseTimeoutMs = responseTimeout; 32 | } 33 | 34 | uint64_t Channel::getResponseTimeout() const 35 | { 36 | SWSS_LOG_ENTER(); 37 | 38 | return m_responseTimeoutMs; 39 | } 40 | -------------------------------------------------------------------------------- /lib/ClientConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace sairedis 9 | { 10 | class ClientConfig 11 | { 12 | public: 13 | 14 | ClientConfig(); 15 | 16 | virtual ~ClientConfig(); 17 | 18 | public: 19 | 20 | static std::shared_ptr loadFromFile( 21 | _In_ const char* path); 22 | 23 | public: 24 | 25 | std::string m_zmqEndpoint; 26 | 27 | std::string m_zmqNtfEndpoint; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /lib/ContextConfigContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ContextConfig.h" 4 | 5 | #include "swss/sal.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace sairedis 12 | { 13 | class ContextConfigContainer 14 | { 15 | public: 16 | 17 | ContextConfigContainer(); 18 | 19 | virtual ~ContextConfigContainer(); 20 | 21 | public: 22 | 23 | void insert( 24 | _In_ std::shared_ptr contextConfig); 25 | 26 | std::shared_ptr get( 27 | _In_ uint32_t guid); 28 | 29 | std::set> getAllContextConfigs(); 30 | 31 | public: 32 | 33 | static std::shared_ptr loadFromFile( 34 | _In_ const char* contextConfig); 35 | 36 | static std::shared_ptr getDefault(); 37 | 38 | private: 39 | 40 | std::map> m_map; 41 | 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /lib/OidIndexGenerator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace sairedis 9 | { 10 | class OidIndexGenerator 11 | { 12 | public: 13 | 14 | OidIndexGenerator() = default; 15 | 16 | virtual ~OidIndexGenerator() = default; 17 | 18 | public: 19 | 20 | virtual uint64_t increment() = 0; 21 | 22 | virtual std::vector incrementBy( 23 | _In_ uint64_t count) = 0; 24 | 25 | virtual void reset() = 0; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /lib/RedisVidIndexGenerator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "OidIndexGenerator.h" 4 | 5 | #include "swss/dbconnector.h" 6 | #include "swss/sal.h" 7 | 8 | #include 9 | 10 | namespace sairedis 11 | { 12 | class RedisVidIndexGenerator: 13 | public OidIndexGenerator 14 | { 15 | public: 16 | 17 | RedisVidIndexGenerator( 18 | _In_ std::shared_ptr dbConnector, 19 | _In_ const std::string& vidCounterName); 20 | 21 | virtual ~RedisVidIndexGenerator() = default; 22 | 23 | public: 24 | 25 | virtual uint64_t increment() override; 26 | virtual std::vector incrementBy( 27 | _In_ uint64_t count) override; 28 | 29 | virtual void reset() override; 30 | 31 | private: 32 | 33 | std::shared_ptr m_dbConnector; 34 | 35 | std::string m_vidCounterName; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /lib/RemoteSaiInterface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sairedis.h" 4 | 5 | #include "meta/SaiInterface.h" 6 | 7 | namespace sairedis 8 | { 9 | class RemoteSaiInterface: 10 | public SaiInterface 11 | { 12 | public: 13 | 14 | RemoteSaiInterface() = default; 15 | 16 | virtual ~RemoteSaiInterface() = default; 17 | 18 | public: 19 | 20 | /** 21 | * @brief Notify syncd API. 22 | */ 23 | virtual sai_status_t notifySyncd( 24 | _In_ sai_object_id_t switchId, 25 | _In_ sai_redis_notify_syncd_t redisNotifySyncd) = 0; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /lib/SaiInternal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define MUTEX() std::lock_guard _lock(m_apimutex) 4 | #define MUTEX_UNLOCK() m_apimutex.unlock() 5 | -------------------------------------------------------------------------------- /lib/ServerConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace sairedis 9 | { 10 | class ServerConfig 11 | { 12 | public: 13 | 14 | ServerConfig(); 15 | 16 | virtual ~ServerConfig(); 17 | 18 | public: 19 | 20 | static std::shared_ptr loadFromFile( 21 | _In_ const char* path); 22 | 23 | public: 24 | 25 | std::string m_zmqEndpoint; 26 | 27 | std::string m_zmqNtfEndpoint; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /lib/SwitchConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "SwitchConfig.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace sairedis; 6 | 7 | SwitchConfig::SwitchConfig(): 8 | m_switchIndex(0), 9 | m_hardwareInfo("") 10 | { 11 | SWSS_LOG_ENTER(); 12 | 13 | // empty 14 | } 15 | 16 | SwitchConfig::SwitchConfig( 17 | _In_ uint32_t switchIndex, 18 | _In_ const std::string& hwinfo): 19 | m_switchIndex(switchIndex), 20 | m_hardwareInfo(hwinfo) 21 | { 22 | SWSS_LOG_ENTER(); 23 | 24 | // empty 25 | } 26 | -------------------------------------------------------------------------------- /lib/SwitchConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace sairedis 9 | { 10 | class SwitchConfig 11 | { 12 | public: 13 | 14 | SwitchConfig(); 15 | 16 | SwitchConfig( 17 | _In_ uint32_t switchIndex, 18 | _In_ const std::string& hwinfo); 19 | 20 | virtual ~SwitchConfig() = default; 21 | 22 | public: 23 | 24 | uint32_t m_switchIndex; 25 | 26 | std::string m_hardwareInfo; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /lib/SwitchConfigContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SwitchConfig.h" 4 | 5 | #include "swss/sal.h" 6 | 7 | #include 8 | #include 9 | 10 | namespace sairedis 11 | { 12 | class SwitchConfigContainer 13 | { 14 | public: 15 | 16 | SwitchConfigContainer() = default; 17 | 18 | virtual ~SwitchConfigContainer() = default; 19 | 20 | public: 21 | 22 | void insert( 23 | _In_ std::shared_ptr config); 24 | 25 | std::shared_ptr getConfig( 26 | _In_ uint32_t switchIndex) const; 27 | 28 | std::shared_ptr getConfig( 29 | _In_ const std::string& hardwareInfo) const; 30 | 31 | private: 32 | 33 | std::map> m_indexToConfig; 34 | 35 | std::map> m_hwinfoToConfig; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /lib/client_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "zmq_endpoint": "ipc:///tmp/saiServer", 3 | "zmq_ntf_endpoint": "ipc:///tmp/saiServerNtf" 4 | } 5 | -------------------------------------------------------------------------------- /meta/MetaKeyHasher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "saimetadata.h" 5 | } 6 | 7 | #include 8 | 9 | namespace saimeta 10 | { 11 | struct MetaKeyHasher 12 | { 13 | std::size_t operator()( 14 | _In_ const sai_object_meta_key_t& k) const; 15 | 16 | bool operator()( 17 | _In_ const sai_object_meta_key_t& a, 18 | _In_ const sai_object_meta_key_t& b) const; 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /meta/Notification.cpp: -------------------------------------------------------------------------------- 1 | #include "Notification.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace sairedis; 6 | 7 | Notification::Notification( 8 | _In_ sai_switch_notification_type_t switchNotificationType, 9 | _In_ const std::string& serializedNotification): 10 | m_switchNotificationType(switchNotificationType), 11 | m_serializedNotification(serializedNotification) 12 | { 13 | SWSS_LOG_ENTER(); 14 | 15 | // empty 16 | } 17 | 18 | sai_switch_notification_type_t Notification::getNotificationType() const 19 | { 20 | SWSS_LOG_ENTER(); 21 | 22 | return m_switchNotificationType; 23 | } 24 | 25 | const std::string& Notification::getSerializedNotification() const 26 | { 27 | SWSS_LOG_ENTER(); 28 | 29 | return m_serializedNotification; 30 | } 31 | -------------------------------------------------------------------------------- /meta/NotificationBfdSessionStateChange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationBfdSessionStateChange: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationBfdSessionStateChange( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationBfdSessionStateChange(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | uint32_t m_count; 32 | 33 | sai_bfd_session_state_notification_t *m_bfdSessionStateNotificationData; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /meta/NotificationFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | #include 6 | 7 | namespace sairedis 8 | { 9 | class NotificationFactory 10 | { 11 | private: 12 | 13 | NotificationFactory() = delete; 14 | ~NotificationFactory() = delete; 15 | 16 | public: 17 | 18 | static std::shared_ptr deserialize( 19 | _In_ const std::string& name, 20 | _In_ const std::string& serializedNotification); 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /meta/NotificationFdbEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationFdbEvent: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationFdbEvent( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationFdbEvent(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | uint32_t m_count; 32 | 33 | sai_fdb_event_notification_data_t* m_fdbEventNotificationData; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /meta/NotificationHaScopeEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationHaScopeEvent: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationHaScopeEvent( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationHaScopeEvent(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | uint32_t m_count; 32 | 33 | sai_ha_scope_event_data_t* m_haScopeEventData; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /meta/NotificationHaSetEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationHaSetEvent: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationHaSetEvent( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationHaSetEvent(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | uint32_t m_count; 32 | 33 | sai_ha_set_event_data_t* m_haSetEventData; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /meta/NotificationIcmpEchoSessionStateChange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationIcmpEchoSessionStateChange: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationIcmpEchoSessionStateChange( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationIcmpEchoSessionStateChange(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | uint32_t m_count; 32 | 33 | sai_icmp_echo_session_state_notification_t *m_icmpEchoSessionStateNotificationData; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /meta/NotificationNatEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationNatEvent: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationNatEvent( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationNatEvent(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | uint32_t m_count; 32 | 33 | sai_nat_event_notification_data_t* m_natEventNotificationData; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /meta/NotificationPortHostTxReadyEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationPortHostTxReady: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationPortHostTxReady( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationPortHostTxReady(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | sai_object_id_t m_portId; 32 | 33 | sai_object_id_t m_switchId; 34 | 35 | sai_port_host_tx_ready_status_t m_portHostTxReadyStatus; 36 | 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /meta/NotificationPortStateChange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationPortStateChange: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationPortStateChange( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationPortStateChange(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | uint32_t m_count; 32 | 33 | sai_port_oper_status_notification_t *m_portOperaStatusNotificationData; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /meta/NotificationQueuePfcDeadlock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationQueuePfcDeadlock: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationQueuePfcDeadlock( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationQueuePfcDeadlock(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | uint32_t m_count; 32 | 33 | sai_queue_deadlock_notification_data_t *m_queueDeadlockNotificationData; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /meta/NotificationSwitchAsicSdkHealthEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationSwitchAsicSdkHealthEvent: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationSwitchAsicSdkHealthEvent( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationSwitchAsicSdkHealthEvent(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | sai_object_id_t m_switchId; 32 | sai_switch_asic_sdk_health_severity_t m_severity; 33 | sai_switch_asic_sdk_health_category_t m_category; 34 | sai_timespec_t m_timestamp; 35 | sai_switch_health_data_t m_healthData; 36 | sai_u8_list_t m_description; 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /meta/NotificationSwitchShutdownRequest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationSwitchShutdownRequest: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationSwitchShutdownRequest( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationSwitchShutdownRequest() = default; 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | sai_object_id_t m_switchId; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /meta/NotificationSwitchStateChange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationSwitchStateChange: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationSwitchStateChange( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationSwitchStateChange() = default; 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | sai_object_id_t m_switchId; 32 | 33 | sai_switch_oper_status_t m_switchOperStatus; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /meta/NotificationTamTelTypeConfigChange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationTamTelTypeConfigChange : public Notification 8 | { 9 | public: 10 | NotificationTamTelTypeConfigChange( 11 | _In_ const std::string &serializedNotification); 12 | 13 | virtual ~NotificationTamTelTypeConfigChange() = default; 14 | 15 | public: 16 | 17 | virtual sai_object_id_t getSwitchId() const override; 18 | 19 | virtual sai_object_id_t getAnyObjectId() const override; 20 | 21 | virtual void processMetadata( 22 | _In_ std::shared_ptr meta) const override; 23 | 24 | virtual void executeCallback( 25 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 26 | 27 | private: 28 | 29 | sai_object_id_t m_tam_id; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /meta/NotificationTwampSessionEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Notification.h" 4 | 5 | namespace sairedis 6 | { 7 | class NotificationTwampSessionEvent: 8 | public Notification 9 | { 10 | public: 11 | 12 | NotificationTwampSessionEvent( 13 | _In_ const std::string& serializedNotification); 14 | 15 | virtual ~NotificationTwampSessionEvent(); 16 | 17 | public: 18 | 19 | virtual sai_object_id_t getSwitchId() const override; 20 | 21 | virtual sai_object_id_t getAnyObjectId() const override; 22 | 23 | virtual void processMetadata( 24 | _In_ std::shared_ptr meta) const override; 25 | 26 | virtual void executeCallback( 27 | _In_ const sai_switch_notifications_t& switchNotifications) const override; 28 | 29 | private: 30 | 31 | uint32_t m_count; 32 | 33 | sai_twamp_session_event_notification_data_t *m_twampSessionEventNotificationData; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /meta/NumberOidIndexGenerator.cpp: -------------------------------------------------------------------------------- 1 | #include "NumberOidIndexGenerator.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saimeta; 6 | 7 | NumberOidIndexGenerator::NumberOidIndexGenerator() 8 | { 9 | SWSS_LOG_ENTER(); 10 | 11 | reset(); 12 | } 13 | 14 | uint64_t NumberOidIndexGenerator::increment() 15 | { 16 | SWSS_LOG_ENTER(); 17 | 18 | return ++m_index; 19 | } 20 | 21 | std::vector NumberOidIndexGenerator::incrementBy( 22 | _In_ uint64_t count) 23 | { 24 | SWSS_LOG_ENTER(); 25 | 26 | std::vector result; 27 | result.reserve(static_cast(count)); 28 | 29 | for (uint64_t i = 0; i < count; ++i) 30 | { 31 | result.push_back(++m_index); 32 | } 33 | 34 | return result; 35 | } 36 | 37 | void NumberOidIndexGenerator::reset() 38 | { 39 | SWSS_LOG_ENTER(); 40 | 41 | m_index = 0; 42 | } 43 | -------------------------------------------------------------------------------- /meta/NumberOidIndexGenerator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "lib/OidIndexGenerator.h" 4 | 5 | namespace saimeta 6 | { 7 | class NumberOidIndexGenerator: 8 | public sairedis::OidIndexGenerator 9 | { 10 | 11 | public: 12 | 13 | NumberOidIndexGenerator(); 14 | 15 | virtual ~NumberOidIndexGenerator() = default; 16 | 17 | public: 18 | 19 | virtual uint64_t increment() override; 20 | virtual std::vector incrementBy( 21 | _In_ uint64_t count) override; 22 | 23 | virtual void reset() override; 24 | 25 | private: 26 | 27 | uint64_t m_index; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /meta/PerformanceIntervalTimer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace sairediscommon 9 | { 10 | class PerformanceIntervalTimer 11 | { 12 | public: 13 | 14 | static constexpr unsigned int DEFAULT_LIMIT = 10000; 15 | 16 | public: 17 | 18 | PerformanceIntervalTimer( 19 | _In_ const char* msg, 20 | _In_ uint64_t limit = DEFAULT_LIMIT); 21 | 22 | ~PerformanceIntervalTimer() = default; // non virtual 23 | 24 | public: 25 | 26 | void start(); 27 | 28 | void stop(); 29 | 30 | void inc( 31 | _In_ uint64_t val = 1); 32 | 33 | void reset(); 34 | 35 | public: 36 | 37 | static bool m_enable; 38 | 39 | private: 40 | 41 | std::string m_msg; 42 | 43 | std::chrono::time_point m_start; 44 | std::chrono::time_point m_stop; 45 | 46 | uint64_t m_limit; 47 | uint64_t m_count; 48 | uint64_t m_calls; 49 | uint64_t m_total; 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /meta/PortRelatedSet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "sai.h" 5 | } 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace saimeta 12 | { 13 | class PortRelatedSet 14 | { 15 | public: 16 | 17 | PortRelatedSet() = default; 18 | 19 | virtual ~PortRelatedSet() = default; 20 | 21 | public: 22 | 23 | void insert( 24 | _In_ sai_object_id_t portId, 25 | _In_ sai_object_id_t relatedObjectId); 26 | 27 | const std::set getPortRelatedObjects( 28 | _In_ sai_object_id_t portId) const; 29 | 30 | void clear(); 31 | 32 | void removePort( 33 | _In_ sai_object_id_t portId); 34 | 35 | std::vector getAllPorts() const; 36 | 37 | private: 38 | 39 | std::map> m_mapset; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /meta/SaiAttrWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "saimetadata.h" 5 | } 6 | 7 | #include "swss/sal.h" 8 | 9 | namespace saimeta 10 | { 11 | class SaiAttrWrapper 12 | { 13 | public: 14 | 15 | SaiAttrWrapper( 16 | _In_ const sai_attr_metadata_t* meta, 17 | _In_ const sai_attribute_t& attr); 18 | 19 | virtual ~SaiAttrWrapper(); 20 | 21 | public: 22 | 23 | const sai_attribute_t* getSaiAttr() const; 24 | 25 | const sai_attr_metadata_t* getSaiAttrMetadata() const; 26 | 27 | sai_attr_id_t getAttrId() const; 28 | 29 | private: 30 | 31 | SaiAttrWrapper(const SaiAttrWrapper&) = delete; 32 | SaiAttrWrapper& operator=(const SaiAttrWrapper&) = delete; 33 | 34 | private: 35 | 36 | /** 37 | * @brief Attribute metadata associated with given attribute. 38 | */ 39 | const sai_attr_metadata_t* m_meta; 40 | 41 | sai_attribute_t m_attr; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /meta/SaiOptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace sairedis 4 | { 5 | class SaiOptions 6 | { 7 | public: 8 | 9 | virtual ~SaiOptions() = default; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /meta/SelectableChannel.cpp: -------------------------------------------------------------------------------- 1 | #include "SelectableChannel.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace sairedis; 6 | 7 | SelectableChannel::SelectableChannel( 8 | _In_ int pri): 9 | Selectable(pri) 10 | { 11 | SWSS_LOG_ENTER(); 12 | 13 | // empty 14 | } 15 | -------------------------------------------------------------------------------- /meta/SelectableChannel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/selectable.h" 4 | #include "swss/table.h" 5 | #include "swss/sal.h" 6 | 7 | #include 8 | #include 9 | 10 | namespace sairedis 11 | { 12 | class SelectableChannel: 13 | public swss::Selectable 14 | { 15 | public: 16 | 17 | SelectableChannel( 18 | _In_ int pri = 0); 19 | 20 | virtual ~SelectableChannel() = default; 21 | 22 | public: 23 | 24 | virtual bool empty() = 0; 25 | 26 | virtual void pop( 27 | _Out_ swss::KeyOpFieldsValuesTuple& kco, 28 | _In_ bool initViewMode) = 0; 29 | 30 | virtual void set( 31 | _In_ const std::string& key, 32 | _In_ const std::vector& values, 33 | _In_ const std::string& op) = 0; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /package.cfg: -------------------------------------------------------------------------------- 1 | { 2 | "description": "This package contains SAI-Redis implementation and syncd for SONiC project.", 3 | "version": "1.0.0", 4 | "maintainer": "Kamil Cudnik ", 5 | "build_depends": [ ], 6 | "packages": [ 7 | { 8 | "name": "sonic-sairedis", 9 | "dependencies": [ 10 | ], 11 | "files": [ 12 | ] 13 | } 14 | ] 15 | } 16 | 17 | -------------------------------------------------------------------------------- /proxylib/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I$(top_srcdir)/meta 2 | 3 | lib_LTLIBRARIES = libsaiproxy.la 4 | 5 | noinst_LIBRARIES = libSaiProxy.a 6 | 7 | libSaiProxy_a_SOURCES = \ 8 | Options.cpp \ 9 | Proxy.cpp \ 10 | Sai.cpp 11 | 12 | BUILT_SOURCES = sai_proxy.cpp 13 | 14 | sai_proxy.cpp: $(top_srcdir)/SAI/meta/saimetadata.c ../stub.pl 15 | ../stub.pl -d ../SAI/ -c Sai -n saiproxy -f sai_proxy.cpp -s stub 16 | 17 | clean-local: 18 | rm -f sai_proxy.cpp 19 | 20 | libsaiproxy_la_SOURCES = sai_proxy.cpp 21 | 22 | libSaiProxy_a_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) 23 | libSaiProxy_a_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) 24 | 25 | libsaiproxy_la_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) 26 | libsaiproxy_la_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) 27 | libsaiproxy_la_LIBADD = -lhiredis -lswsscommon libSaiProxy.a $(CODE_COVERAGE_LIBS) 28 | 29 | # TODO - lib sai proxy server that will accept VendorSai 30 | 31 | -------------------------------------------------------------------------------- /proxylib/Options.cpp: -------------------------------------------------------------------------------- 1 | #include "Options.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | #include 6 | 7 | using namespace saiproxy; 8 | 9 | Options::Options() 10 | { 11 | SWSS_LOG_ENTER(); 12 | 13 | m_config = "config.ini"; 14 | 15 | m_zmqChannel = "tcp://127.0.0.1:5555"; 16 | m_zmqNtfChannel = "tcp://127.0.0.1:5556"; 17 | } 18 | 19 | std::string Options::getString() const 20 | { 21 | SWSS_LOG_ENTER(); 22 | 23 | std::stringstream ss; 24 | 25 | ss << " Config=" << m_config; 26 | ss << " ZmqChannel=" << m_zmqChannel; 27 | ss << " ZmqNtfChannel=" << m_zmqNtfChannel; 28 | 29 | return ss.str(); 30 | } 31 | -------------------------------------------------------------------------------- /proxylib/Options.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace saiproxy 6 | { 7 | class Options 8 | { 9 | public: 10 | 11 | Options(); 12 | 13 | ~Options() = default; 14 | 15 | public: 16 | 17 | std::string getString() const; 18 | 19 | public: 20 | 21 | std::string m_config; 22 | std::string m_zmqChannel; 23 | std::string m_zmqNtfChannel; 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /proxylib/SaiInternal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define MUTEX() std::lock_guard _lock(m_apimutex) 4 | #define MUTEX_UNLOCK() m_apimutex.unlock() 5 | -------------------------------------------------------------------------------- /proxylib/saiproxy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * @brief Proxy config. 5 | * 6 | * Optional. Should point to a config.ini/profile.ini which will contain 7 | * profile variables that should be put into service method table. 8 | */ 9 | #define SAI_PROXY_KEY_CONFIG "SAI_PROXY_CONFIG 10 | -------------------------------------------------------------------------------- /pyext/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = py3 2 | if PYTHON2 3 | SUBDIRS += py2 4 | endif 5 | 6 | ACLOCAL_AMFLAGS = -I m4 7 | -------------------------------------------------------------------------------- /pyext/py2/Makefile.am: -------------------------------------------------------------------------------- 1 | SWIG_SRC=../pysairedis.i 2 | SOURCES=../pysairedis.h ../pysairedis.cpp 3 | 4 | pkgpython_PYTHON = pysairedis.py __init__.py 5 | pkgpyexec_LTLIBRARIES = _pysairedis.la 6 | 7 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I.. 8 | 9 | BUILT_SOURCES = pysairedis_wrap.cpp 10 | 11 | _pysairedis_la_SOURCES = pysairedis_wrap.cpp $(SOURCES) 12 | _pysairedis_la_CXXFLAGS = $(PYTHON2_CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) \ 13 | -Wno-cast-qual -Wno-shadow -Wno-redundant-decls -Wno-conversion $(NO_CAST_FUNCTION_TYPE) 14 | 15 | _pysairedis_la_LDFLAGS = -module \ 16 | -lhiredis -lswsscommon -lpthread \ 17 | -L$(top_srcdir)/lib/.libs -lsairedis \ 18 | -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta \ 19 | -lzmq 20 | 21 | _pysairedis_la_LIBADD = $(PYTHON2_LIBS) 22 | 23 | SWIG_FLAG = -Wall -c++ -python -keyword 24 | if ARCH64 25 | SWIG_FLAG += -DSWIGWORDSIZE64 26 | endif 27 | 28 | pysairedis_wrap.cpp: $(SWIG_SRC) $(SOURCES) 29 | $(SWIG) $(SWIG_FLAG) $(AM_CXXFLAGS) -o $@ $< 30 | 31 | CLEANFILES = pysairedis_wrap.cpp 32 | -------------------------------------------------------------------------------- /pyext/py2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonic-net/sonic-sairedis/205e560e8f2ad526aa7b587329e49b77231f18fa/pyext/py2/__init__.py -------------------------------------------------------------------------------- /pyext/py3/Makefile.am: -------------------------------------------------------------------------------- 1 | SWIG_SRC=../pysairedis.i 2 | SOURCES=../pysairedis.h ../pysairedis.cpp 3 | 4 | pkgpython3_PYTHON = pysairedis.py __init__.py 5 | pkgpy3exec_LTLIBRARIES = _pysairedis.la 6 | 7 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I.. 8 | 9 | BUILT_SOURCES = pysairedis_wrap.cpp 10 | 11 | _pysairedis_la_SOURCES = pysairedis_wrap.cpp $(SOURCES) 12 | _pysairedis_la_CXXFLAGS = $(PYTHON3_CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) \ 13 | -Wno-cast-qual -Wno-shadow -Wno-redundant-decls -Wno-conversion $(NO_CAST_FUNCTION_TYPE) 14 | 15 | _pysairedis_la_LDFLAGS = -module \ 16 | -lhiredis -lswsscommon -lpthread \ 17 | -L$(top_srcdir)/lib/.libs -lsairedis \ 18 | -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta \ 19 | -lzmq 20 | 21 | _pysairedis_la_LIBADD = $(PYTHON3_BLDLIBRARY) 22 | 23 | SWIG_FLAG = -Wall -c++ -python -keyword 24 | if ARCH64 25 | SWIG_FLAG += -DSWIGWORDSIZE64 26 | endif 27 | 28 | pysairedis_wrap.cpp: $(SWIG_SRC) $(SOURCES) 29 | $(SWIG) $(SWIG_FLAG) $(AM_CXXFLAGS) -o $@ $< 30 | 31 | CLEANFILES = pysairedis_wrap.cpp 32 | -------------------------------------------------------------------------------- /pyext/py3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonic-net/sonic-sairedis/205e560e8f2ad526aa7b587329e49b77231f18fa/pyext/py3/__init__.py -------------------------------------------------------------------------------- /pyext/pysairedis.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | extern "C" { 5 | #include "sai.h" 6 | } 7 | 8 | #include 9 | #include 10 | 11 | sai_status_t sai_api_initialize( 12 | uint64_t flags, 13 | const std::map& profileMap); 14 | 15 | // will take python callback, and return C callback to set on notify attributes 16 | sai_pointer_t sai_get_notification_pointer( 17 | sai_attr_id_t id, 18 | PyObject*callback); 19 | -------------------------------------------------------------------------------- /saiasiccmp/AsicCmp.cpp: -------------------------------------------------------------------------------- 1 | #include "AsicCmp.h" 2 | #include "ViewCmp.h" 3 | 4 | #include "swss/logger.h" 5 | 6 | #include 7 | 8 | using namespace saiasiccmp; 9 | 10 | AsicCmp::AsicCmp( 11 | _In_ std::shared_ptr options): 12 | m_commandLineOptions(options) 13 | { 14 | SWSS_LOG_ENTER(); 15 | 16 | // empty 17 | } 18 | 19 | bool AsicCmp::compare() 20 | { 21 | SWSS_LOG_ENTER(); 22 | 23 | auto& args = m_commandLineOptions->m_args; 24 | 25 | if (args.size() != 2) 26 | { 27 | SWSS_LOG_ERROR("ERROR: expected 2 input files, but given: %zu", args.size()); 28 | return false; 29 | } 30 | 31 | try 32 | { 33 | auto a = std::make_shared(args[0]); 34 | auto b = std::make_shared(args[1]); 35 | 36 | SWSS_LOG_NOTICE("max objects: %lu %lu", a->m_maxObjectIndex, b->m_maxObjectIndex); 37 | 38 | b->translateViewVids(a->m_maxObjectIndex); 39 | 40 | ViewCmp cmp(a, b); 41 | 42 | return cmp.compareViews(m_commandLineOptions->m_dumpDiffToStdErr); 43 | } 44 | catch (const std::exception& e) 45 | { 46 | std::cerr << "Exception: " << e.what() << std::endl; 47 | 48 | SWSS_LOG_ERROR("Exception: %s", e.what()); 49 | 50 | return false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /saiasiccmp/AsicCmp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include "CommandLineOptions.h" 6 | 7 | #include 8 | 9 | namespace saiasiccmp 10 | { 11 | class AsicCmp 12 | { 13 | public: 14 | 15 | AsicCmp( 16 | _In_ std::shared_ptr options); 17 | 18 | public: 19 | 20 | bool compare(); 21 | 22 | private: 23 | 24 | std::shared_ptr m_commandLineOptions; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /saiasiccmp/CommandLineOptions.cpp: -------------------------------------------------------------------------------- 1 | #include "CommandLineOptions.h" 2 | 3 | #include "meta/sai_serialize.h" 4 | 5 | #include "swss/logger.h" 6 | 7 | #include 8 | 9 | using namespace saiasiccmp; 10 | 11 | CommandLineOptions::CommandLineOptions() 12 | { 13 | SWSS_LOG_ENTER(); 14 | 15 | // default values for command line options 16 | 17 | m_enableLogLevelInfo = false; 18 | m_dumpDiffToStdErr = false; 19 | } 20 | 21 | std::string CommandLineOptions::getCommandLineString() const 22 | { 23 | SWSS_LOG_ENTER(); 24 | 25 | std::stringstream ss; 26 | 27 | ss << " EnableLogLevelInfo=" << (m_enableLogLevelInfo ? "YES" : "NO"); 28 | ss << " DumpDiffToStdErr=" << (m_dumpDiffToStdErr ? "YES" : "NO"); 29 | 30 | for (auto &arg: m_args) 31 | { 32 | ss << " " << arg ; 33 | } 34 | 35 | return ss.str(); 36 | } 37 | -------------------------------------------------------------------------------- /saiasiccmp/CommandLineOptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace saiasiccmp 9 | { 10 | class CommandLineOptions 11 | { 12 | public: 13 | 14 | CommandLineOptions(); 15 | 16 | virtual ~CommandLineOptions() = default; 17 | 18 | public: 19 | 20 | virtual std::string getCommandLineString() const; 21 | 22 | public: 23 | 24 | bool m_enableLogLevelInfo; 25 | bool m_dumpDiffToStdErr; 26 | 27 | std::vector m_args; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /saiasiccmp/CommandLineOptionsParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CommandLineOptions.h" 4 | 5 | #include 6 | 7 | namespace saiasiccmp 8 | { 9 | class CommandLineOptionsParser 10 | { 11 | private: 12 | 13 | CommandLineOptionsParser() = delete; 14 | 15 | ~CommandLineOptionsParser() = delete; 16 | 17 | public: 18 | 19 | static std::shared_ptr parseCommandLine( 20 | _In_ int argc, 21 | _In_ char **argv); 22 | 23 | static void printUsage(); 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /saiasiccmp/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/meta -I$(top_srcdir)/lib -I$(top_srcdir)/syncd 2 | 3 | bin_PROGRAMS = saiasiccmp 4 | 5 | noinst_LIBRARIES = libAsicCmp.a 6 | 7 | libAsicCmp_a_SOURCES = \ 8 | AsicCmp.cpp \ 9 | CommandLineOptions.cpp \ 10 | CommandLineOptionsParser.cpp \ 11 | SaiSwitchAsic.cpp \ 12 | View.cpp \ 13 | ViewCmp.cpp 14 | 15 | libAsicCmp_a_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) 16 | libAsicCmp_a_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) 17 | 18 | saiasiccmp_SOURCES = main.cpp 19 | saiasiccmp_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) 20 | saiasiccmp_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) 21 | saiasiccmp_LDADD = libAsicCmp.a \ 22 | -ldl -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq \ 23 | $(top_srcdir)/syncd/libSyncd.a $(top_srcdir)/lib/libSaiRedis.a -lhiredis -lswsscommon $(CODE_COVERAGE_LIBS) 24 | 25 | TESTS = test.sh 26 | -------------------------------------------------------------------------------- /saiasiccmp/ViewCmp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include "View.h" 6 | 7 | #include 8 | 9 | namespace saiasiccmp 10 | { 11 | class ViewCmp 12 | { 13 | public: 14 | 15 | ViewCmp( 16 | _In_ std::shared_ptr a, 17 | _In_ std::shared_ptr b); 18 | 19 | public: 20 | 21 | bool compareViews( 22 | _In_ bool dumpDiffToStdErr); 23 | 24 | private: 25 | 26 | void checkColdVids(); 27 | 28 | void checkHidden(); 29 | 30 | void checkVidRidMaps(); 31 | 32 | void checkVidRidMaps( 33 | _In_ std::shared_ptr a, 34 | _In_ std::shared_ptr b); 35 | 36 | void checkStartingPoint(); 37 | 38 | void checkStartingPoint( 39 | _In_ sai_object_type_t ot); 40 | 41 | public: 42 | 43 | std::shared_ptr m_va; 44 | std::shared_ptr m_vb; 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /saiasiccmp/main.cpp: -------------------------------------------------------------------------------- 1 | #include "CommandLineOptionsParser.h" 2 | #include "AsicCmp.h" 3 | 4 | #include "swss/logger.h" 5 | 6 | #include 7 | 8 | using namespace saiasiccmp; 9 | 10 | int main(int argc, char **argv) 11 | { 12 | swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); 13 | 14 | SWSS_LOG_ENTER(); 15 | 16 | swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); 17 | 18 | auto commandLineOptions = CommandLineOptionsParser::parseCommandLine(argc, argv); 19 | 20 | SWSS_LOG_NOTICE("command line: %s", commandLineOptions->getCommandLineString().c_str()); 21 | 22 | if (commandLineOptions->m_enableLogLevelInfo) 23 | { 24 | swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_INFO); 25 | } 26 | 27 | auto& args = commandLineOptions->m_args; 28 | 29 | if (args.size() != 2) 30 | { 31 | std::cerr << "ERROR: expected 2 input files, but given: " << args.size() << std::endl; 32 | exit(1); 33 | } 34 | 35 | AsicCmp asicCmp(commandLineOptions); 36 | 37 | bool equal = asicCmp.compare(); 38 | 39 | std::cerr << "views are" << (equal ? " " : " NOT " ) << "equal" << std::endl; 40 | 41 | return equal ? EXIT_SUCCESS : EXIT_FAILURE; 42 | } 43 | -------------------------------------------------------------------------------- /saiasiccmp/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | EXIT_VALUE=0 4 | 5 | function test_positive() 6 | { 7 | ./saiasiccmp dump1.json dump2.json 8 | 9 | if [ $? != 0 ]; then 10 | echo "${FUNCNAME[0]} ERROR: expected dumps to be equal" 11 | EXIT_VALUE=1 12 | fi 13 | } 14 | 15 | function test_negative() 16 | { 17 | ./saiasiccmp dump1.json dump3.json 18 | 19 | if [ $? == 0 ]; then 20 | echo "${FUNCNAME[0]} ERROR: expected dumps to be not equal" 21 | EXIT_VALUE=1 22 | fi 23 | } 24 | 25 | test_positive; 26 | test_negative; 27 | 28 | exit $EXIT_VALUE 29 | -------------------------------------------------------------------------------- /saidiscovery/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/meta -I$(top_srcdir)/lib 2 | 3 | bin_PROGRAMS = saidiscovery 4 | 5 | if SAIVS 6 | SAILIB=-L$(top_srcdir)/vslib/.libs -lsaivs $(VPP_LIBS) 7 | else 8 | SAILIB=-lsai 9 | endif 10 | 11 | saidiscovery_SOURCES = saidiscovery.cpp 12 | 13 | saidiscovery_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) 14 | saidiscovery_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) 15 | saidiscovery_LDADD = -lhiredis -lswsscommon $(top_srcdir)/syncd/libSyncd.a $(SAILIB) -lpthread \ 16 | -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) $(EXTRA_LIBSAI_LDFLAGS) 17 | -------------------------------------------------------------------------------- /saidump/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib 2 | 3 | bin_PROGRAMS = saidump 4 | 5 | saidump_SOURCES = main.cpp SaiDump.cpp 6 | saidump_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) 7 | saidump_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) 8 | saidump_LDADD = -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta \ 9 | -L$(top_srcdir)/lib/.libs -lsairedis -lzmq $(CODE_COVERAGE_LIBS) 10 | 11 | noinst_LIBRARIES = libsaidump.a 12 | 13 | libsaidump_a_SOURCES = SaiDump.cpp 14 | libsaidump_a_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) 15 | libsaidump_a_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) 16 | -------------------------------------------------------------------------------- /saidump/SaiDump.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "swss/table.h" 3 | #include "meta/sai_serialize.h" 4 | #include 5 | 6 | namespace syncd 7 | { 8 | class SaiDump 9 | { 10 | public: 11 | SaiDump(); 12 | ~SaiDump(); 13 | void handleCmdLine(int argc, char **argv); 14 | void dumpFromRedisDb(int argc, char **argv); 15 | void printUsage(); 16 | sai_status_t dumpFromRedisRdbJson(); 17 | void traverseJson(const nlohmann::json & jsn); 18 | void dumpGraphFun(const swss::TableDump& td); 19 | void printAttributes(size_t indent, const swss::TableMap& map); 20 | void dumpGraphTable(const swss::TableDump &dump); 21 | std::string getRdbJsonFile(); 22 | uint64_t getRdbJSonSizeLimit(); 23 | bool getDumpTempView(); 24 | bool getDumpGraph(); 25 | private: 26 | std::string rdbJsonFile; 27 | uint64_t rdbJSonSizeLimit; 28 | bool dumpTempView; 29 | bool dumpGraph; 30 | private: 31 | std::map mOidMap; 32 | private: 33 | size_t getMaxAttrLen(const swss::TableMap& map); 34 | std::string padString(std::string s, size_t pad); 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /saidump/main.cpp: -------------------------------------------------------------------------------- 1 | #include "SaiDump.h" 2 | 3 | using namespace syncd; 4 | 5 | int main(int argc, char **argv) 6 | { 7 | SWSS_LOG_ENTER(); 8 | SaiDump saiDump; 9 | saiDump.dumpFromRedisDb(argc, argv); 10 | return EXIT_SUCCESS; 11 | } -------------------------------------------------------------------------------- /saiplayer/CommandLineOptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sairedis.h" 4 | 5 | #include "swss/sal.h" 6 | 7 | #include 8 | #include 9 | 10 | namespace saiplayer 11 | { 12 | class CommandLineOptions 13 | { 14 | public: 15 | 16 | CommandLineOptions(); 17 | 18 | virtual ~CommandLineOptions() = default; 19 | 20 | public: 21 | 22 | virtual std::string getCommandLineString() const; 23 | 24 | public: 25 | 26 | bool m_useTempView; 27 | 28 | bool m_inspectAsic; 29 | 30 | bool m_skipNotifySyncd; 31 | 32 | bool m_enableDebug; 33 | 34 | bool m_sleep; 35 | 36 | bool m_syncMode; 37 | 38 | sai_redis_communication_mode_t m_redisCommunicationMode; 39 | 40 | bool m_enableRecording; 41 | 42 | std::string m_profileMapFile; 43 | 44 | std::string m_contextConfig; 45 | 46 | std::vector m_files; 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /saiplayer/CommandLineOptionsParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CommandLineOptions.h" 4 | 5 | #include 6 | 7 | namespace saiplayer 8 | { 9 | class CommandLineOptionsParser 10 | { 11 | private: 12 | 13 | CommandLineOptionsParser() = delete; 14 | 15 | ~CommandLineOptionsParser() = delete; 16 | 17 | public: 18 | 19 | static std::shared_ptr parseCommandLine( 20 | _In_ int argc, 21 | _In_ char **argv); 22 | 23 | static void printUsage(); 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /saiplayer/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib 2 | 3 | bin_PROGRAMS = saiplayer 4 | 5 | noinst_LIBRARIES = libSaiPlayer.a 6 | 7 | libSaiPlayer_a_SOURCES = \ 8 | CommandLineOptions.cpp \ 9 | CommandLineOptionsParser.cpp \ 10 | SaiPlayer.cpp 11 | 12 | libSaiPlayer_a_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) 13 | libSaiPlayer_a_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) 14 | 15 | saiplayer_SOURCES = saiplayer_main.cpp 16 | saiplayer_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) 17 | saiplayer_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) 18 | saiplayer_LDADD = libSaiPlayer.a $(top_srcdir)/syncd/libSyncd.a $(top_srcdir)/lib/libSaiRedis.a \ 19 | -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) 20 | -------------------------------------------------------------------------------- /saiplayer/saiplayer_main.cpp: -------------------------------------------------------------------------------- 1 | #include "SaiPlayer.h" 2 | #include "CommandLineOptionsParser.h" 3 | 4 | #include "lib/ClientServerSai.h" 5 | #include "syncd/MetadataLogger.h" 6 | 7 | #include "swss/logger.h" 8 | 9 | using namespace saiplayer; 10 | 11 | int main(int argc, char **argv) 12 | { 13 | swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); 14 | 15 | SWSS_LOG_ENTER(); 16 | 17 | swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); 18 | 19 | syncd::MetadataLogger::initialize(); 20 | 21 | auto commandLineOptions = CommandLineOptionsParser::parseCommandLine(argc, argv); 22 | 23 | auto sai = std::make_shared(); 24 | 25 | auto player = std::make_shared(sai, commandLineOptions); 26 | 27 | return player->run(); 28 | } 29 | -------------------------------------------------------------------------------- /saisdkdump/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = $(SAIINC) 2 | 3 | bin_PROGRAMS = saisdkdump 4 | 5 | if SAIVS 6 | SAILIB=-L$(top_srcdir)/vslib/.libs -lsaivs $(VPP_LIBS) 7 | else 8 | SAILIB=-lsai 9 | endif 10 | 11 | saisdkdump_SOURCES = saisdkdump.cpp 12 | saisdkdump_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) 13 | saisdkdump_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) 14 | saisdkdump_LDADD = -lhiredis -lswsscommon $(SAILIB) -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) $(EXTRA_LIBSAI_LDFLAGS) 15 | -------------------------------------------------------------------------------- /syncd/Asan.cpp: -------------------------------------------------------------------------------- 1 | #include "swss/logger.h" 2 | 3 | #include 4 | #include 5 | 6 | extern "C" { 7 | const char* __lsan_default_suppressions() { 8 | // SWSS_LOG_ENTER(); // disabled 9 | return "leak:__static_initialization_and_destruction_0\n"; 10 | } 11 | } 12 | 13 | static void sigterm_handler(int signo) 14 | { 15 | SWSS_LOG_ENTER(); 16 | 17 | __lsan_do_leak_check(); 18 | signal(signo, SIG_DFL); 19 | raise(signo); 20 | } 21 | 22 | __attribute__((constructor)) 23 | static void asan_init() 24 | { 25 | SWSS_LOG_ENTER(); 26 | 27 | if (signal(SIGTERM, sigterm_handler) == SIG_ERR) 28 | { 29 | SWSS_LOG_ERROR("failed to setup SIGTERM action"); 30 | exit(1); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /syncd/AsicOperation.cpp: -------------------------------------------------------------------------------- 1 | #include "AsicOperation.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace syncd; 6 | 7 | AsicOperation::AsicOperation( 8 | _In_ int id, 9 | _In_ sai_object_id_t vid, 10 | _In_ bool remove, 11 | _In_ std::shared_ptr& operation): 12 | m_opId(id), 13 | m_vid(vid), 14 | m_isRemove(remove), 15 | m_op(operation) 16 | { 17 | SWSS_LOG_ENTER(); 18 | 19 | // empty 20 | } 21 | -------------------------------------------------------------------------------- /syncd/AsicOperation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C"{ 4 | #include "sai.h" 5 | } 6 | 7 | #include "swss/table.h" 8 | 9 | #include 10 | #include 11 | 12 | namespace syncd 13 | { 14 | class AsicOperation 15 | { 16 | public: 17 | 18 | AsicOperation( 19 | _In_ int id, 20 | _In_ sai_object_id_t vid, 21 | _In_ bool remove, 22 | _In_ std::shared_ptr& operation); 23 | 24 | virtual ~AsicOperation() = default; 25 | 26 | public: 27 | 28 | int m_opId; 29 | 30 | sai_object_id_t m_vid; 31 | 32 | bool m_isRemove; 33 | 34 | std::shared_ptr m_op; 35 | 36 | std::string m_currentValue; 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /syncd/AttrVersionChecker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "sai.h" 5 | #include "saimetadata.h" 6 | } 7 | 8 | #include 9 | #include 10 | 11 | namespace syncd 12 | { 13 | class AttrVersionChecker 14 | { 15 | public: 16 | 17 | AttrVersionChecker(); 18 | 19 | public: 20 | 21 | void enable( 22 | _In_ bool enable); 23 | 24 | void setSaiApiVersion( 25 | _In_ sai_api_version_t version); 26 | 27 | void reset(); 28 | 29 | bool isSufficientVersion( 30 | _In_ const sai_attr_metadata_t *md); 31 | 32 | private: 33 | 34 | bool m_enabled; 35 | 36 | sai_api_version_t m_saiApiVersion; 37 | 38 | std::set m_visitedAttributes; 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /syncd/BreakConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "BreakConfig.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace syncd; 6 | 7 | void BreakConfig::insert( 8 | _In_ sai_object_type_t objectType) 9 | { 10 | SWSS_LOG_ENTER(); 11 | 12 | m_set.insert(objectType); 13 | } 14 | 15 | void BreakConfig::remove( 16 | _In_ sai_object_type_t objectType) 17 | { 18 | SWSS_LOG_ENTER(); 19 | 20 | auto it = m_set.find(objectType); 21 | 22 | if (it != m_set.end()) 23 | { 24 | m_set.erase(it); 25 | } 26 | } 27 | 28 | void BreakConfig::clear() 29 | { 30 | SWSS_LOG_ENTER(); 31 | 32 | m_set.clear(); 33 | } 34 | 35 | bool BreakConfig::shouldBreakBeforeMake( 36 | _In_ sai_object_type_t objectType) const 37 | { 38 | SWSS_LOG_ENTER(); 39 | 40 | return m_set.find(objectType) != m_set.end(); 41 | } 42 | 43 | size_t BreakConfig::size() const 44 | { 45 | SWSS_LOG_ENTER(); 46 | 47 | return m_set.size(); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /syncd/BreakConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C"{ 4 | #include "sai.h" 5 | } 6 | 7 | #include 8 | 9 | namespace syncd 10 | { 11 | class BreakConfig 12 | { 13 | public: 14 | 15 | BreakConfig() = default; 16 | 17 | ~BreakConfig() = default; 18 | 19 | public: 20 | 21 | void insert( 22 | _In_ sai_object_type_t objectType); 23 | 24 | void remove( 25 | _In_ sai_object_type_t objectType); 26 | 27 | void clear(); 28 | 29 | bool shouldBreakBeforeMake( 30 | _In_ sai_object_type_t objectType) const; 31 | 32 | size_t size() const; 33 | 34 | private: 35 | 36 | std::set m_set; 37 | 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /syncd/BreakConfigParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BreakConfig.h" 4 | 5 | #include 6 | 7 | namespace syncd 8 | { 9 | class BreakConfigParser 10 | { 11 | private: 12 | 13 | BreakConfigParser() = delete; 14 | 15 | ~BreakConfigParser() = delete; 16 | 17 | public: 18 | 19 | static std::shared_ptr parseBreakConfig( 20 | _In_ const std::string& filePath); 21 | 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /syncd/CommandLineOptionsParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CommandLineOptions.h" 4 | 5 | #include 6 | 7 | namespace syncd 8 | { 9 | class CommandLineOptionsParser 10 | { 11 | private: 12 | 13 | CommandLineOptionsParser() = delete; 14 | 15 | ~CommandLineOptionsParser() = delete; 16 | 17 | public: 18 | 19 | static std::shared_ptr parseCommandLine( 20 | _In_ int argc, 21 | _In_ char **argv); 22 | 23 | static void printUsage(); 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /syncd/GlobalSwitchId.cpp: -------------------------------------------------------------------------------- 1 | #include "GlobalSwitchId.h" 2 | 3 | #include "meta/sai_serialize.h" 4 | 5 | #include "swss/logger.h" 6 | 7 | using namespace syncd; 8 | 9 | #ifdef SAITHRIFT 10 | 11 | /** 12 | * @brief Global switch RID used by thrift RPC server. 13 | */ 14 | sai_object_id_t gSwitchId = SAI_NULL_OBJECT_ID; 15 | 16 | #endif 17 | 18 | void GlobalSwitchId::setSwitchId( 19 | _In_ sai_object_id_t switchRid) 20 | { 21 | SWSS_LOG_ENTER(); 22 | 23 | #ifdef SAITHRIFT 24 | 25 | if (gSwitchId != SAI_NULL_OBJECT_ID) 26 | { 27 | SWSS_LOG_THROW("gSwitchId already initialized!, SAI THRIFT don't support multiple switches yet, FIXME"); 28 | } 29 | 30 | gSwitchId = switchRid; 31 | 32 | SWSS_LOG_NOTICE("Initialize gSwitchId with ID = %s", 33 | sai_serialize_object_id(gSwitchId).c_str()); 34 | #endif 35 | 36 | } 37 | -------------------------------------------------------------------------------- /syncd/GlobalSwitchId.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "sai.h" 5 | } 6 | 7 | namespace syncd 8 | { 9 | class GlobalSwitchId 10 | { 11 | private: 12 | 13 | GlobalSwitchId() = delete; 14 | ~GlobalSwitchId() = delete; 15 | 16 | public: 17 | 18 | static void setSwitchId( 19 | _In_ sai_object_id_t switchRid); 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /syncd/MdioIpcClient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | extern "C" { 7 | #include "sai.h" 8 | } 9 | 10 | /* Function declarations */ 11 | extern "C" { 12 | sai_status_t mdio_read(uint64_t platform_context, uint32_t mdio_addr, uint32_t reg_addr, 13 | uint32_t number_of_registers, uint32_t *data); 14 | sai_status_t mdio_write(uint64_t platform_context, uint32_t mdio_addr, 15 | uint32_t reg_addr, uint32_t number_of_registers, const uint32_t *data); 16 | 17 | sai_status_t mdio_read_cl22(uint64_t platform_context, uint32_t mdio_addr, uint32_t reg_addr, 18 | uint32_t number_of_registers, uint32_t *data); 19 | sai_status_t mdio_write_cl22(uint64_t platform_context, uint32_t mdio_addr, 20 | uint32_t reg_addr, uint32_t number_of_registers, const uint32_t *data); 21 | } 22 | -------------------------------------------------------------------------------- /syncd/MdioIpcCommon.h: -------------------------------------------------------------------------------- 1 | #define SYNCD_IPC_SOCK_SYNCD "/var/run/sswsyncd" 2 | #define SYNCD_IPC_SOCK_HOST "/var/run/docker-syncd" 3 | #define SYNCD_IPC_SOCK_FILE "mdio-ipc" 4 | #define SYNCD_IPC_BUFF_SIZE 256 /* buffer size */ 5 | 6 | #define MDIO_SERVER_TIMEOUT 30 /* sec, connection timeout */ 7 | #define MDIO_CLIENT_TIMEOUT 25 /* shorter than 30 sec on server side */ 8 | 9 | #define MDIO_CONN_MAX 18 /* max. number of connections */ 10 | -------------------------------------------------------------------------------- /syncd/MetadataLogger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace syncd 4 | { 5 | class MetadataLogger 6 | { 7 | private: 8 | 9 | MetadataLogger() = delete; 10 | ~MetadataLogger() = delete; 11 | 12 | public: 13 | 14 | static void initialize(); 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /syncd/NotificationProducerBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "swss/table.h" 6 | #include "swss/sal.h" 7 | 8 | namespace syncd 9 | { 10 | class NotificationProducerBase 11 | { 12 | public: 13 | 14 | NotificationProducerBase() = default; 15 | 16 | virtual ~NotificationProducerBase() = default; 17 | 18 | public: 19 | 20 | virtual void send( 21 | _In_ const std::string& op, 22 | _In_ const std::string& data, 23 | _In_ const std::vector& values) = 0; 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /syncd/PortMap.cpp: -------------------------------------------------------------------------------- 1 | #include "PortMap.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace syncd; 6 | 7 | /** 8 | * @brief Port map global map. 9 | * 10 | * WARNING: This object must have global declaration and this exact name since 11 | * external RPC server is linking against this object when in use. 12 | */ 13 | std::map, std::string> gPortMap; 14 | 15 | void PortMap::insert( 16 | _In_ const std::set& laneSet, 17 | _In_ const std::string& name) 18 | { 19 | SWSS_LOG_ENTER(); 20 | 21 | m_portMap.insert(std::make_pair(laneSet, name)); 22 | } 23 | 24 | void PortMap::clear() 25 | { 26 | SWSS_LOG_ENTER(); 27 | 28 | m_portMap.clear(); 29 | } 30 | 31 | size_t PortMap::size() const 32 | { 33 | SWSS_LOG_ENTER(); 34 | 35 | return m_portMap.size(); 36 | } 37 | 38 | const std::map, std::string>& PortMap::getRawPortMap() const 39 | { 40 | SWSS_LOG_ENTER(); 41 | 42 | return m_portMap; 43 | }; 44 | 45 | void PortMap::setGlobalPortMap( 46 | _In_ std::shared_ptr portMap) 47 | { 48 | SWSS_LOG_ENTER(); 49 | 50 | SWSS_LOG_NOTICE("setting global gPortMap for rpc server"); 51 | 52 | gPortMap = portMap->getRawPortMap(); 53 | } 54 | -------------------------------------------------------------------------------- /syncd/PortMap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace syncd 11 | { 12 | class PortMap 13 | { 14 | public: 15 | 16 | PortMap() = default; 17 | 18 | virtual ~PortMap() = default; 19 | 20 | public: 21 | 22 | void insert( 23 | _In_ const std::set& laneSet, 24 | _In_ const std::string& name); 25 | 26 | void clear(); 27 | 28 | size_t size() const; 29 | 30 | const std::map, std::string>& getRawPortMap() const; 31 | 32 | /** 33 | * @brief Set global object for RPC server binding. 34 | */ 35 | static void setGlobalPortMap( 36 | _In_ std::shared_ptr portMap); 37 | 38 | private: 39 | 40 | std::map, std::string> m_portMap; 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /syncd/PortMapParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "PortMap.h" 4 | 5 | #include 6 | 7 | namespace syncd 8 | { 9 | class PortMapParser 10 | { 11 | private: 12 | 13 | PortMapParser() = delete; 14 | ~PortMapParser() = delete; 15 | 16 | public: 17 | 18 | static std::shared_ptr parsePortMap( 19 | _In_ const std::string& portMapFile); 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /syncd/RedisNotificationProducer.cpp: -------------------------------------------------------------------------------- 1 | #include "RedisNotificationProducer.h" 2 | 3 | #include "sairediscommon.h" 4 | 5 | #include "swss/logger.h" 6 | 7 | using namespace syncd; 8 | 9 | RedisNotificationProducer::RedisNotificationProducer( 10 | _In_ const std::string& dbName) 11 | { 12 | SWSS_LOG_ENTER(); 13 | 14 | m_db = std::make_shared(dbName, 0); 15 | 16 | m_notificationProducer = std::make_shared(m_db.get(), REDIS_TABLE_NOTIFICATIONS_PER_DB(dbName)); 17 | } 18 | 19 | void RedisNotificationProducer::send( 20 | _In_ const std::string& op, 21 | _In_ const std::string& data, 22 | _In_ const std::vector& values) 23 | { 24 | SWSS_LOG_ENTER(); 25 | 26 | std::vector vals = values; 27 | 28 | m_notificationProducer->send(op, data, vals); 29 | } 30 | -------------------------------------------------------------------------------- /syncd/RedisNotificationProducer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "NotificationProducerBase.h" 4 | 5 | #include "swss/dbconnector.h" 6 | #include "swss/notificationproducer.h" 7 | 8 | namespace syncd 9 | { 10 | class RedisNotificationProducer: 11 | public NotificationProducerBase 12 | { 13 | public: 14 | 15 | RedisNotificationProducer( 16 | _In_ const std::string& dbName); 17 | 18 | virtual ~RedisNotificationProducer() = default; 19 | 20 | public: 21 | 22 | virtual void send( 23 | _In_ const std::string& op, 24 | _In_ const std::string& data, 25 | _In_ const std::vector& values) override; 26 | 27 | private: 28 | 29 | std::shared_ptr m_db; 30 | 31 | std::shared_ptr m_notificationProducer; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /syncd/RequestShutdown.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "RequestShutdownCommandLineOptions.h" 4 | #include "ContextConfig.h" 5 | 6 | #include "swss/sal.h" 7 | 8 | #include 9 | 10 | #define SYNCD_NOTIFICATION_CHANNEL_RESTARTQUERY "RESTARTQUERY" 11 | 12 | /** 13 | * @brief Notification channel 'restartQuery' per DB scope 14 | * 15 | * In https://redis.io/docs/manual/pubsub/, it says: 16 | * "Pub/Sub has no relation to the key space. It was made to not interfere with 17 | * it on any level, including database numbers." 18 | */ 19 | #define SYNCD_NOTIFICATION_CHANNEL_RESTARTQUERY_PER_DB(dbName) \ 20 | ((dbName) == "ASIC_DB" ? \ 21 | SYNCD_NOTIFICATION_CHANNEL_RESTARTQUERY : \ 22 | (dbName) + "_" + SYNCD_NOTIFICATION_CHANNEL_RESTARTQUERY) 23 | 24 | namespace syncd 25 | { 26 | class RequestShutdown 27 | { 28 | public: 29 | 30 | RequestShutdown( 31 | _In_ std::shared_ptr options); 32 | 33 | virtual ~RequestShutdown(); 34 | 35 | public: 36 | 37 | void send(); 38 | 39 | private: 40 | 41 | std::shared_ptr m_options; 42 | 43 | std::shared_ptr m_contextConfig; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /syncd/RequestShutdownCommandLineOptionsParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "RequestShutdownCommandLineOptions.h" 4 | 5 | #include "swss/sal.h" 6 | 7 | #include 8 | 9 | namespace syncd 10 | { 11 | class RequestShutdownCommandLineOptionsParser 12 | { 13 | private: 14 | 15 | RequestShutdownCommandLineOptionsParser() = delete; 16 | 17 | ~RequestShutdownCommandLineOptionsParser() = delete; 18 | 19 | public: 20 | 21 | static std::shared_ptr parseCommandLine( 22 | _In_ int argc, 23 | _In_ char **argv); 24 | 25 | static void printUsage(); 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /syncd/SelectableEventHandler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace syncd 4 | { 5 | // This class implements handler for Selectable events. 6 | class SelectableEventHandler 7 | { 8 | public: 9 | 10 | virtual ~SelectableEventHandler() = default; 11 | 12 | virtual void handleSelectableEvent() = 0; 13 | 14 | protected: 15 | 16 | SelectableEventHandler() = default; 17 | }; 18 | 19 | } // namespace syncd 20 | -------------------------------------------------------------------------------- /syncd/VendorSaiOptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "meta/SaiOptions.h" 4 | 5 | namespace syncd 6 | { 7 | class VendorSaiOptions: 8 | public sairedis::SaiOptions 9 | { 10 | public: 11 | static constexpr const char *OPTIONS_KEY = "vok"; 12 | 13 | public: 14 | 15 | bool m_checkAttrVersion = false; 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /syncd/WarmRestartTable.cpp: -------------------------------------------------------------------------------- 1 | #include "WarmRestartTable.h" 2 | 3 | using namespace syncd; 4 | 5 | WarmRestartTable::WarmRestartTable( 6 | _In_ const std::string& dbName) 7 | { 8 | SWSS_LOG_ENTER(); 9 | 10 | m_dbState = std::make_shared(dbName, 0); 11 | 12 | m_table = std::make_shared(m_dbState.get(), STATE_WARM_RESTART_TABLE_NAME); 13 | } 14 | 15 | WarmRestartTable::~WarmRestartTable() 16 | { 17 | SWSS_LOG_ENTER(); 18 | 19 | // empty 20 | } 21 | 22 | void WarmRestartTable::setFlagFailed() 23 | { 24 | SWSS_LOG_ENTER(); 25 | 26 | m_table->hset("warm-shutdown", "state", "set-flag-failed"); 27 | } 28 | 29 | void WarmRestartTable::setPreShutdown( 30 | _In_ bool succeeded) 31 | { 32 | SWSS_LOG_ENTER(); 33 | 34 | m_table->hset("warm-shutdown", "state", succeeded ? "pre-shutdown-succeeded" : "pre-shutdown-failed"); 35 | } 36 | 37 | void WarmRestartTable::setWarmShutdown( 38 | _In_ bool succeeded) 39 | { 40 | SWSS_LOG_ENTER(); 41 | 42 | m_table->hset("warm-shutdown", "state", succeeded ? "warm-shutdown-succeeded": "warm-shutdown-failed"); 43 | } 44 | -------------------------------------------------------------------------------- /syncd/WarmRestartTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | #include "swss/dbconnector.h" 5 | #include "swss/table.h" 6 | 7 | #include 8 | #include 9 | 10 | namespace syncd 11 | { 12 | class WarmRestartTable 13 | { 14 | public: 15 | 16 | WarmRestartTable( 17 | _In_ const std::string& dbName); 18 | 19 | virtual ~WarmRestartTable(); 20 | 21 | public: 22 | 23 | void setFlagFailed(); 24 | 25 | void setPreShutdown( 26 | _In_ bool succeeded); 27 | 28 | void setWarmShutdown( 29 | _In_ bool succeeded); 30 | 31 | private: 32 | 33 | std::shared_ptr m_dbState; 34 | 35 | std::shared_ptr m_table; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /syncd/WatchdogScope.cpp: -------------------------------------------------------------------------------- 1 | #include "WatchdogScope.h" 2 | 3 | using namespace syncd; 4 | 5 | WatchdogScope::WatchdogScope( 6 | _In_ TimerWatchdog& tw, 7 | _In_ const std::string& eventName, 8 | _In_ const swss::KeyOpFieldsValuesTuple* kco): 9 | m_tw(tw) 10 | { 11 | // SWSS_LOG_ENTER(); // disabled 12 | 13 | m_tw.setStartTime(); 14 | 15 | m_tw.setEventData(eventName, kco); 16 | } 17 | 18 | WatchdogScope::~WatchdogScope() 19 | { 20 | // SWSS_LOG_ENTER(); // disabled 21 | 22 | m_tw.setEndTime(); 23 | } 24 | -------------------------------------------------------------------------------- /syncd/WatchdogScope.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TimerWatchdog.h" 4 | 5 | namespace syncd 6 | { 7 | class WatchdogScope 8 | { 9 | public: 10 | 11 | /** 12 | * @brief Watchdog scope constructor. 13 | * 14 | * @param timerWatchdog - Timer watchdog to work on. 15 | * @param eventName - Name of the event. 16 | * @param data - Event data. NOTE: event data is passed here as a 17 | * pointer here to avoid expensive data copy, but then we must be 18 | * sure that that data object was not destroyed before watchdog 19 | * scope destructor will be called. This will make sure that if 20 | * event was too long, then it data will be logged into syslog from 21 | * object that is still alive and not destroyed. 22 | */ 23 | WatchdogScope( 24 | _In_ TimerWatchdog& timerWatchdog, 25 | _In_ const std::string& eventName, 26 | _In_ const swss::KeyOpFieldsValuesTuple* data = nullptr); 27 | 28 | ~WatchdogScope(); 29 | 30 | private: 31 | 32 | TimerWatchdog& m_tw; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /syncd/ZeroMQNotificationProducer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "NotificationProducerBase.h" 4 | 5 | #include "swss/dbconnector.h" 6 | #include "swss/notificationproducer.h" 7 | 8 | namespace syncd 9 | { 10 | class ZeroMQNotificationProducer: 11 | public NotificationProducerBase 12 | { 13 | public: 14 | 15 | ZeroMQNotificationProducer( 16 | _In_ const std::string& ntfEndpoint); 17 | 18 | virtual ~ZeroMQNotificationProducer(); 19 | 20 | public: 21 | 22 | virtual void send( 23 | _In_ const std::string& op, 24 | _In_ const std::string& data, 25 | _In_ const std::vector& values) override; 26 | 27 | private: 28 | 29 | void* m_ntfContext; 30 | 31 | void* m_ntfSocket; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /syncd/lanemap.ini: -------------------------------------------------------------------------------- 1 | ; comment 2 | # comment 3 | eth0:29,30,31,32 4 | eth1:25,26,27,28 5 | eth2:37,38,39,40 6 | eth3:33,34,35,36 7 | eth4:41,42,43,44 8 | eth5:45,46,47,48 9 | eth6:5,6,7,8 10 | eth7:1,2,3,4 11 | eth8:9,10,11,12 12 | eth9:13,14,15,16 13 | eth10:21,22,23,24 14 | eth11:17,18,19,20 15 | eth12:249,50,51,52 16 | eth13:353,54,55,56 17 | eth14:461,62,63,64 18 | eth15:557,58,59,60 19 | eth16:665,66,67,68 20 | eth17:769,70,71,72 21 | eth18:877,78,79,80 22 | eth19:973,74,75,76 23 | eth20:105,106,107,108 24 | eth21:109,110,111,112 25 | eth22:117,118,119,120 26 | eth23:113,114,115,116 27 | eth24:121,122,123,124 28 | eth25:125,126,127,128 29 | eth26:85,86,87,88 30 | eth27:81,82,83,84 31 | eth28:89,90,91,92 32 | eth29:93,94,95,96 33 | eth30:97,98,99,100 34 | eth31:101,102,103,104 35 | -------------------------------------------------------------------------------- /syncd/main.cpp: -------------------------------------------------------------------------------- 1 | #include "swss/logger.h" 2 | 3 | int syncd_main(int argc, char **argv); 4 | 5 | int main(int argc, char **argv) 6 | { 7 | SWSS_LOG_ENTER(); 8 | 9 | return syncd_main(argc, argv); 10 | } 11 | -------------------------------------------------------------------------------- /syncd/profile.ini: -------------------------------------------------------------------------------- 1 | SAI_WARM_BOOT_READ_FILE=/var/cache/sai_warmboot.bin 2 | SAI_WARM_BOOT_WRITE_FILE=/var/cache/sai_warmboot.bin 3 | -------------------------------------------------------------------------------- /syncd/scripts/sai_failure_dump.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Script for sai failure dump 4 | # 5 | 6 | # Source the platform specific dump file 7 | 8 | SAI_MAX_FAILURE_DUMPS=10 9 | 10 | DUMPDIR=/var/log/sai_failure_dump 11 | 12 | if [ -f /usr/bin/platform_syncd_dump.sh ]; then 13 | . ./usr/bin/platform_syncd_dump.sh 14 | fi 15 | 16 | if [ -z "$(ls -A $DUMPDIR/)" ]; then 17 | exit 0 18 | fi 19 | 20 | # Perform rotation 21 | 22 | ls -1td $DUMPDIR/* | tail -n +$(($SAI_MAX_FAILURE_DUMPS+1)) | xargs rm -rf 23 | -------------------------------------------------------------------------------- /syncd/scripts/syncd_start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Script to start syncd using supervisord 4 | # 5 | 6 | # Source the file that holds common code for systemd and supervisord 7 | . /usr/bin/syncd_init_common.sh 8 | 9 | config_syncd 10 | 11 | exec ${CMD} ${CMD_ARGS} 12 | 13 | -------------------------------------------------------------------------------- /syncd/syncd_request_shutdown.cpp: -------------------------------------------------------------------------------- 1 | #include "RequestShutdownCommandLineOptionsParser.h" 2 | #include "RequestShutdown.h" 3 | 4 | #include "swss/logger.h" 5 | 6 | using namespace syncd; 7 | 8 | int main(int argc, char **argv) 9 | { 10 | swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); 11 | 12 | SWSS_LOG_ENTER(); 13 | 14 | auto options = RequestShutdownCommandLineOptionsParser::parseCommandLine(argc, argv); 15 | 16 | RequestShutdown rs(options); 17 | 18 | rs.send(); 19 | 20 | return EXIT_SUCCESS; 21 | } 22 | -------------------------------------------------------------------------------- /syncd/testprofile.ini: -------------------------------------------------------------------------------- 1 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 2 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 3 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 4 | SAI_VS_INTERFACE_LANE_MAP_FILE=lanemap.ini 5 | -------------------------------------------------------------------------------- /syncd/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/syncd -I$(top_srcdir)/lib -I$(top_srcdir)/vslib 2 | 3 | LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main 4 | 5 | bin_PROGRAMS = tests 6 | 7 | tests_SOURCES = \ 8 | main.cpp TestSyncdBrcm.cpp TestSyncdMlnx.cpp TestSyncdNvdaBf.cpp TestSyncdLib.cpp 9 | tests_CXXFLAGS = \ 10 | $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) 11 | tests_LDADD = \ 12 | $(top_srcdir)/syncd/libSyncd.a $(top_srcdir)/lib/libSaiRedis.a $(top_srcdir)/syncd/libSyncdRequestShutdown.a \ 13 | -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -L$(top_srcdir)/vslib/.libs -lsaivs \ 14 | -lhiredis -lswsscommon -lpthread -lzmq $(LDADD_GTEST) $(CODE_COVERAGE_LIBS) $(VPP_LIBS) 15 | 16 | TESTS = tests 17 | -------------------------------------------------------------------------------- /syncd/tests/TestSyncdLib.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "RequestShutdown.h" 8 | 9 | #include "TestSyncdLib.h" 10 | 11 | void flushDb(std::string name) 12 | { 13 | SWSS_LOG_ENTER(); 14 | 15 | auto db = std::make_shared(name, 0, true); 16 | auto reply = std::make_shared(db.get(), "FLUSHALL", REDIS_REPLY_STATUS); 17 | 18 | reply->checkStatusOK(); 19 | 20 | SWSS_LOG_NOTICE("Flushed %s", name.c_str()); 21 | } 22 | 23 | void flushAsicDb() 24 | { 25 | SWSS_LOG_ENTER(); 26 | 27 | flushDb("ASIC_DB"); 28 | } 29 | 30 | void flushFlexCounterDb() 31 | { 32 | SWSS_LOG_ENTER(); 33 | 34 | flushDb("FLEX_COUNTER_DB"); 35 | } 36 | void sendSyncdShutdownNotification() 37 | { 38 | SWSS_LOG_ENTER(); 39 | 40 | auto opt = std::make_shared(); 41 | opt->setRestartType(syncd::SYNCD_RESTART_TYPE_COLD); 42 | 43 | auto req = std::make_shared(opt); 44 | req->send(); 45 | 46 | SWSS_LOG_NOTICE("Sent syncd shutdown request"); 47 | } 48 | -------------------------------------------------------------------------------- /syncd/tests/TestSyncdLib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void flushAsicDb(); 4 | void flushFlexCounterDb(); 5 | void sendSyncdShutdownNotification(); 6 | -------------------------------------------------------------------------------- /syncd/tests/TestSyncdNvdaBf.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "Sai.h" 17 | #include "Syncd.h" 18 | #include "MetadataLogger.h" 19 | 20 | #include "TestSyncdLib.h" 21 | 22 | class SyncdNvdaBfTest : public ::testing::Test 23 | { 24 | public: 25 | SyncdNvdaBfTest() = default; 26 | virtual ~SyncdNvdaBfTest() = default; 27 | 28 | public: 29 | virtual void SetUp() override; 30 | 31 | virtual void TearDown() override; 32 | 33 | sai_object_id_t CreateCounter(); 34 | void RemoveCounter(sai_object_id_t counter); 35 | 36 | sai_object_id_t CreateVnet(uint32_t vni); 37 | void RemoveVnet(sai_object_id_t vnet); 38 | 39 | sai_object_id_t CreateEni(sai_object_id_t vnet); 40 | void RemoveEni(sai_object_id_t eni); 41 | 42 | sai_object_id_t CreateOutboundRoutingGroup(bool disabled); 43 | void RemoveOutboundRoutingGroup(sai_object_id_t outbound_routing_group); 44 | 45 | protected: 46 | std::shared_ptr m_worker; 47 | std::shared_ptr m_sairedis; 48 | 49 | sai_object_id_t m_switchId = SAI_NULL_OBJECT_ID; 50 | }; 51 | -------------------------------------------------------------------------------- /syncd/tests/brcm/lanemap.ini: -------------------------------------------------------------------------------- 1 | ; comment 2 | # comment 3 | eth0:29,30,31,32 4 | eth1:25,26,27,28 5 | eth2:37,38,39,40 6 | eth3:33,34,35,36 7 | eth4:41,42,43,44 8 | eth5:45,46,47,48 9 | eth6:5,6,7,8 10 | eth7:1,2,3,4 11 | eth8:9,10,11,12 12 | eth9:13,14,15,16 13 | eth10:21,22,23,24 14 | eth11:17,18,19,20 15 | eth12:249,50,51,52 16 | eth13:353,54,55,56 17 | eth14:461,62,63,64 18 | eth15:557,58,59,60 19 | eth16:665,66,67,68 20 | eth17:769,70,71,72 21 | eth18:877,78,79,80 22 | eth19:973,74,75,76 23 | eth20:105,106,107,108 24 | eth21:109,110,111,112 25 | eth22:117,118,119,120 26 | eth23:113,114,115,116 27 | eth24:121,122,123,124 28 | eth25:125,126,127,128 29 | eth26:85,86,87,88 30 | eth27:81,82,83,84 31 | eth28:89,90,91,92 32 | eth29:93,94,95,96 33 | eth30:97,98,99,100 34 | eth31:101,102,103,104 35 | -------------------------------------------------------------------------------- /syncd/tests/brcm/testprofile.ini: -------------------------------------------------------------------------------- 1 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 2 | SAI_VS_HOSTIF_USE_TAP_DEVICE=false 3 | SAI_VS_INTERFACE_LANE_MAP_FILE=./brcm/lanemap.ini 4 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 5 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 6 | -------------------------------------------------------------------------------- /syncd/tests/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char* argv[]) 4 | { 5 | testing::InitGoogleTest(&argc, argv); 6 | 7 | const auto env = new ::testing::Environment(); 8 | 9 | testing::AddGlobalTestEnvironment(env); 10 | 11 | return RUN_ALL_TESTS(); 12 | } 13 | -------------------------------------------------------------------------------- /syncd/tests/mlnx/lanemap.ini: -------------------------------------------------------------------------------- 1 | eth1:0,1,2,3 2 | eth2:4,5,6,7 3 | eth3:8,9,10,11 4 | eth4:12,13,14,15 5 | eth5:16,17,18,19 6 | eth6:20,21,22,23 7 | eth7:24,25,26,27 8 | eth8:28,29,30,31 9 | eth9:32,33,34,35 10 | eth10:36,37,38,39 11 | eth11:40,41,42,43 12 | eth12:44,45,46,47 13 | eth13:48,49,50,51 14 | eth14:52,53,54,55 15 | eth15:56,57,58,59 16 | eth16:60,61,62,63 17 | eth17:64,65,66,67 18 | eth18:68,69,70,71 19 | eth19:72,73,74,75 20 | eth20:76,77,78,79 21 | eth21:80,81,82,83 22 | eth22:84,85,86,87 23 | eth23:88,89,90,91 24 | eth24:92,93,94,95 25 | eth25:96,97,98,99 26 | eth26:100,101,102,103 27 | eth27:104,105,106,107 28 | eth28:108,109,110,111 29 | eth29:112,113,114,115 30 | eth30:116,117,118,119 31 | eth31:120,121,122,123 32 | eth32:124,125,126,127 33 | -------------------------------------------------------------------------------- /syncd/tests/mlnx/sai.profile: -------------------------------------------------------------------------------- 1 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_MLNX2700 2 | SAI_VS_HOSTIF_USE_TAP_DEVICE=false 3 | SAI_VS_INTERFACE_LANE_MAP_FILE=./mlnx/lanemap.ini 4 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 5 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 6 | -------------------------------------------------------------------------------- /syncd/tests/nvda-bf/lanemap.ini: -------------------------------------------------------------------------------- 1 | eth1:0,1,2,3 2 | eth2:4,5,6,7 3 | -------------------------------------------------------------------------------- /syncd/tests/nvda-bf/sai.profile: -------------------------------------------------------------------------------- 1 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_NVDA_MBF2H536C 2 | SAI_VS_HOSTIF_USE_TAP_DEVICE=false 3 | SAI_VS_INTERFACE_LANE_MAP_FILE=./nvda-bf/lanemap.ini 4 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 5 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 6 | -------------------------------------------------------------------------------- /tests/BCM56850/bbm.ini: -------------------------------------------------------------------------------- 1 | SAI_OBJECT_TYPE_ACL_TABLE 2 | -------------------------------------------------------------------------------- /tests/BCM56850/client_switch.rec: -------------------------------------------------------------------------------- 1 | 2020-12-31.21:34:31.861834|a|INIT_VIEW 2 | 2020-12-31.21:34:31.862379|A|SAI_STATUS_SUCCESS 3 | 2020-12-31.21:34:31.864591|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2020-12-31.21:34:41.215885|a|APPLY_VIEW 5 | 2020-12-31.21:34:41.216326|A|SAI_STATUS_SUCCESS 6 | 2020-12-31.21:34:41.216326|#|give 5 seconds to client to connect to existing switch 7 | 2020-12-31.21:34:41.216326|@|5000 8 | -------------------------------------------------------------------------------- /tests/BCM56850/ctx_multi.json: -------------------------------------------------------------------------------- 1 | { 2 | "CONTEXTS": [ 3 | { 4 | "guid" : 0, 5 | "name" : "syncd", 6 | "dbAsic" : "ASIC_DB", 7 | "dbCounters" : "COUNTERS_DB", 8 | "dbFlex": "FLEX_COUNTER_DB", 9 | "dbState" : "STATE_DB", 10 | "zmq_enable": false, 11 | "zmq_endpoint": "tcp://127.0.0.1:5555", 12 | "zmq_ntf_endpoint": "tcp://127.0.0.1:5556", 13 | "switches": [ 14 | { 15 | "index" : 0, 16 | "hwinfo" : "" 17 | }, 18 | { 19 | "index" : 1, 20 | "hwinfo" : "1" 21 | } 22 | ] 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /tests/BCM56850/ctx_zmq.json: -------------------------------------------------------------------------------- 1 | { 2 | "CONTEXTS": [ 3 | { 4 | "guid" : 0, 5 | "name" : "syncd0", 6 | "dbAsic" : "ASIC_DB", 7 | "dbCounters" : "COUNTERS_DB", 8 | "dbFlex": "FLEX_COUNTER_DB", 9 | "dbState" : "STATE_DB", 10 | "zmq_enable": true, 11 | "zmq_endpoint": "tcp://127.0.0.1:5555", 12 | "zmq_ntf_endpoint": "tcp://127.0.0.1:5556", 13 | "switches": [ 14 | { 15 | "index" : 0, 16 | "hwinfo" : "" 17 | } 18 | ] 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tests/BCM56850/depreacated.rec: -------------------------------------------------------------------------------- 1 | 2020-12-14.18:07:17.827920|a|INIT_VIEW 2 | 2020-12-14.18:07:19.066651|A|SAI_STATUS_SUCCESS 3 | 2020-12-14.18:07:19.068136|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2020-12-14.18:07:26.140577|c|SAI_OBJECT_TYPE_NEXT_HOP_GROUP:oid:0x5000000000663|SAI_NEXT_HOP_GROUP_ATTR_TYPE=SAI_NEXT_HOP_GROUP_TYPE_ECMP 5 | 2020-12-14.18:07:20.116252|a|APPLY_VIEW 6 | 2020-12-14.18:07:20.118297|A|SAI_STATUS_SUCCESS 7 | -------------------------------------------------------------------------------- /tests/BCM56850/empty_sw.rec: -------------------------------------------------------------------------------- 1 | 2017-05-13.20:47:13.432144|#|recording to: sairedis.2017-05-13.20:47:13.431964.rec 2 | 2017-05-13.20:47:13.435733|a|INIT_VIEW 3 | 2017-05-13.20:47:13.439887|A|SAI_STATUS_SUCCESS 4 | 2017-05-13.20:47:13.443079|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 5 | 2017-06-14.01:55:46.558259|s|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_SRC_MAC_ADDRESS=00:11:11:11:11:11 6 | 2017-05-13.20:47:24.881973|a|APPLY_VIEW 7 | 2017-05-13.20:47:24.883499|A|SAI_STATUS_SUCCESS 8 | -------------------------------------------------------------------------------- /tests/BCM56850/full_nhg_bug.rec: -------------------------------------------------------------------------------- 1 | 2017-06-14.01:55:46.541806|#|recording on: ./sairedis.2017-06-14.01:55:46.541389.rec 2 | 2017-06-14.01:55:46.543987|a|INIT_VIEW 3 | 2017-06-14.01:55:46.551164|A|SAI_STATUS_SUCCESS 4 | 2017-06-14.01:55:46.555975|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY=0x417890|SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY=0x4179f0|SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY=0x417b50 5 | 2017-06-14.01:56:40.192374|c|SAI_OBJECT_TYPE_NEXT_HOP_GROUP:oid:0x5000000000628|SAI_NEXT_HOP_GROUP_ATTR_TYPE=SAI_NEXT_HOP_GROUP_TYPE_ECMP 6 | 2017-06-14.01:56:06.151337|a|APPLY_VIEW 7 | 2017-06-14.01:56:06.156740|A|SAI_STATUS_SUCCESS 8 | -------------------------------------------------------------------------------- /tests/BCM56850/full_nhg_bug_trap_group_create_fail.rec: -------------------------------------------------------------------------------- 1 | 2017-06-14.01:55:46.541806|#|recording on: ./sairedis.2017-06-14.01:55:46.541389.rec 2 | 2017-06-14.01:55:46.543987|a|INIT_VIEW 3 | 2017-06-14.01:55:46.551164|A|SAI_STATUS_SUCCESS 4 | 2017-06-14.01:55:46.555975|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY=0x417890|SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY=0x4179f0|SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY=0x417b50 5 | 2017-06-14.01:56:21.570181|c|SAI_OBJECT_TYPE_POLICER:oid:0x120000000005fb|SAI_POLICER_ATTR_CBS=600|SAI_POLICER_ATTR_CIR=600|SAI_POLICER_ATTR_METER_TYPE=SAI_METER_TYPE_PACKETS|SAI_POLICER_ATTR_MODE=SAI_POLICER_MODE_SR_TCM|SAI_POLICER_ATTR_RED_PACKET_ACTION=SAI_PACKET_ACTION_DROP 6 | 2017-06-14.01:56:21.567734|c|SAI_OBJECT_TYPE_HOSTIF_TRAP_GROUP:oid:0x110000000005fa|SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE=4|SAI_HOSTIF_TRAP_GROUP_ATTR_POLICER=oid:0x120000000005fb 7 | 2017-06-14.01:56:06.151337|a|APPLY_VIEW 8 | 2017-06-14.01:56:06.156740|A|SAI_STATUS_SUCCESS 9 | -------------------------------------------------------------------------------- /tests/BCM56850/ignore_attributes.rec: -------------------------------------------------------------------------------- 1 | 2017-06-14.01:55:46.543987|a|INIT_VIEW 2 | 2017-06-14.01:55:46.551164|A|SAI_STATUS_SUCCESS 3 | 2017-06-14.01:55:46.555975|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2017-06-14.01:56:05.520538|g|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_PORT_NUMBER=0 5 | 2017-06-14.01:56:05.525938|G|SAI_STATUS_SUCCESS|SAI_SWITCH_ATTR_PORT_NUMBER=32 6 | 2017-06-14.01:56:06.151337|a|APPLY_VIEW 7 | 2017-06-14.01:56:06.156740|A|SAI_STATUS_SUCCESS 8 | -------------------------------------------------------------------------------- /tests/BCM56850/lag_label_A.rec: -------------------------------------------------------------------------------- 1 | 2020-12-31.21:34:31.861834|a|INIT_VIEW 2 | 2020-12-31.21:34:31.862379|A|SAI_STATUS_SUCCESS 3 | 2020-12-31.21:34:31.864591|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000761|SAI_LAG_ATTR_LABEL=foo|SAI_LAG_ATTR_PORT_VLAN_ID=2|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=5 5 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000762|SAI_LAG_ATTR_LABEL=car|SAI_LAG_ATTR_PORT_VLAN_ID=2|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=5 6 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000763|SAI_LAG_ATTR_LABEL=bar|SAI_LAG_ATTR_PORT_VLAN_ID=3|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=7 7 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000764|SAI_LAG_ATTR_LABEL=baz|SAI_LAG_ATTR_PORT_VLAN_ID=3|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=7 8 | 2020-12-31.21:34:41.215885|a|APPLY_VIEW 9 | 2020-12-31.21:34:41.216326|A|SAI_STATUS_SUCCESS 10 | -------------------------------------------------------------------------------- /tests/BCM56850/lag_label_B.rec: -------------------------------------------------------------------------------- 1 | 2020-12-31.21:34:31.861834|a|INIT_VIEW 2 | 2020-12-31.21:34:31.862379|A|SAI_STATUS_SUCCESS 3 | 2020-12-31.21:34:31.864591|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000765|SAI_LAG_ATTR_LABEL=bar|SAI_LAG_ATTR_PORT_VLAN_ID=2|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=5 5 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000766|SAI_LAG_ATTR_LABEL=baz|SAI_LAG_ATTR_PORT_VLAN_ID=2|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=5 6 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000767|SAI_LAG_ATTR_LABEL=foo|SAI_LAG_ATTR_PORT_VLAN_ID=3|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=7 7 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000768|SAI_LAG_ATTR_LABEL=car|SAI_LAG_ATTR_PORT_VLAN_ID=3|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=7 8 | 2020-12-31.21:34:41.215885|a|APPLY_VIEW 9 | 2020-12-31.21:34:41.216326|A|SAI_STATUS_SUCCESS 10 | -------------------------------------------------------------------------------- /tests/BCM56850/lanemap.ini: -------------------------------------------------------------------------------- 1 | ; comment 2 | # comment 3 | eth0:29,30,31,32 4 | eth1:25,26,27,28 5 | eth2:37,38,39,40 6 | eth3:33,34,35,36 7 | eth4:41,42,43,44 8 | eth5:45,46,47,48 9 | eth6:5,6,7,8 10 | eth7:1,2,3,4 11 | eth8:9,10,11,12 12 | eth9:13,14,15,16 13 | eth10:21,22,23,24 14 | eth11:17,18,19,20 15 | eth12:249,50,51,52 16 | eth13:353,54,55,56 17 | eth14:461,62,63,64 18 | eth15:557,58,59,60 19 | eth16:665,66,67,68 20 | eth17:769,70,71,72 21 | eth18:877,78,79,80 22 | eth19:973,74,75,76 23 | eth20:105,106,107,108 24 | eth21:109,110,111,112 25 | eth22:117,118,119,120 26 | eth23:113,114,115,116 27 | eth24:121,122,123,124 28 | eth25:125,126,127,128 29 | eth26:85,86,87,88 30 | eth27:81,82,83,84 31 | eth28:89,90,91,92 32 | eth29:93,94,95,96 33 | eth30:97,98,99,100 34 | eth31:101,102,103,104 35 | -------------------------------------------------------------------------------- /tests/BCM56850/limits.ini: -------------------------------------------------------------------------------- 1 | SAI_OBJECT_TYPE_ACL_TABLE=3 2 | -------------------------------------------------------------------------------- /tests/BCM56850/multi_switch_key.rec: -------------------------------------------------------------------------------- 1 | 2020-06-08.18:03:22.457728|a|INIT_VIEW 2 | 2020-06-08.18:03:22.459307|A|SAI_STATUS_SUCCESS 3 | 2020-06-08.18:03:22.481256|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2020-06-08.18:03:22.485235|g|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID=oid:0x0 5 | 2020-06-08.18:03:24.753799|G|SAI_STATUS_SUCCESS|SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID=oid:0x3000000000022 6 | 2020-06-08.18:03:33.803112|c|SAI_OBJECT_TYPE_SWITCH:oid:0x121000000000001|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO=1:49 7 | 2020-06-08.18:03:33.803112|c|SAI_OBJECT_TYPE_VLAN:oid:0x260000000005d2|SAI_VLAN_ATTR_VLAN_ID=2 8 | 2020-06-08.18:03:33.803112|c|SAI_OBJECT_TYPE_VLAN:oid:0x1260000000005d2|SAI_VLAN_ATTR_VLAN_ID=2 9 | 2020-06-08.18:03:22.461844|a|APPLY_VIEW 10 | 2020-06-08.18:03:22.463034|A|SAI_STATUS_SUCCESS 11 | -------------------------------------------------------------------------------- /tests/BCM56850/no_lag_label_A.rec: -------------------------------------------------------------------------------- 1 | 2020-12-31.21:34:31.861834|a|INIT_VIEW 2 | 2020-12-31.21:34:31.862379|A|SAI_STATUS_SUCCESS 3 | 2020-12-31.21:34:31.864591|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000763|SAI_LAG_ATTR_PORT_VLAN_ID=2|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=5 5 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000764|SAI_LAG_ATTR_PORT_VLAN_ID=3|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=7 6 | 2020-12-31.21:34:41.215885|a|APPLY_VIEW 7 | 2020-12-31.21:34:41.216326|A|SAI_STATUS_SUCCESS 8 | -------------------------------------------------------------------------------- /tests/BCM56850/no_lag_label_B.rec: -------------------------------------------------------------------------------- 1 | 2020-12-31.21:34:31.861834|a|INIT_VIEW 2 | 2020-12-31.21:34:31.862379|A|SAI_STATUS_SUCCESS 3 | 2020-12-31.21:34:31.864591|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000763|SAI_LAG_ATTR_LABEL=bar|SAI_LAG_ATTR_PORT_VLAN_ID=2|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=5 5 | 2020-05-27.17:28:54.352190|c|SAI_OBJECT_TYPE_LAG:oid:0x2000000000764|SAI_LAG_ATTR_LABEL=baz|SAI_LAG_ATTR_PORT_VLAN_ID=3|SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY=7 6 | 2020-12-31.21:34:41.215885|a|APPLY_VIEW 7 | 2020-12-31.21:34:41.216326|A|SAI_STATUS_SUCCESS 8 | -------------------------------------------------------------------------------- /tests/BCM56850/non_depreacated.rec: -------------------------------------------------------------------------------- 1 | 2020-12-14.18:10:34.795241|a|INIT_VIEW 2 | 2020-12-14.18:10:40.621645|A|SAI_STATUS_SUCCESS 3 | 2020-12-14.18:10:40.624021|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2020-12-14.18:10:43.015167|c|SAI_OBJECT_TYPE_NEXT_HOP_GROUP:oid:0x50000000006f2|SAI_NEXT_HOP_GROUP_ATTR_TYPE=SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP 5 | 2020-12-14.18:10:46.959121|a|APPLY_VIEW 6 | 2020-12-14.18:10:52.541432|A|SAI_STATUS_SUCCESS 7 | -------------------------------------------------------------------------------- /tests/BCM56850/ntf1.rec: -------------------------------------------------------------------------------- 1 | 2019-02-14.20:16:47.696163|a|INIT_VIEW 2 | 2019-02-14.20:17:09.080480|A|SAI_STATUS_SUCCESS 3 | 2019-02-14.20:17:09.083395|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY=0x42c410|SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY=0x42c420|SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY=0x42c430|SAI_SWITCH_ATTR_SRC_MAC_ADDRESS=00:1C:73:F1:55:AE 4 | 2019-02-14.20:17:14.021109|a|APPLY_VIEW 5 | 2019-02-14.20:17:09.080480|A|SAI_STATUS_SUCCESS 6 | -------------------------------------------------------------------------------- /tests/BCM56850/ntf2.rec: -------------------------------------------------------------------------------- 1 | 2019-02-14.20:16:47.696163|a|INIT_VIEW 2 | 2019-02-14.20:17:09.080480|A|SAI_STATUS_SUCCESS 3 | 2019-02-14.20:17:09.083395|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY=0x52c410|SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY=0x52c420|SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY=0x0|SAI_SWITCH_ATTR_SRC_MAC_ADDRESS=00:1C:73:F1:55:AE 4 | 2019-02-14.20:17:14.021109|a|APPLY_VIEW 5 | 2019-02-14.20:17:09.080480|A|SAI_STATUS_SUCCESS 6 | -------------------------------------------------------------------------------- /tests/BCM56850/query_attr_enum_values_capability.rec: -------------------------------------------------------------------------------- 1 | 2019-10-25.04:21:31.884173|a|INIT_VIEW 2 | 2019-10-25.04:21:31.884636|A|SAI_STATUS_SUCCESS 3 | 2019-10-25.04:21:31.884882|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_SRC_MAC_ADDRESS=02:42:AC:11:00:02 4 | 2019-10-25.04:21:32.853334|q|attribute_enum_values_capability|oid:0x21000000000000|OBJECT_TYPE=SAI_OBJECT_TYPE_DEBUG_COUNTER|ATTR_ID=SAI_DEBUG_COUNTER_ATTR_IN_DROP_REASON_LIST|LIST_SIZE=100 5 | 2019-10-25.04:21:32.854651|Q|attribute_enum_values_capability|SAI_STATUS_SUCCESS|ENUM_CAPABILITIES=0,11,41|ENUM_COUNT=3 6 | 2019-10-25.04:21:32.854730|q|attribute_enum_values_capability|oid:0x21000000000000|OBJECT_TYPE=SAI_OBJECT_TYPE_DEBUG_COUNTER|ATTR_ID=SAI_DEBUG_COUNTER_ATTR_OUT_DROP_REASON_LIST|LIST_SIZE=100 7 | 2019-10-25.04:21:32.855398|Q|attribute_enum_values_capability|SAI_STATUS_SUCCESS|ENUM_CAPABILITIES=0,2|ENUM_COUNT=2 8 | 2019-10-25.04:21:32.862373|a|APPLY_VIEW 9 | 2019-10-25.04:21:32.863487|A|SAI_STATUS_SUCCESS 10 | -------------------------------------------------------------------------------- /tests/BCM56850/vsprofile.ini: -------------------------------------------------------------------------------- 1 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 2 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 3 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 4 | SAI_VS_INTERFACE_LANE_MAP_FILE=BCM56850/lanemap.ini 5 | #SAI_VS_INTERFACE_LANE_MAP_FILE=BCM56850/lane66.ini 6 | #SAI_VS_HOSTIF_USE_TAP_DEVICE=true 7 | #SAI_VS_RESOURCE_LIMITER_FILE=BCM56850/limits.ini 8 | -------------------------------------------------------------------------------- /tests/BCM56850/vsprofile_acl_limit.ini: -------------------------------------------------------------------------------- 1 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 2 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 3 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 4 | SAI_VS_INTERFACE_LANE_MAP_FILE=BCM56850/lanemap.ini 5 | #SAI_VS_INTERFACE_LANE_MAP_FILE=brcm/lane66.ini 6 | #SAI_VS_HOSTIF_USE_TAP_DEVICE=true 7 | SAI_VS_RESOURCE_LIMITER_FILE=BCM56850/limits.ini 8 | -------------------------------------------------------------------------------- /tests/BCM56850/vsprofile_ctx_multi.ini: -------------------------------------------------------------------------------- 1 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 2 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 3 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 4 | SAI_VS_INTERFACE_LANE_MAP_FILE=BCM56850/lanemap_multi.ini 5 | SAI_REDIS_CONTEXT_CONFIG=BCM56850/ctx_multi.json 6 | -------------------------------------------------------------------------------- /tests/BCM56850/vsprofile_ctx_zmq.ini: -------------------------------------------------------------------------------- 1 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 2 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 3 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 4 | SAI_VS_INTERFACE_LANE_MAP_FILE=BCM56850/lanemap.ini 5 | #SAI_VS_INTERFACE_LANE_MAP_FILE=BCM56850/lane66.ini 6 | #SAI_VS_HOSTIF_USE_TAP_DEVICE=true 7 | #SAI_VS_RESOURCE_LIMITER_FILE=BCM56850/limits.ini 8 | SAI_REDIS_CONTEXT_CONFIG=BCM56850/ctx_zmq.json 9 | -------------------------------------------------------------------------------- /tests/BCM56850/vxlan_default_router_mac.rec: -------------------------------------------------------------------------------- 1 | 2017-06-14.01:55:46.543987|a|INIT_VIEW 2 | 2017-06-14.01:55:46.551164|A|SAI_STATUS_SUCCESS 3 | 2017-06-14.01:55:46.555975|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2017-06-14.01:55:46.558259|s|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC=00:22:22:22:22:22 5 | 2017-06-14.01:56:06.151337|a|APPLY_VIEW 6 | 2017-06-14.01:56:06.156740|A|SAI_STATUS_SUCCESS 7 | 2017-06-14.01:55:46.543987|a|INIT_VIEW 8 | 2017-06-14.01:55:46.551164|A|SAI_STATUS_SUCCESS 9 | 2017-06-14.01:55:46.555975|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 10 | 2017-06-14.01:56:06.151337|a|APPLY_VIEW 11 | 2017-06-14.01:56:06.156740|A|SAI_STATUS_SUCCESS 12 | -------------------------------------------------------------------------------- /tests/BCM56971B0.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | BEGIN { push @INC,'.'; } 4 | 5 | use strict; 6 | use warnings; 7 | use diagnostics; 8 | 9 | use utils; 10 | 11 | sub test_brcm_acl_limit 12 | { 13 | fresh_start("-b", "$utils::DIR/break.ini", "-p", "$utils::DIR/vsprofile.ini"); 14 | 15 | play "acl_limit.rec"; 16 | } 17 | 18 | sub test_brcm_acl_prio 19 | { 20 | fresh_start("-b", "$utils::DIR/break.ini", "-p", "$utils::DIR/vsprofile.ini"); 21 | 22 | play "acl_prio.rec"; 23 | play "acl_prio.rec", 0; 24 | play "acl_prio.rec", 0; 25 | play "acl_prio.rec", 0; 26 | play "acl_prio.rec", 0; 27 | play "acl_prio.rec", 0; 28 | } 29 | 30 | test_brcm_acl_prio; 31 | test_brcm_acl_limit; 32 | 33 | kill_syncd; 34 | -------------------------------------------------------------------------------- /tests/BCM56971B0/break.ini: -------------------------------------------------------------------------------- 1 | SAI_OBJECT_TYPE_ACL_TABLE 2 | -------------------------------------------------------------------------------- /tests/BCM56971B0/limits.ini: -------------------------------------------------------------------------------- 1 | SAI_OBJECT_TYPE_ACL_TABLE=3 2 | -------------------------------------------------------------------------------- /tests/BCM56971B0/vsprofile.ini: -------------------------------------------------------------------------------- 1 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 2 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 3 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56971B0 4 | SAI_VS_INTERFACE_LANE_MAP_FILE=BCM56971B0/lanemap.ini 5 | SAI_VS_RESOURCE_LIMITER_FILE=BCM56971B0/limits.ini 6 | -------------------------------------------------------------------------------- /tests/MLNX2700/empty.rec: -------------------------------------------------------------------------------- 1 | 2017-05-13.20:47:13.432144|#|recording to: sairedis.2017-05-13.20:47:13.431964.rec 2 | 2017-05-13.20:47:13.435733|a|INIT_VIEW 3 | 2017-05-13.20:47:13.439887|A|SAI_STATUS_SUCCESS 4 | 2017-05-13.20:47:24.881973|a|APPLY_VIEW 5 | 2017-05-13.20:47:24.883499|A|SAI_STATUS_SUCCESS 6 | -------------------------------------------------------------------------------- /tests/MLNX2700/empty_sw.rec: -------------------------------------------------------------------------------- 1 | 2017-05-13.20:47:13.432144|#|recording to: sairedis.2017-05-13.20:47:13.431964.rec 2 | 2017-05-13.20:47:13.435733|a|INIT_VIEW 3 | 2017-05-13.20:47:13.439887|A|SAI_STATUS_SUCCESS 4 | 2017-05-13.20:47:13.443079|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY=0x1 5 | 2017-05-13.20:47:24.881973|a|APPLY_VIEW 6 | 2017-05-13.20:47:24.883499|A|SAI_STATUS_SUCCESS 7 | -------------------------------------------------------------------------------- /tests/MLNX2700/vsprofile.ini: -------------------------------------------------------------------------------- 1 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 2 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 3 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_MLNX2700 4 | -------------------------------------------------------------------------------- /tests/NVDAMBF2H536C.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | BEGIN { push @INC,'.'; } 4 | 5 | use strict; 6 | use warnings; 7 | use diagnostics; 8 | 9 | use utils; 10 | 11 | sub test_dashapi_replay 12 | { 13 | fresh_start; 14 | 15 | play "dashapis.rec"; 16 | 17 | # Normally exit for collecting gcov data 18 | request_cold_shutdown; 19 | } 20 | 21 | sub test_dashapi_replay_bulk 22 | { 23 | fresh_start_bulk; 24 | 25 | play "dashapis.rec"; 26 | 27 | # Normally exit for collecting gcov data 28 | request_cold_shutdown; 29 | } 30 | 31 | # RUN 32 | 33 | test_dashapi_replay; 34 | test_dashapi_replay_bulk; 35 | -------------------------------------------------------------------------------- /tests/NVDAMBF2H536C/client_switch.rec: -------------------------------------------------------------------------------- 1 | 2020-12-31.21:34:31.861834|a|INIT_VIEW 2 | 2020-12-31.21:34:31.862379|A|SAI_STATUS_SUCCESS 3 | 2020-12-31.21:34:31.864591|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true 4 | 2020-12-31.21:34:41.215885|a|APPLY_VIEW 5 | 2020-12-31.21:34:41.216326|A|SAI_STATUS_SUCCESS 6 | 2020-12-31.21:34:41.216326|#|give 5 seconds to client to connect to existing switch 7 | 2020-12-31.21:34:41.216326|@|5000 8 | -------------------------------------------------------------------------------- /tests/NVDAMBF2H536C/vsprofile.ini: -------------------------------------------------------------------------------- 1 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 2 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 3 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_NVDA_MBF2H536C 4 | -------------------------------------------------------------------------------- /tests/TestDashEnv.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include 5 | #include 6 | } 7 | 8 | #include "gtest/gtest.h" 9 | 10 | #define ENV_CLIENT_MODE_OPT "TESTDASH_CLIENT_MODE" 11 | 12 | class TestDashEnv : public ::testing::Environment 13 | { 14 | public: 15 | static TestDashEnv* instance(); 16 | 17 | virtual void SetUp() override; 18 | 19 | virtual void TearDown() override; 20 | 21 | sai_object_id_t getSwitchOid() const { return m_switch_id; } 22 | 23 | private: 24 | void StopSyncd(); 25 | void StartSyncd(); 26 | void FlushRedis(); 27 | void CreateSwitch(); 28 | TestDashEnv(); 29 | 30 | sai_object_id_t m_switch_id = SAI_NULL_OBJECT_ID; 31 | bool m_manage_syncd = true; 32 | }; 33 | -------------------------------------------------------------------------------- /tests/TestDashMain.cpp: -------------------------------------------------------------------------------- 1 | #include "TestDashEnv.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | SWSS_LOG_ENTER(); 8 | 9 | swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); 10 | 11 | testing::InitGoogleTest(&argc, argv); 12 | 13 | testing::AddGlobalTestEnvironment(TestDashEnv::instance()); 14 | 15 | return RUN_ALL_TESTS(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/checkwhitespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo Checkig for white spaces ... 4 | 5 | find .. -type f | 6 | grep -v SAI/ | 7 | grep -v debian/ | 8 | grep -v _wrap.cpp | 9 | perl -ne 'print if /\.(c|cpp|h|hpp|am|sh|pl|pm|install|dirs|links|json|ini|yml|pws|md|py|cfg|conf|i|ac)$/' | 10 | xargs grep -nP "\\s\$" 11 | 12 | if [ $? -eq 0 ]; then 13 | echo ERROR: some files contain white spaces at the end of line, please fix 14 | exit 1 15 | fi 16 | -------------------------------------------------------------------------------- /tests/conflictnames.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | use diagnostics; 6 | 7 | my @files = `find ../ -type f -name "sai*.h"`; 8 | 9 | my %H = (); 10 | 11 | my $exit = 0; 12 | 13 | for my $file (@files) 14 | { 15 | chomp $file; 16 | next if $file =~ m!SAI/flex!; 17 | next if $file =~ m!/debian/!; 18 | next if not $file =~ m!/(sai[^/]*.h)$!; 19 | 20 | if (defined $H{$1}) 21 | { 22 | printf "SAME file name CONFLICT: $H{$1} and $file\n"; 23 | printf "files will be copied to /usr/include/sai/ during package install and will override, change name of $1\n"; 24 | $exit = 1; 25 | next; 26 | } 27 | 28 | $H{$1} = $file; 29 | } 30 | 31 | exit $exit; 32 | -------------------------------------------------------------------------------- /tests/main.cpp: -------------------------------------------------------------------------------- 1 | #include "swss/logger.h" 2 | 3 | int syncd_main(int argc, char **argv); 4 | 5 | int main(int argc, char **argv) 6 | { 7 | SWSS_LOG_ENTER(); 8 | 9 | return syncd_main(argc, argv); 10 | } 11 | -------------------------------------------------------------------------------- /tests/swsslogentercheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # find all source files that can use SWSS_LOG_ENTER macro 4 | # and check if macro is in expected place 5 | 6 | set -e 7 | 8 | DIR=$(dirname "${BASH_SOURCE[0]}") 9 | 10 | find "$DIR/../" -name "*.cpp" -o -name "*.h" | xargs ./swsslogentercheck.pl 11 | -------------------------------------------------------------------------------- /tests/testclient_main.cpp: -------------------------------------------------------------------------------- 1 | #include "TestClient.h" 2 | 3 | int main() 4 | { 5 | swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); 6 | 7 | SWSS_LOG_ENTER(); 8 | 9 | swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); 10 | 11 | TestClient tc; 12 | 13 | tc.test_create_switch(); 14 | 15 | tc.test_create_vlan(); 16 | 17 | tc.test_bulk_create_vlan(); 18 | 19 | tc.test_query_api(); 20 | 21 | tc.test_fdb_flush(); 22 | 23 | tc.test_stats(); 24 | 25 | return EXIT_SUCCESS; 26 | } 27 | -------------------------------------------------------------------------------- /unittest/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = meta lib vslib syncd proxylib saidump 2 | -------------------------------------------------------------------------------- /unittest/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/meta -I$(top_srcdir)/lib 2 | 3 | bin_PROGRAMS = tests 4 | 5 | LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main -lgmock 6 | 7 | tests_SOURCES = \ 8 | main.cpp \ 9 | ../../meta/NumberOidIndexGenerator.cpp \ 10 | TestSwitch.cpp \ 11 | TestClientConfig.cpp \ 12 | TestClientServerSai.cpp \ 13 | TestContext.cpp \ 14 | TestContextConfig.cpp \ 15 | TestContextConfigContainer.cpp \ 16 | TestUtils.cpp \ 17 | TestVirtualObjectIdManager.cpp \ 18 | TestZeroMQChannel.cpp \ 19 | TestSwitchContainer.cpp \ 20 | TestSwitchConfigContainer.cpp \ 21 | TestSkipRecordAttrContainer.cpp \ 22 | TestServerConfig.cpp \ 23 | TestRedisVidIndexGenerator.cpp \ 24 | TestRecorder.cpp \ 25 | TestRedisChannel.cpp \ 26 | TestClientSai.cpp \ 27 | TestRedisRemoteSaiInterface.cpp \ 28 | TestServerSai.cpp \ 29 | TestSai.cpp \ 30 | MockSaiInterface.cpp 31 | 32 | tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) -fno-access-control 33 | tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/lib/libSaiRedis.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) 34 | 35 | TESTS = tests 36 | -------------------------------------------------------------------------------- /unittest/lib/MockSaiInterface.cpp: -------------------------------------------------------------------------------- 1 | #include "MockSaiInterface.h" 2 | #include "swss/logger.h" 3 | 4 | MockSaiInterface::MockSaiInterface() 5 | { 6 | SWSS_LOG_ENTER(); 7 | } 8 | 9 | MockSaiInterface::~MockSaiInterface() 10 | { 11 | SWSS_LOG_ENTER(); 12 | } 13 | 14 | sai_status_t MockSaiInterface::apiInitialize( 15 | _In_ uint64_t flags, 16 | _In_ const sai_service_method_table_t *service_method_table) 17 | { 18 | SWSS_LOG_ENTER(); 19 | return SAI_STATUS_SUCCESS; 20 | } 21 | 22 | sai_status_t MockSaiInterface::apiUninitialize() 23 | { 24 | SWSS_LOG_ENTER(); 25 | return SAI_STATUS_SUCCESS; 26 | } 27 | -------------------------------------------------------------------------------- /unittest/lib/MockSaiInterface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "DummySaiInterface.h" 5 | #include 6 | 7 | class MockSaiInterface: public saimeta::DummySaiInterface 8 | { 9 | public: 10 | 11 | MockSaiInterface(); 12 | 13 | virtual ~MockSaiInterface(); 14 | 15 | public: 16 | 17 | virtual sai_status_t apiInitialize( 18 | _In_ uint64_t flags, 19 | _In_ const sai_service_method_table_t *service_method_table) override; 20 | virtual sai_status_t apiUninitialize(void) override; 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /unittest/lib/TestClientConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "ClientConfig.h" 2 | 3 | #include 4 | 5 | using namespace sairedis; 6 | 7 | TEST(ClientConfig, loadFromFile) 8 | { 9 | EXPECT_NE(ClientConfig::loadFromFile("non_existing"), nullptr); 10 | 11 | EXPECT_NE(ClientConfig::loadFromFile("files/client_config_bad.txt"), nullptr); 12 | 13 | EXPECT_NE(ClientConfig::loadFromFile("files/client_config_ok.txt"), nullptr); 14 | } 15 | -------------------------------------------------------------------------------- /unittest/lib/TestClientSai.cpp: -------------------------------------------------------------------------------- 1 | #include "ClientSai.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace sairedis; 8 | 9 | static const char* profile_get_value( 10 | _In_ sai_switch_profile_id_t profile_id, 11 | _In_ const char* variable) 12 | { 13 | SWSS_LOG_ENTER(); 14 | return NULL; 15 | } 16 | 17 | static int profile_get_next_value( 18 | _In_ sai_switch_profile_id_t profile_id, 19 | _Out_ const char** variable, 20 | _Out_ const char** value) 21 | { 22 | SWSS_LOG_ENTER(); 23 | return -1; 24 | } 25 | 26 | static sai_service_method_table_t test_services = { 27 | profile_get_value, 28 | profile_get_next_value 29 | }; 30 | 31 | TEST(ClientSai, bulkGet) 32 | { 33 | ClientSai sai; 34 | 35 | sai.apiInitialize(0,&test_services); 36 | 37 | sai_object_id_t oids[1] = {0}; 38 | uint32_t attrcount[1] = {0}; 39 | sai_attribute_t* attrs[1] = {0}; 40 | sai_status_t statuses[1] = {0}; 41 | 42 | EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, 43 | sai.bulkGet( 44 | SAI_OBJECT_TYPE_PORT, 45 | 1, 46 | oids, 47 | attrcount, 48 | attrs, 49 | SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, 50 | statuses)); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /unittest/lib/TestContextConfigContainer.cpp: -------------------------------------------------------------------------------- 1 | #include "ContextConfigContainer.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | #include 6 | 7 | using namespace sairedis; 8 | 9 | TEST(ContextConfigContainer, get) 10 | { 11 | ContextConfigContainer ccc; 12 | 13 | EXPECT_EQ(ccc.get(0), nullptr); 14 | } 15 | 16 | TEST(ContextConfigContainer, loadFromFile) 17 | { 18 | ContextConfigContainer ccc; 19 | 20 | EXPECT_NE(ccc.loadFromFile("files/ccc_bad.txt"), nullptr); 21 | } 22 | 23 | TEST(ContextConfigContainer, insert) 24 | { 25 | ContextConfigContainer ccc; 26 | 27 | auto cc = std::make_shared(0, "syncd", "ASIC_DB", "COUNTERS_DB","FLEX_DB", "STATE_DB"); 28 | 29 | ccc.insert(cc); 30 | 31 | EXPECT_THROW(ccc.insert(cc), std::runtime_error); 32 | } 33 | -------------------------------------------------------------------------------- /unittest/lib/TestRecorder.cpp: -------------------------------------------------------------------------------- 1 | #include "Recorder.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace sairedis; 8 | 9 | TEST(Recorder, requestLogRotate) 10 | { 11 | Recorder rec; 12 | 13 | rec.enableRecording(true); 14 | 15 | rec.recordComment("foo"); 16 | 17 | int code = rename("sairedis.rec", "sairedis.rec.1"); 18 | 19 | EXPECT_EQ(code, 0); 20 | 21 | EXPECT_NE(access("sairedis.rec", F_OK),0); 22 | 23 | rec.requestLogRotate(); 24 | 25 | EXPECT_EQ(access("sairedis.rec", F_OK),0); 26 | 27 | rec.recordComment("bar"); 28 | } 29 | -------------------------------------------------------------------------------- /unittest/lib/TestRedisChannel.cpp: -------------------------------------------------------------------------------- 1 | #include "RedisChannel.h" 2 | #include "sairediscommon.h" 3 | 4 | #include "swss/notificationproducer.h" 5 | 6 | #include 7 | 8 | #include 9 | 10 | using namespace sairedis; 11 | 12 | static std::string g_op; 13 | static std::string g_data; 14 | 15 | static void callback( 16 | _In_ const std::string& op, 17 | _In_ const std::string& data, 18 | _In_ const std::vector& values) 19 | { 20 | SWSS_LOG_ENTER(); 21 | 22 | g_op = op; 23 | g_data = data; 24 | } 25 | 26 | TEST(RedisChannel, reset) 27 | { 28 | RedisChannel rc("ASIC_DB", callback); 29 | 30 | EXPECT_NE(nullptr, rc.getDbConnector()); 31 | } 32 | 33 | TEST(RedisChannel, notificationThreadFunction) 34 | { 35 | RedisChannel rc("ASIC_DB", callback); 36 | 37 | rc.setResponseTimeout(10); 38 | 39 | auto db = std::make_shared("ASIC_DB", 0); 40 | 41 | swss::NotificationProducer p(db.get(), REDIS_TABLE_NOTIFICATIONS); 42 | 43 | std::vector vals; 44 | p.send("foo", "bar", vals); 45 | 46 | usleep(200*1000); 47 | 48 | EXPECT_EQ(g_op, "foo"); 49 | } 50 | 51 | TEST(RedisChannel, flush) 52 | { 53 | RedisChannel rc("ASIC_DB", callback); 54 | 55 | rc.flush(); 56 | } 57 | -------------------------------------------------------------------------------- /unittest/lib/TestRedisVidIndexGenerator.cpp: -------------------------------------------------------------------------------- 1 | #include "RedisVidIndexGenerator.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace sairedis; 8 | 9 | TEST(RedisVidIndexGenerator, reset) 10 | { 11 | auto db = std::make_shared("ASIC_DB", 0); 12 | 13 | RedisVidIndexGenerator g(db, "FOO"); 14 | 15 | g.reset(); 16 | } 17 | -------------------------------------------------------------------------------- /unittest/lib/TestServerConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "ServerConfig.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace sairedis; 8 | 9 | TEST(ServerConfig, loadFromFile) 10 | { 11 | EXPECT_NE(ServerConfig::loadFromFile("/not_existing"), nullptr); 12 | 13 | EXPECT_NE(ServerConfig::loadFromFile("files/server_config_ok.json"), nullptr); 14 | EXPECT_NE(ServerConfig::loadFromFile("files/server_config_bad.json"), nullptr); 15 | } 16 | -------------------------------------------------------------------------------- /unittest/lib/TestSwitchConfigContainer.cpp: -------------------------------------------------------------------------------- 1 | #include "SwitchConfigContainer.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace sairedis; 8 | 9 | TEST(SwitchConfigContainer, insert) 10 | { 11 | auto sc = std::make_shared(0, ""); 12 | auto sc1 = std::make_shared(1, ""); 13 | 14 | auto scc = std::make_shared(); 15 | 16 | scc->insert(sc); 17 | 18 | EXPECT_THROW(scc->insert(sc), std::runtime_error); 19 | EXPECT_THROW(scc->insert(sc1), std::runtime_error); 20 | } 21 | 22 | TEST(SwitchConfigContainer, getConfig) 23 | { 24 | auto sc0 = std::make_shared(0, "0"); 25 | auto sc1 = std::make_shared(1, "1"); 26 | 27 | auto scc = std::make_shared(); 28 | 29 | scc->insert(sc0); 30 | scc->insert(sc1); 31 | 32 | EXPECT_EQ(scc->getConfig(7), nullptr); 33 | 34 | EXPECT_NE(scc->getConfig(1), nullptr); 35 | EXPECT_NE(scc->getConfig(0), nullptr); 36 | } 37 | -------------------------------------------------------------------------------- /unittest/lib/TestZeroMQChannel.cpp: -------------------------------------------------------------------------------- 1 | #include "ZeroMQChannel.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | using namespace sairedis; 10 | 11 | TEST(ZeroMQChannel, ctr) 12 | { 13 | EXPECT_THROW(std::make_shared("/invalid_ep", "/invalid_ntf_ep", nullptr), std::runtime_error); 14 | 15 | EXPECT_THROW(std::make_shared("ipc:///tmp/valid", "/invalid_ntf_ep", nullptr), std::runtime_error); 16 | } 17 | 18 | TEST(ZeroMQChannel, flush) 19 | { 20 | auto c = std::make_shared("ipc:///tmp/valid_ep", "ipc:///tmp/valid_ntf_ep", nullptr); 21 | 22 | c->flush(); 23 | } 24 | 25 | TEST(ZeroMQChannel, wait) 26 | { 27 | auto c = std::make_shared("ipc:///tmp/valid_ep", "ipc:///tmp/valid_ntf_ep", nullptr); 28 | 29 | c->setResponseTimeout(60); 30 | 31 | swss::KeyOpFieldsValuesTuple kco; 32 | 33 | EXPECT_NE(c->wait("foo", kco), SAI_STATUS_SUCCESS); 34 | } 35 | -------------------------------------------------------------------------------- /unittest/lib/files/ccc_bad.txt: -------------------------------------------------------------------------------- 1 | foo bar 2 | -------------------------------------------------------------------------------- /unittest/lib/files/client_config_bad.txt: -------------------------------------------------------------------------------- 1 | foo bar 2 | -------------------------------------------------------------------------------- /unittest/lib/files/client_config_ok.txt: -------------------------------------------------------------------------------- 1 | { 2 | "zmq_endpoint": "ipc:///tmp/saiServer", 3 | "zmq_ntf_endpoint": "ipc:///tmp/saiServerNtf" 4 | } 5 | -------------------------------------------------------------------------------- /unittest/lib/files/server_config_bad.json: -------------------------------------------------------------------------------- 1 | { 2 | "zm 3 | -------------------------------------------------------------------------------- /unittest/lib/files/server_config_ok.json: -------------------------------------------------------------------------------- 1 | { 2 | "zmq_endpoint": "ipc:///tmp/saiServer", 3 | "zmq_ntf_endpoint": "ipc:///tmp/saiServerNtf" 4 | } 5 | -------------------------------------------------------------------------------- /unittest/lib/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | class SwsscommonEnvironment: 6 | public ::testing::Environment 7 | { 8 | public: 9 | void SetUp() override { } 10 | }; 11 | 12 | int main(int argc, char* argv[]) 13 | { 14 | testing::InitGoogleTest(&argc, argv); 15 | 16 | const auto env = new SwsscommonEnvironment; 17 | 18 | testing::AddGlobalTestEnvironment(env); 19 | 20 | return RUN_ALL_TESTS(); 21 | } 22 | -------------------------------------------------------------------------------- /unittest/meta/MockMeta.cpp: -------------------------------------------------------------------------------- 1 | #include "MockMeta.h" 2 | 3 | using namespace saimeta; 4 | 5 | MockMeta::MockMeta( 6 | _In_ std::shared_ptr impl): 7 | Meta(impl) 8 | { 9 | SWSS_LOG_ENTER(); 10 | 11 | // empty 12 | } 13 | 14 | sai_status_t MockMeta::call_meta_validate_stats( 15 | _In_ sai_object_type_t object_type, 16 | _In_ sai_object_id_t object_id, 17 | _In_ uint32_t number_of_counters, 18 | _In_ const sai_stat_id_t *counter_ids, 19 | _Out_ uint64_t *counters, 20 | _In_ sai_stats_mode_t mode) 21 | { 22 | SWSS_LOG_ENTER(); 23 | 24 | return meta_validate_stats( 25 | object_type, 26 | object_id, 27 | number_of_counters, 28 | counter_ids, 29 | counters, 30 | mode); 31 | } 32 | -------------------------------------------------------------------------------- /unittest/meta/MockMeta.h: -------------------------------------------------------------------------------- 1 | #include "Meta.h" 2 | 3 | namespace saimeta 4 | { 5 | class MockMeta: 6 | public Meta 7 | { 8 | public: 9 | 10 | using sairedis::SaiInterface::set; // name hiding 11 | 12 | MockMeta( 13 | _In_ std::shared_ptr impl); 14 | 15 | virtual ~MockMeta() = default; 16 | 17 | public: 18 | 19 | sai_status_t call_meta_validate_stats( 20 | _In_ sai_object_type_t object_type, 21 | _In_ sai_object_id_t object_id, 22 | _In_ uint32_t number_of_counters, 23 | _In_ const sai_stat_id_t *counter_ids, 24 | _Out_ uint64_t *counters, 25 | _In_ sai_stats_mode_t mode); 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /unittest/meta/TestAttrKeyMap.cpp: -------------------------------------------------------------------------------- 1 | #include "AttrKeyMap.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saimeta; 8 | 9 | TEST(AttrKeyMap, constructKey) 10 | { 11 | auto akm = std::make_shared(); 12 | 13 | sai_object_meta_key_t mk; 14 | 15 | memset(&mk, 0, sizeof(mk)); 16 | 17 | EXPECT_THROW( 18 | akm->constructKey(SAI_NULL_OBJECT_ID, mk, 0, nullptr), 19 | std::runtime_error); 20 | } 21 | 22 | TEST(AttrKeyMap, clear) 23 | { 24 | AttrKeyMap akm; 25 | 26 | EXPECT_EQ(akm.getAllKeys().size(), 0); 27 | 28 | akm.insert("foo", "bar"); 29 | 30 | EXPECT_EQ(akm.getAllKeys().size(), 1); 31 | 32 | akm.clear(); 33 | 34 | EXPECT_EQ(akm.getAllKeys().size(), 0); 35 | } 36 | -------------------------------------------------------------------------------- /unittest/meta/TestLegacy.h: -------------------------------------------------------------------------------- 1 | #include "Meta.h" 2 | #include "MetaTestSaiInterface.h" 3 | 4 | namespace TestLegacy 5 | { 6 | extern std::shared_ptr g_sai; 7 | extern std::shared_ptr g_meta; 8 | 9 | // STATIC HELPER METHODS 10 | 11 | void clear_local(); 12 | 13 | sai_object_id_t create_switch(); 14 | 15 | void remove_switch( 16 | _In_ sai_object_id_t switchId); 17 | 18 | sai_object_id_t create_bridge( 19 | _In_ sai_object_id_t switch_id); 20 | 21 | sai_object_id_t create_port( 22 | _In_ sai_object_id_t switch_id); 23 | 24 | sai_object_id_t create_bridge_port( 25 | _In_ sai_object_id_t switch_id, 26 | _In_ sai_object_id_t bridge_id); 27 | 28 | sai_object_id_t create_dummy_object_id( 29 | _In_ sai_object_type_t object_type, 30 | _In_ sai_object_id_t switch_id); 31 | 32 | sai_object_id_t create_virtual_router( 33 | _In_ sai_object_id_t switch_id); 34 | 35 | sai_object_id_t create_rif( 36 | _In_ sai_object_id_t switch_id); 37 | 38 | sai_object_id_t create_stp( 39 | _In_ sai_object_id_t switch_id); 40 | 41 | sai_object_id_t create_next_hop( 42 | _In_ sai_object_id_t switch_id); 43 | } 44 | -------------------------------------------------------------------------------- /unittest/meta/TestNotificationTam.cpp: -------------------------------------------------------------------------------- 1 | #include "NotificationTamTelTypeConfigChange.h" 2 | #include "Meta.h" 3 | #include "MetaTestSaiInterface.h" 4 | 5 | #include "sairediscommon.h" 6 | #include "sai_serialize.h" 7 | 8 | #include 9 | 10 | using namespace sairedis; 11 | using namespace saimeta; 12 | 13 | TEST(NotificationTamTelTypeConfigChange, processMetadata) 14 | { 15 | auto sai = std::make_shared(); 16 | auto meta = std::make_shared(sai); 17 | 18 | sai_object_id_t switch_id; 19 | sai_object_id_t tam_id; 20 | 21 | sai_attribute_t attr; 22 | attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; 23 | attr.value.booldata = true; 24 | 25 | sai->create(SAI_OBJECT_TYPE_SWITCH, &switch_id, SAI_NULL_OBJECT_ID, 1, &attr); 26 | sai->create(SAI_OBJECT_TYPE_TAM_TEL_TYPE, &tam_id, switch_id, 0, nullptr); 27 | 28 | std::stringstream ss; 29 | ss << "oid:0x" << std::hex << tam_id; 30 | 31 | NotificationTamTelTypeConfigChange n(ss.str()); 32 | n.processMetadata(meta); 33 | } 34 | -------------------------------------------------------------------------------- /unittest/meta/TestPerformanceIntervalTimer.cpp: -------------------------------------------------------------------------------- 1 | #include "PerformanceIntervalTimer.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace sairediscommon; 8 | 9 | TEST(PerformanceIntervalTimer, inc) 10 | { 11 | PerformanceIntervalTimer p("foo", 2); 12 | 13 | p.inc(); 14 | p.inc(10); 15 | } 16 | -------------------------------------------------------------------------------- /unittest/meta/TestPortRelatedSet.cpp: -------------------------------------------------------------------------------- 1 | #include "PortRelatedSet.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saimeta; 8 | 9 | TEST(PortRelatedSet, inc) 10 | { 11 | PortRelatedSet set; 12 | 13 | set.insert(0, 0); 14 | 15 | EXPECT_EQ(set.getAllPorts().size(), 0); 16 | 17 | EXPECT_THROW(set.insert(0, 1), std::runtime_error); 18 | } 19 | -------------------------------------------------------------------------------- /unittest/meta/TestSaiAttrWrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "SaiAttrWrapper.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saimeta; 8 | 9 | TEST(SaiAttrWrapper, ctr) 10 | { 11 | sai_attribute_t attr; 12 | 13 | attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; 14 | attr.value.booldata = true; 15 | 16 | EXPECT_THROW(std::make_shared(nullptr, attr), std::runtime_error); 17 | } 18 | 19 | TEST(SaiAttrWrapper, getAttrId) 20 | { 21 | sai_attribute_t attr; 22 | 23 | attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; 24 | attr.value.booldata = true; 25 | 26 | auto meta = sai_metadata_get_attr_metadata( 27 | SAI_OBJECT_TYPE_SWITCH, 28 | SAI_SWITCH_ATTR_INIT_SWITCH); 29 | 30 | SaiAttrWrapper w(meta, attr); 31 | 32 | EXPECT_EQ(w.getAttrId(), SAI_SWITCH_ATTR_INIT_SWITCH); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /unittest/meta/TestSaiObject.cpp: -------------------------------------------------------------------------------- 1 | #include "SaiObject.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saimeta; 8 | 9 | TEST(SaiObject, ctr) 10 | { 11 | sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_NULL, .objectkey = { .key = { .object_id = 0 } } }; 12 | 13 | EXPECT_THROW(std::make_shared(meta_key), std::runtime_error); 14 | } 15 | 16 | TEST(SaiObject, hasAttr) 17 | { 18 | sai_object_meta_key_t mk = { .objecttype = SAI_OBJECT_TYPE_SWITCH, .objectkey = { .key = { .object_id = 0 } } }; 19 | 20 | SaiObject so(mk); 21 | 22 | EXPECT_FALSE(so.hasAttr(1)); 23 | } 24 | 25 | TEST(SaiObject, setAttr) 26 | { 27 | sai_object_meta_key_t mk = { .objecttype = SAI_OBJECT_TYPE_SWITCH, .objectkey = { .key = { .object_id = 0 } } }; 28 | 29 | SaiObject so(mk); 30 | 31 | sai_attribute_t attr; 32 | 33 | attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; 34 | attr.value.booldata = true; 35 | 36 | auto meta = sai_metadata_get_attr_metadata( 37 | SAI_OBJECT_TYPE_SWITCH, 38 | SAI_SWITCH_ATTR_INIT_SWITCH); 39 | 40 | auto a = std::make_shared(meta, attr); 41 | 42 | so.setAttr(a); 43 | } 44 | -------------------------------------------------------------------------------- /unittest/meta/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | class SwsscommonEnvironment: 6 | public ::testing::Environment 7 | { 8 | public: 9 | void SetUp() override { } 10 | }; 11 | 12 | int main(int argc, char* argv[]) 13 | { 14 | testing::InitGoogleTest(&argc, argv); 15 | 16 | const auto env = new SwsscommonEnvironment; 17 | 18 | testing::AddGlobalTestEnvironment(env); 19 | 20 | return RUN_ALL_TESTS(); 21 | } 22 | -------------------------------------------------------------------------------- /unittest/proxylib/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/meta -I$(top_srcdir)/proxylib -I$(top_srcdir)/lib 2 | 3 | bin_PROGRAMS = tests 4 | 5 | LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main 6 | 7 | tests_SOURCES = \ 8 | main.cpp \ 9 | TestProxy.cpp \ 10 | TestSai.cpp 11 | 12 | tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) 13 | tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/proxylib/libSaiProxy.a \ 14 | $(top_srcdir)/lib/libSaiRedis.a \ 15 | $(top_srcdir)/syncd/libSyncd.a \ 16 | -lhiredis -lswsscommon -lpthread \ 17 | -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta \ 18 | -lzmq $(CODE_COVERAGE_LIBS) 19 | 20 | TESTS = tests 21 | -------------------------------------------------------------------------------- /unittest/proxylib/config.ini: -------------------------------------------------------------------------------- 1 | # test proxu config comment 2 | ; comment 3 | 4 | invalid line 5 | 6 | VARIABLE=VALUE 7 | FOO=bar 8 | BAR=baz 9 | -------------------------------------------------------------------------------- /unittest/proxylib/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | class SwsscommonEnvironment: 6 | public ::testing::Environment 7 | { 8 | public: 9 | void SetUp() override { } 10 | }; 11 | 12 | int main(int argc, char* argv[]) 13 | { 14 | testing::InitGoogleTest(&argc, argv); 15 | 16 | const auto env = new SwsscommonEnvironment; 17 | 18 | testing::AddGlobalTestEnvironment(env); 19 | 20 | return RUN_ALL_TESTS(); 21 | } 22 | -------------------------------------------------------------------------------- /unittest/saidump/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/saidump -I$(top_srcdir)/lib -I$(top_srcdir)/vslib -I$(top_srcdir)/meta 2 | 3 | bin_PROGRAMS = tests 4 | 5 | LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main 6 | 7 | tests_SOURCES = main.cpp TestSaiDump.cpp 8 | 9 | tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) 10 | tests_LDFLAGS = -D_UNITTEST_ 11 | tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/saidump/libsaidump.a -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 -lpthread -L$(top_srcdir)/lib/.libs -lsairedis -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) 12 | 13 | TESTS = tests -------------------------------------------------------------------------------- /unittest/saidump/err.json: -------------------------------------------------------------------------------- 1 | [{]} 2 | -------------------------------------------------------------------------------- /unittest/saidump/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | testing::InitGoogleTest(&argc, argv); 6 | const auto env = new ::testing::Environment(); 7 | testing::AddGlobalTestEnvironment(env); 8 | return RUN_ALL_TESTS(); 9 | } 10 | -------------------------------------------------------------------------------- /unittest/syncd/MockHelper.cpp: -------------------------------------------------------------------------------- 1 | #include "VidManager.h" 2 | #include "swss/dbconnector.h" 3 | #include "swss/table.h" 4 | 5 | namespace test_syncd { 6 | sai_object_type_t mock_objectTypeQuery_result; 7 | void mockVidManagerObjectTypeQuery(sai_object_type_t mock_result) 8 | { 9 | SWSS_LOG_ENTER(); 10 | mock_objectTypeQuery_result = mock_result; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /unittest/syncd/MockHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace test_syncd { 4 | void mockVidManagerObjectTypeQuery(sai_object_type_t); 5 | } -------------------------------------------------------------------------------- /unittest/syncd/TestBestCandidateFinder.cpp: -------------------------------------------------------------------------------- 1 | #include "BestCandidateFinder.h" 2 | #include "MockableSaiSwitchInterface.h" 3 | 4 | #include 5 | 6 | using namespace syncd; 7 | using namespace unittests; 8 | 9 | TEST(BestCandidateFinder, getSaiAttrFromDefaultValue) 10 | { 11 | AsicView av; 12 | 13 | auto *meta = sai_metadata_get_attr_metadata( 14 | SAI_OBJECT_TYPE_SWITCH, 15 | SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC); 16 | 17 | EXPECT_NE(meta, nullptr); 18 | 19 | auto sw = std::make_shared(0,0); 20 | 21 | auto attr = BestCandidateFinder::getSaiAttrFromDefaultValue(av, sw, *meta); 22 | EXPECT_NE(attr, nullptr); 23 | } 24 | -------------------------------------------------------------------------------- /unittest/syncd/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | int main(int argc, char* argv[]) 6 | { 7 | testing::InitGoogleTest(&argc, argv); 8 | 9 | const auto env = new ::testing::Environment(); 10 | 11 | testing::AddGlobalTestEnvironment(env); 12 | 13 | return RUN_ALL_TESTS(); 14 | } 15 | -------------------------------------------------------------------------------- /unittest/syncd/profile.ini: -------------------------------------------------------------------------------- 1 | SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin 2 | SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin 3 | SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_MLNX2700 4 | -------------------------------------------------------------------------------- /unittest/vslib/TestBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "Buffer.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saivs; 8 | 9 | TEST(Buffer, ctr) 10 | { 11 | EXPECT_THROW(std::make_shared(nullptr, 0), std::runtime_error); 12 | 13 | Buffer b((const uint8_t*)"foo", 3); 14 | } 15 | 16 | TEST(Buffer, dtr) 17 | { 18 | auto b = std::make_shared((const uint8_t*)"foo", 3); 19 | 20 | b = nullptr; 21 | } 22 | 23 | TEST(Buffer, getData) 24 | { 25 | EXPECT_THROW(std::make_shared(nullptr,0), std::runtime_error); 26 | 27 | Buffer b((const uint8_t*)"foo", 3); 28 | 29 | EXPECT_NE(b.getData(), nullptr); 30 | } 31 | 32 | TEST(Buffer, getSize) 33 | { 34 | EXPECT_THROW(std::make_shared(nullptr,0), std::runtime_error); 35 | 36 | Buffer b((const uint8_t*)"foo", 3); 37 | 38 | EXPECT_EQ(b.getSize(), 3); 39 | } 40 | 41 | TEST(Buffer, flow) 42 | { 43 | EXPECT_THROW(std::make_shared(nullptr,0), std::runtime_error); 44 | 45 | Buffer b((const uint8_t*)"foo", 3); 46 | 47 | EXPECT_NE(b.getData(), nullptr); 48 | 49 | EXPECT_EQ(b.getSize(), 3); 50 | } 51 | -------------------------------------------------------------------------------- /unittest/vslib/TestCorePortIndexMapFileParser.cpp: -------------------------------------------------------------------------------- 1 | #include "CorePortIndexMapFileParser.h" 2 | 3 | #include 4 | 5 | using namespace saivs; 6 | 7 | TEST(CorePortIndexMapFileParser, isInterfaceNameValid) 8 | { 9 | EXPECT_EQ(CorePortIndexMapFileParser::isInterfaceNameValid(""), false); 10 | 11 | EXPECT_EQ(CorePortIndexMapFileParser::isInterfaceNameValid("1111111111111111111111111111111111111111111111111111111"), false); 12 | 13 | EXPECT_EQ(CorePortIndexMapFileParser::isInterfaceNameValid("rer/;"), false); 14 | 15 | EXPECT_EQ(CorePortIndexMapFileParser::isInterfaceNameValid("foo"), true); 16 | } 17 | 18 | 19 | TEST(CorePortIndexMapFileParser, parseCorePortIndexMapFile) 20 | { 21 | // should load default 22 | 23 | EXPECT_NE(CorePortIndexMapFileParser::parseCorePortIndexMapFile(nullptr), nullptr); 24 | 25 | EXPECT_NE(CorePortIndexMapFileParser::parseCorePortIndexMapFile("not_existing"), nullptr); 26 | 27 | EXPECT_NE(CorePortIndexMapFileParser::parseCorePortIndexMapFile("files/core_port_empty.txt"), nullptr); 28 | 29 | EXPECT_NE(CorePortIndexMapFileParser::parseCorePortIndexMapFile("files/core_port_ok.txt"), nullptr); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /unittest/vslib/TestEventPayloadNetLinkMsg.cpp: -------------------------------------------------------------------------------- 1 | #include "EventPayloadNetLinkMsg.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saivs; 8 | 9 | TEST(EventPayloadNetLinkMsg, ctr) 10 | { 11 | EventPayloadNetLinkMsg ep(0, 1, 2, IFF_UP, "foo"); 12 | } 13 | 14 | TEST(EventPayloadNetLinkMsg, getSwitchId) 15 | { 16 | EventPayloadNetLinkMsg ep(0, 1, 2, IFF_UP, "foo"); 17 | 18 | EXPECT_EQ(ep.getSwitchId(), 0); 19 | } 20 | 21 | TEST(EventPayloadNetLinkMsg, getNlmsgType) 22 | { 23 | EventPayloadNetLinkMsg ep(0, 1, 2, IFF_UP, "foo"); 24 | 25 | EXPECT_EQ(ep.getNlmsgType(), 1); 26 | } 27 | 28 | TEST(EventPayloadNetLinkMsg, getIfIndex) 29 | { 30 | EventPayloadNetLinkMsg ep(0, 1, 2, IFF_UP, "foo"); 31 | 32 | EXPECT_EQ(ep.getIfIndex(), 2); 33 | } 34 | 35 | TEST(EventPayloadNetLinkMsg, getIfFlags) 36 | { 37 | EventPayloadNetLinkMsg ep(0, 1, 2, IFF_UP, "foo"); 38 | 39 | EXPECT_EQ(ep.getIfFlags(), IFF_UP); 40 | } 41 | 42 | TEST(EventPayloadNetLinkMsg, getIfName) 43 | { 44 | EventPayloadNetLinkMsg ep(0, 1, 2, IFF_UP, "foo"); 45 | 46 | EXPECT_EQ(ep. getIfName(), "foo"); 47 | } 48 | -------------------------------------------------------------------------------- /unittest/vslib/TestEventPayloadPacket.cpp: -------------------------------------------------------------------------------- 1 | #include "EventPayloadPacket.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saivs; 8 | 9 | TEST(EventPayloadPacket, ctr) 10 | { 11 | uint8_t data[2] = { 1, 2 }; 12 | 13 | Buffer b(data, 2); 14 | 15 | EventPayloadPacket ep(0, 1, "foo", b); 16 | } 17 | 18 | TEST(EventPayloadPacket, getPort) 19 | { 20 | uint8_t data[2] = { 1, 2 }; 21 | Buffer b(data, 2); 22 | EventPayloadPacket ep(0, 1, "foo", b); 23 | 24 | EXPECT_EQ(ep.getPort(), 0); 25 | } 26 | 27 | TEST(EventPayloadPacket, getIfIndex) 28 | { 29 | uint8_t data[2] = { 1, 2 }; 30 | Buffer b(data, 2); 31 | EventPayloadPacket ep(0, 1, "foo", b); 32 | 33 | EXPECT_EQ(ep.getIfIndex(), 1); 34 | } 35 | 36 | TEST(EventPayloadPacket, getIfName) 37 | { 38 | uint8_t data[2] = { 1, 2 }; 39 | Buffer b(data, 2); 40 | EventPayloadPacket ep(0, 1, "foo", b); 41 | 42 | EXPECT_EQ(ep.getIfName(), "foo"); 43 | } 44 | 45 | TEST(EventPayloadPacket, getBuffer) 46 | { 47 | uint8_t data[2] = { 1, 2 }; 48 | Buffer b(data, 2); 49 | EventPayloadPacket ep(0, 1, "foo", b); 50 | 51 | auto&bb = ep.getBuffer(); 52 | 53 | EXPECT_EQ(bb.getData()[0], 1); 54 | EXPECT_EQ(bb.getData()[1], 2); 55 | } 56 | -------------------------------------------------------------------------------- /unittest/vslib/TestEventQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "EventQueue.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | using namespace saivs; 10 | 11 | TEST(EventQueue, ctr) 12 | { 13 | EXPECT_THROW(std::make_shared(nullptr), std::runtime_error); 14 | 15 | auto s = std::make_shared(); 16 | 17 | EventQueue eq(s); 18 | } 19 | 20 | TEST(EventQueue, size) 21 | { 22 | auto s = std::make_shared(); 23 | 24 | EventQueue eq(s); 25 | 26 | EXPECT_EQ(eq.size(), 0); 27 | } 28 | -------------------------------------------------------------------------------- /unittest/vslib/TestLaneMapFileParser.cpp: -------------------------------------------------------------------------------- 1 | #include "LaneMapFileParser.h" 2 | 3 | #include 4 | 5 | using namespace saivs; 6 | 7 | TEST(LaneMapFileParser, isInterfaceNameValid) 8 | { 9 | EXPECT_FALSE(LaneMapFileParser::isInterfaceNameValid("")); 10 | EXPECT_FALSE(LaneMapFileParser::isInterfaceNameValid("111111111111111111111111111111111111111")); 11 | EXPECT_FALSE(LaneMapFileParser::isInterfaceNameValid("ab09AZ:")); 12 | } 13 | 14 | 15 | TEST(LaneMapFileParser, parseLaneMapFile) 16 | { 17 | EXPECT_NE(LaneMapFileParser::parseLaneMapFile(nullptr), nullptr); 18 | 19 | EXPECT_NE(LaneMapFileParser::parseLaneMapFile("not_existing"), nullptr); 20 | 21 | EXPECT_NE(LaneMapFileParser::parseLaneMapFile("files/lane_map_empty.txt"), nullptr); 22 | 23 | EXPECT_NE(LaneMapFileParser::parseLaneMapFile("files/lane_nap_ok.txt"), nullptr); 24 | } 25 | -------------------------------------------------------------------------------- /unittest/vslib/TestMACsecEgressFilter.cpp: -------------------------------------------------------------------------------- 1 | #include "MACsecEgressFilter.h" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define EAPOL_ETHER_TYPE (0x888e) 13 | 14 | using namespace saivs; 15 | 16 | TEST(MACsecEgressFilter, ctr) 17 | { 18 | MACsecEgressFilter filter("foo"); 19 | } 20 | 21 | TEST(MACsecEgressFilter, forward) 22 | { 23 | MACsecEgressFilter filter("foo"); 24 | 25 | filter.set_macsec_fd(0); 26 | 27 | uint8_t packet[4000]; 28 | 29 | memset(packet, 0, sizeof(packet)); 30 | 31 | ethhdr* eth = (ethhdr*)packet; 32 | 33 | eth->h_proto = ntohs(EAPOL_ETHER_TYPE); 34 | 35 | size_t len = sizeof(packet); 36 | 37 | EXPECT_EQ(filter.execute(packet, len), TrafficFilter::CONTINUE); 38 | 39 | eth->h_proto = ntohs(6); 40 | 41 | EXPECT_EQ(filter.execute(packet, len), TrafficFilter::TERMINATE); 42 | 43 | filter.enable_macsec_device(true); 44 | 45 | // fd is ok, stdout 46 | EXPECT_EQ(filter.execute(packet, len), TrafficFilter::TERMINATE); 47 | 48 | filter.set_macsec_fd(70); // bad fd 49 | 50 | EXPECT_EQ(filter.execute(packet, len), TrafficFilter::TERMINATE); 51 | } 52 | -------------------------------------------------------------------------------- /unittest/vslib/TestMACsecFilterStateGuard.cpp: -------------------------------------------------------------------------------- 1 | #include "MACsecFilterStateGuard.h" 2 | 3 | #include 4 | 5 | using namespace saivs; 6 | 7 | TEST(MACsecFilterStateGuard, ctr) 8 | { 9 | MACsecFilter::MACsecFilterState state = MACsecFilter::MACsecFilterState::MACSEC_FILTER_STATE_IDLE; 10 | 11 | { 12 | MACsecFilterStateGuard guard(state, MACsecFilter::MACsecFilterState::MACSEC_FILTER_STATE_BUSY); 13 | 14 | EXPECT_EQ(state, MACsecFilter::MACsecFilterState::MACSEC_FILTER_STATE_BUSY); 15 | } 16 | 17 | EXPECT_EQ(state, MACsecFilter::MACsecFilterState::MACSEC_FILTER_STATE_IDLE); 18 | } 19 | -------------------------------------------------------------------------------- /unittest/vslib/TestMACsecForwarder.cpp: -------------------------------------------------------------------------------- 1 | #include "MACsecForwarder.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saivs; 8 | 9 | TEST(MACsecForwarder, ctr) 10 | { 11 | EXPECT_THROW(std::make_shared("foo", nullptr), std::runtime_error); 12 | 13 | auto s = std::make_shared(); 14 | 15 | auto q = std::make_shared(s); 16 | } 17 | -------------------------------------------------------------------------------- /unittest/vslib/TestMACsecIngressFilter.cpp: -------------------------------------------------------------------------------- 1 | #include "MACsecIngressFilter.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define EAPOL_ETHER_TYPE (0x888e) 11 | 12 | #include 13 | 14 | using namespace saivs; 15 | 16 | TEST(MACsecIngressFilter, forward) 17 | { 18 | MACsecIngressFilter filter("foo"); 19 | 20 | filter.set_macsec_fd(0); 21 | 22 | uint8_t packet[4000]; 23 | 24 | memset(packet, 0, sizeof(packet)); 25 | 26 | ethhdr* eth = (ethhdr*)packet; 27 | 28 | eth->h_proto = ntohs(EAPOL_ETHER_TYPE); 29 | 30 | size_t len = sizeof(packet); 31 | 32 | EXPECT_EQ(filter.execute(packet, len), TrafficFilter::CONTINUE); 33 | 34 | eth->h_proto = ntohs(6); 35 | 36 | EXPECT_EQ(filter.execute(packet, len), TrafficFilter::TERMINATE); 37 | 38 | filter.enable_macsec_device(true); 39 | 40 | // fd is ok, stdout 41 | EXPECT_EQ(filter.execute(packet, len), TrafficFilter::TERMINATE); 42 | 43 | filter.set_macsec_fd(70); // bad fd 44 | 45 | EXPECT_EQ(filter.execute(packet, len), TrafficFilter::TERMINATE); 46 | } 47 | -------------------------------------------------------------------------------- /unittest/vslib/TestNetMsgRegistrar.cpp: -------------------------------------------------------------------------------- 1 | #include "NetMsgRegistrar.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | #include 6 | 7 | using namespace saivs; 8 | 9 | static void callback(int, struct nl_object*) 10 | { 11 | SWSS_LOG_ENTER(); 12 | 13 | // empty 14 | } 15 | 16 | TEST(NetMsgRegistrar, registerCallback) 17 | { 18 | auto& reg = NetMsgRegistrar::getInstance(); 19 | 20 | auto index = reg.registerCallback(callback); 21 | 22 | reg.unregisterCallback(index); 23 | } 24 | 25 | TEST(NetMsgRegistrar, unregisterAll) 26 | { 27 | auto& reg = NetMsgRegistrar::getInstance(); 28 | 29 | reg.registerCallback(callback); 30 | 31 | usleep(100*1000); 32 | 33 | reg.unregisterAll(); 34 | } 35 | 36 | TEST(NetMsgRegistrar, resetIndex) 37 | { 38 | auto& reg = NetMsgRegistrar::getInstance(); 39 | 40 | reg.resetIndex(); 41 | 42 | auto index = reg.registerCallback(callback); 43 | 44 | reg.unregisterAll(); 45 | 46 | auto index2 = reg.registerCallback(callback); 47 | 48 | EXPECT_NE(index, index2); 49 | 50 | reg.unregisterAll(); 51 | 52 | reg.resetIndex(); 53 | 54 | auto index3 = reg.registerCallback(callback); 55 | 56 | EXPECT_EQ(index, index3); 57 | } 58 | -------------------------------------------------------------------------------- /unittest/vslib/TestResourceLimiter.cpp: -------------------------------------------------------------------------------- 1 | #include "ResourceLimiter.h" 2 | 3 | #include 4 | 5 | using namespace saivs; 6 | 7 | TEST(ResourceLimiter, ctr) 8 | { 9 | ResourceLimiter rl(0); 10 | } 11 | 12 | TEST(ResourceLimiter, getObjectTypeLimit) 13 | { 14 | ResourceLimiter rl(0); 15 | 16 | EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), SIZE_MAX); 17 | 18 | rl.setObjectTypeLimit(SAI_OBJECT_TYPE_PORT, 5); 19 | 20 | EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), 5); 21 | } 22 | 23 | TEST(ResourceLimiter, removeObjectTypeLimit) 24 | { 25 | ResourceLimiter rl(0); 26 | 27 | EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), SIZE_MAX); 28 | 29 | rl.setObjectTypeLimit(SAI_OBJECT_TYPE_PORT, 5); 30 | 31 | EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), 5); 32 | 33 | rl.removeObjectTypeLimit(SAI_OBJECT_TYPE_PORT); 34 | 35 | EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), SIZE_MAX); 36 | } 37 | 38 | TEST(ResourceLimiter, clearLimits) 39 | { 40 | ResourceLimiter rl(0); 41 | 42 | rl.setObjectTypeLimit(SAI_OBJECT_TYPE_PORT, 5); 43 | 44 | EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), 5); 45 | 46 | rl.clearLimits(); 47 | 48 | EXPECT_EQ(rl.getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), SIZE_MAX); 49 | } 50 | -------------------------------------------------------------------------------- /unittest/vslib/TestResourceLimiterContainer.cpp: -------------------------------------------------------------------------------- 1 | #include "ResourceLimiterContainer.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saivs; 8 | 9 | TEST(ResourceLimiterContainer, insert) 10 | { 11 | auto rl = std::make_shared(0); 12 | 13 | ResourceLimiterContainer rlc; 14 | 15 | EXPECT_THROW(rlc.insert(0, nullptr), std::runtime_error); 16 | 17 | rlc.insert(0, rl); 18 | 19 | EXPECT_NE(rlc.getResourceLimiter(0), nullptr); 20 | } 21 | 22 | TEST(ResourceLimiterContainer, remove) 23 | { 24 | auto rl = std::make_shared(0); 25 | 26 | ResourceLimiterContainer rlc; 27 | 28 | EXPECT_THROW(rlc.insert(0, nullptr), std::runtime_error); 29 | 30 | rlc.insert(0, rl); 31 | 32 | EXPECT_NE(rlc.getResourceLimiter(0), nullptr); 33 | 34 | rlc.remove(0); 35 | 36 | EXPECT_EQ(rlc.getResourceLimiter(0), nullptr); 37 | } 38 | 39 | TEST(ResourceLimiterContainer, getResourceLimiter) 40 | { 41 | auto rl = std::make_shared(0); 42 | 43 | ResourceLimiterContainer rlc; 44 | 45 | EXPECT_THROW(rlc.insert(0, nullptr), std::runtime_error); 46 | 47 | rlc.insert(0, rl); 48 | 49 | EXPECT_NE(rlc.getResourceLimiter(0), nullptr); 50 | 51 | rlc.clear(); 52 | 53 | EXPECT_EQ(rlc.getResourceLimiter(0), nullptr); 54 | } 55 | -------------------------------------------------------------------------------- /unittest/vslib/TestResourceLimiterParser.cpp: -------------------------------------------------------------------------------- 1 | #include "ResourceLimiterParser.h" 2 | 3 | #include 4 | 5 | using namespace saivs; 6 | 7 | TEST(ResourceLimiterParser, parseFromFile) 8 | { 9 | EXPECT_NE(ResourceLimiterParser::parseFromFile(nullptr), nullptr); 10 | 11 | EXPECT_NE(ResourceLimiterParser::parseFromFile("not_existing"), nullptr); 12 | 13 | EXPECT_NE(ResourceLimiterParser::parseFromFile("files/resource_limiter_bad.txt"), nullptr); 14 | 15 | EXPECT_NE(ResourceLimiterParser::parseFromFile("files/resource_limiter_ok.txt"), nullptr); 16 | 17 | auto rlc = ResourceLimiterParser::parseFromFile("files/resource_limiter_ok.txt"); 18 | 19 | auto rl = rlc->getResourceLimiter(1); 20 | 21 | EXPECT_NE(rl, nullptr); 22 | 23 | EXPECT_EQ(rl->getObjectTypeLimit(SAI_OBJECT_TYPE_PORT), 8); 24 | } 25 | -------------------------------------------------------------------------------- /unittest/vslib/TestSaiAttrWrap.cpp: -------------------------------------------------------------------------------- 1 | #include "SaiAttrWrap.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saivs; 8 | 9 | TEST(SaiAttrWrap, ctr) 10 | { 11 | EXPECT_THROW(std::make_shared("attrId", "attrValue"), std::runtime_error); 12 | } 13 | -------------------------------------------------------------------------------- /unittest/vslib/TestSelectableFd.cpp: -------------------------------------------------------------------------------- 1 | #include "SelectableFd.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saivs; 8 | 9 | TEST(SelectableFd, ctr) 10 | { 11 | EXPECT_THROW(std::make_shared(-1), std::runtime_error); 12 | 13 | SelectableFd fd(0); 14 | } 15 | 16 | TEST(SelectableFd, getFd) 17 | { 18 | SelectableFd fd(7); 19 | 20 | EXPECT_EQ(fd.getFd(), 7); 21 | } 22 | 23 | TEST(SelectableFd, readData) 24 | { 25 | SelectableFd fd(7); 26 | 27 | EXPECT_EQ(fd.readData(), 0); 28 | } 29 | -------------------------------------------------------------------------------- /unittest/vslib/TestSignal.cpp: -------------------------------------------------------------------------------- 1 | #include "Signal.h" 2 | 3 | #include 4 | 5 | using namespace saivs; 6 | 7 | TEST(Signal, notifyOne) 8 | { 9 | Signal s; 10 | 11 | s.notifyOne(); 12 | } 13 | -------------------------------------------------------------------------------- /unittest/vslib/TestSwitchConfigContainer.cpp: -------------------------------------------------------------------------------- 1 | #include "SwitchConfigContainer.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | using namespace saivs; 8 | 9 | TEST(SwitchConfigContainer, insert) 10 | { 11 | SwitchConfigContainer scc; 12 | 13 | EXPECT_THROW(scc.insert(nullptr), std::runtime_error); 14 | 15 | auto sc0 = std::make_shared(0,"foo"); 16 | auto sc1 = std::make_shared(0,"bar"); 17 | auto sc2 = std::make_shared(1,"bar"); 18 | 19 | scc.insert(sc1); 20 | 21 | EXPECT_THROW(scc.insert(sc0), std::runtime_error); 22 | 23 | EXPECT_THROW(scc.insert(sc2), std::runtime_error); 24 | } 25 | 26 | TEST(SwitchConfigContainer, getConfig) 27 | { 28 | SwitchConfigContainer scc; 29 | 30 | auto sc0 = std::make_shared(0,"foo"); 31 | auto sc1 = std::make_shared(1,"bar"); 32 | 33 | scc.insert(sc0); 34 | scc.insert(sc1); 35 | 36 | EXPECT_EQ(scc.getConfig(2), nullptr); 37 | EXPECT_NE(scc.getConfig(0), nullptr); 38 | EXPECT_NE(scc.getConfig(1), nullptr); 39 | } 40 | -------------------------------------------------------------------------------- /unittest/vslib/files/bcm81724.warm.bin: -------------------------------------------------------------------------------- 1 | SAI_OBJECT_TYPE_SWITCH oid:0x2100000000 SAI_SWITCH_ATTR_DEFAULT_TRAP_GROUP oid:0x0 2 | SAI_OBJECT_TYPE_SWITCH oid:0x2100000000 SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION 825110646 3 | SAI_OBJECT_TYPE_SWITCH oid:0x2100000000 SAI_SWITCH_ATTR_NUMBER_OF_ACTIVE_PORTS 0 4 | SAI_OBJECT_TYPE_SWITCH oid:0x2100000000 SAI_SWITCH_ATTR_SUPPORTED_OBJECT_TYPE_LIST 2:SAI_OBJECT_TYPE_NULL,SAI_OBJECT_TYPE_PORT 5 | SAI_OBJECT_TYPE_SWITCH oid:0x2100000000 SAI_SWITCH_ATTR_TYPE SAI_SWITCH_TYPE_PHY 6 | SAI_OBJECT_TYPE_SWITCH oid:0x2100000000 SAI_SWITCH_ATTR_WARM_RECOVER false 7 | -------------------------------------------------------------------------------- /unittest/vslib/files/context_config.bad.json: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /unittest/vslib/files/context_config.good.json: -------------------------------------------------------------------------------- 1 | { 2 | "CONTEXTS": [ 3 | { 4 | "guid" : 0, 5 | "name" : "syncd", 6 | "dbAsic" : "ASIC_DB", 7 | "dbCounters" : "COUNTERS_DB", 8 | "dbFlex": "FLEX_COUNTER_DB", 9 | "dbState" : "STATE_DB", 10 | "zmq_enable": false, 11 | "zmq_endpoint": "tcp://127.0.0.1:5555", 12 | "zmq_ntf_endpoint": "tcp://127.0.0.1:5556", 13 | "switches": [ 14 | { 15 | "index" : 0, 16 | "hwinfo" : "" 17 | }, 18 | { 19 | "index" : 1, 20 | "hwinfo" : "1" 21 | } 22 | ] 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /unittest/vslib/files/core_port_empty.txt: -------------------------------------------------------------------------------- 1 | ; comment 2 | # comment 3 | error line 4 | 0:0 5 | 0:0:0 6 | d:d:d 7 | d:x_x:d 8 | 1:xx:d,d 9 | -------------------------------------------------------------------------------- /unittest/vslib/files/core_port_ok.txt: -------------------------------------------------------------------------------- 1 | ; comment 2 | # comment 3 | error line 4 | 0:ifname:1,2 5 | -------------------------------------------------------------------------------- /unittest/vslib/files/lane_map_empty.txt: -------------------------------------------------------------------------------- 1 | # 2 | ; 3 | token 4 | 0:x_x:0 5 | 0:x_x:0,1,2 6 | d:d 7 | d:d:d 8 | 0:ed:0,1,2 9 | -------------------------------------------------------------------------------- /unittest/vslib/files/lane_map_ok.txt: -------------------------------------------------------------------------------- 1 | 0:eth1:1,2,3,4 2 | -------------------------------------------------------------------------------- /unittest/vslib/files/resource_limiter_bad.txt: -------------------------------------------------------------------------------- 1 | # cmt 2 | ; cmt 3 | 4 | foo 5 | foo:bar 6 | foo:bar:car 7 | foo:bar=6 8 | foo:bar:car=6 9 | 0:foo=5 10 | d:foo=6 11 | d:SAI_OBJECT_TYPE_PORT=6 12 | 0:SAI_OBJECT_TYPE_PORT=zz 13 | SAI_OBJECT_TYPE_PORT=zz 14 | -------------------------------------------------------------------------------- /unittest/vslib/files/resource_limiter_ok.txt: -------------------------------------------------------------------------------- 1 | SAI_OBJECT_TYPE_PORT=7 2 | 1:SAI_OBJECT_TYPE_PORT=8 3 | -------------------------------------------------------------------------------- /unittest/vslib/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "swss/logger.h" 4 | 5 | #include 6 | 7 | int main(int argc, char* argv[]) 8 | { 9 | testing::InitGoogleTest(&argc, argv); 10 | 11 | const auto env = new ::testing::Environment(); 12 | 13 | testing::AddGlobalTestEnvironment(env); 14 | 15 | return RUN_ALL_TESTS(); 16 | } 17 | -------------------------------------------------------------------------------- /vslib/Buffer.cpp: -------------------------------------------------------------------------------- 1 | #include "Buffer.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | #include 6 | 7 | using namespace saivs; 8 | 9 | Buffer::Buffer( 10 | _In_ const uint8_t* data, 11 | _In_ size_t size) 12 | { 13 | SWSS_LOG_ENTER(); 14 | 15 | if (!data) 16 | { 17 | SWSS_LOG_THROW("data is NULL!"); 18 | } 19 | 20 | m_data = std::vector(data, data + size); 21 | } 22 | 23 | const uint8_t* Buffer::getData() const 24 | { 25 | SWSS_LOG_ENTER(); 26 | 27 | return m_data.data(); 28 | } 29 | 30 | size_t Buffer::getSize() const 31 | { 32 | SWSS_LOG_ENTER(); 33 | 34 | return m_data.size(); 35 | } 36 | -------------------------------------------------------------------------------- /vslib/Buffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace saivs 11 | { 12 | class Buffer 13 | { 14 | public: 15 | 16 | Buffer( 17 | _In_ const uint8_t* data, 18 | _In_ size_t size); 19 | 20 | virtual ~Buffer() = default; 21 | 22 | public: 23 | 24 | const uint8_t* getData() const; 25 | 26 | size_t getSize() const; 27 | 28 | private: 29 | 30 | std::vector m_data; 31 | 32 | size_t m_size; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /vslib/Context.cpp: -------------------------------------------------------------------------------- 1 | #include "Context.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saivs; 6 | 7 | Context::Context( 8 | _In_ std::shared_ptr contextConfig): 9 | m_contextConfig(contextConfig) 10 | { 11 | SWSS_LOG_ENTER(); 12 | 13 | // empty 14 | } 15 | 16 | Context::~Context() 17 | { 18 | SWSS_LOG_ENTER(); 19 | 20 | // empty 21 | } 22 | 23 | std::shared_ptr Context::getContextConfig() const 24 | { 25 | SWSS_LOG_ENTER(); 26 | 27 | return m_contextConfig; 28 | } 29 | -------------------------------------------------------------------------------- /vslib/Context.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ContextConfig.h" 4 | 5 | namespace saivs 6 | { 7 | class Context 8 | { 9 | public: 10 | 11 | Context( 12 | _In_ std::shared_ptr contextConfig); 13 | 14 | virtual ~Context(); 15 | 16 | public: 17 | 18 | std::shared_ptr getContextConfig() const; 19 | 20 | private: 21 | 22 | std::shared_ptr m_contextConfig; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /vslib/ContextConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "ContextConfig.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saivs; 6 | 7 | ContextConfig::ContextConfig( 8 | _In_ uint32_t guid, 9 | _In_ const std::string& name, 10 | _In_ const std::string& dbAsic): 11 | m_guid(guid), 12 | m_name(name), 13 | m_dbAsic(dbAsic) 14 | { 15 | SWSS_LOG_ENTER(); 16 | 17 | m_scc = std::make_shared(); 18 | } 19 | 20 | ContextConfig::~ContextConfig() 21 | { 22 | SWSS_LOG_ENTER(); 23 | 24 | // empty 25 | } 26 | 27 | void ContextConfig::insert( 28 | _In_ std::shared_ptr config) 29 | { 30 | SWSS_LOG_ENTER(); 31 | 32 | m_scc->insert(config); 33 | } 34 | -------------------------------------------------------------------------------- /vslib/ContextConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SwitchConfigContainer.h" 4 | 5 | namespace saivs 6 | { 7 | class ContextConfig 8 | { 9 | public: 10 | 11 | ContextConfig( 12 | _In_ uint32_t guid, 13 | _In_ const std::string& name, 14 | _In_ const std::string& dbAsic); 15 | 16 | virtual ~ContextConfig(); 17 | 18 | public: 19 | 20 | void insert( 21 | _In_ std::shared_ptr config); 22 | 23 | 24 | public: // TODO to private 25 | 26 | uint32_t m_guid; 27 | 28 | std::string m_name; 29 | 30 | std::string m_dbAsic; // unit tests channel 31 | 32 | std::shared_ptr m_scc; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /vslib/ContextConfigContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ContextConfig.h" 4 | 5 | #include "swss/sal.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace saivs 12 | { 13 | class ContextConfigContainer 14 | { 15 | public: 16 | 17 | ContextConfigContainer(); 18 | 19 | virtual ~ContextConfigContainer(); 20 | 21 | public: 22 | 23 | void insert( 24 | _In_ std::shared_ptr contextConfig); 25 | 26 | std::shared_ptr get( 27 | _In_ uint32_t guid); 28 | 29 | std::set> getAllContextConfigs(); 30 | 31 | public: 32 | 33 | static std::shared_ptr loadFromFile( 34 | _In_ const char* contextConfig); 35 | 36 | static std::shared_ptr getDefault(); 37 | 38 | private: 39 | 40 | std::map> m_map; 41 | 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /vslib/CorePortIndexMapContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CorePortIndexMap.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace saivs 9 | { 10 | class CorePortIndexMapContainer 11 | { 12 | public: 13 | 14 | CorePortIndexMapContainer() = default; 15 | 16 | virtual ~CorePortIndexMapContainer() = default; 17 | 18 | public: 19 | 20 | void insert( 21 | _In_ std::shared_ptr corePortIndexMap); 22 | 23 | void remove( 24 | _In_ uint32_t switchIndex); 25 | 26 | std::shared_ptr getCorePortIndexMap( 27 | _In_ uint32_t switchIndex) const; 28 | 29 | void clear(); 30 | 31 | bool hasCorePortIndexMap( 32 | _In_ uint32_t switchIndex) const; 33 | 34 | size_t size() const; 35 | 36 | void removeEmptyCorePortIndexMaps(); 37 | 38 | private: 39 | 40 | std::map> m_map; 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /vslib/Event.cpp: -------------------------------------------------------------------------------- 1 | #include "Event.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saivs; 6 | 7 | Event::Event( 8 | _In_ EventType eventType, 9 | _In_ std::shared_ptr payload): 10 | m_eventType(eventType), 11 | m_payload(payload) 12 | { 13 | SWSS_LOG_ENTER(); 14 | 15 | // empty 16 | } 17 | 18 | EventType Event::getType() const 19 | { 20 | SWSS_LOG_ENTER(); 21 | 22 | return m_eventType; 23 | } 24 | 25 | std::shared_ptr Event::getPayload() const 26 | { 27 | SWSS_LOG_ENTER(); 28 | 29 | return m_payload; 30 | } 31 | -------------------------------------------------------------------------------- /vslib/Event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "EventPayload.h" 4 | 5 | #include "swss/sal.h" 6 | 7 | #include 8 | 9 | namespace saivs 10 | { 11 | typedef enum _EventType 12 | { 13 | EVENT_TYPE_END_THREAD, 14 | 15 | EVENT_TYPE_NET_LINK_MSG, 16 | 17 | EVENT_TYPE_PACKET, 18 | 19 | EVENT_TYPE_NOTIFICATION, 20 | 21 | } EventType; 22 | 23 | class Event 24 | { 25 | public: 26 | 27 | Event( 28 | _In_ EventType eventType, 29 | _In_ std::shared_ptr payload); 30 | 31 | virtual ~Event() = default; 32 | 33 | public: 34 | 35 | EventType getType() const; 36 | 37 | std::shared_ptr getPayload() const; 38 | 39 | private: 40 | 41 | EventType m_eventType; 42 | 43 | std::shared_ptr m_payload; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /vslib/EventPayload.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace saivs 4 | { 5 | class EventPayload 6 | { 7 | public: 8 | 9 | EventPayload() = default; 10 | 11 | virtual ~EventPayload() = default; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /vslib/EventPayloadNetLinkMsg.cpp: -------------------------------------------------------------------------------- 1 | #include "EventPayloadNetLinkMsg.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saivs; 6 | 7 | EventPayloadNetLinkMsg::EventPayloadNetLinkMsg( 8 | _In_ sai_object_id_t switchId, 9 | _In_ int nlmsgType, 10 | _In_ int ifIndex, 11 | _In_ unsigned int ifFlags, 12 | _In_ const std::string& ifName): 13 | m_switchId(switchId), 14 | m_nlmsgType(nlmsgType), 15 | m_ifIndex(ifIndex), 16 | m_ifFlags(ifFlags), 17 | m_ifName(ifName) 18 | { 19 | SWSS_LOG_ENTER(); 20 | 21 | // empty 22 | } 23 | 24 | sai_object_id_t EventPayloadNetLinkMsg::getSwitchId() const 25 | { 26 | SWSS_LOG_ENTER(); 27 | 28 | return m_switchId; 29 | } 30 | 31 | int EventPayloadNetLinkMsg::getNlmsgType() const 32 | { 33 | SWSS_LOG_ENTER(); 34 | 35 | return m_nlmsgType; 36 | } 37 | 38 | int EventPayloadNetLinkMsg::getIfIndex() const 39 | { 40 | SWSS_LOG_ENTER(); 41 | 42 | return m_ifIndex; 43 | } 44 | 45 | unsigned int EventPayloadNetLinkMsg::getIfFlags() const 46 | { 47 | SWSS_LOG_ENTER(); 48 | 49 | return m_ifFlags; 50 | } 51 | 52 | const std::string& EventPayloadNetLinkMsg::getIfName() const 53 | { 54 | SWSS_LOG_ENTER(); 55 | 56 | return m_ifName; 57 | } 58 | -------------------------------------------------------------------------------- /vslib/EventPayloadNetLinkMsg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "sai.h" 5 | } 6 | 7 | #include "EventPayload.h" 8 | 9 | #include "swss/sal.h" 10 | 11 | #include 12 | 13 | namespace saivs 14 | { 15 | class EventPayloadNetLinkMsg: 16 | public EventPayload 17 | { 18 | public: 19 | 20 | EventPayloadNetLinkMsg( 21 | _In_ sai_object_id_t switchId, 22 | _In_ int nlmsgType, 23 | _In_ int ifIndex, 24 | _In_ unsigned int ifFlags, 25 | _In_ const std::string& ifName); 26 | 27 | virtual ~EventPayloadNetLinkMsg() = default; 28 | 29 | public: 30 | 31 | sai_object_id_t getSwitchId() const; 32 | 33 | int getNlmsgType() const; 34 | 35 | int getIfIndex() const; 36 | 37 | unsigned int getIfFlags() const; 38 | 39 | const std::string& getIfName() const; 40 | 41 | private: 42 | 43 | sai_object_id_t m_switchId; 44 | 45 | int m_nlmsgType; 46 | 47 | int m_ifIndex; 48 | 49 | unsigned int m_ifFlags; 50 | 51 | std::string m_ifName; 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /vslib/EventPayloadNotification.cpp: -------------------------------------------------------------------------------- 1 | #include "EventPayloadNotification.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saivs; 6 | 7 | EventPayloadNotification::EventPayloadNotification( 8 | _In_ std::shared_ptr ntf, 9 | _In_ const sai_switch_notifications_t& switchNotifications): 10 | m_ntf(ntf), 11 | m_switchNotifications(switchNotifications) 12 | { 13 | SWSS_LOG_ENTER(); 14 | 15 | // empty 16 | } 17 | 18 | std::shared_ptr EventPayloadNotification::getNotification() const 19 | { 20 | SWSS_LOG_ENTER(); 21 | 22 | return m_ntf; 23 | } 24 | 25 | const sai_switch_notifications_t& EventPayloadNotification::getSwitchNotifications() const 26 | { 27 | SWSS_LOG_ENTER(); 28 | 29 | return m_switchNotifications; 30 | } 31 | -------------------------------------------------------------------------------- /vslib/EventPayloadNotification.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C"{ 4 | #include "saimetadata.h" 5 | } 6 | 7 | #include "EventPayload.h" 8 | 9 | #include "meta/Notification.h" 10 | 11 | namespace saivs 12 | { 13 | class EventPayloadNotification: 14 | public EventPayload 15 | { 16 | public: 17 | 18 | EventPayloadNotification( 19 | _In_ std::shared_ptr ntf, 20 | _In_ const sai_switch_notifications_t& switchNotifications); 21 | 22 | virtual ~EventPayloadNotification() = default; 23 | 24 | public: 25 | 26 | std::shared_ptr getNotification() const; 27 | 28 | const sai_switch_notifications_t& getSwitchNotifications() const; 29 | 30 | private: 31 | 32 | std::shared_ptr m_ntf; 33 | 34 | sai_switch_notifications_t m_switchNotifications; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /vslib/EventPayloadPacket.cpp: -------------------------------------------------------------------------------- 1 | #include "EventPayloadPacket.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saivs; 6 | 7 | EventPayloadPacket::EventPayloadPacket( 8 | _In_ sai_object_id_t port, 9 | _In_ int ifIndex, 10 | _In_ const std::string& ifName, 11 | _In_ const Buffer& buffer): 12 | m_port(port), 13 | m_ifIndex(ifIndex), 14 | m_ifName(ifName), 15 | m_buffer(buffer) 16 | { 17 | SWSS_LOG_ENTER(); 18 | 19 | // empty 20 | } 21 | 22 | sai_object_id_t EventPayloadPacket::getPort() const 23 | { 24 | SWSS_LOG_ENTER(); 25 | 26 | return m_port; 27 | } 28 | 29 | 30 | int EventPayloadPacket::getIfIndex() const 31 | { 32 | SWSS_LOG_ENTER(); 33 | 34 | return m_ifIndex; 35 | } 36 | 37 | const std::string& EventPayloadPacket::getIfName() const 38 | { 39 | SWSS_LOG_ENTER(); 40 | 41 | return m_ifName; 42 | } 43 | 44 | const Buffer& EventPayloadPacket::getBuffer() const 45 | { 46 | SWSS_LOG_ENTER(); 47 | 48 | return m_buffer; 49 | } 50 | -------------------------------------------------------------------------------- /vslib/EventPayloadPacket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "sai.h" 5 | } 6 | 7 | #include "EventPayload.h" 8 | #include "Buffer.h" 9 | 10 | #include 11 | 12 | namespace saivs 13 | { 14 | class EventPayloadPacket: 15 | public EventPayload 16 | { 17 | public: 18 | 19 | EventPayloadPacket( 20 | _In_ sai_object_id_t port, 21 | _In_ int ifIndex, 22 | _In_ const std::string& ifName, 23 | _In_ const Buffer& buffer); 24 | 25 | virtual ~EventPayloadPacket() = default; 26 | 27 | public: 28 | 29 | sai_object_id_t getPort() const; 30 | 31 | int getIfIndex() const; 32 | 33 | const std::string& getIfName() const; 34 | 35 | const Buffer& getBuffer() const; 36 | 37 | private: 38 | 39 | sai_object_id_t m_port; 40 | 41 | int m_ifIndex; 42 | 43 | std::string m_ifName; 44 | 45 | Buffer m_buffer; 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /vslib/EventQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "EventQueue.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saivs; 6 | 7 | #define QUEUE_MUTEX std::lock_guard _lock(m_mutex); 8 | 9 | EventQueue::EventQueue( 10 | _In_ std::shared_ptr signal): 11 | m_signal(signal) 12 | { 13 | SWSS_LOG_ENTER(); 14 | 15 | if (signal == nullptr) 16 | { 17 | SWSS_LOG_THROW("signal can't be nullptr"); 18 | } 19 | } 20 | 21 | void EventQueue::enqueue( 22 | _In_ std::shared_ptr event) 23 | { 24 | SWSS_LOG_ENTER(); 25 | 26 | QUEUE_MUTEX; 27 | 28 | m_queue.push_back(event); 29 | 30 | m_signal->notifyAll(); 31 | } 32 | 33 | std::shared_ptr EventQueue::dequeue() 34 | { 35 | SWSS_LOG_ENTER(); 36 | 37 | QUEUE_MUTEX; 38 | 39 | if (m_queue.size()) 40 | { 41 | auto item = m_queue.front(); 42 | 43 | m_queue.pop_front(); 44 | 45 | return item; 46 | } 47 | 48 | return nullptr; 49 | } 50 | 51 | size_t EventQueue::size() 52 | { 53 | SWSS_LOG_ENTER(); 54 | 55 | QUEUE_MUTEX; 56 | 57 | return m_queue.size(); 58 | } 59 | -------------------------------------------------------------------------------- /vslib/EventQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Event.h" 4 | #include "Signal.h" 5 | 6 | #include 7 | #include 8 | 9 | namespace saivs 10 | { 11 | class EventQueue 12 | { 13 | public: 14 | 15 | EventQueue( 16 | _In_ std::shared_ptr signal); 17 | 18 | virtual ~EventQueue() = default; 19 | 20 | public: 21 | 22 | void enqueue( 23 | _In_ std::shared_ptr event); 24 | 25 | std::shared_ptr dequeue(); 26 | 27 | size_t size(); 28 | 29 | private: 30 | 31 | std::shared_ptr m_signal; 32 | 33 | std::mutex m_mutex; 34 | 35 | std::deque> m_queue; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /vslib/LaneMapContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "LaneMap.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace saivs 9 | { 10 | class LaneMapContainer 11 | { 12 | public: 13 | 14 | LaneMapContainer() = default; 15 | 16 | virtual ~LaneMapContainer() = default; 17 | 18 | public: 19 | 20 | bool insert( 21 | _In_ std::shared_ptr laneMap); 22 | 23 | bool remove( 24 | _In_ uint32_t switchIndex); 25 | 26 | std::shared_ptr getLaneMap( 27 | _In_ uint32_t switchIndex) const; 28 | 29 | void clear(); 30 | 31 | bool hasLaneMap( 32 | _In_ uint32_t switchIndex) const; 33 | 34 | size_t size() const; 35 | 36 | void removeEmptyLaneMaps(); 37 | 38 | private: 39 | 40 | std::map> m_map; 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /vslib/MACsecEgressFilter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MACsecFilter.h" 4 | 5 | namespace saivs 6 | { 7 | class MACsecEgressFilter: 8 | public MACsecFilter 9 | { 10 | public: 11 | 12 | MACsecEgressFilter( 13 | _In_ const std::string &macsecInterfaceName); 14 | 15 | virtual ~MACsecEgressFilter() = default; 16 | 17 | protected: 18 | 19 | virtual FilterStatus forward( 20 | _In_ const void *buffer, 21 | _In_ size_t length) override; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /vslib/MACsecFilterStateGuard.cpp: -------------------------------------------------------------------------------- 1 | #include "MACsecFilterStateGuard.h" 2 | 3 | #include 4 | 5 | using namespace saivs; 6 | 7 | MACsecFilterStateGuard::MACsecFilterStateGuard( 8 | _Inout_ MACsecFilter::MACsecFilterState &guarded_state, 9 | _In_ MACsecFilter::MACsecFilterState target_state): 10 | m_guarded_state(guarded_state) 11 | { 12 | SWSS_LOG_ENTER(); 13 | 14 | m_old_state = m_guarded_state; 15 | m_guarded_state = target_state; 16 | } 17 | 18 | MACsecFilterStateGuard::~MACsecFilterStateGuard() 19 | { 20 | SWSS_LOG_ENTER(); 21 | 22 | m_guarded_state = m_old_state; 23 | } 24 | -------------------------------------------------------------------------------- /vslib/MACsecFilterStateGuard.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MACsecFilter.h" 4 | 5 | namespace saivs 6 | { 7 | class MACsecFilterStateGuard 8 | { 9 | public: 10 | 11 | MACsecFilterStateGuard( 12 | _Inout_ MACsecFilter::MACsecFilterState &guarded_state, 13 | _In_ MACsecFilter::MACsecFilterState target_state); 14 | 15 | ~MACsecFilterStateGuard(); 16 | 17 | private: 18 | 19 | MACsecFilter::MACsecFilterState m_old_state; 20 | MACsecFilter::MACsecFilterState &m_guarded_state; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /vslib/MACsecForwarder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "HostInterfaceInfo.h" 4 | #include "TrafficForwarder.h" 5 | 6 | #include "swss/sal.h" 7 | #include "swss/selectableevent.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace saivs 14 | { 15 | class MACsecForwarder : 16 | public TrafficForwarder 17 | { 18 | public: 19 | 20 | MACsecForwarder( 21 | _In_ const std::string &macsecInterfaceName, 22 | _In_ std::shared_ptr info); 23 | 24 | virtual ~MACsecForwarder(); 25 | 26 | int get_macsecfd() const; 27 | 28 | void forward(); 29 | 30 | private: 31 | 32 | int m_macsecfd; 33 | 34 | const std::string m_macsecInterfaceName; 35 | 36 | bool m_runThread; 37 | 38 | swss::SelectableEvent m_exitEvent; 39 | 40 | std::shared_ptr m_forwardThread; 41 | 42 | std::shared_ptr m_info; 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /vslib/MACsecIngressFilter.cpp: -------------------------------------------------------------------------------- 1 | #include "MACsecIngressFilter.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | #include 6 | #include 7 | 8 | using namespace saivs; 9 | 10 | MACsecIngressFilter::MACsecIngressFilter( 11 | _In_ const std::string &macsecInterfaceName) : 12 | MACsecFilter(macsecInterfaceName) 13 | { 14 | SWSS_LOG_ENTER(); 15 | 16 | // empty intentionally 17 | } 18 | 19 | TrafficFilter::FilterStatus MACsecIngressFilter::forward( 20 | _In_ const void *buffer, 21 | _In_ size_t length) 22 | { 23 | SWSS_LOG_ENTER(); 24 | 25 | // MACsec interface will automatically forward ingress MACsec traffic 26 | // by Linux Kernel. 27 | // So this filter just need to drop all ingress MACsec traffic directly 28 | 29 | return TrafficFilter::TERMINATE; 30 | } 31 | -------------------------------------------------------------------------------- /vslib/MACsecIngressFilter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MACsecFilter.h" 4 | 5 | namespace saivs 6 | { 7 | class MACsecIngressFilter : 8 | public MACsecFilter 9 | { 10 | public: 11 | 12 | MACsecIngressFilter( 13 | _In_ const std::string &macsecInterfaceName); 14 | 15 | virtual ~MACsecIngressFilter() = default; 16 | 17 | protected: 18 | 19 | virtual FilterStatus forward( 20 | _In_ const void *buffer, 21 | _In_ size_t length) override; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /vslib/ResourceLimiter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "sai.h" 5 | } 6 | 7 | #include 8 | 9 | namespace saivs 10 | { 11 | class ResourceLimiter 12 | { 13 | public: 14 | 15 | constexpr static uint32_t DEFAULT_SWITCH_INDEX = 0; 16 | 17 | public: 18 | 19 | ResourceLimiter( 20 | _In_ uint32_t switchIndex); 21 | 22 | virtual ~ResourceLimiter() = default; 23 | 24 | public: 25 | 26 | size_t getObjectTypeLimit( 27 | _In_ sai_object_type_t objectType) const; 28 | 29 | void setObjectTypeLimit( 30 | _In_ sai_object_type_t objectType, 31 | _In_ size_t limit); 32 | 33 | void removeObjectTypeLimit( 34 | _In_ sai_object_type_t objectType); 35 | 36 | void clearLimits(); 37 | 38 | private: 39 | 40 | uint32_t m_switchIndex; 41 | 42 | std::map m_objectTypeLimits; 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /vslib/ResourceLimiterContainer.cpp: -------------------------------------------------------------------------------- 1 | #include "ResourceLimiterContainer.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saivs; 6 | 7 | void ResourceLimiterContainer::insert( 8 | _In_ uint32_t switchIndex, 9 | _In_ std::shared_ptr rl) 10 | { 11 | SWSS_LOG_ENTER(); 12 | 13 | if (rl == nullptr) 14 | { 15 | SWSS_LOG_THROW("resouorce limitter pointer can't be nullptr"); 16 | } 17 | 18 | m_container[switchIndex] = rl; 19 | } 20 | 21 | void ResourceLimiterContainer::remove( 22 | _In_ uint32_t switchIndex) 23 | { 24 | SWSS_LOG_ENTER(); 25 | 26 | auto it = m_container.find(switchIndex); 27 | 28 | if (it != m_container.end()) 29 | { 30 | m_container.erase(it); 31 | } 32 | } 33 | 34 | std::shared_ptr ResourceLimiterContainer::getResourceLimiter( 35 | _In_ uint32_t switchIndex) const 36 | { 37 | SWSS_LOG_ENTER(); 38 | 39 | auto it = m_container.find(switchIndex); 40 | 41 | if (it != m_container.end()) 42 | { 43 | return it->second; 44 | } 45 | 46 | return nullptr; 47 | } 48 | 49 | void ResourceLimiterContainer::clear() 50 | { 51 | SWSS_LOG_ENTER(); 52 | 53 | m_container.clear(); 54 | } 55 | -------------------------------------------------------------------------------- /vslib/ResourceLimiterContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ResourceLimiter.h" 4 | 5 | #include 6 | 7 | namespace saivs 8 | { 9 | class ResourceLimiterContainer 10 | { 11 | public: 12 | 13 | ResourceLimiterContainer() = default; 14 | 15 | virtual ~ResourceLimiterContainer() = default; 16 | 17 | public: 18 | 19 | void insert( 20 | _In_ uint32_t switchIndex, 21 | _In_ std::shared_ptr rl); 22 | 23 | void remove( 24 | _In_ uint32_t switchIndex); 25 | 26 | std::shared_ptr getResourceLimiter( 27 | _In_ uint32_t switchIndex) const; 28 | 29 | void clear(); 30 | 31 | private: 32 | 33 | std::map> m_container; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /vslib/SaiAttrWrap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "saimetadata.h" 5 | } 6 | 7 | #include 8 | 9 | namespace saivs 10 | { 11 | // TODO unify wrapper and add to common 12 | class SaiAttrWrap 13 | { 14 | private: 15 | 16 | SaiAttrWrap(const SaiAttrWrap&) = delete; 17 | SaiAttrWrap& operator=(const SaiAttrWrap&) = delete; 18 | 19 | public: 20 | 21 | SaiAttrWrap( 22 | _In_ sai_object_type_t object_type, 23 | _In_ const sai_attribute_t *attr); 24 | 25 | SaiAttrWrap( 26 | _In_ const std::string& attrId, 27 | _In_ const std::string& attrValue); 28 | 29 | virtual ~SaiAttrWrap(); 30 | 31 | public: 32 | 33 | const sai_attribute_t* getAttr() const; 34 | 35 | const sai_attr_metadata_t* getAttrMetadata() const; 36 | 37 | const std::string& getAttrStrValue() const; 38 | 39 | private: 40 | 41 | const sai_attr_metadata_t *m_meta; 42 | 43 | sai_attribute_t m_attr; 44 | 45 | std::string m_value; 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /vslib/SaiInternal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define MUTEX() std::lock_guard _lock(m_apimutex) 4 | -------------------------------------------------------------------------------- /vslib/SelectableFd.cpp: -------------------------------------------------------------------------------- 1 | #include "SelectableFd.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saivs; 6 | 7 | SelectableFd::SelectableFd( 8 | _In_ int fd) 9 | { 10 | SWSS_LOG_ENTER(); 11 | 12 | if (fd < 0) 13 | { 14 | SWSS_LOG_THROW("invalid file descriptor: %d", fd); 15 | } 16 | 17 | m_fd = fd; 18 | } 19 | 20 | int SelectableFd::getFd() 21 | { 22 | SWSS_LOG_ENTER(); 23 | 24 | return m_fd; 25 | } 26 | 27 | uint64_t SelectableFd::readData() 28 | { 29 | SWSS_LOG_ENTER(); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /vslib/SelectableFd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | #include "swss/selectable.h" 5 | 6 | namespace saivs 7 | { 8 | class SelectableFd: 9 | public swss::Selectable 10 | { 11 | private: 12 | 13 | SelectableFd(const SelectableFd&) = delete; 14 | SelectableFd& operator=(const SelectableFd&) = delete; 15 | 16 | public: 17 | 18 | SelectableFd( 19 | _In_ int fd); 20 | 21 | virtual ~SelectableFd() = default; 22 | 23 | int getFd() override; 24 | 25 | uint64_t readData() override; 26 | 27 | private: 28 | 29 | int m_fd; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /vslib/Signal.cpp: -------------------------------------------------------------------------------- 1 | #include "Signal.h" 2 | 3 | #include "swss/logger.h" 4 | 5 | using namespace saivs; 6 | 7 | void Signal::notifyAll() 8 | { 9 | SWSS_LOG_ENTER(); 10 | 11 | m_cv.notify_all(); 12 | } 13 | 14 | void Signal::notifyOne() 15 | { 16 | SWSS_LOG_ENTER(); 17 | 18 | m_cv.notify_one(); 19 | } 20 | 21 | void Signal::wait() 22 | { 23 | SWSS_LOG_ENTER(); 24 | 25 | std::unique_lock lock(m_mutex); 26 | 27 | m_cv.wait(lock); 28 | } 29 | -------------------------------------------------------------------------------- /vslib/Signal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace saivs 7 | { 8 | class Signal 9 | { 10 | public: 11 | 12 | Signal() = default; 13 | 14 | virtual ~Signal() = default; 15 | 16 | public: 17 | 18 | void notifyAll(); 19 | 20 | void notifyOne(); 21 | 22 | void wait(); 23 | 24 | private: 25 | 26 | std::condition_variable m_cv; 27 | 28 | std::mutex m_mutex; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /vslib/SwitchConfigContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SwitchConfig.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace saivs 10 | { 11 | class SwitchConfigContainer 12 | { 13 | public: 14 | 15 | SwitchConfigContainer() = default; 16 | 17 | virtual ~SwitchConfigContainer() = default; 18 | 19 | public: 20 | 21 | void insert( 22 | _In_ std::shared_ptr config); 23 | 24 | std::shared_ptr getConfig( 25 | _In_ uint32_t switchIndex) const; 26 | 27 | std::shared_ptr getConfig( 28 | _In_ const std::string& hardwareInfo) const; 29 | 30 | std::set> getSwitchConfigs() const; 31 | 32 | private: 33 | 34 | std::map> m_indexToConfig; 35 | 36 | std::map> m_hwinfoToConfig; 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /vslib/SwitchNvdaMBF2H536C.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SwitchStateBase.h" 4 | 5 | namespace saivs 6 | { 7 | class SwitchNvdaMBF2H536C: 8 | public SwitchStateBase 9 | { 10 | public: 11 | 12 | SwitchNvdaMBF2H536C( 13 | _In_ sai_object_id_t switch_id, 14 | _In_ std::shared_ptr manager, 15 | _In_ std::shared_ptr config); 16 | 17 | SwitchNvdaMBF2H536C( 18 | _In_ sai_object_id_t switch_id, 19 | _In_ std::shared_ptr manager, 20 | _In_ std::shared_ptr config, 21 | _In_ std::shared_ptr warmBootState); 22 | 23 | virtual ~SwitchNvdaMBF2H536C() = default; 24 | 25 | public: 26 | 27 | void processFdbEntriesForAging(); 28 | 29 | virtual sai_status_t initialize_default_objects( 30 | _In_ uint32_t attr_count, 31 | _In_ const sai_attribute_t *attr_list); 32 | 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /vslib/TrafficFilter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include 6 | 7 | namespace saivs 8 | { 9 | typedef enum _FilterPriority 10 | { 11 | MACSEC_FILTER, 12 | 13 | } FilterPriority; 14 | 15 | class TrafficFilter 16 | { 17 | public: 18 | 19 | typedef enum _FilterStatus 20 | { 21 | CONTINUE, 22 | 23 | TERMINATE, 24 | 25 | ERROR, 26 | 27 | } FilterStatus; 28 | 29 | public: 30 | 31 | TrafficFilter() = default; 32 | 33 | virtual ~TrafficFilter() = default; 34 | 35 | public: 36 | 37 | virtual FilterStatus execute( 38 | _Inout_ void *buffer, 39 | _Inout_ size_t &length) = 0; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /vslib/TrafficFilterPipes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TrafficFilter.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace saivs 10 | { 11 | class TrafficFilterPipes 12 | { 13 | public: 14 | 15 | TrafficFilterPipes() = default; 16 | 17 | virtual ~TrafficFilterPipes() = default; 18 | 19 | public: 20 | 21 | bool installFilter( 22 | _In_ int priority, 23 | _In_ std::shared_ptr filter); 24 | 25 | bool uninstallFilter( 26 | _In_ std::shared_ptr filter); 27 | 28 | TrafficFilter::FilterStatus execute( 29 | _Inout_ void *buffer, 30 | _Inout_ size_t &length); 31 | 32 | private: 33 | 34 | typedef std::map > FilterPriorityQueue; 35 | 36 | std::mutex m_mutex; 37 | 38 | FilterPriorityQueue m_filters; 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /vslib/TrafficForwarder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "swss/sal.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace saivs 9 | { 10 | static constexpr size_t ETH_FRAME_BUFFER_SIZE = 0x4000; 11 | static constexpr size_t CONTROL_MESSAGE_BUFFER_SIZE = 0x1000; 12 | 13 | class TrafficForwarder 14 | { 15 | public: 16 | 17 | virtual ~TrafficForwarder() = default; 18 | 19 | protected: 20 | 21 | TrafficForwarder() = default; 22 | 23 | public: 24 | 25 | static bool addVlanTag( 26 | _Inout_ unsigned char *buffer, 27 | _Inout_ size_t &length, 28 | _Inout_ struct msghdr &msg); 29 | 30 | virtual bool sendTo( 31 | _In_ int fd, 32 | _In_ const unsigned char *buffer, 33 | _In_ size_t length) const; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /vslib/WarmBootState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "sai.h" 5 | } 6 | 7 | #include "SwitchState.h" 8 | #include "FdbInfo.h" 9 | 10 | #include 11 | 12 | namespace saivs 13 | { 14 | class WarmBootState 15 | { 16 | public: 17 | 18 | sai_object_id_t m_switchId; 19 | 20 | std::set m_fdbInfoSet; 21 | 22 | SwitchState::ObjectHash m_objectHash; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /vslib/vpp/IpVrfInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" { 4 | #include "sai.h" 5 | } 6 | 7 | namespace saivs 8 | { 9 | class IpVrfInfo 10 | { 11 | public: 12 | 13 | IpVrfInfo( 14 | _In_ sai_object_id_t obj_id, 15 | _In_ uint32_t vrf_id, 16 | _In_ std::string &vrf_name, 17 | _In_ bool is_ipv6); 18 | 19 | virtual ~IpVrfInfo(); 20 | 21 | public: 22 | 23 | sai_object_id_t m_obj_id; 24 | 25 | uint32_t m_vrf_id; 26 | 27 | std::string m_vrf_name; 28 | 29 | bool m_is_ipv6; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /vslib/vpp/README.md: -------------------------------------------------------------------------------- 1 | This directory source code is merged here from 2 | https://github.com/sonic-net/sonic-platform-vpp/tree/main/saivpp/src and is 3 | UNCHECKED for ay bugs or completeness 4 | 5 | TODO for future is to gradually bring it back to vslib/ directory 6 | with slow refactoring to standard 7 | -------------------------------------------------------------------------------- /vslib/vpp/SwitchVppAcl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #define MAX_ACL_ATTRS 12 8 | 9 | typedef struct _acl_tbl_entries_ { 10 | uint32_t priority; 11 | 12 | sai_attribute_t attr_range; 13 | sai_object_id_t range_objid_list[2]; 14 | 15 | sai_u32_range_t range_limit[2]; 16 | sai_acl_range_type_t range_type[2]; 17 | uint32_t range_count; 18 | sai_attribute_t attrs[MAX_ACL_ATTRS]; 19 | uint32_t attrs_count; 20 | } acl_tbl_entries_t; 21 | 22 | typedef struct ordered_ace_list_ { 23 | uint32_t index; 24 | uint32_t priority; 25 | sai_object_id_t ace_oid; 26 | bool is_tunterm; 27 | } ordered_ace_list_t; 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /vslib/vpp/SwitchVppNexthop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | typedef struct nexthop_grp_member_ { 8 | sai_ip_address_t addr; 9 | sai_object_id_t rif_oid; 10 | uint32_t weight; 11 | uint32_t seq_id; 12 | uint32_t sw_if_index; 13 | } nexthop_grp_member_t; 14 | 15 | typedef struct nexthop_grp_config_ { 16 | int32_t grp_type; 17 | uint32_t nmembers; 18 | 19 | /* Must be the last variable */ 20 | nexthop_grp_member_t grp_members[0]; 21 | } nexthop_grp_config_t; 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /vslib/vpp/vppxlate/SaiAclStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | *------------------------------------------------------------------ 3 | * SaiAclStats.h 4 | * 5 | * Copyright (c) 2023 Cisco and/or its affiliates. 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at: 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *------------------------------------------------------------------ 18 | */ 19 | 20 | #ifndef _SAIACLSTATS_H_ 21 | #define _SAIACLSTATS_H_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef struct vpp_ace_stats_ { 28 | uint64_t packets; 29 | uint64_t bytes; 30 | uint32_t ace_index; 31 | } vpp_ace_stats_t; 32 | 33 | int vpp_acl_ace_stats_query(uint32_t acl_index, uint32_t ace_index, 34 | vpp_ace_stats_t *stats); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | --------------------------------------------------------------------------------