blob: 87eb5e6f7f460d1fc9e5e0d537e6feb019080687 [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. */
Alexandre Huff019cb422023-04-11 10:56:48 -0300921 if(peerInfo) {
dhirajverma9f59b572021-07-23 02:36:13 -0400922 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530923 peerInfo = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -0300924 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200925 break;
926 } else {
Alexandre Huff019cb422023-04-11 10:56:48 -0300927 if(peerInfo) {
dhirajverma9f59b572021-07-23 02:36:13 -0400928 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530929 peerInfo = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -0300930 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200931 mdclog_write(MDCLOG_ERR, "Accept error, errno = %s", strerror(errno));
932 break;
933 }
934 }
935 if (setSocketNoBlocking(peerInfo->fileDescriptor) == -1) {
936 mdclog_write(MDCLOG_ERR, "setSocketNoBlocking failed to set new connection %s on port %s\n", hostBuff, portBuff);
937 close(peerInfo->fileDescriptor);
Alexandre Huff019cb422023-04-11 10:56:48 -0300938 if(peerInfo) {
dhirajverma9f59b572021-07-23 02:36:13 -0400939 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530940 peerInfo = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -0300941 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200942 break;
Alexandre Hufffff97942023-03-31 21:22:20 -0300943#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +0200944 }
czichy2175dd32022-05-17 15:24:51 +0300945 struct sctp_event_subscribe sctpevents;
946 memset( (void *)&sctpevents, 0, sizeof(sctpevents) );
947 sctpevents.sctp_data_io_event = 1;
948 setsockopt(peerInfo->fileDescriptor, SOL_SCTP, SCTP_EVENTS,(const void *)&sctpevents, sizeof(sctpevents) );
949
aa7133@att.com84bd3342020-03-16 18:04:57 +0200950 auto ans = getnameinfo(&in_addr, in_len,
aa7133@att.com96c9b882020-03-25 14:50:40 +0200951 peerInfo->hostName, NI_MAXHOST,
952 peerInfo->portNumber, NI_MAXSERV, (unsigned )((unsigned int)NI_NUMERICHOST | (unsigned int)NI_NUMERICSERV));
aa7133@att.com84bd3342020-03-16 18:04:57 +0200953 if (ans < 0) {
954 mdclog_write(MDCLOG_ERR, "Failed to get info on connection request. %s\n", strerror(errno));
955 close(peerInfo->fileDescriptor);
Alexandre Huff019cb422023-04-11 10:56:48 -0300956 if(peerInfo) {
dhirajverma9f59b572021-07-23 02:36:13 -0400957 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530958 peerInfo = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -0300959 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200960 break;
961 }
962 if (mdclog_level_get() >= MDCLOG_DEBUG) {
963 mdclog_write(MDCLOG_DEBUG, "Accepted connection on descriptor %d (host=%s, port=%s)\n", peerInfo->fileDescriptor, peerInfo->hostName, peerInfo->portNumber);
964 }
965 peerInfo->isConnected = false;
966 peerInfo->gotSetup = false;
967 if (addToEpoll(params->epoll_fd,
968 peerInfo,
969 (EPOLLIN | EPOLLET),
970 params->sctpMap, nullptr,
aa7133@att.combe92d712020-03-18 17:30:39 +0200971 0) != 0) {
Alexandre Huff019cb422023-04-11 10:56:48 -0300972 if(peerInfo) {
dhirajverma9f59b572021-07-23 02:36:13 -0400973 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530974 peerInfo = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -0300975 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200976 break;
977 }
aa7133@att.com6680c3b2020-03-22 12:06:58 +0200978 break;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200979 }
ss412g1a79bdf2019-10-24 12:03:05 +0300980 } else if (params->rmrListenFd == events[i].data.fd) {
981 // got message from XAPP
aa7133@att.comde40d1c2020-08-26 16:19:20 +0300982 //num_of_XAPP_messages.fetch_add(1, std::memory_order_release);
ss412g1a79bdf2019-10-24 12:03:05 +0300983 num_of_messages.fetch_add(1, std::memory_order_release);
984 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comf13529a2020-08-27 11:21:16 +0300985 mdclog_write(MDCLOG_DEBUG, "new RMR message");
ss412g1a79bdf2019-10-24 12:03:05 +0300986 }
aa7133@att.com6680c3b2020-03-22 12:06:58 +0200987 if (receiveXappMessages(params->sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +0300988 rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +0200989 message.message.time) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +0300990 mdclog_write(MDCLOG_ERR, "Error handling Xapp message");
991 }
ss412g3bac2da2020-01-05 11:52:19 +0200992 } else if (params->inotifyFD == events[i].data.fd) {
993 mdclog_write(MDCLOG_INFO, "Got event from inotify (configuration update)");
994 handleConfigChange(params);
ss412g1a79bdf2019-10-24 12:03:05 +0300995 } else {
996 /* We RMR_ERR_RETRY have data on the fd waiting to be read. Read and display it.
997 * We must read whatever data is available completely, as we are running
998 * in edge-triggered mode and won't get a notification again for the same data. */
999 num_of_messages.fetch_add(1, std::memory_order_release);
1000 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1001 mdclog_write(MDCLOG_DEBUG, "new message from SCTP, epoll flags are : %0x", events[i].events);
1002 }
1003 receiveDataFromSctp(&events[i],
1004 params->sctpMap,
1005 num_of_SCTP_messages,
1006 rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001007 message.message.time);
ss412g1a79bdf2019-10-24 12:03:05 +03001008 }
1009
1010 clock_gettime(CLOCK_MONOTONIC, &end);
1011 if (mdclog_level_get() >= MDCLOG_INFO) {
1012 totalTime += ((end.tv_sec + 1.0e-9 * end.tv_nsec) -
1013 ((double) start.tv_sec + 1.0e-9 * start.tv_nsec));
1014 }
1015 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1016 mdclog_write(MDCLOG_DEBUG, "message handling is %ld seconds %ld nanoseconds",
1017 end.tv_sec - start.tv_sec,
1018 end.tv_nsec - start.tv_nsec);
1019 }
1020 }
dhirajverma6cf28612021-06-23 04:53:34 -04001021#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04001022 break;
dhirajverma6cf28612021-06-23 04:53:34 -04001023#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001024 }
ss412g1a79bdf2019-10-24 12:03:05 +03001025}
1026
1027/**
1028 *
ss412g3bac2da2020-01-05 11:52:19 +02001029 * @param sctpParams
1030 */
1031void handleConfigChange(sctp_params_t *sctpParams) {
1032 char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event))));
1033 const struct inotify_event *event;
1034 char *ptr;
dhirajverma60f8bef2021-06-29 07:22:58 -04001035#ifdef UNIT_TEST
1036 struct inotify_event tmpEvent;
1037#endif
ss412g3bac2da2020-01-05 11:52:19 +02001038 path p = (sctpParams->configFilePath + "/" + sctpParams->configFileName).c_str();
1039 auto endlessLoop = true;
1040 while (endlessLoop) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001041#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
dhirajverma93b6d9c2021-07-10 00:49:13 -04001042 auto len = read(sctpParams->inotifyFD, buf, sizeof buf);
dhirajverma60f8bef2021-06-29 07:22:58 -04001043#else
1044 auto len=10;
1045#endif
ss412g3bac2da2020-01-05 11:52:19 +02001046 if (len == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001047#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001048 if (errno != EAGAIN) {
1049 mdclog_write(MDCLOG_ERR, "read %s ", strerror(errno));
1050 endlessLoop = false;
1051 continue;
1052 }
1053 else {
1054 endlessLoop = false;
1055 continue;
1056 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001057#endif
ss412g3bac2da2020-01-05 11:52:19 +02001058 }
1059
1060 for (ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + event->len) {
dhirajverma60f8bef2021-06-29 07:22:58 -04001061#ifndef UNIT_TEST
1062 event = (const struct inotify_event *)ptr;
1063#else
1064 tmpEvent.mask = (uint32_t)IN_CLOSE_WRITE;
1065 event = &tmpEvent;
1066#endif
ss412g3bac2da2020-01-05 11:52:19 +02001067 if (event->mask & (uint32_t)IN_ISDIR) {
1068 continue;
1069 }
1070
1071 // the directory name
1072 if (sctpParams->inotifyWD == event->wd) {
1073 // not the directory
1074 }
1075 if (event->len) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001076#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comdfc1db92020-03-31 17:32:04 +03001077 auto retVal = strcmp(sctpParams->configFileName.c_str(), event->name);
1078 if (retVal != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001079 continue;
1080 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001081#endif
ss412g3bac2da2020-01-05 11:52:19 +02001082 }
1083 // only the file we want
1084 if (event->mask & (uint32_t)IN_CLOSE_WRITE) {
aa7133@att.comdfc1db92020-03-31 17:32:04 +03001085 if (mdclog_level_get() >= MDCLOG_INFO) {
1086 mdclog_write(MDCLOG_INFO, "Configuration file changed");
1087 }
ss412g3bac2da2020-01-05 11:52:19 +02001088 if (exists(p)) {
1089 const int size = 2048;
1090 auto fileSize = file_size(p);
1091 if (fileSize > size) {
1092 mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size);
1093 return;
1094 }
1095 } else {
1096 mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str());
1097 return;
1098 }
1099
1100 ReadConfigFile conf;
1101 if (conf.openConfigFile(p.string()) == -1) {
1102 mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s",
1103 p.string().c_str(), strerror(errno));
1104 return;
1105 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001106 auto tmpStr = conf.getStringValue("trace");
ss412g3bac2da2020-01-05 11:52:19 +02001107 if (tmpStr.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +03001108 mdclog_write(MDCLOG_ERR, "illegal trace. Set trace to stop");
ss412g3bac2da2020-01-05 11:52:19 +02001109 tmpStr = "stop";
1110 }
1111
1112 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
1113 if ((tmpStr.compare("start")) == 0) {
1114 mdclog_write(MDCLOG_INFO, "Trace set to: start");
1115 sctpParams->trace = true;
1116 } else if ((tmpStr.compare("stop")) == 0) {
1117 mdclog_write(MDCLOG_INFO, "Trace set to: stop");
1118 sctpParams->trace = false;
1119 } else {
1120 mdclog_write(MDCLOG_ERR, "Trace was set to wrong value %s, set to stop", tmpStr.c_str());
1121 sctpParams->trace = false;
1122 }
1123 jsonTrace = sctpParams->trace;
ss412g4aeeda22020-06-16 14:12:41 +03001124
ss412g4aeeda22020-06-16 14:12:41 +03001125
ss412g3bac2da2020-01-05 11:52:19 +02001126 endlessLoop = false;
1127 }
dhirajverma60f8bef2021-06-29 07:22:58 -04001128#ifdef UNIT_TEST
1129 break;
1130#endif
ss412g3bac2da2020-01-05 11:52:19 +02001131 }
1132 }
1133}
1134
1135/**
1136 *
1137 * @param event
1138 * @param message
1139 * @param rmrMessageBuffer
1140 * @param params
ss412g3bac2da2020-01-05 11:52:19 +02001141 */
1142void handleEinprogressMessages(struct epoll_event &event,
1143 ReportingMessages_t &message,
1144 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001145 sctp_params_t *params) {
ss412g3bac2da2020-01-05 11:52:19 +02001146 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
1147 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1148
1149 mdclog_write(MDCLOG_INFO, "file descriptor %d got EPOLLOUT", peerInfo->fileDescriptor);
1150 auto retVal = 0;
1151 socklen_t retValLen = 0;
1152 auto rc = getsockopt(peerInfo->fileDescriptor, SOL_SOCKET, SO_ERROR, &retVal, &retValLen);
1153 if (rc != 0 || retVal != 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001154#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001155 if (rc != 0) {
1156 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1157 "%s|Failed SCTP Connection, after EINPROGRESS the getsockopt%s",
1158 peerInfo->enodbName, strerror(errno));
1159 } else if (retVal != 0) {
1160 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1161 "%s|Failed SCTP Connection after EINPROGRESS, SO_ERROR",
1162 peerInfo->enodbName);
1163 }
1164
1165 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1166 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
1167 mdclog_write(MDCLOG_ERR, "%s", rmrMessageBuffer.sendMessage->payload);
1168 message.message.direction = 'N';
aa7133@att.combe92d712020-03-18 17:30:39 +02001169 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001170 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1171 }
dhirajverma31768a92021-05-06 12:38:49 +05301172#endif
ss412g3bac2da2020-01-05 11:52:19 +02001173 memset(peerInfo->asnData, 0, peerInfo->asnLength);
1174 peerInfo->asnLength = 0;
1175 peerInfo->mtype = 0;
ss412g3bac2da2020-01-05 11:52:19 +02001176 return;
1177 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001178#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001179 peerInfo->isConnected = true;
1180
1181 if (modifyToEpoll(params->epoll_fd, peerInfo, (EPOLLIN | EPOLLET), params->sctpMap, peerInfo->enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02001182 peerInfo->mtype) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001183 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_MOD");
ss412g3bac2da2020-01-05 11:52:19 +02001184 return;
1185 }
1186
1187 message.message.asndata = (unsigned char *)peerInfo->asnData;
1188 message.message.asnLength = peerInfo->asnLength;
1189 message.message.messageType = peerInfo->mtype;
1190 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1191 num_of_messages.fetch_add(1, std::memory_order_release);
1192 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1193 mdclog_write(MDCLOG_DEBUG, "send the delayed SETUP/ENDC SETUP to sctp for %s",
1194 message.message.enodbName);
1195 }
aa7133@att.combe92d712020-03-18 17:30:39 +02001196 if (sendSctpMsg(peerInfo, message, params->sctpMap) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001197 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1198 mdclog_write(MDCLOG_DEBUG, "Error write to SCTP %s %d", __func__, __LINE__);
1199 }
ss412g3bac2da2020-01-05 11:52:19 +02001200 return;
1201 }
1202
1203 memset(peerInfo->asnData, 0, peerInfo->asnLength);
1204 peerInfo->asnLength = 0;
1205 peerInfo->mtype = 0;
Alexandre Hufffff97942023-03-31 21:22:20 -03001206#endif
ss412g3bac2da2020-01-05 11:52:19 +02001207}
1208
1209
1210void handlepoll_error(struct epoll_event &event,
1211 ReportingMessages_t &message,
1212 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001213 sctp_params_t *params) {
sandeekuea662102022-11-08 18:51:20 +05301214 if ((event.data.fd != params->rmrListenFd) && (event.data.ptr != nullptr)) {
ss412g3bac2da2020-01-05 11:52:19 +02001215 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
1216 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on fd %d, RAN NAME : %s",
1217 event.events, peerInfo->fileDescriptor, peerInfo->enodbName);
dhirajverma93b6d9c2021-07-10 00:49:13 -04001218#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001219 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1220 "%s|Failed SCTP Connection",
1221 peerInfo->enodbName);
1222 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1223 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
1224
1225 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1226 message.message.direction = 'N';
aa7133@att.combe92d712020-03-18 17:30:39 +02001227 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001228 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1229 }
dhirajverma31768a92021-05-06 12:38:49 +05301230#endif
ss412g3bac2da2020-01-05 11:52:19 +02001231 close(peerInfo->fileDescriptor);
sandeekuea662102022-11-08 18:51:20 +05301232 //params->sctpMap->erase(peerInfo->enodbName);
aa7133@att.combe92d712020-03-18 17:30:39 +02001233 cleanHashEntry((ConnectedCU_t *) event.data.ptr, params->sctpMap);
ss412g3bac2da2020-01-05 11:52:19 +02001234 } else {
1235 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on RMR FD", event.events);
1236 }
ss412g3bac2da2020-01-05 11:52:19 +02001237}
1238/**
1239 *
ss412g1a79bdf2019-10-24 12:03:05 +03001240 * @param socket
1241 * @return
1242 */
1243int setSocketNoBlocking(int socket) {
1244 auto flags = fcntl(socket, F_GETFL, 0);
1245
1246 if (flags == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +03001247 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03001248 return -1;
1249 }
1250
1251 flags = (unsigned) flags | (unsigned) O_NONBLOCK;
1252 if (fcntl(socket, F_SETFL, flags) == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +03001253 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03001254 return -1;
1255 }
1256
1257 return 0;
1258}
1259
1260/**
1261 *
1262 * @param val
1263 * @param m
ss412g1a79bdf2019-10-24 12:03:05 +03001264 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001265void cleanHashEntry(ConnectedCU_t *val, Sctp_Map_t *m) {
Alexandre Huff019cb422023-04-11 10:56:48 -03001266 if(val != nullptr) {
1267 char *dummy;
1268 auto port = (uint16_t) strtol(val->portNumber, &dummy, 10);
1269 char searchBuff[2048]{};
ss412g1a79bdf2019-10-24 12:03:05 +03001270
Alexandre Huff019cb422023-04-11 10:56:48 -03001271 snprintf(searchBuff, sizeof searchBuff, "host:%s:%d", val->hostName, port);
1272 if(m->find(searchBuff)) {
1273 m->erase(searchBuff);
1274 }
ss412g1a79bdf2019-10-24 12:03:05 +03001275
Alexandre Huff019cb422023-04-11 10:56:48 -03001276 if(m->find(val->enodbName)) {
1277 mdclog_write(MDCLOG_DEBUG, "remove key enodbName = %s from %s at line %d", val->enodbName, __FUNCTION__, __LINE__);
1278 m->erase(val->enodbName);
1279 }
dhirajverma31768a92021-05-06 12:38:49 +05301280#ifndef UNIT_TEST
Alexandre Huff019cb422023-04-11 10:56:48 -03001281 if(val) {
1282 free(val);
1283 val = nullptr;
1284 }
dhirajverma31768a92021-05-06 12:38:49 +05301285#endif
sandeekuea662102022-11-08 18:51:20 +05301286 }
ss412g1a79bdf2019-10-24 12:03:05 +03001287}
1288
1289/**
1290 *
aa7133@att.com409f2232020-10-29 13:06:45 +03001291 * @param fd file descriptor
ss412g1a79bdf2019-10-24 12:03:05 +03001292 * @param data the asn data to send
1293 * @param len length of the data
1294 * @param enodbName the enodbName as in the map for printing purpose
1295 * @param m map host information
1296 * @param mtype message number
aa7133@att.com409f2232020-10-29 13:06:45 +03001297 * @return 0 success, a negative number on fail
ss412g1a79bdf2019-10-24 12:03:05 +03001298 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001299int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_t *m) {
ss412g1a79bdf2019-10-24 12:03:05 +03001300 auto loglevel = mdclog_level_get();
Alexandre Hufffff97942023-03-31 21:22:20 -03001301#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001302 int fd = peerInfo->fileDescriptor;
czichy2175dd32022-05-17 15:24:51 +03001303 int streamId = fetchStreamId(peerInfo,message);
dhirajverma99990292021-07-05 10:03:59 -04001304#else
1305 int fd = FILE_DESCRIPTOR;
czichy2175dd32022-05-17 15:24:51 +03001306 int streamId = 0;
Alexandre Hufffff97942023-03-31 21:22:20 -03001307#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001308 if (loglevel >= MDCLOG_DEBUG) {
1309 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for CU %s, %s",
1310 message.message.enodbName, __FUNCTION__);
1311 }
1312
1313 while (true) {
czichy6dd00bc2023-03-03 15:43:29 +02001314 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 +03001315 if (errno == EINTR) {
1316 continue;
1317 }
1318 mdclog_write(MDCLOG_ERR, "error writing to CU a message, %s ", strerror(errno));
Alexandre Hufffff97942023-03-31 21:22:20 -03001319#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +02001320 if (!peerInfo->isConnected) {
1321 mdclog_write(MDCLOG_ERR, "connection to CU %s is still in progress.", message.message.enodbName);
aa7133@att.com84bd3342020-03-16 18:04:57 +02001322 return -1;
1323 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001324#endif
Alexandre Hufffff97942023-03-31 21:22:20 -03001325#ifndef UNIT_TEST
aa7133@att.combe92d712020-03-18 17:30:39 +02001326 cleanHashEntry(peerInfo, m);
dhirajvermac40ea1f2021-07-08 12:52:30 -04001327 close(fd);
Alexandre Hufffff97942023-03-31 21:22:20 -03001328#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001329 char key[MAX_ENODB_NAME_SIZE * 2];
1330 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName,
1331 message.message.messageType);
1332 if (loglevel >= MDCLOG_DEBUG) {
1333 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
1334 }
aa7133@att.com96c9b882020-03-25 14:50:40 +02001335 auto tmp = m->find(key);
ss412g1a79bdf2019-10-24 12:03:05 +03001336 if (tmp) {
1337 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05301338 tmp = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03001339 }
1340 m->erase(key);
dhirajverma6cf28612021-06-23 04:53:34 -04001341#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001342 return -1;
dhirajverma6cf28612021-06-23 04:53:34 -04001343#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001344 }
1345 message.message.direction = 'D';
1346 // send report.buffer of size
1347 buildJsonMessage(message);
1348
1349 if (loglevel >= MDCLOG_DEBUG) {
1350 mdclog_write(MDCLOG_DEBUG,
1351 "SCTP message for CU %s sent from %s",
1352 message.message.enodbName,
1353 __FUNCTION__);
1354 }
ss412g1a79bdf2019-10-24 12:03:05 +03001355 return 0;
1356 }
1357}
1358
1359/**
1360 *
1361 * @param message
1362 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03001363 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001364void getRequestMetaData(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03001365 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
1366 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
1367
1368 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1369 mdclog_write(MDCLOG_DEBUG, "Message from Xapp RAN name = %s message length = %ld",
1370 message.message.enodbName, (unsigned long) message.message.asnLength);
1371 }
ss412g1a79bdf2019-10-24 12:03:05 +03001372}
1373
1374
ss412g1a79bdf2019-10-24 12:03:05 +03001375
1376/**
1377 *
1378 * @param events
1379 * @param sctpMap
1380 * @param numOfMessages
1381 * @param rmrMessageBuffer
1382 * @param ts
ss412g1a79bdf2019-10-24 12:03:05 +03001383 * @return
1384 */
1385int receiveDataFromSctp(struct epoll_event *events,
1386 Sctp_Map_t *sctpMap,
1387 int &numOfMessages,
1388 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001389 struct timespec &ts) {
ss412g1a79bdf2019-10-24 12:03:05 +03001390 /* We have data on the fd waiting to be read. Read and display it.
1391 * We must read whatever data is available completely, as we are running
1392 * in edge-triggered mode and won't get a notification again for the same data. */
aa7133@att.com84bd3342020-03-16 18:04:57 +02001393 ReportingMessages_t message {};
1394 auto done = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03001395 auto loglevel = mdclog_level_get();
czichy2175dd32022-05-17 15:24:51 +03001396 struct sctp_sndrcvinfo sndrcvinfo;
1397 int flags;
1398 int streamId;
aa7133@att.com84bd3342020-03-16 18:04:57 +02001399
ss412g1a79bdf2019-10-24 12:03:05 +03001400 // get the identity of the interface
sandeekuea662102022-11-08 18:51:20 +05301401 if (events->data.ptr != nullptr){
Alexandre Huff019cb422023-04-11 10:56:48 -03001402 message.peerInfo = (ConnectedCU_t *)events->data.ptr;
sandeekuea662102022-11-08 18:51:20 +05301403 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001404
ss412g1a79bdf2019-10-24 12:03:05 +03001405 struct timespec start{0, 0};
aa7133@att.com409f2232020-10-29 13:06:45 +03001406 struct timespec decodeStart{0, 0};
ss412g1a79bdf2019-10-24 12:03:05 +03001407 struct timespec end{0, 0};
1408
1409 E2AP_PDU_t *pdu = nullptr;
1410
ss412g1a79bdf2019-10-24 12:03:05 +03001411 while (true) {
1412 if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001413 mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP %d fd", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001414 clock_gettime(CLOCK_MONOTONIC, &start);
1415 }
1416 // read the buffer directly to rmr payload
1417 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
Alexandre Hufffff97942023-03-31 21:22:20 -03001418#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001419 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
czichy2175dd32022-05-17 15:24:51 +03001420 sctp_recvmsg(message.peerInfo->fileDescriptor, rmrMessageBuffer.sendMessage->payload, RECEIVE_SCTP_BUFFER_SIZE,(struct sockaddr *) NULL, 0, &sndrcvinfo, &flags);
1421 mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP fd %d stream %d ", message.peerInfo->fileDescriptor, sndrcvinfo.sinfo_stream);
1422 streamId = sndrcvinfo.sinfo_stream;
dhirajverma99990292021-07-05 10:03:59 -04001423#else
1424 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
czichy2175dd32022-05-17 15:24:51 +03001425 streamId = 0;
dhirajverma99990292021-07-05 10:03:59 -04001426#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +02001427
ss412g1a79bdf2019-10-24 12:03:05 +03001428 if (loglevel >= MDCLOG_DEBUG) {
1429 mdclog_write(MDCLOG_DEBUG, "Finish Read from SCTP %d fd message length = %ld",
aa7133@att.com96c9b882020-03-25 14:50:40 +02001430 message.peerInfo->fileDescriptor, message.message.asnLength);
ss412g1a79bdf2019-10-24 12:03:05 +03001431 }
aa7133@att.com16c799b2020-03-24 18:01:51 +02001432
aa7133@att.com84bd3342020-03-16 18:04:57 +02001433 memcpy(message.message.enodbName, message.peerInfo->enodbName, sizeof(message.peerInfo->enodbName));
ss412g1a79bdf2019-10-24 12:03:05 +03001434 message.message.direction = 'U';
1435 message.message.time.tv_nsec = ts.tv_nsec;
1436 message.message.time.tv_sec = ts.tv_sec;
1437
1438 if (message.message.asnLength < 0) {
1439 if (errno == EINTR) {
1440 continue;
1441 }
1442 /* If errno == EAGAIN, that means we have read all
aa7133@att.com84bd3342020-03-16 18:04:57 +02001443 data. So goReportingMessages_t back to the main loop. */
ss412g1a79bdf2019-10-24 12:03:05 +03001444 if (errno != EAGAIN) {
1445 mdclog_write(MDCLOG_ERR, "Read error, %s ", strerror(errno));
1446 done = 1;
1447 } else if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001448 mdclog_write(MDCLOG_DEBUG, "EAGAIN - descriptor = %d", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001449 }
1450 break;
1451 } else if (message.message.asnLength == 0) {
1452 /* End of file. The remote has closed the connection. */
1453 if (loglevel >= MDCLOG_INFO) {
1454 mdclog_write(MDCLOG_INFO, "END of File Closed connection - descriptor = %d",
aa7133@att.com84bd3342020-03-16 18:04:57 +02001455 message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001456 }
1457 done = 1;
1458 break;
1459 }
1460
ss412g1a79bdf2019-10-24 12:03:05 +03001461 if (loglevel >= MDCLOG_DEBUG) {
swc58d4f5d2020-10-20 15:08:38 +09001462 char printBuffer[RECEIVE_SCTP_BUFFER_SIZE]{};
ss412g1a79bdf2019-10-24 12:03:05 +03001463 char *tmp = printBuffer;
1464 for (size_t i = 0; i < (size_t)message.message.asnLength; ++i) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001465 snprintf(tmp, 3, "%02x", message.message.asndata[i]);
ss412g1a79bdf2019-10-24 12:03:05 +03001466 tmp += 2;
1467 }
1468 printBuffer[message.message.asnLength] = 0;
1469 clock_gettime(CLOCK_MONOTONIC, &end);
1470 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 +02001471 message.peerInfo->enodbName, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001472 mdclog_write(MDCLOG_DEBUG, "PDU buffer length = %ld, data = : %s", message.message.asnLength,
1473 printBuffer);
aa7133@att.com409f2232020-10-29 13:06:45 +03001474 clock_gettime(CLOCK_MONOTONIC, &decodeStart);
ss412g1a79bdf2019-10-24 12:03:05 +03001475 }
dhirajverma99990292021-07-05 10:03:59 -04001476#ifndef UNIT_TEST
aa7133@att.com7b437f72020-03-30 13:25:54 +03001477 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu,
dhirajverma99990292021-07-05 10:03:59 -04001478 message.message.asndata, message.message.asnLength);
1479#else
1480 asn_dec_rval_t rval = {RC_OK, 0};
1481 pdu = (E2AP_PDU_t*)rmrMessageBuffer.sendMessage->tp_buf;
1482#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001483 if (rval.code != RC_OK) {
1484 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from RAN : %s", rval.code,
aa7133@att.com84bd3342020-03-16 18:04:57 +02001485 message.peerInfo->enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04001486 if (pdu != nullptr) {
1487 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1488 pdu = nullptr;
1489 }
ss412g1a79bdf2019-10-24 12:03:05 +03001490 break;
1491 }
1492
1493 if (loglevel >= MDCLOG_DEBUG) {
1494 clock_gettime(CLOCK_MONOTONIC, &end);
1495 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 +03001496 message.peerInfo->enodbName, end.tv_sec - decodeStart.tv_sec, end.tv_nsec - decodeStart.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001497 char *printBuffer;
1498 size_t size;
1499 FILE *stream = open_memstream(&printBuffer, &size);
1500 asn_fprint(stream, &asn_DEF_E2AP_PDU, pdu);
1501 mdclog_write(MDCLOG_DEBUG, "Encoding E2AP PDU past : %s", printBuffer);
aa7133@att.com409f2232020-10-29 13:06:45 +03001502 clock_gettime(CLOCK_MONOTONIC, &decodeStart);
Byonggon Chuncae9bd52020-11-18 13:37:29 +09001503
1504 fclose(stream);
1505 free(printBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001506 }
1507
1508 switch (pdu->present) {
1509 case E2AP_PDU_PR_initiatingMessage: {//initiating message
czichy2175dd32022-05-17 15:24:51 +03001510 asnInitiatingRequest(pdu, sctpMap,message, rmrMessageBuffer, streamId);
ss412g1a79bdf2019-10-24 12:03:05 +03001511 break;
1512 }
1513 case E2AP_PDU_PR_successfulOutcome: { //successful outcome
aa7133@att.com409f2232020-10-29 13:06:45 +03001514 asnSuccessfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001515 break;
1516 }
1517 case E2AP_PDU_PR_unsuccessfulOutcome: { //Unsuccessful Outcome
aa7133@att.com7b437f72020-03-30 13:25:54 +03001518 asnUnSuccsesfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001519 break;
1520 }
1521 default:
1522 mdclog_write(MDCLOG_ERR, "Unknown index %d in E2AP PDU", pdu->present);
1523 break;
1524 }
1525 if (loglevel >= MDCLOG_DEBUG) {
1526 clock_gettime(CLOCK_MONOTONIC, &end);
1527 mdclog_write(MDCLOG_DEBUG,
1528 "After processing message and sent to rmr for : %s, Read time is : %ld seconds, %ld nanoseconds",
aa7133@att.com409f2232020-10-29 13:06:45 +03001529 message.peerInfo->enodbName, end.tv_sec - decodeStart.tv_sec, end.tv_nsec - decodeStart.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001530 }
1531 numOfMessages++;
dhirajverma9f59b572021-07-23 02:36:13 -04001532#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001533 if (pdu != nullptr) {
dhirajverma9f59b572021-07-23 02:36:13 -04001534 // ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); /* With reset we were not freeing the memory and was causing the leak here. */
1535 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1536 pdu = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03001537 }
dhirajverma9f59b572021-07-23 02:36:13 -04001538#else
dhirajverma99990292021-07-05 10:03:59 -04001539 done = 1;
1540 break;
1541#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001542 }
ss412g1a79bdf2019-10-24 12:03:05 +03001543
1544 if (done) {
1545 if (loglevel >= MDCLOG_INFO) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001546 mdclog_write(MDCLOG_INFO, "Closed connection - descriptor = %d", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001547 }
1548 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
1549 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
aa7133@att.com96c9b882020-03-25 14:50:40 +02001550 256,
1551 "%s|CU disconnected unexpectedly",
1552 message.peerInfo->enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03001553 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
Alexandre Hufffff97942023-03-31 21:22:20 -03001554#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03001555 if (sendRequestToXapp(message,
1556 RIC_SCTP_CONNECTION_FAILURE,
aa7133@att.combe92d712020-03-18 17:30:39 +02001557 rmrMessageBuffer) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03001558 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1559 }
Alexandre Hufffff97942023-03-31 21:22:20 -03001560#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001561
1562 /* Closing descriptor make epoll remove it from the set of descriptors which are monitored. */
sandeekuea662102022-11-08 18:51:20 +05301563#ifndef UNIT_TEST
1564 pthread_mutex_lock(&thread_lock);
1565 if (fcntl(message.peerInfo->fileDescriptor, F_GETFD) != -1) {
1566 mdclog_write(MDCLOG_DEBUG, "Closing connection - descriptor = %d", message.peerInfo->fileDescriptor);
1567 close(message.peerInfo->fileDescriptor);
1568 cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap);
1569 }
1570 pthread_mutex_unlock(&thread_lock);
1571#else
aa7133@att.com84bd3342020-03-16 18:04:57 +02001572 close(message.peerInfo->fileDescriptor);
aa7133@att.combe92d712020-03-18 17:30:39 +02001573 cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap);
Alexandre Hufffff97942023-03-31 21:22:20 -03001574#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001575 }
1576 if (loglevel >= MDCLOG_DEBUG) {
1577 clock_gettime(CLOCK_MONOTONIC, &end);
1578 mdclog_write(MDCLOG_DEBUG, "from receive SCTP to send RMR time is %ld seconds and %ld nanoseconds",
1579 end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
1580
1581 }
ss412g1a79bdf2019-10-24 12:03:05 +03001582 return 0;
1583}
1584
aa7133@att.com409f2232020-10-29 13:06:45 +03001585static void buildAndSendSetupRequest(ReportingMessages_t &message,
aa7133@att.com84bd3342020-03-16 18:04:57 +02001586 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001587 E2AP_PDU_t *pdu/*,
ss412g4aeeda22020-06-16 14:12:41 +03001588 string const &messageName,
1589 string const &ieName,
1590 vector<string> &functionsToAdd_v,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001591 vector<string> &functionsToModified_v*/) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001592 auto logLevel = mdclog_level_get();
aa7133@att.com84bd3342020-03-16 18:04:57 +02001593 // now we can send the data to e2Mgr
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001594
ss412g4aeeda22020-06-16 14:12:41 +03001595 asn_enc_rval_t er;
1596 auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
Byonggon Chun51885f32020-11-18 15:31:04 +09001597 unsigned char *buffer = nullptr;
1598 buffer = (unsigned char *) calloc(buffer_size, sizeof(unsigned char));
1599 if(!buffer)
1600 {
Alexandre Hufffff97942023-03-31 21:22:20 -03001601#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
Byonggon Chun51885f32020-11-18 15:31:04 +09001602 mdclog_write(MDCLOG_ERR, "Allocating buffer for %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1603 return;
Alexandre Hufffff97942023-03-31 21:22:20 -03001604#endif
Byonggon Chun51885f32020-11-18 15:31:04 +09001605 }
ss412g4aeeda22020-06-16 14:12:41 +03001606 while (true) {
ss412g4aeeda22020-06-16 14:12:41 +03001607 er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size);
1608 if (er.encoded == -1) {
Alexandre Hufffff97942023-03-31 21:22:20 -03001609#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g4aeeda22020-06-16 14:12:41 +03001610 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1611 return;
Alexandre Hufffff97942023-03-31 21:22:20 -03001612#endif
ss412g4aeeda22020-06-16 14:12:41 +03001613 } else if (er.encoded > (ssize_t) buffer_size) {
1614 buffer_size = er.encoded + 128;
Alexandre Hufffff97942023-03-31 21:22:20 -03001615#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g4aeeda22020-06-16 14:12:41 +03001616 mdclog_write(MDCLOG_WARN, "Buffer of size %d is to small for %s. Reallocate buffer of size %d",
1617 (int) buffer_size,
1618 asn_DEF_E2AP_PDU.name, buffer_size);
1619 buffer_size = er.encoded + 128;
Byonggon Chun51885f32020-11-18 15:31:04 +09001620
1621 unsigned char *newBuffer = nullptr;
1622 newBuffer = (unsigned char *) realloc(buffer, buffer_size);
1623 if (!newBuffer)
1624 {
1625 // out of memory
1626 mdclog_write(MDCLOG_ERR, "Reallocating buffer for %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1627 free(buffer);
sandeekuea662102022-11-08 18:51:20 +05301628 buffer = nullptr;
Byonggon Chun51885f32020-11-18 15:31:04 +09001629 return;
1630 }
1631 buffer = newBuffer;
ss412g4aeeda22020-06-16 14:12:41 +03001632 continue;
Alexandre Hufffff97942023-03-31 21:22:20 -03001633#endif
ss412g4aeeda22020-06-16 14:12:41 +03001634 }
1635 buffer[er.encoded] = '\0';
1636 break;
1637 }
1638 // encode to xml
1639
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001640 string res((char *)buffer);
1641 res.erase(std::remove(res.begin(), res.end(), '\n'), res.end());
1642 res.erase(std::remove(res.begin(), res.end(), '\t'), res.end());
1643 res.erase(std::remove(res.begin(), res.end(), ' '), res.end());
1644
1645// string res {};
1646// if (!functionsToAdd_v.empty() || !functionsToModified_v.empty()) {
1647// res = buildXmlData(messageName, ieName, functionsToAdd_v, functionsToModified_v, buffer, (size_t) er.encoded);
1648// }
ss412g4aeeda22020-06-16 14:12:41 +03001649 rmr_mbuf_t *rmrMsg;
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001650// if (res.length() == 0) {
1651// rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size + 256);
1652// rmrMsg->len = snprintf((char *) rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s",
1653// message.peerInfo->sctpParams->myIP.c_str(),
1654// message.peerInfo->sctpParams->rmrPort,
1655// buffer);
1656// } else {
ss412g4aeeda22020-06-16 14:12:41 +03001657 rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, (int)res.length() + 256);
1658 rmrMsg->len = snprintf((char *) rmrMsg->payload, res.length() + 256, "%s:%d|%s",
1659 message.peerInfo->sctpParams->myIP.c_str(),
1660 message.peerInfo->sctpParams->rmrPort,
1661 res.c_str());
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001662// }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001663
ss412g4aeeda22020-06-16 14:12:41 +03001664 if (logLevel >= MDCLOG_DEBUG) {
1665 mdclog_write(MDCLOG_DEBUG, "Setup request of size %d :\n %s\n", rmrMsg->len, rmrMsg->payload);
1666 }
1667 // send to RMR
1668 rmrMsg->mtype = message.message.messageType;
1669 rmrMsg->state = 0;
1670 rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName));
aa7133@att.com84bd3342020-03-16 18:04:57 +02001671
ss412g4aeeda22020-06-16 14:12:41 +03001672 static unsigned char tx[32];
1673 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1674 rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx));
dhirajverma60f8bef2021-06-29 07:22:58 -04001675#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +03001676 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
dhirajverma60f8bef2021-06-29 07:22:58 -04001677#endif
ss412g4aeeda22020-06-16 14:12:41 +03001678 if (rmrMsg == nullptr) {
1679 mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr");
1680 } else if (rmrMsg->state != 0) {
1681 char meid[RMR_MAX_MEID]{};
1682 if (rmrMsg->state == RMR_ERR_RETRY) {
1683 usleep(5);
1684 rmrMsg->state = 0;
1685 mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s",
1686 rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid));
dhirajverma60f8bef2021-06-29 07:22:58 -04001687#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +03001688 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
dhirajverma60f8bef2021-06-29 07:22:58 -04001689#endif
ss412g4aeeda22020-06-16 14:12:41 +03001690 if (rmrMsg == nullptr) {
1691 mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr");
1692 } else if (rmrMsg->state != 0) {
1693 mdclog_write(MDCLOG_ERR,
1694 "RMR Retry failed %s sending request %d to Xapp from %s",
aa7133@att.com84bd3342020-03-16 18:04:57 +02001695 translateRmrErrorMessages(rmrMsg->state).c_str(),
1696 rmrMsg->mtype,
1697 rmr_get_meid(rmrMsg, (unsigned char *) meid));
1698 }
ss412g4aeeda22020-06-16 14:12:41 +03001699 } else {
1700 mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s",
1701 translateRmrErrorMessages(rmrMsg->state).c_str(),
1702 rmrMsg->mtype,
1703 rmr_get_meid(rmrMsg, (unsigned char *) meid));
aa7133@att.combc110772020-03-25 09:45:14 +02001704 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001705 }
ss412g4aeeda22020-06-16 14:12:41 +03001706 message.peerInfo->gotSetup = true;
1707 buildJsonMessage(message);
Byonggon Chun51885f32020-11-18 15:31:04 +09001708
ss412g4aeeda22020-06-16 14:12:41 +03001709 if (rmrMsg != nullptr) {
1710 rmr_free_msg(rmrMsg);
1711 }
Byonggon Chun51885f32020-11-18 15:31:04 +09001712 free(buffer);
sandeekuea662102022-11-08 18:51:20 +05301713 buffer = nullptr;
Byonggon Chun51885f32020-11-18 15:31:04 +09001714
1715 return;
aa7133@att.com84bd3342020-03-16 18:04:57 +02001716}
aa7133@att.comc5a15202020-04-05 19:57:01 +03001717
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001718#if 0
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001719int RAN_Function_list_To_Vector(RANfunctions_List_t& list, vector <string> &runFunXML_v) {
1720 auto index = 0;
1721 runFunXML_v.clear();
1722 for (auto j = 0; j < list.list.count; j++) {
1723 auto *raNfunctionItemIEs = (RANfunction_ItemIEs_t *)list.list.array[j];
1724 if (raNfunctionItemIEs->id == ProtocolIE_ID_id_RANfunction_Item &&
1725 (raNfunctionItemIEs->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item)) {
1726 // encode to xml
1727 E2SM_gNB_NRT_RANfunction_Definition_t *ranFunDef = nullptr;
1728 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER,
1729 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1730 (void **)&ranFunDef,
1731 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.buf,
1732 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.size);
1733 if (rval.code != RC_OK) {
1734 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2SM message from : %s",
1735 rval.code,
1736 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name);
1737 return -1;
1738 }
1739
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001740 auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1741 unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
ss412g4aeeda22020-06-16 14:12:41 +03001742 memset(xml_buffer, 0, RECEIVE_SCTP_BUFFER_SIZE * 2);
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001743 // encode to xml
1744 auto er = asn_encode_to_buffer(nullptr,
1745 ATS_BASIC_XER,
1746 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1747 ranFunDef,
1748 xml_buffer,
1749 xml_buffer_size);
1750 if (er.encoded == -1) {
1751 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s",
1752 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1753 strerror(errno));
1754 } else if (er.encoded > (ssize_t)xml_buffer_size) {
1755 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
1756 (int) xml_buffer_size,
1757 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, __func__, __LINE__);
1758 } else {
1759 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1760 mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU number %d : %s",
1761 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1762 index++,
1763 xml_buffer);
1764 }
ss412g4aeeda22020-06-16 14:12:41 +03001765
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001766 string runFuncs = (char *)(xml_buffer);
1767 runFunXML_v.emplace_back(runFuncs);
1768 }
1769 }
1770 }
1771 return 0;
1772}
aa7133@att.comc5a15202020-04-05 19:57:01 +03001773
ss412g4aeeda22020-06-16 14:12:41 +03001774int collectServiceUpdate_RequestData(E2AP_PDU_t *pdu,
1775 Sctp_Map_t *sctpMap,
1776 ReportingMessages_t &message,
1777 vector <string> &RANfunctionsAdded_v,
1778 vector <string> &RANfunctionsModified_v) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03001779 memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE);
ss412g4aeeda22020-06-16 14:12:41 +03001780 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.count; i++) {
1781 auto *ie = pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.array[i];
1782 if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
1783 if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctionsID_List) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03001784 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001785 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
1786 ie->value.choice.RANfunctions_List.list.count);
aa7133@att.comc5a15202020-04-05 19:57:01 +03001787 }
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001788 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) {
1789 return -1;
1790 }
1791 }
1792 } else if (ie->id == ProtocolIE_ID_id_RANfunctionsModified) {
ss412g4aeeda22020-06-16 14:12:41 +03001793 if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List) {
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001794 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1795 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
1796 ie->value.choice.RANfunctions_List.list.count);
1797 }
1798 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsModified_v) != 0 ) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001799 return -1;
aa7133@att.comc5a15202020-04-05 19:57:01 +03001800 }
1801 }
1802 }
1803 }
1804 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1805 mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries",
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001806 RANfunctionsAdded_v.size());
aa7133@att.comc5a15202020-04-05 19:57:01 +03001807 }
1808 return 0;
1809}
ss412g4aeeda22020-06-16 14:12:41 +03001810
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001811#endif
ss412g4aeeda22020-06-16 14:12:41 +03001812
1813
Mohamed Abukar64f37242021-08-15 12:39:56 +00001814void buildE2TPrometheusCounters(sctp_params_t &sctpParams) {
1815 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestMsgs"}});
1816 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestBytes"}});
1817
1818 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupResponseMsgs"}});
1819 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupResponseBytes"}});
1820
1821 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestFailureMsgs"}});
1822 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestFailureBytes"}});
1823
czichy2175dd32022-05-17 15:24:51 +03001824 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateMsgs"}});
1825 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateBytes"}});
1826
1827 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateResponseMsgs"}});
1828 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateResponseBytes"}});
1829
1830 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateFailureMsgs"}});
1831 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateFailureBytes"}});
1832
Mohamed Abukar64f37242021-08-15 12:39:56 +00001833 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &sctpParams.prometheusFamily->Add({{"counter", "ErrorIndicationMsgs"}});
1834 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &sctpParams.prometheusFamily->Add({{"counter", "ErrorIndicationBytes"}});
1835
1836 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetRequestMsgs"}});
1837 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetRequestBytes"}});
1838
1839 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetAckMsgs"}});
1840 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetAckBytes"}});
1841
1842 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateMsgs"}});
1843 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateBytes"}});
1844
1845 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateRespMsgs"}});
1846 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateRespBytes"}});
1847
1848 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateFailureMsgs"}});
1849 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateFailureBytes"}});
1850
1851 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlMsgs"}});
1852 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlBytes"}});
1853
1854 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlAckMsgs"}});
1855 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlAckBytes"}});
1856
1857 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlFailureMsgs"}});
1858 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlFailureBytes"}});
1859
1860 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionMsgs"}});
1861 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionBytes"}});
1862
1863 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionAckMsgs"}});
1864 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionAckBytes"}});
1865
1866 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionFailureMsgs"}});
1867 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionFailureBytes"}});
1868
1869 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteMsgs"}});
1870 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteBytes"}});
1871
1872 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteAckMsgs"}});
1873 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteAckBytes"}});
1874
1875 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteFailMsgs"}});
1876 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteFailBytes"}});
1877
1878 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication] = &sctpParams.prometheusFamily->Add({{"counter", "RICIndicationMsgs"}});
1879 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication] = &sctpParams.prometheusFamily->Add({{"counter", "RICIndicationBytes"}});
1880
1881 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceQueryMsgs"}});
1882 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceQueryBytes"}});
gunjarastogi85f507f2023-01-18 16:27:55 +05301883
1884 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteRequiredMsgs"}});
1885 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteRequiredBytes"}});
1886
Mohamed Abukar64f37242021-08-15 12:39:56 +00001887}
1888
aa7133@att.com409f2232020-10-29 13:06:45 +03001889void buildPrometheusList(ConnectedCU_t *peerInfo, Family<Counter> *prometheusFamily) {
aa7133@att.coma4c80012020-06-24 16:36:47 +03001890 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Messages"}});
1891 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001892
czichy2175dd32022-05-17 15:24:51 +03001893 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"E2NodeConfigUpdate", "Messages"}});
1894 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"E2NodeConfigUpdate", "Bytes"}});
1895
aa7133@att.coma4c80012020-06-24 16:36:47 +03001896 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Messages"}});
1897 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001898
aa7133@att.coma4c80012020-06-24 16:36:47 +03001899 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICindication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Messages"}});
1900 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICindication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001901
aa7133@att.coma4c80012020-06-24 16:36:47 +03001902 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Messages"}});
1903 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001904
aa7133@att.coma4c80012020-06-24 16:36:47 +03001905 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Messages"}});
1906 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001907 // ---------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03001908 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Messages"}});
1909 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001910
aa7133@att.coma4c80012020-06-24 16:36:47 +03001911 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Messages"}});
1912 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001913
aa7133@att.coma4c80012020-06-24 16:36:47 +03001914 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Messages"}});
1915 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001916
aa7133@att.coma4c80012020-06-24 16:36:47 +03001917 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Messages"}});
1918 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001919 //-------------------------------------------------------------
1920
aa7133@att.coma4c80012020-06-24 16:36:47 +03001921 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Messages"}});
1922 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001923
aa7133@att.coma4c80012020-06-24 16:36:47 +03001924 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Messages"}});
1925 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001926
aa7133@att.coma4c80012020-06-24 16:36:47 +03001927 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Messages"}});
1928 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001929
1930 //====================================================================================
aa7133@att.coma4c80012020-06-24 16:36:47 +03001931 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Messages"}});
1932 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001933
aa7133@att.coma4c80012020-06-24 16:36:47 +03001934 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Messages"}});
1935 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001936
aa7133@att.coma4c80012020-06-24 16:36:47 +03001937 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Messages"}});
1938 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001939
aa7133@att.coma4c80012020-06-24 16:36:47 +03001940 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceQuery)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Messages"}});
1941 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceQuery)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001942
aa7133@att.coma4c80012020-06-24 16:36:47 +03001943 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Messages"}});
1944 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001945
aa7133@att.coma4c80012020-06-24 16:36:47 +03001946 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Messages"}});
1947 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001948 //---------------------------------------------------------------------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03001949 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Messages"}});
1950 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001951
czichy2175dd32022-05-17 15:24:51 +03001952 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateSuccess", "Messages"}});
1953 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateSuccess", "Bytes"}});
1954
aa7133@att.coma4c80012020-06-24 16:36:47 +03001955 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Messages"}});
1956 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001957
aa7133@att.coma4c80012020-06-24 16:36:47 +03001958 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Messages"}});
1959 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001960 //----------------------------------------------------------------------------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03001961 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Messages"}});
1962 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001963
czichy2175dd32022-05-17 15:24:51 +03001964 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateFailure", "Messages"}});
1965 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateFailure", "Bytes"}});
1966
aa7133@att.coma4c80012020-06-24 16:36:47 +03001967 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Messages"}});
1968 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Bytes"}});
gunjarastogi85f507f2023-01-18 16:27:55 +05301969
1970
1971 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDeleteRequired)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteRequired", "Messages"}});
1972 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDeleteRequired)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteRequired", "Bytes"}});
1973
ss412g4aeeda22020-06-16 14:12:41 +03001974}
Mohamed Abukar64f37242021-08-15 12:39:56 +00001975
ss412g4aeeda22020-06-16 14:12:41 +03001976/**
1977 *
1978 * @param pdu
1979 * @param sctpMap
1980 * @param message
1981 * @param RANfunctionsAdded_v
1982 * @return
1983 */
1984int collectSetupRequestData(E2AP_PDU_t *pdu,
1985 Sctp_Map_t *sctpMap,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001986 ReportingMessages_t &message /*, vector <string> &RANfunctionsAdded_v*/) {
ss412g4aeeda22020-06-16 14:12:41 +03001987 memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE);
1988 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) {
1989 auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i];
1990 if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) {
1991 // get the ran name for meid
1992 if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) {
1993 if (buildRanName(message.peerInfo->enodbName, ie) < 0) {
1994 mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n");
aa7133@att.com409f2232020-10-29 13:06:45 +03001995 // no message will be sent
ss412g4aeeda22020-06-16 14:12:41 +03001996 return -1;
1997 }
1998
1999 memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName));
2000 sctpMap->setkey(message.message.enodbName, message.peerInfo);
2001 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002002 } /*else if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
ss412g4aeeda22020-06-16 14:12:41 +03002003 if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) {
2004 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2005 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
2006 ie->value.choice.RANfunctions_List.list.count);
2007 }
2008 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) {
2009 return -1;
2010 }
2011 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002012 } */
ss412g4aeeda22020-06-16 14:12:41 +03002013 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002014// if (mdclog_level_get() >= MDCLOG_DEBUG) {
2015// mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries",
2016// RANfunctionsAdded_v.size());
2017// }
ss412g4aeeda22020-06-16 14:12:41 +03002018 return 0;
2019}
2020
2021int XML_From_PER(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
2022 E2AP_PDU_t *pdu = nullptr;
2023
2024 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2025 mdclog_write(MDCLOG_DEBUG, "got PER message of size %d is:%s",
2026 rmrMessageBuffer.sendMessage->len, rmrMessageBuffer.sendMessage->payload);
2027 }
2028 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu,
2029 rmrMessageBuffer.sendMessage->payload, rmrMessageBuffer.sendMessage->len);
2030 if (rval.code != RC_OK) {
2031 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
2032 rval.code,
2033 message.message.enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04002034 if (pdu != nullptr) {
2035 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2036 pdu = nullptr;
2037 }
ss412g4aeeda22020-06-16 14:12:41 +03002038 return -1;
2039 }
2040
2041 int buff_size = RECEIVE_XAPP_BUFFER_SIZE;
2042 auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu,
2043 rmrMessageBuffer.sendMessage->payload, buff_size);
2044 if (er.encoded == -1) {
2045 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
dhirajverma9f59b572021-07-23 02:36:13 -04002046 if (pdu != nullptr) {
2047 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2048 pdu = nullptr;
2049 }
ss412g4aeeda22020-06-16 14:12:41 +03002050 return -1;
2051 } else if (er.encoded > (ssize_t)buff_size) {
2052 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
2053 (int)rmrMessageBuffer.sendMessage->len,
2054 asn_DEF_E2AP_PDU.name,
2055 __func__,
2056 __LINE__);
dhirajverma9f59b572021-07-23 02:36:13 -04002057 if (pdu != nullptr) {
2058 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2059 pdu = nullptr;
2060 }
ss412g4aeeda22020-06-16 14:12:41 +03002061 return -1;
2062 }
2063 rmrMessageBuffer.sendMessage->len = er.encoded;
dhirajverma9f59b572021-07-23 02:36:13 -04002064 if (pdu != nullptr) {
2065 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2066 pdu = nullptr;
2067 }
ss412g4aeeda22020-06-16 14:12:41 +03002068 return 0;
2069
2070}
2071
ss412g1a79bdf2019-10-24 12:03:05 +03002072/**
2073 *
2074 * @param pdu
2075 * @param message
2076 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002077 */
2078void asnInitiatingRequest(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002079 Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002080 ReportingMessages_t &message,
czichy2175dd32022-05-17 15:24:51 +03002081 RmrMessagesBuffer_t &rmrMessageBuffer, int streamId) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002082 auto logLevel = mdclog_level_get();
ss412g1a79bdf2019-10-24 12:03:05 +03002083 auto procedureCode = ((InitiatingMessage_t *) pdu->choice.initiatingMessage)->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002084 if (logLevel >= MDCLOG_DEBUG) {
2085 mdclog_write(MDCLOG_DEBUG, "Initiating message %ld\n", procedureCode);
ss412g1a79bdf2019-10-24 12:03:05 +03002086 }
2087 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002088 case ProcedureCode_id_E2setup: {
2089 if (logLevel >= MDCLOG_DEBUG) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002090 mdclog_write(MDCLOG_DEBUG, "Got E2setup");
aa7133@att.com84bd3342020-03-16 18:04:57 +02002091 }
2092
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002093// vector <string> RANfunctionsAdded_v;
2094// vector <string> RANfunctionsModified_v;
2095// RANfunctionsAdded_v.clear();
2096// RANfunctionsModified_v.clear();
2097 if (collectSetupRequestData(pdu, sctpMap, message) != 0) {
aa7133@att.com7b437f72020-03-30 13:25:54 +03002098 break;
2099 }
czichy2175dd32022-05-17 15:24:51 +03002100 struct sctp_status status;
2101 int stat_size = sizeof(status);
2102 getsockopt( message.peerInfo->fileDescriptor, SOL_SCTP, SCTP_STATUS,(void *)&status, (socklen_t *)&stat_size );
2103 if (logLevel >= MDCLOG_DEBUG) {
2104 mdclog_write(MDCLOG_DEBUG, "Start from SCTP %d fd", message.peerInfo->fileDescriptor);
2105 mdclog_write(MDCLOG_DEBUG, "SCTP status assoc id %d instrms %d outstrms %d", status.sstat_assoc_id,
2106 status.sstat_instrms, status.sstat_outstrms);
2107 }
2108 if(status.sstat_outstrms == 1 || status.sstat_instrms == 1)
2109 {
2110 message.peerInfo->isSingleStream = true;
2111 message.peerInfo->singleStreamId = streamId;
2112 if (status.sstat_outstrms == 1 && status.sstat_instrms == 1){
2113 if (logLevel >= MDCLOG_DEBUG) {
2114 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__);
2115 }
2116 }
2117 else {
2118 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,
2119 status.sstat_instrms, status.sstat_outstrms);
2120 }
2121 }
aa7133@att.com7b437f72020-03-30 13:25:54 +03002122
aa7133@att.com409f2232020-10-29 13:06:45 +03002123 buildPrometheusList(message.peerInfo, message.peerInfo->sctpParams->prometheusFamily);
ss412g4aeeda22020-06-16 14:12:41 +03002124
2125 string messageName("E2setupRequest");
2126 string ieName("E2setupRequestIEs");
2127 message.message.messageType = RIC_E2_SETUP_REQ;
aa7133@att.coma4c80012020-06-24 16:36:47 +03002128 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2129 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002130
2131 // Update E2T instance level metrics
2132 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2133 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment((double)message.message.asnLength);
2134
aa7133@att.com409f2232020-10-29 13:06:45 +03002135 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
ss412g1a79bdf2019-10-24 12:03:05 +03002136 break;
2137 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002138 case ProcedureCode_id_RICserviceUpdate: {
2139 if (logLevel >= MDCLOG_DEBUG) {
2140 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
2141 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002142// vector <string> RANfunctionsAdded_v;
2143// vector <string> RANfunctionsModified_v;
2144// RANfunctionsAdded_v.clear();
2145// RANfunctionsModified_v.clear();
2146// if (collectServiceUpdate_RequestData(pdu, sctpMap, message,
2147// RANfunctionsAdded_v, RANfunctionsModified_v) != 0) {
2148// break;
2149// }
ss412g4aeeda22020-06-16 14:12:41 +03002150
2151 string messageName("RICserviceUpdate");
2152 string ieName("RICserviceUpdateIEs");
2153 message.message.messageType = RIC_SERVICE_UPDATE;
Alexandre Hufffff97942023-03-31 21:22:20 -03002154#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002155 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2156 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002157
2158 // Update E2T instance level metrics
2159 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2160 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002161#endif
aa7133@att.com409f2232020-10-29 13:06:45 +03002162 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002163 break;
2164 }
czichy2175dd32022-05-17 15:24:51 +03002165
2166case ProcedureCode_id_E2nodeConfigurationUpdate: {
2167 if (logLevel >= MDCLOG_DEBUG) {
2168 mdclog_write(MDCLOG_DEBUG, "Got E2nodeConfigurationUpdate %s", message.message.enodbName);
2169 }
2170
2171 string messageName("RICE2nodeConfigurationUpdate");
2172 string ieName("RICE2nodeConfigurationUpdateIEs");
2173 message.message.messageType = RIC_E2NODE_CONFIG_UPDATE;
2174#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2175 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2176 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment((double)message.message.asnLength);
2177
2178 // Update E2T instance level metrics
2179 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2180 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment((double)message.message.asnLength);
2181#endif
2182 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
2183 break;
2184 }
2185
aa7133@att.com84bd3342020-03-16 18:04:57 +02002186 case ProcedureCode_id_ErrorIndication: {
2187 if (logLevel >= MDCLOG_DEBUG) {
2188 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
2189 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002190#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002191 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2192 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002193
2194 // Update E2T instance level metrics
2195 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2196 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002197#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002198 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002199 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
ss412g1a79bdf2019-10-24 12:03:05 +03002200 }
2201 break;
2202 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002203 case ProcedureCode_id_Reset: {
2204 if (logLevel >= MDCLOG_DEBUG) {
2205 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002206 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002207#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002208 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2209 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002210
2211 // Update E2T instance level metrics
2212 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2213 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002214#endif
ss412g4aeeda22020-06-16 14:12:41 +03002215 if (XML_From_PER(message, rmrMessageBuffer) < 0) {
2216 break;
ss412g1a79bdf2019-10-24 12:03:05 +03002217 }
ss412g4aeeda22020-06-16 14:12:41 +03002218
2219 if (sendRequestToXapp(message, RIC_E2_RESET_REQ, rmrMessageBuffer) != 0) {
2220 mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_REQ message failed to send to xAPP");
aa7133@att.com84bd3342020-03-16 18:04:57 +02002221 }
2222 break;
2223 }
2224 case ProcedureCode_id_RICindication: {
2225 if (logLevel >= MDCLOG_DEBUG) {
2226 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
2227 }
2228 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
ss412g1a79bdf2019-10-24 12:03:05 +03002229 auto messageSent = false;
2230 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
aa7133@att.com84bd3342020-03-16 18:04:57 +02002231 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002232 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2233 }
2234 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002235 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002236 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2237 }
2238 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
2239 static unsigned char tx[32];
2240 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
2241 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2242 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
ss412g3bac2da2020-01-05 11:52:19 +02002243 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
aa7133@att.com84bd3342020-03-16 18:04:57 +02002244 (unsigned char *)message.message.enodbName,
2245 strlen(message.message.enodbName));
ss412g1a79bdf2019-10-24 12:03:05 +03002246 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.comc5a15202020-04-05 19:57:01 +03002247 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
2248
2249 //ie->value.choice.RICrequestID.ricInstanceID;
ss412g3bac2da2020-01-05 11:52:19 +02002250 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03002251 mdclog_write(MDCLOG_DEBUG, "sub id = %d, mtype = %d, ric instance id %ld, requestor id = %ld",
aa7133@att.com84bd3342020-03-16 18:04:57 +02002252 rmrMessageBuffer.sendMessage->sub_id,
aa7133@att.comc5a15202020-04-05 19:57:01 +03002253 rmrMessageBuffer.sendMessage->mtype,
2254 ie->value.choice.RICrequestID.ricInstanceID,
2255 ie->value.choice.RICrequestID.ricRequestorID);
ss412g3bac2da2020-01-05 11:52:19 +02002256 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002257#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002258 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication]->Increment();
2259 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002260
2261 // Update E2T instance level metrics
2262 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication]->Increment();
2263 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002264#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002265 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002266 messageSent = true;
2267 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002268 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002269 }
2270 }
2271 if (messageSent) {
2272 break;
2273 }
2274 }
2275 break;
2276 }
gunjarastogi85f507f2023-01-18 16:27:55 +05302277 case ProcedureCode_id_RICsubscriptionDeleteRequired: {
2278 if (logLevel >= MDCLOG_DEBUG) {
2279 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDeleteRequired %s", message.message.enodbName);
2280 }
2281 #if !(defined(UNIT_TEST) || defined(MODULE_TEST))
Alexandre Huff019cb422023-04-11 10:56:48 -03002282 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment();
2283 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment((double)message.message.asnLength);
gunjarastogi85f507f2023-01-18 16:27:55 +05302284
Alexandre Huff019cb422023-04-11 10:56:48 -03002285 // Update E2T instance level metrics
2286 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment();
2287 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment((double)message.message.asnLength);
gunjarastogi85f507f2023-01-18 16:27:55 +05302288 #endif
2289 if (sendRequestToXapp(message, RIC_SUB_DEL_REQUIRED, rmrMessageBuffer) != 0) {
2290 mdclog_write(MDCLOG_ERR, "Subscription Delete Required message failed to send to xAPP");
2291 }
2292 break;
2293 }
2294
ss412g1a79bdf2019-10-24 12:03:05 +03002295 default: {
2296 mdclog_write(MDCLOG_ERR, "Undefined or not supported message = %ld", procedureCode);
2297 message.message.messageType = 0; // no RMR message type yet
2298
2299 buildJsonMessage(message);
2300
2301 break;
2302 }
2303 }
ss412g1a79bdf2019-10-24 12:03:05 +03002304}
2305
2306/**
2307 *
2308 * @param pdu
2309 * @param message
ss412g1a79bdf2019-10-24 12:03:05 +03002310 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002311 */
aa7133@att.com409f2232020-10-29 13:06:45 +03002312void asnSuccessfulMsg(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002313 Sctp_Map_t *sctpMap,
2314 ReportingMessages_t &message,
2315 RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002316 auto procedureCode = pdu->choice.successfulOutcome->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002317 auto logLevel = mdclog_level_get();
2318 if (logLevel >= MDCLOG_INFO) {
ss412g1a79bdf2019-10-24 12:03:05 +03002319 mdclog_write(MDCLOG_INFO, "Successful Outcome %ld", procedureCode);
2320 }
2321 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002322 case ProcedureCode_id_Reset: {
2323 if (logLevel >= MDCLOG_DEBUG) {
2324 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002325 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002326#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002327 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2328 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002329
2330 // Update E2T instance level metrics
2331 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2332 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002333#endif
ss412g4aeeda22020-06-16 14:12:41 +03002334 if (XML_From_PER(message, rmrMessageBuffer) < 0) {
2335 break;
2336 }
2337 if (sendRequestToXapp(message, RIC_E2_RESET_RESP, rmrMessageBuffer) != 0) {
2338 mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_RESP message failed to send to xAPP");
ss412g1a79bdf2019-10-24 12:03:05 +03002339 }
2340 break;
2341 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002342 case ProcedureCode_id_RICcontrol: {
2343 if (logLevel >= MDCLOG_DEBUG) {
2344 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002345 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002346 for (auto i = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03002347 i < pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; i++) {
2348 auto messageSent = false;
2349 RICcontrolAcknowledge_IEs_t *ie = pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[i];
2350 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2351 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2352 }
2353 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
2354 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2355 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2356 }
2357 if (ie->value.present == RICcontrolAcknowledge_IEs__value_PR_RICrequestID) {
2358 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_ACK;
2359 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002360// rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
2361 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
2362
ss412g1a79bdf2019-10-24 12:03:05 +03002363 static unsigned char tx[32];
2364 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2365 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
ss412g3bac2da2020-01-05 11:52:19 +02002366 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
aa7133@att.com84bd3342020-03-16 18:04:57 +02002367 (unsigned char *)message.message.enodbName,
2368 strlen(message.message.enodbName));
Alexandre Hufffff97942023-03-31 21:22:20 -03002369#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002370 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2371 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002372
2373 // Update E2T instance level metrics
2374 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2375 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002376#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002377 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002378 messageSent = true;
2379 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002380 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002381 }
2382 }
2383 if (messageSent) {
2384 break;
2385 }
2386 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002387
2388 break;
2389 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002390 case ProcedureCode_id_RICsubscription: {
2391 if (logLevel >= MDCLOG_DEBUG) {
2392 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
2393 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002394#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002395 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2396 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002397
2398 // Update E2T instance level metrics
2399 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2400 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002401#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002402 if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002403 mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP");
2404 }
2405 break;
2406 }
2407 case ProcedureCode_id_RICsubscriptionDelete: {
2408 if (logLevel >= MDCLOG_DEBUG) {
2409 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
2410 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002411#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002412 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2413 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002414
2415 // Update E2T instance level metrics
2416 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2417 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002418#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002419 if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002420 mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP");
2421 }
ss412g1a79bdf2019-10-24 12:03:05 +03002422 break;
2423 }
2424 default: {
2425 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
2426 message.message.messageType = 0; // no RMR message type yet
2427 buildJsonMessage(message);
2428
2429 break;
2430 }
2431 }
ss412g1a79bdf2019-10-24 12:03:05 +03002432}
2433
2434/**
2435 *
2436 * @param pdu
2437 * @param message
ss412g1a79bdf2019-10-24 12:03:05 +03002438 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002439 */
2440void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002441 Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002442 ReportingMessages_t &message,
aa7133@att.combe92d712020-03-18 17:30:39 +02002443 RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002444 auto procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002445 auto logLevel = mdclog_level_get();
2446 if (logLevel >= MDCLOG_INFO) {
ss412g1a79bdf2019-10-24 12:03:05 +03002447 mdclog_write(MDCLOG_INFO, "Unsuccessful Outcome %ld", procedureCode);
2448 }
2449 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002450 case ProcedureCode_id_RICcontrol: {
2451 if (logLevel >= MDCLOG_DEBUG) {
2452 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002453 }
2454 for (int i = 0;
2455 i < pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.count; i++) {
2456 auto messageSent = false;
2457 RICcontrolFailure_IEs_t *ie = pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.array[i];
aa7133@att.com84bd3342020-03-16 18:04:57 +02002458 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002459 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2460 }
2461 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002462 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002463 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2464 }
2465 if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) {
2466 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_FAILURE;
2467 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002468// rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricRequestorID;
2469 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
ss412g1a79bdf2019-10-24 12:03:05 +03002470 static unsigned char tx[32];
2471 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2472 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
aa7133@att.com84bd3342020-03-16 18:04:57 +02002473 rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName,
2474 strlen(message.message.enodbName));
Alexandre Hufffff97942023-03-31 21:22:20 -03002475#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002476 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2477 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002478
2479 // Update E2T instance level metrics
2480 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2481 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
dhirajverma99990292021-07-05 10:03:59 -04002482#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002483 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002484 messageSent = true;
2485 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002486 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002487 }
2488 }
2489 if (messageSent) {
2490 break;
2491 }
2492 }
2493 break;
2494 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002495 case ProcedureCode_id_RICsubscription: {
2496 if (logLevel >= MDCLOG_DEBUG) {
2497 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
2498 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002499#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002500 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2501 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002502
2503 // Update E2T instance level metrics
2504 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2505 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002506#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002507 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002508 mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP");
2509 }
2510 break;
2511 }
2512 case ProcedureCode_id_RICsubscriptionDelete: {
2513 if (logLevel >= MDCLOG_DEBUG) {
2514 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
2515 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002516#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002517 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2518 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002519
2520 // Update E2T instance level metrics
2521 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2522 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002523#endif
ss412g4aeeda22020-06-16 14:12:41 +03002524 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002525 mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP");
2526 }
2527 break;
2528 }
ss412g1a79bdf2019-10-24 12:03:05 +03002529 default: {
2530 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
2531 message.message.messageType = 0; // no RMR message type yet
Alexandre Hufffff97942023-03-31 21:22:20 -03002532#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03002533 buildJsonMessage(message);
Alexandre Hufffff97942023-03-31 21:22:20 -03002534#endif
ss412g1a79bdf2019-10-24 12:03:05 +03002535 break;
2536 }
2537 }
ss412g1a79bdf2019-10-24 12:03:05 +03002538}
2539
2540/**
2541 *
2542 * @param message
2543 * @param requestId
2544 * @param rmrMmessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002545 * @return
2546 */
2547int sendRequestToXapp(ReportingMessages_t &message,
2548 int requestId,
aa7133@att.combe92d712020-03-18 17:30:39 +02002549 RmrMessagesBuffer_t &rmrMmessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002550 rmr_bytes2meid(rmrMmessageBuffer.sendMessage,
2551 (unsigned char *)message.message.enodbName,
2552 strlen(message.message.enodbName));
2553 message.message.messageType = rmrMmessageBuffer.sendMessage->mtype = requestId;
2554 rmrMmessageBuffer.sendMessage->state = 0;
2555 static unsigned char tx[32];
2556 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2557 rmr_bytes2xact(rmrMmessageBuffer.sendMessage, tx, strlen((const char *) tx));
2558
aa7133@att.combe92d712020-03-18 17:30:39 +02002559 auto rc = sendRmrMessage(rmrMmessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002560 return rc;
2561}
2562
ss412g4aeeda22020-06-16 14:12:41 +03002563/**
2564 *
2565 * @param pSctpParams
2566 */
aa7133@att.combe92d712020-03-18 17:30:39 +02002567void getRmrContext(sctp_params_t &pSctpParams) {
ss412g3bac2da2020-01-05 11:52:19 +02002568 pSctpParams.rmrCtx = nullptr;
aa7133@att.comab0e0f42020-04-06 17:13:58 +03002569 pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RECEIVE_XAPP_BUFFER_SIZE, RMRFL_NONE);
ss412g3bac2da2020-01-05 11:52:19 +02002570 if (pSctpParams.rmrCtx == nullptr) {
2571 mdclog_write(MDCLOG_ERR, "Failed to initialize RMR");
ss412g3bac2da2020-01-05 11:52:19 +02002572 return;
ss412g1a79bdf2019-10-24 12:03:05 +03002573 }
2574
ss412g3bac2da2020-01-05 11:52:19 +02002575 rmr_set_stimeout(pSctpParams.rmrCtx, 0); // disable retries for any send operation
ss412g1a79bdf2019-10-24 12:03:05 +03002576 // we need to find that routing table exist and we can run
2577 if (mdclog_level_get() >= MDCLOG_INFO) {
2578 mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready");
2579 }
2580 int rmrReady = 0;
2581 int count = 0;
2582 while (!rmrReady) {
ss412g3bac2da2020-01-05 11:52:19 +02002583 if ((rmrReady = rmr_ready(pSctpParams.rmrCtx)) == 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002584 sleep(1);
2585 }
2586 count++;
2587 if (count % 60 == 0) {
2588 mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count);
2589 }
2590 }
2591 if (mdclog_level_get() >= MDCLOG_INFO) {
2592 mdclog_write(MDCLOG_INFO, "RMR running");
2593 }
ss412g3bac2da2020-01-05 11:52:19 +02002594 rmr_init_trace(pSctpParams.rmrCtx, 200);
2595 // get the RMR fd for the epoll
2596 pSctpParams.rmrListenFd = rmr_get_rcvfd(pSctpParams.rmrCtx);
2597 struct epoll_event event{};
2598 // add RMR fd to epoll
2599 event.events = (EPOLLIN);
2600 event.data.fd = pSctpParams.rmrListenFd;
2601 // add listening RMR FD to epoll
2602 if (epoll_ctl(pSctpParams.epoll_fd, EPOLL_CTL_ADD, pSctpParams.rmrListenFd, &event)) {
2603 mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll");
2604 close(pSctpParams.rmrListenFd);
2605 rmr_close(pSctpParams.rmrCtx);
2606 pSctpParams.rmrCtx = nullptr;
2607 }
ss412g1a79bdf2019-10-24 12:03:05 +03002608}
2609
ss412g4aeeda22020-06-16 14:12:41 +03002610/**
2611 *
2612 * @param message
2613 * @param rmrMessageBuffer
2614 * @return
2615 */
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002616int PER_FromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
aa7133@att.com07e256f2020-04-20 15:59:51 +03002617 E2AP_PDU_t *pdu = nullptr;
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002618
2619 if (mdclog_level_get() >= MDCLOG_DEBUG) {
ss412g4aeeda22020-06-16 14:12:41 +03002620 mdclog_write(MDCLOG_DEBUG, "got xml Format data from xApp of size %d is:%s",
aa7133@att.com07e256f2020-04-20 15:59:51 +03002621 rmrMessageBuffer.rcvMessage->len, rmrMessageBuffer.rcvMessage->payload);
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002622 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002623 auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &pdu,
2624 rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len);
aa7133@att.com409f2232020-10-29 13:06:45 +03002625 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2626 mdclog_write(MDCLOG_DEBUG, "%s After decoding the XML to PDU", __func__ );
2627 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002628 if (rval.code != RC_OK) {
dhirajvermac40ea1f2021-07-08 12:52:30 -04002629#ifdef UNIT_TEST
2630 return 0;
Alexandre Hufffff97942023-03-31 21:22:20 -03002631#endif
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002632 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
aa7133@att.com1fecb052020-03-29 09:44:09 +03002633 rval.code,
2634 message.message.enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04002635 if (pdu != nullptr) {
2636 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2637 pdu = nullptr;
2638 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002639 return -1;
2640 }
2641
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002642 int buff_size = RECEIVE_XAPP_BUFFER_SIZE;
2643 auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu,
2644 rmrMessageBuffer.rcvMessage->payload, buff_size);
aa7133@att.com409f2232020-10-29 13:06:45 +03002645 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2646 mdclog_write(MDCLOG_DEBUG, "%s After encoding PDU to PER", __func__ );
2647 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002648 if (er.encoded == -1) {
2649 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
dhirajverma9f59b572021-07-23 02:36:13 -04002650 if (pdu != nullptr) {
2651 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2652 pdu = nullptr;
2653 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002654 return -1;
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002655 } else if (er.encoded > (ssize_t)buff_size) {
2656 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 +03002657 (int)rmrMessageBuffer.rcvMessage->len,
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002658 asn_DEF_E2AP_PDU.name,
2659 __func__,
2660 __LINE__);
dhirajverma9f59b572021-07-23 02:36:13 -04002661 if (pdu != nullptr) {
2662 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2663 pdu = nullptr;
2664 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002665 return -1;
2666 }
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002667 rmrMessageBuffer.rcvMessage->len = er.encoded;
dhirajverma9f59b572021-07-23 02:36:13 -04002668 if (pdu != nullptr) {
2669 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2670 pdu = nullptr;
2671 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002672 return 0;
2673}
2674
ss412g1a79bdf2019-10-24 12:03:05 +03002675/**
2676 *
ss412g1a79bdf2019-10-24 12:03:05 +03002677 * @param sctpMap
2678 * @param rmrMessageBuffer
2679 * @param ts
ss412g1a79bdf2019-10-24 12:03:05 +03002680 * @return
2681 */
aa7133@att.com6680c3b2020-03-22 12:06:58 +02002682int receiveXappMessages(Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002683 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02002684 struct timespec &ts) {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002685 int loglevel = mdclog_level_get();
ss412g1a79bdf2019-10-24 12:03:05 +03002686 if (rmrMessageBuffer.rcvMessage == nullptr) {
2687 //we have error
2688 mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03002689 return -1;
2690 }
2691
aa7133@att.comf13529a2020-08-27 11:21:16 +03002692// if (loglevel >= MDCLOG_DEBUG) {
2693// mdclog_write(MDCLOG_DEBUG, "Call to rmr_rcv_msg");
2694// }
ss412g1a79bdf2019-10-24 12:03:05 +03002695 rmrMessageBuffer.rcvMessage = rmr_rcv_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
2696 if (rmrMessageBuffer.rcvMessage == nullptr) {
aa7133@att.com409f2232020-10-29 13:06:45 +03002697 mdclog_write(MDCLOG_ERR, "RMR Receiving message with null pointer, Reallocated rmr message buffer");
ss412g1a79bdf2019-10-24 12:03:05 +03002698 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g1a79bdf2019-10-24 12:03:05 +03002699 return -2;
2700 }
2701 ReportingMessages_t message;
2702 message.message.direction = 'D';
2703 message.message.time.tv_nsec = ts.tv_nsec;
2704 message.message.time.tv_sec = ts.tv_sec;
2705
2706 // get message payload
2707 //auto msgData = msg->payload;
dhirajverma60f8bef2021-06-29 07:22:58 -04002708#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04002709 rmrMessageBuffer.rcvMessage->state = 0;
dhirajverma60f8bef2021-06-29 07:22:58 -04002710#endif
ss412g1a79bdf2019-10-24 12:03:05 +03002711 if (rmrMessageBuffer.rcvMessage->state != 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +03002712 mdclog_write(MDCLOG_ERR, "RMR Receiving message with stat = %d", rmrMessageBuffer.rcvMessage->state);
ss412g1a79bdf2019-10-24 12:03:05 +03002713 return -1;
2714 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002715 rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)message.message.enodbName);
ss412g4aeeda22020-06-16 14:12:41 +03002716 message.peerInfo = (ConnectedCU_t *) sctpMap->find(message.message.enodbName);
2717 if (message.peerInfo == nullptr) {
2718 auto type = rmrMessageBuffer.rcvMessage->mtype;
2719 switch (type) {
2720 case RIC_SCTP_CLEAR_ALL:
2721 case E2_TERM_KEEP_ALIVE_REQ:
2722 case RIC_HEALTH_CHECK_REQ:
2723 break;
2724 default:
dhirajverma99990292021-07-05 10:03:59 -04002725#ifdef UNIT_TEST
2726 break;
Alexandre Hufffff97942023-03-31 21:22:20 -03002727#endif
ss412g4aeeda22020-06-16 14:12:41 +03002728 mdclog_write(MDCLOG_ERR, "Failed to send message no CU entry %s", message.message.enodbName);
2729 return -1;
2730 }
2731 }
2732
aa7133@att.comde40d1c2020-08-26 16:19:20 +03002733 if (rmrMessageBuffer.rcvMessage->mtype != RIC_HEALTH_CHECK_REQ) {
2734 num_of_XAPP_messages.fetch_add(1, std::memory_order_release);
2735
2736 }
ss412g1a79bdf2019-10-24 12:03:05 +03002737 switch (rmrMessageBuffer.rcvMessage->mtype) {
aa7133@att.combe92d712020-03-18 17:30:39 +02002738 case RIC_E2_SETUP_RESP : {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002739 if (loglevel >= MDCLOG_DEBUG) {
2740 mdclog_write(MDCLOG_DEBUG, "RIC_E2_SETUP_RESP");
2741 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002742 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com1fecb052020-03-29 09:44:09 +03002743 break;
2744 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002745#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002746 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2747 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002748
2749 // Update E2T instance level metrics
2750 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2751 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002752#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002753 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2754 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_RESP");
2755 return -6;
ss412g1a79bdf2019-10-24 12:03:05 +03002756 }
2757 break;
2758 }
aa7133@att.combe92d712020-03-18 17:30:39 +02002759 case RIC_E2_SETUP_FAILURE : {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002760 if (loglevel >= MDCLOG_DEBUG) {
2761 mdclog_write(MDCLOG_DEBUG, "RIC_E2_SETUP_FAILURE");
2762 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002763 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com1fecb052020-03-29 09:44:09 +03002764 break;
2765 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002766#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002767 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2768 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002769
2770 // Update E2T instance level metrics
2771 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2772 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002773#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002774 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2775 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_FAILURE");
2776 return -6;
ss412g1a79bdf2019-10-24 12:03:05 +03002777 }
2778 break;
2779 }
czichy2175dd32022-05-17 15:24:51 +03002780
2781 case RIC_E2NODE_CONFIG_UPDATE_ACK: {
2782 if (loglevel >= MDCLOG_DEBUG) {
2783 mdclog_write(MDCLOG_DEBUG, "RIC_E2NODE_CONFIG_UPDATE_ACK");
2784 }
2785 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2786 break;
2787 }
2788#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2789 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2790 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2791
2792 // Update E2T instance level metrics
2793 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2794 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2795#endif
2796 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2797 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2NODE_CONFIG_UPDATE_ACK");
2798 return -6;
2799 }
2800 break;
2801 }
2802
2803 case RIC_E2NODE_CONFIG_UPDATE_FAILURE: {
2804 if (loglevel >= MDCLOG_DEBUG) {
2805 mdclog_write(MDCLOG_DEBUG, "RIC_E2NODE_CONFIG_UPDATE_FAILURE");
2806 }
2807 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2808 break;
2809 }
2810#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2811 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2812 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2813
2814 // Update E2T instance level metrics
2815 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2816 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2817#endif
2818 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2819 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2NODE_CONFIG_UPDATE_FAILURE");
2820 return -6;
2821 }
2822 break;
2823 }
2824
aa7133@att.combe92d712020-03-18 17:30:39 +02002825 case RIC_ERROR_INDICATION: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002826 if (loglevel >= MDCLOG_DEBUG) {
2827 mdclog_write(MDCLOG_DEBUG, "RIC_ERROR_INDICATION");
2828 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002829#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002830 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2831 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002832
2833 // Update E2T instance level metrics
2834 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2835 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002836#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002837 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2838 mdclog_write(MDCLOG_ERR, "Failed to send RIC_ERROR_INDICATION");
ss412g1a79bdf2019-10-24 12:03:05 +03002839 return -6;
2840 }
2841 break;
2842 }
2843 case RIC_SUB_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002844 if (loglevel >= MDCLOG_DEBUG) {
2845 mdclog_write(MDCLOG_DEBUG, "RIC_SUB_REQ");
2846 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002847#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002848 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2849 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002850
2851 // Update E2T instance level metrics
2852 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2853 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002854#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002855 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002856 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002857 return -6;
2858 }
2859 break;
2860 }
2861 case RIC_SUB_DEL_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002862 if (loglevel >= MDCLOG_DEBUG) {
2863 mdclog_write(MDCLOG_DEBUG, "RIC_SUB_DEL_REQ");
2864 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002865#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002866 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2867 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002868
2869 // Update E2T instance level metrics
2870 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2871 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002872#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002873 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002874 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_DEL_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002875 return -6;
2876 }
2877 break;
2878 }
2879 case RIC_CONTROL_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002880 if (loglevel >= MDCLOG_DEBUG) {
2881 mdclog_write(MDCLOG_DEBUG, "RIC_CONTROL_REQ");
2882 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002883#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002884 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2885 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002886
2887 // Update E2T instance level metrics
2888 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2889 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002890#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002891 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002892 mdclog_write(MDCLOG_ERR, "Failed to send RIC_CONTROL_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002893 return -6;
2894 }
2895 break;
2896 }
2897 case RIC_SERVICE_QUERY: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002898 if (loglevel >= MDCLOG_DEBUG) {
2899 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_QUERY");
2900 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002901 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2902 break;
2903 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002904#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002905 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment();
2906 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002907
2908 // Update E2T instance level metrics
2909 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment();
2910 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002911#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002912 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002913 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY");
ss412g1a79bdf2019-10-24 12:03:05 +03002914 return -6;
2915 }
2916 break;
2917 }
2918 case RIC_SERVICE_UPDATE_ACK: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002919 if (loglevel >= MDCLOG_DEBUG) {
2920 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_UPDATE_ACK");
2921 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002922 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com54885fe2020-10-29 17:24:49 +03002923 mdclog_write(MDCLOG_ERR, "error in PER_FromXML");
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002924 break;
2925 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002926#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002927 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
aa7133@att.com52771912020-10-29 17:45:01 +03002928 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002929
2930 // Update E2T instance level metrics
2931 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2932 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002933#endif
aa7133@att.com54885fe2020-10-29 17:24:49 +03002934 if (loglevel >= MDCLOG_DEBUG) {
2935 mdclog_write(MDCLOG_DEBUG, "Before sending to CU");
2936 }
aa7133@att.combe92d712020-03-18 17:30:39 +02002937 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002938 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK");
ss412g1a79bdf2019-10-24 12:03:05 +03002939 return -6;
2940 }
2941 break;
2942 }
2943 case RIC_SERVICE_UPDATE_FAILURE: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002944 if (loglevel >= MDCLOG_DEBUG) {
2945 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_UPDATE_FAILURE");
2946 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002947 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2948 break;
2949 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002950#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002951 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
aa7133@att.com7c07fee2020-10-29 17:54:38 +03002952 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002953
2954 // Update E2T instance level metrics
2955 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2956 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002957#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002958 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002959 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE");
ss412g1a79bdf2019-10-24 12:03:05 +03002960 return -6;
2961 }
2962 break;
2963 }
ss412g4aeeda22020-06-16 14:12:41 +03002964 case RIC_E2_RESET_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002965 if (loglevel >= MDCLOG_DEBUG) {
2966 mdclog_write(MDCLOG_DEBUG, "RIC_E2_RESET_REQ");
2967 }
ss412g4aeeda22020-06-16 14:12:41 +03002968 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2969 break;
2970 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002971#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002972 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2973 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002974
2975 // Update E2T instance level metrics
2976 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2977 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002978#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002979 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03002980 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET");
ss412g1a79bdf2019-10-24 12:03:05 +03002981 return -6;
2982 }
2983 break;
2984 }
ss412g4aeeda22020-06-16 14:12:41 +03002985 case RIC_E2_RESET_RESP: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002986 if (loglevel >= MDCLOG_DEBUG) {
2987 mdclog_write(MDCLOG_DEBUG, "RIC_E2_RESET_RESP");
2988 }
ss412g4aeeda22020-06-16 14:12:41 +03002989 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2990 break;
2991 }
Alexandre Hufffff97942023-03-31 21:22:20 -03002992#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002993 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2994 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002995
2996 // Update E2T instance level metrics
2997 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2998 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Alexandre Hufffff97942023-03-31 21:22:20 -03002999#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02003000 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03003001 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET_RESP");
ss412g1a79bdf2019-10-24 12:03:05 +03003002 return -6;
3003 }
3004 break;
3005 }
3006 case RIC_SCTP_CLEAR_ALL: {
3007 mdclog_write(MDCLOG_INFO, "RIC_SCTP_CLEAR_ALL");
3008 // loop on all keys and close socket and then erase all map.
3009 vector<char *> v;
3010 sctpMap->getKeys(v);
3011 for (auto const &iter : v) { //}; iter != sctpMap.end(); iter++) {
3012 if (!boost::starts_with((string) (iter), "host:") && !boost::starts_with((string) (iter), "msg:")) {
3013 auto *peerInfo = (ConnectedCU_t *) sctpMap->find(iter);
3014 if (peerInfo == nullptr) {
3015 continue;
3016 }
3017 close(peerInfo->fileDescriptor);
3018 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
3019 message.message.direction = 'D';
3020 message.message.time.tv_nsec = ts.tv_nsec;
3021 message.message.time.tv_sec = ts.tv_sec;
3022
3023 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
3024 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
aa7133@att.com96c9b882020-03-25 14:50:40 +02003025 256,
3026 "%s|RIC_SCTP_CLEAR_ALL",
3027 peerInfo->enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03003028 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
3029 mdclog_write(MDCLOG_INFO, "%s", message.message.asndata);
aa7133@att.combe92d712020-03-18 17:30:39 +02003030 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03003031 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
3032 }
3033 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +05303034 peerInfo = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03003035 }
3036 }
3037
3038 sleep(1);
3039 sctpMap->clear();
3040 break;
3041 }
ss412g3bac2da2020-01-05 11:52:19 +02003042 case E2_TERM_KEEP_ALIVE_REQ: {
3043 // send message back
ss412g3bac2da2020-01-05 11:52:19 +02003044 rmr_bytes2payload(rmrMessageBuffer.sendMessage,
aa7133@att.com96c9b882020-03-25 14:50:40 +02003045 (unsigned char *)rmrMessageBuffer.ka_message,
3046 rmrMessageBuffer.ka_message_len);
ss412g3bac2da2020-01-05 11:52:19 +02003047 rmrMessageBuffer.sendMessage->mtype = E2_TERM_KEEP_ALIVE_RESP;
3048 rmrMessageBuffer.sendMessage->state = 0;
3049 static unsigned char tx[32];
3050 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
3051 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, txLen);
Alexandre Hufffff97942023-03-31 21:22:20 -03003052#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02003053 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003054#endif
ss412g3bac2da2020-01-05 11:52:19 +02003055 if (rmrMessageBuffer.sendMessage == nullptr) {
3056 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
aa7133@att.com77fff432020-01-27 12:01:20 +02003057 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP RMR message returned NULL");
ss412g3bac2da2020-01-05 11:52:19 +02003058 } else if (rmrMessageBuffer.sendMessage->state != 0) {
aa7133@att.com77fff432020-01-27 12:01:20 +02003059 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 +02003060 rmrMessageBuffer.sendMessage->state, translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str());
aa7133@att.comf13529a2020-08-27 11:21:16 +03003061 } else if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.combc110772020-03-25 09:45:14 +02003062 mdclog_write(MDCLOG_DEBUG, "Got Keep Alive Request send : %s", rmrMessageBuffer.ka_message);
ss412g3bac2da2020-01-05 11:52:19 +02003063 }
aa7133@att.com342843e2020-01-26 12:53:34 +02003064
ss412g3bac2da2020-01-05 11:52:19 +02003065 break;
3066 }
ss412g4aeeda22020-06-16 14:12:41 +03003067 case RIC_HEALTH_CHECK_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03003068 static int counter = 0;
ss412g4aeeda22020-06-16 14:12:41 +03003069 // send message back
aa7133@att.comc18fe532020-06-30 12:40:18 +03003070 rmr_bytes2payload(rmrMessageBuffer.rcvMessage,
ss412g4aeeda22020-06-16 14:12:41 +03003071 (unsigned char *)"OK",
3072 2);
aa7133@att.comc18fe532020-06-30 12:40:18 +03003073 rmrMessageBuffer.rcvMessage->mtype = RIC_HEALTH_CHECK_RESP;
3074 rmrMessageBuffer.rcvMessage->state = 0;
ss412g4aeeda22020-06-16 14:12:41 +03003075 static unsigned char tx[32];
3076 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
aa7133@att.comc18fe532020-06-30 12:40:18 +03003077 rmr_bytes2xact(rmrMessageBuffer.rcvMessage, tx, txLen);
3078 rmrMessageBuffer.rcvMessage = rmr_rts_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
3079 //rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
3080 if (rmrMessageBuffer.rcvMessage == nullptr) {
3081 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g4aeeda22020-06-16 14:12:41 +03003082 mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP RMR message returned NULL");
aa7133@att.comc18fe532020-06-30 12:40:18 +03003083 } else if (rmrMessageBuffer.rcvMessage->state != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03003084 mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP, on RMR state = %d ( %s)",
aa7133@att.comc18fe532020-06-30 12:40:18 +03003085 rmrMessageBuffer.rcvMessage->state, translateRmrErrorMessages(rmrMessageBuffer.rcvMessage->state).c_str());
dhirajvermab55bc172021-11-09 02:15:08 -05003086 } else if (loglevel >= MDCLOG_DEBUG && (++counter % 100 == 0)) {
aa7133@att.comf13529a2020-08-27 11:21:16 +03003087 mdclog_write(MDCLOG_DEBUG, "Got %d RIC_HEALTH_CHECK_REQ Request send : OK", counter);
ss412g4aeeda22020-06-16 14:12:41 +03003088 }
3089
3090 break;
3091 }
3092
ss412g1a79bdf2019-10-24 12:03:05 +03003093 default:
aa7133@att.com409f2232020-10-29 13:06:45 +03003094 mdclog_write(MDCLOG_WARN, "Message Type : %d is not supported", rmrMessageBuffer.rcvMessage->mtype);
ss412g1a79bdf2019-10-24 12:03:05 +03003095 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
3096 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
3097 message.message.time.tv_nsec = ts.tv_nsec;
3098 message.message.time.tv_sec = ts.tv_sec;
3099 message.message.messageType = rmrMessageBuffer.rcvMessage->mtype;
3100
3101 buildJsonMessage(message);
3102
3103
ss412g1a79bdf2019-10-24 12:03:05 +03003104 return -7;
3105 }
3106 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3107 mdclog_write(MDCLOG_DEBUG, "EXIT OK from %s", __FUNCTION__);
3108 }
ss412g1a79bdf2019-10-24 12:03:05 +03003109 return 0;
3110}
3111
3112/**
3113 * Send message to the CU that is not expecting for successful or unsuccessful results
3114 * @param messageBuffer
3115 * @param message
3116 * @param failedMsgId
3117 * @param sctpMap
ss412g1a79bdf2019-10-24 12:03:05 +03003118 * @return
3119 */
3120int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer,
3121 ReportingMessages_t &message,
3122 int failedMsgId,
aa7133@att.combe92d712020-03-18 17:30:39 +02003123 Sctp_Map_t *sctpMap) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003124 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3125 mdclog_write(MDCLOG_DEBUG, "send message: %d to %s address", message.message.messageType, message.message.enodbName);
3126 }
ss412g1a79bdf2019-10-24 12:03:05 +03003127
aa7133@att.combe92d712020-03-18 17:30:39 +02003128 getRequestMetaData(message, messageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03003129 if (mdclog_level_get() >= MDCLOG_INFO) {
3130 mdclog_write(MDCLOG_INFO, "send message to %s address", message.message.enodbName);
3131 }
3132
aa7133@att.combe92d712020-03-18 17:30:39 +02003133 auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId);
ss412g1a79bdf2019-10-24 12:03:05 +03003134 return rc;
3135}
3136
3137/**
3138 *
3139 * @param sctpMap
3140 * @param messageBuffer
3141 * @param message
3142 * @param failedMesgId
ss412g1a79bdf2019-10-24 12:03:05 +03003143 * @return
3144 */
3145int sendMessagetoCu(Sctp_Map_t *sctpMap,
3146 RmrMessagesBuffer_t &messageBuffer,
3147 ReportingMessages_t &message,
aa7133@att.combe92d712020-03-18 17:30:39 +02003148 int failedMesgId) {
ss412g1a79bdf2019-10-24 12:03:05 +03003149 // get the FD
3150 message.message.messageType = messageBuffer.rcvMessage->mtype;
ss412g4aeeda22020-06-16 14:12:41 +03003151 auto rc = sendSctpMsg(message.peerInfo, message, sctpMap);
ss412g1a79bdf2019-10-24 12:03:05 +03003152 return rc;
3153}
3154
ss412g1a79bdf2019-10-24 12:03:05 +03003155
3156/**
3157 *
3158 * @param epoll_fd
3159 * @param peerInfo
3160 * @param events
3161 * @param sctpMap
3162 * @param enodbName
3163 * @param msgType
ss412g1a79bdf2019-10-24 12:03:05 +03003164 * @return
3165 */
3166int addToEpoll(int epoll_fd,
3167 ConnectedCU_t *peerInfo,
3168 uint32_t events,
3169 Sctp_Map_t *sctpMap,
3170 char *enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02003171 int msgType) {
ss412g1a79bdf2019-10-24 12:03:05 +03003172 // Add to Epol
3173 struct epoll_event event{};
3174 event.data.ptr = peerInfo;
3175 event.events = events;
3176 if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peerInfo->fileDescriptor, &event) < 0) {
Alexandre Hufffff97942023-03-31 21:22:20 -03003177#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03003178 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003179 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here), %s, %s %d",
ss412g1a79bdf2019-10-24 12:03:05 +03003180 strerror(errno), __func__, __LINE__);
3181 }
3182 close(peerInfo->fileDescriptor);
aa7133@att.com84bd3342020-03-16 18:04:57 +02003183 if (enodbName != nullptr) {
aa7133@att.combe92d712020-03-18 17:30:39 +02003184 cleanHashEntry(peerInfo, sctpMap);
aa7133@att.com84bd3342020-03-16 18:04:57 +02003185 char key[MAX_ENODB_NAME_SIZE * 2];
3186 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
3187 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3188 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
3189 }
3190 auto tmp = sctpMap->find(key);
3191 if (tmp) {
3192 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05303193 tmp = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +02003194 sctpMap->erase(key);
3195 }
3196 } else {
3197 peerInfo->enodbName[0] = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03003198 }
aa7133@att.com409f2232020-10-29 13:06:45 +03003199 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here)");
ss412g1a79bdf2019-10-24 12:03:05 +03003200 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -04003201#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003202 }
ss412g1a79bdf2019-10-24 12:03:05 +03003203 return 0;
3204}
3205
3206/**
3207 *
3208 * @param epoll_fd
3209 * @param peerInfo
3210 * @param events
3211 * @param sctpMap
3212 * @param enodbName
3213 * @param msgType
ss412g1a79bdf2019-10-24 12:03:05 +03003214 * @return
3215 */
3216int modifyToEpoll(int epoll_fd,
3217 ConnectedCU_t *peerInfo,
3218 uint32_t events,
3219 Sctp_Map_t *sctpMap,
3220 char *enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02003221 int msgType) {
ss412g1a79bdf2019-10-24 12:03:05 +03003222 // Add to Epol
3223 struct epoll_event event{};
3224 event.data.ptr = peerInfo;
3225 event.events = events;
3226 if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, peerInfo->fileDescriptor, &event) < 0) {
3227 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003228 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_MOD (may check not to quit here), %s, %s %d",
ss412g1a79bdf2019-10-24 12:03:05 +03003229 strerror(errno), __func__, __LINE__);
3230 }
3231 close(peerInfo->fileDescriptor);
aa7133@att.combe92d712020-03-18 17:30:39 +02003232 cleanHashEntry(peerInfo, sctpMap);
ss412g1a79bdf2019-10-24 12:03:05 +03003233 char key[MAX_ENODB_NAME_SIZE * 2];
3234 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
3235 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3236 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
3237 }
aa7133@att.com96c9b882020-03-25 14:50:40 +02003238 auto tmp = sctpMap->find(key);
ss412g1a79bdf2019-10-24 12:03:05 +03003239 if (tmp) {
3240 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05303241 tmp = nullptr;
Alexandre Huff019cb422023-04-11 10:56:48 -03003242 sctpMap->erase(key);
sandeekuea662102022-11-08 18:51:20 +05303243 }
aa7133@att.com409f2232020-10-29 13:06:45 +03003244 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here)");
ss412g1a79bdf2019-10-24 12:03:05 +03003245 return -1;
3246 }
ss412g1a79bdf2019-10-24 12:03:05 +03003247 return 0;
3248}
3249
3250
aa7133@att.combe92d712020-03-18 17:30:39 +02003251int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message) {
ss412g1a79bdf2019-10-24 12:03:05 +03003252 buildJsonMessage(message);
dhirajverma60f8bef2021-06-29 07:22:58 -04003253#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03003254 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003255#else
dhirajverma99990292021-07-05 10:03:59 -04003256 rmrMessageBuffer.sendMessage->state = RMR_ERR_RETRY;
dhirajverma60f8bef2021-06-29 07:22:58 -04003257#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003258 if (rmrMessageBuffer.sendMessage == nullptr) {
3259 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
3260 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
ss412g1a79bdf2019-10-24 12:03:05 +03003261 return -1;
3262 }
3263
3264 if (rmrMessageBuffer.sendMessage->state != 0) {
3265 char meid[RMR_MAX_MEID]{};
3266 if (rmrMessageBuffer.sendMessage->state == RMR_ERR_RETRY) {
3267 usleep(5);
3268 rmrMessageBuffer.sendMessage->state = 0;
3269 mdclog_write(MDCLOG_INFO, "RETRY sending Message type %d to Xapp from %s",
3270 rmrMessageBuffer.sendMessage->mtype,
3271 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
dhirajverma60f8bef2021-06-29 07:22:58 -04003272#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03003273 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003274#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003275 if (rmrMessageBuffer.sendMessage == nullptr) {
3276 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
3277 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g1a79bdf2019-10-24 12:03:05 +03003278 return -1;
3279 } else if (rmrMessageBuffer.sendMessage->state != 0) {
3280 mdclog_write(MDCLOG_ERR,
3281 "Message state %s while sending request %d to Xapp from %s after retry of 10 microseconds",
3282 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
3283 rmrMessageBuffer.sendMessage->mtype,
3284 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
3285 auto rc = rmrMessageBuffer.sendMessage->state;
ss412g1a79bdf2019-10-24 12:03:05 +03003286 return rc;
3287 }
3288 } else {
3289 mdclog_write(MDCLOG_ERR, "Message state %s while sending request %d to Xapp from %s",
3290 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
3291 rmrMessageBuffer.sendMessage->mtype,
3292 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
ss412g1a79bdf2019-10-24 12:03:05 +03003293 return rmrMessageBuffer.sendMessage->state;
3294 }
3295 }
3296 return 0;
3297}
3298
3299void buildJsonMessage(ReportingMessages_t &message) {
dhirajverma60f8bef2021-06-29 07:22:58 -04003300#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04003301 jsonTrace = true;
dhirajverma60f8bef2021-06-29 07:22:58 -04003302#endif
ss412g3bac2da2020-01-05 11:52:19 +02003303 if (jsonTrace) {
3304 message.outLen = sizeof(message.base64Data);
3305 base64::encode((const unsigned char *) message.message.asndata,
3306 (const int) message.message.asnLength,
3307 message.base64Data,
3308 message.outLen);
3309 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03003310 mdclog_write(MDCLOG_DEBUG, "Tracing: ASN length = %d, base64 message length = %d ",
ss412g3bac2da2020-01-05 11:52:19 +02003311 (int) message.message.asnLength,
3312 (int) message.outLen);
3313 }
3314
3315 snprintf(message.buffer, sizeof(message.buffer),
aa7133@att.com96c9b882020-03-25 14:50:40 +02003316 "{\"header\": {\"ts\": \"%ld.%09ld\","
3317 "\"ranName\": \"%s\","
3318 "\"messageType\": %d,"
3319 "\"direction\": \"%c\"},"
3320 "\"base64Length\": %d,"
3321 "\"asnBase64\": \"%s\"}",
3322 message.message.time.tv_sec,
3323 message.message.time.tv_nsec,
3324 message.message.enodbName,
3325 message.message.messageType,
3326 message.message.direction,
3327 (int) message.outLen,
3328 message.base64Data);
ss412g3bac2da2020-01-05 11:52:19 +02003329 static src::logger_mt &lg = my_logger::get();
3330
3331 BOOST_LOG(lg) << message.buffer;
ss412g1a79bdf2019-10-24 12:03:05 +03003332 }
ss412g1a79bdf2019-10-24 12:03:05 +03003333}
3334
3335
3336/**
3337 * take RMR error code to string
3338 * @param state
3339 * @return
3340 */
3341string translateRmrErrorMessages(int state) {
3342 string str = {};
3343 switch (state) {
3344 case RMR_OK:
3345 str = "RMR_OK - state is good";
3346 break;
3347 case RMR_ERR_BADARG:
aa7133@att.com409f2232020-10-29 13:06:45 +03003348 str = "RMR_ERR_BADARG - argument passed to function was unusable";
ss412g1a79bdf2019-10-24 12:03:05 +03003349 break;
3350 case RMR_ERR_NOENDPT:
3351 str = "RMR_ERR_NOENDPT - send//call could not find an endpoint based on msg type";
3352 break;
3353 case RMR_ERR_EMPTY:
3354 str = "RMR_ERR_EMPTY - msg received had no payload; attempt to send an empty message";
3355 break;
3356 case RMR_ERR_NOHDR:
3357 str = "RMR_ERR_NOHDR - message didn't contain a valid header";
3358 break;
3359 case RMR_ERR_SENDFAILED:
3360 str = "RMR_ERR_SENDFAILED - send failed; errno has nano reason";
3361 break;
3362 case RMR_ERR_CALLFAILED:
3363 str = "RMR_ERR_CALLFAILED - unable to send call() message";
3364 break;
3365 case RMR_ERR_NOWHOPEN:
3366 str = "RMR_ERR_NOWHOPEN - no wormholes are open";
3367 break;
3368 case RMR_ERR_WHID:
3369 str = "RMR_ERR_WHID - wormhole id was invalid";
3370 break;
3371 case RMR_ERR_OVERFLOW:
3372 str = "RMR_ERR_OVERFLOW - operation would have busted through a buffer/field size";
3373 break;
3374 case RMR_ERR_RETRY:
3375 str = "RMR_ERR_RETRY - request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)";
3376 break;
3377 case RMR_ERR_RCVFAILED:
3378 str = "RMR_ERR_RCVFAILED - receive failed (hard error)";
3379 break;
3380 case RMR_ERR_TIMEOUT:
3381 str = "RMR_ERR_TIMEOUT - message processing call timed out";
3382 break;
3383 case RMR_ERR_UNSET:
3384 str = "RMR_ERR_UNSET - the message hasn't been populated with a transport buffer";
3385 break;
3386 case RMR_ERR_TRUNC:
3387 str = "RMR_ERR_TRUNC - received message likely truncated";
3388 break;
3389 case RMR_ERR_INITFAILED:
3390 str = "RMR_ERR_INITFAILED - initialisation of something (probably message) failed";
3391 break;
3392 case RMR_ERR_NOTSUPP:
3393 str = "RMR_ERR_NOTSUPP - the request is not supported, or RMr was not initialised for the request";
3394 break;
3395 default:
3396 char buf[128]{};
3397 snprintf(buf, sizeof buf, "UNDOCUMENTED RMR_ERR : %d", state);
3398 str = buf;
3399 break;
3400 }
3401 return str;
3402}
czichy2175dd32022-05-17 15:24:51 +03003403int fetchStreamId(ConnectedCU_t *peerInfo, ReportingMessages_t &message)
3404{
3405 auto loglevel = mdclog_level_get();
3406 int streamId = INVALID_STREAM_ID;
3407 if(message.peerInfo->isSingleStream != false)
3408 {
3409 streamId = message.peerInfo->singleStreamId;
3410 if (loglevel >= MDCLOG_DEBUG) {
3411 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for SINGLE_STREAM streamId %d , Messeage Type %d ,%s",
3412 streamId,message.message.messageType, __FUNCTION__);
3413 }
3414 return streamId;
3415 }
3416 int msgType = message.message.messageType;
3417 switch (msgType){
3418 case RIC_E2_RESET_REQ:
3419 case RIC_E2_RESET_RESP:
3420 case RIC_E2_SETUP_RESP:
3421 case RIC_E2_SETUP_FAILURE:
3422 case RIC_ERROR_INDICATION:
3423 case RIC_SERVICE_QUERY:
3424 case RIC_SERVICE_UPDATE_ACK:
3425 case RIC_SERVICE_UPDATE_FAILURE:
3426 streamId = 0;
3427 break;
3428 case RIC_SUB_REQ:
3429 case RIC_SUB_DEL_REQ:
3430 case RIC_CONTROL_REQ:
3431 streamId = 1;
3432 break;
3433 default:
3434 streamId = 0;
3435 break;
3436 }
3437 if (loglevel >= MDCLOG_DEBUG) {
3438 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for streamId %d Messeage Type %d, %s",
3439 streamId, message.message.messageType, __FUNCTION__);
3440 }
3441 return streamId;
3442}