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(
39 : const uint32_t subEventId, const uint32_t queueId, void* mbuf, 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 : // not allow copy constructor and assignment operators
57 : ConfigInfoOperator(const ConfigInfoOperator&) = delete;
58 :
59 : ConfigInfoOperator& operator=(const ConfigInfoOperator&) = delete;
60 :
61 : ConfigInfoOperator(ConfigInfoOperator&&) = delete;
62 :
63 : ConfigInfoOperator& operator=(ConfigInfoOperator&&) = delete;
64 :
65 : /**
66 : * process update routes
67 : * @return BQS_STATUS_OK: success, other: failed.
68 : */
69 : BqsStatus ProcessUpdateRoutes(const uint32_t index) const;
70 :
71 : /**
72 : * preprocess update config info
73 : * @param mbufData mbuf data addr
74 : * @param dataLen data len
75 : * @return BQS_STATUS_OK: success, other: failed.
76 : */
77 : BqsStatus PreprocessUpdateCfgInfo(const uintptr_t mbufData, const uint64_t dataLen);
78 :
79 : /**
80 : * check and record update config info to updateCfgInfo_
81 : * @param mbufData mbuf data
82 : * @param dataLen mbuf data len
83 : * @return BQS_STATUS_OK:success, other:failed.
84 : */
85 : BqsStatus CheckAndRecordUpdateCfgInfo(const uintptr_t mbufData, const uint64_t dataLen);
86 :
87 : /**
88 : * check and record update route info to updateCfgInfo_
89 : * @return BQS_STATUS_OK:success, other:failed.
90 : */
91 : BqsStatus CheckAndRecordRouteInfo() const;
92 :
93 : /**
94 : * check and record create group info to updateCfgInfo_
95 : * @return BQS_STATUS_OK:success, other:failed.
96 : */
97 : BqsStatus CheckAndRecordAddGrpInfo() const;
98 :
99 : /**
100 : * check and record delete group/update profiling info to updateCfgInfo_
101 : * @return BQS_STATUS_OK:success, other:failed.
102 : */
103 : BqsStatus CheckAndRecordCfgInfo() const;
104 :
105 : BqsStatus CheckAndRecordCommonCfg(const size_t resultOffset) const;
106 :
107 : BqsStatus CheckAndRecordRedeployCfg() const;
108 :
109 : /**
110 : * check flow queue auth
111 : * @return BQS_STATUS_OK:success, other:failed.
112 : */
113 : BqsStatus CheckFlowQueueAuth() const;
114 :
115 : /**
116 : * check queue auth
117 : * @param queueId queue id
118 : * @param isSrc is src queue
119 : * @return BQS_STATUS_OK:success, other:failed.
120 : */
121 : BqsStatus CheckQueueAuth(const uint32_t queueId, const uint32_t resId, const bool isSrc) const;
122 :
123 : /**
124 : * check queue auth
125 : * @param info entity info
126 : * @param isSrc is src queue
127 : * @return BQS_STATUS_OK:success, other:failed.
128 : */
129 : BqsStatus CheckQueueAuth(const EntityInfo& info, const bool isSrc) const;
130 :
131 : /**
132 : * check queue auth for group
133 : * @param groupId group id
134 : * @param isSrc is src
135 : * @return BQS_STATUS_OK:success, other:failed.
136 : */
137 : BqsStatus CheckQueueAuthForGroup(const uint32_t groupId, const bool isSrc) const;
138 :
139 : /**
140 : * attach queue
141 : * @param info entity info
142 : * @return BQS_STATUS_OK:success, other:failed
143 : */
144 : BqsStatus AttachQueue(const EntityInfo& info) const;
145 :
146 : /**
147 : * attach queue in group
148 : * @param groupId group id
149 : * @return BQS_STATUS_OK:success, other:failed
150 : */
151 : BqsStatus AttachQueueInGroup(const uint32_t groupId) const;
152 :
153 : /**
154 : * query config
155 : * @param mbufData mbuf data addr
156 : * @param dataLen mbuf data len
157 : * @return BQS_STATUS_OK:success, other:failed.
158 : */
159 : BqsStatus QueryConfig(const uintptr_t mbufData, const uint64_t dataLen) const;
160 :
161 : /**
162 : * query config number
163 : * @param mbufData mbuf data addr
164 : * @param dataLen mbuf data len
165 : * @return BQS_STATUS_OK:success, other:failed.
166 : */
167 : BqsStatus QueryConfigNum(const uintptr_t mbufData, const uint64_t dataLen) const;
168 :
169 : /**
170 : * create hcom handle
171 : * @param mbufData mbuf data addr
172 : * @param dataLen mbuf data len
173 : * @return BQS_STATUS_OK:success, other:failed.
174 : */
175 : BqsStatus CreateHcomHandle(const uintptr_t mbufData, const uint64_t dataLen);
176 :
177 : /**
178 : * destroy hcom handle
179 : * @param mbufData mbuf data addr
180 : * @param dataLen mbuf data len
181 : * @return BQS_STATUS_OK:success, other:failed.
182 : */
183 : BqsStatus DestroyHcomHandle(const uintptr_t mbufData, const uint64_t dataLen) const;
184 :
185 : /**
186 : * query group
187 : * @param mbufData mbuf data addr
188 : * @param dataLen mbuf data len
189 : * @param onlyQryNum only query num
190 : * @return BQS_STATUS_OK:success, other:failed.
191 : */
192 : BqsStatus QueryGroup(const uintptr_t mbufData, const uint64_t dataLen, const bool onlyQryNum) const;
193 :
194 : /**
195 : * query route by src
196 : * @param mbufData mbuf data addr
197 : * @param src src entity info
198 : * @param onlyQryNum only query num
199 : * @return BQS_STATUS_OK:success, other:failed.
200 : */
201 : BqsStatus QueryRoutesBySrc(const uintptr_t mbufData, const EntityInfo& src, const bool onlyQryNum) const;
202 :
203 : /**
204 : * query route by dst
205 : * @param mbufData mbuf data addr
206 : * @param dst dst entity info
207 : * @param onlyQryNum only query num
208 : * @return BQS_STATUS_OK:success, other:failed.
209 : */
210 : BqsStatus QueryRoutesByDst(const uintptr_t mbufData, const EntityInfo& dst, const bool onlyQryNum) const;
211 :
212 : /**
213 : * query route by src and dst
214 : * @param mbufData mbuf data addr
215 : * @param src src entity info
216 : * @param dst dst entity info
217 : * @param onlyQryNum only query num
218 : * @return BQS_STATUS_OK:success, other:failed.
219 : */
220 : BqsStatus QueryRoutesBySrcAndDst(
221 : const uintptr_t mbufData, const EntityInfo& src, const EntityInfo& dst, const bool onlyQryNum) const;
222 :
223 : /**
224 : * query all routes
225 : * @param mbufData mbuf data addr
226 : * @param onlyQryNum only query num
227 : * @return BQS_STATUS_OK: success, other: failed.
228 : */
229 : BqsStatus QueryAllRoutes(const uintptr_t mbufData, const bool onlyQryNum) const;
230 :
231 : /**
232 : * query route
233 : * @param mbufData mbuf data addr
234 : * @param dataLen mbuf data len
235 : * @param onlyQryNum only query num
236 : * @return BQS_STATUS_OK:success, other:failed.
237 : */
238 : BqsStatus QueryRoutes(const uintptr_t mbufData, const uint64_t dataLen, const bool onlyQryNum) const;
239 :
240 : /**
241 : * record query result
242 : * @param routeList routes list
243 : * @param mbufData mbuf data
244 : * @param onlyQryNum only query num
245 : * @return BQS_STATUS_OK: success, other: failed.
246 : */
247 : BqsStatus SaveQueryResult(
248 : std::list<std::pair<const EntityInfo*, const EntityInfo*>>& routeList, const uintptr_t mbufData,
249 : 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(
305 : const std::string rawStr, const char_t delimeter, 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(
318 : const EntityInfo& src, const MapEnitityInfoToInfoSet& srcToDstRelation,
319 : std::list<std::pair<const EntityInfo*, const EntityInfo*>>& routeList) const;
320 :
321 : void QueryRoutesByDstFromRelation(
322 : const EntityInfo& dst, const MapEnitityInfoToInfoSet& dstToSrcRelation,
323 : std::list<std::pair<const EntityInfo*, const EntityInfo*>>& routeList) const;
324 :
325 : uint32_t ParseDeviceId(const uint32_t rawDeviceId) const;
326 :
327 : BqsStatus SubscribeQueueEvent(
328 : const bool isLocalQ, const uint32_t queueId, const uint32_t deviceId, const uint32_t resIndex,
329 : const bool isEnqueue) const;
330 :
331 : bool IsSvmShareGrp(const std::string& grpName) const;
332 :
333 : // define struct for store update config info
334 : struct UpdateCfgInfo {
335 : // mbuf data addr for config
336 : uintptr_t mbufData;
337 : // mbuf data len
338 : uint64_t dataLen;
339 : // config info
340 : ConfigInfo* cfgInfo;
341 : // routes
342 : std::vector<Route*> routes;
343 : // endpoints in group
344 : std::vector<Endpoint*> endpointsInGroup;
345 : // results
346 : std::vector<CfgRetInfo*> results;
347 : // entities in routes: after transform
348 : std::vector<std::pair<EntityInfoPtr, EntityInfoPtr>> entitiesInRoutes;
349 : // entities in group: after tranform
350 : std::vector<EntityInfoPtr> entitiesInGroup;
351 : };
352 :
353 : // device id
354 : uint32_t deviceId_ = 0U;
355 : // record update config info
356 : std::unique_ptr<UpdateCfgInfo> updateCfgInfo_ = nullptr;
357 : std::string groupNames_ = "";
358 : std::vector<GrpQueryGroupAddrInfo> grpAllocInfos_;
359 : uint16_t clientVersion_;
360 : };
361 : } // namespace bqs
362 : #endif // CONFIG_INFO_OPERATOR_H
|