NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
LTENR_RLC.h
1#pragma once
2/************************************************************************************
3* Copyright (C) 2023 *
4* TETCOS, Bangalore. India *
5* *
6* Tetcos owns the intellectual property rights in the Product and its content. *
7* The copying, redistribution, reselling or publication of any or all of the *
8* Product or its content without express prior written consent of Tetcos is *
9* prohibited. Ownership and / or any other right relating to the software and all *
10* intellectual property rights therein shall remain at all times with Tetcos. *
11* *
12* This source code is licensed per the NetSim license agreement. *
13* *
14* No portion of this source code may be used as the basis for a derivative work, *
15* or used, for any purpose other than its intended use per the NetSim license *
16* agreement. *
17* *
18* This source code and the algorithms contained within it are confidential trade *
19* secrets of TETCOS and may not be used as the basis for any other software, *
20* hardware, product or service. *
21* *
22* Author: Shashi Kant Suman *
23* *
24* ----------------------------------------------------------------------------------*/
25#ifndef _NETSIM_LTENR_RLC_H_
26#define _NETSIM_LTENR_RLC_H_
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#pragma region HEADER_FILES
33#include "LTENR_Buffer.h"
34#include "LTENR_RLCMSG.h"
35#include "List.h"
36#pragma endregion
37
38#pragma region MACROS
39//Window Size
40#if RLC_AM_SN_SIZE == 12
41#define AM_Window_Size 0x800
42#elif RLC_AM_SN_SIZE == 18
43#define AM_Window_Size 0x20000
44#endif
45
46#if RLC_UM_SN_SIZE == 6
47#define UM_Window_Size 0x20
48#elif RLC_UM_SN_SIZE == 12
49#define UM_Window_Size 0x800
50#endif
51
52 //Logical channel mapping
53#define LTENR_RLC_IS_LOGICALCHANNEL_FOR_TM(ch) (((ch) == LTENR_LOGICALCHANNEL_BCCH) || \
54 ((ch) == LTENR_LOGICALCHANNEL_CCCH) || \
55 ((ch) == LTENR_LOGICALCHANNEL_PCCH))
56
57#define LTENR_RLC_IS_LOGICALCHANNEL_FOR_UM(ch) (((ch) == LTENR_LOGICALCHANNEL_DTCH))
58
59#define LTENR_RLC_IS_LOGICALCHANNEL_FOR_AM(ch) (((ch) == LTENR_LOGICALCHANNEL_DCCH) || \
60 ((ch) == LTENR_LOGICALCHANNEL_DTCH))
61
62 //a SN falls within the reassembly window if (RX_Next_Highest – UM_Window_Size) <= SN <RX_Next_Highest;
63#define LTENR_RLC_UM_IsSNFallsInReassemblyWindows(entity,sn) ((((entity)->UM.RX_Next_Highest - UM_Window_Size) <= (sn)) && ((sn)<(entity)->UM.RX_Next_Highest))
64#pragma endregion
65
66#pragma region RLC_RECEPTION_BUFFER
68 {
69 UINT reassembleCount;
70 UINT SN;
71 UINT lastSDUSO;
72 bool isLastSDUReceived;
73 NetSim_PACKET* head;
74 NetSim_PACKET* tail;
75 _ptr_ele ele;
76 }LTENR_RLC_RECEPTIONBUFFER, *ptrLTENR_RLC_RECEPTIONBUFFER;
77#define LTENR_RLC_RECEPTIONBUFFER_ALLOC() ((ptrLTENR_RLC_RECEPTIONBUFFER)list_alloc(sizeof(LTENR_RLC_RECEPTIONBUFFER),offsetof(LTENR_RLC_RECEPTIONBUFFER,ele)))
78#define LTENR_RLC_RECEPTIONBUFFER_NEXT(buf) ((ptrLTENR_RLC_RECEPTIONBUFFER)LIST_NEXT(buf))
79#define LTENR_RLC_RECEPTIONBUFFER_ADD(ls,mem) (LIST_ADD_LAST(ls,mem))
80#pragma endregion
81
82#pragma region RLC_BUFFER
84 {
85 SI si;
86 UINT SN;
87 UINT16 SO;
88
89 UINT retxCount;
90 LTENR_LOGICALCHANNEL channel;
91 NetSim_PACKET* packet;
92 bool isMarkedForRemoval;
93 bool isFragmented;
94 struct stru_LTENR_RLCBuffer_Data* next;
95 struct stru_LTENR_RLCBuffer_Data* prev;
96 }LTENR_RLCBUFFER_DATA, *ptrLTENR_RLCBUFFER_DATA;
97
98 typedef struct stru_LTENR_RLCBuffer
99 {
100 ptrLTENR_RLCBUFFER_DATA head;
101 ptrLTENR_RLCBUFFER_DATA tail;
102 }LTENR_RLCBUFFER, * ptrLTENR_RLCBUFFER;
103 ptrLTENR_RLCBUFFER LTENR_RLCBUFFER_ALLOC();
104 void LTENR_RLCBUFFER_FREE(ptrLTENR_RLCBUFFER buffer);
105 void LTENR_RLCBUFFER_ADD_DATA(ptrLTENR_RLCBUFFER buffer, ptrLTENR_RLCBUFFER_DATA data);
106 void LTENR_RLCBUFFER_REMOVE_DATA(ptrLTENR_RLCBUFFER buffer, ptrLTENR_RLCBUFFER_DATA data);
107 ptrLTENR_RLCBUFFER_DATA LTENR_RLCBUFFER_GETHEAD(ptrLTENR_RLCBUFFER buffer);
108#define LTENR_RLCBUFFER_NEXT(buf) ((buf) = (buf)->next)
109#define LTENR_RLCBuffer_MarkForRemoval(buf) ((buf)->isMarkedForRemoval = true)
110#pragma endregion
111
112#pragma region RLC_FUN_DEF
113 void LTENR_RLCBuffer_AddPacket(ptrLTENR_RLCBUFFER buffer, NetSim_PACKET* packet,
114 UINT sn, UINT16 so, LTENR_LOGICALCHANNEL channel);
115 void LTENR_RLCBuffer_UpdateBuffer(ptrLTENR_RLCBUFFER buffer);
116 ptrLTENR_RLCBUFFER LTENR_RLCBUFFER_FindAndRemoveAllBySN(ptrLTENR_RLCBUFFER buffer, UINT sn);
117 ptrLTENR_RLCBUFFER_DATA LTENR_RLCBUFFER_FindAndRemoveBySNSO(ptrLTENR_RLCBUFFER buffer, UINT sn, UINT16 so);
118#pragma endregion
119
120#pragma region RLC_AM_STATUS
122 {
123 SI si;
124 UINT SN;
125 UINT16 SO;
126 _ptr_ele ele;
127 }LTENR_RLCAM_STATUS, *ptrLTENR_RLCAM_STATUS;
128#define LTENR_RLCAM_STATUS_ALLOC() ((ptrLTENR_RLCAM_STATUS)list_alloc(sizeof(LTENR_RLCAM_STATUS),offsetof(LTENR_RLCAM_STATUS,ele)))
129#define LTENR_RLCAM_STATUS_NEXT(status) (status=(ptrLTENR_RLCAM_STATUS)LIST_NEXT(status))
130#pragma endregion
131
132#pragma region RLC_ENTITY
133 typedef struct stru_LTENR_RLCEntity
134 {
135 NETSIM_ID d;
136 NETSIM_ID in;
137 NETSIM_ID peerId;
138 NETSIM_ID peerIf;
139
140 LTENR_RLCMODE rlcMode;
141 bool isTransmittingRLCEntity;
142 bool isReceivingRLCEntity;
143
145 {
146 //RLC-AM Transmitting side state variable
147 UINT TX_Next_Ack;
148 UINT TX_Next;
149 UINT POLL_SN;
150 UINT TX_HighestSN;
151
152 //RLC-AM Transmitting side counter
153 UINT PDU_WITHOUT_POLL;
154 UINT BYTE_WITHOUT_POLL;
155 UINT RETX_COUNT;
156
157 //RLC-AM Receiving side state variable
158 UINT RX_Next;
159 UINT RX_Next_Status_Trigger;
160 UINT RX_Highest_Status;
161 UINT RX_Next_Highest;
162
163 ptrLTENR_RLC_RECEPTIONBUFFER receptionBuffer;
164 bool isStatusReportDelayed;
165 bool isConstructStatusReortDelayed;
166 ptrLTENR_RLCAM_STATUS recvdInfo;
167 }AM;
168
170 {
171 //RLC-UM Transmitting side state variables and counters
172 UINT TX_Next;
173
174 //RLC-UM Receiving side state variables and counters
175 UINT RX_Timer_Trigger;
176 UINT RX_Next_Reassembly;
177 UINT RX_Next_Highest;
178
179 ptrLTENR_RLC_RECEPTIONBUFFER receptionBuffer;
180 }UM;
181
182 //Timer
183 double t_PollRetransmit;
184 bool isPollRetransmitTimerStarted;
185 UINT64 pollRetransmitTimerId;
186
187 double t_Reassembly;
188 bool isReassemblyTimerStarted;
189 UINT64 reassemblyTimerId;
190
191 double t_StatusProhibit;
192 bool isStatusProhibitTimerStarted;
193 UINT64 statusProhibitTimerId;
194
195 //Config parameter
196 UINT maxRetxThreshold;
197 UINT pollPDU;
198 UINT pollByte;
199
200 //Buffer
201 ptrLTENR_RLCBUFFER transmissionBuffer;
202 ptrLTENR_RLCBUFFER transmittedBuffer;
203 ptrLTENR_RLCBUFFER retransmissionBuffer;
204 UINT bufferStatus[LTENR_LOGICALCHANNEL_LAST];
205
206 _ptr_ele ele;
207 }LTENR_RLCENTITY, *ptrLTENR_RLCENTITY;
208#define LTENR_RLCENTITY_ALLOC() (list_alloc(sizeof(LTENR_RLCENTITY),offsetof(LTENR_RLCENTITY,ele)))
209#define LTENR_RLCENTITY_NEXT(entity) (LIST_NEXT(entity))
210#define LTENR_RLCENTITY_ADD(rlc,e) (LIST_ADD_LAST(&((rlc)->rlcEntities),e))
211#define LTENR_RLCENTITY_REMOVE(rlc,e) (LIST_REMOVE(&((rlc)->rlcEntities),e))
212 //void LTENR_RLCENTITY_ADD(void* var, ptrLTENR_RLCENTITY entity);
213 //void LTENR_RLCENTITY_REMOVE(void* var, ptrLTENR_RLCENTITY entity);
214#pragma endregion
215
216#pragma region RLC_VAR_AND_ITS_API
217 typedef struct stru_LTENR_RLCVar
218 {
219 double t_reassembly;
220 //ptrLTENR_RLCENTITY rlcEntities;
221 ptrLTENR_RLCENTITY***** rlcEntities;
222 }LTENR_RLCVAR, *ptrLTENR_RLCVAR;
223#define LTENR_RLC_GET_TM_TRANSMITTING_ENTITY(d,in,r,rin) (LTENR_RLC_FINDENTITY(d,in,r,rin,LTENR_RLCMODE_TM,true,false))
224#define LTENR_RLC_GET_TM_RECEIVING_ENTITY(d,in,r,rin) (LTENR_RLC_FINDENTITY(d,in,r,rin,LTENR_RLCMODE_TM,false,true))
225#define LTENR_RLC_GET_UM_TRANSMITTING_ENTITY(d,in,r,rin) (LTENR_RLC_FINDENTITY(d,in,r,rin,LTENR_RLCMODE_UM,true,false))
226#define LTENR_RLC_GET_UM_RECEIVING_ENTITY(d,in,r,rin) (LTENR_RLC_FINDENTITY(d,in,r,rin,LTENR_RLCMODE_UM,false,true))
227#define LTENR_RLC_GET_AM_TRANSMITTING_ENTITY(d,in,r,rin) (LTENR_RLC_FINDENTITY(d,in,r,rin,LTENR_RLCMODE_AM,true,true))
228#define LTENR_RLC_GET_AM_RECEIVING_ENTITY(d,in,r,rin) (LTENR_RLC_FINDENTITY(d,in,r,rin,LTENR_RLCMODE_AM,true,true))
229#pragma endregion
230
231#pragma region FUN_DEF
232 //Function prototype
233 //RLC TM
234 void LTENR_RLC_TM_HandlePDUFromUpperLayer();
235
236 //RLC UM
237 void LTENR_RLC_UM_HandlePDUFromUpperLayer();
238 UINT LTENR_RLC_UM_SEND_PDU(NETSIM_ID d, NETSIM_ID in,
239 NETSIM_ID r, NETSIM_ID rin,
240 UINT size, LTENR_LOGICALCHANNEL logicalChannel);
241 void LTENR_RLC_UM_RECEIVE_PDU();
242 void LTENR_RLC_UM_Handle_t_reassemblyTimer();
243
244 //RLC AM
245 void LTENR_RLCAM_HandlePDUFromUpperLayer();
246 UINT LTENR_RLCAM_SEND_PDU(NETSIM_ID d, NETSIM_ID in,
247 NETSIM_ID r, NETSIM_ID rin,
248 UINT size, LTENR_LOGICALCHANNEL logicalChannel);
249 void LTENR_RLC_AM_RECEIVE_PDU();
250 void LTENR_RLCAM_Start_t_ReassemblyTimer(ptrLTENR_RLCENTITY entity);
251 void LTENR_RLCAM_Handle_t_reassemblyTimer();
252 void LTENR_RLCAM_Handle_t_PollRetransmitTimer();
253 void LTENR_RLCAM_Handle_t_StatusProhibitTimer();
254 void LTENR_RLCAM_ReceiveStatusPDU();
255 void LTENR_RLCAM_Start_t_PollRetransmitTimer(ptrLTENR_RLCENTITY entity);
256 void LTENR_RLCAM_Stop_t_PollRetransmitTimer(ptrLTENR_RLCENTITY entity);
257 //RLC Entity
258 ptrLTENR_RLCENTITY LTENR_RLC_FINDENTITY(NETSIM_ID d, NETSIM_ID in,
259 NETSIM_ID peerId, NETSIM_ID peerIf,
260 LTENR_RLCMODE mode,
261 bool isTransmitting,
262 bool isReceiving);
263 void LTENR_RLC_ESTABLISHENTITYALL(NETSIM_ID d, NETSIM_ID in,
264 NETSIM_ID peerId, NETSIM_ID peerIf);
265 void LTENR_RLC_TMESTABLISHENTITYALL(NETSIM_ID d, NETSIM_ID in,
266 NETSIM_ID peerId, NETSIM_ID peerIf);
267 void LTENR_RLC_ASSOCIATION(NETSIM_ID d, NETSIM_ID in,
268 NETSIM_ID peerId, NETSIM_ID peerIf,
269 bool isAssociated);
270#pragma endregion
271
272#ifdef __cplusplus
273}
274#endif // __cplusplus
275#endif //_NETSIM_LTENR_RLC_H_