25#pragma region HEADER_FILES
28#include "NetSim_utility.h"
29#include "LTENR_NetworkSlicing.h"
34char* sliceToString(_In_ ptrNetworkSliceInfo info, _Inout_
char* buf)
36 sprintf(buf,
"SliceInfo{ ""mSliceServiceType=%s"
37 ", mSliceDifferentiator=%d }",
38 strSLICE_SERVICE_TYPE[info->sliceServiceType], info->sliceDifferentiator);
42void setSliceServiceType(_In_ ptrNetworkSliceInfo sliceInfo, SLICE_SERVICE_TYPE type)
44 sliceInfo->sliceServiceType = type;
47void setSliceDifferentiator(_In_ ptrNetworkSliceInfo sliceInfo, _In_range_(MIN_SLICE_DIFFERENTIATOR,MAX_SLICE_DIFFERENTIATOR)
int sliceDifferentiator)
49 if (sliceDifferentiator < MIN_SLICE_DIFFERENTIATOR
50 || sliceDifferentiator > MAX_SLICE_DIFFERENTIATOR)
52 fnNetSimError(
"The slice differentiator value is out of range");
55 sliceInfo->sliceDifferentiator = sliceDifferentiator;
58_Check_return_ _Ret_notnull_ ptrNetworkSliceInfo sliceBuilder()
60 ptrNetworkSliceInfo info = calloc(1,
sizeof * info);
61 info->sliceDifferentiator = SLICE_DIFFERENTIATOR_NO_SLICE;
62 info->sliceServiceType = SLICE_SERVICE_TYPE_NONE;
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) {
75static void fn_ConfigureNTN_SlicingConfig()
77 ptrNTN_PROPAGATIONCONFIG ntnInfo = getNTN_PropInfo();
79 nws->rsrcSharingTechnique = LTENR_RESOURCE_SHARING_STATIC;
80 nws->sliceCount = ntnInfo->beamCount-1;
82 for (UINT i = 0; i < ntnInfo->beamCount; i++)
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);
92void LTENR_ConfigureNETWORK_SLICINGConfig()
96 char data[BUFSIZ], input[BUFSIZ];
105 fn_ConfigureNTN_SlicingConfig();
109 sdCount = calloc(SLICE_SERVICE_TYPE_UNKNOWN,
sizeof * sdCount);
110 sprintf(input,
"%s%s%s", pszIOPath, pathSeperator,
"ConfigSupport/networkslicing.csv");
112 fp = fopen(input,
"r");
115 fnSystemError(
"Unable to open %s file", input);
121 while (fgets(data, BUFSIZ, fp) != NULL)
127 if (*temp ==
'\n' || *temp ==
'#' || *temp == 0 || *temp ==
',')
132 size_t len = strlen(temp);
133 while (len > 0 && ((temp[len - 1] ==
'\n') || (temp[len - 1] ==
','))) temp[--len] =
'\0';
136 char* f = strtok(temp,
",");
137 if (!_stricmp(f,
"resource_sharing_technique"))
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);
143 nws->rsrcSharingTechnique = i;
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);
156 else if (*temp ==
'N')
158 char* f = strtok(temp,
",");
159 if (!_stricmp(f,
"number_of_slices"))
161 char* l = strtok(NULL,
",\n");
162 nws->sliceCount = atoi(l);
169 else if (*temp ==
'L')
171 char* f = strtok(temp,
",");
172 if (!_stricmp(f,
"lambda_max"))
174 char* l = strtok(NULL,
",\n");
175 nws->lambda_max = atoi(l);
183 else if (*temp ==
'S')
185 char* f = strtok(temp,
",");
186 if (!_stricmp(f,
"slice_id"))
189 char* l = strtok(NULL,
",\n");
190 nws->Info[slCount - 1].sliceId = atoi(l);
192 else if (!_stricmp(f,
"slice_type"))
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);
200 setSliceServiceType(&nws->Info[slCount - 1], slIndex);
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);
210 else if (!_stricmp(f,
"slice_differentiator"))
212 char* l = strtok(NULL,
",\n");
215 setSliceDifferentiator(&nws->Info[slCount - 1], sdCount[slIndex]);
217 else if (!_stricmp(f,
"slice_index_bias_learning_rate"))
219 char* l = strtok(NULL,
",\n");
220 nws->sliceIndexBiasLearningRate = atof(l);
227 else if (*temp ==
'P')
229 char* f = strtok(temp,
",");
230 if (!_stricmp(f,
"percentage_of_resources_allocated"))
232 char* l = strtok(NULL,
",\n");
233 nws->Info[slCount - 1].downlinkBandwidth.resourceAllocationPercentage = atof(l);
234 nws->Info[slCount - 1].uplinkBandwidth.resourceAllocationPercentage = atof(l);
241 else if (*temp ==
'M')
243 char* f = strtok(temp,
",");
250 if (!_stricmp(f,
"min_ul_resource_share"))
252 char* l = strtok(NULL,
",\n");
253 nws->Info[slCount - 1].uplinkBandwidth.minResourceShare = atof(l);
255 else if (!_stricmp(f,
"max_ul_resource_share"))
257 char* l = strtok(NULL,
",\n");
258 nws->Info[slCount - 1].uplinkBandwidth.maxResourceShare = atof(l);
260 else if (!_stricmp(f,
"min_dl_resource_share"))
262 char* l = strtok(NULL,
",\n");
263 nws->Info[slCount - 1].downlinkBandwidth.minResourceShare = atof(l);
265 else if (!_stricmp(f,
"max_dl_resource_share"))
267 char* l = strtok(NULL,
",\n");
268 nws->Info[slCount - 1].downlinkBandwidth.maxResourceShare = atof(l);
293 else if (sscanf(data,
"%d,%d\"",
296 NETSIM_ID ueId = fn_NetSim_GetDeviceIdByConfigId(d);
298 nws->ueSliceId[ueId] = slid;
300 fprintf(stderr,
"In networkslicing.csv, the device id is invalid, at line no %d\n", line);
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);