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 CONFIG_INFO_OPERATOR_H
12 : #define CONFIG_INFO_OPERATOR_H
13 :
14 : #include <string>
15 : #include "bind_relation.h"
16 : #include "common/bqs_status.h"
17 : #include "queue_schedule/dgw_client.h"
18 :
19 : namespace bqs {
20 : class ConfigInfoOperator {
21 : public:
22 : /**
23 : * default constructor
24 : */
25 99 : explicit ConfigInfoOperator(const uint32_t deviceId, const std::string groupNames = "");
26 :
27 : /**
28 : * default destructor
29 : */
30 76 : virtual ~ConfigInfoOperator() = default;
31 :
32 : /**
33 : * @brief parse config event
34 : * @param subEventId subEventId
35 : * @param queueId queue id
36 : * @return BQS_STATUS_OK: success, other: failed.
37 : */
38 : BqsStatus ParseConfigEvent(const uint32_t subEventId, const uint32_t queueId, void *mbuf,
39 : const uint16_t clientVersion);
40 :
41 : /**
42 : * process update config
43 : * @return BQS_STATUS_OK: success, other: failed.
44 : */
45 : BqsStatus ProcessUpdateConfig(const uint32_t index);
46 :
47 : /**
48 : * attach queue process and check src queue read authoriy, dst queue write authority
49 : * @param src src entity info
50 : * @param dst dst entity info
51 : * @return BQS_STATUS_OK:success, other:failed.
52 : */
53 : BqsStatus AttachAndCheckQueue(const EntityInfo& src, const EntityInfo& dst) const;
54 :
55 : private:
56 :
57 : // not allow copy constructor and assignment operators
58 : ConfigInfoOperator(const ConfigInfoOperator &) = delete;
59 :
60 : ConfigInfoOperator &operator=(const ConfigInfoOperator &) = delete;
61 :
62 : ConfigInfoOperator(ConfigInfoOperator &&) = delete;
63 :
64 : ConfigInfoOperator &operator=(ConfigInfoOperator &&) = delete;
65 :
66 : /**
67 : * process update routes
68 : * @return BQS_STATUS_OK: success, other: failed.
69 : */
70 : BqsStatus ProcessUpdateRoutes(const uint32_t index) const;
71 :
72 : /**
73 : * preprocess update config info
74 : * @param mbufData mbuf data addr
75 : * @param dataLen data len
76 : * @return BQS_STATUS_OK: success, other: failed.
77 : */
78 : BqsStatus PreprocessUpdateCfgInfo(const uintptr_t mbufData, const uint64_t dataLen);
79 :
80 : /**
81 : * check and record update config info to updateCfgInfo_
82 : * @param mbufData mbuf data
83 : * @param dataLen mbuf data len
84 : * @return BQS_STATUS_OK:success, other:failed.
85 : */
86 : BqsStatus CheckAndRecordUpdateCfgInfo(const uintptr_t mbufData, const uint64_t dataLen);
87 :
88 : /**
89 : * check and record update route info to updateCfgInfo_
90 : * @return BQS_STATUS_OK:success, other:failed.
91 : */
92 : BqsStatus CheckAndRecordRouteInfo() const;
93 :
94 : /**
95 : * check and record create group info to updateCfgInfo_
96 : * @return BQS_STATUS_OK:success, other:failed.
97 : */
98 : BqsStatus CheckAndRecordAddGrpInfo() const;
99 :
100 : /**
101 : * check and record delete group/update profiling info to updateCfgInfo_
102 : * @return BQS_STATUS_OK:success, other:failed.
103 : */
104 : BqsStatus CheckAndRecordCfgInfo() const;
105 :
106 : BqsStatus CheckAndRecordCommonCfg(const size_t resultOffset) const;
107 :
108 : BqsStatus CheckAndRecordRedeployCfg() const;
109 :
110 : /**
111 : * check flow queue auth
112 : * @return BQS_STATUS_OK:success, other:failed.
113 : */
114 : BqsStatus CheckFlowQueueAuth() const;
115 :
116 : /**
117 : * check queue auth
118 : * @param queueId queue id
119 : * @param isSrc is src queue
120 : * @return BQS_STATUS_OK:success, other:failed.
121 : */
122 : BqsStatus CheckQueueAuth(const uint32_t queueId, const uint32_t resId, const bool isSrc) const;
123 :
124 : /**
125 : * check queue auth
126 : * @param info entity info
127 : * @param isSrc is src queue
128 : * @return BQS_STATUS_OK:success, other:failed.
129 : */
130 : BqsStatus CheckQueueAuth(const EntityInfo &info, const bool isSrc) const;
131 :
132 : /**
133 : * check queue auth for group
134 : * @param groupId group id
135 : * @param isSrc is src
136 : * @return BQS_STATUS_OK:success, other:failed.
137 : */
138 : BqsStatus CheckQueueAuthForGroup(const uint32_t groupId, const bool isSrc) const;
139 :
140 : /**
141 : * attach queue
142 : * @param info entity info
143 : * @return BQS_STATUS_OK:success, other:failed
144 : */
145 : BqsStatus AttachQueue(const EntityInfo &info) const;
146 :
147 : /**
148 : * attach queue in group
149 : * @param groupId group id
150 : * @return BQS_STATUS_OK:success, other:failed
151 : */
152 : BqsStatus AttachQueueInGroup(const uint32_t groupId) const;
153 :
154 : /**
155 : * query config
156 : * @param mbufData mbuf data addr
157 : * @param dataLen mbuf data len
158 : * @return BQS_STATUS_OK:success, other:failed.
159 : */
160 : BqsStatus QueryConfig(const uintptr_t mbufData, const uint64_t dataLen) const;
161 :
162 : /**
163 : * query config number
164 : * @param mbufData mbuf data addr
165 : * @param dataLen mbuf data len
166 : * @return BQS_STATUS_OK:success, other:failed.
167 : */
168 : BqsStatus QueryConfigNum(const uintptr_t mbufData, const uint64_t dataLen) const;
169 :
170 : /**
171 : * create hcom handle
172 : * @param mbufData mbuf data addr
173 : * @param dataLen mbuf data len
174 : * @return BQS_STATUS_OK:success, other:failed.
175 : */
176 : BqsStatus CreateHcomHandle(const uintptr_t mbufData, const uint64_t dataLen);
177 :
178 : /**
179 : * destroy hcom handle
180 : * @param mbufData mbuf data addr
181 : * @param dataLen mbuf data len
182 : * @return BQS_STATUS_OK:success, other:failed.
183 : */
184 : BqsStatus DestroyHcomHandle(const uintptr_t mbufData, const uint64_t dataLen) const;
185 :
186 : /**
187 : * query group
188 : * @param mbufData mbuf data addr
189 : * @param dataLen mbuf data len
190 : * @param onlyQryNum only query num
191 : * @return BQS_STATUS_OK:success, other:failed.
192 : */
193 : BqsStatus QueryGroup(const uintptr_t mbufData, const uint64_t dataLen, const bool onlyQryNum) const;
194 :
195 : /**
196 : * query route by src
197 : * @param mbufData mbuf data addr
198 : * @param src src entity info
199 : * @param onlyQryNum only query num
200 : * @return BQS_STATUS_OK:success, other:failed.
201 : */
202 : BqsStatus QueryRoutesBySrc(const uintptr_t mbufData, const EntityInfo &src, const bool onlyQryNum) const;
203 :
204 : /**
205 : * query route by dst
206 : * @param mbufData mbuf data addr
207 : * @param dst dst entity info
208 : * @param onlyQryNum only query num
209 : * @return BQS_STATUS_OK:success, other:failed.
210 : */
211 : BqsStatus QueryRoutesByDst(const uintptr_t mbufData, const EntityInfo &dst, const bool onlyQryNum) const;
212 :
213 : /**
214 : * query route by src and dst
215 : * @param mbufData mbuf data addr
216 : * @param src src entity info
217 : * @param dst dst entity info
218 : * @param onlyQryNum only query num
219 : * @return BQS_STATUS_OK:success, other:failed.
220 : */
221 : BqsStatus QueryRoutesBySrcAndDst(const uintptr_t mbufData, const EntityInfo &src,
222 : const EntityInfo &dst, const bool onlyQryNum) const;
223 :
224 : /**
225 : * query all routes
226 : * @param mbufData mbuf data addr
227 : * @param onlyQryNum only query num
228 : * @return BQS_STATUS_OK: success, other: failed.
229 : */
230 : BqsStatus QueryAllRoutes(const uintptr_t mbufData, const bool onlyQryNum) const;
231 :
232 : /**
233 : * query route
234 : * @param mbufData mbuf data addr
235 : * @param dataLen mbuf data len
236 : * @param onlyQryNum only query num
237 : * @return BQS_STATUS_OK:success, other:failed.
238 : */
239 : BqsStatus QueryRoutes(const uintptr_t mbufData, const uint64_t dataLen, const bool onlyQryNum) const;
240 :
241 : /**
242 : * record query result
243 : * @param routeList routes list
244 : * @param mbufData mbuf data
245 : * @param onlyQryNum only query num
246 : * @return BQS_STATUS_OK: success, other: failed.
247 : */
248 : BqsStatus SaveQueryResult(std::list<std::pair<const EntityInfo *, const EntityInfo *>> &routeList,
249 : const uintptr_t mbufData, const bool onlyQryNum) const;
250 :
251 : /**
252 : * convert to route
253 : * @param src src entity info
254 : * @param dst dst entity info
255 : * @param route route
256 : * @return BQS_STATUS_OK: success, other: failed.
257 : */
258 : BqsStatus ConvertToRoute(const EntityInfo &src, const EntityInfo &dst, Route &route) const;
259 :
260 : /**
261 : * convert to endpoint
262 : * @param entity entity info
263 : * @param endpoint endpoint
264 : * @return BQS_STATUS_OK: success, other: failed.
265 : */
266 : BqsStatus ConvertToEndpoint(const EntityInfo &entity, Endpoint &endpoint) const;
267 :
268 : /**
269 : * create entity info
270 : * @param endpoint endpoint
271 : * @param isQry is query
272 : * @return entity info pointer
273 : */
274 : EntityInfoPtr CreateEntityInfo(const Endpoint &endpoint, const bool isQry) const;
275 :
276 : /**
277 : * process add group
278 : * @return BQS_STATUS_OK: success, other: failed.
279 : */
280 : BqsStatus ProcessAddGroup() const;
281 :
282 : /**
283 : * process delete group
284 : * @return BQS_STATUS_OK: success, other: failed.
285 : */
286 : BqsStatus ProcessDelGroup() const;
287 :
288 : /**
289 : * process update profiling
290 : * @return BQS_STATUS_OK: success, other: failed.
291 : */
292 : BqsStatus ProcessUpdateProfiling() const;
293 :
294 : /**
295 : * check comm channel attr
296 : * @param attr comm channel attr
297 : * @param isQry is query
298 : * @return BQS_STATUS_OK: success, other: failed.
299 : */
300 : BqsStatus CheckCommChannelAttr(const CommChannelAttr &attr, const bool isQry) const;
301 :
302 : BqsStatus QueryGroupAllocInfo();
303 :
304 : void SplitStringWithDelimeter(const std::string rawStr, const char_t delimeter,
305 : std::vector<std::string> &results) const;
306 :
307 : BqsStatus QureySelfMemGroup(std::vector<std::string> &groupNames) const;
308 :
309 : BqsStatus ProcessUpdateHcclProtocol() const;
310 :
311 : BqsStatus ProcessInitDynamicSched() const;
312 :
313 : BqsStatus ProcessStopSchedule(const uint32_t index) const;
314 :
315 : BqsStatus ProcessRestartSchedule(const uint32_t index) const;
316 :
317 : void QueryRoutesBySrcFromRelation(const EntityInfo &src, const MapEnitityInfoToInfoSet &srcToDstRelation,
318 : std::list<std::pair<const EntityInfo*, const EntityInfo*>> &routeList) const;
319 :
320 : void QueryRoutesByDstFromRelation(const EntityInfo &dst, const MapEnitityInfoToInfoSet &dstToSrcRelation,
321 : std::list<std::pair<const EntityInfo*, const EntityInfo*>> &routeList) const;
322 :
323 : uint32_t ParseDeviceId(const uint32_t rawDeviceId) const;
324 :
325 : BqsStatus SubscribeQueueEvent(const bool isLocalQ, const uint32_t queueId, const uint32_t deviceId,
326 : const uint32_t resIndex, const bool isEnqueue) const;
327 :
328 : bool IsSvmShareGrp(const std::string &grpName) const;
329 :
330 : // define struct for store update config info
331 : struct UpdateCfgInfo {
332 : // mbuf data addr for config
333 : uintptr_t mbufData;
334 : // mbuf data len
335 : uint64_t dataLen;
336 : // config info
337 : ConfigInfo *cfgInfo;
338 : // routes
339 : std::vector<Route *> routes;
340 : // endpoints in group
341 : std::vector<Endpoint *> endpointsInGroup;
342 : // results
343 : std::vector<CfgRetInfo *> results;
344 : // entities in routes: after transform
345 : std::vector<std::pair<EntityInfoPtr, EntityInfoPtr>> entitiesInRoutes;
346 : // entities in group: after tranform
347 : std::vector<EntityInfoPtr> entitiesInGroup;
348 : };
349 :
350 : // device id
351 : uint32_t deviceId_ = 0U;
352 : // record update config info
353 : std::unique_ptr<UpdateCfgInfo> updateCfgInfo_ = nullptr;
354 : std::string groupNames_ = "";
355 : std::vector<GrpQueryGroupAddrInfo> grpAllocInfos_;
356 : uint16_t clientVersion_;
357 : };
358 : } // namespace bqs
359 : #endif // CONFIG_INFO_OPERATOR_H
|