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 EDGE_INFO_H
12 : #define EDGE_INFO_H
13 :
14 : #include <string>
15 : #include <unordered_map>
16 : #include <set>
17 : #include "nlohmann/json.hpp"
18 : #include "types.h"
19 : #include "topo_common_types.h"
20 : #include "ip_address.h"
21 :
22 : namespace Hccl {
23 :
24 : constexpr u32 PORT_MAX_LENGTH = 32;
25 : constexpr u32 MAX_PORTS_SIZE = 64;
26 : constexpr u32 LEGACY_BINARY_LAYER = 0;
27 :
28 : class EdgeInfo {
29 : public:
30 240 : EdgeInfo() {};
31 : EdgeInfo(BinaryStream& binaryStream);
32 1185 : ~EdgeInfo() {};
33 :
34 : LinkType linkType;
35 : TopoType topoType{TopoType::CLOS};
36 : u32 topoInstId{0};
37 : std::set<LinkProtocol> protocols;
38 :
39 : u32 localA{0};
40 : std::set<std::string> localAPorts;
41 : u32 localB{0};
42 : std::set<std::string> localBPorts;
43 : AddrPosition position;
44 :
45 : bool operator==(const EdgeInfo& other) const;
46 : void Deserialize(const nlohmann::json& edgeInfoJson);
47 : LinkProtocol GetLinkProtocol(std::string str) const;
48 : TopoType GetTopoType(std::string topoTypeStr) const;
49 : LinkType GetLinkType(std::string linkTypeStr) const;
50 : AddrPosition GetAddrPosition(std::string str) const;
51 : std::string Describe() const;
52 : void GetBinStream(BinaryStream& binaryStream) const;
53 :
54 : private:
55 : const static std::unordered_map<std::string, LinkProtocol> strToLinkProtocol;
56 : const static std::unordered_map<std::string, TopoType> strToTopoType;
57 : const static std::unordered_map<std::string, LinkType> strToLinkType;
58 : const static std::unordered_map<std::string, AddrPosition> strToAddrPosition;
59 : bool CompareEndpoints(const EdgeInfo& other) const;
60 : void DeserializeProtocol(const nlohmann::json& edgeInfoJson);
61 : void DeserializeEndpoint(const nlohmann::json& edgeInfoJson);
62 : void DeserializePort(const nlohmann::json& edgeInfoJson, std::string propName, std::set<std::string>& ports);
63 : std::string DescribePorts(std::set<std::string> ports) const;
64 : };
65 : } // namespace Hccl
66 :
67 : #endif // EDGE_INFO_H
|