LCOV - code coverage report
Current view: top level - legacy/ascend910/platform/ping_mesh - ping_mesh.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 5 5
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 7 7

            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 PING_MESH_PUB_H
      12              : #define PING_MESH_PUB_H
      13              : 
      14              : #include <map>
      15              : #include <thread>
      16              : #include <atomic>
      17              : #include "hccl_ip_address.h"
      18              : #include "hccl_socket.h"
      19              : #include "hdc_pub.h"
      20              : #include "network/hccp_common.h"
      21              : #include "network/hccp_ping.h"
      22              : #include "hccn_rping.h"
      23              : #include "orion_adapter_hccp.h"
      24              : #include "dispatcher_task_types.h"
      25              : #include "universal_concurrent_map.h"
      26              : 
      27              : namespace hccl {
      28              : constexpr u32 ONE_MILLISEC = 1000;
      29              : constexpr u32 RPING_INTERFACE_OPCODE = 71;
      30              : constexpr u32 RPING_INTERFACE_VERSION = 1;
      31              : constexpr u32 RPING_PAYLOAD_LEN_MAX = 1500;
      32              : constexpr u64 TSD_EXT_PARA_NUM = 2;
      33              : constexpr u32 RPING_SERVICE_LEVEL_DEFAULT = 4;
      34              : constexpr u32 RPING_TRAFFIC_CLASS_DEFAULT = 132;
      35              : 
      36              : // 判断类型相关函数
      37              : bool IsSupportHCCLV2(const char* socNamePtr);
      38              : HcclResult GetAddrType(u32* addrtype);
      39              : // HCCN接口需要的结构体
      40              : struct RpingInput {
      41              :     HcclIpAddress sip;
      42              :     HcclIpAddress dip;
      43              :     int srcPort;  // UDP源端口号,用户配置,参与hash选路
      44              :     int reserved; // 保留字段,用于对齐,暂不使用
      45              :     int sl;       // 指定队列
      46              :     int tc;       // 主要是修改DSCP
      47              :     int port;     // 监听端口
      48              :     u32 len;
      49              :     u32 addrType; /* address type, 0: ip, 1: eid */ // todo: 是否要添加需要确定
      50              :     char payload[RPING_PAYLOAD_LEN_MAX];
      51              : };
      52              : 
      53          100 : MAKE_ENUM(HrtNetworkMode, PEER, HDC)
      54              : 
      55              : struct HRaInfo {
      56              :     HrtNetworkMode mode;
      57              :     uint32_t phyId;
      58            2 :     HRaInfo(HrtNetworkMode mode, uint32_t phyId) : mode(mode), phyId(phyId) {}
      59              : };
      60              : 
      61              : struct RpingOutput {
      62              :     u32 txPkt; // rping发包总数
      63              :     u32 rxPkt; // rping收包总数
      64              :     u32 minRTT;
      65              :     u32 maxRTT;
      66              :     u32 avgRTT;
      67              :     u32 state;
      68              :     u32 reserved[2];
      69              : };
      70              : 
      71              : // 需要重填的payload头只有前136字节,后面是固定的
      72              : struct RpingPayloadHead {
      73              :     union {
      74              :         char srcIp[64];  /* local(client) ip */
      75              :         char srcEid[16]; /* local(client) eid */
      76              :     };
      77              :     union {
      78              :         char dstIp[64];  /* remote(target) ip  */
      79              :         char dstEid[16]; /* remote(target) eid */
      80              :     };
      81              :     u32 payloadLen;
      82              :     u32 resvd[3];
      83              :     u64 timestamp[8];
      84              :     u32 rpingBatchId;
      85              :     u32 addrType; /* address type, 0: ip, 1: eid */
      86              :     u8 reserved[40];
      87              : };
      88              : 
      89              : union RpingIpHead {
      90              :     struct {
      91              :         u32 versionTclassFlow; // 4bit version, 8bit tclass, 20bit flow label
      92              :         u16 payLen;            // ub报文的payload长度
      93              :         u8 nextHdr;            // 下一个头部的类型
      94              :         u8 hopLimit;           // 最大跳数
      95              :         u8 srcIp[16];          // sip的gid,128bit
      96              :         u8 dstIp[16];          // dip的gid,128bit
      97              :     } ipv6;
      98              : 
      99              :     struct {
     100              :         u8 rsvd[20];           // 前20字节为空
     101              :         u32 verIhlTosTlen;     // 4bit version, 4bit IHL, 8bit type of service, 16bit total length
     102              :         u32 IdFlagsFragOffset; // 16bit identification, 3bit flags, 13bit fragment offset
     103              :         u8 tol;                // time to live
     104              :         u8 protocol;           // 协议类型
     105              :         u16 headChecksum;
     106              :         u32 srcIp;
     107              :         u32 dstIp;
     108              :     } ipv4;
     109              : };
     110              : 
     111              : struct RpingEidHead {
     112              :     u32 version;       // 32bit version
     113              :     u32 type;          // 32bit type
     114              :     u32 ser_version;   // 32bit serversion
     115              :     u32 padding1;      // 32bitpadding
     116              :     u8 info_size1;     // 8bit的info_size
     117              :     u8 srcEid[16];     // sip的Eid,128bit
     118              :     u32 uasid1;        // 32bit的uasid
     119              :     u32 jetty_id1;     // 32bit的jetty_id值
     120              :     u32 padding2;      // 32bit的padding
     121              :     u8 resvd[7];       // 56bit的reserved
     122              :     u32 s_token_value; // 32bit的s_token_value
     123              :     u32 dst_version;   // 32bit的dst_version
     124              :     u32 padding3;      // 32bit的padding
     125              :     u8 info_size2;     // 4bit的info_size
     126              :     u8 dstEid[16];     // dip的Eid,128bit
     127              :     u32 uasid2;        // 32bit的uasid2
     128              :     u32 jetty_id2;     // 32bit的jetty_id2
     129              :     u8 reserv[7];
     130              :     u32 client_jetty_token_value; // 32bit的client_jetty_token_value
     131              :     u64 times[8];
     132              :     u32 taskId;
     133              :     u8 reserved[44];
     134              : };
     135              : 
     136              : enum class RpingState { UNINIT, INITED, READY, RUN, STOP, RESERVED };
     137              : 
     138              : enum class RpingLinkState { CONNECTED, CONNECTING, DISCONNECTED, TIMEOUT, ERROR };
     139              : 
     140              : enum WhiteListStatus { WHITE_LIST_CLOSE = 0, WHITE_LIST_OPEN = 1 };
     141              : 
     142              : class PingMesh {
     143              : private:
     144              :     PingInitInfo initInfo_{};                      // 初始化信息
     145              :     void* pingHandle_ = nullptr;                   // 记录hccp侧的pingmesh句柄
     146              :     std::shared_ptr<HcclSocket> socket_ = nullptr; // 记录server端的socket信息,用于建立rdma链路
     147              :     HcclIpAddress ipAddr_;                         // 记录device的ip信息
     148              :     u8* payload_ = nullptr;                        // client侧记录的payload信息
     149              :     RpingState rpingState_ = RpingState::UNINIT;   // 记录client状态
     150              :     int rpingTargetNum_ = 0;                       // 记录client目标数量
     151              :     u32 pktNum_ = 0;                               // 记录最近一次BatchPingStart的发包数量
     152              :     std::mutex socketMapsMtx_;
     153              :     std::map<std::string, std::shared_ptr<HcclSocket>> socketMaps_; // 记录client端的socket信息
     154              :     UniversalConcurrentMap<std::string, PingQpInfo> rdmaInfoMaps_;  // 记录target的rdma或者ub信息
     155              :     std::unique_ptr<std::thread> connThread_;                       // server端等待socket建链的背景线程
     156              :     HcclNetDevCtx netCtx_ = nullptr;                                // 记录网络上下文信息
     157              :     std::shared_ptr<HDCommunicate> hdcD2H_ = nullptr;               // 从device侧获取数据的接口
     158              :     s32 deviceLogicId_ = 0;
     159              :     u32 devicePhyId_ = 0;
     160              :     bool isDeinited_ = false;
     161              :     bool isSocketClosed_ = false;
     162              :     std::atomic<bool> connThreadStop_{false}; // 侦听的子线程的结束条件
     163              :     bool isUsePayload_ = false;
     164              :     UniversalConcurrentMap<std::string, u32> payloadLenMap_; // 记录自定义payload的长度
     165              :     HccnRpingMode mode = HCCN_RPING_MODE_ROCE;               // ROCEorUB,
     166              : 
     167              :     HcclResult RpingSendInitInfo(
     168              :         u32 deviceId, u32 port, HcclIpAddress ipAddr, PingInitInfo initInfo, std::shared_ptr<HcclSocket> socket);
     169              :     HcclResult
     170              :     RpingRecvTargetInfo(void* clientNetCtx, u32 port, HcclIpAddress ipAddr, PingInitInfo& recvInfo, u32 timeout);
     171              :     HcclResult StartSocketThread(u32 deviceId, HcclIpAddress ipAddr, u32 port);
     172              :     HcclResult HccnCloseSubProc(u32 deviceId);
     173              :     HcclResult HccnRaInit(u32 deviceId);
     174              :     HcclResult HccnTargetAttrInter(
     175              :         u32 targetNumInter, RpingInput* inputInter, HccnRpingAddTargetConfig* configInter, PingTargetInfo* targetInter);
     176              :     HcclResult HccnTarRemoveAttrInter(
     177              :         u32 targetNumInter, RpingInput* inputInter, PingTargetCommInfo* targetInter,
     178              :         std::shared_ptr<HcclSocket>& socketInter);
     179              :     HcclResult RpingResultInfoInit(
     180              :         PingTargetResult* resultInfo, UniversalConcurrentMap<std::string, PingQpInfo>& rdmaInfoMaps, RpingInput* input,
     181              :         u32 targetNum);
     182              :     HcclResult HccnSupportedAndGetphyid(u32 deviceId, LinkType netMode);
     183              :     HcclResult HccnRpingOpenTsd(u32 deviceId, u32 mode, u32 port, u32 nodeNum, u32 bufferSize, u32 sl, u32 tc);
     184              : 
     185              : public:
     186              :     PingMesh();
     187              :     ~PingMesh();
     188              :     HcclResult HccnRpingInit(
     189              :         u32 deviceId, u32 mode, HcclIpAddress ipAddr, u32 port, u32 nodeNum, u32 bufferSize,
     190              :         u32 sl = RPING_SERVICE_LEVEL_DEFAULT, u32 tc = RPING_TRAFFIC_CLASS_DEFAULT);
     191              :     HcclResult HccnRpingDeinit(u32 deviceId);
     192              :     HcclResult HccnRpingAddTarget(u32 deviceId, u32 targetNum, RpingInput* input, HccnRpingAddTargetConfig* config);
     193              :     HcclResult HccnRpingRemoveTarget(u32 deviceId, u32 targetNum, RpingInput* input);
     194              :     HcclResult HccnRpingGetTarget(u32 deviceId, u32 targetNum, RpingInput* input, int* targetStat);
     195              :     HcclResult HccnRpingBatchPingStart(u32 deviceId, u32 pktNum, u32 interval, u32 timeout);
     196              :     HcclResult HccnRpingBatchPingStop(u32 deviceId);
     197              :     HcclResult HccnRpingGetResult(u32 deviceId, u32 targetNum, RpingInput* input, RpingOutput* output);
     198              :     HcclResult HccnRpingRefillPayloadHead(u8* originalHead, u32 payloadNum);
     199              :     HcclResult HccnRpingRefillUbPayloadHead(u8* originalHead, u32 payloadNum);
     200              :     HcclResult HccnRpingGetPayload(u32 deviceId, void** payload, u32* payloadLen, HccnRpingMode mode);
     201              : 
     202           14 :     inline s32 GetDeviceLogicId() { return deviceLogicId_; }
     203            1 :     inline HccnRpingMode GetMode() { return mode; }
     204            6 :     inline void init(HccnRpingInitAttr* attr) { this->mode = attr->mode; }
     205              : };
     206              : } // namespace hccl
     207              : #endif
        

Generated by: LCOV version 2.0-1