NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
LTENR_EPC.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 "stdafx.h"
27#include "LTENR_EPC.h"
28#pragma endregion
29
30#pragma region EPC_INIT
31void LTENR_EPC_ALLOC(NETSIM_ID d, NETSIM_ID in)
32{
33 ptrLTENR_EPC epc = calloc(1, sizeof * epc);
34 LTENR_EPC_SET(d, in, epc);
35 epc->d = d;
36 epc->in = in;
37}
38#pragma endregion
39
40#pragma region EPC_ASSOCIATION
41void LTENR_EPC_ASSOCIATION(NETSIM_ID epcId, NETSIM_ID epcIf,
42 NETSIM_ID gnbId, NETSIM_ID gnbIf,
43 NETSIM_ID ueId, NETSIM_ID ueIf)
44{
45 ptrLTENR_EPC_HLR hlr = LTENR_EPC_HLR_ALLOC();
46 hlr->gnbId = gnbId;
47 hlr->gnbIf = gnbIf;
48 hlr->ueId = ueId;
49 hlr->ueIf = ueIf;
50
51 ptrLTENR_EPC epc = LTENR_EPC_GET(epcId, epcIf);
52 LTENR_EPC_HLR_ADD(epc, hlr);
53}
54
55void LTENR_GNB_SETEPC(NETSIM_ID d, NETSIM_ID in,
56 NETSIM_ID* e, NETSIM_ID* ein)
57{
58 NETSIM_ID i;
59 NETSIM_ID r;
60 NETSIM_ID rin;
61
62 for (i = 0; i < DEVICE(d)->nNumOfInterface; i++)
63 {
64 if (i + 1 == in)
65 continue;
66
67 fn_NetSim_Stack_GetConnectedDevice(d, i + 1, &r, &rin);
68 if (r != 0) {
69 if (DEVICE_INTERFACE(r, rin)->nLocalNetworkProtocol == MAC_PROTOCOL_LTE ||
70 DEVICE_INTERFACE(r, rin)->nLocalNetworkProtocol == MAC_PROTOCOL_LTE_NR)
71 {
72 *e = r;
73 *ein = rin;
74 break;
75 }
76 }
77 }
78}
79
80ptrLTENR_EPC_HLR LTENR_EPC_FindHLR(NETSIM_ID d, NETSIM_ID in, NETSIM_ID dest)
81{
82 ptrLTENR_EPC epc = LTENR_EPC_GET(d, in);
83 ptrLTENR_EPC_HLR hlr = epc->hlr;
84 while (hlr)
85 {
86 if (hlr->ueId == dest)
87 return hlr;
88 LTENR_EPC_HLR_NEXT(hlr);
89 }
90 return NULL;
91}
92
93ptrLTENR_EPC_HLR LTENR_EPC_FindHLR_For_GNB(NETSIM_ID d, NETSIM_ID in, NETSIM_ID dest, NETSIM_ID gnbID)
94{
95 ptrLTENR_EPC epc = LTENR_EPC_GET(d, in);
96 ptrLTENR_EPC_HLR hlr = epc->hlr;
97 while (hlr)
98 {
99 if (hlr->ueId == dest && hlr->gnbId == gnbID)
100 return hlr;
101 LTENR_EPC_HLR_NEXT(hlr);
102 }
103 return NULL;
104}
105
106NETSIM_ID LTENR_EPC_HLR_FindOutInterface(NETSIM_ID d, NETSIM_ID dest)
107{
108 NETSIM_ID i;
109 for (i = 0; i < DEVICE(d)->nNumOfInterface; i++)
110 {
111 if (DEVICE_INTERFACE(d, i + 1)->nLocalNetworkProtocol == MAC_PROTOCOL_LTE_NR ||
112 DEVICE_INTERFACE(d, i + 1)->nLocalNetworkProtocol == MAC_PROTOCOL_LTE)
113 {
114 if(LTENR_EPC_FindHLR(d, i + 1, dest))
115 return i + 1;
116 }
117 }
118 return 0;
119}
120
121NETSIM_ID LTENR_NSA_EPC_HLR_FindOutInterface(NETSIM_ID d, NETSIM_ID dest)
122{
123 NETSIM_ID i;
124 NETSIM_ID splitID = fn_NetSim_LTENR_NSA_Splitting_Alogrithm_For_EPC(dest);
125 for (i = 0; i < DEVICE(d)->nNumOfInterface; i++)
126 {
127 if (DEVICE_INTERFACE(d, i + 1)->nLocalNetworkProtocol == MAC_PROTOCOL_LTE_NR ||
128 DEVICE_INTERFACE(d, i + 1)->nLocalNetworkProtocol == MAC_PROTOCOL_LTE)
129 {
130 ptrLTENR_EPC_HLR hlr = LTENR_EPC_FindHLR(d, i + 1, dest);
131 if (hlr) {
132 if (hlr->gnbId == splitID)
133 return i + 1;
134 }
135
136 }
137 }
138 return 0;
139}
140
141NETSIM_ID LTENR_NSA_EPC_HLR_FindOutInterface_FOR_GNB(NETSIM_ID d, NETSIM_ID dest, NETSIM_ID gnbID)
142{
143 NETSIM_ID i;
144 for (i = 0; i < DEVICE(d)->nNumOfInterface; i++)
145 {
146 if (DEVICE_INTERFACE(d, i + 1)->nLocalNetworkProtocol == MAC_PROTOCOL_LTE_NR ||
147 DEVICE_INTERFACE(d, i + 1)->nLocalNetworkProtocol == MAC_PROTOCOL_LTE)
148 {
149 ptrLTENR_EPC_HLR hlr = LTENR_EPC_FindHLR(d, i + 1, dest);
150 if (hlr) {
151 if (hlr->gnbId == gnbID)
152 return i + 1;
153 }
154
155 }
156 }
157 return 0;
158}
159#pragma endregion
160
161#pragma region EPC_PACKETPROCESSING
162void LTENR_EPC_NetworkOut()
163{
164 NetSim_PACKET* packet = pstruEventDetails->pPacket;
165 NETSIM_ID d = pstruEventDetails->nDeviceId;
166 //NETSIM_ID in = pstruEventDetails->nInterfaceId;
167
168 if (isBroadcastPacket(packet) ||
169 isMulticastPacket(packet))
170 {
171 //No broadcast and multicast
172 fn_NetSim_Packet_FreePacket(packet);
173 return;
174 }
175
176 NETSIM_ID dest = get_first_dest_from_packet(packet);
177 NETSIM_ID outIn = LTENR_EPC_HLR_FindOutInterface(d, dest);
178 NETSIM_ID in = pstruEventDetails->nInterfaceId;
179 ptrLTENR_PROTODATA data = LTENR_PROTODATA_GET(d, in);
180 if (data->isDCEnable && !isLTENRControlPacket(packet)) {
181 if (fn_NetSim_LTENR_NSA_IS_CORE_SPLIT_EXISTS(d, in) ||
182 fn_NetSim_LTENR_NSA_IS_OPTION_X_EXISTS(d, in)) {
183 outIn = LTENR_NSA_EPC_HLR_FindOutInterface(d, dest);
184 }
185 }
186
187 if (!outIn)
188 {
189 print_ltenr_log("Device %d is not connected to EPC %d\n", dest, d);
190 fn_NetSim_Packet_FreePacket(packet);
191 return;
192 }
193
194 NetSim_BUFFER* buf = DEVICE_ACCESSBUFFER(d, outIn);
195 if (!fn_NetSim_GetBufferStatus(buf))
196 {
197 pstruEventDetails->nEventType = MAC_OUT_EVENT;
198 pstruEventDetails->nInterfaceId = outIn;
199 pstruEventDetails->nProtocolId = DEVICE_MACLAYER(d, outIn)->nMacProtocolId;
200 pstruEventDetails->pPacket = NULL;
201 fnpAddEvent(pstruEventDetails);
202 }
203 fn_NetSim_Packet_AddPacketToList(buf, packet, 0);
204 pstruEventDetails->pPacket = NULL;
205}
206#pragma endregion