c01228d84cf23373f7753efe7edd5697f4e97934
[o-du/l2.git] / src / 5gnrrlc / rlc_stats.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /**********************************************************************
20  
21     Name:  
22  
23     Type:   C include file
24  
25     Desc:   
26  
27     File:  rlc_stats.c
28  
29 **********************************************************************/
30
31 /* header (.h) include files */
32 #include "common_def.h"
33 #include "lkw.h"           /* LKW defines */
34 #include "ckw.h"           /* CKW defines */
35 #include "kwu.h"           /* KWU defines */
36 #include "rgu.h"           /* RGU defines */
37 #include "rlc_err.h"        /* RLC error options */
38 #include "rlc_env.h"        /* RLC environment options */
39
40 /* extern (.x) include files */
41 #include "lkw.x"           /* LKW */
42 #include "ckw.x"           /* CKW */
43 #include "kwu.x"           /* KWU */
44 #include "rgu.x"           /* RGU */
45
46 #ifdef TENB_STATS
47 #include "l2_tenb_stats.x"    /* Total EnodeB Stats declarations */
48 #endif
49
50 #include "rlc_utils.h"            /* RLC defines */
51 #include "rlc_ul.h"
52
53 #ifdef TENB_STATS
54 TSL2CellStatsCb* l2CellStats[L2_STATS_MAX_CELLS];
55 TSL2UeStatsCb*   l2UeStats[L2_STATS_MAX_UES];
56 CmLListCp        freeL2UeStatsLst; /*!< Free Pool of UE stats Blocks */
57 CmLListCp        inUseL2UeStatsLst;/*!< In Use Pool of UE stats Blocks */
58
59 /*
60 *
61 *       Fun:   TSL2AllocStatsMem
62 *
63 *       Desc:  Pre-Allocate Memory for L2 stats BLOCKs 
64 *
65 *       Ret:   
66 *
67 *       Notes: None
68 *
69 *
70 */
71 Void TSL2AllocStatsMem(Region region,Pool pool)
72 {
73    uint32_t cnt=0;
74
75    cmLListInit(&inUseL2UeStatsLst);     
76    cmLListInit(&freeL2UeStatsLst);      
77    for (cnt=0; cnt < L2_STATS_MAX_CELLS; cnt++)
78    {
79       if(NULL == l2CellStats[cnt])
80       {
81          if (SGetSBuf(region, pool, (Data **)&l2CellStats[cnt],
82                   (Size)sizeof (TSL2CellStatsCb)) != ROK)
83          {
84             DU_LOG("\nERROR  -->  RLC : STATS Unexpected MEM Alloc Failure\n");
85          }
86       }
87       memset(l2CellStats[cnt], 0x00, sizeof(TSL2CellStatsCb));
88    }
89
90    for (cnt=0; cnt < L2_STATS_MAX_UES; cnt++)
91    {
92       TSL2UeStatsCb *statsCb = l2UeStats[cnt];
93       if(NULL == statsCb)
94       {
95          if (SGetSBuf(region, pool, (Data **)&statsCb,
96                   (Size)sizeof (TSL2UeStatsCb)) != ROK)
97          {
98             DU_LOG("\nERROR  -->   RLC : STATS Unexpected MEM Alloc Failure at %d\n", (int)cnt);
99          }
100       }
101       memset(statsCb, 0x00, sizeof(TSL2UeStatsCb));
102       statsCb->lnk.node = (PTR)statsCb;
103       cmLListAdd2Tail(&freeL2UeStatsLst, &statsCb->lnk);
104       l2UeStats[cnt] = statsCb;
105    }
106
107    return;
108 }
109
110 /*
111  *
112  *       Fun:   TSL2AllocUeStatsBlk
113  *
114  *       Desc:  Assign Stats Block for this UE[RNTI] 
115  *
116  *       Ret:   
117  *
118  *       Notes: None
119  *
120  *
121  */
122 TSL2UeStatsCb* TSL2AllocUeStatsBlk (uint16_t rnti)
123 {
124    CmLList          *tmp = NULLP;
125    TSL2UeStatsCb  *statsCb = NULLP;
126
127    tmp = freeL2UeStatsLst.first;
128    if (tmp == NULLP)
129    {
130       DU_LOG("\nERROR  -->  RLC :  STATS Unexpected Mem BLK unavailable for UE %d\n", rnti);
131    }
132    cmLListDelFrm(&freeL2UeStatsLst, tmp);
133    statsCb = (TSL2UeStatsCb *)(tmp->node);
134    cmLListAdd2Tail(&inUseL2UeStatsLst, tmp);
135
136    statsCb->stats.rnti = (uint32_t)rnti;
137    statsCb->inUse = TRUE;
138
139    return (statsCb);
140 }
141
142 /*
143  *
144  *       Fun:   TSL2DeallocUeStatsBlk
145  *
146  *       Desc:  Deassign Stats Block for this UE[RNTI] 
147  *
148  *       Ret:   
149  *
150  *       Notes: None
151  *
152  *
153  */
154 Void TSL2DeallocUeStatsBlk(uint16_t rnti,TSL2UeStatsCb *statsCb)
155 {
156    statsCb->inUse = FALSE;
157    cmLListDelFrm(&inUseL2UeStatsLst, &statsCb->lnk);
158    freeL2UeStatsLst.crnt = freeL2UeStatsLst.first;
159    cmLListInsAfterCrnt(&freeL2UeStatsLst, &statsCb->lnk);
160
161    return;
162 }
163
164 /*
165  *
166  *       Fun:   TSL2AllocCellStatsBlk
167  *
168  *       Desc:  Assign Stats Block for this CELL[CELLID] 
169  *
170  *       Ret:   
171  *
172  *       Notes: None
173  *
174  *
175  */
176 TSL2CellStatsCb* TSL2AllocCellStatsBlk(uint32_t cellId)
177 {
178    if (cellId != 1)
179    {
180       DU_LOG("\nERROR  -->  RLC : STATS Unexpected CellID = %d\n", (int)cellId);
181    }
182
183    return (l2CellStats[cellId-1]);
184 }
185
186 /*
187  *
188  *       Fun:   TSL2DeallocCellStatsBlk
189  *
190  *       Desc:  Deassign Stats Block for this CELL[CELLID] 
191  *
192  *       Ret:   
193  *
194  *       Notes: None
195  *
196  *
197  */
198 Void TSL2DeallocCellStatsBlk(uint32_t cellId)
199 {
200
201    return;
202 }
203
204 /*
205  *
206  *       Fun:   TSL2SendStatsToApp
207  *
208  *       Desc:  Collates and Sends STATS to Application 
209  *              Send UE STATS first. 10 UEs are grouped in one message.
210  *              Followed by CELL Stats. All CELLS are grouped in one msg.
211  *              At Reception of CELL stats APP assumes STATS reception cycle is complete.
212  *
213  *       Ret:   
214  *
215  *       Notes: None
216  *
217  *
218  */
219 Void TSL2SendStatsToApp(Pst    *pst, SuId   suId)
220 {
221    uint32_t idx;
222
223    for (idx = 0; idx < L2_STATS_MAX_UES; idx++)
224    {
225       TSL2UeStatsCb *statsCb = l2UeStats[idx];
226       uint32_t rnti;
227       if (statsCb->inUse != TRUE)
228       {
229          continue;
230       }
231       if (pst->selector == 0)
232       {
233          /* Loose Coupling */
234          TSInfPkSndL2UeStats(pst, suId, &statsCb->stats);
235       }
236       else
237       {
238 #ifdef PX
239          /* Tight Coupling */
240          TSInfHdlL2UeStatsInd(pst, suId, &statsCb->stats);
241 #endif
242       }
243       rnti = statsCb->stats.rnti;
244       memset(&statsCb->stats.nonPersistent, 0x00, sizeof(statsCb->stats.nonPersistent));
245       /* memset(&statsCb->stats, 0x00, sizeof(TSInfL2UeStats)); */
246       statsCb->stats.rnti = rnti;
247    }
248
249    /* Allocate mBuf for CELLSTATS */
250    for (idx = 0; idx < L2_STATS_MAX_CELLS; idx++)
251    {
252       TSL2CellStatsCb *statsCellCb = l2CellStats[idx];
253       uint32_t cellId;
254       if (pst->selector == 0)
255       {
256          /* Loose Coupling */
257          TSInfPkSndL2CellStats(pst, suId, l2CellStats[idx]);
258       }
259       else
260       {
261 #ifdef PX
262          /* Tight Coupling */
263          TSInfHdlL2CellStatsInd(pst, suId, l2CellStats[idx]);
264 #endif
265       }
266       cellId = statsCellCb->cellId;
267       memset(l2CellStats[idx], 0x00, sizeof(TSInfL2CellStats));
268       statsCellCb->cellId = cellId;
269    }
270    return;
271 }
272 #endif /* TENB_STATS */
273 /**********************************************************************
274   End of file
275  **********************************************************************/