JIRA-ID ODUHIGH-275 classification of logs of RLC part -3
[o-du/l2.git] / src / 5gnrrlc / kw_tenb_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:  l2_tenb_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 "kw_err.h"        /* RLC error options */
38 #include "kw_env.h"        /* RLC environment options */
39 #include "kw.h"            /* RLC defines */
40 #include "kw_ul.h"
41
42 /* extern (.x) include files */
43 #include "lkw.x"           /* LKW */
44 #include "ckw.x"           /* CKW */
45 #include "kwu.x"           /* KWU */
46 #include "rgu.x"           /* RGU */
47
48 #include "kw.x"
49 #include "kw_ul.x"
50 #ifdef TENB_STATS
51 #include "l2_tenb_stats.x"    /* Total EnodeB Stats declarations */
52 #endif
53
54 #ifdef TENB_STATS
55 TSL2CellStatsCb* l2CellStats[L2_STATS_MAX_CELLS];
56 TSL2UeStatsCb*   l2UeStats[L2_STATS_MAX_UES];
57 CmLListCp        freeL2UeStatsLst; /*!< Free Pool of UE stats Blocks */
58 CmLListCp        inUseL2UeStatsLst;/*!< In Use Pool of UE stats Blocks */
59
60 /*
61 *
62 *       Fun:   TSL2AllocStatsMem
63 *
64 *       Desc:  Pre-Allocate Memory for L2 stats BLOCKs 
65 *
66 *       Ret:   
67 *
68 *       Notes: None
69 *
70 *
71 */
72 Void TSL2AllocStatsMem(Region region,Pool pool)
73 {
74    uint32_t cnt=0;
75
76    cmLListInit(&inUseL2UeStatsLst);     
77    cmLListInit(&freeL2UeStatsLst);      
78    for (cnt=0; cnt < L2_STATS_MAX_CELLS; cnt++)
79    {
80                   if(NULL == l2CellStats[cnt])
81                   {
82                  if (SGetSBuf(region, pool, (Data **)&l2CellStats[cnt],
83                                          (Size)sizeof (TSL2CellStatsCb)) != ROK)
84                  {
85                                 printf("\n STATS Unexpected MEM Alloc Failure\n");
86                  }
87           }
88         memset(l2CellStats[cnt], 0x00, sizeof(TSL2CellStatsCb));
89    }
90
91    for (cnt=0; cnt < L2_STATS_MAX_UES; cnt++)
92    {
93         TSL2UeStatsCb *statsCb = l2UeStats[cnt];
94                   if(NULL == statsCb)
95                   {
96                  if (SGetSBuf(region, pool, (Data **)&statsCb,
97                                          (Size)sizeof (TSL2UeStatsCb)) != ROK)
98                  {
99                                 printf("\n STATS Unexpected MEM Alloc Failure at %d\n", (int)cnt);
100                  }
101                   }
102         memset(statsCb, 0x00, sizeof(TSL2UeStatsCb));
103         statsCb->lnk.node = (PTR)statsCb;
104         cmLListAdd2Tail(&freeL2UeStatsLst, &statsCb->lnk);
105         l2UeStats[cnt] = statsCb;
106    }
107
108    return;
109 }
110
111 /*
112 *
113 *       Fun:   TSL2AllocUeStatsBlk
114 *
115 *       Desc:  Assign Stats Block for this UE[RNTI] 
116 *
117 *       Ret:   
118 *
119 *       Notes: None
120 *
121 *
122 */
123 TSL2UeStatsCb* TSL2AllocUeStatsBlk (uint16_t rnti)
124 {
125    CmLList          *tmp = NULLP;
126    TSL2UeStatsCb  *statsCb = NULLP;
127
128    tmp = freeL2UeStatsLst.first;
129    if (tmp == NULLP)
130    {
131       printf("\n STATS Unexpected Mem BLK unavailable for UE %d\n", rnti);
132    }
133    cmLListDelFrm(&freeL2UeStatsLst, tmp);
134    statsCb = (TSL2UeStatsCb *)(tmp->node);
135    cmLListAdd2Tail(&inUseL2UeStatsLst, tmp);
136
137    statsCb->stats.rnti = (uint32_t)rnti;
138    statsCb->inUse = TRUE;
139
140    return (statsCb);
141 }
142
143 /*
144 *
145 *       Fun:   TSL2DeallocUeStatsBlk
146 *
147 *       Desc:  Deassign Stats Block for this UE[RNTI] 
148 *
149 *       Ret:   
150 *
151 *       Notes: None
152 *
153 *
154 */
155 Void TSL2DeallocUeStatsBlk(uint16_t rnti,TSL2UeStatsCb *statsCb)
156 {
157    statsCb->inUse = FALSE;
158    cmLListDelFrm(&inUseL2UeStatsLst, &statsCb->lnk);
159    freeL2UeStatsLst.crnt = freeL2UeStatsLst.first;
160    cmLListInsAfterCrnt(&freeL2UeStatsLst, &statsCb->lnk);
161
162    return;
163 }
164
165 /*
166 *
167 *       Fun:   TSL2AllocCellStatsBlk
168 *
169 *       Desc:  Assign Stats Block for this CELL[CELLID] 
170 *
171 *       Ret:   
172 *
173 *       Notes: None
174 *
175 *
176 */
177 TSL2CellStatsCb* TSL2AllocCellStatsBlk(uint32_t cellId)
178 {
179    if (cellId != 1)
180    {
181       printf("\n STATS Unexpected CellID = %d\n", (int)cellId);
182    }
183
184    return (l2CellStats[cellId-1]);
185 }
186
187 /*
188 *
189 *       Fun:   TSL2DeallocCellStatsBlk
190 *
191 *       Desc:  Deassign Stats Block for this CELL[CELLID] 
192 *
193 *       Ret:   
194 *
195 *       Notes: None
196 *
197 *
198 */
199 Void TSL2DeallocCellStatsBlk(uint32_t cellId)
200 {
201
202    return;
203 }
204
205 /*
206 *
207 *       Fun:   TSL2SendStatsToApp
208 *
209 *       Desc:  Collates and Sends STATS to Application 
210 *              Send UE STATS first. 10 UEs are grouped in one message.
211 *              Followed by CELL Stats. All CELLS are grouped in one msg.
212 *              At Reception of CELL stats APP assumes STATS reception cycle is complete.
213 *
214 *       Ret:   
215 *
216 *       Notes: None
217 *
218 *
219 */
220 Void TSL2SendStatsToApp(Pst    *pst, SuId   suId)
221 {
222    uint32_t idx;
223
224    for (idx = 0; idx < L2_STATS_MAX_UES; idx++)
225    {
226       TSL2UeStatsCb *statsCb = l2UeStats[idx];
227       uint32_t rnti;
228       if (statsCb->inUse != TRUE)
229       {
230          continue;
231       }
232       if (pst->selector == 0)
233       {
234          /* Loose Coupling */
235          TSInfPkSndL2UeStats(pst, suId, &statsCb->stats);
236       }
237       else
238       {
239 #ifdef PX
240          /* Tight Coupling */
241          TSInfHdlL2UeStatsInd(pst, suId, &statsCb->stats);
242 #endif
243       }
244       rnti = statsCb->stats.rnti;
245       memset(&statsCb->stats.nonPersistent, 0x00, sizeof(statsCb->stats.nonPersistent));
246       /* memset(&statsCb->stats, 0x00, sizeof(TSInfL2UeStats)); */
247       statsCb->stats.rnti = rnti;
248    }
249
250    /* Allocate mBuf for CELLSTATS */
251    for (idx = 0; idx < L2_STATS_MAX_CELLS; idx++)
252    {
253       TSL2CellStatsCb *statsCellCb = l2CellStats[idx];
254       uint32_t cellId;
255       if (pst->selector == 0)
256       {
257          /* Loose Coupling */
258          TSInfPkSndL2CellStats(pst, suId, l2CellStats[idx]);
259       }
260       else
261       {
262 #ifdef PX
263          /* Tight Coupling */
264          TSInfHdlL2CellStatsInd(pst, suId, l2CellStats[idx]);
265 #endif
266       }
267       cellId = statsCellCb->cellId;
268       memset(l2CellStats[idx], 0x00, sizeof(TSInfL2CellStats));
269       statsCellCb->cellId = cellId;
270    }
271    return;
272 }
273 #endif /* TENB_STATS */
274 /**********************************************************************
275          End of file
276 **********************************************************************/