1 /*
2 * Copyright (c) 2025-2026 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef ROUTESELECTIONDESCRIPTORINFO_H
17 #define ROUTESELECTIONDESCRIPTORINFO_H
18
19 #include <cstdint>
20 #include <string>
21 #include <vector>
22 #include <iostream>
23
24 namespace OHOS {
25 namespace NetManagerStandard {
26
27 class RouteSelectionDescriptorInfo {
28 public:
29 static const int INVAILID_PDU_SESSION_TYPE;
30 static const std::string RSD_SSCMODE;
31 static const std::string RSD_SNSSAI;
32 static const std::string RSD_DNN;
33 static const std::string RSD_PDU_SESSION_TYPE;
34 static const uint8_t MATCH_ALL;
RouteSelectionDescriptorInfo()35 RouteSelectionDescriptorInfo()
36 : mSscMode(0), mDnn(""), mSnssai(""), mIsMatchAll(false), mPduSessionType(0)
37 {
38 mSscMode = 0;
39 mDnn = "";
40 mSnssai = "";
41 mIsMatchAll = false;
42 mPduSessionType = 0;
43 }
44
45 RouteSelectionDescriptorInfo(uint8_t sscMode, const std::string& dnn,
46 const std::string& snssai, bool isMatchAll, int pduSessionType);
47 class Builder {
48 public:
Builder()49 Builder()
50 : mSscMode(0), mDnn(""), mSnssai(""), mIsMatchAll(false), mPduSessionType(0)
51 {}
52
setRSDSscMode(uint8_t sscMode)53 Builder& setRSDSscMode(uint8_t sscMode)
54 {
55 mSscMode = sscMode;
56 return *this;
57 }
58
setRSDDnn(const std::string & ids)59 Builder& setRSDDnn(const std::string& ids)
60 {
61 mDnn = ids;
62 return *this;
63 }
64
setRSDSnssai(const std::string & ids)65 Builder& setRSDSnssai(const std::string& ids)
66 {
67 mSnssai = ids;
68 return *this;
69 }
70
setIsMatchAll(bool isMatchAll)71 Builder& setIsMatchAll(bool isMatchAll)
72 {
73 mIsMatchAll = isMatchAll;
74 return *this;
75 }
76
setPduSessionType(int PduSessionType)77 Builder& setPduSessionType(int PduSessionType)
78 {
79 mPduSessionType = PduSessionType;
80 return *this;
81 }
82
build()83 RouteSelectionDescriptorInfo build()
84 {
85 RouteSelectionDescriptorInfo rsdinfo;
86 rsdinfo.mSscMode = mSscMode;
87 rsdinfo.mDnn = mDnn;
88 rsdinfo.mSnssai = mSnssai;
89 rsdinfo.mIsMatchAll = mIsMatchAll;
90 rsdinfo.mPduSessionType = mPduSessionType;
91 return rsdinfo;
92 }
93 private:
94 uint8_t mSscMode;
95 std::string mDnn;
96 std::string mSnssai;
97 bool mIsMatchAll;
98 int mPduSessionType;
99 };
100
makeRouteSelectionDescriptor(std::map<std::string,std::string> & data)101 static RouteSelectionDescriptorInfo makeRouteSelectionDescriptor(std::map<std::string, std::string>& data)
102 {
103 NETMGR_EXT_LOG_I("makeRouteSelectionDescriptor");
104 int sscMode = 0;
105 if (data.find(RSD_SSCMODE) != data.end()) {
106 sscMode = static_cast<int>(std::stoi(data[RSD_SSCMODE]));
107 NETMGR_EXT_LOG_I("makeRouteSelectionDescriptor sscMode = %{public}d", sscMode);
108 }
109 std::string dnn = "";
110 if (data.find(RSD_DNN) != data.end()) {
111 dnn = data[RSD_DNN];
112 NETMGR_EXT_LOG_I("makeRouteSelectionDescriptor dnn = %{public}s", dnn.c_str());
113 }
114 std::string snssai = "";
115 if (data.find(RSD_SNSSAI) != data.end()) {
116 snssai = data[RSD_SNSSAI];
117 NETMGR_EXT_LOG_I("makeRouteSelectionDescriptor snssai = %{public}s", snssai.c_str());
118 }
119 int pduSessionType = INVAILID_PDU_SESSION_TYPE;
120 if (data.find(RSD_PDU_SESSION_TYPE) != data.end()) {
121 pduSessionType = std::stoi(data[RSD_PDU_SESSION_TYPE]);
122 NETMGR_EXT_LOG_I("makeRouteSelectionDescriptor pduSessionType = %{public}d", pduSessionType);
123 }
124 bool isMatchAll = false;
125 if (data.find(TrafficDescriptorsInfo::TDS_ROUTE_BITMAP) != data.end()) {
126 isMatchAll = (std::stoi(data[TrafficDescriptorsInfo::TDS_ROUTE_BITMAP]) & MATCH_ALL) != 0;
127 NETMGR_EXT_LOG_I("makeRouteSelectionDescriptor isMatchAll = %{public}d", isMatchAll ? 1 : 0);
128 }
129 RouteSelectionDescriptorInfo::Builder builder;
130 builder.setRSDSscMode(sscMode);
131 builder.setRSDDnn(dnn);
132 builder.setRSDSnssai(snssai);
133 builder.setIsMatchAll(isMatchAll);
134 builder.setPduSessionType(pduSessionType);
135 return builder.build();
136 }
137
getSscMode()138 uint8_t getSscMode() const
139 {
140 return mSscMode;
141 }
142
getSnssai()143 std::string getSnssai() const
144 {
145 return mSnssai;
146 }
147
getDnn()148 std::string getDnn() const
149 {
150 return mDnn;
151 }
getPduSessionType()152 int getPduSessionType() const
153 {
154 return mPduSessionType;
155 }
156
isMatchAll()157 bool isMatchAll() const
158 {
159 return mIsMatchAll;
160 }
161
162 bool operator==(const RouteSelectionDescriptorInfo& other) const
163 {
164 NETMGR_EXT_LOG_I("mSscMode = %{public}d, other.mSscMode = %{public}d", mSscMode, other.mSscMode);
165 NETMGR_EXT_LOG_I("mDnn = %{public}s, other.mDnn = %{public}s", mDnn.c_str(), other.mDnn.c_str());
166 NETMGR_EXT_LOG_I("mSnssai = %{public}s, other.mSnssai = %{public}s", mSnssai.c_str(), other.mSnssai.c_str());
167 NETMGR_EXT_LOG_I("mIsMatchAll = %{public}d, other.mIsMatchAll = %{public}d", mIsMatchAll, other.mIsMatchAll);
168 NETMGR_EXT_LOG_I("mPduSessionType = %{public}d, other.mPduSessionType = %{public}d",
169 mPduSessionType, other.mPduSessionType);
170 return mSscMode == other.mSscMode && mDnn == other.mDnn && mSnssai == other.mSnssai
171 && mIsMatchAll == other.mIsMatchAll && mPduSessionType == other.mPduSessionType;
172 }
173
174 private:
175 uint8_t mSscMode;
176 std::string mDnn;
177 std::string mSnssai;
178 bool mIsMatchAll;
179 int mPduSessionType;
180 };
181
182 const inline int RouteSelectionDescriptorInfo::INVAILID_PDU_SESSION_TYPE = -1;
183 const inline std::string RouteSelectionDescriptorInfo::RSD_SSCMODE = "sscMode";
184 const inline std::string RouteSelectionDescriptorInfo::RSD_SNSSAI = "sNssai";
185 const inline std::string RouteSelectionDescriptorInfo::RSD_DNN = "dnn";
186 const inline std::string RouteSelectionDescriptorInfo::RSD_PDU_SESSION_TYPE = "pduSessionType";
187 const inline uint8_t RouteSelectionDescriptorInfo::MATCH_ALL = 1;
RouteSelectionDescriptorInfo(uint8_t sscMode,const std::string & dnn,const std::string & snssai,bool isMatchAll,int pduSessionType)188 inline RouteSelectionDescriptorInfo::RouteSelectionDescriptorInfo(uint8_t sscMode, const std::string& dnn,
189 const std::string& snssai, bool isMatchAll, int pduSessionType) : mSscMode(sscMode), mDnn(dnn), mSnssai(snssai),
190 mIsMatchAll(isMatchAll), mPduSessionType(pduSessionType) {}
191
192 } // namespace NetManagerStandard
193 } // namespace OHOS
194
195 #endif // ROUTESELECTIONDESCRIPTORINFO_H
196