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_SERVICE_H
12 : #define HCCLV2_RANK_INFO_DETECT_SERVICE_H
13 :
14 : #include "socket.h"
15 : #include <unordered_map>
16 : #include "new_rank_info.h"
17 : #include "rank_table_info.h"
18 : #include "json_parser.h"
19 : #include "internal_exception.h"
20 : #include "timeout_exception.h"
21 : #include "socket_exception.h"
22 : #include "socket_agent.h"
23 :
24 : namespace Hccl {
25 :
26 : class RankInfoDetectService {
27 : public:
28 30 : RankInfoDetectService(u32 devPhyId, std::shared_ptr<Socket> serverSocket,
29 : std::string identifier, vector<RaSocketWhitelist> wlistInfo)
30 60 : : devPhyId_(devPhyId), serverSocket_(serverSocket), hostIp_(serverSocket_->GetLocalIp()),
31 60 : identifier_(identifier), wlistInfo_(wlistInfo)
32 : {
33 30 : }
34 : ~RankInfoDetectService();
35 :
36 : void Setup();
37 :
38 : private:
39 : u32 devPhyId_{0};
40 : shared_ptr<Socket> serverSocket_{nullptr};
41 : std::unordered_map<std::string, std::shared_ptr<Socket>> connSockets_{};
42 : IpAddress hostIp_{};
43 : RankTableInfo rankTable_{};
44 : std::string failedAgentIdList_{};
45 : u32 currentStep_{0};
46 : std::string identifier_{};
47 : vector<RaSocketWhitelist> wlistInfo_{};
48 :
49 : void GetConnections();
50 : void GetRankTable();
51 : void BroadcastRankTable();
52 : void Disconnect();
53 : void TearDown();
54 :
55 : bool RecvRemoteAgentId(SocketAgent &connSocketAgent, std::string &agentId);
56 : bool RecvRemoteRankSize(SocketAgent &connSocketAgent, u32 &rankSize);
57 : void RecvRankInfoMsg(SocketAgent &connSocketAgent, vector<char> &rankInfoMsg);
58 : void SendRankTable(Socket *connSocket);
59 : void SortRankTable();
60 : void ParseRankTable(vector<char> &rankInfoMsg);
61 :
62 : // 异常流程处理方法
63 : void FailedConnectionAgentIdString(u32 rankSize);
64 :
65 : // 校验相关方法
66 : bool RecvAndVerifyRemoteAgentIdAndRankSize(
67 : std::shared_ptr<Socket> connSocket, u32 &expectedSocketNum, u32 &previousRankSize);
68 : bool VerifyRemoteRankSize(u32 &previousRankSize, u32 remoteRankSize) const;
69 :
70 : // DFX相关方法
71 : void DisplayConnectedRank(const std::map<std::string, std::shared_ptr<Socket>> &connectSockets);
72 : void DisplayConnectingStatus(u32 totalSockets, u32 waitSockets);
73 : void DisplayConnectedRanks();
74 : };
75 :
76 : } // namespace Hccl
77 : #endif // HCCLV2_RANK_INFO_DETECT_SERVICE_H
|