NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
LTENR_NetworkSlicing.c
1/************************************************************************************
2* Copyright (C) 2023 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* This source code is licensed per the NetSim license agreement. *
12* *
13* No portion of this source code may be used as the basis for a derivative work, *
14* or used, for any purpose other than its intended use per the NetSim license *
15* agreement. *
16* *
17* This source code and the algorithms contained within it are confidential trade *
18* secrets of TETCOS and may not be used as the basis for any other software, *
19* hardware, product or service. *
20* *
21* Author: Shashi Kant Suman *
22* *
23* ----------------------------------------------------------------------------------*/
24
25#pragma region HEADER_FILES
26#include "main.h"
27#include "LTE_NR.h"
28#include "NetSim_utility.h"
29#include "LTENR_NetworkSlicing.h"
30#include "LTENR_PHY.h"
31#pragma endregion
32
33#pragma region BUILDER
34char* sliceToString(_In_ ptrNetworkSliceInfo info, _Inout_ char* buf)
35{
36 sprintf(buf, "SliceInfo{ ""mSliceServiceType=%s"
37 ", mSliceDifferentiator=%d }",
38 strSLICE_SERVICE_TYPE[info->sliceServiceType], info->sliceDifferentiator);
39 return buf;
40}
41
42void setSliceServiceType(_In_ ptrNetworkSliceInfo sliceInfo, SLICE_SERVICE_TYPE type)
43{
44 sliceInfo->sliceServiceType = type;
45}
46
47void setSliceDifferentiator(_In_ ptrNetworkSliceInfo sliceInfo, _In_range_(MIN_SLICE_DIFFERENTIATOR,MAX_SLICE_DIFFERENTIATOR) int sliceDifferentiator)
48{
49 if (sliceDifferentiator < MIN_SLICE_DIFFERENTIATOR
50 || sliceDifferentiator > MAX_SLICE_DIFFERENTIATOR)
51 {
52 fnNetSimError("The slice differentiator value is out of range");
53 return;
54 }
55 sliceInfo->sliceDifferentiator = sliceDifferentiator;
56}
57
58_Check_return_ _Ret_notnull_ ptrNetworkSliceInfo sliceBuilder()
59{
60 ptrNetworkSliceInfo info = calloc(1,sizeof * info);
61 info->sliceDifferentiator = SLICE_DIFFERENTIATOR_NO_SLICE;
62 info->sliceServiceType = SLICE_SERVICE_TYPE_NONE;
63 return info;
64}
65
66int findIndex(const char* arr[], int size, const char* target) {
67 for (int i = 0; i < size; i++) {
68 if (strcmp(target, arr[i]) == 0) {
69 return i;
70 }
71 }
72 return -1; // Indicates that the string was not found in the array
73}
74
75static void fn_ConfigureNTN_SlicingConfig()
76{
77 ptrNTN_PROPAGATIONCONFIG ntnInfo = getNTN_PropInfo();
78
79 nws->rsrcSharingTechnique = LTENR_RESOURCE_SHARING_STATIC;
80 nws->sliceCount = ntnInfo->beamCount-1;
81
82 for (UINT i = 0; i < ntnInfo->beamCount; i++)
83 {
84 nws->Info[i].sliceId = i;
85 nws->Info[i].sliceServiceType = SLICE_SERVICE_TYPE_NONE;
86 nws->Info[i].downlinkBandwidth.resourceAllocationPercentage = floor(100/ntnInfo->channelCount);
87 nws->Info[i].uplinkBandwidth.resourceAllocationPercentage = floor(100 / ntnInfo->channelCount);
88 }
89 return;
90}
91
92void LTENR_ConfigureNETWORK_SLICINGConfig() //auto assign slice differentiator
93{
94 FILE* fp;
95 char* temp;
96 char data[BUFSIZ], input[BUFSIZ];
97 int line = 0;
98 int slCount = 0;
99 int slIndex = 0;
100 int *sdCount;
101 NETSIM_ID d, slid;
102
103 if (isNTNScenario())
104 {
105 fn_ConfigureNTN_SlicingConfig();
106 return;
107 }
108
109 sdCount = calloc(SLICE_SERVICE_TYPE_UNKNOWN, sizeof * sdCount);
110 sprintf(input, "%s%s%s", pszIOPath, pathSeperator, "ConfigSupport/networkslicing.csv"/*nws->slicingFileName*/);
111
112 fp = fopen(input, "r");
113 if (fp == NULL)
114 {
115 fnSystemError("Unable to open %s file", input);
116 perror(input);
117 return;
118 }
119 else
120 {
121 while (fgets(data, BUFSIZ, fp) != NULL)
122 {
123 line++;
124 temp = data;
125 temp = lskip(temp);
126
127 if (*temp == '\n' || *temp == '#' || *temp == 0 || *temp == ',')
128 continue;
129
130 _strupr(temp);
131
132 size_t len = strlen(temp);
133 while (len > 0 && ((temp[len - 1] == '\n') || (temp[len - 1] == ','))) temp[--len] = '\0';
134 if (*temp == 'R')
135 {
136 char* f = strtok(temp, ",");
137 if (!_stricmp(f, "resource_sharing_technique"))
138 {
139 char* l = strtok(NULL, ",\n");
140 int size = sizeof(strLTENR_RESOURCE_SHARING_TECHNIQUE) / sizeof(strLTENR_RESOURCE_SHARING_TECHNIQUE[0]);
141 int i = findIndex(strLTENR_RESOURCE_SHARING_TECHNIQUE, size, l);
142 if (i >= 0)
143 nws->rsrcSharingTechnique = i;
144 else
145 {
146 fprintf(stderr, "Invalid resource sharing technique found in line %d.\n\"%s\" is not a valid Resource Sharing Technique. Please edit the file and re-run simulation. \n"
147 "Press any key to skip this line and continue simulation.\n", line, temp);
148 _getch();
149 }
150 }
151 else
152 {
153 goto INVALIDINPUT;
154 }
155 }
156 else if (*temp == 'N')
157 {
158 char* f = strtok(temp, ",");
159 if (!_stricmp(f, "number_of_slices"))
160 {
161 char* l = strtok(NULL, ",\n");
162 nws->sliceCount = atoi(l);
163 }
164 else
165 {
166 goto INVALIDINPUT;
167 }
168 }
169 else if (*temp == 'L')
170 {
171 char* f = strtok(temp, ",");
172 if (!_stricmp(f, "lambda_max"))
173 {
174 char* l = strtok(NULL, ",\n");
175 nws->lambda_max = atoi(l);
176 }
177 else
178 {
179 goto INVALIDINPUT;
180 }
181 }
182 //Read and update nws->nu_max and nws->lambda_max
183 else if (*temp == 'S')
184 {
185 char* f = strtok(temp, ",");
186 if (!_stricmp(f, "slice_id"))
187 {
188 slCount++;
189 char* l = strtok(NULL, ",\n");
190 nws->Info[slCount - 1].sliceId = atoi(l);
191 }
192 else if (!_stricmp(f, "slice_type"))
193 {
194 char* l = strtok(NULL, ",\n");
195 int size = sizeof(strSLICE_SERVICE_TYPE) / sizeof(strSLICE_SERVICE_TYPE[0]);
196 slIndex = findIndex(strSLICE_SERVICE_TYPE, size, l);
197 if (slIndex >= 0)
198 {
199 //nws->Info[slCount - 1].sliceServiceType = slIndex;
200 setSliceServiceType(&nws->Info[slCount - 1], slIndex);
201 sdCount[slIndex]++;
202 }
203 else
204 {
205 fprintf(stderr, "Invalid slice type found in line %d.\n\"%s\" is not a valid slice type. Please edit the file and re-run simulation. \n"
206 "Press any key to skip this line and continue simulation.\n", line, temp);
207 _getch();
208 }
209 }
210 else if (!_stricmp(f, "slice_differentiator"))
211 {
212 char* l = strtok(NULL, ",\n");
213 //nws->Info[slCount - 1].sliceDifferentiator = atoi(l);
214 //setSliceDifferentiator(&nws->Info[slCount - 1], atoi(l)); //manual from file
215 setSliceDifferentiator(&nws->Info[slCount - 1], sdCount[slIndex]); //auto assignment
216 }
217 else if (!_stricmp(f, "slice_index_bias_learning_rate"))
218 {
219 char* l = strtok(NULL, ",\n");
220 nws->sliceIndexBiasLearningRate = atof(l);
221 }
222 else
223 {
224 goto INVALIDINPUT;
225 }
226 }
227 else if (*temp == 'P')
228 {
229 char* f = strtok(temp, ",");
230 if (!_stricmp(f, "percentage_of_resources_allocated"))
231 {
232 char* l = strtok(NULL, ",\n");
233 nws->Info[slCount - 1].downlinkBandwidth.resourceAllocationPercentage = atof(l);
234 nws->Info[slCount - 1].uplinkBandwidth.resourceAllocationPercentage = atof(l);
235 }
236 else
237 {
238 goto INVALIDINPUT;
239 }
240 }
241 else if (*temp == 'M')
242 {
243 char* f = strtok(temp, ",");
244 /*if (!_stricmp(f, "min_aggr_throughput"))
245 {
246 char* l = strtok(NULL, ",\n");
247 nws->Info[slCount - 1].downlinkBandwidth.minGuaranteedBitRate_mbps = atof(l);
248 nws->Info[slCount - 1].uplinkBandwidth.minGuaranteedBitRate_mbps = atof(l);
249 }*/
250 if (!_stricmp(f, "min_ul_resource_share"))
251 {
252 char* l = strtok(NULL, ",\n");
253 nws->Info[slCount - 1].uplinkBandwidth.minResourceShare = atof(l);
254 }
255 else if (!_stricmp(f, "max_ul_resource_share"))
256 {
257 char* l = strtok(NULL, ",\n");
258 nws->Info[slCount - 1].uplinkBandwidth.maxResourceShare = atof(l);
259 }
260 else if (!_stricmp(f, "min_dl_resource_share"))
261 {
262 char* l = strtok(NULL, ",\n");
263 nws->Info[slCount - 1].downlinkBandwidth.minResourceShare = atof(l);
264 }
265 else if (!_stricmp(f, "max_dl_resource_share"))
266 {
267 char* l = strtok(NULL, ",\n");
268 nws->Info[slCount - 1].downlinkBandwidth.maxResourceShare = atof(l);
269 }
270 else
271 {
272 goto INVALIDINPUT;
273 }
274 }
275 /*else if (*temp == 'A')
276 {
277 char* f = strtok(temp, ",");
278 if (!_stricmp(f, "aggregate_rate_guarantee_dl"))
279 {
280 char* l = strtok(NULL, ",\n");
281 nws->Info[slCount - 1].downlinkBandwidth.aggregateRateGuarantee_mbps = atof(l);
282 }
283 else if (!_stricmp(f, "aggregate_rate_guarantee_ul"))
284 {
285 char* l = strtok(NULL, ",\n");
286 nws->Info[slCount - 1].uplinkBandwidth.aggregateRateGuarantee_mbps = atof(l);
287 }
288 else
289 {
290 goto INVALIDINPUT;
291 }
292 }*/
293 else if (sscanf(data, "%d,%d\"",
294 &d, &slid) == 2)
295 {
296 NETSIM_ID ueId = fn_NetSim_GetDeviceIdByConfigId(d);
297 if (ueId > 0)
298 nws->ueSliceId[ueId] = slid;
299 else
300 fprintf(stderr, "In networkslicing.csv, the device id is invalid, at line no %d\n", line);
301
302 }
303 else
304 {
305 INVALIDINPUT:
306 fprintf(stderr, "Invalid input found in line %d.\n\"%s\"\n"
307 "Press any key to skip this line and continue simulation.\n", line, temp);
308 _getch();
309 }
310 }
311 }
312 if (fp)
313 fclose(fp);
314}
315#pragma endregion