blob: d34a4e59bc224ef885173e4437e45094746f2b26 [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;
ss412g3bac2da2020-01-05 11:52:19 +020062double 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 {
dhirajverma55e755b2021-06-29 02:01:47 +0530133
Alexandre Hufffff97942023-03-31 21:22:20 -0300134 FD_ZERO (&fds);
135 FD_SET (ifd, &fds);
dhirajverma55e755b2021-06-29 02:01:47 +0530136 while( 1 ) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300137 res = select (ifd + 1, &fds, NULL, NULL, NULL);
dhirajverma55e755b2021-06-29 02:01:47 +0530138 if(res)
139 {
140 n = read( ifd, rbuf, sizeof( rbuf ) ); // read the event
141 if( n < 0 ) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300142#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
dhirajverma55e755b2021-06-29 02:01:47 +0530143 if( errno == EAGAIN ) {
144 } else {
Alexandre Hufffff97942023-03-31 21:22:20 -0300145 fprintf( stderr, "### CRIT ### config listener read err: %s\n", strerror( errno ) );
dhirajverma55e755b2021-06-29 02:01:47 +0530146 }
147 continue;
Alexandre Hufffff97942023-03-31 21:22:20 -0300148#endif
dhirajverma55e755b2021-06-29 02:01:47 +0530149 }
150
151 //Retrieving Log Level from configmap by parsing configmap file
152 log_level = parse_file(fileName);
153 update_mdc_log_level_severity(log_level); //setting log level
Alexandre Hufffff97942023-03-31 21:22:20 -0300154 if(log_level != NULL) {
155 mdclog_write(MDCLOG_INFO, "MDC log level updated to %s", log_level);
156 free(log_level);
157 }
dhirajverma55e755b2021-06-29 02:01:47 +0530158 }
159 }
160 inotify_rm_watch(ifd,wfd);
161 }
162 close(ifd);
163 }
164 free(bname);
165 free(dname);
Alexandre Hufffff97942023-03-31 21:22:20 -0300166 free(fileName);
dhirajverma55e755b2021-06-29 02:01:47 +0530167
168 pthread_exit(NULL);
169}
170
171void update_mdc_log_level_severity(char* log_level)
172{
173 mdclog_severity_t level = MDCLOG_ERR;
174
175 if(log_level == NULL)
176 {
177 printf("### ERR ### Invalid Log-Level Configuration in ConfigMap, Default Log-Level Applied: %d\n",level);
178 }
179 else if(strcasecmp(log_level,"1")==0)
180 {
181 level = MDCLOG_ERR;
182 }
183 else if(strcasecmp(log_level,"2")==0)
184 {
185 level = MDCLOG_WARN;
186 }
187 else if(strcasecmp(log_level,"3")==0)
188 {
189 level = MDCLOG_INFO;
190 }
191 else if(strcasecmp(log_level,"4")==0)
192 {
193 level = MDCLOG_DEBUG;
194 }
195
196 mdclog_level_set(level);
197}
Alexandre Hufffff97942023-03-31 21:22:20 -0300198
199/**
200 * @brief Remove leading and trailing spaces from s.
201 *
202 * If the string was allocated dynamically, the caller cannot
203 * overwrite the returned pointer.
204 *
205 * @param s the string we want to remove spaces.
206 * @return Returns a null-terminated substring of "s".
207 */
208static inline char *trim(char *s)
209{
210 char *end;
211 /* skip leading spaces */
212 while (isspace(*s)) s++;
213
214 /* all spaces */
215 if (*s == '\0') return s;
216
217 /* skip trailing spaces */
218 end = s + strlen(s) - 1;
219 while (end > s && isspace(*end)) end--;
220
221 /* write null character */
222 *(end+1) = '\0';
223
224 return s;
225}
226
dhirajverma55e755b2021-06-29 02:01:47 +0530227static char* parse_file(char* filename)
228{
229 char *token=NULL;
dhirajverma55e755b2021-06-29 02:01:47 +0530230 bool found = false;
231 FILE *file = fopen ( filename, "r" );
Alexandre Hufffff97942023-03-31 21:22:20 -0300232
dhirajverma55e755b2021-06-29 02:01:47 +0530233 if ( file != NULL )
234 {
235 char line [ 128 ];
Alexandre Hufffff97942023-03-31 21:22:20 -0300236 while ( fgets ( line, sizeof(line), file ) != NULL )
dhirajverma55e755b2021-06-29 02:01:47 +0530237 {
Alexandre Hufffff97942023-03-31 21:22:20 -0300238 token = strtok(line, ":");
239 token = trim(token);
240 if (strcmp(token,"log-level") == 0) {
dhirajverma55e755b2021-06-29 02:01:47 +0530241 found = true;
Alexandre Hufffff97942023-03-31 21:22:20 -0300242 token = strtok(NULL, "\n");
243 token = trim(token);
dhirajverma55e755b2021-06-29 02:01:47 +0530244 break;
245 }
246 }
247 fclose ( file );
248 }
249 if(found)
250 return(strdup(token));
251 else
252 return(NULL);
253}
254
255char *read_env_param(const char*envkey)
256{
257 if(envkey)
258 {
259 char *value = getenv(envkey);
260 if(value)
261 return strdup(value);
262 }
263 return NULL;
264}
265
266void dynamic_log_level_change()
267{
268 char *logFile_Name = read_env_param(LOG_FILE_CONFIG_MAP);
269 char* log_level_init=NULL;
270 if(logFile_Name)
271 {
272 log_level_init = parse_file(logFile_Name);
273 update_mdc_log_level_severity(log_level_init); //setting log level
Alexandre Hufffff97942023-03-31 21:22:20 -0300274 mdclog_write(MDCLOG_INFO, "MDC log level set to %s", log_level_init);
dhirajverma55e755b2021-06-29 02:01:47 +0530275 free(log_level_init);
276
277 }
278 enable_log_change_notify(logFile_Name);
dhirajverma55e755b2021-06-29 02:01:47 +0530279}
280
ss412g1a79bdf2019-10-24 12:03:05 +0300281void init_log() {
dhirajverma55e755b2021-06-29 02:01:47 +0530282 int log_change_monitor = 0;
ss412g1a79bdf2019-10-24 12:03:05 +0300283 mdclog_attr_t *attr;
284 mdclog_attr_init(&attr);
285 mdclog_attr_set_ident(attr, "E2Terminator");
286 mdclog_init(attr);
dhirajverma5f132832021-06-17 17:27:54 +0530287 if(mdclog_format_initialize(log_change_monitor)!=0)
288 mdclog_write(MDCLOG_ERR, "Failed to intialize MDC log format !!!");
dhirajverma55e755b2021-06-29 02:01:47 +0530289 dynamic_log_level_change();
ss412g1a79bdf2019-10-24 12:03:05 +0300290 mdclog_attr_destroy(attr);
291}
ss412g3bac2da2020-01-05 11:52:19 +0200292auto start_time = std::chrono::high_resolution_clock::now();
293typedef std::chrono::duration<double, std::ratio<1,1>> seconds_t;
ss412g1a79bdf2019-10-24 12:03:05 +0300294
ss412g3bac2da2020-01-05 11:52:19 +0200295double age() {
296 return seconds_t(std::chrono::high_resolution_clock::now() - start_time).count();
297}
298
aa7133@att.com409f2232020-10-29 13:06:45 +0300299double approx_CPU_MHz(unsigned sleepTime) {
ss412g3bac2da2020-01-05 11:52:19 +0200300 using namespace std::chrono_literals;
301 uint32_t aux = 0;
302 uint64_t cycles_start = rdtscp(aux);
303 double time_start = age();
aa7133@att.com409f2232020-10-29 13:06:45 +0300304 std::this_thread::sleep_for(sleepTime * 1ms);
ss412g3bac2da2020-01-05 11:52:19 +0200305 uint64_t elapsed_cycles = rdtscp(aux) - cycles_start;
306 double elapsed_time = age() - time_start;
307 return elapsed_cycles / elapsed_time;
308}
ss412g1a79bdf2019-10-24 12:03:05 +0300309
310//std::atomic<int64_t> rmrCounter{0};
311std::atomic<int64_t> num_of_messages{0};
ss412g3bac2da2020-01-05 11:52:19 +0200312std::atomic<int64_t> num_of_XAPP_messages{0};
ss412g1a79bdf2019-10-24 12:03:05 +0300313static long transactionCounter = 0;
sandeekuea662102022-11-08 18:51:20 +0530314pthread_mutex_t thread_lock;
ss412g1a79bdf2019-10-24 12:03:05 +0300315
aa7133@att.com84bd3342020-03-16 18:04:57 +0200316int buildListeningPort(sctp_params_t &sctpParams) {
aa7133@att.comf211f192020-06-23 12:50:10 +0300317 sctpParams.listenFD = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP);
318 if (sctpParams.listenFD <= 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300319#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comf211f192020-06-23 12:50:10 +0300320 mdclog_write(MDCLOG_ERR, "Error Opening socket, %s", strerror(errno));
321 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300322#endif
aa7133@att.comf211f192020-06-23 12:50:10 +0300323 }
czichy2175dd32022-05-17 15:24:51 +0300324 struct sctp_initmsg initmsg;
325 memset (&initmsg, 0, sizeof (initmsg));
326 initmsg.sinit_num_ostreams = 2;
327 initmsg.sinit_max_instreams = 2;
328 initmsg.sinit_max_attempts = 4;
329 setsockopt (sctpParams.listenFD, IPPROTO_SCTP, SCTP_INITMSG, &initmsg, sizeof (initmsg));
aa7133@att.comf211f192020-06-23 12:50:10 +0300330
aa7133@att.com409f2232020-10-29 13:06:45 +0300331 struct sockaddr_in6 serverAddress {};
332 serverAddress.sin6_family = AF_INET6;
333 serverAddress.sin6_addr = in6addr_any;
334 serverAddress.sin6_port = htons(sctpParams.sctpPort);
335 if (bind(sctpParams.listenFD, (SA *)&serverAddress, sizeof(serverAddress)) < 0 ) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300336#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comf211f192020-06-23 12:50:10 +0300337 mdclog_write(MDCLOG_ERR, "Error binding port %d. %s", sctpParams.sctpPort, strerror(errno));
aa7133@att.com84bd3342020-03-16 18:04:57 +0200338 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300339#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +0200340 }
341 if (setSocketNoBlocking(sctpParams.listenFD) == -1) {
342 //mdclog_write(MDCLOG_ERR, "Error binding. %s", strerror(errno));
343 return -1;
344 }
345 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300346 struct sockaddr_in6 clientAddress {};
347 socklen_t len = sizeof(clientAddress);
348 getsockname(sctpParams.listenFD, (SA *)&clientAddress, &len);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200349 char buff[1024] {};
aa7133@att.com409f2232020-10-29 13:06:45 +0300350 inet_ntop(AF_INET6, &clientAddress.sin6_addr, buff, sizeof(buff));
351 mdclog_write(MDCLOG_DEBUG, "My address: %s, port %d\n", buff, htons(clientAddress.sin6_port));
ss412g1a79bdf2019-10-24 12:03:05 +0300352 }
353
aa7133@att.com84bd3342020-03-16 18:04:57 +0200354 if (listen(sctpParams.listenFD, SOMAXCONN) < 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300355#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +0200356 mdclog_write(MDCLOG_ERR, "Error listening. %s\n", strerror(errno));
357 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300358#endif
ss412g3bac2da2020-01-05 11:52:19 +0200359 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200360 struct epoll_event event {};
361 event.events = EPOLLIN | EPOLLET;
362 event.data.fd = sctpParams.listenFD;
363
364 // add listening port to epoll
365 if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.listenFD, &event)) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400366#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +0200367 printf("Failed to add descriptor to epoll\n");
368 mdclog_write(MDCLOG_ERR, "Failed to add descriptor to epoll. %s\n", strerror(errno));
369 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300370#endif
ss412g3bac2da2020-01-05 11:52:19 +0200371 }
372
aa7133@att.com84bd3342020-03-16 18:04:57 +0200373 return 0;
374}
ss412g3bac2da2020-01-05 11:52:19 +0200375
aa7133@att.com84bd3342020-03-16 18:04:57 +0200376int buildConfiguration(sctp_params_t &sctpParams) {
ss412g3bac2da2020-01-05 11:52:19 +0200377 path p = (sctpParams.configFilePath + "/" + sctpParams.configFileName).c_str();
378 if (exists(p)) {
379 const int size = 2048;
380 auto fileSize = file_size(p);
381 if (fileSize > size) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300382#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200383 mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200384 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300385#endif
ss412g3bac2da2020-01-05 11:52:19 +0200386 }
387 } else {
Alexandre Hufffff97942023-03-31 21:22:20 -0300388#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200389 mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str());
aa7133@att.com84bd3342020-03-16 18:04:57 +0200390 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300391#endif
ss412g3bac2da2020-01-05 11:52:19 +0200392 }
393
ss412g3bac2da2020-01-05 11:52:19 +0200394 ReadConfigFile conf;
395 if (conf.openConfigFile(p.string()) == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300396#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200397 mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s",
398 p.string().c_str(), strerror(errno));
aa7133@att.com84bd3342020-03-16 18:04:57 +0200399 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300400#endif
ss412g3bac2da2020-01-05 11:52:19 +0200401 }
402 int rmrPort = conf.getIntValue("nano");
403 if (rmrPort == -1) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400404#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300405 mdclog_write(MDCLOG_ERR, "illegal RMR port ");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200406 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300407#endif
ss412g3bac2da2020-01-05 11:52:19 +0200408 }
409 sctpParams.rmrPort = (uint16_t)rmrPort;
410 snprintf(sctpParams.rmrAddress, sizeof(sctpParams.rmrAddress), "%d", (int) (sctpParams.rmrPort));
dhirajverma5f132832021-06-17 17:27:54 +0530411 auto tmpStr = conf.getStringValue("volume");
ss412g3bac2da2020-01-05 11:52:19 +0200412 if (tmpStr.length() == 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300413#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300414 mdclog_write(MDCLOG_ERR, "illegal volume.");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200415 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300416#endif
ss412g3bac2da2020-01-05 11:52:19 +0200417 }
418
ss412g1a79bdf2019-10-24 12:03:05 +0300419 char tmpLogFilespec[VOLUME_URL_SIZE];
420 tmpLogFilespec[0] = 0;
ss412g3bac2da2020-01-05 11:52:19 +0200421 sctpParams.volume[0] = 0;
422 snprintf(sctpParams.volume, VOLUME_URL_SIZE, "%s", tmpStr.c_str());
423 // copy the name to temp file as well
424 snprintf(tmpLogFilespec, VOLUME_URL_SIZE, "%s", tmpStr.c_str());
425
426
427 // define the file name in the tmp directory under the volume
428 strcat(tmpLogFilespec,"/tmp/E2Term_%Y-%m-%d_%H-%M-%S.%N.tmpStr");
429
430 sctpParams.myIP = conf.getStringValue("local-ip");
431 if (sctpParams.myIP.length() == 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300432#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300433 mdclog_write(MDCLOG_ERR, "illegal local-ip.");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200434 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300435#endif
ss412g1a79bdf2019-10-24 12:03:05 +0300436 }
437
aa7133@att.combe92d712020-03-18 17:30:39 +0200438 int sctpPort = conf.getIntValue("sctp-port");
439 if (sctpPort == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300440#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300441 mdclog_write(MDCLOG_ERR, "illegal SCTP port ");
aa7133@att.combe92d712020-03-18 17:30:39 +0200442 return -1;
Alexandre Hufffff97942023-03-31 21:22:20 -0300443#endif
aa7133@att.combe92d712020-03-18 17:30:39 +0200444 }
445 sctpParams.sctpPort = (uint16_t)sctpPort;
446
aa7133@att.com84bd3342020-03-16 18:04:57 +0200447 sctpParams.fqdn = conf.getStringValue("external-fqdn");
448 if (sctpParams.fqdn.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 external-fqdn");
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 }
ss412g1a79bdf2019-10-24 12:03:05 +0300454
aa7133@att.com342843e2020-01-26 12:53:34 +0200455 std::string pod = conf.getStringValue("pod_name");
dhirajverma6cf28612021-06-23 04:53:34 -0400456#ifndef UNIT_TEST
aa7133@att.com342843e2020-01-26 12:53:34 +0200457 if (pod.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300458 mdclog_write(MDCLOG_ERR, "illegal pod_name in config file");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200459 return -1;
aa7133@att.com342843e2020-01-26 12:53:34 +0200460 }
461 auto *podName = getenv(pod.c_str());
462 if (podName == nullptr) {
aa7133@att.com54885fe2020-10-29 17:24:49 +0300463 mdclog_write(MDCLOG_ERR, "illegal pod_name or environment variable not exists : %s", pod.c_str());
aa7133@att.com84bd3342020-03-16 18:04:57 +0200464 return -1;
aa7133@att.com342843e2020-01-26 12:53:34 +0200465
466 } else {
467 sctpParams.podName.assign(podName);
468 if (sctpParams.podName.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300469 mdclog_write(MDCLOG_ERR, "illegal pod_name");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200470 return -1;
aa7133@att.com342843e2020-01-26 12:53:34 +0200471 }
472 }
dhirajverma6cf28612021-06-23 04:53:34 -0400473#endif
ss412g3bac2da2020-01-05 11:52:19 +0200474 tmpStr = conf.getStringValue("trace");
475 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
476 if ((tmpStr.compare("start")) == 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300477#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200478 mdclog_write(MDCLOG_INFO, "Trace set to: start");
479 sctpParams.trace = true;
Alexandre Hufffff97942023-03-31 21:22:20 -0300480#endif
ss412g3bac2da2020-01-05 11:52:19 +0200481 } else if ((tmpStr.compare("stop")) == 0) {
482 mdclog_write(MDCLOG_INFO, "Trace set to: stop");
483 sctpParams.trace = false;
aa7133@att.com41fcb3f2020-11-29 13:48:25 +0200484 } else {
Alexandre Hufffff97942023-03-31 21:22:20 -0300485#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com41fcb3f2020-11-29 13:48:25 +0200486 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 +0200487 sctpParams.trace = false;
Alexandre Hufffff97942023-03-31 21:22:20 -0300488#endif
ss412g3bac2da2020-01-05 11:52:19 +0200489 }
490 jsonTrace = sctpParams.trace;
ss412g1a79bdf2019-10-24 12:03:05 +0300491
ss412g4aeeda22020-06-16 14:12:41 +0300492 sctpParams.epollTimeOut = -1;
ss412g4aeeda22020-06-16 14:12:41 +0300493
494 tmpStr = conf.getStringValue("prometheusPort");
495 if (tmpStr.length() != 0) {
496 sctpParams.prometheusPort = tmpStr;
497 }
498
aa7133@att.combe92d712020-03-18 17:30:39 +0200499 sctpParams.ka_message_length = snprintf(sctpParams.ka_message, KA_MESSAGE_SIZE, "{\"address\": \"%s:%d\","
aa7133@att.com96c9b882020-03-25 14:50:40 +0200500 "\"fqdn\": \"%s\","
501 "\"pod_name\": \"%s\"}",
aa7133@att.com342843e2020-01-26 12:53:34 +0200502 (const char *)sctpParams.myIP.c_str(),
503 sctpParams.rmrPort,
504 sctpParams.fqdn.c_str(),
505 sctpParams.podName.c_str());
506
ss412g1a79bdf2019-10-24 12:03:05 +0300507 if (mdclog_level_get() >= MDCLOG_INFO) {
dhirajverma5f132832021-06-17 17:27:54 +0530508 mdclog_write(MDCLOG_DEBUG,"RMR Port: %s", to_string(sctpParams.rmrPort).c_str());
dhirajverma5f132832021-06-17 17:27:54 +0530509 mdclog_write(MDCLOG_DEBUG,"volume: %s", sctpParams.volume);
510 mdclog_write(MDCLOG_DEBUG,"tmpLogFilespec: %s", tmpLogFilespec);
511 mdclog_write(MDCLOG_DEBUG,"my ip: %s", sctpParams.myIP.c_str());
512 mdclog_write(MDCLOG_DEBUG,"pod name: %s", sctpParams.podName.c_str());
ss412g1a79bdf2019-10-24 12:03:05 +0300513
aa7133@att.com342843e2020-01-26 12:53:34 +0200514 mdclog_write(MDCLOG_INFO, "running parameters for instance : %s", sctpParams.ka_message);
ss412g1a79bdf2019-10-24 12:03:05 +0300515 }
ss412g1a79bdf2019-10-24 12:03:05 +0300516
517 // Files written to the current working directory
518 boostLogger = logging::add_file_log(
ss412g3bac2da2020-01-05 11:52:19 +0200519 keywords::file_name = tmpLogFilespec, // to temp directory
ss412g1a79bdf2019-10-24 12:03:05 +0300520 keywords::rotation_size = 10 * 1024 * 1024,
521 keywords::time_based_rotation = sinks::file::rotation_at_time_interval(posix_time::hours(1)),
522 keywords::format = "%Message%"
ss412g3bac2da2020-01-05 11:52:19 +0200523 //keywords::format = "[%TimeStamp%]: %Message%" // use each tmpStr with time stamp
ss412g1a79bdf2019-10-24 12:03:05 +0300524 );
525
aa7133@att.com54885fe2020-10-29 17:24:49 +0300526 // Setup a destination folder for collecting rotated (closed) files --since the same volume can use rename()
ss412g1a79bdf2019-10-24 12:03:05 +0300527 boostLogger->locked_backend()->set_file_collector(sinks::file::make_collector(
ss412g3bac2da2020-01-05 11:52:19 +0200528 keywords::target = sctpParams.volume
ss412g1a79bdf2019-10-24 12:03:05 +0300529 ));
530
531 // Upon restart, scan the directory for files matching the file_name pattern
532 boostLogger->locked_backend()->scan_for_files();
533
ss412g3bac2da2020-01-05 11:52:19 +0200534 // Enable auto-flushing after each tmpStr record written
ss412g1a79bdf2019-10-24 12:03:05 +0300535 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +0200536 boostLogger->locked_backend()->auto_flush(true);
537 }
538
539 return 0;
540}
541
aa7133@att.coma4c80012020-06-24 16:36:47 +0300542void startPrometheus(sctp_params_t &sctpParams) {
Mohamed Abukar64f37242021-08-15 12:39:56 +0000543 auto podName = std::getenv("POD_NAME");
544 string metric = "E2TBeta";
545 if (strstr(podName, "alpha") != NULL) {
546 metric = "E2TAlpha";
547 }
wahidw1d1a9b72021-09-24 17:35:28 +0000548 //Get eth0 interface IP
549 char* host = getinterfaceip();
550 string hostip = host;
Mohamed Abukar64f37242021-08-15 12:39:56 +0000551
aa7133@att.coma4c80012020-06-24 16:36:47 +0300552 sctpParams.prometheusFamily = &BuildCounter()
Mohamed Abukar64f37242021-08-15 12:39:56 +0000553 .Name(metric.c_str())
554 .Help("E2T instance metrics")
aa7133@att.coma4c80012020-06-24 16:36:47 +0300555 .Labels({{"POD_NAME", sctpParams.podName}})
556 .Register(*sctpParams.prometheusRegistry);
aa7133@att.com16c799b2020-03-24 18:01:51 +0200557
Mohamed Abukar64f37242021-08-15 12:39:56 +0000558 // Build E2T instance level metrics
559 buildE2TPrometheusCounters(sctpParams);
560
wahidw1d1a9b72021-09-24 17:35:28 +0000561 string prometheusPath;
562 if (hostip.empty())
563 prometheusPath = sctpParams.prometheusPort + "," + "[::]:" + sctpParams.prometheusPort;
564 else
565 prometheusPath = hostip + ":" + sctpParams.prometheusPort;
566
aa7133@att.comb92748d2020-06-29 11:52:30 +0300567 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com54885fe2020-10-29 17:24:49 +0300568 mdclog_write(MDCLOG_DEBUG, "Start Prometheus Pull mode on %s", prometheusPath.c_str());
aa7133@att.coma4c80012020-06-24 16:36:47 +0300569 }
aa7133@att.com54885fe2020-10-29 17:24:49 +0300570 sctpParams.prometheusExposer = new Exposer(prometheusPath, 1);
aa7133@att.comb92748d2020-06-29 11:52:30 +0300571 sctpParams.prometheusExposer->RegisterCollectable(sctpParams.prometheusRegistry);
aa7133@att.coma4c80012020-06-24 16:36:47 +0300572}
dhirajverma31768a92021-05-06 12:38:49 +0530573#ifndef UNIT_TEST
dhirajverma5f132832021-06-17 17:27:54 +0530574
aa7133@att.com84bd3342020-03-16 18:04:57 +0200575int main(const int argc, char **argv) {
576 sctp_params_t sctpParams;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200577 {
578 std::random_device device{};
579 std::mt19937 generator(device());
580 std::uniform_int_distribution<long> distribution(1, (long) 1e12);
581 transactionCounter = distribution(generator);
582 }
583
584// uint64_t st = 0;
585// uint32_t aux1 = 0;
586// st = rdtscp(aux1);
587
588 unsigned num_cpus = std::thread::hardware_concurrency();
589 init_log();
aa7133@att.com84bd3342020-03-16 18:04:57 +0200590 if (std::signal(SIGINT, catch_function) == SIG_ERR) {
591 mdclog_write(MDCLOG_ERR, "Error initializing SIGINT");
592 exit(1);
593 }
594 if (std::signal(SIGABRT, catch_function)== SIG_ERR) {
595 mdclog_write(MDCLOG_ERR, "Error initializing SIGABRT");
596 exit(1);
597 }
598 if (std::signal(SIGTERM, catch_function)== SIG_ERR) {
599 mdclog_write(MDCLOG_ERR, "Error initializing SIGTERM");
600 exit(1);
601 }
602
603 cpuClock = approx_CPU_MHz(100);
604
605 mdclog_write(MDCLOG_DEBUG, "CPU speed %11.11f", cpuClock);
606
607 auto result = parse(argc, argv, sctpParams);
608
609 if (buildConfiguration(sctpParams) != 0) {
610 exit(-1);
ss412g1a79bdf2019-10-24 12:03:05 +0300611 }
612
ss412g4aeeda22020-06-16 14:12:41 +0300613 //auto registry = std::make_shared<Registry>();
614 sctpParams.prometheusRegistry = std::make_shared<Registry>();
615
aa7133@att.com409f2232020-10-29 13:06:45 +0300616 //sctpParams.prometheusFamily = new Family<Counter>("E2T", "E2T message counter", {{"E", sctpParams.podName}});
ss412g4aeeda22020-06-16 14:12:41 +0300617
aa7133@att.coma4c80012020-06-24 16:36:47 +0300618 startPrometheus(sctpParams);
ss412g4aeeda22020-06-16 14:12:41 +0300619
ss412g1a79bdf2019-10-24 12:03:05 +0300620 // start epoll
ss412g3bac2da2020-01-05 11:52:19 +0200621 sctpParams.epoll_fd = epoll_create1(0);
622 if (sctpParams.epoll_fd == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +0300623 mdclog_write(MDCLOG_ERR, "failed to open epoll descriptor");
624 exit(-1);
625 }
aa7133@att.combe92d712020-03-18 17:30:39 +0200626 getRmrContext(sctpParams);
ss412g3bac2da2020-01-05 11:52:19 +0200627 if (sctpParams.rmrCtx == nullptr) {
628 close(sctpParams.epoll_fd);
ss412g1a79bdf2019-10-24 12:03:05 +0300629 exit(-1);
630 }
631
ss412g3bac2da2020-01-05 11:52:19 +0200632 if (buildInotify(sctpParams) == -1) {
633 close(sctpParams.rmrListenFd);
634 rmr_close(sctpParams.rmrCtx);
635 close(sctpParams.epoll_fd);
636 exit(-1);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200637 }
638
639 if (buildListeningPort(sctpParams) != 0) {
640 close(sctpParams.rmrListenFd);
641 rmr_close(sctpParams.rmrCtx);
642 close(sctpParams.epoll_fd);
643 exit(-1);
644 }
ss412g3bac2da2020-01-05 11:52:19 +0200645
646 sctpParams.sctpMap = new mapWrapper();
ss412g1a79bdf2019-10-24 12:03:05 +0300647
sandeekuea662102022-11-08 18:51:20 +0530648 if (pthread_mutex_init(&thread_lock, NULL) != 0) {
649 mdclog_write(MDCLOG_ERR, "failed to init thread lock");
650 exit(-1);
651 }
ss412g1a79bdf2019-10-24 12:03:05 +0300652 std::vector<std::thread> threads(num_cpus);
653// std::vector<std::thread> threads;
654
aa7133@att.com24e9fa42020-11-13 20:32:53 +0200655 num_cpus = 3;
ss412g1a79bdf2019-10-24 12:03:05 +0300656 for (unsigned int i = 0; i < num_cpus; i++) {
ss412g3bac2da2020-01-05 11:52:19 +0200657 threads[i] = std::thread(listener, &sctpParams);
ss412g1a79bdf2019-10-24 12:03:05 +0300658
659 cpu_set_t cpuset;
660 CPU_ZERO(&cpuset);
661 CPU_SET(i, &cpuset);
662 int rc = pthread_setaffinity_np(threads[i].native_handle(), sizeof(cpu_set_t), &cpuset);
663 if (rc != 0) {
664 mdclog_write(MDCLOG_ERR, "Error calling pthread_setaffinity_np: %d", rc);
665 }
ss412g1a79bdf2019-10-24 12:03:05 +0300666 }
667
aa7133@att.com16c799b2020-03-24 18:01:51 +0200668
ss412g3bac2da2020-01-05 11:52:19 +0200669 //loop over term_init until first message from xApp
670 handleTermInit(sctpParams);
671
672 for (auto &t : threads) {
673 t.join();
674 }
sandeekuea662102022-11-08 18:51:20 +0530675 pthread_mutex_destroy(&thread_lock);
ss412g3bac2da2020-01-05 11:52:19 +0200676 return 0;
677}
dhirajverma60f8bef2021-06-29 07:22:58 -0400678#endif
ss412g3bac2da2020-01-05 11:52:19 +0200679void handleTermInit(sctp_params_t &sctpParams) {
680 sendTermInit(sctpParams);
ss412g1a79bdf2019-10-24 12:03:05 +0300681 //send to e2 manager init of e2 term
682 //E2_TERM_INIT
ss412g1a79bdf2019-10-24 12:03:05 +0300683
ss412g3bac2da2020-01-05 11:52:19 +0200684 int count = 0;
685 while (true) {
686 auto xappMessages = num_of_XAPP_messages.load(std::memory_order_acquire);
687 if (xappMessages > 0) {
688 if (mdclog_level_get() >= MDCLOG_INFO) {
aa7133@att.com54885fe2020-10-29 17:24:49 +0300689 mdclog_write(MDCLOG_INFO, "Got a message from some application, stop sending E2_TERM_INIT");
ss412g3bac2da2020-01-05 11:52:19 +0200690 }
691 return;
692 }
693 usleep(100000);
694 count++;
695 if (count % 1000 == 0) {
696 mdclog_write(MDCLOG_ERR, "GOT No messages from any xApp");
697 sendTermInit(sctpParams);
698 }
699 }
700}
701
702void sendTermInit(sctp_params_t &sctpParams) {
703 rmr_mbuf_t *msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.ka_message_length);
ss412g1a79bdf2019-10-24 12:03:05 +0300704 auto count = 0;
ss412g3bac2da2020-01-05 11:52:19 +0200705 while (true) {
ss412g1a79bdf2019-10-24 12:03:05 +0300706 msg->mtype = E2_TERM_INIT;
707 msg->state = 0;
ss412g3bac2da2020-01-05 11:52:19 +0200708 rmr_bytes2payload(msg, (unsigned char *)sctpParams.ka_message, sctpParams.ka_message_length);
ss412g1a79bdf2019-10-24 12:03:05 +0300709 static unsigned char tx[32];
710 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
711 rmr_bytes2xact(msg, tx, txLen);
ss412g3bac2da2020-01-05 11:52:19 +0200712 msg = rmr_send_msg(sctpParams.rmrCtx, msg);
ss412g1a79bdf2019-10-24 12:03:05 +0300713 if (msg == nullptr) {
aa7133@att.comc9575aa2020-04-02 11:40:09 +0300714 msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.ka_message_length);
ss412g1a79bdf2019-10-24 12:03:05 +0300715 } else if (msg->state == 0) {
ss412g1a79bdf2019-10-24 12:03:05 +0300716 rmr_free_msg(msg);
ss412g3bac2da2020-01-05 11:52:19 +0200717 if (mdclog_level_get() >= MDCLOG_INFO) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300718 mdclog_write(MDCLOG_INFO, "E2_TERM_INIT successfully sent ");
ss412g3bac2da2020-01-05 11:52:19 +0200719 }
720 return;
ss412g1a79bdf2019-10-24 12:03:05 +0300721 } else {
722 if (count % 100 == 0) {
aa7133@att.com11b17d42020-03-22 11:35:16 +0200723 mdclog_write(MDCLOG_ERR, "Error sending E2_TERM_INIT cause : %s ", translateRmrErrorMessages(msg->state).c_str());
ss412g1a79bdf2019-10-24 12:03:05 +0300724 }
725 sleep(1);
726 }
727 count++;
728 }
ss412g3bac2da2020-01-05 11:52:19 +0200729}
730
731/**
732 *
733 * @param argc
734 * @param argv
735 * @param sctpParams
736 * @return
737 */
738cxxopts::ParseResult parse(int argc, char *argv[], sctp_params_t &sctpParams) {
739 cxxopts::Options options(argv[0], "e2 term help");
740 options.positional_help("[optional args]").show_positional_help();
741 options.allow_unrecognised_options().add_options()
742 ("p,path", "config file path", cxxopts::value<std::string>(sctpParams.configFilePath)->default_value("config"))
743 ("f,file", "config file name", cxxopts::value<std::string>(sctpParams.configFileName)->default_value("config.conf"))
744 ("h,help", "Print help");
745
aa7133@att.comde40d1c2020-08-26 16:19:20 +0300746 auto result = options.parse(argc, (const char **&)argv);
ss412g3bac2da2020-01-05 11:52:19 +0200747
748 if (result.count("help")) {
749 std::cout << options.help({""}) << std::endl;
750 exit(0);
751 }
752 return result;
753}
754
755/**
756 *
757 * @param sctpParams
758 * @return -1 failed 0 success
759 */
760int buildInotify(sctp_params_t &sctpParams) {
761 sctpParams.inotifyFD = inotify_init1(IN_NONBLOCK);
762 if (sctpParams.inotifyFD == -1) {
763 mdclog_write(MDCLOG_ERR, "Failed to init inotify (inotify_init1) %s", strerror(errno));
ss412g3bac2da2020-01-05 11:52:19 +0200764 return -1;
ss412g1a79bdf2019-10-24 12:03:05 +0300765 }
766
ss412g3bac2da2020-01-05 11:52:19 +0200767 sctpParams.inotifyWD = inotify_add_watch(sctpParams.inotifyFD,
aa7133@att.com96c9b882020-03-25 14:50:40 +0200768 (const char *)sctpParams.configFilePath.c_str(),
aa7133@att.com84bd3342020-03-16 18:04:57 +0200769 (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 +0200770 if (sctpParams.inotifyWD == -1) {
771 mdclog_write(MDCLOG_ERR, "Failed to add directory : %s to inotify (inotify_add_watch) %s",
aa7133@att.com96c9b882020-03-25 14:50:40 +0200772 sctpParams.configFilePath.c_str(),
773 strerror(errno));
ss412g3bac2da2020-01-05 11:52:19 +0200774 close(sctpParams.inotifyFD);
775 return -1;
776 }
777
778 struct epoll_event event{};
779 event.events = (EPOLLIN);
780 event.data.fd = sctpParams.inotifyFD;
781 // add listening RMR FD to epoll
782 if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.inotifyFD, &event)) {
783 mdclog_write(MDCLOG_ERR, "Failed to add inotify FD to epoll");
784 close(sctpParams.inotifyFD);
785 return -1;
786 }
ss412g1a79bdf2019-10-24 12:03:05 +0300787 return 0;
788}
789
790/**
791 *
792 * @param args
793 * @return
794 */
795void listener(sctp_params_t *params) {
ss412g1a79bdf2019-10-24 12:03:05 +0300796 int num_of_SCTP_messages = 0;
ss412g1a79bdf2019-10-24 12:03:05 +0300797 auto totalTime = 0.0;
ss412g1a79bdf2019-10-24 12:03:05 +0300798 std::thread::id this_id = std::this_thread::get_id();
799 //save cout
dhirajverma5f132832021-06-17 17:27:54 +0530800 auto pod_name = std::getenv("POD_NAME");
801 auto container_name = std::getenv("CONTAINER_NAME");
802 auto service_name = std::getenv("SERVICE_NAME");
803 auto host_name = std::getenv("HOST_NAME");
804 auto system_name = std::getenv("SYSTEM_NAME");
805 auto pid = std::to_string(getpid()).c_str();
ss412g1a79bdf2019-10-24 12:03:05 +0300806 streambuf *oldCout = cout.rdbuf();
807 ostringstream memCout;
808 // create new cout
809 cout.rdbuf(memCout.rdbuf());
810 cout << this_id;
811 //return to the normal cout
812 cout.rdbuf(oldCout);
813
814 char tid[32];
815 memcpy(tid, memCout.str().c_str(), memCout.str().length() < 32 ? memCout.str().length() : 31);
816 tid[memCout.str().length()] = 0;
dhirajverma5f132832021-06-17 17:27:54 +0530817 mdclog_mdc_add("SYSTEM_NAME", system_name);
818 mdclog_mdc_add("HOST_NAME", host_name);
819 mdclog_mdc_add("SERVICE_NAME", service_name);
820 mdclog_mdc_add("CONTAINER_NAME", container_name);
821 mdclog_mdc_add("POD_NAME", pod_name);
822 mdclog_mdc_add("PID", pid);
ss412g1a79bdf2019-10-24 12:03:05 +0300823
824 if (mdclog_level_get() >= MDCLOG_DEBUG) {
825 mdclog_write(MDCLOG_DEBUG, "started thread number %s", tid);
826 }
827
828 RmrMessagesBuffer_t rmrMessageBuffer{};
829 //create and init RMR
830 rmrMessageBuffer.rmrCtx = params->rmrCtx;
831
832 auto *events = (struct epoll_event *) calloc(MAXEVENTS, sizeof(struct epoll_event));
833 struct timespec end{0, 0};
834 struct timespec start{0, 0};
835
836 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
837 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
838
ss412g3bac2da2020-01-05 11:52:19 +0200839 memcpy(rmrMessageBuffer.ka_message, params->ka_message, params->ka_message_length);
840 rmrMessageBuffer.ka_message_len = params->ka_message_length;
841 rmrMessageBuffer.ka_message[rmrMessageBuffer.ka_message_len] = 0;
842
843 if (mdclog_level_get() >= MDCLOG_DEBUG) {
844 mdclog_write(MDCLOG_DEBUG, "keep alive message is : %s", rmrMessageBuffer.ka_message);
845 }
846
ss412g1a79bdf2019-10-24 12:03:05 +0300847 ReportingMessages_t message {};
848
aa7133@att.com409f2232020-10-29 13:06:45 +0300849// for (int i = 0; i < MAX_RMR_BUFF_ARRAY; i++) {
aa7133@att.com7c3e4c02020-03-25 16:37:19 +0200850// rmrMessageBuffer.rcvBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
851// rmrMessageBuffer.sendBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
852// }
ss412g1a79bdf2019-10-24 12:03:05 +0300853
854 while (true) {
855 if (mdclog_level_get() >= MDCLOG_DEBUG) {
ss412g4aeeda22020-06-16 14:12:41 +0300856 mdclog_write(MDCLOG_DEBUG, "Start EPOLL Wait. Timeout = %d", params->epollTimeOut);
ss412g1a79bdf2019-10-24 12:03:05 +0300857 }
dhirajverma6cf28612021-06-23 04:53:34 -0400858#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +0300859 auto numOfEvents = epoll_wait(params->epoll_fd, events, MAXEVENTS, params->epollTimeOut);
dhirajverma6cf28612021-06-23 04:53:34 -0400860#else
861 auto numOfEvents = 1;
862#endif
aa7133@att.comb92748d2020-06-29 11:52:30 +0300863 if (numOfEvents == 0) { // time out
Alexandre Hufffff97942023-03-31 21:22:20 -0300864#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comb92748d2020-06-29 11:52:30 +0300865 if (mdclog_level_get() >= MDCLOG_DEBUG) {
866 mdclog_write(MDCLOG_DEBUG, "got epoll timeout");
ss412g1a79bdf2019-10-24 12:03:05 +0300867 }
868 continue;
ss412g4aeeda22020-06-16 14:12:41 +0300869 } else if (numOfEvents < 0) {
870 if (errno == EINTR) {
871 if (mdclog_level_get() >= MDCLOG_DEBUG) {
872 mdclog_write(MDCLOG_DEBUG, "got EINTR : %s", strerror(errno));
873 }
874 continue;
875 }
ss412g1a79bdf2019-10-24 12:03:05 +0300876 mdclog_write(MDCLOG_ERR, "Epoll wait failed, errno = %s", strerror(errno));
dhirajvermab55bc172021-11-09 02:15:08 -0500877 if(events)
878 {
879 free(events);
sandeekuea662102022-11-08 18:51:20 +0530880 events = nullptr;
dhirajvermab55bc172021-11-09 02:15:08 -0500881 }
ss412g1a79bdf2019-10-24 12:03:05 +0300882 return;
Alexandre Hufffff97942023-03-31 21:22:20 -0300883#endif
ss412g1a79bdf2019-10-24 12:03:05 +0300884 }
885 for (auto i = 0; i < numOfEvents; i++) {
886 if (mdclog_level_get() >= MDCLOG_DEBUG) {
887 mdclog_write(MDCLOG_DEBUG, "handling epoll event %d out of %d", i + 1, numOfEvents);
888 }
889 clock_gettime(CLOCK_MONOTONIC, &message.message.time);
890 start.tv_sec = message.message.time.tv_sec;
891 start.tv_nsec = message.message.time.tv_nsec;
ss412g3bac2da2020-01-05 11:52:19 +0200892
893
ss412g1a79bdf2019-10-24 12:03:05 +0300894 if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP)) {
aa7133@att.combe92d712020-03-18 17:30:39 +0200895 handlepoll_error(events[i], message, rmrMessageBuffer, params);
ss412g1a79bdf2019-10-24 12:03:05 +0300896 } else if (events[i].events & EPOLLOUT) {
aa7133@att.combe92d712020-03-18 17:30:39 +0200897 handleEinprogressMessages(events[i], message, rmrMessageBuffer, params);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200898 } else if (params->listenFD == events[i].data.fd) {
aa7133@att.com6680c3b2020-03-22 12:06:58 +0200899 if (mdclog_level_get() >= MDCLOG_INFO) {
900 mdclog_write(MDCLOG_INFO, "New connection request from sctp network\n");
901 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200902 // new connection is requested from RAN start build connection
903 while (true) {
904 struct sockaddr in_addr {};
905 socklen_t in_len;
906 char hostBuff[NI_MAXHOST];
907 char portBuff[NI_MAXSERV];
908
909 in_len = sizeof(in_addr);
910 auto *peerInfo = (ConnectedCU_t *)calloc(1, sizeof(ConnectedCU_t));
aa7133@att.com409f2232020-10-29 13:06:45 +0300911 if(peerInfo == nullptr){
swc58d4f5d2020-10-20 15:08:38 +0900912 mdclog_write(MDCLOG_ERR, "calloc failed");
913 break;
914 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200915 peerInfo->sctpParams = params;
916 peerInfo->fileDescriptor = accept(params->listenFD, &in_addr, &in_len);
917 if (peerInfo->fileDescriptor == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -0300918#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +0200919 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
920 /* We have processed all incoming connections. */
dhirajverma9f59b572021-07-23 02:36:13 -0400921 if(peerInfo)
922 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530923 peerInfo = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200924 break;
925 } else {
dhirajverma9f59b572021-07-23 02:36:13 -0400926 if(peerInfo)
927 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530928 peerInfo = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200929 mdclog_write(MDCLOG_ERR, "Accept error, errno = %s", strerror(errno));
930 break;
931 }
932 }
933 if (setSocketNoBlocking(peerInfo->fileDescriptor) == -1) {
934 mdclog_write(MDCLOG_ERR, "setSocketNoBlocking failed to set new connection %s on port %s\n", hostBuff, portBuff);
935 close(peerInfo->fileDescriptor);
dhirajverma9f59b572021-07-23 02:36:13 -0400936 if(peerInfo)
937 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530938 peerInfo = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200939 break;
Alexandre Hufffff97942023-03-31 21:22:20 -0300940#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +0200941 }
czichy2175dd32022-05-17 15:24:51 +0300942 struct sctp_event_subscribe sctpevents;
943 memset( (void *)&sctpevents, 0, sizeof(sctpevents) );
944 sctpevents.sctp_data_io_event = 1;
945 setsockopt(peerInfo->fileDescriptor, SOL_SCTP, SCTP_EVENTS,(const void *)&sctpevents, sizeof(sctpevents) );
946
aa7133@att.com84bd3342020-03-16 18:04:57 +0200947 auto ans = getnameinfo(&in_addr, in_len,
aa7133@att.com96c9b882020-03-25 14:50:40 +0200948 peerInfo->hostName, NI_MAXHOST,
949 peerInfo->portNumber, NI_MAXSERV, (unsigned )((unsigned int)NI_NUMERICHOST | (unsigned int)NI_NUMERICSERV));
aa7133@att.com84bd3342020-03-16 18:04:57 +0200950 if (ans < 0) {
951 mdclog_write(MDCLOG_ERR, "Failed to get info on connection request. %s\n", strerror(errno));
952 close(peerInfo->fileDescriptor);
dhirajverma9f59b572021-07-23 02:36:13 -0400953 if(peerInfo)
954 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530955 peerInfo = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200956 break;
957 }
958 if (mdclog_level_get() >= MDCLOG_DEBUG) {
959 mdclog_write(MDCLOG_DEBUG, "Accepted connection on descriptor %d (host=%s, port=%s)\n", peerInfo->fileDescriptor, peerInfo->hostName, peerInfo->portNumber);
960 }
961 peerInfo->isConnected = false;
962 peerInfo->gotSetup = false;
963 if (addToEpoll(params->epoll_fd,
964 peerInfo,
965 (EPOLLIN | EPOLLET),
966 params->sctpMap, nullptr,
aa7133@att.combe92d712020-03-18 17:30:39 +0200967 0) != 0) {
dhirajverma9f59b572021-07-23 02:36:13 -0400968 if(peerInfo)
969 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530970 peerInfo = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200971 break;
972 }
aa7133@att.com6680c3b2020-03-22 12:06:58 +0200973 break;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200974 }
ss412g1a79bdf2019-10-24 12:03:05 +0300975 } else if (params->rmrListenFd == events[i].data.fd) {
976 // got message from XAPP
aa7133@att.comde40d1c2020-08-26 16:19:20 +0300977 //num_of_XAPP_messages.fetch_add(1, std::memory_order_release);
ss412g1a79bdf2019-10-24 12:03:05 +0300978 num_of_messages.fetch_add(1, std::memory_order_release);
979 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comf13529a2020-08-27 11:21:16 +0300980 mdclog_write(MDCLOG_DEBUG, "new RMR message");
ss412g1a79bdf2019-10-24 12:03:05 +0300981 }
aa7133@att.com6680c3b2020-03-22 12:06:58 +0200982 if (receiveXappMessages(params->sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +0300983 rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +0200984 message.message.time) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +0300985 mdclog_write(MDCLOG_ERR, "Error handling Xapp message");
986 }
ss412g3bac2da2020-01-05 11:52:19 +0200987 } else if (params->inotifyFD == events[i].data.fd) {
988 mdclog_write(MDCLOG_INFO, "Got event from inotify (configuration update)");
989 handleConfigChange(params);
ss412g1a79bdf2019-10-24 12:03:05 +0300990 } else {
991 /* We RMR_ERR_RETRY have data on the fd waiting to be read. Read and display it.
992 * We must read whatever data is available completely, as we are running
993 * in edge-triggered mode and won't get a notification again for the same data. */
994 num_of_messages.fetch_add(1, std::memory_order_release);
995 if (mdclog_level_get() >= MDCLOG_DEBUG) {
996 mdclog_write(MDCLOG_DEBUG, "new message from SCTP, epoll flags are : %0x", events[i].events);
997 }
998 receiveDataFromSctp(&events[i],
999 params->sctpMap,
1000 num_of_SCTP_messages,
1001 rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001002 message.message.time);
ss412g1a79bdf2019-10-24 12:03:05 +03001003 }
1004
1005 clock_gettime(CLOCK_MONOTONIC, &end);
1006 if (mdclog_level_get() >= MDCLOG_INFO) {
1007 totalTime += ((end.tv_sec + 1.0e-9 * end.tv_nsec) -
1008 ((double) start.tv_sec + 1.0e-9 * start.tv_nsec));
1009 }
1010 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1011 mdclog_write(MDCLOG_DEBUG, "message handling is %ld seconds %ld nanoseconds",
1012 end.tv_sec - start.tv_sec,
1013 end.tv_nsec - start.tv_nsec);
1014 }
1015 }
dhirajverma6cf28612021-06-23 04:53:34 -04001016#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04001017 break;
dhirajverma6cf28612021-06-23 04:53:34 -04001018#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001019 }
ss412g1a79bdf2019-10-24 12:03:05 +03001020}
1021
1022/**
1023 *
ss412g3bac2da2020-01-05 11:52:19 +02001024 * @param sctpParams
1025 */
1026void handleConfigChange(sctp_params_t *sctpParams) {
1027 char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event))));
1028 const struct inotify_event *event;
1029 char *ptr;
dhirajverma60f8bef2021-06-29 07:22:58 -04001030#ifdef UNIT_TEST
1031 struct inotify_event tmpEvent;
1032#endif
ss412g3bac2da2020-01-05 11:52:19 +02001033 path p = (sctpParams->configFilePath + "/" + sctpParams->configFileName).c_str();
1034 auto endlessLoop = true;
1035 while (endlessLoop) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001036#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
dhirajverma93b6d9c2021-07-10 00:49:13 -04001037 auto len = read(sctpParams->inotifyFD, buf, sizeof buf);
dhirajverma60f8bef2021-06-29 07:22:58 -04001038#else
1039 auto len=10;
1040#endif
ss412g3bac2da2020-01-05 11:52:19 +02001041 if (len == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001042#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001043 if (errno != EAGAIN) {
1044 mdclog_write(MDCLOG_ERR, "read %s ", strerror(errno));
1045 endlessLoop = false;
1046 continue;
1047 }
1048 else {
1049 endlessLoop = false;
1050 continue;
1051 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001052#endif
ss412g3bac2da2020-01-05 11:52:19 +02001053 }
1054
1055 for (ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + event->len) {
dhirajverma60f8bef2021-06-29 07:22:58 -04001056#ifndef UNIT_TEST
1057 event = (const struct inotify_event *)ptr;
1058#else
1059 tmpEvent.mask = (uint32_t)IN_CLOSE_WRITE;
1060 event = &tmpEvent;
1061#endif
ss412g3bac2da2020-01-05 11:52:19 +02001062 if (event->mask & (uint32_t)IN_ISDIR) {
1063 continue;
1064 }
1065
1066 // the directory name
1067 if (sctpParams->inotifyWD == event->wd) {
1068 // not the directory
1069 }
1070 if (event->len) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001071#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comdfc1db92020-03-31 17:32:04 +03001072 auto retVal = strcmp(sctpParams->configFileName.c_str(), event->name);
1073 if (retVal != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001074 continue;
1075 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001076#endif
ss412g3bac2da2020-01-05 11:52:19 +02001077 }
1078 // only the file we want
1079 if (event->mask & (uint32_t)IN_CLOSE_WRITE) {
aa7133@att.comdfc1db92020-03-31 17:32:04 +03001080 if (mdclog_level_get() >= MDCLOG_INFO) {
1081 mdclog_write(MDCLOG_INFO, "Configuration file changed");
1082 }
ss412g3bac2da2020-01-05 11:52:19 +02001083 if (exists(p)) {
1084 const int size = 2048;
1085 auto fileSize = file_size(p);
1086 if (fileSize > size) {
1087 mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size);
1088 return;
1089 }
1090 } else {
1091 mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str());
1092 return;
1093 }
1094
1095 ReadConfigFile conf;
1096 if (conf.openConfigFile(p.string()) == -1) {
1097 mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s",
1098 p.string().c_str(), strerror(errno));
1099 return;
1100 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001101 auto tmpStr = conf.getStringValue("trace");
ss412g3bac2da2020-01-05 11:52:19 +02001102 if (tmpStr.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +03001103 mdclog_write(MDCLOG_ERR, "illegal trace. Set trace to stop");
ss412g3bac2da2020-01-05 11:52:19 +02001104 tmpStr = "stop";
1105 }
1106
1107 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
1108 if ((tmpStr.compare("start")) == 0) {
1109 mdclog_write(MDCLOG_INFO, "Trace set to: start");
1110 sctpParams->trace = true;
1111 } else if ((tmpStr.compare("stop")) == 0) {
1112 mdclog_write(MDCLOG_INFO, "Trace set to: stop");
1113 sctpParams->trace = false;
1114 } else {
1115 mdclog_write(MDCLOG_ERR, "Trace was set to wrong value %s, set to stop", tmpStr.c_str());
1116 sctpParams->trace = false;
1117 }
1118 jsonTrace = sctpParams->trace;
ss412g4aeeda22020-06-16 14:12:41 +03001119
ss412g4aeeda22020-06-16 14:12:41 +03001120
ss412g3bac2da2020-01-05 11:52:19 +02001121 endlessLoop = false;
1122 }
dhirajverma60f8bef2021-06-29 07:22:58 -04001123#ifdef UNIT_TEST
1124 break;
1125#endif
ss412g3bac2da2020-01-05 11:52:19 +02001126 }
1127 }
1128}
1129
1130/**
1131 *
1132 * @param event
1133 * @param message
1134 * @param rmrMessageBuffer
1135 * @param params
ss412g3bac2da2020-01-05 11:52:19 +02001136 */
1137void handleEinprogressMessages(struct epoll_event &event,
1138 ReportingMessages_t &message,
1139 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001140 sctp_params_t *params) {
ss412g3bac2da2020-01-05 11:52:19 +02001141 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
1142 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1143
1144 mdclog_write(MDCLOG_INFO, "file descriptor %d got EPOLLOUT", peerInfo->fileDescriptor);
1145 auto retVal = 0;
1146 socklen_t retValLen = 0;
1147 auto rc = getsockopt(peerInfo->fileDescriptor, SOL_SOCKET, SO_ERROR, &retVal, &retValLen);
1148 if (rc != 0 || retVal != 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001149#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001150 if (rc != 0) {
1151 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1152 "%s|Failed SCTP Connection, after EINPROGRESS the getsockopt%s",
1153 peerInfo->enodbName, strerror(errno));
1154 } else if (retVal != 0) {
1155 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1156 "%s|Failed SCTP Connection after EINPROGRESS, SO_ERROR",
1157 peerInfo->enodbName);
1158 }
1159
1160 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1161 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
1162 mdclog_write(MDCLOG_ERR, "%s", rmrMessageBuffer.sendMessage->payload);
1163 message.message.direction = 'N';
aa7133@att.combe92d712020-03-18 17:30:39 +02001164 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001165 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1166 }
dhirajverma31768a92021-05-06 12:38:49 +05301167#endif
ss412g3bac2da2020-01-05 11:52:19 +02001168 memset(peerInfo->asnData, 0, peerInfo->asnLength);
1169 peerInfo->asnLength = 0;
1170 peerInfo->mtype = 0;
ss412g3bac2da2020-01-05 11:52:19 +02001171 return;
1172 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001173#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001174 peerInfo->isConnected = true;
1175
1176 if (modifyToEpoll(params->epoll_fd, peerInfo, (EPOLLIN | EPOLLET), params->sctpMap, peerInfo->enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02001177 peerInfo->mtype) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001178 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_MOD");
ss412g3bac2da2020-01-05 11:52:19 +02001179 return;
1180 }
1181
1182 message.message.asndata = (unsigned char *)peerInfo->asnData;
1183 message.message.asnLength = peerInfo->asnLength;
1184 message.message.messageType = peerInfo->mtype;
1185 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1186 num_of_messages.fetch_add(1, std::memory_order_release);
1187 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1188 mdclog_write(MDCLOG_DEBUG, "send the delayed SETUP/ENDC SETUP to sctp for %s",
1189 message.message.enodbName);
1190 }
aa7133@att.combe92d712020-03-18 17:30:39 +02001191 if (sendSctpMsg(peerInfo, message, params->sctpMap) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001192 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1193 mdclog_write(MDCLOG_DEBUG, "Error write to SCTP %s %d", __func__, __LINE__);
1194 }
ss412g3bac2da2020-01-05 11:52:19 +02001195 return;
1196 }
1197
1198 memset(peerInfo->asnData, 0, peerInfo->asnLength);
1199 peerInfo->asnLength = 0;
1200 peerInfo->mtype = 0;
Alexandre Hufffff97942023-03-31 21:22:20 -03001201#endif
ss412g3bac2da2020-01-05 11:52:19 +02001202}
1203
1204
1205void handlepoll_error(struct epoll_event &event,
1206 ReportingMessages_t &message,
1207 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001208 sctp_params_t *params) {
sandeekuea662102022-11-08 18:51:20 +05301209 if ((event.data.fd != params->rmrListenFd) && (event.data.ptr != nullptr)) {
ss412g3bac2da2020-01-05 11:52:19 +02001210 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
1211 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on fd %d, RAN NAME : %s",
1212 event.events, peerInfo->fileDescriptor, peerInfo->enodbName);
dhirajverma93b6d9c2021-07-10 00:49:13 -04001213#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001214 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1215 "%s|Failed SCTP Connection",
1216 peerInfo->enodbName);
1217 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1218 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
1219
1220 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1221 message.message.direction = 'N';
aa7133@att.combe92d712020-03-18 17:30:39 +02001222 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001223 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1224 }
dhirajverma31768a92021-05-06 12:38:49 +05301225#endif
ss412g3bac2da2020-01-05 11:52:19 +02001226 close(peerInfo->fileDescriptor);
sandeekuea662102022-11-08 18:51:20 +05301227 //params->sctpMap->erase(peerInfo->enodbName);
aa7133@att.combe92d712020-03-18 17:30:39 +02001228 cleanHashEntry((ConnectedCU_t *) event.data.ptr, params->sctpMap);
ss412g3bac2da2020-01-05 11:52:19 +02001229 } else {
1230 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on RMR FD", event.events);
1231 }
ss412g3bac2da2020-01-05 11:52:19 +02001232}
1233/**
1234 *
ss412g1a79bdf2019-10-24 12:03:05 +03001235 * @param socket
1236 * @return
1237 */
1238int setSocketNoBlocking(int socket) {
1239 auto flags = fcntl(socket, F_GETFL, 0);
1240
1241 if (flags == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +03001242 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03001243 return -1;
1244 }
1245
1246 flags = (unsigned) flags | (unsigned) O_NONBLOCK;
1247 if (fcntl(socket, F_SETFL, flags) == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +03001248 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03001249 return -1;
1250 }
1251
1252 return 0;
1253}
1254
1255/**
1256 *
1257 * @param val
1258 * @param m
ss412g1a79bdf2019-10-24 12:03:05 +03001259 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001260void cleanHashEntry(ConnectedCU_t *val, Sctp_Map_t *m) {
sandeekuea662102022-11-08 18:51:20 +05301261 if(val != nullptr)
1262 {
ss412g1a79bdf2019-10-24 12:03:05 +03001263 char *dummy;
1264 auto port = (uint16_t) strtol(val->portNumber, &dummy, 10);
aa7133@att.com84bd3342020-03-16 18:04:57 +02001265 char searchBuff[2048]{};
ss412g1a79bdf2019-10-24 12:03:05 +03001266
1267 snprintf(searchBuff, sizeof searchBuff, "host:%s:%d", val->hostName, port);
sandeekuea662102022-11-08 18:51:20 +05301268 if(m->find(searchBuff))
1269 {
ss412g1a79bdf2019-10-24 12:03:05 +03001270 m->erase(searchBuff);
sandeekuea662102022-11-08 18:51:20 +05301271 }
ss412g1a79bdf2019-10-24 12:03:05 +03001272
sandeekuea662102022-11-08 18:51:20 +05301273 if(m->find(val->enodbName))
1274 {
1275 mdclog_write(MDCLOG_DEBUG, "remove key enodbName = %s from %s at line %d", val->enodbName, __FUNCTION__, __LINE__);
ss412g1a79bdf2019-10-24 12:03:05 +03001276 m->erase(val->enodbName);
sandeekuea662102022-11-08 18:51:20 +05301277 }
dhirajverma31768a92021-05-06 12:38:49 +05301278#ifndef UNIT_TEST
sandeekuea662102022-11-08 18:51:20 +05301279 if(val) {
1280 free(val);
1281 val = nullptr;
1282 }
dhirajverma31768a92021-05-06 12:38:49 +05301283#endif
sandeekuea662102022-11-08 18:51:20 +05301284 }
ss412g1a79bdf2019-10-24 12:03:05 +03001285}
1286
1287/**
1288 *
aa7133@att.com409f2232020-10-29 13:06:45 +03001289 * @param fd file descriptor
ss412g1a79bdf2019-10-24 12:03:05 +03001290 * @param data the asn data to send
1291 * @param len length of the data
1292 * @param enodbName the enodbName as in the map for printing purpose
1293 * @param m map host information
1294 * @param mtype message number
aa7133@att.com409f2232020-10-29 13:06:45 +03001295 * @return 0 success, a negative number on fail
ss412g1a79bdf2019-10-24 12:03:05 +03001296 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001297int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_t *m) {
ss412g1a79bdf2019-10-24 12:03:05 +03001298 auto loglevel = mdclog_level_get();
Alexandre Hufffff97942023-03-31 21:22:20 -03001299#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001300 int fd = peerInfo->fileDescriptor;
czichy2175dd32022-05-17 15:24:51 +03001301 int streamId = fetchStreamId(peerInfo,message);
dhirajverma99990292021-07-05 10:03:59 -04001302#else
1303 int fd = FILE_DESCRIPTOR;
czichy2175dd32022-05-17 15:24:51 +03001304 int streamId = 0;
Alexandre Hufffff97942023-03-31 21:22:20 -03001305#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001306 if (loglevel >= MDCLOG_DEBUG) {
1307 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for CU %s, %s",
1308 message.message.enodbName, __FUNCTION__);
1309 }
1310
1311 while (true) {
czichy6dd00bc2023-03-03 15:43:29 +02001312 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 +03001313 if (errno == EINTR) {
1314 continue;
1315 }
1316 mdclog_write(MDCLOG_ERR, "error writing to CU a message, %s ", strerror(errno));
Alexandre Hufffff97942023-03-31 21:22:20 -03001317#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +02001318 if (!peerInfo->isConnected) {
1319 mdclog_write(MDCLOG_ERR, "connection to CU %s is still in progress.", message.message.enodbName);
aa7133@att.com84bd3342020-03-16 18:04:57 +02001320 return -1;
1321 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001322#endif
Alexandre Hufffff97942023-03-31 21:22:20 -03001323#ifndef UNIT_TEST
aa7133@att.combe92d712020-03-18 17:30:39 +02001324 cleanHashEntry(peerInfo, m);
dhirajvermac40ea1f2021-07-08 12:52:30 -04001325 close(fd);
Alexandre Hufffff97942023-03-31 21:22:20 -03001326#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001327 char key[MAX_ENODB_NAME_SIZE * 2];
1328 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName,
1329 message.message.messageType);
1330 if (loglevel >= MDCLOG_DEBUG) {
1331 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
1332 }
aa7133@att.com96c9b882020-03-25 14:50:40 +02001333 auto tmp = m->find(key);
ss412g1a79bdf2019-10-24 12:03:05 +03001334 if (tmp) {
1335 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05301336 tmp = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03001337 }
1338 m->erase(key);
dhirajverma6cf28612021-06-23 04:53:34 -04001339#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001340 return -1;
dhirajverma6cf28612021-06-23 04:53:34 -04001341#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001342 }
1343 message.message.direction = 'D';
1344 // send report.buffer of size
1345 buildJsonMessage(message);
1346
1347 if (loglevel >= MDCLOG_DEBUG) {
1348 mdclog_write(MDCLOG_DEBUG,
1349 "SCTP message for CU %s sent from %s",
1350 message.message.enodbName,
1351 __FUNCTION__);
1352 }
ss412g1a79bdf2019-10-24 12:03:05 +03001353 return 0;
1354 }
1355}
1356
1357/**
1358 *
1359 * @param message
1360 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03001361 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001362void getRequestMetaData(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03001363 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
1364 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
1365
1366 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1367 mdclog_write(MDCLOG_DEBUG, "Message from Xapp RAN name = %s message length = %ld",
1368 message.message.enodbName, (unsigned long) message.message.asnLength);
1369 }
ss412g1a79bdf2019-10-24 12:03:05 +03001370}
1371
1372
ss412g1a79bdf2019-10-24 12:03:05 +03001373
1374/**
1375 *
1376 * @param events
1377 * @param sctpMap
1378 * @param numOfMessages
1379 * @param rmrMessageBuffer
1380 * @param ts
ss412g1a79bdf2019-10-24 12:03:05 +03001381 * @return
1382 */
1383int receiveDataFromSctp(struct epoll_event *events,
1384 Sctp_Map_t *sctpMap,
1385 int &numOfMessages,
1386 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001387 struct timespec &ts) {
ss412g1a79bdf2019-10-24 12:03:05 +03001388 /* We have data on the fd waiting to be read. Read and display it.
1389 * We must read whatever data is available completely, as we are running
1390 * in edge-triggered mode and won't get a notification again for the same data. */
aa7133@att.com84bd3342020-03-16 18:04:57 +02001391 ReportingMessages_t message {};
1392 auto done = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03001393 auto loglevel = mdclog_level_get();
czichy2175dd32022-05-17 15:24:51 +03001394 struct sctp_sndrcvinfo sndrcvinfo;
1395 int flags;
1396 int streamId;
aa7133@att.com84bd3342020-03-16 18:04:57 +02001397
ss412g1a79bdf2019-10-24 12:03:05 +03001398 // get the identity of the interface
sandeekuea662102022-11-08 18:51:20 +05301399 if (events->data.ptr != nullptr){
aa7133@att.com84bd3342020-03-16 18:04:57 +02001400 message.peerInfo = (ConnectedCU_t *)events->data.ptr;
sandeekuea662102022-11-08 18:51:20 +05301401 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001402
ss412g1a79bdf2019-10-24 12:03:05 +03001403 struct timespec start{0, 0};
aa7133@att.com409f2232020-10-29 13:06:45 +03001404 struct timespec decodeStart{0, 0};
ss412g1a79bdf2019-10-24 12:03:05 +03001405 struct timespec end{0, 0};
1406
1407 E2AP_PDU_t *pdu = nullptr;
1408
ss412g1a79bdf2019-10-24 12:03:05 +03001409 while (true) {
1410 if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001411 mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP %d fd", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001412 clock_gettime(CLOCK_MONOTONIC, &start);
1413 }
1414 // read the buffer directly to rmr payload
1415 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
Alexandre Hufffff97942023-03-31 21:22:20 -03001416#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001417 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
czichy2175dd32022-05-17 15:24:51 +03001418 sctp_recvmsg(message.peerInfo->fileDescriptor, rmrMessageBuffer.sendMessage->payload, RECEIVE_SCTP_BUFFER_SIZE,(struct sockaddr *) NULL, 0, &sndrcvinfo, &flags);
1419 mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP fd %d stream %d ", message.peerInfo->fileDescriptor, sndrcvinfo.sinfo_stream);
1420 streamId = sndrcvinfo.sinfo_stream;
dhirajverma99990292021-07-05 10:03:59 -04001421#else
1422 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
czichy2175dd32022-05-17 15:24:51 +03001423 streamId = 0;
dhirajverma99990292021-07-05 10:03:59 -04001424#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +02001425
ss412g1a79bdf2019-10-24 12:03:05 +03001426 if (loglevel >= MDCLOG_DEBUG) {
1427 mdclog_write(MDCLOG_DEBUG, "Finish Read from SCTP %d fd message length = %ld",
aa7133@att.com96c9b882020-03-25 14:50:40 +02001428 message.peerInfo->fileDescriptor, message.message.asnLength);
ss412g1a79bdf2019-10-24 12:03:05 +03001429 }
aa7133@att.com16c799b2020-03-24 18:01:51 +02001430
aa7133@att.com84bd3342020-03-16 18:04:57 +02001431 memcpy(message.message.enodbName, message.peerInfo->enodbName, sizeof(message.peerInfo->enodbName));
ss412g1a79bdf2019-10-24 12:03:05 +03001432 message.message.direction = 'U';
1433 message.message.time.tv_nsec = ts.tv_nsec;
1434 message.message.time.tv_sec = ts.tv_sec;
1435
1436 if (message.message.asnLength < 0) {
1437 if (errno == EINTR) {
1438 continue;
1439 }
1440 /* If errno == EAGAIN, that means we have read all
aa7133@att.com84bd3342020-03-16 18:04:57 +02001441 data. So goReportingMessages_t back to the main loop. */
ss412g1a79bdf2019-10-24 12:03:05 +03001442 if (errno != EAGAIN) {
1443 mdclog_write(MDCLOG_ERR, "Read error, %s ", strerror(errno));
1444 done = 1;
1445 } else if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001446 mdclog_write(MDCLOG_DEBUG, "EAGAIN - descriptor = %d", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001447 }
1448 break;
1449 } else if (message.message.asnLength == 0) {
1450 /* End of file. The remote has closed the connection. */
1451 if (loglevel >= MDCLOG_INFO) {
1452 mdclog_write(MDCLOG_INFO, "END of File Closed connection - descriptor = %d",
aa7133@att.com84bd3342020-03-16 18:04:57 +02001453 message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001454 }
1455 done = 1;
1456 break;
1457 }
1458
ss412g1a79bdf2019-10-24 12:03:05 +03001459 if (loglevel >= MDCLOG_DEBUG) {
swc58d4f5d2020-10-20 15:08:38 +09001460 char printBuffer[RECEIVE_SCTP_BUFFER_SIZE]{};
ss412g1a79bdf2019-10-24 12:03:05 +03001461 char *tmp = printBuffer;
1462 for (size_t i = 0; i < (size_t)message.message.asnLength; ++i) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001463 snprintf(tmp, 3, "%02x", message.message.asndata[i]);
ss412g1a79bdf2019-10-24 12:03:05 +03001464 tmp += 2;
1465 }
1466 printBuffer[message.message.asnLength] = 0;
1467 clock_gettime(CLOCK_MONOTONIC, &end);
1468 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 +02001469 message.peerInfo->enodbName, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001470 mdclog_write(MDCLOG_DEBUG, "PDU buffer length = %ld, data = : %s", message.message.asnLength,
1471 printBuffer);
aa7133@att.com409f2232020-10-29 13:06:45 +03001472 clock_gettime(CLOCK_MONOTONIC, &decodeStart);
ss412g1a79bdf2019-10-24 12:03:05 +03001473 }
dhirajverma99990292021-07-05 10:03:59 -04001474#ifndef UNIT_TEST
aa7133@att.com7b437f72020-03-30 13:25:54 +03001475 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu,
dhirajverma99990292021-07-05 10:03:59 -04001476 message.message.asndata, message.message.asnLength);
1477#else
1478 asn_dec_rval_t rval = {RC_OK, 0};
1479 pdu = (E2AP_PDU_t*)rmrMessageBuffer.sendMessage->tp_buf;
1480#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001481 if (rval.code != RC_OK) {
1482 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from RAN : %s", rval.code,
aa7133@att.com84bd3342020-03-16 18:04:57 +02001483 message.peerInfo->enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04001484 if (pdu != nullptr) {
1485 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1486 pdu = nullptr;
1487 }
ss412g1a79bdf2019-10-24 12:03:05 +03001488 break;
1489 }
1490
1491 if (loglevel >= MDCLOG_DEBUG) {
1492 clock_gettime(CLOCK_MONOTONIC, &end);
1493 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 +03001494 message.peerInfo->enodbName, end.tv_sec - decodeStart.tv_sec, end.tv_nsec - decodeStart.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001495 char *printBuffer;
1496 size_t size;
1497 FILE *stream = open_memstream(&printBuffer, &size);
1498 asn_fprint(stream, &asn_DEF_E2AP_PDU, pdu);
1499 mdclog_write(MDCLOG_DEBUG, "Encoding E2AP PDU past : %s", printBuffer);
aa7133@att.com409f2232020-10-29 13:06:45 +03001500 clock_gettime(CLOCK_MONOTONIC, &decodeStart);
Byonggon Chuncae9bd52020-11-18 13:37:29 +09001501
1502 fclose(stream);
1503 free(printBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001504 }
1505
1506 switch (pdu->present) {
1507 case E2AP_PDU_PR_initiatingMessage: {//initiating message
czichy2175dd32022-05-17 15:24:51 +03001508 asnInitiatingRequest(pdu, sctpMap,message, rmrMessageBuffer, streamId);
ss412g1a79bdf2019-10-24 12:03:05 +03001509 break;
1510 }
1511 case E2AP_PDU_PR_successfulOutcome: { //successful outcome
aa7133@att.com409f2232020-10-29 13:06:45 +03001512 asnSuccessfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001513 break;
1514 }
1515 case E2AP_PDU_PR_unsuccessfulOutcome: { //Unsuccessful Outcome
aa7133@att.com7b437f72020-03-30 13:25:54 +03001516 asnUnSuccsesfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001517 break;
1518 }
1519 default:
1520 mdclog_write(MDCLOG_ERR, "Unknown index %d in E2AP PDU", pdu->present);
1521 break;
1522 }
1523 if (loglevel >= MDCLOG_DEBUG) {
1524 clock_gettime(CLOCK_MONOTONIC, &end);
1525 mdclog_write(MDCLOG_DEBUG,
1526 "After processing message and sent to rmr for : %s, Read time is : %ld seconds, %ld nanoseconds",
aa7133@att.com409f2232020-10-29 13:06:45 +03001527 message.peerInfo->enodbName, end.tv_sec - decodeStart.tv_sec, end.tv_nsec - decodeStart.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001528 }
1529 numOfMessages++;
dhirajverma9f59b572021-07-23 02:36:13 -04001530#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001531 if (pdu != nullptr) {
dhirajverma9f59b572021-07-23 02:36:13 -04001532 // ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); /* With reset we were not freeing the memory and was causing the leak here. */
1533 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1534 pdu = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03001535 }
dhirajverma9f59b572021-07-23 02:36:13 -04001536#else
dhirajverma99990292021-07-05 10:03:59 -04001537 done = 1;
1538 break;
1539#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001540 }
ss412g1a79bdf2019-10-24 12:03:05 +03001541
1542 if (done) {
1543 if (loglevel >= MDCLOG_INFO) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001544 mdclog_write(MDCLOG_INFO, "Closed connection - descriptor = %d", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001545 }
1546 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
1547 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
aa7133@att.com96c9b882020-03-25 14:50:40 +02001548 256,
1549 "%s|CU disconnected unexpectedly",
1550 message.peerInfo->enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03001551 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
Alexandre Hufffff97942023-03-31 21:22:20 -03001552#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03001553 if (sendRequestToXapp(message,
1554 RIC_SCTP_CONNECTION_FAILURE,
aa7133@att.combe92d712020-03-18 17:30:39 +02001555 rmrMessageBuffer) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03001556 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1557 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001558#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001559
1560 /* Closing descriptor make epoll remove it from the set of descriptors which are monitored. */
sandeekuea662102022-11-08 18:51:20 +05301561#ifndef UNIT_TEST
1562 pthread_mutex_lock(&thread_lock);
1563 if (fcntl(message.peerInfo->fileDescriptor, F_GETFD) != -1) {
1564 mdclog_write(MDCLOG_DEBUG, "Closing connection - descriptor = %d", message.peerInfo->fileDescriptor);
1565 close(message.peerInfo->fileDescriptor);
1566 cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap);
1567 }
1568 pthread_mutex_unlock(&thread_lock);
1569#else
aa7133@att.com84bd3342020-03-16 18:04:57 +02001570 close(message.peerInfo->fileDescriptor);
aa7133@att.combe92d712020-03-18 17:30:39 +02001571 cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap);
Alexandre Hufffff97942023-03-31 21:22:20 -03001572#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001573 }
1574 if (loglevel >= MDCLOG_DEBUG) {
1575 clock_gettime(CLOCK_MONOTONIC, &end);
1576 mdclog_write(MDCLOG_DEBUG, "from receive SCTP to send RMR time is %ld seconds and %ld nanoseconds",
1577 end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
1578
1579 }
ss412g1a79bdf2019-10-24 12:03:05 +03001580 return 0;
1581}
1582
aa7133@att.com409f2232020-10-29 13:06:45 +03001583static void buildAndSendSetupRequest(ReportingMessages_t &message,
aa7133@att.com84bd3342020-03-16 18:04:57 +02001584 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001585 E2AP_PDU_t *pdu/*,
ss412g4aeeda22020-06-16 14:12:41 +03001586 string const &messageName,
1587 string const &ieName,
1588 vector<string> &functionsToAdd_v,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001589 vector<string> &functionsToModified_v*/) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001590 auto logLevel = mdclog_level_get();
aa7133@att.com84bd3342020-03-16 18:04:57 +02001591 // now we can send the data to e2Mgr
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001592
ss412g4aeeda22020-06-16 14:12:41 +03001593 asn_enc_rval_t er;
1594 auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
Byonggon Chun51885f32020-11-18 15:31:04 +09001595 unsigned char *buffer = nullptr;
1596 buffer = (unsigned char *) calloc(buffer_size, sizeof(unsigned char));
1597 if(!buffer)
1598 {
Alexandre Hufffff97942023-03-31 21:22:20 -03001599#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
Byonggon Chun51885f32020-11-18 15:31:04 +09001600 mdclog_write(MDCLOG_ERR, "Allocating buffer for %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1601 return;
Alexandre Hufffff97942023-03-31 21:22:20 -03001602#endif
Byonggon Chun51885f32020-11-18 15:31:04 +09001603 }
ss412g4aeeda22020-06-16 14:12:41 +03001604 while (true) {
ss412g4aeeda22020-06-16 14:12:41 +03001605 er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size);
1606 if (er.encoded == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001607#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g4aeeda22020-06-16 14:12:41 +03001608 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1609 return;
Alexandre Hufffff97942023-03-31 21:22:20 -03001610#endif
ss412g4aeeda22020-06-16 14:12:41 +03001611 } else if (er.encoded > (ssize_t) buffer_size) {
1612 buffer_size = er.encoded + 128;
Alexandre Hufffff97942023-03-31 21:22:20 -03001613#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g4aeeda22020-06-16 14:12:41 +03001614 mdclog_write(MDCLOG_WARN, "Buffer of size %d is to small for %s. Reallocate buffer of size %d",
1615 (int) buffer_size,
1616 asn_DEF_E2AP_PDU.name, buffer_size);
1617 buffer_size = er.encoded + 128;
Byonggon Chun51885f32020-11-18 15:31:04 +09001618
1619 unsigned char *newBuffer = nullptr;
1620 newBuffer = (unsigned char *) realloc(buffer, buffer_size);
1621 if (!newBuffer)
1622 {
1623 // out of memory
1624 mdclog_write(MDCLOG_ERR, "Reallocating buffer for %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1625 free(buffer);
sandeekuea662102022-11-08 18:51:20 +05301626 buffer = nullptr;
Byonggon Chun51885f32020-11-18 15:31:04 +09001627 return;
1628 }
1629 buffer = newBuffer;
ss412g4aeeda22020-06-16 14:12:41 +03001630 continue;
Alexandre Hufffff97942023-03-31 21:22:20 -03001631#endif
ss412g4aeeda22020-06-16 14:12:41 +03001632 }
1633 buffer[er.encoded] = '\0';
1634 break;
1635 }
1636 // encode to xml
1637
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001638 string res((char *)buffer);
1639 res.erase(std::remove(res.begin(), res.end(), '\n'), res.end());
1640 res.erase(std::remove(res.begin(), res.end(), '\t'), res.end());
1641 res.erase(std::remove(res.begin(), res.end(), ' '), res.end());
1642
1643// string res {};
1644// if (!functionsToAdd_v.empty() || !functionsToModified_v.empty()) {
1645// res = buildXmlData(messageName, ieName, functionsToAdd_v, functionsToModified_v, buffer, (size_t) er.encoded);
1646// }
ss412g4aeeda22020-06-16 14:12:41 +03001647 rmr_mbuf_t *rmrMsg;
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001648// if (res.length() == 0) {
1649// rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size + 256);
1650// rmrMsg->len = snprintf((char *) rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s",
1651// message.peerInfo->sctpParams->myIP.c_str(),
1652// message.peerInfo->sctpParams->rmrPort,
1653// buffer);
1654// } else {
ss412g4aeeda22020-06-16 14:12:41 +03001655 rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, (int)res.length() + 256);
1656 rmrMsg->len = snprintf((char *) rmrMsg->payload, res.length() + 256, "%s:%d|%s",
1657 message.peerInfo->sctpParams->myIP.c_str(),
1658 message.peerInfo->sctpParams->rmrPort,
1659 res.c_str());
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001660// }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001661
ss412g4aeeda22020-06-16 14:12:41 +03001662 if (logLevel >= MDCLOG_DEBUG) {
1663 mdclog_write(MDCLOG_DEBUG, "Setup request of size %d :\n %s\n", rmrMsg->len, rmrMsg->payload);
1664 }
1665 // send to RMR
1666 rmrMsg->mtype = message.message.messageType;
1667 rmrMsg->state = 0;
1668 rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName));
aa7133@att.com84bd3342020-03-16 18:04:57 +02001669
ss412g4aeeda22020-06-16 14:12:41 +03001670 static unsigned char tx[32];
1671 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1672 rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx));
dhirajverma60f8bef2021-06-29 07:22:58 -04001673#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +03001674 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
dhirajverma60f8bef2021-06-29 07:22:58 -04001675#endif
ss412g4aeeda22020-06-16 14:12:41 +03001676 if (rmrMsg == nullptr) {
1677 mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr");
1678 } else if (rmrMsg->state != 0) {
1679 char meid[RMR_MAX_MEID]{};
1680 if (rmrMsg->state == RMR_ERR_RETRY) {
1681 usleep(5);
1682 rmrMsg->state = 0;
1683 mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s",
1684 rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid));
dhirajverma60f8bef2021-06-29 07:22:58 -04001685#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +03001686 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
dhirajverma60f8bef2021-06-29 07:22:58 -04001687#endif
ss412g4aeeda22020-06-16 14:12:41 +03001688 if (rmrMsg == nullptr) {
1689 mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr");
1690 } else if (rmrMsg->state != 0) {
1691 mdclog_write(MDCLOG_ERR,
1692 "RMR Retry failed %s sending request %d to Xapp from %s",
aa7133@att.com84bd3342020-03-16 18:04:57 +02001693 translateRmrErrorMessages(rmrMsg->state).c_str(),
1694 rmrMsg->mtype,
1695 rmr_get_meid(rmrMsg, (unsigned char *) meid));
1696 }
ss412g4aeeda22020-06-16 14:12:41 +03001697 } else {
1698 mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s",
1699 translateRmrErrorMessages(rmrMsg->state).c_str(),
1700 rmrMsg->mtype,
1701 rmr_get_meid(rmrMsg, (unsigned char *) meid));
aa7133@att.combc110772020-03-25 09:45:14 +02001702 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001703 }
ss412g4aeeda22020-06-16 14:12:41 +03001704 message.peerInfo->gotSetup = true;
1705 buildJsonMessage(message);
Byonggon Chun51885f32020-11-18 15:31:04 +09001706
ss412g4aeeda22020-06-16 14:12:41 +03001707 if (rmrMsg != nullptr) {
1708 rmr_free_msg(rmrMsg);
1709 }
Byonggon Chun51885f32020-11-18 15:31:04 +09001710 free(buffer);
sandeekuea662102022-11-08 18:51:20 +05301711 buffer = nullptr;
Byonggon Chun51885f32020-11-18 15:31:04 +09001712
1713 return;
aa7133@att.com84bd3342020-03-16 18:04:57 +02001714}
aa7133@att.comc5a15202020-04-05 19:57:01 +03001715
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001716#if 0
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001717int RAN_Function_list_To_Vector(RANfunctions_List_t& list, vector <string> &runFunXML_v) {
1718 auto index = 0;
1719 runFunXML_v.clear();
1720 for (auto j = 0; j < list.list.count; j++) {
1721 auto *raNfunctionItemIEs = (RANfunction_ItemIEs_t *)list.list.array[j];
1722 if (raNfunctionItemIEs->id == ProtocolIE_ID_id_RANfunction_Item &&
1723 (raNfunctionItemIEs->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item)) {
1724 // encode to xml
1725 E2SM_gNB_NRT_RANfunction_Definition_t *ranFunDef = nullptr;
1726 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER,
1727 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1728 (void **)&ranFunDef,
1729 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.buf,
1730 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.size);
1731 if (rval.code != RC_OK) {
1732 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2SM message from : %s",
1733 rval.code,
1734 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name);
1735 return -1;
1736 }
1737
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001738 auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1739 unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
ss412g4aeeda22020-06-16 14:12:41 +03001740 memset(xml_buffer, 0, RECEIVE_SCTP_BUFFER_SIZE * 2);
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001741 // encode to xml
1742 auto er = asn_encode_to_buffer(nullptr,
1743 ATS_BASIC_XER,
1744 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1745 ranFunDef,
1746 xml_buffer,
1747 xml_buffer_size);
1748 if (er.encoded == -1) {
1749 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s",
1750 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1751 strerror(errno));
1752 } else if (er.encoded > (ssize_t)xml_buffer_size) {
1753 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
1754 (int) xml_buffer_size,
1755 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, __func__, __LINE__);
1756 } else {
1757 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1758 mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU number %d : %s",
1759 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1760 index++,
1761 xml_buffer);
1762 }
ss412g4aeeda22020-06-16 14:12:41 +03001763
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001764 string runFuncs = (char *)(xml_buffer);
1765 runFunXML_v.emplace_back(runFuncs);
1766 }
1767 }
1768 }
1769 return 0;
1770}
aa7133@att.comc5a15202020-04-05 19:57:01 +03001771
ss412g4aeeda22020-06-16 14:12:41 +03001772int collectServiceUpdate_RequestData(E2AP_PDU_t *pdu,
1773 Sctp_Map_t *sctpMap,
1774 ReportingMessages_t &message,
1775 vector <string> &RANfunctionsAdded_v,
1776 vector <string> &RANfunctionsModified_v) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03001777 memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE);
ss412g4aeeda22020-06-16 14:12:41 +03001778 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.count; i++) {
1779 auto *ie = pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.array[i];
1780 if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
1781 if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctionsID_List) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03001782 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001783 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
1784 ie->value.choice.RANfunctions_List.list.count);
aa7133@att.comc5a15202020-04-05 19:57:01 +03001785 }
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001786 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) {
1787 return -1;
1788 }
1789 }
1790 } else if (ie->id == ProtocolIE_ID_id_RANfunctionsModified) {
ss412g4aeeda22020-06-16 14:12:41 +03001791 if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List) {
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001792 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1793 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
1794 ie->value.choice.RANfunctions_List.list.count);
1795 }
1796 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsModified_v) != 0 ) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001797 return -1;
aa7133@att.comc5a15202020-04-05 19:57:01 +03001798 }
1799 }
1800 }
1801 }
1802 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1803 mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries",
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001804 RANfunctionsAdded_v.size());
aa7133@att.comc5a15202020-04-05 19:57:01 +03001805 }
1806 return 0;
1807}
ss412g4aeeda22020-06-16 14:12:41 +03001808
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001809#endif
ss412g4aeeda22020-06-16 14:12:41 +03001810
1811
Mohamed Abukar64f37242021-08-15 12:39:56 +00001812void buildE2TPrometheusCounters(sctp_params_t &sctpParams) {
1813 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestMsgs"}});
1814 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestBytes"}});
1815
1816 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupResponseMsgs"}});
1817 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupResponseBytes"}});
1818
1819 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestFailureMsgs"}});
1820 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestFailureBytes"}});
1821
czichy2175dd32022-05-17 15:24:51 +03001822 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateMsgs"}});
1823 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateBytes"}});
1824
1825 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateResponseMsgs"}});
1826 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateResponseBytes"}});
1827
1828 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateFailureMsgs"}});
1829 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateFailureBytes"}});
1830
Mohamed Abukar64f37242021-08-15 12:39:56 +00001831 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &sctpParams.prometheusFamily->Add({{"counter", "ErrorIndicationMsgs"}});
1832 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &sctpParams.prometheusFamily->Add({{"counter", "ErrorIndicationBytes"}});
1833
1834 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetRequestMsgs"}});
1835 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetRequestBytes"}});
1836
1837 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetAckMsgs"}});
1838 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetAckBytes"}});
1839
1840 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateMsgs"}});
1841 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateBytes"}});
1842
1843 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateRespMsgs"}});
1844 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateRespBytes"}});
1845
1846 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateFailureMsgs"}});
1847 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateFailureBytes"}});
1848
1849 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlMsgs"}});
1850 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlBytes"}});
1851
1852 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlAckMsgs"}});
1853 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlAckBytes"}});
1854
1855 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlFailureMsgs"}});
1856 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlFailureBytes"}});
1857
1858 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionMsgs"}});
1859 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionBytes"}});
1860
1861 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionAckMsgs"}});
1862 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionAckBytes"}});
1863
1864 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionFailureMsgs"}});
1865 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionFailureBytes"}});
1866
1867 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteMsgs"}});
1868 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteBytes"}});
1869
1870 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteAckMsgs"}});
1871 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteAckBytes"}});
1872
1873 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteFailMsgs"}});
1874 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteFailBytes"}});
1875
1876 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication] = &sctpParams.prometheusFamily->Add({{"counter", "RICIndicationMsgs"}});
1877 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication] = &sctpParams.prometheusFamily->Add({{"counter", "RICIndicationBytes"}});
1878
1879 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceQueryMsgs"}});
1880 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceQueryBytes"}});
gunjarastogi85f507f2023-01-18 16:27:55 +05301881
1882 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteRequiredMsgs"}});
1883 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteRequiredBytes"}});
1884
Mohamed Abukar64f37242021-08-15 12:39:56 +00001885}
1886
aa7133@att.com409f2232020-10-29 13:06:45 +03001887void buildPrometheusList(ConnectedCU_t *peerInfo, Family<Counter> *prometheusFamily) {
aa7133@att.coma4c80012020-06-24 16:36:47 +03001888 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Messages"}});
1889 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001890
czichy2175dd32022-05-17 15:24:51 +03001891 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"E2NodeConfigUpdate", "Messages"}});
1892 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"E2NodeConfigUpdate", "Bytes"}});
1893
aa7133@att.coma4c80012020-06-24 16:36:47 +03001894 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Messages"}});
1895 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001896
aa7133@att.coma4c80012020-06-24 16:36:47 +03001897 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICindication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Messages"}});
1898 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICindication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001899
aa7133@att.coma4c80012020-06-24 16:36:47 +03001900 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Messages"}});
1901 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001902
aa7133@att.coma4c80012020-06-24 16:36:47 +03001903 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Messages"}});
1904 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001905 // ---------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03001906 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Messages"}});
1907 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001908
aa7133@att.coma4c80012020-06-24 16:36:47 +03001909 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Messages"}});
1910 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001911
aa7133@att.coma4c80012020-06-24 16:36:47 +03001912 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Messages"}});
1913 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001914
aa7133@att.coma4c80012020-06-24 16:36:47 +03001915 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Messages"}});
1916 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001917 //-------------------------------------------------------------
1918
aa7133@att.coma4c80012020-06-24 16:36:47 +03001919 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Messages"}});
1920 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001921
aa7133@att.coma4c80012020-06-24 16:36:47 +03001922 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Messages"}});
1923 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001924
aa7133@att.coma4c80012020-06-24 16:36:47 +03001925 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Messages"}});
1926 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001927
1928 //====================================================================================
aa7133@att.coma4c80012020-06-24 16:36:47 +03001929 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Messages"}});
1930 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001931
aa7133@att.coma4c80012020-06-24 16:36:47 +03001932 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Messages"}});
1933 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001934
aa7133@att.coma4c80012020-06-24 16:36:47 +03001935 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Messages"}});
1936 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001937
aa7133@att.coma4c80012020-06-24 16:36:47 +03001938 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceQuery)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Messages"}});
1939 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceQuery)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001940
aa7133@att.coma4c80012020-06-24 16:36:47 +03001941 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Messages"}});
1942 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001943
aa7133@att.coma4c80012020-06-24 16:36:47 +03001944 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Messages"}});
1945 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001946 //---------------------------------------------------------------------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03001947 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Messages"}});
1948 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001949
czichy2175dd32022-05-17 15:24:51 +03001950 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateSuccess", "Messages"}});
1951 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateSuccess", "Bytes"}});
1952
aa7133@att.coma4c80012020-06-24 16:36:47 +03001953 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Messages"}});
1954 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001955
aa7133@att.coma4c80012020-06-24 16:36:47 +03001956 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Messages"}});
1957 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001958 //----------------------------------------------------------------------------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03001959 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Messages"}});
1960 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001961
czichy2175dd32022-05-17 15:24:51 +03001962 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateFailure", "Messages"}});
1963 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateFailure", "Bytes"}});
1964
aa7133@att.coma4c80012020-06-24 16:36:47 +03001965 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Messages"}});
1966 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Bytes"}});
gunjarastogi85f507f2023-01-18 16:27:55 +05301967
1968
1969 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDeleteRequired)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteRequired", "Messages"}});
1970 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDeleteRequired)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteRequired", "Bytes"}});
1971
ss412g4aeeda22020-06-16 14:12:41 +03001972}
Mohamed Abukar64f37242021-08-15 12:39:56 +00001973
ss412g4aeeda22020-06-16 14:12:41 +03001974/**
1975 *
1976 * @param pdu
1977 * @param sctpMap
1978 * @param message
1979 * @param RANfunctionsAdded_v
1980 * @return
1981 */
1982int collectSetupRequestData(E2AP_PDU_t *pdu,
1983 Sctp_Map_t *sctpMap,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001984 ReportingMessages_t &message /*, vector <string> &RANfunctionsAdded_v*/) {
ss412g4aeeda22020-06-16 14:12:41 +03001985 memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE);
1986 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) {
1987 auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i];
1988 if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) {
1989 // get the ran name for meid
1990 if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) {
1991 if (buildRanName(message.peerInfo->enodbName, ie) < 0) {
1992 mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n");
aa7133@att.com409f2232020-10-29 13:06:45 +03001993 // no message will be sent
ss412g4aeeda22020-06-16 14:12:41 +03001994 return -1;
1995 }
1996
1997 memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName));
1998 sctpMap->setkey(message.message.enodbName, message.peerInfo);
1999 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002000 } /*else if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
ss412g4aeeda22020-06-16 14:12:41 +03002001 if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) {
2002 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2003 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
2004 ie->value.choice.RANfunctions_List.list.count);
2005 }
2006 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) {
2007 return -1;
2008 }
2009 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002010 } */
ss412g4aeeda22020-06-16 14:12:41 +03002011 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002012// if (mdclog_level_get() >= MDCLOG_DEBUG) {
2013// mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries",
2014// RANfunctionsAdded_v.size());
2015// }
ss412g4aeeda22020-06-16 14:12:41 +03002016 return 0;
2017}
2018
2019int XML_From_PER(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
2020 E2AP_PDU_t *pdu = nullptr;
2021
2022 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2023 mdclog_write(MDCLOG_DEBUG, "got PER message of size %d is:%s",
2024 rmrMessageBuffer.sendMessage->len, rmrMessageBuffer.sendMessage->payload);
2025 }
2026 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu,
2027 rmrMessageBuffer.sendMessage->payload, rmrMessageBuffer.sendMessage->len);
2028 if (rval.code != RC_OK) {
2029 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
2030 rval.code,
2031 message.message.enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04002032 if (pdu != nullptr) {
2033 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2034 pdu = nullptr;
2035 }
ss412g4aeeda22020-06-16 14:12:41 +03002036 return -1;
2037 }
2038
2039 int buff_size = RECEIVE_XAPP_BUFFER_SIZE;
2040 auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu,
2041 rmrMessageBuffer.sendMessage->payload, buff_size);
2042 if (er.encoded == -1) {
2043 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
dhirajverma9f59b572021-07-23 02:36:13 -04002044 if (pdu != nullptr) {
2045 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2046 pdu = nullptr;
2047 }
ss412g4aeeda22020-06-16 14:12:41 +03002048 return -1;
2049 } else if (er.encoded > (ssize_t)buff_size) {
2050 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
2051 (int)rmrMessageBuffer.sendMessage->len,
2052 asn_DEF_E2AP_PDU.name,
2053 __func__,
2054 __LINE__);
dhirajverma9f59b572021-07-23 02:36:13 -04002055 if (pdu != nullptr) {
2056 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2057 pdu = nullptr;
2058 }
ss412g4aeeda22020-06-16 14:12:41 +03002059 return -1;
2060 }
2061 rmrMessageBuffer.sendMessage->len = er.encoded;
dhirajverma9f59b572021-07-23 02:36:13 -04002062 if (pdu != nullptr) {
2063 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2064 pdu = nullptr;
2065 }
ss412g4aeeda22020-06-16 14:12:41 +03002066 return 0;
2067
2068}
2069
ss412g1a79bdf2019-10-24 12:03:05 +03002070/**
2071 *
2072 * @param pdu
2073 * @param message
2074 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002075 */
2076void asnInitiatingRequest(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002077 Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002078 ReportingMessages_t &message,
czichy2175dd32022-05-17 15:24:51 +03002079 RmrMessagesBuffer_t &rmrMessageBuffer, int streamId) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002080 auto logLevel = mdclog_level_get();
ss412g1a79bdf2019-10-24 12:03:05 +03002081 auto procedureCode = ((InitiatingMessage_t *) pdu->choice.initiatingMessage)->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002082 if (logLevel >= MDCLOG_DEBUG) {
2083 mdclog_write(MDCLOG_DEBUG, "Initiating message %ld\n", procedureCode);
ss412g1a79bdf2019-10-24 12:03:05 +03002084 }
2085 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002086 case ProcedureCode_id_E2setup: {
2087 if (logLevel >= MDCLOG_DEBUG) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002088 mdclog_write(MDCLOG_DEBUG, "Got E2setup");
aa7133@att.com84bd3342020-03-16 18:04:57 +02002089 }
2090
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002091// vector <string> RANfunctionsAdded_v;
2092// vector <string> RANfunctionsModified_v;
2093// RANfunctionsAdded_v.clear();
2094// RANfunctionsModified_v.clear();
2095 if (collectSetupRequestData(pdu, sctpMap, message) != 0) {
aa7133@att.com7b437f72020-03-30 13:25:54 +03002096 break;
2097 }
czichy2175dd32022-05-17 15:24:51 +03002098 struct sctp_status status;
2099 int stat_size = sizeof(status);
2100 getsockopt( message.peerInfo->fileDescriptor, SOL_SCTP, SCTP_STATUS,(void *)&status, (socklen_t *)&stat_size );
2101 if (logLevel >= MDCLOG_DEBUG) {
2102 mdclog_write(MDCLOG_DEBUG, "Start from SCTP %d fd", message.peerInfo->fileDescriptor);
2103 mdclog_write(MDCLOG_DEBUG, "SCTP status assoc id %d instrms %d outstrms %d", status.sstat_assoc_id,
2104 status.sstat_instrms, status.sstat_outstrms);
2105 }
2106 if(status.sstat_outstrms == 1 || status.sstat_instrms == 1)
2107 {
2108 message.peerInfo->isSingleStream = true;
2109 message.peerInfo->singleStreamId = streamId;
2110 if (status.sstat_outstrms == 1 && status.sstat_instrms == 1){
2111 if (logLevel >= MDCLOG_DEBUG) {
2112 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__);
2113 }
2114 }
2115 else {
2116 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,
2117 status.sstat_instrms, status.sstat_outstrms);
2118 }
2119 }
aa7133@att.com7b437f72020-03-30 13:25:54 +03002120
aa7133@att.com409f2232020-10-29 13:06:45 +03002121 buildPrometheusList(message.peerInfo, message.peerInfo->sctpParams->prometheusFamily);
ss412g4aeeda22020-06-16 14:12:41 +03002122
2123 string messageName("E2setupRequest");
2124 string ieName("E2setupRequestIEs");
2125 message.message.messageType = RIC_E2_SETUP_REQ;
aa7133@att.coma4c80012020-06-24 16:36:47 +03002126 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2127 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002128
2129 // Update E2T instance level metrics
2130 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2131 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment((double)message.message.asnLength);
2132
aa7133@att.com409f2232020-10-29 13:06:45 +03002133 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
ss412g1a79bdf2019-10-24 12:03:05 +03002134 break;
2135 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002136 case ProcedureCode_id_RICserviceUpdate: {
2137 if (logLevel >= MDCLOG_DEBUG) {
2138 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
2139 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002140// vector <string> RANfunctionsAdded_v;
2141// vector <string> RANfunctionsModified_v;
2142// RANfunctionsAdded_v.clear();
2143// RANfunctionsModified_v.clear();
2144// if (collectServiceUpdate_RequestData(pdu, sctpMap, message,
2145// RANfunctionsAdded_v, RANfunctionsModified_v) != 0) {
2146// break;
2147// }
ss412g4aeeda22020-06-16 14:12:41 +03002148
2149 string messageName("RICserviceUpdate");
2150 string ieName("RICserviceUpdateIEs");
2151 message.message.messageType = RIC_SERVICE_UPDATE;
Alexandre Hufffff97942023-03-31 21:22:20 -03002152#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002153 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2154 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002155
2156 // Update E2T instance level metrics
2157 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2158 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002159#endif
aa7133@att.com409f2232020-10-29 13:06:45 +03002160 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002161 break;
2162 }
czichy2175dd32022-05-17 15:24:51 +03002163
2164case ProcedureCode_id_E2nodeConfigurationUpdate: {
2165 if (logLevel >= MDCLOG_DEBUG) {
2166 mdclog_write(MDCLOG_DEBUG, "Got E2nodeConfigurationUpdate %s", message.message.enodbName);
2167 }
2168
2169 string messageName("RICE2nodeConfigurationUpdate");
2170 string ieName("RICE2nodeConfigurationUpdateIEs");
2171 message.message.messageType = RIC_E2NODE_CONFIG_UPDATE;
2172#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2173 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2174 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment((double)message.message.asnLength);
2175
2176 // Update E2T instance level metrics
2177 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2178 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment((double)message.message.asnLength);
2179#endif
2180 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
2181 break;
2182 }
2183
aa7133@att.com84bd3342020-03-16 18:04:57 +02002184 case ProcedureCode_id_ErrorIndication: {
2185 if (logLevel >= MDCLOG_DEBUG) {
2186 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
2187 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002188#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002189 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2190 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002191
2192 // Update E2T instance level metrics
2193 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2194 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002195#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002196 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002197 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
ss412g1a79bdf2019-10-24 12:03:05 +03002198 }
2199 break;
2200 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002201 case ProcedureCode_id_Reset: {
2202 if (logLevel >= MDCLOG_DEBUG) {
2203 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002204 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002205#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002206 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2207 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002208
2209 // Update E2T instance level metrics
2210 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2211 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002212#endif
ss412g4aeeda22020-06-16 14:12:41 +03002213 if (XML_From_PER(message, rmrMessageBuffer) < 0) {
2214 break;
ss412g1a79bdf2019-10-24 12:03:05 +03002215 }
ss412g4aeeda22020-06-16 14:12:41 +03002216
2217 if (sendRequestToXapp(message, RIC_E2_RESET_REQ, rmrMessageBuffer) != 0) {
2218 mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_REQ message failed to send to xAPP");
aa7133@att.com84bd3342020-03-16 18:04:57 +02002219 }
2220 break;
2221 }
2222 case ProcedureCode_id_RICindication: {
2223 if (logLevel >= MDCLOG_DEBUG) {
2224 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
2225 }
2226 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
ss412g1a79bdf2019-10-24 12:03:05 +03002227 auto messageSent = false;
2228 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
aa7133@att.com84bd3342020-03-16 18:04:57 +02002229 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002230 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2231 }
2232 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002233 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002234 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2235 }
2236 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
2237 static unsigned char tx[32];
2238 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
2239 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2240 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
ss412g3bac2da2020-01-05 11:52:19 +02002241 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
aa7133@att.com84bd3342020-03-16 18:04:57 +02002242 (unsigned char *)message.message.enodbName,
2243 strlen(message.message.enodbName));
ss412g1a79bdf2019-10-24 12:03:05 +03002244 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.comc5a15202020-04-05 19:57:01 +03002245 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
2246
2247 //ie->value.choice.RICrequestID.ricInstanceID;
ss412g3bac2da2020-01-05 11:52:19 +02002248 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03002249 mdclog_write(MDCLOG_DEBUG, "sub id = %d, mtype = %d, ric instance id %ld, requestor id = %ld",
aa7133@att.com84bd3342020-03-16 18:04:57 +02002250 rmrMessageBuffer.sendMessage->sub_id,
aa7133@att.comc5a15202020-04-05 19:57:01 +03002251 rmrMessageBuffer.sendMessage->mtype,
2252 ie->value.choice.RICrequestID.ricInstanceID,
2253 ie->value.choice.RICrequestID.ricRequestorID);
ss412g3bac2da2020-01-05 11:52:19 +02002254 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002255#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002256 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication]->Increment();
2257 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002258
2259 // Update E2T instance level metrics
2260 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication]->Increment();
2261 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002262#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002263 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002264 messageSent = true;
2265 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002266 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002267 }
2268 }
2269 if (messageSent) {
2270 break;
2271 }
2272 }
2273 break;
2274 }
gunjarastogi85f507f2023-01-18 16:27:55 +05302275 case ProcedureCode_id_RICsubscriptionDeleteRequired: {
2276 if (logLevel >= MDCLOG_DEBUG) {
2277 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDeleteRequired %s", message.message.enodbName);
2278 }
2279 #if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2280 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment();
2281 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment((double)message.message.asnLength);
2282
2283 // Update E2T instance level metrics
2284 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment();
2285 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment((double)message.message.asnLength);
2286 #endif
2287 if (sendRequestToXapp(message, RIC_SUB_DEL_REQUIRED, rmrMessageBuffer) != 0) {
2288 mdclog_write(MDCLOG_ERR, "Subscription Delete Required message failed to send to xAPP");
2289 }
2290 break;
2291 }
2292
ss412g1a79bdf2019-10-24 12:03:05 +03002293 default: {
2294 mdclog_write(MDCLOG_ERR, "Undefined or not supported message = %ld", procedureCode);
2295 message.message.messageType = 0; // no RMR message type yet
2296
2297 buildJsonMessage(message);
2298
2299 break;
2300 }
2301 }
ss412g1a79bdf2019-10-24 12:03:05 +03002302}
2303
2304/**
2305 *
2306 * @param pdu
2307 * @param message
ss412g1a79bdf2019-10-24 12:03:05 +03002308 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002309 */
aa7133@att.com409f2232020-10-29 13:06:45 +03002310void asnSuccessfulMsg(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002311 Sctp_Map_t *sctpMap,
2312 ReportingMessages_t &message,
2313 RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002314 auto procedureCode = pdu->choice.successfulOutcome->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002315 auto logLevel = mdclog_level_get();
2316 if (logLevel >= MDCLOG_INFO) {
ss412g1a79bdf2019-10-24 12:03:05 +03002317 mdclog_write(MDCLOG_INFO, "Successful Outcome %ld", procedureCode);
2318 }
2319 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002320 case ProcedureCode_id_Reset: {
2321 if (logLevel >= MDCLOG_DEBUG) {
2322 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002323 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002324#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002325 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2326 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002327
2328 // Update E2T instance level metrics
2329 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2330 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002331#endif
ss412g4aeeda22020-06-16 14:12:41 +03002332 if (XML_From_PER(message, rmrMessageBuffer) < 0) {
2333 break;
2334 }
2335 if (sendRequestToXapp(message, RIC_E2_RESET_RESP, rmrMessageBuffer) != 0) {
2336 mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_RESP message failed to send to xAPP");
ss412g1a79bdf2019-10-24 12:03:05 +03002337 }
2338 break;
2339 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002340 case ProcedureCode_id_RICcontrol: {
2341 if (logLevel >= MDCLOG_DEBUG) {
2342 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002343 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002344 for (auto i = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03002345 i < pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; i++) {
2346 auto messageSent = false;
2347 RICcontrolAcknowledge_IEs_t *ie = pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[i];
2348 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2349 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2350 }
2351 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
2352 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2353 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2354 }
2355 if (ie->value.present == RICcontrolAcknowledge_IEs__value_PR_RICrequestID) {
2356 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_ACK;
2357 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002358// rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
2359 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
2360
ss412g1a79bdf2019-10-24 12:03:05 +03002361 static unsigned char tx[32];
2362 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2363 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
ss412g3bac2da2020-01-05 11:52:19 +02002364 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
aa7133@att.com84bd3342020-03-16 18:04:57 +02002365 (unsigned char *)message.message.enodbName,
2366 strlen(message.message.enodbName));
Alexandre Hufffff97942023-03-31 21:22:20 -03002367#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002368 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2369 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002370
2371 // Update E2T instance level metrics
2372 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2373 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002374#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002375 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002376 messageSent = true;
2377 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002378 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002379 }
2380 }
2381 if (messageSent) {
2382 break;
2383 }
2384 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002385
2386 break;
2387 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002388 case ProcedureCode_id_RICsubscription: {
2389 if (logLevel >= MDCLOG_DEBUG) {
2390 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
2391 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002392#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002393 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2394 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002395
2396 // Update E2T instance level metrics
2397 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2398 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002399#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002400 if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002401 mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP");
2402 }
2403 break;
2404 }
2405 case ProcedureCode_id_RICsubscriptionDelete: {
2406 if (logLevel >= MDCLOG_DEBUG) {
2407 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
2408 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002409#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002410 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2411 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002412
2413 // Update E2T instance level metrics
2414 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2415 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002416#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002417 if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002418 mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP");
2419 }
ss412g1a79bdf2019-10-24 12:03:05 +03002420 break;
2421 }
2422 default: {
2423 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
2424 message.message.messageType = 0; // no RMR message type yet
2425 buildJsonMessage(message);
2426
2427 break;
2428 }
2429 }
ss412g1a79bdf2019-10-24 12:03:05 +03002430}
2431
2432/**
2433 *
2434 * @param pdu
2435 * @param message
ss412g1a79bdf2019-10-24 12:03:05 +03002436 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002437 */
2438void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002439 Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002440 ReportingMessages_t &message,
aa7133@att.combe92d712020-03-18 17:30:39 +02002441 RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002442 auto procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002443 auto logLevel = mdclog_level_get();
2444 if (logLevel >= MDCLOG_INFO) {
ss412g1a79bdf2019-10-24 12:03:05 +03002445 mdclog_write(MDCLOG_INFO, "Unsuccessful Outcome %ld", procedureCode);
2446 }
2447 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002448 case ProcedureCode_id_RICcontrol: {
2449 if (logLevel >= MDCLOG_DEBUG) {
2450 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002451 }
2452 for (int i = 0;
2453 i < pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.count; i++) {
2454 auto messageSent = false;
2455 RICcontrolFailure_IEs_t *ie = pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.array[i];
aa7133@att.com84bd3342020-03-16 18:04:57 +02002456 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002457 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2458 }
2459 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002460 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002461 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2462 }
2463 if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) {
2464 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_FAILURE;
2465 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002466// rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricRequestorID;
2467 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
ss412g1a79bdf2019-10-24 12:03:05 +03002468 static unsigned char tx[32];
2469 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2470 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
aa7133@att.com84bd3342020-03-16 18:04:57 +02002471 rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName,
2472 strlen(message.message.enodbName));
Alexandre Hufffff97942023-03-31 21:22:20 -03002473#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002474 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2475 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002476
2477 // Update E2T instance level metrics
2478 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2479 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
dhirajverma99990292021-07-05 10:03:59 -04002480#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002481 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002482 messageSent = true;
2483 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002484 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002485 }
2486 }
2487 if (messageSent) {
2488 break;
2489 }
2490 }
2491 break;
2492 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002493 case ProcedureCode_id_RICsubscription: {
2494 if (logLevel >= MDCLOG_DEBUG) {
2495 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
2496 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002497#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002498 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2499 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002500
2501 // Update E2T instance level metrics
2502 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2503 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002504#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002505 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002506 mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP");
2507 }
2508 break;
2509 }
2510 case ProcedureCode_id_RICsubscriptionDelete: {
2511 if (logLevel >= MDCLOG_DEBUG) {
2512 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
2513 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002514#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002515 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2516 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002517
2518 // Update E2T instance level metrics
2519 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2520 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002521#endif
ss412g4aeeda22020-06-16 14:12:41 +03002522 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002523 mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP");
2524 }
2525 break;
2526 }
ss412g1a79bdf2019-10-24 12:03:05 +03002527 default: {
2528 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
2529 message.message.messageType = 0; // no RMR message type yet
Alexandre Hufffff97942023-03-31 21:22:20 -03002530#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03002531 buildJsonMessage(message);
Alexandre Hufffff97942023-03-31 21:22:20 -03002532#endif
ss412g1a79bdf2019-10-24 12:03:05 +03002533 break;
2534 }
2535 }
ss412g1a79bdf2019-10-24 12:03:05 +03002536}
2537
2538/**
2539 *
2540 * @param message
2541 * @param requestId
2542 * @param rmrMmessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002543 * @return
2544 */
2545int sendRequestToXapp(ReportingMessages_t &message,
2546 int requestId,
aa7133@att.combe92d712020-03-18 17:30:39 +02002547 RmrMessagesBuffer_t &rmrMmessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002548 rmr_bytes2meid(rmrMmessageBuffer.sendMessage,
2549 (unsigned char *)message.message.enodbName,
2550 strlen(message.message.enodbName));
2551 message.message.messageType = rmrMmessageBuffer.sendMessage->mtype = requestId;
2552 rmrMmessageBuffer.sendMessage->state = 0;
2553 static unsigned char tx[32];
2554 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2555 rmr_bytes2xact(rmrMmessageBuffer.sendMessage, tx, strlen((const char *) tx));
2556
aa7133@att.combe92d712020-03-18 17:30:39 +02002557 auto rc = sendRmrMessage(rmrMmessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002558 return rc;
2559}
2560
ss412g4aeeda22020-06-16 14:12:41 +03002561/**
2562 *
2563 * @param pSctpParams
2564 */
aa7133@att.combe92d712020-03-18 17:30:39 +02002565void getRmrContext(sctp_params_t &pSctpParams) {
ss412g3bac2da2020-01-05 11:52:19 +02002566 pSctpParams.rmrCtx = nullptr;
aa7133@att.comab0e0f42020-04-06 17:13:58 +03002567 pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RECEIVE_XAPP_BUFFER_SIZE, RMRFL_NONE);
ss412g3bac2da2020-01-05 11:52:19 +02002568 if (pSctpParams.rmrCtx == nullptr) {
2569 mdclog_write(MDCLOG_ERR, "Failed to initialize RMR");
ss412g3bac2da2020-01-05 11:52:19 +02002570 return;
ss412g1a79bdf2019-10-24 12:03:05 +03002571 }
2572
ss412g3bac2da2020-01-05 11:52:19 +02002573 rmr_set_stimeout(pSctpParams.rmrCtx, 0); // disable retries for any send operation
ss412g1a79bdf2019-10-24 12:03:05 +03002574 // we need to find that routing table exist and we can run
2575 if (mdclog_level_get() >= MDCLOG_INFO) {
2576 mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready");
2577 }
2578 int rmrReady = 0;
2579 int count = 0;
2580 while (!rmrReady) {
ss412g3bac2da2020-01-05 11:52:19 +02002581 if ((rmrReady = rmr_ready(pSctpParams.rmrCtx)) == 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002582 sleep(1);
2583 }
2584 count++;
2585 if (count % 60 == 0) {
2586 mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count);
2587 }
2588 }
2589 if (mdclog_level_get() >= MDCLOG_INFO) {
2590 mdclog_write(MDCLOG_INFO, "RMR running");
2591 }
ss412g3bac2da2020-01-05 11:52:19 +02002592 rmr_init_trace(pSctpParams.rmrCtx, 200);
2593 // get the RMR fd for the epoll
2594 pSctpParams.rmrListenFd = rmr_get_rcvfd(pSctpParams.rmrCtx);
2595 struct epoll_event event{};
2596 // add RMR fd to epoll
2597 event.events = (EPOLLIN);
2598 event.data.fd = pSctpParams.rmrListenFd;
2599 // add listening RMR FD to epoll
2600 if (epoll_ctl(pSctpParams.epoll_fd, EPOLL_CTL_ADD, pSctpParams.rmrListenFd, &event)) {
2601 mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll");
2602 close(pSctpParams.rmrListenFd);
2603 rmr_close(pSctpParams.rmrCtx);
2604 pSctpParams.rmrCtx = nullptr;
2605 }
ss412g1a79bdf2019-10-24 12:03:05 +03002606}
2607
ss412g4aeeda22020-06-16 14:12:41 +03002608/**
2609 *
2610 * @param message
2611 * @param rmrMessageBuffer
2612 * @return
2613 */
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002614int PER_FromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
aa7133@att.com07e256f2020-04-20 15:59:51 +03002615 E2AP_PDU_t *pdu = nullptr;
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002616
2617 if (mdclog_level_get() >= MDCLOG_DEBUG) {
ss412g4aeeda22020-06-16 14:12:41 +03002618 mdclog_write(MDCLOG_DEBUG, "got xml Format data from xApp of size %d is:%s",
aa7133@att.com07e256f2020-04-20 15:59:51 +03002619 rmrMessageBuffer.rcvMessage->len, rmrMessageBuffer.rcvMessage->payload);
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002620 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002621 auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &pdu,
2622 rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len);
aa7133@att.com409f2232020-10-29 13:06:45 +03002623 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2624 mdclog_write(MDCLOG_DEBUG, "%s After decoding the XML to PDU", __func__ );
2625 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002626 if (rval.code != RC_OK) {
dhirajvermac40ea1f2021-07-08 12:52:30 -04002627#ifdef UNIT_TEST
2628 return 0;
Alexandre Hufffff97942023-03-31 21:22:20 -03002629#endif
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002630 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
aa7133@att.com1fecb052020-03-29 09:44:09 +03002631 rval.code,
2632 message.message.enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04002633 if (pdu != nullptr) {
2634 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2635 pdu = nullptr;
2636 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002637 return -1;
2638 }
2639
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002640 int buff_size = RECEIVE_XAPP_BUFFER_SIZE;
2641 auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu,
2642 rmrMessageBuffer.rcvMessage->payload, buff_size);
aa7133@att.com409f2232020-10-29 13:06:45 +03002643 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2644 mdclog_write(MDCLOG_DEBUG, "%s After encoding PDU to PER", __func__ );
2645 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002646 if (er.encoded == -1) {
2647 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
dhirajverma9f59b572021-07-23 02:36:13 -04002648 if (pdu != nullptr) {
2649 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2650 pdu = nullptr;
2651 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002652 return -1;
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002653 } else if (er.encoded > (ssize_t)buff_size) {
2654 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 +03002655 (int)rmrMessageBuffer.rcvMessage->len,
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002656 asn_DEF_E2AP_PDU.name,
2657 __func__,
2658 __LINE__);
dhirajverma9f59b572021-07-23 02:36:13 -04002659 if (pdu != nullptr) {
2660 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2661 pdu = nullptr;
2662 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002663 return -1;
2664 }
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002665 rmrMessageBuffer.rcvMessage->len = er.encoded;
dhirajverma9f59b572021-07-23 02:36:13 -04002666 if (pdu != nullptr) {
2667 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2668 pdu = nullptr;
2669 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002670 return 0;
2671}
2672
ss412g1a79bdf2019-10-24 12:03:05 +03002673/**
2674 *
ss412g1a79bdf2019-10-24 12:03:05 +03002675 * @param sctpMap
2676 * @param rmrMessageBuffer
2677 * @param ts
ss412g1a79bdf2019-10-24 12:03:05 +03002678 * @return
2679 */
aa7133@att.com6680c3b2020-03-22 12:06:58 +02002680int receiveXappMessages(Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002681 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02002682 struct timespec &ts) {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002683 int loglevel = mdclog_level_get();
ss412g1a79bdf2019-10-24 12:03:05 +03002684 if (rmrMessageBuffer.rcvMessage == nullptr) {
2685 //we have error
2686 mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03002687 return -1;
2688 }
2689
aa7133@att.comf13529a2020-08-27 11:21:16 +03002690// if (loglevel >= MDCLOG_DEBUG) {
2691// mdclog_write(MDCLOG_DEBUG, "Call to rmr_rcv_msg");
2692// }
ss412g1a79bdf2019-10-24 12:03:05 +03002693 rmrMessageBuffer.rcvMessage = rmr_rcv_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
2694 if (rmrMessageBuffer.rcvMessage == nullptr) {
aa7133@att.com409f2232020-10-29 13:06:45 +03002695 mdclog_write(MDCLOG_ERR, "RMR Receiving message with null pointer, Reallocated rmr message buffer");
ss412g1a79bdf2019-10-24 12:03:05 +03002696 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g1a79bdf2019-10-24 12:03:05 +03002697 return -2;
2698 }
2699 ReportingMessages_t message;
2700 message.message.direction = 'D';
2701 message.message.time.tv_nsec = ts.tv_nsec;
2702 message.message.time.tv_sec = ts.tv_sec;
2703
2704 // get message payload
2705 //auto msgData = msg->payload;
dhirajverma60f8bef2021-06-29 07:22:58 -04002706#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04002707 rmrMessageBuffer.rcvMessage->state = 0;
dhirajverma60f8bef2021-06-29 07:22:58 -04002708#endif
ss412g1a79bdf2019-10-24 12:03:05 +03002709 if (rmrMessageBuffer.rcvMessage->state != 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +03002710 mdclog_write(MDCLOG_ERR, "RMR Receiving message with stat = %d", rmrMessageBuffer.rcvMessage->state);
ss412g1a79bdf2019-10-24 12:03:05 +03002711 return -1;
2712 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002713 rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)message.message.enodbName);
ss412g4aeeda22020-06-16 14:12:41 +03002714 message.peerInfo = (ConnectedCU_t *) sctpMap->find(message.message.enodbName);
2715 if (message.peerInfo == nullptr) {
2716 auto type = rmrMessageBuffer.rcvMessage->mtype;
2717 switch (type) {
2718 case RIC_SCTP_CLEAR_ALL:
2719 case E2_TERM_KEEP_ALIVE_REQ:
2720 case RIC_HEALTH_CHECK_REQ:
2721 break;
2722 default:
dhirajverma99990292021-07-05 10:03:59 -04002723#ifdef UNIT_TEST
2724 break;
Alexandre Hufffff97942023-03-31 21:22:20 -03002725#endif
ss412g4aeeda22020-06-16 14:12:41 +03002726 mdclog_write(MDCLOG_ERR, "Failed to send message no CU entry %s", message.message.enodbName);
2727 return -1;
2728 }
2729 }
2730
aa7133@att.comde40d1c2020-08-26 16:19:20 +03002731 if (rmrMessageBuffer.rcvMessage->mtype != RIC_HEALTH_CHECK_REQ) {
2732 num_of_XAPP_messages.fetch_add(1, std::memory_order_release);
2733
2734 }
ss412g1a79bdf2019-10-24 12:03:05 +03002735 switch (rmrMessageBuffer.rcvMessage->mtype) {
aa7133@att.combe92d712020-03-18 17:30:39 +02002736 case RIC_E2_SETUP_RESP : {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002737 if (loglevel >= MDCLOG_DEBUG) {
2738 mdclog_write(MDCLOG_DEBUG, "RIC_E2_SETUP_RESP");
2739 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002740 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com1fecb052020-03-29 09:44:09 +03002741 break;
2742 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002743#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002744 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2745 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002746
2747 // Update E2T instance level metrics
2748 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2749 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002750#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002751 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2752 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_RESP");
2753 return -6;
ss412g1a79bdf2019-10-24 12:03:05 +03002754 }
2755 break;
2756 }
aa7133@att.combe92d712020-03-18 17:30:39 +02002757 case RIC_E2_SETUP_FAILURE : {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002758 if (loglevel >= MDCLOG_DEBUG) {
2759 mdclog_write(MDCLOG_DEBUG, "RIC_E2_SETUP_FAILURE");
2760 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002761 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com1fecb052020-03-29 09:44:09 +03002762 break;
2763 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002764#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002765 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2766 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002767
2768 // Update E2T instance level metrics
2769 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2770 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002771#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002772 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2773 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_FAILURE");
2774 return -6;
ss412g1a79bdf2019-10-24 12:03:05 +03002775 }
2776 break;
2777 }
czichy2175dd32022-05-17 15:24:51 +03002778
2779 case RIC_E2NODE_CONFIG_UPDATE_ACK: {
2780 if (loglevel >= MDCLOG_DEBUG) {
2781 mdclog_write(MDCLOG_DEBUG, "RIC_E2NODE_CONFIG_UPDATE_ACK");
2782 }
2783 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2784 break;
2785 }
2786#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2787 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2788 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2789
2790 // Update E2T instance level metrics
2791 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2792 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2793#endif
2794 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2795 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2NODE_CONFIG_UPDATE_ACK");
2796 return -6;
2797 }
2798 break;
2799 }
2800
2801 case RIC_E2NODE_CONFIG_UPDATE_FAILURE: {
2802 if (loglevel >= MDCLOG_DEBUG) {
2803 mdclog_write(MDCLOG_DEBUG, "RIC_E2NODE_CONFIG_UPDATE_FAILURE");
2804 }
2805 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2806 break;
2807 }
2808#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2809 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2810 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2811
2812 // Update E2T instance level metrics
2813 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2814 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2815#endif
2816 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2817 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2NODE_CONFIG_UPDATE_FAILURE");
2818 return -6;
2819 }
2820 break;
2821 }
2822
aa7133@att.combe92d712020-03-18 17:30:39 +02002823 case RIC_ERROR_INDICATION: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002824 if (loglevel >= MDCLOG_DEBUG) {
2825 mdclog_write(MDCLOG_DEBUG, "RIC_ERROR_INDICATION");
2826 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002827#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002828 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2829 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002830
2831 // Update E2T instance level metrics
2832 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2833 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002834#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002835 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2836 mdclog_write(MDCLOG_ERR, "Failed to send RIC_ERROR_INDICATION");
ss412g1a79bdf2019-10-24 12:03:05 +03002837 return -6;
2838 }
2839 break;
2840 }
2841 case RIC_SUB_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002842 if (loglevel >= MDCLOG_DEBUG) {
2843 mdclog_write(MDCLOG_DEBUG, "RIC_SUB_REQ");
2844 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002845#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002846 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2847 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002848
2849 // Update E2T instance level metrics
2850 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2851 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002852#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002853 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002854 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002855 return -6;
2856 }
2857 break;
2858 }
2859 case RIC_SUB_DEL_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002860 if (loglevel >= MDCLOG_DEBUG) {
2861 mdclog_write(MDCLOG_DEBUG, "RIC_SUB_DEL_REQ");
2862 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002863#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002864 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2865 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002866
2867 // Update E2T instance level metrics
2868 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2869 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002870#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002871 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002872 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_DEL_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002873 return -6;
2874 }
2875 break;
2876 }
2877 case RIC_CONTROL_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002878 if (loglevel >= MDCLOG_DEBUG) {
2879 mdclog_write(MDCLOG_DEBUG, "RIC_CONTROL_REQ");
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_RICcontrol]->Increment();
2883 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002884
2885 // Update E2T instance level metrics
2886 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2887 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->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) {
ss412g1a79bdf2019-10-24 12:03:05 +03002890 mdclog_write(MDCLOG_ERR, "Failed to send RIC_CONTROL_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002891 return -6;
2892 }
2893 break;
2894 }
2895 case RIC_SERVICE_QUERY: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002896 if (loglevel >= MDCLOG_DEBUG) {
2897 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_QUERY");
2898 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002899 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2900 break;
2901 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002902#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002903 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment();
2904 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002905
2906 // Update E2T instance level metrics
2907 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment();
2908 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002909#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002910 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002911 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY");
ss412g1a79bdf2019-10-24 12:03:05 +03002912 return -6;
2913 }
2914 break;
2915 }
2916 case RIC_SERVICE_UPDATE_ACK: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002917 if (loglevel >= MDCLOG_DEBUG) {
2918 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_UPDATE_ACK");
2919 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002920 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com54885fe2020-10-29 17:24:49 +03002921 mdclog_write(MDCLOG_ERR, "error in PER_FromXML");
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002922 break;
2923 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002924#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002925 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
aa7133@att.com52771912020-10-29 17:45:01 +03002926 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002927
2928 // Update E2T instance level metrics
2929 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2930 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002931#endif
aa7133@att.com54885fe2020-10-29 17:24:49 +03002932 if (loglevel >= MDCLOG_DEBUG) {
2933 mdclog_write(MDCLOG_DEBUG, "Before sending to CU");
2934 }
aa7133@att.combe92d712020-03-18 17:30:39 +02002935 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002936 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK");
ss412g1a79bdf2019-10-24 12:03:05 +03002937 return -6;
2938 }
2939 break;
2940 }
2941 case RIC_SERVICE_UPDATE_FAILURE: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002942 if (loglevel >= MDCLOG_DEBUG) {
2943 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_UPDATE_FAILURE");
2944 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002945 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2946 break;
2947 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002948#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002949 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
aa7133@att.com7c07fee2020-10-29 17:54:38 +03002950 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002951
2952 // Update E2T instance level metrics
2953 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2954 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002955#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002956 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002957 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE");
ss412g1a79bdf2019-10-24 12:03:05 +03002958 return -6;
2959 }
2960 break;
2961 }
ss412g4aeeda22020-06-16 14:12:41 +03002962 case RIC_E2_RESET_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002963 if (loglevel >= MDCLOG_DEBUG) {
2964 mdclog_write(MDCLOG_DEBUG, "RIC_E2_RESET_REQ");
2965 }
ss412g4aeeda22020-06-16 14:12:41 +03002966 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2967 break;
2968 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002969#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002970 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2971 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002972
2973 // Update E2T instance level metrics
2974 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2975 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002976#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002977 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03002978 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET");
ss412g1a79bdf2019-10-24 12:03:05 +03002979 return -6;
2980 }
2981 break;
2982 }
ss412g4aeeda22020-06-16 14:12:41 +03002983 case RIC_E2_RESET_RESP: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002984 if (loglevel >= MDCLOG_DEBUG) {
2985 mdclog_write(MDCLOG_DEBUG, "RIC_E2_RESET_RESP");
2986 }
ss412g4aeeda22020-06-16 14:12:41 +03002987 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2988 break;
2989 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002990#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002991 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2992 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002993
2994 // Update E2T instance level metrics
2995 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2996 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002997#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002998 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03002999 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET_RESP");
ss412g1a79bdf2019-10-24 12:03:05 +03003000 return -6;
3001 }
3002 break;
3003 }
3004 case RIC_SCTP_CLEAR_ALL: {
3005 mdclog_write(MDCLOG_INFO, "RIC_SCTP_CLEAR_ALL");
3006 // loop on all keys and close socket and then erase all map.
3007 vector<char *> v;
3008 sctpMap->getKeys(v);
3009 for (auto const &iter : v) { //}; iter != sctpMap.end(); iter++) {
3010 if (!boost::starts_with((string) (iter), "host:") && !boost::starts_with((string) (iter), "msg:")) {
3011 auto *peerInfo = (ConnectedCU_t *) sctpMap->find(iter);
3012 if (peerInfo == nullptr) {
3013 continue;
3014 }
3015 close(peerInfo->fileDescriptor);
3016 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
3017 message.message.direction = 'D';
3018 message.message.time.tv_nsec = ts.tv_nsec;
3019 message.message.time.tv_sec = ts.tv_sec;
3020
3021 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
3022 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
aa7133@att.com96c9b882020-03-25 14:50:40 +02003023 256,
3024 "%s|RIC_SCTP_CLEAR_ALL",
3025 peerInfo->enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03003026 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
3027 mdclog_write(MDCLOG_INFO, "%s", message.message.asndata);
aa7133@att.combe92d712020-03-18 17:30:39 +02003028 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03003029 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
3030 }
3031 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +05303032 peerInfo = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03003033 }
3034 }
3035
3036 sleep(1);
3037 sctpMap->clear();
3038 break;
3039 }
ss412g3bac2da2020-01-05 11:52:19 +02003040 case E2_TERM_KEEP_ALIVE_REQ: {
3041 // send message back
ss412g3bac2da2020-01-05 11:52:19 +02003042 rmr_bytes2payload(rmrMessageBuffer.sendMessage,
aa7133@att.com96c9b882020-03-25 14:50:40 +02003043 (unsigned char *)rmrMessageBuffer.ka_message,
3044 rmrMessageBuffer.ka_message_len);
ss412g3bac2da2020-01-05 11:52:19 +02003045 rmrMessageBuffer.sendMessage->mtype = E2_TERM_KEEP_ALIVE_RESP;
3046 rmrMessageBuffer.sendMessage->state = 0;
3047 static unsigned char tx[32];
3048 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
3049 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, txLen);
Alexandre Hufffff97942023-03-31 21:22:20 -03003050#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02003051 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003052#endif
ss412g3bac2da2020-01-05 11:52:19 +02003053 if (rmrMessageBuffer.sendMessage == nullptr) {
3054 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
aa7133@att.com77fff432020-01-27 12:01:20 +02003055 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP RMR message returned NULL");
ss412g3bac2da2020-01-05 11:52:19 +02003056 } else if (rmrMessageBuffer.sendMessage->state != 0) {
aa7133@att.com77fff432020-01-27 12:01:20 +02003057 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 +02003058 rmrMessageBuffer.sendMessage->state, translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str());
aa7133@att.comf13529a2020-08-27 11:21:16 +03003059 } else if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.combc110772020-03-25 09:45:14 +02003060 mdclog_write(MDCLOG_DEBUG, "Got Keep Alive Request send : %s", rmrMessageBuffer.ka_message);
ss412g3bac2da2020-01-05 11:52:19 +02003061 }
aa7133@att.com342843e2020-01-26 12:53:34 +02003062
ss412g3bac2da2020-01-05 11:52:19 +02003063 break;
3064 }
ss412g4aeeda22020-06-16 14:12:41 +03003065 case RIC_HEALTH_CHECK_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03003066 static int counter = 0;
ss412g4aeeda22020-06-16 14:12:41 +03003067 // send message back
aa7133@att.comc18fe532020-06-30 12:40:18 +03003068 rmr_bytes2payload(rmrMessageBuffer.rcvMessage,
ss412g4aeeda22020-06-16 14:12:41 +03003069 (unsigned char *)"OK",
3070 2);
aa7133@att.comc18fe532020-06-30 12:40:18 +03003071 rmrMessageBuffer.rcvMessage->mtype = RIC_HEALTH_CHECK_RESP;
3072 rmrMessageBuffer.rcvMessage->state = 0;
ss412g4aeeda22020-06-16 14:12:41 +03003073 static unsigned char tx[32];
3074 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
aa7133@att.comc18fe532020-06-30 12:40:18 +03003075 rmr_bytes2xact(rmrMessageBuffer.rcvMessage, tx, txLen);
3076 rmrMessageBuffer.rcvMessage = rmr_rts_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
3077 //rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
3078 if (rmrMessageBuffer.rcvMessage == nullptr) {
3079 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g4aeeda22020-06-16 14:12:41 +03003080 mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP RMR message returned NULL");
aa7133@att.comc18fe532020-06-30 12:40:18 +03003081 } else if (rmrMessageBuffer.rcvMessage->state != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03003082 mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP, on RMR state = %d ( %s)",
aa7133@att.comc18fe532020-06-30 12:40:18 +03003083 rmrMessageBuffer.rcvMessage->state, translateRmrErrorMessages(rmrMessageBuffer.rcvMessage->state).c_str());
dhirajvermab55bc172021-11-09 02:15:08 -05003084 } else if (loglevel >= MDCLOG_DEBUG && (++counter % 100 == 0)) {
aa7133@att.comf13529a2020-08-27 11:21:16 +03003085 mdclog_write(MDCLOG_DEBUG, "Got %d RIC_HEALTH_CHECK_REQ Request send : OK", counter);
ss412g4aeeda22020-06-16 14:12:41 +03003086 }
3087
3088 break;
3089 }
3090
ss412g1a79bdf2019-10-24 12:03:05 +03003091 default:
aa7133@att.com409f2232020-10-29 13:06:45 +03003092 mdclog_write(MDCLOG_WARN, "Message Type : %d is not supported", rmrMessageBuffer.rcvMessage->mtype);
ss412g1a79bdf2019-10-24 12:03:05 +03003093 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
3094 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
3095 message.message.time.tv_nsec = ts.tv_nsec;
3096 message.message.time.tv_sec = ts.tv_sec;
3097 message.message.messageType = rmrMessageBuffer.rcvMessage->mtype;
3098
3099 buildJsonMessage(message);
3100
3101
ss412g1a79bdf2019-10-24 12:03:05 +03003102 return -7;
3103 }
3104 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3105 mdclog_write(MDCLOG_DEBUG, "EXIT OK from %s", __FUNCTION__);
3106 }
ss412g1a79bdf2019-10-24 12:03:05 +03003107 return 0;
3108}
3109
3110/**
3111 * Send message to the CU that is not expecting for successful or unsuccessful results
3112 * @param messageBuffer
3113 * @param message
3114 * @param failedMsgId
3115 * @param sctpMap
ss412g1a79bdf2019-10-24 12:03:05 +03003116 * @return
3117 */
3118int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer,
3119 ReportingMessages_t &message,
3120 int failedMsgId,
aa7133@att.combe92d712020-03-18 17:30:39 +02003121 Sctp_Map_t *sctpMap) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003122 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3123 mdclog_write(MDCLOG_DEBUG, "send message: %d to %s address", message.message.messageType, message.message.enodbName);
3124 }
ss412g1a79bdf2019-10-24 12:03:05 +03003125
aa7133@att.combe92d712020-03-18 17:30:39 +02003126 getRequestMetaData(message, messageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03003127 if (mdclog_level_get() >= MDCLOG_INFO) {
3128 mdclog_write(MDCLOG_INFO, "send message to %s address", message.message.enodbName);
3129 }
3130
aa7133@att.combe92d712020-03-18 17:30:39 +02003131 auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId);
ss412g1a79bdf2019-10-24 12:03:05 +03003132 return rc;
3133}
3134
3135/**
3136 *
3137 * @param sctpMap
3138 * @param messageBuffer
3139 * @param message
3140 * @param failedMesgId
ss412g1a79bdf2019-10-24 12:03:05 +03003141 * @return
3142 */
3143int sendMessagetoCu(Sctp_Map_t *sctpMap,
3144 RmrMessagesBuffer_t &messageBuffer,
3145 ReportingMessages_t &message,
aa7133@att.combe92d712020-03-18 17:30:39 +02003146 int failedMesgId) {
ss412g1a79bdf2019-10-24 12:03:05 +03003147 // get the FD
3148 message.message.messageType = messageBuffer.rcvMessage->mtype;
ss412g4aeeda22020-06-16 14:12:41 +03003149 auto rc = sendSctpMsg(message.peerInfo, message, sctpMap);
ss412g1a79bdf2019-10-24 12:03:05 +03003150 return rc;
3151}
3152
ss412g1a79bdf2019-10-24 12:03:05 +03003153
3154/**
3155 *
3156 * @param epoll_fd
3157 * @param peerInfo
3158 * @param events
3159 * @param sctpMap
3160 * @param enodbName
3161 * @param msgType
ss412g1a79bdf2019-10-24 12:03:05 +03003162 * @return
3163 */
3164int addToEpoll(int epoll_fd,
3165 ConnectedCU_t *peerInfo,
3166 uint32_t events,
3167 Sctp_Map_t *sctpMap,
3168 char *enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02003169 int msgType) {
ss412g1a79bdf2019-10-24 12:03:05 +03003170 // Add to Epol
3171 struct epoll_event event{};
3172 event.data.ptr = peerInfo;
3173 event.events = events;
3174 if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peerInfo->fileDescriptor, &event) < 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -03003175#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03003176 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003177 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here), %s, %s %d",
ss412g1a79bdf2019-10-24 12:03:05 +03003178 strerror(errno), __func__, __LINE__);
3179 }
3180 close(peerInfo->fileDescriptor);
aa7133@att.com84bd3342020-03-16 18:04:57 +02003181 if (enodbName != nullptr) {
aa7133@att.combe92d712020-03-18 17:30:39 +02003182 cleanHashEntry(peerInfo, sctpMap);
aa7133@att.com84bd3342020-03-16 18:04:57 +02003183 char key[MAX_ENODB_NAME_SIZE * 2];
3184 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
3185 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3186 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
3187 }
3188 auto tmp = sctpMap->find(key);
3189 if (tmp) {
3190 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05303191 tmp = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +02003192 sctpMap->erase(key);
3193 }
3194 } else {
3195 peerInfo->enodbName[0] = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03003196 }
aa7133@att.com409f2232020-10-29 13:06:45 +03003197 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here)");
ss412g1a79bdf2019-10-24 12:03:05 +03003198 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -04003199#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003200 }
ss412g1a79bdf2019-10-24 12:03:05 +03003201 return 0;
3202}
3203
3204/**
3205 *
3206 * @param epoll_fd
3207 * @param peerInfo
3208 * @param events
3209 * @param sctpMap
3210 * @param enodbName
3211 * @param msgType
ss412g1a79bdf2019-10-24 12:03:05 +03003212 * @return
3213 */
3214int modifyToEpoll(int epoll_fd,
3215 ConnectedCU_t *peerInfo,
3216 uint32_t events,
3217 Sctp_Map_t *sctpMap,
3218 char *enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02003219 int msgType) {
ss412g1a79bdf2019-10-24 12:03:05 +03003220 // Add to Epol
3221 struct epoll_event event{};
3222 event.data.ptr = peerInfo;
3223 event.events = events;
3224 if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, peerInfo->fileDescriptor, &event) < 0) {
3225 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003226 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_MOD (may check not to quit here), %s, %s %d",
ss412g1a79bdf2019-10-24 12:03:05 +03003227 strerror(errno), __func__, __LINE__);
3228 }
3229 close(peerInfo->fileDescriptor);
aa7133@att.combe92d712020-03-18 17:30:39 +02003230 cleanHashEntry(peerInfo, sctpMap);
ss412g1a79bdf2019-10-24 12:03:05 +03003231 char key[MAX_ENODB_NAME_SIZE * 2];
3232 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
3233 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3234 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
3235 }
aa7133@att.com96c9b882020-03-25 14:50:40 +02003236 auto tmp = sctpMap->find(key);
ss412g1a79bdf2019-10-24 12:03:05 +03003237 if (tmp) {
3238 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05303239 tmp = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03003240 sctpMap->erase(key);
sandeekuea662102022-11-08 18:51:20 +05303241 }
aa7133@att.com409f2232020-10-29 13:06:45 +03003242 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here)");
ss412g1a79bdf2019-10-24 12:03:05 +03003243 return -1;
3244 }
ss412g1a79bdf2019-10-24 12:03:05 +03003245 return 0;
3246}
3247
3248
aa7133@att.combe92d712020-03-18 17:30:39 +02003249int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message) {
ss412g1a79bdf2019-10-24 12:03:05 +03003250 buildJsonMessage(message);
dhirajverma60f8bef2021-06-29 07:22:58 -04003251#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03003252 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003253#else
dhirajverma99990292021-07-05 10:03:59 -04003254 rmrMessageBuffer.sendMessage->state = RMR_ERR_RETRY;
dhirajverma60f8bef2021-06-29 07:22:58 -04003255#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003256 if (rmrMessageBuffer.sendMessage == nullptr) {
3257 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
3258 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
ss412g1a79bdf2019-10-24 12:03:05 +03003259 return -1;
3260 }
3261
3262 if (rmrMessageBuffer.sendMessage->state != 0) {
3263 char meid[RMR_MAX_MEID]{};
3264 if (rmrMessageBuffer.sendMessage->state == RMR_ERR_RETRY) {
3265 usleep(5);
3266 rmrMessageBuffer.sendMessage->state = 0;
3267 mdclog_write(MDCLOG_INFO, "RETRY sending Message type %d to Xapp from %s",
3268 rmrMessageBuffer.sendMessage->mtype,
3269 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
dhirajverma60f8bef2021-06-29 07:22:58 -04003270#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03003271 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003272#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003273 if (rmrMessageBuffer.sendMessage == nullptr) {
3274 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
3275 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g1a79bdf2019-10-24 12:03:05 +03003276 return -1;
3277 } else if (rmrMessageBuffer.sendMessage->state != 0) {
3278 mdclog_write(MDCLOG_ERR,
3279 "Message state %s while sending request %d to Xapp from %s after retry of 10 microseconds",
3280 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
3281 rmrMessageBuffer.sendMessage->mtype,
3282 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
3283 auto rc = rmrMessageBuffer.sendMessage->state;
ss412g1a79bdf2019-10-24 12:03:05 +03003284 return rc;
3285 }
3286 } else {
3287 mdclog_write(MDCLOG_ERR, "Message state %s while sending request %d to Xapp from %s",
3288 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
3289 rmrMessageBuffer.sendMessage->mtype,
3290 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
ss412g1a79bdf2019-10-24 12:03:05 +03003291 return rmrMessageBuffer.sendMessage->state;
3292 }
3293 }
3294 return 0;
3295}
3296
3297void buildJsonMessage(ReportingMessages_t &message) {
dhirajverma60f8bef2021-06-29 07:22:58 -04003298#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04003299 jsonTrace = true;
dhirajverma60f8bef2021-06-29 07:22:58 -04003300#endif
ss412g3bac2da2020-01-05 11:52:19 +02003301 if (jsonTrace) {
3302 message.outLen = sizeof(message.base64Data);
3303 base64::encode((const unsigned char *) message.message.asndata,
3304 (const int) message.message.asnLength,
3305 message.base64Data,
3306 message.outLen);
3307 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03003308 mdclog_write(MDCLOG_DEBUG, "Tracing: ASN length = %d, base64 message length = %d ",
ss412g3bac2da2020-01-05 11:52:19 +02003309 (int) message.message.asnLength,
3310 (int) message.outLen);
3311 }
3312
3313 snprintf(message.buffer, sizeof(message.buffer),
aa7133@att.com96c9b882020-03-25 14:50:40 +02003314 "{\"header\": {\"ts\": \"%ld.%09ld\","
3315 "\"ranName\": \"%s\","
3316 "\"messageType\": %d,"
3317 "\"direction\": \"%c\"},"
3318 "\"base64Length\": %d,"
3319 "\"asnBase64\": \"%s\"}",
3320 message.message.time.tv_sec,
3321 message.message.time.tv_nsec,
3322 message.message.enodbName,
3323 message.message.messageType,
3324 message.message.direction,
3325 (int) message.outLen,
3326 message.base64Data);
ss412g3bac2da2020-01-05 11:52:19 +02003327 static src::logger_mt &lg = my_logger::get();
3328
3329 BOOST_LOG(lg) << message.buffer;
ss412g1a79bdf2019-10-24 12:03:05 +03003330 }
ss412g1a79bdf2019-10-24 12:03:05 +03003331}
3332
3333
3334/**
3335 * take RMR error code to string
3336 * @param state
3337 * @return
3338 */
3339string translateRmrErrorMessages(int state) {
3340 string str = {};
3341 switch (state) {
3342 case RMR_OK:
3343 str = "RMR_OK - state is good";
3344 break;
3345 case RMR_ERR_BADARG:
aa7133@att.com409f2232020-10-29 13:06:45 +03003346 str = "RMR_ERR_BADARG - argument passed to function was unusable";
ss412g1a79bdf2019-10-24 12:03:05 +03003347 break;
3348 case RMR_ERR_NOENDPT:
3349 str = "RMR_ERR_NOENDPT - send//call could not find an endpoint based on msg type";
3350 break;
3351 case RMR_ERR_EMPTY:
3352 str = "RMR_ERR_EMPTY - msg received had no payload; attempt to send an empty message";
3353 break;
3354 case RMR_ERR_NOHDR:
3355 str = "RMR_ERR_NOHDR - message didn't contain a valid header";
3356 break;
3357 case RMR_ERR_SENDFAILED:
3358 str = "RMR_ERR_SENDFAILED - send failed; errno has nano reason";
3359 break;
3360 case RMR_ERR_CALLFAILED:
3361 str = "RMR_ERR_CALLFAILED - unable to send call() message";
3362 break;
3363 case RMR_ERR_NOWHOPEN:
3364 str = "RMR_ERR_NOWHOPEN - no wormholes are open";
3365 break;
3366 case RMR_ERR_WHID:
3367 str = "RMR_ERR_WHID - wormhole id was invalid";
3368 break;
3369 case RMR_ERR_OVERFLOW:
3370 str = "RMR_ERR_OVERFLOW - operation would have busted through a buffer/field size";
3371 break;
3372 case RMR_ERR_RETRY:
3373 str = "RMR_ERR_RETRY - request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)";
3374 break;
3375 case RMR_ERR_RCVFAILED:
3376 str = "RMR_ERR_RCVFAILED - receive failed (hard error)";
3377 break;
3378 case RMR_ERR_TIMEOUT:
3379 str = "RMR_ERR_TIMEOUT - message processing call timed out";
3380 break;
3381 case RMR_ERR_UNSET:
3382 str = "RMR_ERR_UNSET - the message hasn't been populated with a transport buffer";
3383 break;
3384 case RMR_ERR_TRUNC:
3385 str = "RMR_ERR_TRUNC - received message likely truncated";
3386 break;
3387 case RMR_ERR_INITFAILED:
3388 str = "RMR_ERR_INITFAILED - initialisation of something (probably message) failed";
3389 break;
3390 case RMR_ERR_NOTSUPP:
3391 str = "RMR_ERR_NOTSUPP - the request is not supported, or RMr was not initialised for the request";
3392 break;
3393 default:
3394 char buf[128]{};
3395 snprintf(buf, sizeof buf, "UNDOCUMENTED RMR_ERR : %d", state);
3396 str = buf;
3397 break;
3398 }
3399 return str;
3400}
czichy2175dd32022-05-17 15:24:51 +03003401int fetchStreamId(ConnectedCU_t *peerInfo, ReportingMessages_t &message)
3402{
3403 auto loglevel = mdclog_level_get();
3404 int streamId = INVALID_STREAM_ID;
3405 if(message.peerInfo->isSingleStream != false)
3406 {
3407 streamId = message.peerInfo->singleStreamId;
3408 if (loglevel >= MDCLOG_DEBUG) {
3409 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for SINGLE_STREAM streamId %d , Messeage Type %d ,%s",
3410 streamId,message.message.messageType, __FUNCTION__);
3411 }
3412 return streamId;
3413 }
3414 int msgType = message.message.messageType;
3415 switch (msgType){
3416 case RIC_E2_RESET_REQ:
3417 case RIC_E2_RESET_RESP:
3418 case RIC_E2_SETUP_RESP:
3419 case RIC_E2_SETUP_FAILURE:
3420 case RIC_ERROR_INDICATION:
3421 case RIC_SERVICE_QUERY:
3422 case RIC_SERVICE_UPDATE_ACK:
3423 case RIC_SERVICE_UPDATE_FAILURE:
3424 streamId = 0;
3425 break;
3426 case RIC_SUB_REQ:
3427 case RIC_SUB_DEL_REQ:
3428 case RIC_CONTROL_REQ:
3429 streamId = 1;
3430 break;
3431 default:
3432 streamId = 0;
3433 break;
3434 }
3435 if (loglevel >= MDCLOG_DEBUG) {
3436 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for streamId %d Messeage Type %d, %s",
3437 streamId, message.message.messageType, __FUNCTION__);
3438 }
3439 return streamId;
3440}