| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_STORE_STORE_IMPL_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_STORE_STORE_IMPL_H_ |
| |
| #include <cstddef> |
| #include <cstdint> |
| #include <memory> |
| #include <optional> |
| #include <ostream> |
| #include <string> |
| #include <utility> |
| #include <vector> |
| |
| #include "owner_certificate/owner_verification_cert_configuration.pb.h" |
| #include "gbmc-hal/api/app/inventory/smbios_inventory.h" |
| #include "gbmc-hal/api/system/codecs/smbios_codec.h" |
| #include "gbmc-hal/api/system/registry_configs.h" |
| #include "bus_topology.pb.h" |
| #include "absl/container/flat_hash_map.h" |
| #include "absl/functional/any_invocable.h" |
| #include "absl/log/log.h" |
| #include "absl/status/statusor.h" |
| #include "absl/strings/string_view.h" |
| #include "absl/time/time.h" |
| #include <nlohmann/json.hpp> |
| #include "tlbmc/collector/bulk_sensor_collector_base.h" |
| #include "tlbmc/collector/collector.h" |
| #include "tlbmc/collector/fru_collector.h" |
| #include "tlbmc/collector/gpio_collector.h" |
| #include "tlbmc/collector/led_collector.h" |
| #include "tlbmc/collector/metric_collector.h" |
| #include "tlbmc/collector/monitoring_change_base.h" |
| #include "tlbmc/collector/pcie_collector.h" |
| #include "tlbmc/collector/power_control_collector.h" |
| #include "tlbmc/collector/power_fault_log_collector.h" |
| #include "tlbmc/collector/sel_collector.h" |
| #include "tlbmc/collector/sensor_collector.h" |
| #include "tlbmc/collector/sensor_collector_aggregator.h" |
| #include "tlbmc/collector/thermal_collector.h" |
| #include "ad_hoc_fru_config.pb.h" |
| #include "tlbmc/configs/entity_config.h" |
| #include "power_control.pb.h" |
| #include "tlbmc/configs/proto_config_parser.h" |
| #include "topology_config.pb.h" |
| #include "tlbmc/credentials/credential_manager.h" |
| #include "tlbmc/hal/fru_scanner.h" |
| #include "tlbmc/hal/nic_veeprom/interface.h" |
| #include "veeprom.pb.h" |
| #include "tlbmc/hal/peci/peci_access_impl.h" |
| #include "tlbmc/hal/peci/peci_access_interface.h" |
| #include "tlbmc/hal/sysfs/i2c.h" |
| #include "tlbmc/hal/sysfs/i3c.h" |
| #include "tlbmc/hal/sysfs/iio.h" |
| #include "tlbmc/hal/sysfs/led.h" |
| #include "tlbmc/hal/sysfs/peci.h" |
| #include "tlbmc/hal/system_registry.h" |
| #include "tlbmc/host_state/power_control.h" |
| #include "fru.pb.h" |
| #include "power_fault_log_entry.pb.h" |
| #include "resource.pb.h" |
| #include "sensor.pb.h" |
| #include "software_metrics.pb.h" |
| #include "tlbmc/scheduler/scheduler.h" |
| #include "tlbmc/sensors/sensor.h" |
| #include "tlbmc/store/factory.h" |
| #include "tlbmc/store/store.h" |
| #include "tlbmc/thermal/controller/dff_controller.h" |
| #include "tlbmc/thermal/controller/eat_controller.h" |
| #include "tlbmc/thermal/controller/fan_pid_controller.h" |
| #include "tlbmc/thermal/controller/pid_controller.h" |
| #include "tlbmc/thermal/controller/stepwise_controller.h" |
| #include "tlbmc/thermal/zone_manager.h" |
| #include "tlbmc/true_hitless_metrics.pb.h" |
| #include "router_interface.h" |
| |
| namespace milotic_tlbmc { |
| |
| // Houses all the collectors. |
| // Extend this struct to add support for new collectors. |
| struct AllCollectors { |
| std::unique_ptr<SensorCollectorAggregator> sensor_collector_aggregator = |
| nullptr; |
| std::unique_ptr<FruCollector> fru_collector = nullptr; |
| std::unique_ptr<MetricCollector> metric_collector = nullptr; |
| std::unique_ptr<GpioCollector> gpio_collector = nullptr; |
| std::unique_ptr<PowerControlCollector> power_control_collector = nullptr; |
| std::unique_ptr<LedCollector> led_collector = nullptr; |
| std::unique_ptr<SensorCollector> sensor_collector = nullptr; |
| std::unique_ptr<ThermalCollector> thermal_collector = nullptr; |
| std::unique_ptr<PowerFaultLogCollector> power_fault_log_collector = nullptr; |
| std::unique_ptr<SelCollector> sel_collector = nullptr; |
| std::unique_ptr<PcieCollector> pcie_collector = nullptr; |
| std::shared_ptr<BulkSensorCollectorBase> bulk_sensor_collector = nullptr; |
| }; |
| |
| // Implementation of the Store interface. |
| // The store creates and owns all the telemetry collectors and is responsible |
| // for facilitating access to the data collected by the collectors. |
| // |
| // This class is thread-safe. |
| class StoreImpl : public Store { |
| public: |
| struct Options { |
| absl::flat_hash_map<AdHocScannerType, std::unique_ptr<FruScanner>> |
| fru_scanners; |
| absl::flat_hash_map< |
| uhmm::BmcMonitoredComponentsResponse::MonitoredComponent::ProbePath, |
| std::unique_ptr<FruScanner>> |
| deterministic_fru_scanners; |
| std::unique_ptr<IioSysfs> iio_sysfs = nullptr; |
| std::unique_ptr<I2cSysfs> i2c_sysfs = nullptr; |
| std::unique_ptr<I3cSysfs> i3c_sysfs = nullptr; |
| std::unique_ptr<LedSysfs> led_sysfs = nullptr; |
| std::unique_ptr<PeciSysfs> peci_sysfs = nullptr; |
| std::unique_ptr<PeciAccessInterface> peci_access = |
| std::make_unique<PeciAccessImpl>(); |
| std::string config_location = "/etc/tlbmc"; |
| std::unique_ptr<EntityConfigReader> entity_config_reader = |
| std::make_unique<EntityConfigReaderImpl>(); |
| std::unique_ptr<CollectorFactory> collector_factory = |
| std::make_unique<CollectorFactoryImpl>(); |
| std::optional<int> override_sensor_sampling_interval_ms = std::nullopt; |
| std::optional<int> override_store_snapshot_interval_ms = std::nullopt; |
| std::unique_ptr<ProtoConfigParser> proto_parser = nullptr; |
| absl::flat_hash_map<std::string, absl::StatusOr<std::string>> |
| executor_command_map; |
| std::shared_ptr<SystemRegistry> system_registry = nullptr; |
| |
| std::string root_path; |
| std::string cached_fru_table_path; |
| |
| // SMBIOS inventory binary file paths |
| std::string smbios_single_host_file_path = "/var/lib/smbios/smbios2"; |
| std::string smbios_multihost_host_file_path_prefix = |
| "/var/lib/smbios/smbios-remote-host-"; |
| |
| // SMBIOS status latch file paths |
| std::string smbios_single_host_status_file_path = "/run/smbios-mdr/status"; |
| std::string smbios_multihost_host_status_file_path_prefix = |
| "/run/smbios-mdr/status-host-"; |
| |
| std::shared_ptr<platforms::gbmc::hal::SmbiosInventory> smbios_inventory = |
| nullptr; |
| std::shared_ptr<platforms::gbmc::hal::SmbiosCodec> smbios_codec = nullptr; |
| std::vector<uhmm::BmcMonitoredComponentsResponse::MonitoredComponent> |
| expected_smbios_components; |
| |
| std::string private_key_path; |
| std::string cert_path; |
| // The ramfs path is where we store the cert used for the duration of bmc |
| // boot |
| std::string owner_verification_cert_path = |
| "/var/volatile/owner-verification/cert.pem"; |
| |
| std::string owner_verification_config_path = |
| "/var/volatile/owner-verification/config.textproto"; |
| |
| std::string bmc_ssh_trusted_user_ca_keys_path = |
| "/run/ssh/trusted_ca_pubkeys"; |
| |
| std::string trust_bundle_path; |
| |
| std::string trust_bundle_signature_path; |
| |
| std::string os_verification_cert_path = "/var/google/os-keys/cert.pem"; |
| |
| std::string os_verification_key_path = "/var/google/os-keys/key.pem"; |
| |
| std::string serial_console_trusted_user_ca_keys_path = |
| "/var/google/ssh/trusted_user_ca_keys.pub"; |
| |
| std::string serial_console_detatched_signature_path; |
| |
| std::string syslog_client_conf_override_path = |
| "/var/google/production_syslog/client-override.conf"; |
| std::string syslog_root_cert_path = |
| "/var/google/production_syslog/root_cert.pem"; |
| |
| std::string offline_node_entities_path = |
| "/var/google/googlemachineidentity/live/offline_node_entities.pb"; |
| |
| // If true, enable deterministic BMC. |
| bool enable_deterministic_bmc = false; |
| bool enable_deterministic_periodic_fru_scanning = true; |
| int periodic_deterministic_fru_scan_interval_ms = 30 * 1000; // 30 seconds |
| |
| // Enable HFT test sensor injection for integration testing. |
| bool enable_hft_test_sensor = false; |
| |
| // Unit test only. |
| bool tlbmc_unit_test_enable_fake_gpio_collector = false; |
| |
| std::unique_ptr<GpioCollector> gpio_collector = nullptr; |
| std::unique_ptr<LedCollector> led_collector = nullptr; |
| |
| absl::AnyInvocable<std::unique_ptr<nic_veeprom::Accessor>( |
| nic_veeprom::NicTelemetryVersion version, int bus, int address) const> |
| nic_accessor_factory; |
| |
| std::shared_ptr<CredentialManager> credential_manager = nullptr; |
| }; |
| |
| static absl::StatusOr<std::unique_ptr<StoreImpl>> Create(Options&& options); |
| |
| ~StoreImpl() override; |
| |
| // StoreImpl is neither copyable nor movable. |
| StoreImpl(const StoreImpl&) = delete; |
| StoreImpl& operator=(const StoreImpl&) = delete; |
| StoreImpl(StoreImpl&&) = delete; |
| StoreImpl& operator=(StoreImpl&&) = delete; |
| |
| absl::Status ConfigureDeterministicCollection( |
| const Collector::Config& config) const override; |
| |
| // Creates a MonitoringChangeBase, a transaction-like object, which is used to |
| // apply sampling interval and batch size changes. |
| std::unique_ptr<MonitoringChangeBase> CreateMonitoringChange() override; |
| |
| SoftwareMetricsValue GetMetricValues() const override; |
| |
| SocketStatStates GetMetricSocketStatValues() const override; |
| |
| NetFilterStates GetMetricNetFilterValues() const override; |
| |
| std::string GetBmcUuid() const override; |
| |
| std::string GetBmcFirmwareVersion() const override; |
| |
| std::string GetBmcFirmwareVersionId() const override; |
| |
| absl::Status SetGpio(absl::string_view gpio_name, bool value) override; |
| |
| absl::Status SetGpioActive(absl::string_view gpio_name) override; |
| |
| absl::Status SetGpioActiveForDuration(absl::string_view gpio_name, |
| absl::Duration duration) override; |
| absl::Status SendSystemResetRequest(absl::string_view system_id, |
| ResetType reset_type, |
| absl::Duration delay) override; |
| |
| absl::StatusOr<std::vector<ResetType>> GetSupportedCustomChassisResetTypes( |
| absl::string_view chassis_id) const override; |
| |
| absl::StatusOr<bool> SupportsCustomChassisReset( |
| absl::string_view chassis_id) const override; |
| |
| absl::Status ExecuteCustomChassisReset(absl::string_view chassis_id, |
| ResetType reset_type) override; |
| |
| absl::StatusOr<bool> GetGpio(absl::string_view gpio_name) override; |
| |
| bool IsDeterministicBmcEnabled() const override { |
| return options_.enable_deterministic_bmc; |
| } |
| |
| bool IsDeterministicPeriodicFruScanningEnabled() const override { |
| return options_.enable_deterministic_periodic_fru_scanning; |
| } |
| |
| PowerControlCollector* GetPowerControlCollector() const override; |
| |
| // Returns the fru collector as raw pointer. |
| FruCollector* GetFruCollector() const override; |
| GpioCollector* GetGpioCollector() const override; |
| LedCollector* GetLedCollector() const override; |
| PcieCollector* GetPcieCollector() const override; |
| |
| absl::StatusOr<PsiMetrics> GetPsiMetrics() const override; |
| |
| absl::StatusOr<std::vector<std::string>> GetAvailableServices() |
| const override; |
| |
| absl::StatusOr<PsiMetrics> GetPsiMetricsForService( |
| const std::string& service_name) const override; |
| |
| // Starts the sensor collector's collection. |
| void StartSensorCollection() const; |
| |
| // Starts the thermal collector's collection if it is not null. |
| void StartThermalCollection() const; |
| |
| // Enable/Disable fan manual mode for all thermal zones. |
| void SetManualMode(bool enable_manual_mode) override; |
| |
| // Returns the list of sensor names contained by the given config key. |
| std::vector<std::string> GetAllSensorKeysByConfigKey( |
| const std::string& board_config_key) const override; |
| // Returns all the sensors. |
| std::vector<std::shared_ptr<const Sensor>> GetAllSensors() const override; |
| // Returns sensor keys of all shared memory based sensors |
| std::vector<std::string> GetAllSharedMemorySensorKeys() const override; |
| // Returns the sensor for the given sensor key. |
| std::shared_ptr<const Sensor> GetSensorBySensorKey( |
| const std::string& sensor_key) const override; |
| // Returns the sensor for the given board config key and given sensor |
| // key. |
| std::shared_ptr<const Sensor> GetSensorByConfigKeyAndSensorKey( |
| const std::string& board_config_key, |
| const std::string& sensor_key) const override; |
| |
| absl::Status WriteToSensor(const std::string& sensor_key, |
| const SensorValue& value) override; |
| |
| // Returns the sensor devpath for the given sensor key. |
| absl::StatusOr<const std::string&> GetDevpathFromSensor( |
| std::shared_ptr<const Sensor> sensor) const override; |
| |
| absl::StatusOr<const Fru*> GetFru(absl::string_view key) const override; |
| |
| absl::StatusOr<const TopologyConfigNode*> GetFruTopology( |
| absl::string_view config_key) const override; |
| |
| absl::StatusOr<const TopologyConfig*> GetTopologyConfig() const override; |
| |
| absl::StatusOr<std::vector<std::string>> GetAllConfigKeys() const override; |
| |
| absl::StatusOr<std::string> GetConfigKeyByFruKey( |
| absl::string_view fru_key) const override; |
| |
| absl::StatusOr<std::string> GetFruKeyByConfigKey( |
| absl::string_view config_key) const override; |
| |
| absl::StatusOr<std::vector<std::pair<std::string, std::string>>> |
| GetFanInfoByConfigKey(absl::string_view config_name) const override; |
| |
| absl::StatusOr<const FruTable*> GetAllFrus() const override; |
| |
| bool IsConfigKeyOwningAllSensors(absl::string_view config_key) const override; |
| |
| nlohmann::json ToJson() const override; |
| |
| std::string ToString() const override { return ToJson().dump(); } |
| |
| void SetSmartRouter(::crow::RouterInterface* smart_router) override; |
| |
| nlohmann::json GetSchedulerStats() const override; |
| |
| Metrics GetMetrics() const override; |
| |
| TrueHitlessMetrics GetTrueHitlessMetrics() const override; |
| |
| absl::StatusOr<std::vector<const thermal::ZoneManager*>> GetAllThermalZones() |
| const override; |
| |
| absl::StatusOr<std::vector<const thermal::PidController*>> |
| GetAllPidControllers() const override; |
| |
| absl::StatusOr<std::vector<const thermal::StepwiseController*>> |
| GetAllStepwiseControllers() const override; |
| |
| absl::StatusOr<std::vector<const thermal::FanPidController*>> |
| GetAllFanPidControllers() const override; |
| |
| absl::StatusOr<std::vector<const thermal::DffController*>> |
| GetAllDffControllers() const override; |
| |
| absl::StatusOr<std::vector<const thermal::EatController*>> |
| GetAllEatControllers() const override; |
| |
| const Options& GetOptions() const { return options_; } |
| |
| absl::StatusOr<std::string> GenerateCsr( |
| const CredentialManager::CsrParams& csr_params) const override; |
| |
| absl::Status InstallServerCert(const std::string& certificate) const override; |
| |
| absl::Status InstallTrustBundle(const std::string& trust_bundle, |
| const std::string& signature) const override; |
| |
| absl::Status InstallOsVerificationCertificate( |
| const std::string& cert_string) const override; |
| |
| absl::Status InstallSerialConsoleTrustedUserCAKeys( |
| const std::string& trusted_user_ca_keys, |
| const std::string& signature) const override; |
| |
| absl::Status InstallSyslogCert(const std::string& cert_string, |
| const std::string& target_ip, |
| int64_t target_port, SyslogProtocol protocol, |
| SyslogTlsMode tls_mode) const override; |
| |
| bool IsFirmwareUpdateable() const override; |
| |
| absl::StatusOr<std::optional<std::string>> GetOwnerVerificationCert() |
| const override; |
| absl::StatusOr< |
| std::optional<owner_certificate::OwnerVerificationCertConfiguration>> |
| GetOwnerVerificationCertConfiguration() const override; |
| absl::StatusOr<std::optional<std::string>> |
| GetBmcSshTrustedUserCAKeysSignature() const override; |
| absl::StatusOr<std::optional<std::string>> GetTrustBundle() const override; |
| absl::StatusOr<std::optional<std::string>> GetTrustBundleSignature() |
| const override; |
| absl::StatusOr<std::optional<std::string>> GetServerCert() const override; |
| absl::StatusOr<std::optional<std::string>> GetOsVerificationCert() |
| const override; |
| absl::StatusOr<std::optional<std::string>> GetSerialConsoleTrustedUserCAKeys() |
| const override; |
| absl::StatusOr<std::optional<std::string>> |
| GetSerialConsoleDetatchedSignature() const override; |
| absl::StatusOr<std::optional<SyslogTargetConfig>> GetSyslogClientConf() |
| const override; |
| absl::StatusOr<std::optional<std::string>> GetSyslogRootCert() const override; |
| std::shared_ptr<CredentialManager> GetCredentialManager() const override { |
| return credential_manager_; |
| } |
| |
| absl::Time GetCurrentTime() const override; |
| |
| absl::Time GetLastResetTime() const override; |
| |
| absl::StatusOr<std::string> GetHotswapGpioName() override; |
| |
| PowerFaultLogEntries GetPowerFaultLogEntries() const override; |
| |
| absl::StatusOr<std::string> GetPowerFaultLogFileContent( |
| absl::string_view folder_name, |
| absl::string_view file_name) const override; |
| |
| // PID controller setters. |
| absl::Status SetPidControllerCoefficients( |
| absl::string_view controller_id, |
| const thermal::PidController::PidControllerCoefficients& coefficients, |
| absl::Duration timeout) override; |
| // Fan PID controller setters. |
| absl::Status SetFanPidControllerCoefficients( |
| absl::string_view controller_id, |
| const thermal::FanPidController::FanPidControllerCoefficients& |
| coefficients, |
| absl::Duration timeout) override; |
| |
| std::vector<nlohmann::json> GetSelEntriesForward( |
| uint64_t start_id, size_t max_count) const override; |
| |
| std::vector<nlohmann::json> GetSelEntriesBackward( |
| uint64_t start_id, size_t max_count) const override; |
| |
| std::vector<nlohmann::json> GetLatestSelEntries( |
| size_t max_count) const override; |
| |
| void DumpSelEntriesRaw(uint64_t start_id, std::ostream& os) const override; |
| |
| protected: |
| StoreImpl() = default; |
| std::shared_ptr<CredentialManager> credential_manager_; |
| |
| private: |
| explicit StoreImpl(Options&& options, AllCollectors all_collectors, |
| std::shared_ptr<EntityConfig> entity_config, |
| absl::Duration store_snapshot_interval, |
| std::shared_ptr<CredentialManager> credential_manager, |
| Metrics metrics_at_bootup, |
| std::shared_ptr<SystemRegistry> system_registry); |
| |
| void InitializeSensorDevpaths() const; |
| |
| Options options_; |
| |
| // StoreImpl owns all telemetry collectors. |
| // Collectors are thread-safe. |
| AllCollectors all_collectors_; |
| |
| std::shared_ptr<EntityConfig> entity_config_; |
| |
| // Scheduler for store level tasks. |
| // Note: Each collector has its own scheduler. |
| std::unique_ptr<TaskScheduler> task_scheduler_; |
| |
| // System registry access for the store. |
| std::shared_ptr<SystemRegistry> system_registry_; |
| |
| // Metrics for the store. |
| // Note: Const for now, will consider making it mutable if we need to update |
| // metrics during runtime. |
| const Metrics metrics_; |
| }; |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_STORE_STORE_IMPL_H_ |