NetSim Source Code Help
Loading...
Searching...
No Matches
LTENR_Interference.c
Go to the documentation of this file.
1#pragma region HEADER_FILES
2#include "stdafx.h"
3#include "LTENR_PHY.h"
4#pragma endregion
5
6#pragma region INTERFERENCE_PARAMETER
7
11 double DDRth;
12 int BinCount;//BinCount
18#pragma endregion
19
20//Interference Calc
21static double fn_GetEdgeInterference(NETSIM_ID gNBiID, NETSIM_ID gNBjID, double dUEgnbi, double dUEgnbj,bool isDownlink) {
23 double interference_db = -NEGATIVE_DBM;
24 if(isDownlink)
26 if(!isDownlink)
28
29 if (!temp) return interference_db;
30 else {
31 while (temp) {
32 if ((temp->CellId == gNBiID && temp->PairId == gNBjID) ||
33 (temp->CellId == gNBjID && temp->PairId == gNBiID)) {
34 double ratio = (dUEgnbj - dUEgnbi) / dUEgnbj;
35 if (ratio < 0 && ratio>(-temp->DDRth)) return temp->Relative_Intereference_dB[0];
36 if (ratio >= 0 && ratio <= temp->DDRth) {
37 double Band = temp->DDRth / temp->BinCount;
38 int i = 1;
39 while (i <= temp->BinCount+1) {
40 double bi = Band * ((double)i);
41 if (ratio < bi) {
42 return(temp->Relative_Intereference_dB[i]);
43 }
44 i++;
45 }
46 }
47 }
48 temp = temp->next;
49 }
50 }
51 return interference_db;
52}
53
54//Graded Distance Based Wyner Model
56 double* Interference,int CA_ID, bool isDownlink) {
57
58 double Interference_linear = 0;
59 double In_db = INFINITY;//Relative Interference
61 ptrLTENR_UEPHY uePhy = LTENR_UEPHY_GET(info->ueId, info->ueIf);
62 for (NETSIM_ID r = 0; r < NETWORK->nDeviceCount; r++)
63 {
64 if (info->ueId == r + 1)
65 continue;
66
67 for (NETSIM_ID rin = 0; rin < DEVICE(r + 1)->nNumOfInterface; rin++)
68 {
69 if (!isLTE_NRInterface(r + 1, rin + 1))
70 continue;
71
72 ptrLTENR_PROTODATA pd = LTENR_PROTODATA_GET(r + 1, rin + 1);
73 ptrLTENR_GNBPHY phy = NULL;
75 phy = LTENR_GNBPHY_GET(r + 1, rin + 1);
77 ptrLTENR_PROPAGATIONINFO pinfo = assocInfo->propagationInfo[CA_ID];
78
79 if (pinfo && info->gnbId != r + 1 && pinfo->centralFrequency_MHz == info->centralFrequency_MHz) {
80 In_db = fn_GetEdgeInterference(info->gnbId, r + 1, info->dist2D, pinfo->dist2D, isDownlink);
81 Interference_linear += DBM_TO_MW((rxPower_dbm - In_db));
82 //We convert relative interference In into absolute interference(dB)
83 //We than convert dB scale to Linear scale.
84 }
85 }
86 }
87 }
88 *Interference = MW_TO_DBM(Interference_linear);
89 return;
90}
91
92//ConfigInit
94 FILE* fp;
95 char* temp;
96 char data[BUFSIZ], input[BUFSIZ];
99 int line = 0;
100 char* filename = "Graded-Distance-Based-Wyner-Interference-Model.txt";
101 sprintf(input, "%s%s%s", pszIOPath, pathSeperator, filename);
102
103 fp = fopen(input, "r");
104 if (fp == NULL)
105 {
106 return;
107 }
108 else
109 {
110
111 while (fgets(data, BUFSIZ, fp))
112 {
113 line++;
114 temp = data;
115 if (*temp == '\n')
116 continue;
117 if (*temp == '#' || *temp == 0)
118 continue;
119 bool dev1 = false, dev2 = false;
120 double in;
121 char* newline = strchr(temp, '\n'); if (newline) *newline = 0;
122 char* token = strtok(temp, ",");
123
124
125 if (!t) break;
126 if (token != NULL)
127 {
129 if (!t->CellId)
130 {
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);
133 _getch();
134 }
135 else
136 {
137 for (NETSIM_ID In = 1; In <= DEVICE(t->CellId)->nNumOfInterface; In++)
138 {
139 if (!isLTENR_RANInterface(t->CellId, In)) continue;
140 if (isGNB(t->CellId, In))
141 {
142 dev1 = true;
143 break;
144 }
145 }
146 if (!dev1)
147 {
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);
150 _getch();
151 }
152 else
153 {
154 if (token == NULL)
155 continue;
156 else
157 {
158 token = strtok(NULL, ",");
160
161 if (!t->PairId)
162 {
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);
165 _getch();
166 }
167 else
168 {
169 for (NETSIM_ID In = 1; In <= DEVICE(t->PairId)->nNumOfInterface; In++)
170 {
171 if (!isLTENR_RANInterface(t->PairId, In)) continue;
172 if (isGNB(t->PairId, In))
173 {
174 dev2 = true;
175 break;
176 }
177 }
178 if (!dev2)
179 {
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);
182 _getch();
183 }
184 }
185 }
186 }
187 }
188 }
189
190 token = strtok(NULL, ",");
191 if (token != NULL) {
192 t->DDRth = strtod(token, NULL);
193 }
194
195 token = strtok(NULL, ",");
196 int bincount = 4, k = 1;
197 if (token != NULL) {
198 t->BinCount = atoi(token);
199 bincount = t->BinCount;
200 }
201
202 t->Relative_Intereference_dB = calloc((bincount + 2), sizeof(t->Relative_Intereference_dB));//Relative Interference
203
204 token = strtok(NULL, ",");
205 if (token != NULL) {
206 in = strtod(token, NULL);
207 if (in >= -3 && in <= 0) t->Relative_Intereference_dB[0] = in;
208 else
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);
211 }
212 while (k < bincount + 2) {
213
214 token = strtok(NULL, ",");
215 if (token != NULL) {
216 in = strtod(token, NULL);
217 if (t->Relative_Intereference_dB[k - 1] <= in && 0 <= in)
218 t->Relative_Intereference_dB[k] = in;
219 else
220 printf("\nIncorrect value of Relative Interference has been found in line: %d, for In %d", line, k - 1);
221 }
222 k++;
223 }
225 t = t->next;
226
227 }
228
229 }
230 if (fp) fclose(fp);
231}
232
233//Geometric Edge Interference
235 double* Interference,int layerId, int CA_ID, bool isDownlink) {
236
237 double Interference_linear = 0;
238
239 ptrLTENR_PROTODATA data = LTENR_PROTODATA_GET(info->ueId, info->ueIf);
240 if(isDownlink)
241 for (NETSIM_ID r = 0; r < NETWORK->nDeviceCount; r++)
242 {
243 if (info->ueId == r + 1)
244 continue;
245
246 for (NETSIM_ID rin = 0; rin < DEVICE(r + 1)->nNumOfInterface; rin++)
247 {
248 if (!isLTE_NRInterface(r + 1, rin + 1))
249 continue;
250
251 if (data->isDCEnable) {
252 if (data->SecCellType == MMWAVE_CELL_TYPE) {
253 if (!fn_NetSim_isDeviceLTENR(r + 1, rin + 1))
254 continue;
255 }
256 else {
257 if (fn_NetSim_isDeviceLTENR(r + 1, rin + 1))
258 continue;
259 }
260 }
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);
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]);
270 }
271 }
272 }
273 }
274
275 *Interference = MW_TO_DBM(Interference_linear);
276 return;
277}
278
279
281 double* Interference,int layerId, int CA_ID, bool isDownlink) {
282 ptrLTENR_GNBPHY phy = LTENR_GNBPHY_GET(info->gnbId, info->gnbIf);
283
285 LTENR_fn_ExactGeometricModelInterference(info, rxPower_dbm, Interference, layerId, CA_ID, isDownlink);
286
288 LTENR_fn_Graded_Distance_Based_Wyner_Model_Interference(info, rxPower_dbm, Interference, CA_ID, isDownlink);//Cell Edge Interference
289 else
290 *Interference = NEGATIVE_DBM;
291
292}
293
300 temp->Relative_Intereference_dB = NULL;
301 free(temp);
302 temp = NULL;
303 }
304 }
305 return;
306}
unsigned int NETSIM_ID
Definition: Animation.h:45
#define isGNB(d, i)
Definition: LTE_NR.h:591
@ LTENR_DEVICETYPE_GNB
Definition: LTE_NR.h:72
@ LTENR_GRADED_DISTANCE_BASED_WYNER_MODEL_INTERFERENCE
Definition: LTE_NR.h:612
@ LTENR_EXACT_GEOMETRIC_MODEL_INTERFERENCE
Definition: LTE_NR.h:613
#define LTENR_UEPHY_GET(d, i)
Definition: LTE_NR.h:529
@ MMWAVE_CELL_TYPE
Definition: LTE_NR.h:417
bool isLTENR_RANInterface(NETSIM_ID d, NETSIM_ID in)
bool isLTE_NRInterface(NETSIM_ID d, NETSIM_ID i)
ptrLTENR_PROTODATA LTENR_PROTODATA_GET(NETSIM_ID d, NETSIM_ID in)
bool fn_NetSim_isDeviceLTENR(NETSIM_ID r, NETSIM_ID rin)
#define LTENR_GNBPHY_GET(d, i)
Definition: LTE_NR.h:536
void free_interference()
ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE GradedDistanceBasedWynerInterferenceheadDownlink
void LTENR_fn_InterferenceInit()
static void LTENR_fn_Graded_Distance_Based_Wyner_Model_Interference(ptrLTENR_PROPAGATIONINFO info, double rxPower_dbm, double *Interference, int CA_ID, bool isDownlink)
void LTENR_Calculate_Interference(ptrLTENR_PROPAGATIONINFO info, double rxPower_dbm, double *Interference, int layerId, int CA_ID, bool isDownlink)
ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE GradedDistanceBasedWynerInterferenceheadUplink
static double fn_GetEdgeInterference(NETSIM_ID gNBiID, NETSIM_ID gNBjID, double dUEgnbi, double dUEgnbj, bool isDownlink)
struct stru_GRADED_DISTANCE_BASED_WYNER_INTERFERENCE * ptrGRADED_DISTANCE_BASED_WYNER_INTERFERENCE
void LTENR_fn_ExactGeometricModelInterference(ptrLTENR_PROPAGATIONINFO info, double rxPower_dbm, double *Interference, int layerId, int CA_ID, bool isDownlink)
struct stru_GRADED_DISTANCE_BASED_WYNER_INTERFERENCE GRADED_DISTANCE_BASED_WYNER_INTERFERENCE
ptrLTENR_ASSOCIATEDUEPHYINFO LTENR_ASSOCIATEDUEPHYINFO_GET(NETSIM_ID gnbId, NETSIM_ID gnbIf, NETSIM_ID ueId, NETSIM_ID ueIf)
Definition: LTENR_PHY.c:816
#define _getch()
Definition: Linux.h:44
static const char pathSeperator[5]
Definition: Linux.h:71
#define malloc(s)
Definition: Memory.h:30
#define free(p)
Definition: Memory.h:31
#define calloc(c, s)
Definition: Memory.h:29
#define MW_TO_DBM(mw)
#define DBM_TO_MW(dbm)
#define NEGATIVE_DBM
#define DEVICE(DeviceId)
Definition: Stack.h:769
NETSIM_ID fn_NetSim_Stack_GetDeviceId_asName(const char *name)
EXPORTED char * pszIOPath
Definition: Stack.h:842
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
#define INFINITY
Definition: Stack.h:66
struct stru_GRADED_DISTANCE_BASED_WYNER_INTERFERENCE * next
LTENR_DEVICETYPE deviceType
Definition: LTE_NR.h:440
LTENR_CELL_TYPES SecCellType
Definition: LTE_NR.h:511
ptrLTENR_PROPAGATIONINFO propagationInfo[MAX_CA_COUNT]
Definition: LTENR_PHY.h:140
NETSIM_ID gnbIf
Definition: LTENR_PHY.h:180
ptrLTENR_PROPAGATIONCONFIG propagationConfig
Definition: LTENR_PHY.h:207
NETSIM_ID gnbId
Definition: LTENR_PHY.h:179
LTENR_CELL_INTERFERENCEACE_TYPE DownlinkInterferenceModel
__IN__ NETSIM_ID gnbId
Definition: LTENR_PHY.h:44
__IN__ NETSIM_ID gnbIf
Definition: LTENR_PHY.h:45
__IN__ NETSIM_ID ueId
Definition: LTENR_PHY.h:46
__IN__ NETSIM_ID ueIf
Definition: LTENR_PHY.h:47
struct stru_LTENR_propagationInfo::stru_powers uplink
__IN__ double centralFrequency_MHz
Definition: LTENR_PHY.h:50
struct stru_LTENR_propagationInfo::stru_powers downlink