Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef HCCLV2_RANK_INFO_DETECT_CLIENT_H
12 : #define HCCLV2_RANK_INFO_DETECT_CLIENT_H
13 :
14 : #include <cstddef>
15 : #include <functional>
16 : #include <vector>
17 : #include "socket.h"
18 : #include "new_rank_info.h"
19 : #include "rank_table_info.h"
20 : #include "json_parser.h"
21 : #include "internal_exception.h"
22 : #include "timeout_exception.h"
23 : #include "socket_exception.h"
24 : #include "socket_agent.h"
25 : #include "root_handle_v2.h"
26 : #include "ip_address.h"
27 :
28 : namespace Hccl {
29 :
30 : #ifdef OPEN_HCCL_TEST
31 : const u32 WAIT_ERROR_BROADCAST_TIME = 1;
32 : #else
33 : const u32 WAIT_ERROR_BROADCAST_TIME = 20;
34 : #endif
35 :
36 : class RankInfoDetectClient {
37 : public:
38 60 : RankInfoDetectClient(u32 devPhyId, u32 rankSize, u32 rankId, const std::shared_ptr<Socket>& clientSocket)
39 60 : : devPhyId_(devPhyId),
40 60 : rankSize_(rankSize),
41 60 : rankId_(rankId),
42 60 : clientSocket_(clientSocket),
43 60 : socketAgent_(clientSocket.get())
44 60 : {}
45 : ~RankInfoDetectClient();
46 :
47 : void Setup(RankTableInfo& rankTable);
48 :
49 : private:
50 : u32 devPhyId_{0};
51 : u32 rankSize_{0};
52 : u32 rankId_{0};
53 : std::shared_ptr<Socket> clientSocket_{nullptr};
54 : u32 currentStep_{0};
55 : RankTableInfo rankTable_{};
56 : SocketAgent socketAgent_;
57 : std::mutex hostSocketLock_;
58 : std::shared_ptr<Socket> hostSocket_ = nullptr;
59 : bool hostSocketRegistered_ = false; // 标记 hostSocket_ 是否已登记到 SocketManager::GetServerSocketMap()
60 :
61 : void SetupHostListenPort(u32 devLogicId, u32 devPhyId, const IpAddress& hostIp, uint32_t& hostPort);
62 : void SocketTearDown(u32 devPhyId);
63 : void Connect();
64 : void CheckStatus();
65 : void SendAgentIdAndRankSize();
66 : void SendLocalRankTable(const RankTableInfo& localRankTable);
67 : void ConstructRankTable(RankTableInfo& localRankTable);
68 : void VerifyRankTable();
69 : void RecvRankTable();
70 : void RecvRankTableMsg(vector<char>& rankInfoMsg);
71 : void ParseRankTable(vector<char>& rankInfoMsg);
72 : void GetLocalRankTableJson(const nlohmann::json& parseJson, nlohmann::json& localRankTableJson);
73 : void GetLocalDevInfoJson(const nlohmann::json& parseJson, nlohmann::json& localDevInfoJson);
74 : void SelectLocalHostBackupAddr(nlohmann::json& localDevInfoJson);
75 : void SelectAvailableHostAddr(nlohmann::json& addrJson);
76 : void UpdateSelectedHostAddr(
77 : nlohmann::json& addrJson, const std::vector<IpAddress>& candidates, std::size_t selectedIndex) const;
78 : void ProbeHostRoceAddr(const IpAddress& hostAddr, bool& isAvailable) const;
79 : void ConstructSingleRank(RankTableInfo& localRankTable);
80 : HcclResult GetLocalTlsStatus(TlsStatus& tlsStatus) const;
81 : HcclResult GetLocalHostDpuTlsStatus(TlsStatus& tlsStatus) const;
82 : HcclResult VerifyTlsConsistency() const;
83 : HcclResult VerifyHostDpuTlsConsistency() const;
84 : HcclResult VerifyTlsConsistencyByTlsType(
85 : const std::string& tlsType, const std::function<TlsStatus(const NewRankInfo&)>& getTlsStatus) const;
86 : void GenerateTlsStatusStr(std::string& tlsStatusStr, const std::vector<u32>& tlsStatusRanks) const;
87 : void ReportTlsConfigurationError(
88 : const std::string& tlsType, const std::string& tlsInconsistentTlsType, const std::string& tlsEnableRankStr,
89 : const std::string& tlsDisableRankStr, const std::string& tlsUnknownRankStr) const;
90 : void TearDown();
91 : void HostListenPortDetect(NewRankInfo& rankInfo);
92 : };
93 :
94 : } // namespace Hccl
95 : #endif // HCCLV2_RANK_INFO_DETECT_CLIENT_H
|