1#pragma region HEADER_FILES
6#pragma region INTERFERENCE_PARAMETER
14 double* Relative_Intereference_dB;
16}GRADED_DISTANCE_BASED_WYNER_INTERFERENCE, * ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE;
17ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE GradedDistanceBasedWynerInterferenceheadDownlink;
18ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE GradedDistanceBasedWynerInterferenceheadUplink;
22static double fn_GetEdgeInterference(NETSIM_ID gNBiID, NETSIM_ID gNBjID,
double dUEgnbi,
double dUEgnbj,
bool isDownlink) {
23 ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE temp = NULL;
24 double interference_db = -NEGATIVE_DBM;
26 temp = GradedDistanceBasedWynerInterferenceheadDownlink;
28 temp = GradedDistanceBasedWynerInterferenceheadUplink;
30 if (!temp)
return interference_db;
33 if ((temp->CellId == gNBiID && temp->PairId == gNBjID) ||
34 (temp->CellId == gNBjID && temp->PairId == gNBiID)) {
35 double ratio = (dUEgnbj - dUEgnbi) / dUEgnbj;
36 if (ratio < 0 && ratio>(-temp->DDRth))
return temp->Relative_Intereference_dB[0];
37 if (ratio >= 0 && ratio <= temp->DDRth) {
38 double Band = temp->DDRth / temp->BinCount;
40 while (i <= temp->BinCount+1) {
41 double bi = Band * ((double)i);
43 return(temp->Relative_Intereference_dB[i]);
52 return interference_db;
56static void LTENR_fn_Graded_Distance_Based_Wyner_Model_Interference(ptrLTENR_PROPAGATIONINFO info,
double rxPower_dbm,
57 double* Interference,
int CA_ID,
bool isDownlink) {
59 double Interference_linear = 0;
60 double In_db = INFINITY;
61 ptrLTENR_PROTODATA data = LTENR_PROTODATA_GET(info->ueId, info->ueIf);
62 ptrLTENR_UEPHY uePhy = LTENR_UEPHY_GET(info->ueId, info->ueIf);
63 for (NETSIM_ID r = 0; r < NETWORK->nDeviceCount; r++)
65 if (info->ueId == r + 1)
68 for (NETSIM_ID rin = 0; rin < DEVICE(r + 1)->nNumOfInterface; rin++)
70 if (!isLTE_NRInterface(r + 1, rin + 1))
73 ptrLTENR_PROTODATA pd = LTENR_PROTODATA_GET(r + 1, rin + 1);
74 ptrLTENR_GNBPHY phy = NULL;
75 if (pd->deviceType == LTENR_DEVICETYPE_GNB) {
76 phy = LTENR_GNBPHY_GET(r + 1, rin + 1);
77 ptrLTENR_ASSOCIATEDUEPHYINFO assocInfo = LTENR_ASSOCIATEDUEPHYINFO_GET(phy->gnbId, phy->gnbIf, info->ueId, info->ueIf);
78 ptrLTENR_PROPAGATIONINFO pinfo = assocInfo->propagationInfo[CA_ID];
80 if (pinfo && info->gnbId != r + 1 && pinfo->centralFrequency_MHz == info->centralFrequency_MHz) {
81 In_db = fn_GetEdgeInterference(info->gnbId, r + 1, info->dist2D, pinfo->dist2D, isDownlink);
82 Interference_linear += DBM_TO_MW((rxPower_dbm - In_db));
89 *Interference = MW_TO_DBM(Interference_linear);
94void LTENR_fn_InterferenceInit() {
97 char data[BUFSIZ], input[BUFSIZ];
98 GradedDistanceBasedWynerInterferenceheadDownlink = (ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE)malloc(
sizeof(GRADED_DISTANCE_BASED_WYNER_INTERFERENCE));
99 ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE t = GradedDistanceBasedWynerInterferenceheadDownlink;
101 sprintf(input,
"%s%s%s", pszIOPath,pathSeperator, wynerFile);
103 fp = fopen(input,
"r");
111 while (fgets(data, BUFSIZ, fp))
117 if (*temp ==
'#' || *temp == 0)
119 bool dev1 =
false, dev2 =
false;
121 char* newline = strchr(temp,
'\n');
if (newline) *newline = 0;
122 char* token = strtok(temp,
",");
128 t->CellId = fn_NetSim_Stack_GetDeviceId_asName(token);
131 fprintf(stderr,
"Invalid Input detected in line %d.\n\"%s\" is not a valid Device Name. Please edit the file and re-run simulation. \n"
132 "Press any key to skip this line and continue simulation.\n", line, token);
137 for (NETSIM_ID In = 1; In <= DEVICE(t->CellId)->nNumOfInterface; In++)
139 if (!isLTENR_RANInterface(t->CellId, In))
continue;
140 if (isGNB(t->CellId, In))
148 fprintf(stderr,
"Invalid Input detected in line %d.\n\"%s\" is not a valid gNB Device. Please edit the file and re-run simulation. \n"
149 "Press any key to skip this line and continue simulation.\n", line, token);
158 token = strtok(NULL,
",");
159 t->PairId = fn_NetSim_Stack_GetDeviceId_asName(token);
163 fprintf(stderr,
"Invalid Input detected in line %d.\n\"%s\" is not a valid Device Name. Please edit the file and re-run simulation. \n"
164 "Press any key to skip this line and continue simulation.\n", line, token);
169 for (NETSIM_ID In = 1; In <= DEVICE(t->PairId)->nNumOfInterface; In++)
171 if (!isLTENR_RANInterface(t->PairId, In))
continue;
172 if (isGNB(t->PairId, In))
180 fprintf(stderr,
"Invalid Input detected in line %d.\n\"%s\" is not a valid LTE NR Device. Please edit the file and re-run simulation. \n"
181 "Press any key to skip this line and continue simulation.\n", line, token);
190 token = strtok(NULL,
",");
192 t->DDRth = strtod(token, NULL);
195 token = strtok(NULL,
",");
196 int bincount = 4, k = 1;
198 t->BinCount = atoi(token);
199 bincount = t->BinCount;
202 t->Relative_Intereference_dB = calloc((bincount + 2),
sizeof(t->Relative_Intereference_dB));
204 token = strtok(NULL,
",");
206 in = strtod(token, NULL);
207 if (in >= -3 && in <= 0) t->Relative_Intereference_dB[0] = in;
209 printf(
"\nIncorrect value of Relative Interference"
210 "has been found in line: %d, for Relative Interference -1 Enter value in range of 0 to 10", line);
212 while (k < bincount + 2) {
214 token = strtok(NULL,
",");
216 in = strtod(token, NULL);
217 if (t->Relative_Intereference_dB[k - 1] <= in && 0 <= in)
218 t->Relative_Intereference_dB[k] = in;
220 printf(
"\nIncorrect value of Relative Interference has been found in line: %d, for In %d", line, k - 1);
224 t->next = (ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE)malloc(1*
sizeof(GRADED_DISTANCE_BASED_WYNER_INTERFERENCE));
234void LTENR_fn_ExactGeometricModelInterference(ptrLTENR_PROPAGATIONINFO info,
double rxPower_dbm,
235 double* Interference,
int layerId,
int CA_ID,
bool isDownlink) {
237 double Interference_linear = 0;
239 ptrLTENR_PROTODATA data = LTENR_PROTODATA_GET(info->ueId, info->ueIf);
241 for (NETSIM_ID r = 0; r < NETWORK->nDeviceCount; r++)
243 if (info->ueId == r + 1)
246 for (NETSIM_ID rin = 0; rin < DEVICE(r + 1)->nNumOfInterface; rin++)
248 if (!isLTE_NRInterface(r + 1, rin + 1))
251 if (data->isDCEnable) {
252 if (data->SecCellType == MMWAVE_CELL_TYPE) {
253 if (!fn_NetSim_isDeviceLTENR(r + 1, rin + 1))
257 if (fn_NetSim_isDeviceLTENR(r + 1, rin + 1))
261 ptrLTENR_PROTODATA pd = LTENR_PROTODATA_GET(r + 1, rin + 1);
262 ptrLTENR_GNBPHY phy = NULL;
263 if (pd->deviceType == LTENR_DEVICETYPE_GNB) {
264 phy = LTENR_GNBPHY_GET(r + 1, rin + 1);
265 ptrLTENR_ASSOCIATEDUEPHYINFO assocInfo = LTENR_ASSOCIATEDUEPHYINFO_GET(phy->gnbId, phy->gnbIf, info->ueId, info->ueIf);
266 ptrLTENR_PROPAGATIONINFO pinfo = assocInfo->propagationInfo[CA_ID];
267 if (pinfo && info->gnbId != r + 1 && pinfo->centralFrequency_MHz == info->centralFrequency_MHz) {
268 if (isDownlink) Interference_linear += DBM_TO_MW(pinfo->downlink.rxPower_dbm[layerId]);
269 else Interference_linear += DBM_TO_MW(pinfo->uplink.rxPower_dbm[layerId]);
275 *Interference = MW_TO_DBM(Interference_linear);
280void LTENR_Calculate_Interference(ptrLTENR_PROPAGATIONINFO info,
double rxPower_dbm,
281 double* Interference,
int layerId,
int CA_ID,
bool isDownlink) {
282 ptrLTENR_GNBPHY phy = LTENR_GNBPHY_GET(info->gnbId, info->gnbIf);
284 if (phy->propagationConfig->DownlinkInterferenceModel == LTENR_EXACT_GEOMETRIC_MODEL_INTERFERENCE)
285 LTENR_fn_ExactGeometricModelInterference(info, rxPower_dbm, Interference, layerId, CA_ID, isDownlink);
287 else if (phy->propagationConfig->DownlinkInterferenceModel == LTENR_GRADED_DISTANCE_BASED_WYNER_MODEL_INTERFERENCE)
288 LTENR_fn_Graded_Distance_Based_Wyner_Model_Interference(info, rxPower_dbm, Interference, CA_ID, isDownlink);
290 *Interference = NEGATIVE_DBM;
294void free_interference() {
295 if (GradedDistanceBasedWynerInterferenceheadDownlink) {
296 while (GradedDistanceBasedWynerInterferenceheadDownlink!=NULL) {
297 ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE temp = GradedDistanceBasedWynerInterferenceheadDownlink;
298 GradedDistanceBasedWynerInterferenceheadDownlink = GradedDistanceBasedWynerInterferenceheadDownlink->next;
299 free(temp->Relative_Intereference_dB);
300 temp->Relative_Intereference_dB = NULL;