blob: 1ec624c31d5507b3449306a11651c7ddc56b904b [file] [log] [blame]
ss412g1a79bdf2019-10-24 12:03:05 +03001// Copyright 2019 AT&T Intellectual Property
2// Copyright 2019 Nokia
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
nm755n2e268142019-11-28 16:40:23 +000016// This source code is part of the near-RT RIC (RAN Intelligent Controller)
17// platform project (RICP).
18
ss412g1a79bdf2019-10-24 12:03:05 +030019// TODO: High-level file comment.
20
21
aa7133@att.com84bd3342020-03-16 18:04:57 +020022
aa7133@att.com7b437f72020-03-30 13:25:54 +030023#include <3rdparty/oranE2/RANfunctions-List.h>
ss412g1a79bdf2019-10-24 12:03:05 +030024#include "sctpThread.h"
aa7133@att.com84bd3342020-03-16 18:04:57 +020025#include "BuildRunName.h"
dhirajverma5f132832021-06-17 17:27:54 +053026#include <unistd.h>
aa7133@att.comdf4f1822020-06-16 16:23:53 +030027//#include "3rdparty/oranE2SM/E2SM-gNB-NRT-RANfunction-Definition.h"
28//#include "BuildXml.h"
29//#include "pugixml/src/pugixml.hpp"
dhirajverma55e755b2021-06-29 02:01:47 +053030#include <pthread.h>
31#include <sys/time.h>
32#include <sys/inotify.h>
33#include <errno.h>
34#include <sys/stat.h>
czichy6dd00bc2023-03-03 15:43:29 +020035#include <arpa/inet.h>
dhirajverma55e755b2021-06-29 02:01:47 +053036
aa7133@att.com84bd3342020-03-16 18:04:57 +020037using namespace std;
38//using namespace std::placeholders;
ss412g3bac2da2020-01-05 11:52:19 +020039using namespace boost::filesystem;
ss412g4aeeda22020-06-16 14:12:41 +030040using namespace prometheus;
41
ss412g3bac2da2020-01-05 11:52:19 +020042
ss412g1a79bdf2019-10-24 12:03:05 +030043//#ifdef __cplusplus
44//extern "C"
45//{
46//#endif
47
ss412g3bac2da2020-01-05 11:52:19 +020048// need to expose without the include of gcov
49extern "C" void __gcov_flush(void);
dhirajverma55e755b2021-06-29 02:01:47 +053050#define LOG_FILE_CONFIG_MAP "CONFIG_MAP_NAME"
czichy6dd00bc2023-03-03 15:43:29 +020051#define E2AP_PPID 70 // as per E2GAP chapter 6.1
ss412g3bac2da2020-01-05 11:52:19 +020052
53static void catch_function(int signal) {
54 __gcov_flush();
55 exit(signal);
56}
57
58
ss412g1a79bdf2019-10-24 12:03:05 +030059BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::logger_mt)
60
61boost::shared_ptr<sinks::synchronous_sink<sinks::text_file_backend>> boostLogger;
pwpmurthyb1877062023-04-12 14:49:58 +000062// double cpuClock = 0.0;
aa7133@att.com41fcb3f2020-11-29 13:48:25 +020063bool jsonTrace = false;
ss412g1a79bdf2019-10-24 12:03:05 +030064
wahidw1d1a9b72021-09-24 17:35:28 +000065char* getinterfaceip()
66{
67 char hostname[256];
68 char *IP;
69 struct hostent *host_entry;
70 int retVal;
71 retVal = gethostname(hostname, sizeof(hostname));
72 if ( retVal == -1 )
73 return NULL;
74 host_entry = gethostbyname(hostname);
75 if ( host_entry == NULL )
76 return NULL;
77 IP = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0]));
78 return IP;
79}
80
dhirajverma55e755b2021-06-29 02:01:47 +053081
82static int enable_log_change_notify(const char* fileName)
83{
84 int ret = -1;
85 struct stat fileInfo;
86 if ( lstat(fileName,&fileInfo) == 0 )
87 {
88 ret = register_log_change_notify(fileName);
89 }
90 return ret;
91}
92
93
94static int register_log_change_notify(const char *fileName)
95{
96 pthread_attr_t cb_attr;
97 pthread_t tid;
98 pthread_attr_init(&cb_attr);
99 pthread_attr_setdetachstate(&cb_attr,PTHREAD_CREATE_DETACHED);
dhirajverma9f59b572021-07-23 02:36:13 -0400100 return pthread_create(&tid, &cb_attr,&monitor_loglevel_change_handler,(void *)fileName);
dhirajverma55e755b2021-06-29 02:01:47 +0530101}
102
103
104static void * monitor_loglevel_change_handler(void* arg)
105{
106 char *fileName = (char*) arg;
107 int ifd; // the inotify file des
108 int wfd; // the watched file des
109 ssize_t n = 0;
110 char rbuf[4096]; // large read buffer as the event is var len
111 fd_set fds;
112 int res = 0;
dhirajverma55e755b2021-06-29 02:01:47 +0530113 char* dname=NULL; // directory name
114 char* bname = NULL; // basename
115 char* tok=NULL;
116 char* log_level=NULL;
117
Alexandre Hufffff97942023-03-31 21:22:20 -0300118 dname = strdup( fileName ); // defrock the file name into dir and basename
dhirajverma55e755b2021-06-29 02:01:47 +0530119 if( (tok = strrchr( dname, '/' )) != NULL ) {
120 *tok = '\0';
121 bname = strdup( tok+1 );
122 }
123
dhirajverma55e755b2021-06-29 02:01:47 +0530124 ifd = inotify_init1( 0 ); // initialise watcher setting blocking read (no option)
125 if( ifd < 0 ) {
126 fprintf( stderr, "### ERR ### unable to initialise file watch %s\n", strerror( errno ) );
127 } else {
128 wfd = inotify_add_watch( ifd, dname, IN_MOVED_TO | IN_CLOSE_WRITE ); // we only care about close write changes
129
130 if( wfd < 0 ) {
131 fprintf( stderr, "### ERR ### unable to add watch on config file %s: %s\n", fileName, strerror( errno ) );
132 } else {
Alexandre Hufffff97942023-03-31 21:22:20 -0300133 FD_ZERO (&fds);
134 FD_SET (ifd, &fds);
dhirajverma55e755b2021-06-29 02:01:47 +0530135 while( 1 ) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300136 res = select (ifd + 1, &fds, NULL, NULL, NULL);
dhirajverma55e755b2021-06-29 02:01:47 +0530137 if(res)
138 {
139 n = read( ifd, rbuf, sizeof( rbuf ) ); // read the event
140 if( n < 0 ) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300141#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
dhirajverma55e755b2021-06-29 02:01:47 +0530142 if( errno == EAGAIN ) {
143 } else {
Alexandre Hufffff97942023-03-31 21:22:20 -0300144 fprintf( stderr, "### CRIT ### config listener read err: %s\n", strerror( errno ) );
dhirajverma55e755b2021-06-29 02:01:47 +0530145 }
146 continue;
Alexandre Hufffff97942023-03-31 21:22:20 -0300147#endif
dhirajverma55e755b2021-06-29 02:01:47 +0530148 }
149
150 //Retrieving Log Level from configmap by parsing configmap file
151 log_level = parse_file(fileName);
152 update_mdc_log_level_severity(log_level); //setting log level
Alexandre Hufffff97942023-03-31 21:22:20 -0300153 if(log_level != NULL) {
154 mdclog_write(MDCLOG_INFO, "MDC log level updated to %s", log_level);
155 free(log_level);
156 }
dhirajverma55e755b2021-06-29 02:01:47 +0530157 }
158 }
159 inotify_rm_watch(ifd,wfd);
160 }
161 close(ifd);
162 }
163 free(bname);
164 free(dname);
Alexandre Hufffff97942023-03-31 21:22:20 -0300165 free(fileName);
dhirajverma55e755b2021-06-29 02:01:47 +0530166
167 pthread_exit(NULL);
168}
169
170void update_mdc_log_level_severity(char* log_level)
171{
172 mdclog_severity_t level = MDCLOG_ERR;
173
174 if(log_level == NULL)
175 {
176 printf("### ERR ### Invalid Log-Level Configuration in ConfigMap, Default Log-Level Applied: %d\n",level);
177 }
178 else if(strcasecmp(log_level,"1")==0)
179 {
180 level = MDCLOG_ERR;
181 }
182 else if(strcasecmp(log_level,"2")==0)
183 {
184 level = MDCLOG_WARN;
185 }
186 else if(strcasecmp(log_level,"3")==0)
187 {
188 level = MDCLOG_INFO;
189 }
190 else if(strcasecmp(log_level,"4")==0)
191 {
192 level = MDCLOG_DEBUG;
193 }
194
195 mdclog_level_set(level);
196}
Alexandre Hufffff97942023-03-31 21:22:20 -0300197
198/**
199 * @brief Remove leading and trailing spaces from s.
200 *
201 * If the string was allocated dynamically, the caller cannot
202 * overwrite the returned pointer.
203 *
204 * @param s the string we want to remove spaces.
205 * @return Returns a null-terminated substring of "s".
206 */
207static inline char *trim(char *s)
208{
209 char *end;
210 /* skip leading spaces */
211 while (isspace(*s)) s++;
212
213 /* all spaces */
214 if (*s == '\0') return s;
215
216 /* skip trailing spaces */
217 end = s + strlen(s) - 1;
218 while (end > s && isspace(*end)) end--;
219
220 /* write null character */
221 *(end+1) = '\0';
222
223 return s;
224}
225
dhirajverma55e755b2021-06-29 02:01:47 +0530226static char* parse_file(char* filename)
227{
228 char *token=NULL;
dhirajverma55e755b2021-06-29 02:01:47 +0530229 bool found = false;
230 FILE *file = fopen ( filename, "r" );
Alexandre Hufffff97942023-03-31 21:22:20 -0300231
dhirajverma55e755b2021-06-29 02:01:47 +0530232 if ( file != NULL )
233 {
234 char line [ 128 ];
Alexandre Hufffff97942023-03-31 21:22:20 -0300235 while ( fgets ( line, sizeof(line), file ) != NULL )
dhirajverma55e755b2021-06-29 02:01:47 +0530236 {
Alexandre Hufffff97942023-03-31 21:22:20 -0300237 token = strtok(line, ":");
238 token = trim(token);
239 if (strcmp(token,"log-level") == 0) {
dhirajverma55e755b2021-06-29 02:01:47 +0530240 found = true;
Alexandre Hufffff97942023-03-31 21:22:20 -0300241 token = strtok(NULL, "\n");
242 token = trim(token);
dhirajverma55e755b2021-06-29 02:01:47 +0530243 break;
244 }
245 }
246 fclose ( file );
247 }
248 if(found)
249 return(strdup(token));
250 else
251 return(NULL);
252}
253
254char *read_env_param(const char*envkey)
255{
256 if(envkey)
257 {
258 char *value = getenv(envkey);
259 if(value)
260 return strdup(value);
261 }
262 return NULL;
263}
264
265void dynamic_log_level_change()
266{
267 char *logFile_Name = read_env_param(LOG_FILE_CONFIG_MAP);
268 char* log_level_init=NULL;
269 if(logFile_Name)
270 {
271 log_level_init = parse_file(logFile_Name);
272 update_mdc_log_level_severity(log_level_init); //setting log level
Alexandre Hufffff97942023-03-31 21:22:20 -0300273 mdclog_write(MDCLOG_INFO, "MDC log level set to %s", log_level_init);
dhirajverma55e755b2021-06-29 02:01:47 +0530274 free(log_level_init);
275
276 }
277 enable_log_change_notify(logFile_Name);
dhirajverma55e755b2021-06-29 02:01:47 +0530278}
279
ss412g1a79bdf2019-10-24 12:03:05 +0300280void init_log() {
dhirajverma55e755b2021-06-29 02:01:47 +0530281 int log_change_monitor = 0;
ss412g1a79bdf2019-10-24 12:03:05 +0300282 mdclog_attr_t *attr;
283 mdclog_attr_init(&attr);
284 mdclog_attr_set_ident(attr, "E2Terminator");
285 mdclog_init(attr);
dhirajverma5f132832021-06-17 17:27:54 +0530286 if(mdclog_format_initialize(log_change_monitor)!=0)
287 mdclog_write(MDCLOG_ERR, "Failed to intialize MDC log format !!!");
dhirajverma55e755b2021-06-29 02:01:47 +0530288 dynamic_log_level_change();
ss412g1a79bdf2019-10-24 12:03:05 +0300289 mdclog_attr_destroy(attr);
290}
pwpmurthyb1877062023-04-12 14:49:58 +0000291//auto start_time = std::chrono::high_resolution_clock::now();
292//typedef std::chrono::duration<double, std::ratio<1,1>> seconds_t;
ss412g1a79bdf2019-10-24 12:03:05 +0300293
pwpmurthyb1877062023-04-12 14:49:58 +0000294//double age() {
295// return seconds_t(std::chrono::high_resolution_clock::now() - start_time).count();
296//}
ss412g3bac2da2020-01-05 11:52:19 +0200297
pwpmurthyb1877062023-04-12 14:49:58 +0000298// If model name in "/proc/cpuinfo" is happens to be "Common KVM processor" then
299// approx_CPU_MHz() results in "SIGILL - Illegal Instruction" signal.
300//
301// double approx_CPU_MHz(unsigned sleepTime) {
302// using namespace std::chrono_literals;
303// uint32_t aux = 0;
304// uint64_t cycles_start = rdtscp(aux);
305// double time_start = age();
306// std::this_thread::sleep_for(sleepTime * 1ms);
307// uint64_t elapsed_cycles = rdtscp(aux) - cycles_start;
308// double elapsed_time = age() - time_start;
309// return elapsed_cycles / elapsed_time;
310//}
ss412g1a79bdf2019-10-24 12:03:05 +0300311
312//std::atomic<int64_t> rmrCounter{0};
313std::atomic<int64_t> num_of_messages{0};
ss412g3bac2da2020-01-05 11:52:19 +0200314std::atomic<int64_t> num_of_XAPP_messages{0};
ss412g1a79bdf2019-10-24 12:03:05 +0300315static long transactionCounter = 0;
sandeekuea662102022-11-08 18:51:20 +0530316pthread_mutex_t thread_lock;
ss412g1a79bdf2019-10-24 12:03:05 +0300317
aa7133@att.com84bd3342020-03-16 18:04:57 +0200318int buildListeningPort(sctp_params_t &sctpParams) {
aa7133@att.comf211f192020-06-23 12:50:10 +0300319 sctpParams.listenFD = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP);
320 if (sctpParams.listenFD <= 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300321#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comf211f192020-06-23 12:50:10 +0300322 mdclog_write(MDCLOG_ERR, "Error Opening socket, %s", strerror(errno));
323 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300324#endif
aa7133@att.comf211f192020-06-23 12:50:10 +0300325 }
czichy2175dd32022-05-17 15:24:51 +0300326 struct sctp_initmsg initmsg;
327 memset (&initmsg, 0, sizeof (initmsg));
328 initmsg.sinit_num_ostreams = 2;
329 initmsg.sinit_max_instreams = 2;
330 initmsg.sinit_max_attempts = 4;
331 setsockopt (sctpParams.listenFD, IPPROTO_SCTP, SCTP_INITMSG, &initmsg, sizeof (initmsg));
aa7133@att.comf211f192020-06-23 12:50:10 +0300332
aa7133@att.com409f2232020-10-29 13:06:45 +0300333 struct sockaddr_in6 serverAddress {};
334 serverAddress.sin6_family = AF_INET6;
335 serverAddress.sin6_addr = in6addr_any;
336 serverAddress.sin6_port = htons(sctpParams.sctpPort);
337 if (bind(sctpParams.listenFD, (SA *)&serverAddress, sizeof(serverAddress)) < 0 ) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300338#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comf211f192020-06-23 12:50:10 +0300339 mdclog_write(MDCLOG_ERR, "Error binding port %d. %s", sctpParams.sctpPort, strerror(errno));
aa7133@att.com84bd3342020-03-16 18:04:57 +0200340 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300341#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +0200342 }
343 if (setSocketNoBlocking(sctpParams.listenFD) == -1) {
344 //mdclog_write(MDCLOG_ERR, "Error binding. %s", strerror(errno));
345 return -1;
346 }
347 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300348 struct sockaddr_in6 clientAddress {};
349 socklen_t len = sizeof(clientAddress);
350 getsockname(sctpParams.listenFD, (SA *)&clientAddress, &len);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200351 char buff[1024] {};
aa7133@att.com409f2232020-10-29 13:06:45 +0300352 inet_ntop(AF_INET6, &clientAddress.sin6_addr, buff, sizeof(buff));
353 mdclog_write(MDCLOG_DEBUG, "My address: %s, port %d\n", buff, htons(clientAddress.sin6_port));
ss412g1a79bdf2019-10-24 12:03:05 +0300354 }
355
pwpmurthy9f9d7502023-04-20 16:55:30 +0000356 // SCTP_HB_INTERVAL is in milisec
357 char *sctp_hb_interval = std::getenv("SCTP_HB_INTERVAL");
358 if (sctp_hb_interval) {
359 // Setting the heartbeat interval timeout value
360 struct sctp_paddrparams sckt_parms;
361 memset(&sckt_parms, 0, sizeof(sckt_parms));
362 unsigned int sckt_parms_size = sizeof(sckt_parms);
363 sckt_parms.spp_address.ss_family = AF_INET6;
364 sckt_parms.spp_flags |= SPP_HB_ENABLE;
365 sctp_opt_info(sctpParams.listenFD, 0, SCTP_PEER_ADDR_PARAMS, &sckt_parms, &sckt_parms_size);
366 if (sckt_parms_size != sizeof(sckt_parms)) {
367 fprintf(stderr, "Invalid size of sctp_paddrparams socket option: {} / {}", sckt_parms_size, (socklen_t)sizeof(sckt_parms));
368 } else {
369 sckt_parms.spp_hbinterval = atoi(sctp_hb_interval);
370 setsockopt(sctpParams.listenFD, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &sckt_parms, sizeof(sckt_parms));
371 }
372 }
373
374 char *sctp_max_retries = std::getenv("SCTP_MAX_RETRIES");
375 if (sctp_max_retries) {
376 // Setting the max retries config for the socket if rechability loss
377 struct sctp_assocparams sckt_assoc;
378 memset(&sckt_assoc, 0, sizeof(sckt_assoc));
379 unsigned int str_assoc_size = sizeof(sckt_assoc);
380 sctp_opt_info(sctpParams.listenFD, 0, SCTP_ASSOCINFO, &sckt_assoc, &str_assoc_size);
381 if (str_assoc_size != sizeof(sckt_assoc)) {
382 fprintf(stderr, "Invalid size of sctp_assocparams socket option: {} / {}", str_assoc_size, (socklen_t)sizeof(sckt_assoc));
383 } else {
384 sckt_assoc.sasoc_asocmaxrxt = atoi(sctp_max_retries);
385 setsockopt(sctpParams.listenFD, IPPROTO_SCTP, SCTP_ASSOCINFO, &sckt_assoc, sizeof(sckt_assoc));
386 }
387 }
388
389
aa7133@att.com84bd3342020-03-16 18:04:57 +0200390 if (listen(sctpParams.listenFD, SOMAXCONN) < 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300391#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +0200392 mdclog_write(MDCLOG_ERR, "Error listening. %s\n", strerror(errno));
393 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300394#endif
ss412g3bac2da2020-01-05 11:52:19 +0200395 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200396 struct epoll_event event {};
397 event.events = EPOLLIN | EPOLLET;
398 event.data.fd = sctpParams.listenFD;
399
400 // add listening port to epoll
401 if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.listenFD, &event)) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400402#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +0200403 printf("Failed to add descriptor to epoll\n");
404 mdclog_write(MDCLOG_ERR, "Failed to add descriptor to epoll. %s\n", strerror(errno));
405 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300406#endif
ss412g3bac2da2020-01-05 11:52:19 +0200407 }
408
aa7133@att.com84bd3342020-03-16 18:04:57 +0200409 return 0;
410}
ss412g3bac2da2020-01-05 11:52:19 +0200411
aa7133@att.com84bd3342020-03-16 18:04:57 +0200412int buildConfiguration(sctp_params_t &sctpParams) {
ss412g3bac2da2020-01-05 11:52:19 +0200413 path p = (sctpParams.configFilePath + "/" + sctpParams.configFileName).c_str();
414 if (exists(p)) {
415 const int size = 2048;
416 auto fileSize = file_size(p);
417 if (fileSize > size) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300418#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200419 mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200420 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300421#endif
ss412g3bac2da2020-01-05 11:52:19 +0200422 }
423 } else {
Alexandre Hufffff97942023-03-31 21:22:20 -0300424#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200425 mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str());
aa7133@att.com84bd3342020-03-16 18:04:57 +0200426 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300427#endif
ss412g3bac2da2020-01-05 11:52:19 +0200428 }
429
ss412g3bac2da2020-01-05 11:52:19 +0200430 ReadConfigFile conf;
431 if (conf.openConfigFile(p.string()) == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300432#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200433 mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s",
434 p.string().c_str(), strerror(errno));
aa7133@att.com84bd3342020-03-16 18:04:57 +0200435 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300436#endif
ss412g3bac2da2020-01-05 11:52:19 +0200437 }
438 int rmrPort = conf.getIntValue("nano");
439 if (rmrPort == -1) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400440#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300441 mdclog_write(MDCLOG_ERR, "illegal RMR port ");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200442 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300443#endif
ss412g3bac2da2020-01-05 11:52:19 +0200444 }
445 sctpParams.rmrPort = (uint16_t)rmrPort;
446 snprintf(sctpParams.rmrAddress, sizeof(sctpParams.rmrAddress), "%d", (int) (sctpParams.rmrPort));
dhirajverma5f132832021-06-17 17:27:54 +0530447 auto tmpStr = conf.getStringValue("volume");
ss412g3bac2da2020-01-05 11:52:19 +0200448 if (tmpStr.length() == 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300449#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300450 mdclog_write(MDCLOG_ERR, "illegal volume.");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200451 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300452#endif
ss412g3bac2da2020-01-05 11:52:19 +0200453 }
454
ss412g1a79bdf2019-10-24 12:03:05 +0300455 char tmpLogFilespec[VOLUME_URL_SIZE];
456 tmpLogFilespec[0] = 0;
ss412g3bac2da2020-01-05 11:52:19 +0200457 sctpParams.volume[0] = 0;
458 snprintf(sctpParams.volume, VOLUME_URL_SIZE, "%s", tmpStr.c_str());
459 // copy the name to temp file as well
460 snprintf(tmpLogFilespec, VOLUME_URL_SIZE, "%s", tmpStr.c_str());
461
462
463 // define the file name in the tmp directory under the volume
464 strcat(tmpLogFilespec,"/tmp/E2Term_%Y-%m-%d_%H-%M-%S.%N.tmpStr");
465
466 sctpParams.myIP = conf.getStringValue("local-ip");
467 if (sctpParams.myIP.length() == 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300468#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300469 mdclog_write(MDCLOG_ERR, "illegal local-ip.");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200470 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300471#endif
ss412g1a79bdf2019-10-24 12:03:05 +0300472 }
473
aa7133@att.combe92d712020-03-18 17:30:39 +0200474 int sctpPort = conf.getIntValue("sctp-port");
475 if (sctpPort == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300476#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300477 mdclog_write(MDCLOG_ERR, "illegal SCTP port ");
aa7133@att.combe92d712020-03-18 17:30:39 +0200478 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300479#endif
aa7133@att.combe92d712020-03-18 17:30:39 +0200480 }
481 sctpParams.sctpPort = (uint16_t)sctpPort;
482
aa7133@att.com84bd3342020-03-16 18:04:57 +0200483 sctpParams.fqdn = conf.getStringValue("external-fqdn");
484 if (sctpParams.fqdn.length() == 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300485#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300486 mdclog_write(MDCLOG_ERR, "illegal external-fqdn");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200487 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300488#endif
ss412g3bac2da2020-01-05 11:52:19 +0200489 }
ss412g1a79bdf2019-10-24 12:03:05 +0300490
aa7133@att.com342843e2020-01-26 12:53:34 +0200491 std::string pod = conf.getStringValue("pod_name");
dhirajverma6cf28612021-06-23 04:53:34 -0400492#ifndef UNIT_TEST
aa7133@att.com342843e2020-01-26 12:53:34 +0200493 if (pod.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300494 mdclog_write(MDCLOG_ERR, "illegal pod_name in config file");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200495 return -1;
aa7133@att.com342843e2020-01-26 12:53:34 +0200496 }
497 auto *podName = getenv(pod.c_str());
498 if (podName == nullptr) {
aa7133@att.com54885fe2020-10-29 17:24:49 +0300499 mdclog_write(MDCLOG_ERR, "illegal pod_name or environment variable not exists : %s", pod.c_str());
aa7133@att.com84bd3342020-03-16 18:04:57 +0200500 return -1;
aa7133@att.com342843e2020-01-26 12:53:34 +0200501
502 } else {
503 sctpParams.podName.assign(podName);
504 if (sctpParams.podName.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300505 mdclog_write(MDCLOG_ERR, "illegal pod_name");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200506 return -1;
aa7133@att.com342843e2020-01-26 12:53:34 +0200507 }
508 }
dhirajverma6cf28612021-06-23 04:53:34 -0400509#endif
ss412g3bac2da2020-01-05 11:52:19 +0200510 tmpStr = conf.getStringValue("trace");
511 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
512 if ((tmpStr.compare("start")) == 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300513#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200514 mdclog_write(MDCLOG_INFO, "Trace set to: start");
515 sctpParams.trace = true;
Alexandre Hufffff97942023-03-31 21:22:20 -0300516#endif
ss412g3bac2da2020-01-05 11:52:19 +0200517 } else if ((tmpStr.compare("stop")) == 0) {
518 mdclog_write(MDCLOG_INFO, "Trace set to: stop");
519 sctpParams.trace = false;
aa7133@att.com41fcb3f2020-11-29 13:48:25 +0200520 } else {
Alexandre Hufffff97942023-03-31 21:22:20 -0300521#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com41fcb3f2020-11-29 13:48:25 +0200522 mdclog_write(MDCLOG_ERR, "Trace was set to wrong value %s, set to stop", tmpStr.c_str());
aa7133@att.com92aeebe2020-11-29 14:22:09 +0200523 sctpParams.trace = false;
Alexandre Hufffff97942023-03-31 21:22:20 -0300524#endif
ss412g3bac2da2020-01-05 11:52:19 +0200525 }
526 jsonTrace = sctpParams.trace;
ss412g1a79bdf2019-10-24 12:03:05 +0300527
ss412g4aeeda22020-06-16 14:12:41 +0300528 sctpParams.epollTimeOut = -1;
ss412g4aeeda22020-06-16 14:12:41 +0300529
530 tmpStr = conf.getStringValue("prometheusPort");
531 if (tmpStr.length() != 0) {
532 sctpParams.prometheusPort = tmpStr;
533 }
534
aa7133@att.combe92d712020-03-18 17:30:39 +0200535 sctpParams.ka_message_length = snprintf(sctpParams.ka_message, KA_MESSAGE_SIZE, "{\"address\": \"%s:%d\","
aa7133@att.com96c9b882020-03-25 14:50:40 +0200536 "\"fqdn\": \"%s\","
537 "\"pod_name\": \"%s\"}",
aa7133@att.com342843e2020-01-26 12:53:34 +0200538 (const char *)sctpParams.myIP.c_str(),
539 sctpParams.rmrPort,
540 sctpParams.fqdn.c_str(),
541 sctpParams.podName.c_str());
542
ss412g1a79bdf2019-10-24 12:03:05 +0300543 if (mdclog_level_get() >= MDCLOG_INFO) {
dhirajverma5f132832021-06-17 17:27:54 +0530544 mdclog_write(MDCLOG_DEBUG,"RMR Port: %s", to_string(sctpParams.rmrPort).c_str());
dhirajverma5f132832021-06-17 17:27:54 +0530545 mdclog_write(MDCLOG_DEBUG,"volume: %s", sctpParams.volume);
546 mdclog_write(MDCLOG_DEBUG,"tmpLogFilespec: %s", tmpLogFilespec);
547 mdclog_write(MDCLOG_DEBUG,"my ip: %s", sctpParams.myIP.c_str());
548 mdclog_write(MDCLOG_DEBUG,"pod name: %s", sctpParams.podName.c_str());
ss412g1a79bdf2019-10-24 12:03:05 +0300549
aa7133@att.com342843e2020-01-26 12:53:34 +0200550 mdclog_write(MDCLOG_INFO, "running parameters for instance : %s", sctpParams.ka_message);
ss412g1a79bdf2019-10-24 12:03:05 +0300551 }
ss412g1a79bdf2019-10-24 12:03:05 +0300552
553 // Files written to the current working directory
554 boostLogger = logging::add_file_log(
ss412g3bac2da2020-01-05 11:52:19 +0200555 keywords::file_name = tmpLogFilespec, // to temp directory
ss412g1a79bdf2019-10-24 12:03:05 +0300556 keywords::rotation_size = 10 * 1024 * 1024,
557 keywords::time_based_rotation = sinks::file::rotation_at_time_interval(posix_time::hours(1)),
558 keywords::format = "%Message%"
ss412g3bac2da2020-01-05 11:52:19 +0200559 //keywords::format = "[%TimeStamp%]: %Message%" // use each tmpStr with time stamp
ss412g1a79bdf2019-10-24 12:03:05 +0300560 );
561
aa7133@att.com54885fe2020-10-29 17:24:49 +0300562 // Setup a destination folder for collecting rotated (closed) files --since the same volume can use rename()
ss412g1a79bdf2019-10-24 12:03:05 +0300563 boostLogger->locked_backend()->set_file_collector(sinks::file::make_collector(
ss412g3bac2da2020-01-05 11:52:19 +0200564 keywords::target = sctpParams.volume
ss412g1a79bdf2019-10-24 12:03:05 +0300565 ));
566
567 // Upon restart, scan the directory for files matching the file_name pattern
568 boostLogger->locked_backend()->scan_for_files();
569
ss412g3bac2da2020-01-05 11:52:19 +0200570 // Enable auto-flushing after each tmpStr record written
ss412g1a79bdf2019-10-24 12:03:05 +0300571 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +0200572 boostLogger->locked_backend()->auto_flush(true);
573 }
574
575 return 0;
576}
577
aa7133@att.coma4c80012020-06-24 16:36:47 +0300578void startPrometheus(sctp_params_t &sctpParams) {
Mohamed Abukar64f37242021-08-15 12:39:56 +0000579 auto podName = std::getenv("POD_NAME");
580 string metric = "E2TBeta";
581 if (strstr(podName, "alpha") != NULL) {
582 metric = "E2TAlpha";
583 }
wahidw1d1a9b72021-09-24 17:35:28 +0000584 //Get eth0 interface IP
585 char* host = getinterfaceip();
586 string hostip = host;
Mohamed Abukar64f37242021-08-15 12:39:56 +0000587
aa7133@att.coma4c80012020-06-24 16:36:47 +0300588 sctpParams.prometheusFamily = &BuildCounter()
Mohamed Abukar64f37242021-08-15 12:39:56 +0000589 .Name(metric.c_str())
590 .Help("E2T instance metrics")
aa7133@att.coma4c80012020-06-24 16:36:47 +0300591 .Labels({{"POD_NAME", sctpParams.podName}})
592 .Register(*sctpParams.prometheusRegistry);
aa7133@att.com16c799b2020-03-24 18:01:51 +0200593
Mohamed Abukar64f37242021-08-15 12:39:56 +0000594 // Build E2T instance level metrics
595 buildE2TPrometheusCounters(sctpParams);
596
wahidw1d1a9b72021-09-24 17:35:28 +0000597 string prometheusPath;
598 if (hostip.empty())
599 prometheusPath = sctpParams.prometheusPort + "," + "[::]:" + sctpParams.prometheusPort;
600 else
601 prometheusPath = hostip + ":" + sctpParams.prometheusPort;
602
aa7133@att.comb92748d2020-06-29 11:52:30 +0300603 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com54885fe2020-10-29 17:24:49 +0300604 mdclog_write(MDCLOG_DEBUG, "Start Prometheus Pull mode on %s", prometheusPath.c_str());
aa7133@att.coma4c80012020-06-24 16:36:47 +0300605 }
aa7133@att.com54885fe2020-10-29 17:24:49 +0300606 sctpParams.prometheusExposer = new Exposer(prometheusPath, 1);
aa7133@att.comb92748d2020-06-29 11:52:30 +0300607 sctpParams.prometheusExposer->RegisterCollectable(sctpParams.prometheusRegistry);
aa7133@att.coma4c80012020-06-24 16:36:47 +0300608}
dhirajverma31768a92021-05-06 12:38:49 +0530609#ifndef UNIT_TEST
dhirajverma5f132832021-06-17 17:27:54 +0530610
aa7133@att.com84bd3342020-03-16 18:04:57 +0200611int main(const int argc, char **argv) {
612 sctp_params_t sctpParams;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200613 {
614 std::random_device device{};
615 std::mt19937 generator(device());
616 std::uniform_int_distribution<long> distribution(1, (long) 1e12);
617 transactionCounter = distribution(generator);
618 }
619
620// uint64_t st = 0;
621// uint32_t aux1 = 0;
622// st = rdtscp(aux1);
623
624 unsigned num_cpus = std::thread::hardware_concurrency();
625 init_log();
aa7133@att.com84bd3342020-03-16 18:04:57 +0200626 if (std::signal(SIGINT, catch_function) == SIG_ERR) {
627 mdclog_write(MDCLOG_ERR, "Error initializing SIGINT");
628 exit(1);
629 }
630 if (std::signal(SIGABRT, catch_function)== SIG_ERR) {
631 mdclog_write(MDCLOG_ERR, "Error initializing SIGABRT");
632 exit(1);
633 }
634 if (std::signal(SIGTERM, catch_function)== SIG_ERR) {
635 mdclog_write(MDCLOG_ERR, "Error initializing SIGTERM");
636 exit(1);
637 }
638
pwpmurthyb1877062023-04-12 14:49:58 +0000639// cpuClock = approx_CPU_MHz(100);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200640
pwpmurthyb1877062023-04-12 14:49:58 +0000641// mdclog_write(MDCLOG_DEBUG, "CPU speed %11.11f", cpuClock);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200642
643 auto result = parse(argc, argv, sctpParams);
644
645 if (buildConfiguration(sctpParams) != 0) {
646 exit(-1);
ss412g1a79bdf2019-10-24 12:03:05 +0300647 }
648
ss412g4aeeda22020-06-16 14:12:41 +0300649 //auto registry = std::make_shared<Registry>();
650 sctpParams.prometheusRegistry = std::make_shared<Registry>();
651
aa7133@att.com409f2232020-10-29 13:06:45 +0300652 //sctpParams.prometheusFamily = new Family<Counter>("E2T", "E2T message counter", {{"E", sctpParams.podName}});
ss412g4aeeda22020-06-16 14:12:41 +0300653
aa7133@att.coma4c80012020-06-24 16:36:47 +0300654 startPrometheus(sctpParams);
ss412g4aeeda22020-06-16 14:12:41 +0300655
ss412g1a79bdf2019-10-24 12:03:05 +0300656 // start epoll
ss412g3bac2da2020-01-05 11:52:19 +0200657 sctpParams.epoll_fd = epoll_create1(0);
658 if (sctpParams.epoll_fd == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +0300659 mdclog_write(MDCLOG_ERR, "failed to open epoll descriptor");
660 exit(-1);
661 }
aa7133@att.combe92d712020-03-18 17:30:39 +0200662 getRmrContext(sctpParams);
ss412g3bac2da2020-01-05 11:52:19 +0200663 if (sctpParams.rmrCtx == nullptr) {
664 close(sctpParams.epoll_fd);
ss412g1a79bdf2019-10-24 12:03:05 +0300665 exit(-1);
666 }
667
ss412g3bac2da2020-01-05 11:52:19 +0200668 if (buildInotify(sctpParams) == -1) {
669 close(sctpParams.rmrListenFd);
670 rmr_close(sctpParams.rmrCtx);
671 close(sctpParams.epoll_fd);
672 exit(-1);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200673 }
674
675 if (buildListeningPort(sctpParams) != 0) {
676 close(sctpParams.rmrListenFd);
677 rmr_close(sctpParams.rmrCtx);
678 close(sctpParams.epoll_fd);
679 exit(-1);
680 }
ss412g3bac2da2020-01-05 11:52:19 +0200681
682 sctpParams.sctpMap = new mapWrapper();
ss412g1a79bdf2019-10-24 12:03:05 +0300683
sandeekuea662102022-11-08 18:51:20 +0530684 if (pthread_mutex_init(&thread_lock, NULL) != 0) {
685 mdclog_write(MDCLOG_ERR, "failed to init thread lock");
686 exit(-1);
687 }
ss412g1a79bdf2019-10-24 12:03:05 +0300688 std::vector<std::thread> threads(num_cpus);
689// std::vector<std::thread> threads;
690
aa7133@att.com24e9fa42020-11-13 20:32:53 +0200691 num_cpus = 3;
ss412g1a79bdf2019-10-24 12:03:05 +0300692 for (unsigned int i = 0; i < num_cpus; i++) {
ss412g3bac2da2020-01-05 11:52:19 +0200693 threads[i] = std::thread(listener, &sctpParams);
ss412g1a79bdf2019-10-24 12:03:05 +0300694
695 cpu_set_t cpuset;
696 CPU_ZERO(&cpuset);
697 CPU_SET(i, &cpuset);
698 int rc = pthread_setaffinity_np(threads[i].native_handle(), sizeof(cpu_set_t), &cpuset);
699 if (rc != 0) {
700 mdclog_write(MDCLOG_ERR, "Error calling pthread_setaffinity_np: %d", rc);
701 }
ss412g1a79bdf2019-10-24 12:03:05 +0300702 }
703
aa7133@att.com16c799b2020-03-24 18:01:51 +0200704
ss412g3bac2da2020-01-05 11:52:19 +0200705 //loop over term_init until first message from xApp
706 handleTermInit(sctpParams);
707
708 for (auto &t : threads) {
709 t.join();
710 }
sandeekuea662102022-11-08 18:51:20 +0530711 pthread_mutex_destroy(&thread_lock);
ss412g3bac2da2020-01-05 11:52:19 +0200712 return 0;
713}
dhirajverma60f8bef2021-06-29 07:22:58 -0400714#endif
ss412g3bac2da2020-01-05 11:52:19 +0200715void handleTermInit(sctp_params_t &sctpParams) {
716 sendTermInit(sctpParams);
ss412g1a79bdf2019-10-24 12:03:05 +0300717 //send to e2 manager init of e2 term
718 //E2_TERM_INIT
ss412g1a79bdf2019-10-24 12:03:05 +0300719
ss412g3bac2da2020-01-05 11:52:19 +0200720 int count = 0;
721 while (true) {
722 auto xappMessages = num_of_XAPP_messages.load(std::memory_order_acquire);
723 if (xappMessages > 0) {
724 if (mdclog_level_get() >= MDCLOG_INFO) {
aa7133@att.com54885fe2020-10-29 17:24:49 +0300725 mdclog_write(MDCLOG_INFO, "Got a message from some application, stop sending E2_TERM_INIT");
ss412g3bac2da2020-01-05 11:52:19 +0200726 }
727 return;
728 }
729 usleep(100000);
730 count++;
731 if (count % 1000 == 0) {
732 mdclog_write(MDCLOG_ERR, "GOT No messages from any xApp");
733 sendTermInit(sctpParams);
734 }
735 }
736}
737
738void sendTermInit(sctp_params_t &sctpParams) {
739 rmr_mbuf_t *msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.ka_message_length);
ss412g1a79bdf2019-10-24 12:03:05 +0300740 auto count = 0;
ss412g3bac2da2020-01-05 11:52:19 +0200741 while (true) {
ss412g1a79bdf2019-10-24 12:03:05 +0300742 msg->mtype = E2_TERM_INIT;
743 msg->state = 0;
ss412g3bac2da2020-01-05 11:52:19 +0200744 rmr_bytes2payload(msg, (unsigned char *)sctpParams.ka_message, sctpParams.ka_message_length);
ss412g1a79bdf2019-10-24 12:03:05 +0300745 static unsigned char tx[32];
746 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
747 rmr_bytes2xact(msg, tx, txLen);
ss412g3bac2da2020-01-05 11:52:19 +0200748 msg = rmr_send_msg(sctpParams.rmrCtx, msg);
ss412g1a79bdf2019-10-24 12:03:05 +0300749 if (msg == nullptr) {
aa7133@att.comc9575aa2020-04-02 11:40:09 +0300750 msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.ka_message_length);
ss412g1a79bdf2019-10-24 12:03:05 +0300751 } else if (msg->state == 0) {
ss412g1a79bdf2019-10-24 12:03:05 +0300752 rmr_free_msg(msg);
ss412g3bac2da2020-01-05 11:52:19 +0200753 if (mdclog_level_get() >= MDCLOG_INFO) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300754 mdclog_write(MDCLOG_INFO, "E2_TERM_INIT successfully sent ");
ss412g3bac2da2020-01-05 11:52:19 +0200755 }
756 return;
ss412g1a79bdf2019-10-24 12:03:05 +0300757 } else {
758 if (count % 100 == 0) {
aa7133@att.com11b17d42020-03-22 11:35:16 +0200759 mdclog_write(MDCLOG_ERR, "Error sending E2_TERM_INIT cause : %s ", translateRmrErrorMessages(msg->state).c_str());
ss412g1a79bdf2019-10-24 12:03:05 +0300760 }
761 sleep(1);
762 }
763 count++;
764 }
ss412g3bac2da2020-01-05 11:52:19 +0200765}
766
767/**
768 *
769 * @param argc
770 * @param argv
771 * @param sctpParams
772 * @return
773 */
774cxxopts::ParseResult parse(int argc, char *argv[], sctp_params_t &sctpParams) {
775 cxxopts::Options options(argv[0], "e2 term help");
776 options.positional_help("[optional args]").show_positional_help();
777 options.allow_unrecognised_options().add_options()
778 ("p,path", "config file path", cxxopts::value<std::string>(sctpParams.configFilePath)->default_value("config"))
779 ("f,file", "config file name", cxxopts::value<std::string>(sctpParams.configFileName)->default_value("config.conf"))
780 ("h,help", "Print help");
781
aa7133@att.comde40d1c2020-08-26 16:19:20 +0300782 auto result = options.parse(argc, (const char **&)argv);
ss412g3bac2da2020-01-05 11:52:19 +0200783
784 if (result.count("help")) {
785 std::cout << options.help({""}) << std::endl;
786 exit(0);
787 }
788 return result;
789}
790
791/**
792 *
793 * @param sctpParams
794 * @return -1 failed 0 success
795 */
796int buildInotify(sctp_params_t &sctpParams) {
797 sctpParams.inotifyFD = inotify_init1(IN_NONBLOCK);
798 if (sctpParams.inotifyFD == -1) {
799 mdclog_write(MDCLOG_ERR, "Failed to init inotify (inotify_init1) %s", strerror(errno));
ss412g3bac2da2020-01-05 11:52:19 +0200800 return -1;
ss412g1a79bdf2019-10-24 12:03:05 +0300801 }
802
ss412g3bac2da2020-01-05 11:52:19 +0200803 sctpParams.inotifyWD = inotify_add_watch(sctpParams.inotifyFD,
aa7133@att.com96c9b882020-03-25 14:50:40 +0200804 (const char *)sctpParams.configFilePath.c_str(),
aa7133@att.com84bd3342020-03-16 18:04:57 +0200805 (unsigned)IN_OPEN | (unsigned)IN_CLOSE_WRITE | (unsigned)IN_CLOSE_NOWRITE); //IN_CLOSE = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)
ss412g3bac2da2020-01-05 11:52:19 +0200806 if (sctpParams.inotifyWD == -1) {
807 mdclog_write(MDCLOG_ERR, "Failed to add directory : %s to inotify (inotify_add_watch) %s",
aa7133@att.com96c9b882020-03-25 14:50:40 +0200808 sctpParams.configFilePath.c_str(),
809 strerror(errno));
ss412g3bac2da2020-01-05 11:52:19 +0200810 close(sctpParams.inotifyFD);
811 return -1;
812 }
813
814 struct epoll_event event{};
815 event.events = (EPOLLIN);
816 event.data.fd = sctpParams.inotifyFD;
817 // add listening RMR FD to epoll
818 if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.inotifyFD, &event)) {
819 mdclog_write(MDCLOG_ERR, "Failed to add inotify FD to epoll");
820 close(sctpParams.inotifyFD);
821 return -1;
822 }
ss412g1a79bdf2019-10-24 12:03:05 +0300823 return 0;
824}
825
826/**
827 *
828 * @param args
829 * @return
830 */
831void listener(sctp_params_t *params) {
ss412g1a79bdf2019-10-24 12:03:05 +0300832 int num_of_SCTP_messages = 0;
ss412g1a79bdf2019-10-24 12:03:05 +0300833 auto totalTime = 0.0;
ss412g1a79bdf2019-10-24 12:03:05 +0300834 std::thread::id this_id = std::this_thread::get_id();
835 //save cout
dhirajverma5f132832021-06-17 17:27:54 +0530836 auto pod_name = std::getenv("POD_NAME");
837 auto container_name = std::getenv("CONTAINER_NAME");
838 auto service_name = std::getenv("SERVICE_NAME");
839 auto host_name = std::getenv("HOST_NAME");
840 auto system_name = std::getenv("SYSTEM_NAME");
841 auto pid = std::to_string(getpid()).c_str();
ss412g1a79bdf2019-10-24 12:03:05 +0300842 streambuf *oldCout = cout.rdbuf();
843 ostringstream memCout;
844 // create new cout
845 cout.rdbuf(memCout.rdbuf());
846 cout << this_id;
847 //return to the normal cout
848 cout.rdbuf(oldCout);
849
850 char tid[32];
851 memcpy(tid, memCout.str().c_str(), memCout.str().length() < 32 ? memCout.str().length() : 31);
852 tid[memCout.str().length()] = 0;
dhirajverma5f132832021-06-17 17:27:54 +0530853 mdclog_mdc_add("SYSTEM_NAME", system_name);
854 mdclog_mdc_add("HOST_NAME", host_name);
855 mdclog_mdc_add("SERVICE_NAME", service_name);
856 mdclog_mdc_add("CONTAINER_NAME", container_name);
857 mdclog_mdc_add("POD_NAME", pod_name);
858 mdclog_mdc_add("PID", pid);
ss412g1a79bdf2019-10-24 12:03:05 +0300859
860 if (mdclog_level_get() >= MDCLOG_DEBUG) {
861 mdclog_write(MDCLOG_DEBUG, "started thread number %s", tid);
862 }
863
864 RmrMessagesBuffer_t rmrMessageBuffer{};
865 //create and init RMR
866 rmrMessageBuffer.rmrCtx = params->rmrCtx;
867
868 auto *events = (struct epoll_event *) calloc(MAXEVENTS, sizeof(struct epoll_event));
869 struct timespec end{0, 0};
870 struct timespec start{0, 0};
871
872 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
873 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
874
ss412g3bac2da2020-01-05 11:52:19 +0200875 memcpy(rmrMessageBuffer.ka_message, params->ka_message, params->ka_message_length);
876 rmrMessageBuffer.ka_message_len = params->ka_message_length;
877 rmrMessageBuffer.ka_message[rmrMessageBuffer.ka_message_len] = 0;
878
879 if (mdclog_level_get() >= MDCLOG_DEBUG) {
880 mdclog_write(MDCLOG_DEBUG, "keep alive message is : %s", rmrMessageBuffer.ka_message);
881 }
882
ss412g1a79bdf2019-10-24 12:03:05 +0300883 ReportingMessages_t message {};
884
aa7133@att.com409f2232020-10-29 13:06:45 +0300885// for (int i = 0; i < MAX_RMR_BUFF_ARRAY; i++) {
aa7133@att.com7c3e4c02020-03-25 16:37:19 +0200886// rmrMessageBuffer.rcvBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
887// rmrMessageBuffer.sendBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
888// }
ss412g1a79bdf2019-10-24 12:03:05 +0300889
890 while (true) {
891 if (mdclog_level_get() >= MDCLOG_DEBUG) {
ss412g4aeeda22020-06-16 14:12:41 +0300892 mdclog_write(MDCLOG_DEBUG, "Start EPOLL Wait. Timeout = %d", params->epollTimeOut);
ss412g1a79bdf2019-10-24 12:03:05 +0300893 }
dhirajverma6cf28612021-06-23 04:53:34 -0400894#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +0300895 auto numOfEvents = epoll_wait(params->epoll_fd, events, MAXEVENTS, params->epollTimeOut);
dhirajverma6cf28612021-06-23 04:53:34 -0400896#else
897 auto numOfEvents = 1;
898#endif
aa7133@att.comb92748d2020-06-29 11:52:30 +0300899 if (numOfEvents == 0) { // time out
Alexandre Hufffff97942023-03-31 21:22:20 -0300900#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comb92748d2020-06-29 11:52:30 +0300901 if (mdclog_level_get() >= MDCLOG_DEBUG) {
902 mdclog_write(MDCLOG_DEBUG, "got epoll timeout");
ss412g1a79bdf2019-10-24 12:03:05 +0300903 }
904 continue;
ss412g4aeeda22020-06-16 14:12:41 +0300905 } else if (numOfEvents < 0) {
906 if (errno == EINTR) {
907 if (mdclog_level_get() >= MDCLOG_DEBUG) {
908 mdclog_write(MDCLOG_DEBUG, "got EINTR : %s", strerror(errno));
909 }
910 continue;
911 }
ss412g1a79bdf2019-10-24 12:03:05 +0300912 mdclog_write(MDCLOG_ERR, "Epoll wait failed, errno = %s", strerror(errno));
dhirajvermab55bc172021-11-09 02:15:08 -0500913 if(events)
914 {
915 free(events);
sandeekuea662102022-11-08 18:51:20 +0530916 events = nullptr;
dhirajvermab55bc172021-11-09 02:15:08 -0500917 }
ss412g1a79bdf2019-10-24 12:03:05 +0300918 return;
Alexandre Hufffff97942023-03-31 21:22:20 -0300919#endif
ss412g1a79bdf2019-10-24 12:03:05 +0300920 }
921 for (auto i = 0; i < numOfEvents; i++) {
922 if (mdclog_level_get() >= MDCLOG_DEBUG) {
923 mdclog_write(MDCLOG_DEBUG, "handling epoll event %d out of %d", i + 1, numOfEvents);
924 }
925 clock_gettime(CLOCK_MONOTONIC, &message.message.time);
926 start.tv_sec = message.message.time.tv_sec;
927 start.tv_nsec = message.message.time.tv_nsec;
ss412g3bac2da2020-01-05 11:52:19 +0200928
929
ss412g1a79bdf2019-10-24 12:03:05 +0300930 if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP)) {
aa7133@att.combe92d712020-03-18 17:30:39 +0200931 handlepoll_error(events[i], message, rmrMessageBuffer, params);
ss412g1a79bdf2019-10-24 12:03:05 +0300932 } else if (events[i].events & EPOLLOUT) {
aa7133@att.combe92d712020-03-18 17:30:39 +0200933 handleEinprogressMessages(events[i], message, rmrMessageBuffer, params);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200934 } else if (params->listenFD == events[i].data.fd) {
aa7133@att.com6680c3b2020-03-22 12:06:58 +0200935 if (mdclog_level_get() >= MDCLOG_INFO) {
936 mdclog_write(MDCLOG_INFO, "New connection request from sctp network\n");
937 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200938 // new connection is requested from RAN start build connection
939 while (true) {
940 struct sockaddr in_addr {};
941 socklen_t in_len;
942 char hostBuff[NI_MAXHOST];
943 char portBuff[NI_MAXSERV];
944
945 in_len = sizeof(in_addr);
946 auto *peerInfo = (ConnectedCU_t *)calloc(1, sizeof(ConnectedCU_t));
aa7133@att.com409f2232020-10-29 13:06:45 +0300947 if(peerInfo == nullptr){
swc58d4f5d2020-10-20 15:08:38 +0900948 mdclog_write(MDCLOG_ERR, "calloc failed");
949 break;
950 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200951 peerInfo->sctpParams = params;
952 peerInfo->fileDescriptor = accept(params->listenFD, &in_addr, &in_len);
953 if (peerInfo->fileDescriptor == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300954#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +0200955 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
956 /* We have processed all incoming connections. */
Alexandre Huff019cb422023-04-11 10:56:48 -0300957 if(peerInfo) {
dhirajverma9f59b572021-07-23 02:36:13 -0400958 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530959 peerInfo = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -0300960 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200961 break;
962 } else {
Alexandre Huff019cb422023-04-11 10:56:48 -0300963 if(peerInfo) {
dhirajverma9f59b572021-07-23 02:36:13 -0400964 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530965 peerInfo = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -0300966 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200967 mdclog_write(MDCLOG_ERR, "Accept error, errno = %s", strerror(errno));
968 break;
969 }
970 }
971 if (setSocketNoBlocking(peerInfo->fileDescriptor) == -1) {
972 mdclog_write(MDCLOG_ERR, "setSocketNoBlocking failed to set new connection %s on port %s\n", hostBuff, portBuff);
973 close(peerInfo->fileDescriptor);
Alexandre Huff019cb422023-04-11 10:56:48 -0300974 if(peerInfo) {
dhirajverma9f59b572021-07-23 02:36:13 -0400975 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530976 peerInfo = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -0300977 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200978 break;
Alexandre Hufffff97942023-03-31 21:22:20 -0300979#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +0200980 }
czichy2175dd32022-05-17 15:24:51 +0300981 struct sctp_event_subscribe sctpevents;
982 memset( (void *)&sctpevents, 0, sizeof(sctpevents) );
983 sctpevents.sctp_data_io_event = 1;
984 setsockopt(peerInfo->fileDescriptor, SOL_SCTP, SCTP_EVENTS,(const void *)&sctpevents, sizeof(sctpevents) );
985
pwpmurthy7d6caa92023-05-19 15:39:41 +0000986 {
987 char *value = getenv("SCTP_ASSOC_MAX_RETRANS");
988 if (value)
989 {
990 int int_val = atoi(value);
991 mdclog_write(MDCLOG_INFO, "Changing sctp_association_max_retrans to %s, %d\n", value, int_val);
992 if (int_val > 0)
993 {
994 struct sctp_assocparams sctpassocparams;
995 memset((void *)&sctpassocparams, 0, sizeof(sctpassocparams));
996 sctpassocparams.sasoc_asocmaxrxt = int_val;
997 setsockopt(peerInfo->fileDescriptor, SOL_SCTP, SCTP_ASSOCINFO, (const void *)&sctpassocparams, sizeof(sctpassocparams));
998 }
999 }
1000 }
1001
aa7133@att.com84bd3342020-03-16 18:04:57 +02001002 auto ans = getnameinfo(&in_addr, in_len,
aa7133@att.com96c9b882020-03-25 14:50:40 +02001003 peerInfo->hostName, NI_MAXHOST,
1004 peerInfo->portNumber, NI_MAXSERV, (unsigned )((unsigned int)NI_NUMERICHOST | (unsigned int)NI_NUMERICSERV));
aa7133@att.com84bd3342020-03-16 18:04:57 +02001005 if (ans < 0) {
1006 mdclog_write(MDCLOG_ERR, "Failed to get info on connection request. %s\n", strerror(errno));
1007 close(peerInfo->fileDescriptor);
Alexandre Huff019cb422023-04-11 10:56:48 -03001008 if(peerInfo) {
dhirajverma9f59b572021-07-23 02:36:13 -04001009 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +05301010 peerInfo = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -03001011 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001012 break;
1013 }
1014 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1015 mdclog_write(MDCLOG_DEBUG, "Accepted connection on descriptor %d (host=%s, port=%s)\n", peerInfo->fileDescriptor, peerInfo->hostName, peerInfo->portNumber);
1016 }
1017 peerInfo->isConnected = false;
1018 peerInfo->gotSetup = false;
1019 if (addToEpoll(params->epoll_fd,
1020 peerInfo,
1021 (EPOLLIN | EPOLLET),
1022 params->sctpMap, nullptr,
aa7133@att.combe92d712020-03-18 17:30:39 +02001023 0) != 0) {
Alexandre Huff019cb422023-04-11 10:56:48 -03001024 if(peerInfo) {
dhirajverma9f59b572021-07-23 02:36:13 -04001025 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +05301026 peerInfo = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -03001027 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001028 break;
1029 }
aa7133@att.com6680c3b2020-03-22 12:06:58 +02001030 break;
aa7133@att.com84bd3342020-03-16 18:04:57 +02001031 }
ss412g1a79bdf2019-10-24 12:03:05 +03001032 } else if (params->rmrListenFd == events[i].data.fd) {
1033 // got message from XAPP
aa7133@att.comde40d1c2020-08-26 16:19:20 +03001034 //num_of_XAPP_messages.fetch_add(1, std::memory_order_release);
ss412g1a79bdf2019-10-24 12:03:05 +03001035 num_of_messages.fetch_add(1, std::memory_order_release);
1036 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comf13529a2020-08-27 11:21:16 +03001037 mdclog_write(MDCLOG_DEBUG, "new RMR message");
ss412g1a79bdf2019-10-24 12:03:05 +03001038 }
aa7133@att.com6680c3b2020-03-22 12:06:58 +02001039 if (receiveXappMessages(params->sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03001040 rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001041 message.message.time) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03001042 mdclog_write(MDCLOG_ERR, "Error handling Xapp message");
1043 }
ss412g3bac2da2020-01-05 11:52:19 +02001044 } else if (params->inotifyFD == events[i].data.fd) {
1045 mdclog_write(MDCLOG_INFO, "Got event from inotify (configuration update)");
1046 handleConfigChange(params);
ss412g1a79bdf2019-10-24 12:03:05 +03001047 } else {
1048 /* We RMR_ERR_RETRY have data on the fd waiting to be read. Read and display it.
1049 * We must read whatever data is available completely, as we are running
1050 * in edge-triggered mode and won't get a notification again for the same data. */
1051 num_of_messages.fetch_add(1, std::memory_order_release);
1052 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1053 mdclog_write(MDCLOG_DEBUG, "new message from SCTP, epoll flags are : %0x", events[i].events);
1054 }
1055 receiveDataFromSctp(&events[i],
1056 params->sctpMap,
1057 num_of_SCTP_messages,
1058 rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001059 message.message.time);
ss412g1a79bdf2019-10-24 12:03:05 +03001060 }
1061
1062 clock_gettime(CLOCK_MONOTONIC, &end);
1063 if (mdclog_level_get() >= MDCLOG_INFO) {
1064 totalTime += ((end.tv_sec + 1.0e-9 * end.tv_nsec) -
1065 ((double) start.tv_sec + 1.0e-9 * start.tv_nsec));
1066 }
1067 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1068 mdclog_write(MDCLOG_DEBUG, "message handling is %ld seconds %ld nanoseconds",
1069 end.tv_sec - start.tv_sec,
1070 end.tv_nsec - start.tv_nsec);
1071 }
1072 }
dhirajverma6cf28612021-06-23 04:53:34 -04001073#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04001074 break;
dhirajverma6cf28612021-06-23 04:53:34 -04001075#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001076 }
ss412g1a79bdf2019-10-24 12:03:05 +03001077}
1078
1079/**
1080 *
ss412g3bac2da2020-01-05 11:52:19 +02001081 * @param sctpParams
1082 */
1083void handleConfigChange(sctp_params_t *sctpParams) {
1084 char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event))));
1085 const struct inotify_event *event;
1086 char *ptr;
dhirajverma60f8bef2021-06-29 07:22:58 -04001087#ifdef UNIT_TEST
1088 struct inotify_event tmpEvent;
1089#endif
ss412g3bac2da2020-01-05 11:52:19 +02001090 path p = (sctpParams->configFilePath + "/" + sctpParams->configFileName).c_str();
1091 auto endlessLoop = true;
1092 while (endlessLoop) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001093#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
dhirajverma93b6d9c2021-07-10 00:49:13 -04001094 auto len = read(sctpParams->inotifyFD, buf, sizeof buf);
dhirajverma60f8bef2021-06-29 07:22:58 -04001095#else
1096 auto len=10;
1097#endif
ss412g3bac2da2020-01-05 11:52:19 +02001098 if (len == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001099#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001100 if (errno != EAGAIN) {
1101 mdclog_write(MDCLOG_ERR, "read %s ", strerror(errno));
1102 endlessLoop = false;
1103 continue;
1104 }
1105 else {
1106 endlessLoop = false;
1107 continue;
1108 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001109#endif
ss412g3bac2da2020-01-05 11:52:19 +02001110 }
1111
1112 for (ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + event->len) {
dhirajverma60f8bef2021-06-29 07:22:58 -04001113#ifndef UNIT_TEST
1114 event = (const struct inotify_event *)ptr;
1115#else
1116 tmpEvent.mask = (uint32_t)IN_CLOSE_WRITE;
1117 event = &tmpEvent;
1118#endif
ss412g3bac2da2020-01-05 11:52:19 +02001119 if (event->mask & (uint32_t)IN_ISDIR) {
1120 continue;
1121 }
1122
1123 // the directory name
1124 if (sctpParams->inotifyWD == event->wd) {
1125 // not the directory
1126 }
1127 if (event->len) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001128#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comdfc1db92020-03-31 17:32:04 +03001129 auto retVal = strcmp(sctpParams->configFileName.c_str(), event->name);
1130 if (retVal != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001131 continue;
1132 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001133#endif
ss412g3bac2da2020-01-05 11:52:19 +02001134 }
1135 // only the file we want
1136 if (event->mask & (uint32_t)IN_CLOSE_WRITE) {
aa7133@att.comdfc1db92020-03-31 17:32:04 +03001137 if (mdclog_level_get() >= MDCLOG_INFO) {
1138 mdclog_write(MDCLOG_INFO, "Configuration file changed");
1139 }
ss412g3bac2da2020-01-05 11:52:19 +02001140 if (exists(p)) {
1141 const int size = 2048;
1142 auto fileSize = file_size(p);
1143 if (fileSize > size) {
1144 mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size);
1145 return;
1146 }
1147 } else {
1148 mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str());
1149 return;
1150 }
1151
1152 ReadConfigFile conf;
1153 if (conf.openConfigFile(p.string()) == -1) {
1154 mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s",
1155 p.string().c_str(), strerror(errno));
1156 return;
1157 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001158 auto tmpStr = conf.getStringValue("trace");
ss412g3bac2da2020-01-05 11:52:19 +02001159 if (tmpStr.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +03001160 mdclog_write(MDCLOG_ERR, "illegal trace. Set trace to stop");
ss412g3bac2da2020-01-05 11:52:19 +02001161 tmpStr = "stop";
1162 }
1163
1164 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
1165 if ((tmpStr.compare("start")) == 0) {
1166 mdclog_write(MDCLOG_INFO, "Trace set to: start");
1167 sctpParams->trace = true;
1168 } else if ((tmpStr.compare("stop")) == 0) {
1169 mdclog_write(MDCLOG_INFO, "Trace set to: stop");
1170 sctpParams->trace = false;
1171 } else {
1172 mdclog_write(MDCLOG_ERR, "Trace was set to wrong value %s, set to stop", tmpStr.c_str());
1173 sctpParams->trace = false;
1174 }
1175 jsonTrace = sctpParams->trace;
ss412g4aeeda22020-06-16 14:12:41 +03001176
ss412g4aeeda22020-06-16 14:12:41 +03001177
ss412g3bac2da2020-01-05 11:52:19 +02001178 endlessLoop = false;
1179 }
dhirajverma60f8bef2021-06-29 07:22:58 -04001180#ifdef UNIT_TEST
1181 break;
1182#endif
ss412g3bac2da2020-01-05 11:52:19 +02001183 }
1184 }
1185}
1186
1187/**
1188 *
1189 * @param event
1190 * @param message
1191 * @param rmrMessageBuffer
1192 * @param params
ss412g3bac2da2020-01-05 11:52:19 +02001193 */
1194void handleEinprogressMessages(struct epoll_event &event,
1195 ReportingMessages_t &message,
1196 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001197 sctp_params_t *params) {
ss412g3bac2da2020-01-05 11:52:19 +02001198 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
1199 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1200
1201 mdclog_write(MDCLOG_INFO, "file descriptor %d got EPOLLOUT", peerInfo->fileDescriptor);
1202 auto retVal = 0;
1203 socklen_t retValLen = 0;
1204 auto rc = getsockopt(peerInfo->fileDescriptor, SOL_SOCKET, SO_ERROR, &retVal, &retValLen);
1205 if (rc != 0 || retVal != 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001206#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001207 if (rc != 0) {
1208 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1209 "%s|Failed SCTP Connection, after EINPROGRESS the getsockopt%s",
1210 peerInfo->enodbName, strerror(errno));
1211 } else if (retVal != 0) {
1212 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1213 "%s|Failed SCTP Connection after EINPROGRESS, SO_ERROR",
1214 peerInfo->enodbName);
1215 }
1216
1217 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1218 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
1219 mdclog_write(MDCLOG_ERR, "%s", rmrMessageBuffer.sendMessage->payload);
1220 message.message.direction = 'N';
aa7133@att.combe92d712020-03-18 17:30:39 +02001221 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001222 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1223 }
dhirajverma31768a92021-05-06 12:38:49 +05301224#endif
ss412g3bac2da2020-01-05 11:52:19 +02001225 memset(peerInfo->asnData, 0, peerInfo->asnLength);
1226 peerInfo->asnLength = 0;
1227 peerInfo->mtype = 0;
ss412g3bac2da2020-01-05 11:52:19 +02001228 return;
1229 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001230#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001231 peerInfo->isConnected = true;
1232
1233 if (modifyToEpoll(params->epoll_fd, peerInfo, (EPOLLIN | EPOLLET), params->sctpMap, peerInfo->enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02001234 peerInfo->mtype) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001235 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_MOD");
ss412g3bac2da2020-01-05 11:52:19 +02001236 return;
1237 }
1238
1239 message.message.asndata = (unsigned char *)peerInfo->asnData;
1240 message.message.asnLength = peerInfo->asnLength;
1241 message.message.messageType = peerInfo->mtype;
1242 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1243 num_of_messages.fetch_add(1, std::memory_order_release);
1244 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1245 mdclog_write(MDCLOG_DEBUG, "send the delayed SETUP/ENDC SETUP to sctp for %s",
1246 message.message.enodbName);
1247 }
aa7133@att.combe92d712020-03-18 17:30:39 +02001248 if (sendSctpMsg(peerInfo, message, params->sctpMap) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001249 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1250 mdclog_write(MDCLOG_DEBUG, "Error write to SCTP %s %d", __func__, __LINE__);
1251 }
ss412g3bac2da2020-01-05 11:52:19 +02001252 return;
1253 }
1254
1255 memset(peerInfo->asnData, 0, peerInfo->asnLength);
1256 peerInfo->asnLength = 0;
1257 peerInfo->mtype = 0;
Alexandre Hufffff97942023-03-31 21:22:20 -03001258#endif
ss412g3bac2da2020-01-05 11:52:19 +02001259}
1260
1261
1262void handlepoll_error(struct epoll_event &event,
1263 ReportingMessages_t &message,
1264 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001265 sctp_params_t *params) {
sandeekuea662102022-11-08 18:51:20 +05301266 if ((event.data.fd != params->rmrListenFd) && (event.data.ptr != nullptr)) {
ss412g3bac2da2020-01-05 11:52:19 +02001267 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
1268 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on fd %d, RAN NAME : %s",
1269 event.events, peerInfo->fileDescriptor, peerInfo->enodbName);
dhirajverma93b6d9c2021-07-10 00:49:13 -04001270#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001271 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1272 "%s|Failed SCTP Connection",
1273 peerInfo->enodbName);
1274 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1275 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
1276
1277 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1278 message.message.direction = 'N';
aa7133@att.combe92d712020-03-18 17:30:39 +02001279 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001280 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1281 }
dhirajverma31768a92021-05-06 12:38:49 +05301282#endif
ss412g3bac2da2020-01-05 11:52:19 +02001283 close(peerInfo->fileDescriptor);
sandeekuea662102022-11-08 18:51:20 +05301284 //params->sctpMap->erase(peerInfo->enodbName);
aa7133@att.combe92d712020-03-18 17:30:39 +02001285 cleanHashEntry((ConnectedCU_t *) event.data.ptr, params->sctpMap);
ss412g3bac2da2020-01-05 11:52:19 +02001286 } else {
1287 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on RMR FD", event.events);
1288 }
ss412g3bac2da2020-01-05 11:52:19 +02001289}
1290/**
1291 *
ss412g1a79bdf2019-10-24 12:03:05 +03001292 * @param socket
1293 * @return
1294 */
1295int setSocketNoBlocking(int socket) {
1296 auto flags = fcntl(socket, F_GETFL, 0);
1297
1298 if (flags == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +03001299 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03001300 return -1;
1301 }
1302
1303 flags = (unsigned) flags | (unsigned) O_NONBLOCK;
1304 if (fcntl(socket, F_SETFL, flags) == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +03001305 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03001306 return -1;
1307 }
1308
1309 return 0;
1310}
1311
1312/**
1313 *
1314 * @param val
1315 * @param m
ss412g1a79bdf2019-10-24 12:03:05 +03001316 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001317void cleanHashEntry(ConnectedCU_t *val, Sctp_Map_t *m) {
Alexandre Huff019cb422023-04-11 10:56:48 -03001318 if(val != nullptr) {
1319 char *dummy;
1320 auto port = (uint16_t) strtol(val->portNumber, &dummy, 10);
1321 char searchBuff[2048]{};
ss412g1a79bdf2019-10-24 12:03:05 +03001322
Alexandre Huff019cb422023-04-11 10:56:48 -03001323 snprintf(searchBuff, sizeof searchBuff, "host:%s:%d", val->hostName, port);
1324 if(m->find(searchBuff)) {
1325 m->erase(searchBuff);
1326 }
ss412g1a79bdf2019-10-24 12:03:05 +03001327
Alexandre Huff019cb422023-04-11 10:56:48 -03001328 if(m->find(val->enodbName)) {
1329 mdclog_write(MDCLOG_DEBUG, "remove key enodbName = %s from %s at line %d", val->enodbName, __FUNCTION__, __LINE__);
1330 m->erase(val->enodbName);
1331 }
dhirajverma31768a92021-05-06 12:38:49 +05301332#ifndef UNIT_TEST
Alexandre Huff019cb422023-04-11 10:56:48 -03001333 if(val) {
1334 free(val);
1335 val = nullptr;
1336 }
dhirajverma31768a92021-05-06 12:38:49 +05301337#endif
sandeekuea662102022-11-08 18:51:20 +05301338 }
ss412g1a79bdf2019-10-24 12:03:05 +03001339}
1340
1341/**
1342 *
aa7133@att.com409f2232020-10-29 13:06:45 +03001343 * @param fd file descriptor
ss412g1a79bdf2019-10-24 12:03:05 +03001344 * @param data the asn data to send
1345 * @param len length of the data
1346 * @param enodbName the enodbName as in the map for printing purpose
1347 * @param m map host information
1348 * @param mtype message number
aa7133@att.com409f2232020-10-29 13:06:45 +03001349 * @return 0 success, a negative number on fail
ss412g1a79bdf2019-10-24 12:03:05 +03001350 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001351int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_t *m) {
ss412g1a79bdf2019-10-24 12:03:05 +03001352 auto loglevel = mdclog_level_get();
Alexandre Hufffff97942023-03-31 21:22:20 -03001353#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001354 int fd = peerInfo->fileDescriptor;
czichy2175dd32022-05-17 15:24:51 +03001355 int streamId = fetchStreamId(peerInfo,message);
dhirajverma99990292021-07-05 10:03:59 -04001356#else
1357 int fd = FILE_DESCRIPTOR;
czichy2175dd32022-05-17 15:24:51 +03001358 int streamId = 0;
Alexandre Hufffff97942023-03-31 21:22:20 -03001359#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001360 if (loglevel >= MDCLOG_DEBUG) {
1361 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for CU %s, %s",
1362 message.message.enodbName, __FUNCTION__);
1363 }
1364
1365 while (true) {
czichy6dd00bc2023-03-03 15:43:29 +02001366 if (sctp_sendmsg(fd,message.message.asndata, message.message.asnLength,(struct sockaddr *) NULL, 0, htonl(E2AP_PPID), 0,streamId,0,0) < 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03001367 if (errno == EINTR) {
1368 continue;
1369 }
1370 mdclog_write(MDCLOG_ERR, "error writing to CU a message, %s ", strerror(errno));
Alexandre Hufffff97942023-03-31 21:22:20 -03001371#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +02001372 if (!peerInfo->isConnected) {
1373 mdclog_write(MDCLOG_ERR, "connection to CU %s is still in progress.", message.message.enodbName);
aa7133@att.com84bd3342020-03-16 18:04:57 +02001374 return -1;
1375 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001376#endif
Alexandre Hufffff97942023-03-31 21:22:20 -03001377#ifndef UNIT_TEST
aa7133@att.combe92d712020-03-18 17:30:39 +02001378 cleanHashEntry(peerInfo, m);
dhirajvermac40ea1f2021-07-08 12:52:30 -04001379 close(fd);
Alexandre Hufffff97942023-03-31 21:22:20 -03001380#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001381 char key[MAX_ENODB_NAME_SIZE * 2];
1382 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName,
1383 message.message.messageType);
1384 if (loglevel >= MDCLOG_DEBUG) {
1385 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
1386 }
aa7133@att.com96c9b882020-03-25 14:50:40 +02001387 auto tmp = m->find(key);
ss412g1a79bdf2019-10-24 12:03:05 +03001388 if (tmp) {
1389 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05301390 tmp = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03001391 }
1392 m->erase(key);
dhirajverma6cf28612021-06-23 04:53:34 -04001393#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001394 return -1;
dhirajverma6cf28612021-06-23 04:53:34 -04001395#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001396 }
1397 message.message.direction = 'D';
1398 // send report.buffer of size
1399 buildJsonMessage(message);
1400
1401 if (loglevel >= MDCLOG_DEBUG) {
1402 mdclog_write(MDCLOG_DEBUG,
1403 "SCTP message for CU %s sent from %s",
1404 message.message.enodbName,
1405 __FUNCTION__);
1406 }
ss412g1a79bdf2019-10-24 12:03:05 +03001407 return 0;
1408 }
1409}
1410
1411/**
1412 *
1413 * @param message
1414 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03001415 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001416void getRequestMetaData(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03001417 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
1418 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
1419
1420 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1421 mdclog_write(MDCLOG_DEBUG, "Message from Xapp RAN name = %s message length = %ld",
1422 message.message.enodbName, (unsigned long) message.message.asnLength);
1423 }
ss412g1a79bdf2019-10-24 12:03:05 +03001424}
1425
1426
ss412g1a79bdf2019-10-24 12:03:05 +03001427
1428/**
1429 *
1430 * @param events
1431 * @param sctpMap
1432 * @param numOfMessages
1433 * @param rmrMessageBuffer
1434 * @param ts
ss412g1a79bdf2019-10-24 12:03:05 +03001435 * @return
1436 */
1437int receiveDataFromSctp(struct epoll_event *events,
1438 Sctp_Map_t *sctpMap,
1439 int &numOfMessages,
1440 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001441 struct timespec &ts) {
ss412g1a79bdf2019-10-24 12:03:05 +03001442 /* We have data on the fd waiting to be read. Read and display it.
1443 * We must read whatever data is available completely, as we are running
1444 * in edge-triggered mode and won't get a notification again for the same data. */
aa7133@att.com84bd3342020-03-16 18:04:57 +02001445 ReportingMessages_t message {};
1446 auto done = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03001447 auto loglevel = mdclog_level_get();
czichy2175dd32022-05-17 15:24:51 +03001448 struct sctp_sndrcvinfo sndrcvinfo;
1449 int flags;
1450 int streamId;
aa7133@att.com84bd3342020-03-16 18:04:57 +02001451
ss412g1a79bdf2019-10-24 12:03:05 +03001452 // get the identity of the interface
sandeekuea662102022-11-08 18:51:20 +05301453 if (events->data.ptr != nullptr){
Alexandre Huff019cb422023-04-11 10:56:48 -03001454 message.peerInfo = (ConnectedCU_t *)events->data.ptr;
sandeekuea662102022-11-08 18:51:20 +05301455 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001456
ss412g1a79bdf2019-10-24 12:03:05 +03001457 struct timespec start{0, 0};
aa7133@att.com409f2232020-10-29 13:06:45 +03001458 struct timespec decodeStart{0, 0};
ss412g1a79bdf2019-10-24 12:03:05 +03001459 struct timespec end{0, 0};
1460
1461 E2AP_PDU_t *pdu = nullptr;
1462
ss412g1a79bdf2019-10-24 12:03:05 +03001463 while (true) {
1464 if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001465 mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP %d fd", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001466 clock_gettime(CLOCK_MONOTONIC, &start);
1467 }
1468 // read the buffer directly to rmr payload
1469 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
Alexandre Hufffff97942023-03-31 21:22:20 -03001470#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001471 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
czichy2175dd32022-05-17 15:24:51 +03001472 sctp_recvmsg(message.peerInfo->fileDescriptor, rmrMessageBuffer.sendMessage->payload, RECEIVE_SCTP_BUFFER_SIZE,(struct sockaddr *) NULL, 0, &sndrcvinfo, &flags);
1473 mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP fd %d stream %d ", message.peerInfo->fileDescriptor, sndrcvinfo.sinfo_stream);
1474 streamId = sndrcvinfo.sinfo_stream;
dhirajverma99990292021-07-05 10:03:59 -04001475#else
1476 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
czichy2175dd32022-05-17 15:24:51 +03001477 streamId = 0;
dhirajverma99990292021-07-05 10:03:59 -04001478#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +02001479
ss412g1a79bdf2019-10-24 12:03:05 +03001480 if (loglevel >= MDCLOG_DEBUG) {
1481 mdclog_write(MDCLOG_DEBUG, "Finish Read from SCTP %d fd message length = %ld",
aa7133@att.com96c9b882020-03-25 14:50:40 +02001482 message.peerInfo->fileDescriptor, message.message.asnLength);
ss412g1a79bdf2019-10-24 12:03:05 +03001483 }
aa7133@att.com16c799b2020-03-24 18:01:51 +02001484
aa7133@att.com84bd3342020-03-16 18:04:57 +02001485 memcpy(message.message.enodbName, message.peerInfo->enodbName, sizeof(message.peerInfo->enodbName));
ss412g1a79bdf2019-10-24 12:03:05 +03001486 message.message.direction = 'U';
1487 message.message.time.tv_nsec = ts.tv_nsec;
1488 message.message.time.tv_sec = ts.tv_sec;
1489
1490 if (message.message.asnLength < 0) {
1491 if (errno == EINTR) {
1492 continue;
1493 }
1494 /* If errno == EAGAIN, that means we have read all
aa7133@att.com84bd3342020-03-16 18:04:57 +02001495 data. So goReportingMessages_t back to the main loop. */
ss412g1a79bdf2019-10-24 12:03:05 +03001496 if (errno != EAGAIN) {
1497 mdclog_write(MDCLOG_ERR, "Read error, %s ", strerror(errno));
1498 done = 1;
1499 } else if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001500 mdclog_write(MDCLOG_DEBUG, "EAGAIN - descriptor = %d", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001501 }
1502 break;
1503 } else if (message.message.asnLength == 0) {
1504 /* End of file. The remote has closed the connection. */
1505 if (loglevel >= MDCLOG_INFO) {
1506 mdclog_write(MDCLOG_INFO, "END of File Closed connection - descriptor = %d",
aa7133@att.com84bd3342020-03-16 18:04:57 +02001507 message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001508 }
1509 done = 1;
1510 break;
1511 }
1512
ss412g1a79bdf2019-10-24 12:03:05 +03001513 if (loglevel >= MDCLOG_DEBUG) {
swc58d4f5d2020-10-20 15:08:38 +09001514 char printBuffer[RECEIVE_SCTP_BUFFER_SIZE]{};
ss412g1a79bdf2019-10-24 12:03:05 +03001515 char *tmp = printBuffer;
1516 for (size_t i = 0; i < (size_t)message.message.asnLength; ++i) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001517 snprintf(tmp, 3, "%02x", message.message.asndata[i]);
ss412g1a79bdf2019-10-24 12:03:05 +03001518 tmp += 2;
1519 }
1520 printBuffer[message.message.asnLength] = 0;
1521 clock_gettime(CLOCK_MONOTONIC, &end);
1522 mdclog_write(MDCLOG_DEBUG, "Before Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds",
aa7133@att.com84bd3342020-03-16 18:04:57 +02001523 message.peerInfo->enodbName, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001524 mdclog_write(MDCLOG_DEBUG, "PDU buffer length = %ld, data = : %s", message.message.asnLength,
1525 printBuffer);
aa7133@att.com409f2232020-10-29 13:06:45 +03001526 clock_gettime(CLOCK_MONOTONIC, &decodeStart);
ss412g1a79bdf2019-10-24 12:03:05 +03001527 }
dhirajverma99990292021-07-05 10:03:59 -04001528#ifndef UNIT_TEST
aa7133@att.com7b437f72020-03-30 13:25:54 +03001529 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu,
dhirajverma99990292021-07-05 10:03:59 -04001530 message.message.asndata, message.message.asnLength);
1531#else
1532 asn_dec_rval_t rval = {RC_OK, 0};
1533 pdu = (E2AP_PDU_t*)rmrMessageBuffer.sendMessage->tp_buf;
1534#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001535 if (rval.code != RC_OK) {
1536 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from RAN : %s", rval.code,
aa7133@att.com84bd3342020-03-16 18:04:57 +02001537 message.peerInfo->enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04001538 if (pdu != nullptr) {
1539 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1540 pdu = nullptr;
1541 }
ss412g1a79bdf2019-10-24 12:03:05 +03001542 break;
1543 }
1544
1545 if (loglevel >= MDCLOG_DEBUG) {
1546 clock_gettime(CLOCK_MONOTONIC, &end);
1547 mdclog_write(MDCLOG_DEBUG, "After Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds",
aa7133@att.com409f2232020-10-29 13:06:45 +03001548 message.peerInfo->enodbName, end.tv_sec - decodeStart.tv_sec, end.tv_nsec - decodeStart.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001549 char *printBuffer;
1550 size_t size;
1551 FILE *stream = open_memstream(&printBuffer, &size);
1552 asn_fprint(stream, &asn_DEF_E2AP_PDU, pdu);
1553 mdclog_write(MDCLOG_DEBUG, "Encoding E2AP PDU past : %s", printBuffer);
aa7133@att.com409f2232020-10-29 13:06:45 +03001554 clock_gettime(CLOCK_MONOTONIC, &decodeStart);
Byonggon Chuncae9bd52020-11-18 13:37:29 +09001555
1556 fclose(stream);
1557 free(printBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001558 }
1559
1560 switch (pdu->present) {
1561 case E2AP_PDU_PR_initiatingMessage: {//initiating message
czichy2175dd32022-05-17 15:24:51 +03001562 asnInitiatingRequest(pdu, sctpMap,message, rmrMessageBuffer, streamId);
ss412g1a79bdf2019-10-24 12:03:05 +03001563 break;
1564 }
1565 case E2AP_PDU_PR_successfulOutcome: { //successful outcome
aa7133@att.com409f2232020-10-29 13:06:45 +03001566 asnSuccessfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001567 break;
1568 }
1569 case E2AP_PDU_PR_unsuccessfulOutcome: { //Unsuccessful Outcome
aa7133@att.com7b437f72020-03-30 13:25:54 +03001570 asnUnSuccsesfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001571 break;
1572 }
1573 default:
1574 mdclog_write(MDCLOG_ERR, "Unknown index %d in E2AP PDU", pdu->present);
1575 break;
1576 }
1577 if (loglevel >= MDCLOG_DEBUG) {
1578 clock_gettime(CLOCK_MONOTONIC, &end);
1579 mdclog_write(MDCLOG_DEBUG,
1580 "After processing message and sent to rmr for : %s, Read time is : %ld seconds, %ld nanoseconds",
aa7133@att.com409f2232020-10-29 13:06:45 +03001581 message.peerInfo->enodbName, end.tv_sec - decodeStart.tv_sec, end.tv_nsec - decodeStart.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001582 }
1583 numOfMessages++;
dhirajverma9f59b572021-07-23 02:36:13 -04001584#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001585 if (pdu != nullptr) {
dhirajverma9f59b572021-07-23 02:36:13 -04001586 // ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); /* With reset we were not freeing the memory and was causing the leak here. */
1587 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1588 pdu = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03001589 }
dhirajverma9f59b572021-07-23 02:36:13 -04001590#else
dhirajverma99990292021-07-05 10:03:59 -04001591 done = 1;
1592 break;
1593#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001594 }
ss412g1a79bdf2019-10-24 12:03:05 +03001595
1596 if (done) {
1597 if (loglevel >= MDCLOG_INFO) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001598 mdclog_write(MDCLOG_INFO, "Closed connection - descriptor = %d", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001599 }
1600 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
1601 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
aa7133@att.com96c9b882020-03-25 14:50:40 +02001602 256,
1603 "%s|CU disconnected unexpectedly",
1604 message.peerInfo->enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03001605 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
Alexandre Hufffff97942023-03-31 21:22:20 -03001606#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03001607 if (sendRequestToXapp(message,
1608 RIC_SCTP_CONNECTION_FAILURE,
aa7133@att.combe92d712020-03-18 17:30:39 +02001609 rmrMessageBuffer) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03001610 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1611 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001612#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001613
1614 /* Closing descriptor make epoll remove it from the set of descriptors which are monitored. */
sandeekuea662102022-11-08 18:51:20 +05301615#ifndef UNIT_TEST
1616 pthread_mutex_lock(&thread_lock);
1617 if (fcntl(message.peerInfo->fileDescriptor, F_GETFD) != -1) {
1618 mdclog_write(MDCLOG_DEBUG, "Closing connection - descriptor = %d", message.peerInfo->fileDescriptor);
1619 close(message.peerInfo->fileDescriptor);
1620 cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap);
1621 }
1622 pthread_mutex_unlock(&thread_lock);
1623#else
aa7133@att.com84bd3342020-03-16 18:04:57 +02001624 close(message.peerInfo->fileDescriptor);
aa7133@att.combe92d712020-03-18 17:30:39 +02001625 cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap);
Alexandre Hufffff97942023-03-31 21:22:20 -03001626#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001627 }
1628 if (loglevel >= MDCLOG_DEBUG) {
1629 clock_gettime(CLOCK_MONOTONIC, &end);
1630 mdclog_write(MDCLOG_DEBUG, "from receive SCTP to send RMR time is %ld seconds and %ld nanoseconds",
1631 end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
1632
1633 }
ss412g1a79bdf2019-10-24 12:03:05 +03001634 return 0;
1635}
1636
aa7133@att.com409f2232020-10-29 13:06:45 +03001637static void buildAndSendSetupRequest(ReportingMessages_t &message,
aa7133@att.com84bd3342020-03-16 18:04:57 +02001638 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001639 E2AP_PDU_t *pdu/*,
ss412g4aeeda22020-06-16 14:12:41 +03001640 string const &messageName,
1641 string const &ieName,
1642 vector<string> &functionsToAdd_v,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001643 vector<string> &functionsToModified_v*/) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001644 auto logLevel = mdclog_level_get();
aa7133@att.com84bd3342020-03-16 18:04:57 +02001645 // now we can send the data to e2Mgr
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001646
ss412g4aeeda22020-06-16 14:12:41 +03001647 asn_enc_rval_t er;
1648 auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
Byonggon Chun51885f32020-11-18 15:31:04 +09001649 unsigned char *buffer = nullptr;
1650 buffer = (unsigned char *) calloc(buffer_size, sizeof(unsigned char));
1651 if(!buffer)
1652 {
Alexandre Hufffff97942023-03-31 21:22:20 -03001653#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
Byonggon Chun51885f32020-11-18 15:31:04 +09001654 mdclog_write(MDCLOG_ERR, "Allocating buffer for %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1655 return;
Alexandre Hufffff97942023-03-31 21:22:20 -03001656#endif
Byonggon Chun51885f32020-11-18 15:31:04 +09001657 }
ss412g4aeeda22020-06-16 14:12:41 +03001658 while (true) {
ss412g4aeeda22020-06-16 14:12:41 +03001659 er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size);
1660 if (er.encoded == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001661#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g4aeeda22020-06-16 14:12:41 +03001662 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1663 return;
Alexandre Hufffff97942023-03-31 21:22:20 -03001664#endif
ss412g4aeeda22020-06-16 14:12:41 +03001665 } else if (er.encoded > (ssize_t) buffer_size) {
1666 buffer_size = er.encoded + 128;
Alexandre Hufffff97942023-03-31 21:22:20 -03001667#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g4aeeda22020-06-16 14:12:41 +03001668 mdclog_write(MDCLOG_WARN, "Buffer of size %d is to small for %s. Reallocate buffer of size %d",
1669 (int) buffer_size,
1670 asn_DEF_E2AP_PDU.name, buffer_size);
1671 buffer_size = er.encoded + 128;
Byonggon Chun51885f32020-11-18 15:31:04 +09001672
1673 unsigned char *newBuffer = nullptr;
1674 newBuffer = (unsigned char *) realloc(buffer, buffer_size);
1675 if (!newBuffer)
1676 {
1677 // out of memory
1678 mdclog_write(MDCLOG_ERR, "Reallocating buffer for %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1679 free(buffer);
sandeekuea662102022-11-08 18:51:20 +05301680 buffer = nullptr;
Byonggon Chun51885f32020-11-18 15:31:04 +09001681 return;
1682 }
1683 buffer = newBuffer;
ss412g4aeeda22020-06-16 14:12:41 +03001684 continue;
Alexandre Hufffff97942023-03-31 21:22:20 -03001685#endif
ss412g4aeeda22020-06-16 14:12:41 +03001686 }
1687 buffer[er.encoded] = '\0';
1688 break;
1689 }
1690 // encode to xml
1691
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001692 string res((char *)buffer);
1693 res.erase(std::remove(res.begin(), res.end(), '\n'), res.end());
1694 res.erase(std::remove(res.begin(), res.end(), '\t'), res.end());
1695 res.erase(std::remove(res.begin(), res.end(), ' '), res.end());
1696
1697// string res {};
1698// if (!functionsToAdd_v.empty() || !functionsToModified_v.empty()) {
1699// res = buildXmlData(messageName, ieName, functionsToAdd_v, functionsToModified_v, buffer, (size_t) er.encoded);
1700// }
ss412g4aeeda22020-06-16 14:12:41 +03001701 rmr_mbuf_t *rmrMsg;
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001702// if (res.length() == 0) {
1703// rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size + 256);
1704// rmrMsg->len = snprintf((char *) rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s",
1705// message.peerInfo->sctpParams->myIP.c_str(),
1706// message.peerInfo->sctpParams->rmrPort,
1707// buffer);
1708// } else {
ss412g4aeeda22020-06-16 14:12:41 +03001709 rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, (int)res.length() + 256);
1710 rmrMsg->len = snprintf((char *) rmrMsg->payload, res.length() + 256, "%s:%d|%s",
1711 message.peerInfo->sctpParams->myIP.c_str(),
1712 message.peerInfo->sctpParams->rmrPort,
1713 res.c_str());
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001714// }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001715
ss412g4aeeda22020-06-16 14:12:41 +03001716 if (logLevel >= MDCLOG_DEBUG) {
1717 mdclog_write(MDCLOG_DEBUG, "Setup request of size %d :\n %s\n", rmrMsg->len, rmrMsg->payload);
1718 }
1719 // send to RMR
1720 rmrMsg->mtype = message.message.messageType;
1721 rmrMsg->state = 0;
1722 rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName));
aa7133@att.com84bd3342020-03-16 18:04:57 +02001723
ss412g4aeeda22020-06-16 14:12:41 +03001724 static unsigned char tx[32];
1725 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1726 rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx));
dhirajverma60f8bef2021-06-29 07:22:58 -04001727#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +03001728 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
dhirajverma60f8bef2021-06-29 07:22:58 -04001729#endif
ss412g4aeeda22020-06-16 14:12:41 +03001730 if (rmrMsg == nullptr) {
1731 mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr");
1732 } else if (rmrMsg->state != 0) {
1733 char meid[RMR_MAX_MEID]{};
1734 if (rmrMsg->state == RMR_ERR_RETRY) {
1735 usleep(5);
1736 rmrMsg->state = 0;
1737 mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s",
1738 rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid));
dhirajverma60f8bef2021-06-29 07:22:58 -04001739#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +03001740 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
dhirajverma60f8bef2021-06-29 07:22:58 -04001741#endif
ss412g4aeeda22020-06-16 14:12:41 +03001742 if (rmrMsg == nullptr) {
1743 mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr");
1744 } else if (rmrMsg->state != 0) {
1745 mdclog_write(MDCLOG_ERR,
1746 "RMR Retry failed %s sending request %d to Xapp from %s",
aa7133@att.com84bd3342020-03-16 18:04:57 +02001747 translateRmrErrorMessages(rmrMsg->state).c_str(),
1748 rmrMsg->mtype,
1749 rmr_get_meid(rmrMsg, (unsigned char *) meid));
1750 }
ss412g4aeeda22020-06-16 14:12:41 +03001751 } else {
1752 mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s",
1753 translateRmrErrorMessages(rmrMsg->state).c_str(),
1754 rmrMsg->mtype,
1755 rmr_get_meid(rmrMsg, (unsigned char *) meid));
aa7133@att.combc110772020-03-25 09:45:14 +02001756 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001757 }
ss412g4aeeda22020-06-16 14:12:41 +03001758 message.peerInfo->gotSetup = true;
1759 buildJsonMessage(message);
Byonggon Chun51885f32020-11-18 15:31:04 +09001760
ss412g4aeeda22020-06-16 14:12:41 +03001761 if (rmrMsg != nullptr) {
1762 rmr_free_msg(rmrMsg);
1763 }
Byonggon Chun51885f32020-11-18 15:31:04 +09001764 free(buffer);
sandeekuea662102022-11-08 18:51:20 +05301765 buffer = nullptr;
Byonggon Chun51885f32020-11-18 15:31:04 +09001766
1767 return;
aa7133@att.com84bd3342020-03-16 18:04:57 +02001768}
aa7133@att.comc5a15202020-04-05 19:57:01 +03001769
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001770#if 0
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001771int RAN_Function_list_To_Vector(RANfunctions_List_t& list, vector <string> &runFunXML_v) {
1772 auto index = 0;
1773 runFunXML_v.clear();
1774 for (auto j = 0; j < list.list.count; j++) {
1775 auto *raNfunctionItemIEs = (RANfunction_ItemIEs_t *)list.list.array[j];
1776 if (raNfunctionItemIEs->id == ProtocolIE_ID_id_RANfunction_Item &&
1777 (raNfunctionItemIEs->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item)) {
1778 // encode to xml
1779 E2SM_gNB_NRT_RANfunction_Definition_t *ranFunDef = nullptr;
1780 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER,
1781 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1782 (void **)&ranFunDef,
1783 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.buf,
1784 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.size);
1785 if (rval.code != RC_OK) {
1786 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2SM message from : %s",
1787 rval.code,
1788 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name);
1789 return -1;
1790 }
1791
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001792 auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1793 unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
ss412g4aeeda22020-06-16 14:12:41 +03001794 memset(xml_buffer, 0, RECEIVE_SCTP_BUFFER_SIZE * 2);
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001795 // encode to xml
1796 auto er = asn_encode_to_buffer(nullptr,
1797 ATS_BASIC_XER,
1798 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1799 ranFunDef,
1800 xml_buffer,
1801 xml_buffer_size);
1802 if (er.encoded == -1) {
1803 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s",
1804 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1805 strerror(errno));
1806 } else if (er.encoded > (ssize_t)xml_buffer_size) {
1807 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
1808 (int) xml_buffer_size,
1809 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, __func__, __LINE__);
1810 } else {
1811 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1812 mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU number %d : %s",
1813 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1814 index++,
1815 xml_buffer);
1816 }
ss412g4aeeda22020-06-16 14:12:41 +03001817
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001818 string runFuncs = (char *)(xml_buffer);
1819 runFunXML_v.emplace_back(runFuncs);
1820 }
1821 }
1822 }
1823 return 0;
1824}
aa7133@att.comc5a15202020-04-05 19:57:01 +03001825
ss412g4aeeda22020-06-16 14:12:41 +03001826int collectServiceUpdate_RequestData(E2AP_PDU_t *pdu,
1827 Sctp_Map_t *sctpMap,
1828 ReportingMessages_t &message,
1829 vector <string> &RANfunctionsAdded_v,
1830 vector <string> &RANfunctionsModified_v) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03001831 memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE);
ss412g4aeeda22020-06-16 14:12:41 +03001832 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.count; i++) {
1833 auto *ie = pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.array[i];
1834 if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
1835 if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctionsID_List) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03001836 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001837 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
1838 ie->value.choice.RANfunctions_List.list.count);
aa7133@att.comc5a15202020-04-05 19:57:01 +03001839 }
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001840 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) {
1841 return -1;
1842 }
1843 }
1844 } else if (ie->id == ProtocolIE_ID_id_RANfunctionsModified) {
ss412g4aeeda22020-06-16 14:12:41 +03001845 if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List) {
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001846 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1847 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
1848 ie->value.choice.RANfunctions_List.list.count);
1849 }
1850 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsModified_v) != 0 ) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001851 return -1;
aa7133@att.comc5a15202020-04-05 19:57:01 +03001852 }
1853 }
1854 }
1855 }
1856 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1857 mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries",
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001858 RANfunctionsAdded_v.size());
aa7133@att.comc5a15202020-04-05 19:57:01 +03001859 }
1860 return 0;
1861}
ss412g4aeeda22020-06-16 14:12:41 +03001862
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001863#endif
ss412g4aeeda22020-06-16 14:12:41 +03001864
1865
Mohamed Abukar64f37242021-08-15 12:39:56 +00001866void buildE2TPrometheusCounters(sctp_params_t &sctpParams) {
1867 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestMsgs"}});
1868 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestBytes"}});
1869
1870 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupResponseMsgs"}});
1871 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupResponseBytes"}});
1872
1873 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestFailureMsgs"}});
1874 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestFailureBytes"}});
1875
czichy2175dd32022-05-17 15:24:51 +03001876 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateMsgs"}});
1877 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateBytes"}});
1878
1879 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateResponseMsgs"}});
1880 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateResponseBytes"}});
1881
1882 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateFailureMsgs"}});
1883 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateFailureBytes"}});
1884
Mohamed Abukar64f37242021-08-15 12:39:56 +00001885 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &sctpParams.prometheusFamily->Add({{"counter", "ErrorIndicationMsgs"}});
1886 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &sctpParams.prometheusFamily->Add({{"counter", "ErrorIndicationBytes"}});
1887
1888 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetRequestMsgs"}});
1889 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetRequestBytes"}});
1890
1891 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetAckMsgs"}});
1892 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetAckBytes"}});
1893
1894 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateMsgs"}});
1895 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateBytes"}});
1896
1897 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateRespMsgs"}});
1898 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateRespBytes"}});
1899
1900 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateFailureMsgs"}});
1901 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateFailureBytes"}});
1902
1903 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlMsgs"}});
1904 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlBytes"}});
1905
1906 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlAckMsgs"}});
1907 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlAckBytes"}});
1908
1909 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlFailureMsgs"}});
1910 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlFailureBytes"}});
1911
1912 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionMsgs"}});
1913 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionBytes"}});
1914
1915 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionAckMsgs"}});
1916 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionAckBytes"}});
1917
1918 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionFailureMsgs"}});
1919 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionFailureBytes"}});
1920
1921 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteMsgs"}});
1922 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteBytes"}});
1923
1924 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteAckMsgs"}});
1925 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteAckBytes"}});
1926
1927 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteFailMsgs"}});
1928 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteFailBytes"}});
1929
1930 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication] = &sctpParams.prometheusFamily->Add({{"counter", "RICIndicationMsgs"}});
1931 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication] = &sctpParams.prometheusFamily->Add({{"counter", "RICIndicationBytes"}});
1932
1933 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceQueryMsgs"}});
1934 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceQueryBytes"}});
gunjarastogi85f507f2023-01-18 16:27:55 +05301935
1936 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteRequiredMsgs"}});
1937 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteRequiredBytes"}});
1938
Mohamed Abukar64f37242021-08-15 12:39:56 +00001939}
1940
aa7133@att.com409f2232020-10-29 13:06:45 +03001941void buildPrometheusList(ConnectedCU_t *peerInfo, Family<Counter> *prometheusFamily) {
aa7133@att.coma4c80012020-06-24 16:36:47 +03001942 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Messages"}});
1943 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001944
czichy2175dd32022-05-17 15:24:51 +03001945 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"E2NodeConfigUpdate", "Messages"}});
1946 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"E2NodeConfigUpdate", "Bytes"}});
1947
aa7133@att.coma4c80012020-06-24 16:36:47 +03001948 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Messages"}});
1949 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001950
aa7133@att.coma4c80012020-06-24 16:36:47 +03001951 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICindication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Messages"}});
1952 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICindication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001953
aa7133@att.coma4c80012020-06-24 16:36:47 +03001954 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Messages"}});
1955 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001956
aa7133@att.coma4c80012020-06-24 16:36:47 +03001957 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Messages"}});
1958 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001959 // ---------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03001960 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Messages"}});
1961 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001962
aa7133@att.coma4c80012020-06-24 16:36:47 +03001963 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Messages"}});
1964 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001965
aa7133@att.coma4c80012020-06-24 16:36:47 +03001966 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Messages"}});
1967 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001968
aa7133@att.coma4c80012020-06-24 16:36:47 +03001969 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Messages"}});
1970 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001971 //-------------------------------------------------------------
1972
aa7133@att.coma4c80012020-06-24 16:36:47 +03001973 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Messages"}});
1974 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001975
aa7133@att.coma4c80012020-06-24 16:36:47 +03001976 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Messages"}});
1977 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001978
aa7133@att.coma4c80012020-06-24 16:36:47 +03001979 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Messages"}});
1980 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001981
1982 //====================================================================================
aa7133@att.coma4c80012020-06-24 16:36:47 +03001983 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Messages"}});
1984 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001985
aa7133@att.coma4c80012020-06-24 16:36:47 +03001986 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Messages"}});
1987 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001988
aa7133@att.coma4c80012020-06-24 16:36:47 +03001989 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Messages"}});
1990 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001991
aa7133@att.coma4c80012020-06-24 16:36:47 +03001992 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceQuery)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Messages"}});
1993 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceQuery)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001994
aa7133@att.coma4c80012020-06-24 16:36:47 +03001995 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Messages"}});
1996 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001997
aa7133@att.coma4c80012020-06-24 16:36:47 +03001998 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Messages"}});
1999 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03002000 //---------------------------------------------------------------------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03002001 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Messages"}});
2002 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03002003
czichy2175dd32022-05-17 15:24:51 +03002004 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateSuccess", "Messages"}});
2005 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateSuccess", "Bytes"}});
2006
aa7133@att.coma4c80012020-06-24 16:36:47 +03002007 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Messages"}});
2008 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03002009
aa7133@att.coma4c80012020-06-24 16:36:47 +03002010 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Messages"}});
2011 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03002012 //----------------------------------------------------------------------------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03002013 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Messages"}});
2014 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03002015
czichy2175dd32022-05-17 15:24:51 +03002016 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateFailure", "Messages"}});
2017 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateFailure", "Bytes"}});
2018
aa7133@att.coma4c80012020-06-24 16:36:47 +03002019 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Messages"}});
2020 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Bytes"}});
gunjarastogi85f507f2023-01-18 16:27:55 +05302021
2022
2023 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDeleteRequired)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteRequired", "Messages"}});
2024 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDeleteRequired)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteRequired", "Bytes"}});
2025
ss412g4aeeda22020-06-16 14:12:41 +03002026}
Mohamed Abukar64f37242021-08-15 12:39:56 +00002027
ss412g4aeeda22020-06-16 14:12:41 +03002028/**
2029 *
2030 * @param pdu
2031 * @param sctpMap
2032 * @param message
2033 * @param RANfunctionsAdded_v
2034 * @return
2035 */
2036int collectSetupRequestData(E2AP_PDU_t *pdu,
2037 Sctp_Map_t *sctpMap,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002038 ReportingMessages_t &message /*, vector <string> &RANfunctionsAdded_v*/) {
ss412g4aeeda22020-06-16 14:12:41 +03002039 memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE);
2040 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) {
2041 auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i];
2042 if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) {
2043 // get the ran name for meid
2044 if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) {
2045 if (buildRanName(message.peerInfo->enodbName, ie) < 0) {
2046 mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n");
aa7133@att.com409f2232020-10-29 13:06:45 +03002047 // no message will be sent
ss412g4aeeda22020-06-16 14:12:41 +03002048 return -1;
2049 }
2050
2051 memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName));
2052 sctpMap->setkey(message.message.enodbName, message.peerInfo);
2053 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002054 } /*else if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
ss412g4aeeda22020-06-16 14:12:41 +03002055 if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) {
2056 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2057 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
2058 ie->value.choice.RANfunctions_List.list.count);
2059 }
2060 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) {
2061 return -1;
2062 }
2063 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002064 } */
ss412g4aeeda22020-06-16 14:12:41 +03002065 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002066// if (mdclog_level_get() >= MDCLOG_DEBUG) {
2067// mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries",
2068// RANfunctionsAdded_v.size());
2069// }
ss412g4aeeda22020-06-16 14:12:41 +03002070 return 0;
2071}
2072
2073int XML_From_PER(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
2074 E2AP_PDU_t *pdu = nullptr;
2075
2076 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2077 mdclog_write(MDCLOG_DEBUG, "got PER message of size %d is:%s",
2078 rmrMessageBuffer.sendMessage->len, rmrMessageBuffer.sendMessage->payload);
2079 }
2080 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu,
2081 rmrMessageBuffer.sendMessage->payload, rmrMessageBuffer.sendMessage->len);
2082 if (rval.code != RC_OK) {
2083 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
2084 rval.code,
2085 message.message.enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04002086 if (pdu != nullptr) {
2087 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2088 pdu = nullptr;
2089 }
ss412g4aeeda22020-06-16 14:12:41 +03002090 return -1;
2091 }
2092
2093 int buff_size = RECEIVE_XAPP_BUFFER_SIZE;
2094 auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu,
2095 rmrMessageBuffer.sendMessage->payload, buff_size);
2096 if (er.encoded == -1) {
2097 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
dhirajverma9f59b572021-07-23 02:36:13 -04002098 if (pdu != nullptr) {
2099 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2100 pdu = nullptr;
2101 }
ss412g4aeeda22020-06-16 14:12:41 +03002102 return -1;
2103 } else if (er.encoded > (ssize_t)buff_size) {
2104 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
2105 (int)rmrMessageBuffer.sendMessage->len,
2106 asn_DEF_E2AP_PDU.name,
2107 __func__,
2108 __LINE__);
dhirajverma9f59b572021-07-23 02:36:13 -04002109 if (pdu != nullptr) {
2110 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2111 pdu = nullptr;
2112 }
ss412g4aeeda22020-06-16 14:12:41 +03002113 return -1;
2114 }
2115 rmrMessageBuffer.sendMessage->len = er.encoded;
dhirajverma9f59b572021-07-23 02:36:13 -04002116 if (pdu != nullptr) {
2117 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2118 pdu = nullptr;
2119 }
ss412g4aeeda22020-06-16 14:12:41 +03002120 return 0;
2121
2122}
2123
ss412g1a79bdf2019-10-24 12:03:05 +03002124/**
2125 *
2126 * @param pdu
2127 * @param message
2128 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002129 */
2130void asnInitiatingRequest(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002131 Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002132 ReportingMessages_t &message,
czichy2175dd32022-05-17 15:24:51 +03002133 RmrMessagesBuffer_t &rmrMessageBuffer, int streamId) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002134 auto logLevel = mdclog_level_get();
ss412g1a79bdf2019-10-24 12:03:05 +03002135 auto procedureCode = ((InitiatingMessage_t *) pdu->choice.initiatingMessage)->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002136 if (logLevel >= MDCLOG_DEBUG) {
2137 mdclog_write(MDCLOG_DEBUG, "Initiating message %ld\n", procedureCode);
ss412g1a79bdf2019-10-24 12:03:05 +03002138 }
2139 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002140 case ProcedureCode_id_E2setup: {
2141 if (logLevel >= MDCLOG_DEBUG) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002142 mdclog_write(MDCLOG_DEBUG, "Got E2setup");
aa7133@att.com84bd3342020-03-16 18:04:57 +02002143 }
2144
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002145// vector <string> RANfunctionsAdded_v;
2146// vector <string> RANfunctionsModified_v;
2147// RANfunctionsAdded_v.clear();
2148// RANfunctionsModified_v.clear();
2149 if (collectSetupRequestData(pdu, sctpMap, message) != 0) {
aa7133@att.com7b437f72020-03-30 13:25:54 +03002150 break;
2151 }
czichy2175dd32022-05-17 15:24:51 +03002152 struct sctp_status status;
2153 int stat_size = sizeof(status);
2154 getsockopt( message.peerInfo->fileDescriptor, SOL_SCTP, SCTP_STATUS,(void *)&status, (socklen_t *)&stat_size );
2155 if (logLevel >= MDCLOG_DEBUG) {
2156 mdclog_write(MDCLOG_DEBUG, "Start from SCTP %d fd", message.peerInfo->fileDescriptor);
2157 mdclog_write(MDCLOG_DEBUG, "SCTP status assoc id %d instrms %d outstrms %d", status.sstat_assoc_id,
2158 status.sstat_instrms, status.sstat_outstrms);
2159 }
2160 if(status.sstat_outstrms == 1 || status.sstat_instrms == 1)
2161 {
2162 message.peerInfo->isSingleStream = true;
2163 message.peerInfo->singleStreamId = streamId;
2164 if (status.sstat_outstrms == 1 && status.sstat_instrms == 1){
2165 if (logLevel >= MDCLOG_DEBUG) {
2166 mdclog_write(MDCLOG_DEBUG, "Single SCTP stream is used for sending from now on, assoc id %d streamId %d #instrms %d #outstrms %d, %s",status.sstat_assoc_id, streamId, status.sstat_instrms, status.sstat_outstrms, __FUNCTION__);
2167 }
2168 }
2169 else {
2170 mdclog_write(MDCLOG_ERR, "Single SCTP stream used for sending messages even if there is a mismatch in number of in & out streams, assoc id %d instrms %d outstrms %d", status.sstat_assoc_id,
2171 status.sstat_instrms, status.sstat_outstrms);
2172 }
2173 }
aa7133@att.com7b437f72020-03-30 13:25:54 +03002174
aa7133@att.com409f2232020-10-29 13:06:45 +03002175 buildPrometheusList(message.peerInfo, message.peerInfo->sctpParams->prometheusFamily);
ss412g4aeeda22020-06-16 14:12:41 +03002176
2177 string messageName("E2setupRequest");
2178 string ieName("E2setupRequestIEs");
2179 message.message.messageType = RIC_E2_SETUP_REQ;
aa7133@att.coma4c80012020-06-24 16:36:47 +03002180 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2181 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002182
2183 // Update E2T instance level metrics
2184 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2185 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment((double)message.message.asnLength);
2186
aa7133@att.com409f2232020-10-29 13:06:45 +03002187 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
ss412g1a79bdf2019-10-24 12:03:05 +03002188 break;
2189 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002190 case ProcedureCode_id_RICserviceUpdate: {
2191 if (logLevel >= MDCLOG_DEBUG) {
2192 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
2193 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002194// vector <string> RANfunctionsAdded_v;
2195// vector <string> RANfunctionsModified_v;
2196// RANfunctionsAdded_v.clear();
2197// RANfunctionsModified_v.clear();
2198// if (collectServiceUpdate_RequestData(pdu, sctpMap, message,
2199// RANfunctionsAdded_v, RANfunctionsModified_v) != 0) {
2200// break;
2201// }
ss412g4aeeda22020-06-16 14:12:41 +03002202
2203 string messageName("RICserviceUpdate");
2204 string ieName("RICserviceUpdateIEs");
2205 message.message.messageType = RIC_SERVICE_UPDATE;
Alexandre Hufffff97942023-03-31 21:22:20 -03002206#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002207 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2208 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002209
2210 // Update E2T instance level metrics
2211 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2212 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002213#endif
aa7133@att.com409f2232020-10-29 13:06:45 +03002214 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002215 break;
2216 }
czichy2175dd32022-05-17 15:24:51 +03002217
2218case ProcedureCode_id_E2nodeConfigurationUpdate: {
2219 if (logLevel >= MDCLOG_DEBUG) {
2220 mdclog_write(MDCLOG_DEBUG, "Got E2nodeConfigurationUpdate %s", message.message.enodbName);
2221 }
2222
2223 string messageName("RICE2nodeConfigurationUpdate");
2224 string ieName("RICE2nodeConfigurationUpdateIEs");
2225 message.message.messageType = RIC_E2NODE_CONFIG_UPDATE;
2226#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2227 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2228 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment((double)message.message.asnLength);
2229
2230 // Update E2T instance level metrics
2231 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2232 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment((double)message.message.asnLength);
2233#endif
2234 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
2235 break;
2236 }
2237
aa7133@att.com84bd3342020-03-16 18:04:57 +02002238 case ProcedureCode_id_ErrorIndication: {
2239 if (logLevel >= MDCLOG_DEBUG) {
2240 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
2241 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002242#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002243 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2244 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002245
2246 // Update E2T instance level metrics
2247 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2248 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002249#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002250 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002251 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
ss412g1a79bdf2019-10-24 12:03:05 +03002252 }
2253 break;
2254 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002255 case ProcedureCode_id_Reset: {
2256 if (logLevel >= MDCLOG_DEBUG) {
2257 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002258 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002259#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002260 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2261 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002262
2263 // Update E2T instance level metrics
2264 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2265 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002266#endif
ss412g4aeeda22020-06-16 14:12:41 +03002267 if (XML_From_PER(message, rmrMessageBuffer) < 0) {
2268 break;
ss412g1a79bdf2019-10-24 12:03:05 +03002269 }
ss412g4aeeda22020-06-16 14:12:41 +03002270
2271 if (sendRequestToXapp(message, RIC_E2_RESET_REQ, rmrMessageBuffer) != 0) {
2272 mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_REQ message failed to send to xAPP");
aa7133@att.com84bd3342020-03-16 18:04:57 +02002273 }
2274 break;
2275 }
2276 case ProcedureCode_id_RICindication: {
2277 if (logLevel >= MDCLOG_DEBUG) {
2278 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
2279 }
2280 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
ss412g1a79bdf2019-10-24 12:03:05 +03002281 auto messageSent = false;
2282 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
aa7133@att.com84bd3342020-03-16 18:04:57 +02002283 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002284 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2285 }
2286 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002287 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002288 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2289 }
2290 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
2291 static unsigned char tx[32];
2292 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
2293 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2294 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
ss412g3bac2da2020-01-05 11:52:19 +02002295 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
aa7133@att.com84bd3342020-03-16 18:04:57 +02002296 (unsigned char *)message.message.enodbName,
2297 strlen(message.message.enodbName));
ss412g1a79bdf2019-10-24 12:03:05 +03002298 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.comc5a15202020-04-05 19:57:01 +03002299 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
2300
2301 //ie->value.choice.RICrequestID.ricInstanceID;
ss412g3bac2da2020-01-05 11:52:19 +02002302 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03002303 mdclog_write(MDCLOG_DEBUG, "sub id = %d, mtype = %d, ric instance id %ld, requestor id = %ld",
aa7133@att.com84bd3342020-03-16 18:04:57 +02002304 rmrMessageBuffer.sendMessage->sub_id,
aa7133@att.comc5a15202020-04-05 19:57:01 +03002305 rmrMessageBuffer.sendMessage->mtype,
2306 ie->value.choice.RICrequestID.ricInstanceID,
2307 ie->value.choice.RICrequestID.ricRequestorID);
ss412g3bac2da2020-01-05 11:52:19 +02002308 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002309#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002310 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication]->Increment();
2311 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002312
2313 // Update E2T instance level metrics
2314 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication]->Increment();
2315 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002316#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002317 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002318 messageSent = true;
2319 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002320 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002321 }
2322 }
2323 if (messageSent) {
2324 break;
2325 }
2326 }
2327 break;
2328 }
gunjarastogi85f507f2023-01-18 16:27:55 +05302329 case ProcedureCode_id_RICsubscriptionDeleteRequired: {
2330 if (logLevel >= MDCLOG_DEBUG) {
2331 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDeleteRequired %s", message.message.enodbName);
2332 }
2333 #if !(defined(UNIT_TEST) || defined(MODULE_TEST))
Alexandre Huff019cb422023-04-11 10:56:48 -03002334 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment();
2335 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment((double)message.message.asnLength);
gunjarastogi85f507f2023-01-18 16:27:55 +05302336
Alexandre Huff019cb422023-04-11 10:56:48 -03002337 // Update E2T instance level metrics
2338 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment();
2339 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment((double)message.message.asnLength);
gunjarastogi85f507f2023-01-18 16:27:55 +05302340 #endif
2341 if (sendRequestToXapp(message, RIC_SUB_DEL_REQUIRED, rmrMessageBuffer) != 0) {
2342 mdclog_write(MDCLOG_ERR, "Subscription Delete Required message failed to send to xAPP");
2343 }
2344 break;
2345 }
2346
ss412g1a79bdf2019-10-24 12:03:05 +03002347 default: {
2348 mdclog_write(MDCLOG_ERR, "Undefined or not supported message = %ld", procedureCode);
2349 message.message.messageType = 0; // no RMR message type yet
2350
2351 buildJsonMessage(message);
2352
2353 break;
2354 }
2355 }
ss412g1a79bdf2019-10-24 12:03:05 +03002356}
2357
2358/**
2359 *
2360 * @param pdu
2361 * @param message
ss412g1a79bdf2019-10-24 12:03:05 +03002362 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002363 */
aa7133@att.com409f2232020-10-29 13:06:45 +03002364void asnSuccessfulMsg(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002365 Sctp_Map_t *sctpMap,
2366 ReportingMessages_t &message,
2367 RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002368 auto procedureCode = pdu->choice.successfulOutcome->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002369 auto logLevel = mdclog_level_get();
2370 if (logLevel >= MDCLOG_INFO) {
ss412g1a79bdf2019-10-24 12:03:05 +03002371 mdclog_write(MDCLOG_INFO, "Successful Outcome %ld", procedureCode);
2372 }
2373 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002374 case ProcedureCode_id_Reset: {
2375 if (logLevel >= MDCLOG_DEBUG) {
2376 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002377 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002378#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002379 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2380 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002381
2382 // Update E2T instance level metrics
2383 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2384 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002385#endif
ss412g4aeeda22020-06-16 14:12:41 +03002386 if (XML_From_PER(message, rmrMessageBuffer) < 0) {
2387 break;
2388 }
2389 if (sendRequestToXapp(message, RIC_E2_RESET_RESP, rmrMessageBuffer) != 0) {
2390 mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_RESP message failed to send to xAPP");
ss412g1a79bdf2019-10-24 12:03:05 +03002391 }
2392 break;
2393 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002394 case ProcedureCode_id_RICcontrol: {
2395 if (logLevel >= MDCLOG_DEBUG) {
2396 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002397 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002398 for (auto i = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03002399 i < pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; i++) {
2400 auto messageSent = false;
2401 RICcontrolAcknowledge_IEs_t *ie = pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[i];
2402 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2403 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2404 }
2405 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
2406 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2407 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2408 }
2409 if (ie->value.present == RICcontrolAcknowledge_IEs__value_PR_RICrequestID) {
2410 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_ACK;
2411 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002412// rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
2413 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
2414
ss412g1a79bdf2019-10-24 12:03:05 +03002415 static unsigned char tx[32];
2416 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2417 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
ss412g3bac2da2020-01-05 11:52:19 +02002418 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
aa7133@att.com84bd3342020-03-16 18:04:57 +02002419 (unsigned char *)message.message.enodbName,
2420 strlen(message.message.enodbName));
Alexandre Hufffff97942023-03-31 21:22:20 -03002421#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002422 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2423 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002424
2425 // Update E2T instance level metrics
2426 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2427 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002428#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002429 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002430 messageSent = true;
2431 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002432 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002433 }
2434 }
2435 if (messageSent) {
2436 break;
2437 }
2438 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002439
2440 break;
2441 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002442 case ProcedureCode_id_RICsubscription: {
2443 if (logLevel >= MDCLOG_DEBUG) {
2444 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
2445 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002446#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002447 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2448 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002449
2450 // Update E2T instance level metrics
2451 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2452 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002453#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002454 if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002455 mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP");
2456 }
2457 break;
2458 }
2459 case ProcedureCode_id_RICsubscriptionDelete: {
2460 if (logLevel >= MDCLOG_DEBUG) {
2461 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
2462 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002463#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002464 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2465 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002466
2467 // Update E2T instance level metrics
2468 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2469 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002470#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002471 if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002472 mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP");
2473 }
ss412g1a79bdf2019-10-24 12:03:05 +03002474 break;
2475 }
2476 default: {
2477 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
2478 message.message.messageType = 0; // no RMR message type yet
2479 buildJsonMessage(message);
2480
2481 break;
2482 }
2483 }
ss412g1a79bdf2019-10-24 12:03:05 +03002484}
2485
2486/**
2487 *
2488 * @param pdu
2489 * @param message
ss412g1a79bdf2019-10-24 12:03:05 +03002490 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002491 */
2492void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002493 Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002494 ReportingMessages_t &message,
aa7133@att.combe92d712020-03-18 17:30:39 +02002495 RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002496 auto procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002497 auto logLevel = mdclog_level_get();
2498 if (logLevel >= MDCLOG_INFO) {
ss412g1a79bdf2019-10-24 12:03:05 +03002499 mdclog_write(MDCLOG_INFO, "Unsuccessful Outcome %ld", procedureCode);
2500 }
2501 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002502 case ProcedureCode_id_RICcontrol: {
2503 if (logLevel >= MDCLOG_DEBUG) {
2504 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002505 }
2506 for (int i = 0;
2507 i < pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.count; i++) {
2508 auto messageSent = false;
2509 RICcontrolFailure_IEs_t *ie = pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.array[i];
aa7133@att.com84bd3342020-03-16 18:04:57 +02002510 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002511 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2512 }
2513 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002514 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002515 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2516 }
2517 if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) {
2518 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_FAILURE;
2519 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002520// rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricRequestorID;
2521 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
ss412g1a79bdf2019-10-24 12:03:05 +03002522 static unsigned char tx[32];
2523 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2524 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
aa7133@att.com84bd3342020-03-16 18:04:57 +02002525 rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName,
2526 strlen(message.message.enodbName));
Alexandre Hufffff97942023-03-31 21:22:20 -03002527#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002528 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2529 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002530
2531 // Update E2T instance level metrics
2532 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2533 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
dhirajverma99990292021-07-05 10:03:59 -04002534#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002535 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002536 messageSent = true;
2537 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002538 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002539 }
2540 }
2541 if (messageSent) {
2542 break;
2543 }
2544 }
2545 break;
2546 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002547 case ProcedureCode_id_RICsubscription: {
2548 if (logLevel >= MDCLOG_DEBUG) {
2549 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
2550 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002551#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002552 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2553 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002554
2555 // Update E2T instance level metrics
2556 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2557 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002558#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002559 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002560 mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP");
2561 }
2562 break;
2563 }
2564 case ProcedureCode_id_RICsubscriptionDelete: {
2565 if (logLevel >= MDCLOG_DEBUG) {
2566 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
2567 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002568#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002569 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2570 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002571
2572 // Update E2T instance level metrics
2573 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2574 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002575#endif
ss412g4aeeda22020-06-16 14:12:41 +03002576 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002577 mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP");
2578 }
2579 break;
2580 }
ss412g1a79bdf2019-10-24 12:03:05 +03002581 default: {
2582 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
2583 message.message.messageType = 0; // no RMR message type yet
Alexandre Hufffff97942023-03-31 21:22:20 -03002584#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03002585 buildJsonMessage(message);
Alexandre Hufffff97942023-03-31 21:22:20 -03002586#endif
ss412g1a79bdf2019-10-24 12:03:05 +03002587 break;
2588 }
2589 }
ss412g1a79bdf2019-10-24 12:03:05 +03002590}
2591
2592/**
2593 *
2594 * @param message
2595 * @param requestId
2596 * @param rmrMmessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002597 * @return
2598 */
2599int sendRequestToXapp(ReportingMessages_t &message,
2600 int requestId,
aa7133@att.combe92d712020-03-18 17:30:39 +02002601 RmrMessagesBuffer_t &rmrMmessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002602 rmr_bytes2meid(rmrMmessageBuffer.sendMessage,
2603 (unsigned char *)message.message.enodbName,
2604 strlen(message.message.enodbName));
2605 message.message.messageType = rmrMmessageBuffer.sendMessage->mtype = requestId;
2606 rmrMmessageBuffer.sendMessage->state = 0;
2607 static unsigned char tx[32];
2608 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2609 rmr_bytes2xact(rmrMmessageBuffer.sendMessage, tx, strlen((const char *) tx));
2610
aa7133@att.combe92d712020-03-18 17:30:39 +02002611 auto rc = sendRmrMessage(rmrMmessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002612 return rc;
2613}
2614
ss412g4aeeda22020-06-16 14:12:41 +03002615/**
2616 *
2617 * @param pSctpParams
2618 */
aa7133@att.combe92d712020-03-18 17:30:39 +02002619void getRmrContext(sctp_params_t &pSctpParams) {
ss412g3bac2da2020-01-05 11:52:19 +02002620 pSctpParams.rmrCtx = nullptr;
aa7133@att.comab0e0f42020-04-06 17:13:58 +03002621 pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RECEIVE_XAPP_BUFFER_SIZE, RMRFL_NONE);
ss412g3bac2da2020-01-05 11:52:19 +02002622 if (pSctpParams.rmrCtx == nullptr) {
2623 mdclog_write(MDCLOG_ERR, "Failed to initialize RMR");
ss412g3bac2da2020-01-05 11:52:19 +02002624 return;
ss412g1a79bdf2019-10-24 12:03:05 +03002625 }
2626
ss412g3bac2da2020-01-05 11:52:19 +02002627 rmr_set_stimeout(pSctpParams.rmrCtx, 0); // disable retries for any send operation
ss412g1a79bdf2019-10-24 12:03:05 +03002628 // we need to find that routing table exist and we can run
2629 if (mdclog_level_get() >= MDCLOG_INFO) {
2630 mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready");
2631 }
2632 int rmrReady = 0;
2633 int count = 0;
2634 while (!rmrReady) {
ss412g3bac2da2020-01-05 11:52:19 +02002635 if ((rmrReady = rmr_ready(pSctpParams.rmrCtx)) == 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002636 sleep(1);
2637 }
2638 count++;
2639 if (count % 60 == 0) {
2640 mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count);
2641 }
2642 }
2643 if (mdclog_level_get() >= MDCLOG_INFO) {
2644 mdclog_write(MDCLOG_INFO, "RMR running");
2645 }
ss412g3bac2da2020-01-05 11:52:19 +02002646 rmr_init_trace(pSctpParams.rmrCtx, 200);
2647 // get the RMR fd for the epoll
2648 pSctpParams.rmrListenFd = rmr_get_rcvfd(pSctpParams.rmrCtx);
2649 struct epoll_event event{};
2650 // add RMR fd to epoll
2651 event.events = (EPOLLIN);
2652 event.data.fd = pSctpParams.rmrListenFd;
2653 // add listening RMR FD to epoll
2654 if (epoll_ctl(pSctpParams.epoll_fd, EPOLL_CTL_ADD, pSctpParams.rmrListenFd, &event)) {
2655 mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll");
2656 close(pSctpParams.rmrListenFd);
2657 rmr_close(pSctpParams.rmrCtx);
2658 pSctpParams.rmrCtx = nullptr;
2659 }
ss412g1a79bdf2019-10-24 12:03:05 +03002660}
2661
ss412g4aeeda22020-06-16 14:12:41 +03002662/**
2663 *
2664 * @param message
2665 * @param rmrMessageBuffer
2666 * @return
2667 */
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002668int PER_FromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
aa7133@att.com07e256f2020-04-20 15:59:51 +03002669 E2AP_PDU_t *pdu = nullptr;
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002670
2671 if (mdclog_level_get() >= MDCLOG_DEBUG) {
ss412g4aeeda22020-06-16 14:12:41 +03002672 mdclog_write(MDCLOG_DEBUG, "got xml Format data from xApp of size %d is:%s",
aa7133@att.com07e256f2020-04-20 15:59:51 +03002673 rmrMessageBuffer.rcvMessage->len, rmrMessageBuffer.rcvMessage->payload);
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002674 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002675 auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &pdu,
2676 rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len);
aa7133@att.com409f2232020-10-29 13:06:45 +03002677 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2678 mdclog_write(MDCLOG_DEBUG, "%s After decoding the XML to PDU", __func__ );
2679 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002680 if (rval.code != RC_OK) {
dhirajvermac40ea1f2021-07-08 12:52:30 -04002681#ifdef UNIT_TEST
2682 return 0;
Alexandre Hufffff97942023-03-31 21:22:20 -03002683#endif
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002684 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
aa7133@att.com1fecb052020-03-29 09:44:09 +03002685 rval.code,
2686 message.message.enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04002687 if (pdu != nullptr) {
2688 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2689 pdu = nullptr;
2690 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002691 return -1;
2692 }
2693
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002694 int buff_size = RECEIVE_XAPP_BUFFER_SIZE;
2695 auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu,
2696 rmrMessageBuffer.rcvMessage->payload, buff_size);
aa7133@att.com409f2232020-10-29 13:06:45 +03002697 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2698 mdclog_write(MDCLOG_DEBUG, "%s After encoding PDU to PER", __func__ );
2699 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002700 if (er.encoded == -1) {
2701 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
dhirajverma9f59b572021-07-23 02:36:13 -04002702 if (pdu != nullptr) {
2703 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2704 pdu = nullptr;
2705 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002706 return -1;
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002707 } else if (er.encoded > (ssize_t)buff_size) {
2708 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
aa7133@att.com1fecb052020-03-29 09:44:09 +03002709 (int)rmrMessageBuffer.rcvMessage->len,
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002710 asn_DEF_E2AP_PDU.name,
2711 __func__,
2712 __LINE__);
dhirajverma9f59b572021-07-23 02:36:13 -04002713 if (pdu != nullptr) {
2714 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2715 pdu = nullptr;
2716 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002717 return -1;
2718 }
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002719 rmrMessageBuffer.rcvMessage->len = er.encoded;
dhirajverma9f59b572021-07-23 02:36:13 -04002720 if (pdu != nullptr) {
2721 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2722 pdu = nullptr;
2723 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002724 return 0;
2725}
2726
ss412g1a79bdf2019-10-24 12:03:05 +03002727/**
2728 *
ss412g1a79bdf2019-10-24 12:03:05 +03002729 * @param sctpMap
2730 * @param rmrMessageBuffer
2731 * @param ts
ss412g1a79bdf2019-10-24 12:03:05 +03002732 * @return
2733 */
aa7133@att.com6680c3b2020-03-22 12:06:58 +02002734int receiveXappMessages(Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002735 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02002736 struct timespec &ts) {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002737 int loglevel = mdclog_level_get();
ss412g1a79bdf2019-10-24 12:03:05 +03002738 if (rmrMessageBuffer.rcvMessage == nullptr) {
2739 //we have error
2740 mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03002741 return -1;
2742 }
2743
aa7133@att.comf13529a2020-08-27 11:21:16 +03002744// if (loglevel >= MDCLOG_DEBUG) {
2745// mdclog_write(MDCLOG_DEBUG, "Call to rmr_rcv_msg");
2746// }
ss412g1a79bdf2019-10-24 12:03:05 +03002747 rmrMessageBuffer.rcvMessage = rmr_rcv_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
2748 if (rmrMessageBuffer.rcvMessage == nullptr) {
aa7133@att.com409f2232020-10-29 13:06:45 +03002749 mdclog_write(MDCLOG_ERR, "RMR Receiving message with null pointer, Reallocated rmr message buffer");
ss412g1a79bdf2019-10-24 12:03:05 +03002750 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g1a79bdf2019-10-24 12:03:05 +03002751 return -2;
2752 }
2753 ReportingMessages_t message;
2754 message.message.direction = 'D';
2755 message.message.time.tv_nsec = ts.tv_nsec;
2756 message.message.time.tv_sec = ts.tv_sec;
2757
2758 // get message payload
2759 //auto msgData = msg->payload;
dhirajverma60f8bef2021-06-29 07:22:58 -04002760#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04002761 rmrMessageBuffer.rcvMessage->state = 0;
dhirajverma60f8bef2021-06-29 07:22:58 -04002762#endif
ss412g1a79bdf2019-10-24 12:03:05 +03002763 if (rmrMessageBuffer.rcvMessage->state != 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +03002764 mdclog_write(MDCLOG_ERR, "RMR Receiving message with stat = %d", rmrMessageBuffer.rcvMessage->state);
ss412g1a79bdf2019-10-24 12:03:05 +03002765 return -1;
2766 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002767 rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)message.message.enodbName);
ss412g4aeeda22020-06-16 14:12:41 +03002768 message.peerInfo = (ConnectedCU_t *) sctpMap->find(message.message.enodbName);
2769 if (message.peerInfo == nullptr) {
2770 auto type = rmrMessageBuffer.rcvMessage->mtype;
2771 switch (type) {
2772 case RIC_SCTP_CLEAR_ALL:
2773 case E2_TERM_KEEP_ALIVE_REQ:
2774 case RIC_HEALTH_CHECK_REQ:
2775 break;
2776 default:
dhirajverma99990292021-07-05 10:03:59 -04002777#ifdef UNIT_TEST
2778 break;
Alexandre Hufffff97942023-03-31 21:22:20 -03002779#endif
ss412g4aeeda22020-06-16 14:12:41 +03002780 mdclog_write(MDCLOG_ERR, "Failed to send message no CU entry %s", message.message.enodbName);
2781 return -1;
2782 }
2783 }
2784
aa7133@att.comde40d1c2020-08-26 16:19:20 +03002785 if (rmrMessageBuffer.rcvMessage->mtype != RIC_HEALTH_CHECK_REQ) {
2786 num_of_XAPP_messages.fetch_add(1, std::memory_order_release);
2787
2788 }
ss412g1a79bdf2019-10-24 12:03:05 +03002789 switch (rmrMessageBuffer.rcvMessage->mtype) {
aa7133@att.combe92d712020-03-18 17:30:39 +02002790 case RIC_E2_SETUP_RESP : {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002791 if (loglevel >= MDCLOG_DEBUG) {
2792 mdclog_write(MDCLOG_DEBUG, "RIC_E2_SETUP_RESP");
2793 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002794 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com1fecb052020-03-29 09:44:09 +03002795 break;
2796 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002797#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002798 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2799 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002800
2801 // Update E2T instance level metrics
2802 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2803 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002804#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002805 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2806 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_RESP");
2807 return -6;
ss412g1a79bdf2019-10-24 12:03:05 +03002808 }
2809 break;
2810 }
aa7133@att.combe92d712020-03-18 17:30:39 +02002811 case RIC_E2_SETUP_FAILURE : {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002812 if (loglevel >= MDCLOG_DEBUG) {
2813 mdclog_write(MDCLOG_DEBUG, "RIC_E2_SETUP_FAILURE");
2814 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002815 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com1fecb052020-03-29 09:44:09 +03002816 break;
2817 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002818#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002819 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2820 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002821
2822 // Update E2T instance level metrics
2823 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2824 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002825#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002826 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2827 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_FAILURE");
2828 return -6;
ss412g1a79bdf2019-10-24 12:03:05 +03002829 }
2830 break;
2831 }
czichy2175dd32022-05-17 15:24:51 +03002832
2833 case RIC_E2NODE_CONFIG_UPDATE_ACK: {
2834 if (loglevel >= MDCLOG_DEBUG) {
2835 mdclog_write(MDCLOG_DEBUG, "RIC_E2NODE_CONFIG_UPDATE_ACK");
2836 }
2837 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2838 break;
2839 }
2840#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2841 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2842 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2843
2844 // Update E2T instance level metrics
2845 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2846 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2847#endif
2848 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2849 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2NODE_CONFIG_UPDATE_ACK");
2850 return -6;
2851 }
2852 break;
2853 }
2854
2855 case RIC_E2NODE_CONFIG_UPDATE_FAILURE: {
2856 if (loglevel >= MDCLOG_DEBUG) {
2857 mdclog_write(MDCLOG_DEBUG, "RIC_E2NODE_CONFIG_UPDATE_FAILURE");
2858 }
2859 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2860 break;
2861 }
2862#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2863 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2864 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2865
2866 // Update E2T instance level metrics
2867 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2868 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2869#endif
2870 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2871 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2NODE_CONFIG_UPDATE_FAILURE");
2872 return -6;
2873 }
2874 break;
2875 }
2876
aa7133@att.combe92d712020-03-18 17:30:39 +02002877 case RIC_ERROR_INDICATION: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002878 if (loglevel >= MDCLOG_DEBUG) {
2879 mdclog_write(MDCLOG_DEBUG, "RIC_ERROR_INDICATION");
2880 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002881#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002882 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2883 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002884
2885 // Update E2T instance level metrics
2886 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2887 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002888#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002889 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2890 mdclog_write(MDCLOG_ERR, "Failed to send RIC_ERROR_INDICATION");
ss412g1a79bdf2019-10-24 12:03:05 +03002891 return -6;
2892 }
2893 break;
2894 }
2895 case RIC_SUB_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002896 if (loglevel >= MDCLOG_DEBUG) {
2897 mdclog_write(MDCLOG_DEBUG, "RIC_SUB_REQ");
2898 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002899#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002900 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2901 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002902
2903 // Update E2T instance level metrics
2904 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2905 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002906#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002907 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002908 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002909 return -6;
2910 }
2911 break;
2912 }
2913 case RIC_SUB_DEL_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002914 if (loglevel >= MDCLOG_DEBUG) {
2915 mdclog_write(MDCLOG_DEBUG, "RIC_SUB_DEL_REQ");
2916 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002917#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002918 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2919 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002920
2921 // Update E2T instance level metrics
2922 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2923 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002924#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002925 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002926 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_DEL_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002927 return -6;
2928 }
2929 break;
2930 }
2931 case RIC_CONTROL_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002932 if (loglevel >= MDCLOG_DEBUG) {
2933 mdclog_write(MDCLOG_DEBUG, "RIC_CONTROL_REQ");
2934 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002935#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002936 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2937 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002938
2939 // Update E2T instance level metrics
2940 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2941 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002942#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002943 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002944 mdclog_write(MDCLOG_ERR, "Failed to send RIC_CONTROL_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002945 return -6;
2946 }
2947 break;
2948 }
2949 case RIC_SERVICE_QUERY: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002950 if (loglevel >= MDCLOG_DEBUG) {
2951 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_QUERY");
2952 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002953 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2954 break;
2955 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002956#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002957 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment();
2958 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002959
2960 // Update E2T instance level metrics
2961 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment();
2962 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002963#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002964 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002965 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY");
ss412g1a79bdf2019-10-24 12:03:05 +03002966 return -6;
2967 }
2968 break;
2969 }
2970 case RIC_SERVICE_UPDATE_ACK: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002971 if (loglevel >= MDCLOG_DEBUG) {
2972 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_UPDATE_ACK");
2973 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002974 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com54885fe2020-10-29 17:24:49 +03002975 mdclog_write(MDCLOG_ERR, "error in PER_FromXML");
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002976 break;
2977 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002978#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002979 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
aa7133@att.com52771912020-10-29 17:45:01 +03002980 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002981
2982 // Update E2T instance level metrics
2983 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2984 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002985#endif
aa7133@att.com54885fe2020-10-29 17:24:49 +03002986 if (loglevel >= MDCLOG_DEBUG) {
2987 mdclog_write(MDCLOG_DEBUG, "Before sending to CU");
2988 }
aa7133@att.combe92d712020-03-18 17:30:39 +02002989 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002990 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK");
ss412g1a79bdf2019-10-24 12:03:05 +03002991 return -6;
2992 }
2993 break;
2994 }
2995 case RIC_SERVICE_UPDATE_FAILURE: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002996 if (loglevel >= MDCLOG_DEBUG) {
2997 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_UPDATE_FAILURE");
2998 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002999 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
3000 break;
3001 }
Alexandre Hufffff97942023-03-31 21:22:20 -03003002#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03003003 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
aa7133@att.com7c07fee2020-10-29 17:54:38 +03003004 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00003005
3006 // Update E2T instance level metrics
3007 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
3008 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03003009#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02003010 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03003011 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE");
ss412g1a79bdf2019-10-24 12:03:05 +03003012 return -6;
3013 }
3014 break;
3015 }
ss412g4aeeda22020-06-16 14:12:41 +03003016 case RIC_E2_RESET_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03003017 if (loglevel >= MDCLOG_DEBUG) {
3018 mdclog_write(MDCLOG_DEBUG, "RIC_E2_RESET_REQ");
3019 }
ss412g4aeeda22020-06-16 14:12:41 +03003020 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
3021 break;
3022 }
Alexandre Hufffff97942023-03-31 21:22:20 -03003023#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03003024 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
3025 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00003026
3027 // Update E2T instance level metrics
3028 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
3029 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03003030#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02003031 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03003032 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET");
ss412g1a79bdf2019-10-24 12:03:05 +03003033 return -6;
3034 }
3035 break;
3036 }
ss412g4aeeda22020-06-16 14:12:41 +03003037 case RIC_E2_RESET_RESP: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03003038 if (loglevel >= MDCLOG_DEBUG) {
3039 mdclog_write(MDCLOG_DEBUG, "RIC_E2_RESET_RESP");
3040 }
ss412g4aeeda22020-06-16 14:12:41 +03003041 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
3042 break;
3043 }
Alexandre Hufffff97942023-03-31 21:22:20 -03003044#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03003045 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
3046 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00003047
3048 // Update E2T instance level metrics
3049 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
3050 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03003051#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02003052 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03003053 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET_RESP");
ss412g1a79bdf2019-10-24 12:03:05 +03003054 return -6;
3055 }
3056 break;
3057 }
3058 case RIC_SCTP_CLEAR_ALL: {
3059 mdclog_write(MDCLOG_INFO, "RIC_SCTP_CLEAR_ALL");
3060 // loop on all keys and close socket and then erase all map.
3061 vector<char *> v;
3062 sctpMap->getKeys(v);
3063 for (auto const &iter : v) { //}; iter != sctpMap.end(); iter++) {
3064 if (!boost::starts_with((string) (iter), "host:") && !boost::starts_with((string) (iter), "msg:")) {
3065 auto *peerInfo = (ConnectedCU_t *) sctpMap->find(iter);
3066 if (peerInfo == nullptr) {
3067 continue;
3068 }
3069 close(peerInfo->fileDescriptor);
3070 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
3071 message.message.direction = 'D';
3072 message.message.time.tv_nsec = ts.tv_nsec;
3073 message.message.time.tv_sec = ts.tv_sec;
3074
3075 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
3076 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
aa7133@att.com96c9b882020-03-25 14:50:40 +02003077 256,
3078 "%s|RIC_SCTP_CLEAR_ALL",
3079 peerInfo->enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03003080 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
3081 mdclog_write(MDCLOG_INFO, "%s", message.message.asndata);
aa7133@att.combe92d712020-03-18 17:30:39 +02003082 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03003083 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
3084 }
3085 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +05303086 peerInfo = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03003087 }
3088 }
3089
3090 sleep(1);
3091 sctpMap->clear();
3092 break;
3093 }
ss412g3bac2da2020-01-05 11:52:19 +02003094 case E2_TERM_KEEP_ALIVE_REQ: {
3095 // send message back
ss412g3bac2da2020-01-05 11:52:19 +02003096 rmr_bytes2payload(rmrMessageBuffer.sendMessage,
aa7133@att.com96c9b882020-03-25 14:50:40 +02003097 (unsigned char *)rmrMessageBuffer.ka_message,
3098 rmrMessageBuffer.ka_message_len);
ss412g3bac2da2020-01-05 11:52:19 +02003099 rmrMessageBuffer.sendMessage->mtype = E2_TERM_KEEP_ALIVE_RESP;
3100 rmrMessageBuffer.sendMessage->state = 0;
3101 static unsigned char tx[32];
3102 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
3103 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, txLen);
Alexandre Hufffff97942023-03-31 21:22:20 -03003104#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02003105 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003106#endif
ss412g3bac2da2020-01-05 11:52:19 +02003107 if (rmrMessageBuffer.sendMessage == nullptr) {
3108 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
aa7133@att.com77fff432020-01-27 12:01:20 +02003109 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP RMR message returned NULL");
ss412g3bac2da2020-01-05 11:52:19 +02003110 } else if (rmrMessageBuffer.sendMessage->state != 0) {
aa7133@att.com77fff432020-01-27 12:01:20 +02003111 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP, on RMR state = %d ( %s)",
aa7133@att.com96c9b882020-03-25 14:50:40 +02003112 rmrMessageBuffer.sendMessage->state, translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str());
aa7133@att.comf13529a2020-08-27 11:21:16 +03003113 } else if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.combc110772020-03-25 09:45:14 +02003114 mdclog_write(MDCLOG_DEBUG, "Got Keep Alive Request send : %s", rmrMessageBuffer.ka_message);
ss412g3bac2da2020-01-05 11:52:19 +02003115 }
aa7133@att.com342843e2020-01-26 12:53:34 +02003116
ss412g3bac2da2020-01-05 11:52:19 +02003117 break;
3118 }
ss412g4aeeda22020-06-16 14:12:41 +03003119 case RIC_HEALTH_CHECK_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03003120 static int counter = 0;
ss412g4aeeda22020-06-16 14:12:41 +03003121 // send message back
aa7133@att.comc18fe532020-06-30 12:40:18 +03003122 rmr_bytes2payload(rmrMessageBuffer.rcvMessage,
ss412g4aeeda22020-06-16 14:12:41 +03003123 (unsigned char *)"OK",
3124 2);
aa7133@att.comc18fe532020-06-30 12:40:18 +03003125 rmrMessageBuffer.rcvMessage->mtype = RIC_HEALTH_CHECK_RESP;
3126 rmrMessageBuffer.rcvMessage->state = 0;
ss412g4aeeda22020-06-16 14:12:41 +03003127 static unsigned char tx[32];
3128 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
aa7133@att.comc18fe532020-06-30 12:40:18 +03003129 rmr_bytes2xact(rmrMessageBuffer.rcvMessage, tx, txLen);
3130 rmrMessageBuffer.rcvMessage = rmr_rts_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
3131 //rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
3132 if (rmrMessageBuffer.rcvMessage == nullptr) {
3133 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g4aeeda22020-06-16 14:12:41 +03003134 mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP RMR message returned NULL");
aa7133@att.comc18fe532020-06-30 12:40:18 +03003135 } else if (rmrMessageBuffer.rcvMessage->state != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03003136 mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP, on RMR state = %d ( %s)",
aa7133@att.comc18fe532020-06-30 12:40:18 +03003137 rmrMessageBuffer.rcvMessage->state, translateRmrErrorMessages(rmrMessageBuffer.rcvMessage->state).c_str());
dhirajvermab55bc172021-11-09 02:15:08 -05003138 } else if (loglevel >= MDCLOG_DEBUG && (++counter % 100 == 0)) {
aa7133@att.comf13529a2020-08-27 11:21:16 +03003139 mdclog_write(MDCLOG_DEBUG, "Got %d RIC_HEALTH_CHECK_REQ Request send : OK", counter);
ss412g4aeeda22020-06-16 14:12:41 +03003140 }
3141
3142 break;
3143 }
3144
ss412g1a79bdf2019-10-24 12:03:05 +03003145 default:
aa7133@att.com409f2232020-10-29 13:06:45 +03003146 mdclog_write(MDCLOG_WARN, "Message Type : %d is not supported", rmrMessageBuffer.rcvMessage->mtype);
ss412g1a79bdf2019-10-24 12:03:05 +03003147 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
3148 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
3149 message.message.time.tv_nsec = ts.tv_nsec;
3150 message.message.time.tv_sec = ts.tv_sec;
3151 message.message.messageType = rmrMessageBuffer.rcvMessage->mtype;
3152
3153 buildJsonMessage(message);
3154
3155
ss412g1a79bdf2019-10-24 12:03:05 +03003156 return -7;
3157 }
3158 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3159 mdclog_write(MDCLOG_DEBUG, "EXIT OK from %s", __FUNCTION__);
3160 }
ss412g1a79bdf2019-10-24 12:03:05 +03003161 return 0;
3162}
3163
3164/**
3165 * Send message to the CU that is not expecting for successful or unsuccessful results
3166 * @param messageBuffer
3167 * @param message
3168 * @param failedMsgId
3169 * @param sctpMap
ss412g1a79bdf2019-10-24 12:03:05 +03003170 * @return
3171 */
3172int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer,
3173 ReportingMessages_t &message,
3174 int failedMsgId,
aa7133@att.combe92d712020-03-18 17:30:39 +02003175 Sctp_Map_t *sctpMap) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003176 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3177 mdclog_write(MDCLOG_DEBUG, "send message: %d to %s address", message.message.messageType, message.message.enodbName);
3178 }
ss412g1a79bdf2019-10-24 12:03:05 +03003179
aa7133@att.combe92d712020-03-18 17:30:39 +02003180 getRequestMetaData(message, messageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03003181 if (mdclog_level_get() >= MDCLOG_INFO) {
3182 mdclog_write(MDCLOG_INFO, "send message to %s address", message.message.enodbName);
3183 }
3184
aa7133@att.combe92d712020-03-18 17:30:39 +02003185 auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId);
ss412g1a79bdf2019-10-24 12:03:05 +03003186 return rc;
3187}
3188
3189/**
3190 *
3191 * @param sctpMap
3192 * @param messageBuffer
3193 * @param message
3194 * @param failedMesgId
ss412g1a79bdf2019-10-24 12:03:05 +03003195 * @return
3196 */
3197int sendMessagetoCu(Sctp_Map_t *sctpMap,
3198 RmrMessagesBuffer_t &messageBuffer,
3199 ReportingMessages_t &message,
aa7133@att.combe92d712020-03-18 17:30:39 +02003200 int failedMesgId) {
ss412g1a79bdf2019-10-24 12:03:05 +03003201 // get the FD
3202 message.message.messageType = messageBuffer.rcvMessage->mtype;
ss412g4aeeda22020-06-16 14:12:41 +03003203 auto rc = sendSctpMsg(message.peerInfo, message, sctpMap);
ss412g1a79bdf2019-10-24 12:03:05 +03003204 return rc;
3205}
3206
ss412g1a79bdf2019-10-24 12:03:05 +03003207
3208/**
3209 *
3210 * @param epoll_fd
3211 * @param peerInfo
3212 * @param events
3213 * @param sctpMap
3214 * @param enodbName
3215 * @param msgType
ss412g1a79bdf2019-10-24 12:03:05 +03003216 * @return
3217 */
3218int addToEpoll(int epoll_fd,
3219 ConnectedCU_t *peerInfo,
3220 uint32_t events,
3221 Sctp_Map_t *sctpMap,
3222 char *enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02003223 int msgType) {
ss412g1a79bdf2019-10-24 12:03:05 +03003224 // Add to Epol
3225 struct epoll_event event{};
3226 event.data.ptr = peerInfo;
3227 event.events = events;
3228 if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peerInfo->fileDescriptor, &event) < 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -03003229#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03003230 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003231 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here), %s, %s %d",
ss412g1a79bdf2019-10-24 12:03:05 +03003232 strerror(errno), __func__, __LINE__);
3233 }
3234 close(peerInfo->fileDescriptor);
aa7133@att.com84bd3342020-03-16 18:04:57 +02003235 if (enodbName != nullptr) {
aa7133@att.combe92d712020-03-18 17:30:39 +02003236 cleanHashEntry(peerInfo, sctpMap);
aa7133@att.com84bd3342020-03-16 18:04:57 +02003237 char key[MAX_ENODB_NAME_SIZE * 2];
3238 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
3239 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3240 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
3241 }
3242 auto tmp = sctpMap->find(key);
3243 if (tmp) {
3244 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05303245 tmp = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +02003246 sctpMap->erase(key);
3247 }
3248 } else {
3249 peerInfo->enodbName[0] = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03003250 }
aa7133@att.com409f2232020-10-29 13:06:45 +03003251 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here)");
ss412g1a79bdf2019-10-24 12:03:05 +03003252 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -04003253#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003254 }
ss412g1a79bdf2019-10-24 12:03:05 +03003255 return 0;
3256}
3257
3258/**
3259 *
3260 * @param epoll_fd
3261 * @param peerInfo
3262 * @param events
3263 * @param sctpMap
3264 * @param enodbName
3265 * @param msgType
ss412g1a79bdf2019-10-24 12:03:05 +03003266 * @return
3267 */
3268int modifyToEpoll(int epoll_fd,
3269 ConnectedCU_t *peerInfo,
3270 uint32_t events,
3271 Sctp_Map_t *sctpMap,
3272 char *enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02003273 int msgType) {
ss412g1a79bdf2019-10-24 12:03:05 +03003274 // Add to Epol
3275 struct epoll_event event{};
3276 event.data.ptr = peerInfo;
3277 event.events = events;
3278 if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, peerInfo->fileDescriptor, &event) < 0) {
3279 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003280 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_MOD (may check not to quit here), %s, %s %d",
ss412g1a79bdf2019-10-24 12:03:05 +03003281 strerror(errno), __func__, __LINE__);
3282 }
3283 close(peerInfo->fileDescriptor);
aa7133@att.combe92d712020-03-18 17:30:39 +02003284 cleanHashEntry(peerInfo, sctpMap);
ss412g1a79bdf2019-10-24 12:03:05 +03003285 char key[MAX_ENODB_NAME_SIZE * 2];
3286 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
3287 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3288 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
3289 }
aa7133@att.com96c9b882020-03-25 14:50:40 +02003290 auto tmp = sctpMap->find(key);
ss412g1a79bdf2019-10-24 12:03:05 +03003291 if (tmp) {
3292 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05303293 tmp = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -03003294 sctpMap->erase(key);
sandeekuea662102022-11-08 18:51:20 +05303295 }
aa7133@att.com409f2232020-10-29 13:06:45 +03003296 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here)");
ss412g1a79bdf2019-10-24 12:03:05 +03003297 return -1;
3298 }
ss412g1a79bdf2019-10-24 12:03:05 +03003299 return 0;
3300}
3301
3302
aa7133@att.combe92d712020-03-18 17:30:39 +02003303int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message) {
ss412g1a79bdf2019-10-24 12:03:05 +03003304 buildJsonMessage(message);
dhirajverma60f8bef2021-06-29 07:22:58 -04003305#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03003306 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003307#else
dhirajverma99990292021-07-05 10:03:59 -04003308 rmrMessageBuffer.sendMessage->state = RMR_ERR_RETRY;
dhirajverma60f8bef2021-06-29 07:22:58 -04003309#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003310 if (rmrMessageBuffer.sendMessage == nullptr) {
3311 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
3312 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
ss412g1a79bdf2019-10-24 12:03:05 +03003313 return -1;
3314 }
3315
3316 if (rmrMessageBuffer.sendMessage->state != 0) {
3317 char meid[RMR_MAX_MEID]{};
3318 if (rmrMessageBuffer.sendMessage->state == RMR_ERR_RETRY) {
3319 usleep(5);
3320 rmrMessageBuffer.sendMessage->state = 0;
3321 mdclog_write(MDCLOG_INFO, "RETRY sending Message type %d to Xapp from %s",
3322 rmrMessageBuffer.sendMessage->mtype,
3323 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
dhirajverma60f8bef2021-06-29 07:22:58 -04003324#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03003325 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003326#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003327 if (rmrMessageBuffer.sendMessage == nullptr) {
3328 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
3329 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g1a79bdf2019-10-24 12:03:05 +03003330 return -1;
3331 } else if (rmrMessageBuffer.sendMessage->state != 0) {
3332 mdclog_write(MDCLOG_ERR,
3333 "Message state %s while sending request %d to Xapp from %s after retry of 10 microseconds",
3334 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
3335 rmrMessageBuffer.sendMessage->mtype,
3336 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
3337 auto rc = rmrMessageBuffer.sendMessage->state;
ss412g1a79bdf2019-10-24 12:03:05 +03003338 return rc;
3339 }
3340 } else {
3341 mdclog_write(MDCLOG_ERR, "Message state %s while sending request %d to Xapp from %s",
3342 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
3343 rmrMessageBuffer.sendMessage->mtype,
3344 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
ss412g1a79bdf2019-10-24 12:03:05 +03003345 return rmrMessageBuffer.sendMessage->state;
3346 }
3347 }
3348 return 0;
3349}
3350
3351void buildJsonMessage(ReportingMessages_t &message) {
dhirajverma60f8bef2021-06-29 07:22:58 -04003352#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04003353 jsonTrace = true;
dhirajverma60f8bef2021-06-29 07:22:58 -04003354#endif
ss412g3bac2da2020-01-05 11:52:19 +02003355 if (jsonTrace) {
3356 message.outLen = sizeof(message.base64Data);
3357 base64::encode((const unsigned char *) message.message.asndata,
3358 (const int) message.message.asnLength,
3359 message.base64Data,
3360 message.outLen);
3361 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03003362 mdclog_write(MDCLOG_DEBUG, "Tracing: ASN length = %d, base64 message length = %d ",
ss412g3bac2da2020-01-05 11:52:19 +02003363 (int) message.message.asnLength,
3364 (int) message.outLen);
3365 }
3366
3367 snprintf(message.buffer, sizeof(message.buffer),
aa7133@att.com96c9b882020-03-25 14:50:40 +02003368 "{\"header\": {\"ts\": \"%ld.%09ld\","
3369 "\"ranName\": \"%s\","
3370 "\"messageType\": %d,"
3371 "\"direction\": \"%c\"},"
3372 "\"base64Length\": %d,"
3373 "\"asnBase64\": \"%s\"}",
3374 message.message.time.tv_sec,
3375 message.message.time.tv_nsec,
3376 message.message.enodbName,
3377 message.message.messageType,
3378 message.message.direction,
3379 (int) message.outLen,
3380 message.base64Data);
ss412g3bac2da2020-01-05 11:52:19 +02003381 static src::logger_mt &lg = my_logger::get();
3382
3383 BOOST_LOG(lg) << message.buffer;
ss412g1a79bdf2019-10-24 12:03:05 +03003384 }
ss412g1a79bdf2019-10-24 12:03:05 +03003385}
3386
3387
3388/**
3389 * take RMR error code to string
3390 * @param state
3391 * @return
3392 */
3393string translateRmrErrorMessages(int state) {
3394 string str = {};
3395 switch (state) {
3396 case RMR_OK:
3397 str = "RMR_OK - state is good";
3398 break;
3399 case RMR_ERR_BADARG:
aa7133@att.com409f2232020-10-29 13:06:45 +03003400 str = "RMR_ERR_BADARG - argument passed to function was unusable";
ss412g1a79bdf2019-10-24 12:03:05 +03003401 break;
3402 case RMR_ERR_NOENDPT:
3403 str = "RMR_ERR_NOENDPT - send//call could not find an endpoint based on msg type";
3404 break;
3405 case RMR_ERR_EMPTY:
3406 str = "RMR_ERR_EMPTY - msg received had no payload; attempt to send an empty message";
3407 break;
3408 case RMR_ERR_NOHDR:
3409 str = "RMR_ERR_NOHDR - message didn't contain a valid header";
3410 break;
3411 case RMR_ERR_SENDFAILED:
3412 str = "RMR_ERR_SENDFAILED - send failed; errno has nano reason";
3413 break;
3414 case RMR_ERR_CALLFAILED:
3415 str = "RMR_ERR_CALLFAILED - unable to send call() message";
3416 break;
3417 case RMR_ERR_NOWHOPEN:
3418 str = "RMR_ERR_NOWHOPEN - no wormholes are open";
3419 break;
3420 case RMR_ERR_WHID:
3421 str = "RMR_ERR_WHID - wormhole id was invalid";
3422 break;
3423 case RMR_ERR_OVERFLOW:
3424 str = "RMR_ERR_OVERFLOW - operation would have busted through a buffer/field size";
3425 break;
3426 case RMR_ERR_RETRY:
3427 str = "RMR_ERR_RETRY - request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)";
3428 break;
3429 case RMR_ERR_RCVFAILED:
3430 str = "RMR_ERR_RCVFAILED - receive failed (hard error)";
3431 break;
3432 case RMR_ERR_TIMEOUT:
3433 str = "RMR_ERR_TIMEOUT - message processing call timed out";
3434 break;
3435 case RMR_ERR_UNSET:
3436 str = "RMR_ERR_UNSET - the message hasn't been populated with a transport buffer";
3437 break;
3438 case RMR_ERR_TRUNC:
3439 str = "RMR_ERR_TRUNC - received message likely truncated";
3440 break;
3441 case RMR_ERR_INITFAILED:
3442 str = "RMR_ERR_INITFAILED - initialisation of something (probably message) failed";
3443 break;
3444 case RMR_ERR_NOTSUPP:
3445 str = "RMR_ERR_NOTSUPP - the request is not supported, or RMr was not initialised for the request";
3446 break;
3447 default:
3448 char buf[128]{};
3449 snprintf(buf, sizeof buf, "UNDOCUMENTED RMR_ERR : %d", state);
3450 str = buf;
3451 break;
3452 }
3453 return str;
3454}
czichy2175dd32022-05-17 15:24:51 +03003455int fetchStreamId(ConnectedCU_t *peerInfo, ReportingMessages_t &message)
3456{
3457 auto loglevel = mdclog_level_get();
3458 int streamId = INVALID_STREAM_ID;
3459 if(message.peerInfo->isSingleStream != false)
3460 {
3461 streamId = message.peerInfo->singleStreamId;
3462 if (loglevel >= MDCLOG_DEBUG) {
3463 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for SINGLE_STREAM streamId %d , Messeage Type %d ,%s",
3464 streamId,message.message.messageType, __FUNCTION__);
3465 }
3466 return streamId;
3467 }
3468 int msgType = message.message.messageType;
3469 switch (msgType){
3470 case RIC_E2_RESET_REQ:
3471 case RIC_E2_RESET_RESP:
3472 case RIC_E2_SETUP_RESP:
3473 case RIC_E2_SETUP_FAILURE:
3474 case RIC_ERROR_INDICATION:
3475 case RIC_SERVICE_QUERY:
3476 case RIC_SERVICE_UPDATE_ACK:
3477 case RIC_SERVICE_UPDATE_FAILURE:
3478 streamId = 0;
3479 break;
3480 case RIC_SUB_REQ:
3481 case RIC_SUB_DEL_REQ:
3482 case RIC_CONTROL_REQ:
3483 streamId = 1;
3484 break;
3485 default:
3486 streamId = 0;
3487 break;
3488 }
3489 if (loglevel >= MDCLOG_DEBUG) {
3490 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for streamId %d Messeage Type %d, %s",
3491 streamId, message.message.messageType, __FUNCTION__);
3492 }
3493 return streamId;
3494}