blob: 423d51e1837ee01284f1f8faa922498962cbc057 [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>
35
aa7133@att.com84bd3342020-03-16 18:04:57 +020036using namespace std;
37//using namespace std::placeholders;
ss412g3bac2da2020-01-05 11:52:19 +020038using namespace boost::filesystem;
ss412g4aeeda22020-06-16 14:12:41 +030039using namespace prometheus;
40
ss412g3bac2da2020-01-05 11:52:19 +020041
ss412g1a79bdf2019-10-24 12:03:05 +030042//#ifdef __cplusplus
43//extern "C"
44//{
45//#endif
46
ss412g3bac2da2020-01-05 11:52:19 +020047// need to expose without the include of gcov
48extern "C" void __gcov_flush(void);
dhirajverma55e755b2021-06-29 02:01:47 +053049#define LOG_FILE_CONFIG_MAP "CONFIG_MAP_NAME"
ss412g3bac2da2020-01-05 11:52:19 +020050
51static void catch_function(int signal) {
52 __gcov_flush();
53 exit(signal);
54}
55
56
ss412g1a79bdf2019-10-24 12:03:05 +030057BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::logger_mt)
58
59boost::shared_ptr<sinks::synchronous_sink<sinks::text_file_backend>> boostLogger;
ss412g3bac2da2020-01-05 11:52:19 +020060double cpuClock = 0.0;
aa7133@att.com41fcb3f2020-11-29 13:48:25 +020061bool jsonTrace = false;
ss412g1a79bdf2019-10-24 12:03:05 +030062
wahidw1d1a9b72021-09-24 17:35:28 +000063char* getinterfaceip()
64{
65 char hostname[256];
66 char *IP;
67 struct hostent *host_entry;
68 int retVal;
69 retVal = gethostname(hostname, sizeof(hostname));
70 if ( retVal == -1 )
71 return NULL;
72 host_entry = gethostbyname(hostname);
73 if ( host_entry == NULL )
74 return NULL;
75 IP = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0]));
76 return IP;
77}
78
dhirajverma55e755b2021-06-29 02:01:47 +053079
80static int enable_log_change_notify(const char* fileName)
81{
82 int ret = -1;
83 struct stat fileInfo;
84 if ( lstat(fileName,&fileInfo) == 0 )
85 {
86 ret = register_log_change_notify(fileName);
87 }
88 return ret;
89}
90
91
92static int register_log_change_notify(const char *fileName)
93{
94 pthread_attr_t cb_attr;
95 pthread_t tid;
96 pthread_attr_init(&cb_attr);
97 pthread_attr_setdetachstate(&cb_attr,PTHREAD_CREATE_DETACHED);
dhirajverma9f59b572021-07-23 02:36:13 -040098 return pthread_create(&tid, &cb_attr,&monitor_loglevel_change_handler,(void *)fileName);
dhirajverma55e755b2021-06-29 02:01:47 +053099}
100
101
102static void * monitor_loglevel_change_handler(void* arg)
103{
104 char *fileName = (char*) arg;
105 int ifd; // the inotify file des
106 int wfd; // the watched file des
107 ssize_t n = 0;
108 char rbuf[4096]; // large read buffer as the event is var len
109 fd_set fds;
110 int res = 0;
111 struct timeval timeout;
112 char* dname=NULL; // directory name
113 char* bname = NULL; // basename
114 char* tok=NULL;
115 char* log_level=NULL;
116
117 dname = strdup( fileName); // defrock the file name into dir and basename
118 if( (tok = strrchr( dname, '/' )) != NULL ) {
119 *tok = '\0';
120 bname = strdup( tok+1 );
121 }
122
123
124 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 {
133
134
135 memset( &timeout, 0, sizeof(timeout) );
136 while( 1 ) {
137 FD_ZERO (&fds);
138 FD_SET (ifd, &fds);
139 timeout.tv_sec=1;
140 res = select (ifd + 1, &fds, NULL, NULL, &timeout);
141 if(res)
142 {
143 n = read( ifd, rbuf, sizeof( rbuf ) ); // read the event
144 if( n < 0 ) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400145#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
dhirajverma55e755b2021-06-29 02:01:47 +0530146 if( errno == EAGAIN ) {
147 } else {
wahidw1d1a9b72021-09-24 17:35:28 +0000148 printf( "### CRIT ### config listener read err: %s\n", strerror( errno ) );
dhirajverma55e755b2021-06-29 02:01:47 +0530149 }
150 continue;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400151#endif
dhirajverma55e755b2021-06-29 02:01:47 +0530152 }
153
154 //Retrieving Log Level from configmap by parsing configmap file
155 log_level = parse_file(fileName);
156 update_mdc_log_level_severity(log_level); //setting log level
157 free(log_level);
158 }
159 }
160 inotify_rm_watch(ifd,wfd);
161 }
162 close(ifd);
163 }
164 free(bname);
165 free(dname);
166
167 pthread_exit(NULL);
168}
169
170void update_mdc_log_level_severity(char* log_level)
171{
172 mdclog_severity_t level = MDCLOG_ERR;
173
174 if(log_level == NULL)
175 {
176 printf("### ERR ### Invalid Log-Level Configuration in ConfigMap, Default Log-Level Applied: %d\n",level);
177 }
178 else if(strcasecmp(log_level,"1")==0)
179 {
180 level = MDCLOG_ERR;
181 }
182 else if(strcasecmp(log_level,"2")==0)
183 {
184 level = MDCLOG_WARN;
185 }
186 else if(strcasecmp(log_level,"3")==0)
187 {
188 level = MDCLOG_INFO;
189 }
190 else if(strcasecmp(log_level,"4")==0)
191 {
192 level = MDCLOG_DEBUG;
193 }
194
195 mdclog_level_set(level);
196}
197static char* parse_file(char* filename)
198{
199 char *token=NULL;
200 char *search = ": ";
201 char *string_match = "log-level";
202 bool found = false;
203 FILE *file = fopen ( filename, "r" );
204 if ( file != NULL )
205 {
206 char line [ 128 ];
207 while ( fgets ( line, sizeof line, file ) != NULL )
208 {
209 token = strtok(line, search);
210 if(strcmp(token,string_match)==0)
211 {
212 found = true;
213 token = strtok(NULL, search);
214 token = strtok(token, "\n");//removing newline if any
215 break;
216 }
217 }
218 fclose ( file );
219 }
220 if(found)
221 return(strdup(token));
222 else
223 return(NULL);
224}
225
226char *read_env_param(const char*envkey)
227{
228 if(envkey)
229 {
230 char *value = getenv(envkey);
231 if(value)
232 return strdup(value);
233 }
234 return NULL;
235}
236
237void dynamic_log_level_change()
238{
239 char *logFile_Name = read_env_param(LOG_FILE_CONFIG_MAP);
240 char* log_level_init=NULL;
241 if(logFile_Name)
242 {
243 log_level_init = parse_file(logFile_Name);
244 update_mdc_log_level_severity(log_level_init); //setting log level
245 free(log_level_init);
246
247 }
248 enable_log_change_notify(logFile_Name);
249 free(logFile_Name);
250
251}
252
ss412g1a79bdf2019-10-24 12:03:05 +0300253void init_log() {
dhirajverma55e755b2021-06-29 02:01:47 +0530254 int log_change_monitor = 0;
ss412g1a79bdf2019-10-24 12:03:05 +0300255 mdclog_attr_t *attr;
256 mdclog_attr_init(&attr);
257 mdclog_attr_set_ident(attr, "E2Terminator");
258 mdclog_init(attr);
dhirajverma5f132832021-06-17 17:27:54 +0530259 if(mdclog_format_initialize(log_change_monitor)!=0)
260 mdclog_write(MDCLOG_ERR, "Failed to intialize MDC log format !!!");
dhirajverma55e755b2021-06-29 02:01:47 +0530261 dynamic_log_level_change();
ss412g1a79bdf2019-10-24 12:03:05 +0300262 mdclog_attr_destroy(attr);
263}
ss412g3bac2da2020-01-05 11:52:19 +0200264auto start_time = std::chrono::high_resolution_clock::now();
265typedef std::chrono::duration<double, std::ratio<1,1>> seconds_t;
ss412g1a79bdf2019-10-24 12:03:05 +0300266
ss412g3bac2da2020-01-05 11:52:19 +0200267double age() {
268 return seconds_t(std::chrono::high_resolution_clock::now() - start_time).count();
269}
270
aa7133@att.com409f2232020-10-29 13:06:45 +0300271double approx_CPU_MHz(unsigned sleepTime) {
ss412g3bac2da2020-01-05 11:52:19 +0200272 using namespace std::chrono_literals;
273 uint32_t aux = 0;
274 uint64_t cycles_start = rdtscp(aux);
275 double time_start = age();
aa7133@att.com409f2232020-10-29 13:06:45 +0300276 std::this_thread::sleep_for(sleepTime * 1ms);
ss412g3bac2da2020-01-05 11:52:19 +0200277 uint64_t elapsed_cycles = rdtscp(aux) - cycles_start;
278 double elapsed_time = age() - time_start;
279 return elapsed_cycles / elapsed_time;
280}
ss412g1a79bdf2019-10-24 12:03:05 +0300281
282//std::atomic<int64_t> rmrCounter{0};
283std::atomic<int64_t> num_of_messages{0};
ss412g3bac2da2020-01-05 11:52:19 +0200284std::atomic<int64_t> num_of_XAPP_messages{0};
ss412g1a79bdf2019-10-24 12:03:05 +0300285static long transactionCounter = 0;
sandeekuea662102022-11-08 18:51:20 +0530286pthread_mutex_t thread_lock;
ss412g1a79bdf2019-10-24 12:03:05 +0300287
aa7133@att.com84bd3342020-03-16 18:04:57 +0200288int buildListeningPort(sctp_params_t &sctpParams) {
aa7133@att.comf211f192020-06-23 12:50:10 +0300289 sctpParams.listenFD = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP);
290 if (sctpParams.listenFD <= 0) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400291#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comf211f192020-06-23 12:50:10 +0300292 mdclog_write(MDCLOG_ERR, "Error Opening socket, %s", strerror(errno));
293 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400294#endif
aa7133@att.comf211f192020-06-23 12:50:10 +0300295 }
czichy2175dd32022-05-17 15:24:51 +0300296 struct sctp_initmsg initmsg;
297 memset (&initmsg, 0, sizeof (initmsg));
298 initmsg.sinit_num_ostreams = 2;
299 initmsg.sinit_max_instreams = 2;
300 initmsg.sinit_max_attempts = 4;
301 setsockopt (sctpParams.listenFD, IPPROTO_SCTP, SCTP_INITMSG, &initmsg, sizeof (initmsg));
aa7133@att.comf211f192020-06-23 12:50:10 +0300302
aa7133@att.com409f2232020-10-29 13:06:45 +0300303 struct sockaddr_in6 serverAddress {};
304 serverAddress.sin6_family = AF_INET6;
305 serverAddress.sin6_addr = in6addr_any;
306 serverAddress.sin6_port = htons(sctpParams.sctpPort);
307 if (bind(sctpParams.listenFD, (SA *)&serverAddress, sizeof(serverAddress)) < 0 ) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400308#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comf211f192020-06-23 12:50:10 +0300309 mdclog_write(MDCLOG_ERR, "Error binding port %d. %s", sctpParams.sctpPort, strerror(errno));
aa7133@att.com84bd3342020-03-16 18:04:57 +0200310 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400311#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +0200312 }
313 if (setSocketNoBlocking(sctpParams.listenFD) == -1) {
314 //mdclog_write(MDCLOG_ERR, "Error binding. %s", strerror(errno));
315 return -1;
316 }
317 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300318 struct sockaddr_in6 clientAddress {};
319 socklen_t len = sizeof(clientAddress);
320 getsockname(sctpParams.listenFD, (SA *)&clientAddress, &len);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200321 char buff[1024] {};
aa7133@att.com409f2232020-10-29 13:06:45 +0300322 inet_ntop(AF_INET6, &clientAddress.sin6_addr, buff, sizeof(buff));
323 mdclog_write(MDCLOG_DEBUG, "My address: %s, port %d\n", buff, htons(clientAddress.sin6_port));
ss412g1a79bdf2019-10-24 12:03:05 +0300324 }
325
aa7133@att.com84bd3342020-03-16 18:04:57 +0200326 if (listen(sctpParams.listenFD, SOMAXCONN) < 0) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400327#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +0200328 mdclog_write(MDCLOG_ERR, "Error listening. %s\n", strerror(errno));
329 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400330#endif
ss412g3bac2da2020-01-05 11:52:19 +0200331 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200332 struct epoll_event event {};
333 event.events = EPOLLIN | EPOLLET;
334 event.data.fd = sctpParams.listenFD;
335
336 // add listening port to epoll
337 if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.listenFD, &event)) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400338#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +0200339 printf("Failed to add descriptor to epoll\n");
340 mdclog_write(MDCLOG_ERR, "Failed to add descriptor to epoll. %s\n", strerror(errno));
341 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400342#endif
ss412g3bac2da2020-01-05 11:52:19 +0200343 }
344
aa7133@att.com84bd3342020-03-16 18:04:57 +0200345 return 0;
346}
ss412g3bac2da2020-01-05 11:52:19 +0200347
aa7133@att.com84bd3342020-03-16 18:04:57 +0200348int buildConfiguration(sctp_params_t &sctpParams) {
ss412g3bac2da2020-01-05 11:52:19 +0200349 path p = (sctpParams.configFilePath + "/" + sctpParams.configFileName).c_str();
350 if (exists(p)) {
351 const int size = 2048;
352 auto fileSize = file_size(p);
353 if (fileSize > size) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400354#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200355 mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200356 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400357#endif
ss412g3bac2da2020-01-05 11:52:19 +0200358 }
359 } else {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400360#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200361 mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str());
aa7133@att.com84bd3342020-03-16 18:04:57 +0200362 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400363#endif
ss412g3bac2da2020-01-05 11:52:19 +0200364 }
365
ss412g3bac2da2020-01-05 11:52:19 +0200366 ReadConfigFile conf;
367 if (conf.openConfigFile(p.string()) == -1) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400368#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200369 mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s",
370 p.string().c_str(), strerror(errno));
aa7133@att.com84bd3342020-03-16 18:04:57 +0200371 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400372#endif
ss412g3bac2da2020-01-05 11:52:19 +0200373 }
374 int rmrPort = conf.getIntValue("nano");
375 if (rmrPort == -1) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400376#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300377 mdclog_write(MDCLOG_ERR, "illegal RMR port ");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200378 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400379#endif
ss412g3bac2da2020-01-05 11:52:19 +0200380 }
381 sctpParams.rmrPort = (uint16_t)rmrPort;
382 snprintf(sctpParams.rmrAddress, sizeof(sctpParams.rmrAddress), "%d", (int) (sctpParams.rmrPort));
dhirajverma5f132832021-06-17 17:27:54 +0530383 auto tmpStr = conf.getStringValue("volume");
ss412g3bac2da2020-01-05 11:52:19 +0200384 if (tmpStr.length() == 0) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400385#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300386 mdclog_write(MDCLOG_ERR, "illegal volume.");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200387 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400388#endif
ss412g3bac2da2020-01-05 11:52:19 +0200389 }
390
ss412g1a79bdf2019-10-24 12:03:05 +0300391 char tmpLogFilespec[VOLUME_URL_SIZE];
392 tmpLogFilespec[0] = 0;
ss412g3bac2da2020-01-05 11:52:19 +0200393 sctpParams.volume[0] = 0;
394 snprintf(sctpParams.volume, VOLUME_URL_SIZE, "%s", tmpStr.c_str());
395 // copy the name to temp file as well
396 snprintf(tmpLogFilespec, VOLUME_URL_SIZE, "%s", tmpStr.c_str());
397
398
399 // define the file name in the tmp directory under the volume
400 strcat(tmpLogFilespec,"/tmp/E2Term_%Y-%m-%d_%H-%M-%S.%N.tmpStr");
401
402 sctpParams.myIP = conf.getStringValue("local-ip");
403 if (sctpParams.myIP.length() == 0) {
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 local-ip.");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200406 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400407#endif
ss412g1a79bdf2019-10-24 12:03:05 +0300408 }
409
aa7133@att.combe92d712020-03-18 17:30:39 +0200410 int sctpPort = conf.getIntValue("sctp-port");
411 if (sctpPort == -1) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400412#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300413 mdclog_write(MDCLOG_ERR, "illegal SCTP port ");
aa7133@att.combe92d712020-03-18 17:30:39 +0200414 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400415#endif
aa7133@att.combe92d712020-03-18 17:30:39 +0200416 }
417 sctpParams.sctpPort = (uint16_t)sctpPort;
418
aa7133@att.com84bd3342020-03-16 18:04:57 +0200419 sctpParams.fqdn = conf.getStringValue("external-fqdn");
420 if (sctpParams.fqdn.length() == 0) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400421#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com409f2232020-10-29 13:06:45 +0300422 mdclog_write(MDCLOG_ERR, "illegal external-fqdn");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200423 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400424#endif
ss412g3bac2da2020-01-05 11:52:19 +0200425 }
ss412g1a79bdf2019-10-24 12:03:05 +0300426
aa7133@att.com342843e2020-01-26 12:53:34 +0200427 std::string pod = conf.getStringValue("pod_name");
dhirajverma6cf28612021-06-23 04:53:34 -0400428#ifndef UNIT_TEST
aa7133@att.com342843e2020-01-26 12:53:34 +0200429 if (pod.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300430 mdclog_write(MDCLOG_ERR, "illegal pod_name in config file");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200431 return -1;
aa7133@att.com342843e2020-01-26 12:53:34 +0200432 }
433 auto *podName = getenv(pod.c_str());
434 if (podName == nullptr) {
aa7133@att.com54885fe2020-10-29 17:24:49 +0300435 mdclog_write(MDCLOG_ERR, "illegal pod_name or environment variable not exists : %s", pod.c_str());
aa7133@att.com84bd3342020-03-16 18:04:57 +0200436 return -1;
aa7133@att.com342843e2020-01-26 12:53:34 +0200437
438 } else {
439 sctpParams.podName.assign(podName);
440 if (sctpParams.podName.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300441 mdclog_write(MDCLOG_ERR, "illegal pod_name");
aa7133@att.com84bd3342020-03-16 18:04:57 +0200442 return -1;
aa7133@att.com342843e2020-01-26 12:53:34 +0200443 }
444 }
dhirajverma6cf28612021-06-23 04:53:34 -0400445#endif
ss412g3bac2da2020-01-05 11:52:19 +0200446 tmpStr = conf.getStringValue("trace");
447 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
448 if ((tmpStr.compare("start")) == 0) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400449#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +0200450 mdclog_write(MDCLOG_INFO, "Trace set to: start");
451 sctpParams.trace = true;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400452#endif
ss412g3bac2da2020-01-05 11:52:19 +0200453 } else if ((tmpStr.compare("stop")) == 0) {
454 mdclog_write(MDCLOG_INFO, "Trace set to: stop");
455 sctpParams.trace = false;
aa7133@att.com41fcb3f2020-11-29 13:48:25 +0200456 } else {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400457#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com41fcb3f2020-11-29 13:48:25 +0200458 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 +0200459 sctpParams.trace = false;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400460#endif
ss412g3bac2da2020-01-05 11:52:19 +0200461 }
462 jsonTrace = sctpParams.trace;
ss412g1a79bdf2019-10-24 12:03:05 +0300463
ss412g4aeeda22020-06-16 14:12:41 +0300464 sctpParams.epollTimeOut = -1;
ss412g4aeeda22020-06-16 14:12:41 +0300465
466 tmpStr = conf.getStringValue("prometheusPort");
467 if (tmpStr.length() != 0) {
468 sctpParams.prometheusPort = tmpStr;
469 }
470
aa7133@att.combe92d712020-03-18 17:30:39 +0200471 sctpParams.ka_message_length = snprintf(sctpParams.ka_message, KA_MESSAGE_SIZE, "{\"address\": \"%s:%d\","
aa7133@att.com96c9b882020-03-25 14:50:40 +0200472 "\"fqdn\": \"%s\","
473 "\"pod_name\": \"%s\"}",
aa7133@att.com342843e2020-01-26 12:53:34 +0200474 (const char *)sctpParams.myIP.c_str(),
475 sctpParams.rmrPort,
476 sctpParams.fqdn.c_str(),
477 sctpParams.podName.c_str());
478
ss412g1a79bdf2019-10-24 12:03:05 +0300479 if (mdclog_level_get() >= MDCLOG_INFO) {
dhirajverma5f132832021-06-17 17:27:54 +0530480 mdclog_write(MDCLOG_DEBUG,"RMR Port: %s", to_string(sctpParams.rmrPort).c_str());
481 mdclog_write(MDCLOG_DEBUG,"LogLevel: %s", to_string(sctpParams.logLevel).c_str());
482 mdclog_write(MDCLOG_DEBUG,"volume: %s", sctpParams.volume);
483 mdclog_write(MDCLOG_DEBUG,"tmpLogFilespec: %s", tmpLogFilespec);
484 mdclog_write(MDCLOG_DEBUG,"my ip: %s", sctpParams.myIP.c_str());
485 mdclog_write(MDCLOG_DEBUG,"pod name: %s", sctpParams.podName.c_str());
ss412g1a79bdf2019-10-24 12:03:05 +0300486
aa7133@att.com342843e2020-01-26 12:53:34 +0200487 mdclog_write(MDCLOG_INFO, "running parameters for instance : %s", sctpParams.ka_message);
ss412g1a79bdf2019-10-24 12:03:05 +0300488 }
ss412g1a79bdf2019-10-24 12:03:05 +0300489
490 // Files written to the current working directory
491 boostLogger = logging::add_file_log(
ss412g3bac2da2020-01-05 11:52:19 +0200492 keywords::file_name = tmpLogFilespec, // to temp directory
ss412g1a79bdf2019-10-24 12:03:05 +0300493 keywords::rotation_size = 10 * 1024 * 1024,
494 keywords::time_based_rotation = sinks::file::rotation_at_time_interval(posix_time::hours(1)),
495 keywords::format = "%Message%"
ss412g3bac2da2020-01-05 11:52:19 +0200496 //keywords::format = "[%TimeStamp%]: %Message%" // use each tmpStr with time stamp
ss412g1a79bdf2019-10-24 12:03:05 +0300497 );
498
aa7133@att.com54885fe2020-10-29 17:24:49 +0300499 // Setup a destination folder for collecting rotated (closed) files --since the same volume can use rename()
ss412g1a79bdf2019-10-24 12:03:05 +0300500 boostLogger->locked_backend()->set_file_collector(sinks::file::make_collector(
ss412g3bac2da2020-01-05 11:52:19 +0200501 keywords::target = sctpParams.volume
ss412g1a79bdf2019-10-24 12:03:05 +0300502 ));
503
504 // Upon restart, scan the directory for files matching the file_name pattern
505 boostLogger->locked_backend()->scan_for_files();
506
ss412g3bac2da2020-01-05 11:52:19 +0200507 // Enable auto-flushing after each tmpStr record written
ss412g1a79bdf2019-10-24 12:03:05 +0300508 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +0200509 boostLogger->locked_backend()->auto_flush(true);
510 }
511
512 return 0;
513}
514
aa7133@att.coma4c80012020-06-24 16:36:47 +0300515void startPrometheus(sctp_params_t &sctpParams) {
Mohamed Abukar64f37242021-08-15 12:39:56 +0000516 auto podName = std::getenv("POD_NAME");
517 string metric = "E2TBeta";
518 if (strstr(podName, "alpha") != NULL) {
519 metric = "E2TAlpha";
520 }
wahidw1d1a9b72021-09-24 17:35:28 +0000521 //Get eth0 interface IP
522 char* host = getinterfaceip();
523 string hostip = host;
Mohamed Abukar64f37242021-08-15 12:39:56 +0000524
aa7133@att.coma4c80012020-06-24 16:36:47 +0300525 sctpParams.prometheusFamily = &BuildCounter()
Mohamed Abukar64f37242021-08-15 12:39:56 +0000526 .Name(metric.c_str())
527 .Help("E2T instance metrics")
aa7133@att.coma4c80012020-06-24 16:36:47 +0300528 .Labels({{"POD_NAME", sctpParams.podName}})
529 .Register(*sctpParams.prometheusRegistry);
aa7133@att.com16c799b2020-03-24 18:01:51 +0200530
Mohamed Abukar64f37242021-08-15 12:39:56 +0000531 // Build E2T instance level metrics
532 buildE2TPrometheusCounters(sctpParams);
533
wahidw1d1a9b72021-09-24 17:35:28 +0000534 string prometheusPath;
535 if (hostip.empty())
536 prometheusPath = sctpParams.prometheusPort + "," + "[::]:" + sctpParams.prometheusPort;
537 else
538 prometheusPath = hostip + ":" + sctpParams.prometheusPort;
539
aa7133@att.comb92748d2020-06-29 11:52:30 +0300540 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com54885fe2020-10-29 17:24:49 +0300541 mdclog_write(MDCLOG_DEBUG, "Start Prometheus Pull mode on %s", prometheusPath.c_str());
aa7133@att.coma4c80012020-06-24 16:36:47 +0300542 }
aa7133@att.com54885fe2020-10-29 17:24:49 +0300543 sctpParams.prometheusExposer = new Exposer(prometheusPath, 1);
aa7133@att.comb92748d2020-06-29 11:52:30 +0300544 sctpParams.prometheusExposer->RegisterCollectable(sctpParams.prometheusRegistry);
aa7133@att.coma4c80012020-06-24 16:36:47 +0300545}
dhirajverma31768a92021-05-06 12:38:49 +0530546#ifndef UNIT_TEST
dhirajverma5f132832021-06-17 17:27:54 +0530547
aa7133@att.com84bd3342020-03-16 18:04:57 +0200548int main(const int argc, char **argv) {
549 sctp_params_t sctpParams;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200550 {
551 std::random_device device{};
552 std::mt19937 generator(device());
553 std::uniform_int_distribution<long> distribution(1, (long) 1e12);
554 transactionCounter = distribution(generator);
555 }
556
557// uint64_t st = 0;
558// uint32_t aux1 = 0;
559// st = rdtscp(aux1);
560
561 unsigned num_cpus = std::thread::hardware_concurrency();
562 init_log();
aa7133@att.com84bd3342020-03-16 18:04:57 +0200563 if (std::signal(SIGINT, catch_function) == SIG_ERR) {
564 mdclog_write(MDCLOG_ERR, "Error initializing SIGINT");
565 exit(1);
566 }
567 if (std::signal(SIGABRT, catch_function)== SIG_ERR) {
568 mdclog_write(MDCLOG_ERR, "Error initializing SIGABRT");
569 exit(1);
570 }
571 if (std::signal(SIGTERM, catch_function)== SIG_ERR) {
572 mdclog_write(MDCLOG_ERR, "Error initializing SIGTERM");
573 exit(1);
574 }
575
576 cpuClock = approx_CPU_MHz(100);
577
578 mdclog_write(MDCLOG_DEBUG, "CPU speed %11.11f", cpuClock);
579
580 auto result = parse(argc, argv, sctpParams);
581
582 if (buildConfiguration(sctpParams) != 0) {
583 exit(-1);
ss412g1a79bdf2019-10-24 12:03:05 +0300584 }
585
ss412g4aeeda22020-06-16 14:12:41 +0300586 //auto registry = std::make_shared<Registry>();
587 sctpParams.prometheusRegistry = std::make_shared<Registry>();
588
aa7133@att.com409f2232020-10-29 13:06:45 +0300589 //sctpParams.prometheusFamily = new Family<Counter>("E2T", "E2T message counter", {{"E", sctpParams.podName}});
ss412g4aeeda22020-06-16 14:12:41 +0300590
aa7133@att.coma4c80012020-06-24 16:36:47 +0300591 startPrometheus(sctpParams);
ss412g4aeeda22020-06-16 14:12:41 +0300592
ss412g1a79bdf2019-10-24 12:03:05 +0300593 // start epoll
ss412g3bac2da2020-01-05 11:52:19 +0200594 sctpParams.epoll_fd = epoll_create1(0);
595 if (sctpParams.epoll_fd == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +0300596 mdclog_write(MDCLOG_ERR, "failed to open epoll descriptor");
597 exit(-1);
598 }
aa7133@att.combe92d712020-03-18 17:30:39 +0200599 getRmrContext(sctpParams);
ss412g3bac2da2020-01-05 11:52:19 +0200600 if (sctpParams.rmrCtx == nullptr) {
601 close(sctpParams.epoll_fd);
ss412g1a79bdf2019-10-24 12:03:05 +0300602 exit(-1);
603 }
604
ss412g3bac2da2020-01-05 11:52:19 +0200605 if (buildInotify(sctpParams) == -1) {
606 close(sctpParams.rmrListenFd);
607 rmr_close(sctpParams.rmrCtx);
608 close(sctpParams.epoll_fd);
609 exit(-1);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200610 }
611
612 if (buildListeningPort(sctpParams) != 0) {
613 close(sctpParams.rmrListenFd);
614 rmr_close(sctpParams.rmrCtx);
615 close(sctpParams.epoll_fd);
616 exit(-1);
617 }
ss412g3bac2da2020-01-05 11:52:19 +0200618
619 sctpParams.sctpMap = new mapWrapper();
ss412g1a79bdf2019-10-24 12:03:05 +0300620
sandeekuea662102022-11-08 18:51:20 +0530621 if (pthread_mutex_init(&thread_lock, NULL) != 0) {
622 mdclog_write(MDCLOG_ERR, "failed to init thread lock");
623 exit(-1);
624 }
ss412g1a79bdf2019-10-24 12:03:05 +0300625 std::vector<std::thread> threads(num_cpus);
626// std::vector<std::thread> threads;
627
aa7133@att.com24e9fa42020-11-13 20:32:53 +0200628 num_cpus = 3;
ss412g1a79bdf2019-10-24 12:03:05 +0300629 for (unsigned int i = 0; i < num_cpus; i++) {
ss412g3bac2da2020-01-05 11:52:19 +0200630 threads[i] = std::thread(listener, &sctpParams);
ss412g1a79bdf2019-10-24 12:03:05 +0300631
632 cpu_set_t cpuset;
633 CPU_ZERO(&cpuset);
634 CPU_SET(i, &cpuset);
635 int rc = pthread_setaffinity_np(threads[i].native_handle(), sizeof(cpu_set_t), &cpuset);
636 if (rc != 0) {
637 mdclog_write(MDCLOG_ERR, "Error calling pthread_setaffinity_np: %d", rc);
638 }
ss412g1a79bdf2019-10-24 12:03:05 +0300639 }
640
aa7133@att.com16c799b2020-03-24 18:01:51 +0200641
ss412g3bac2da2020-01-05 11:52:19 +0200642 //loop over term_init until first message from xApp
643 handleTermInit(sctpParams);
644
645 for (auto &t : threads) {
646 t.join();
647 }
sandeekuea662102022-11-08 18:51:20 +0530648 pthread_mutex_destroy(&thread_lock);
ss412g3bac2da2020-01-05 11:52:19 +0200649 return 0;
650}
dhirajverma60f8bef2021-06-29 07:22:58 -0400651#endif
ss412g3bac2da2020-01-05 11:52:19 +0200652void handleTermInit(sctp_params_t &sctpParams) {
653 sendTermInit(sctpParams);
ss412g1a79bdf2019-10-24 12:03:05 +0300654 //send to e2 manager init of e2 term
655 //E2_TERM_INIT
ss412g1a79bdf2019-10-24 12:03:05 +0300656
ss412g3bac2da2020-01-05 11:52:19 +0200657 int count = 0;
658 while (true) {
659 auto xappMessages = num_of_XAPP_messages.load(std::memory_order_acquire);
660 if (xappMessages > 0) {
661 if (mdclog_level_get() >= MDCLOG_INFO) {
aa7133@att.com54885fe2020-10-29 17:24:49 +0300662 mdclog_write(MDCLOG_INFO, "Got a message from some application, stop sending E2_TERM_INIT");
ss412g3bac2da2020-01-05 11:52:19 +0200663 }
664 return;
665 }
666 usleep(100000);
667 count++;
668 if (count % 1000 == 0) {
669 mdclog_write(MDCLOG_ERR, "GOT No messages from any xApp");
670 sendTermInit(sctpParams);
671 }
672 }
673}
674
675void sendTermInit(sctp_params_t &sctpParams) {
676 rmr_mbuf_t *msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.ka_message_length);
ss412g1a79bdf2019-10-24 12:03:05 +0300677 auto count = 0;
ss412g3bac2da2020-01-05 11:52:19 +0200678 while (true) {
ss412g1a79bdf2019-10-24 12:03:05 +0300679 msg->mtype = E2_TERM_INIT;
680 msg->state = 0;
ss412g3bac2da2020-01-05 11:52:19 +0200681 rmr_bytes2payload(msg, (unsigned char *)sctpParams.ka_message, sctpParams.ka_message_length);
ss412g1a79bdf2019-10-24 12:03:05 +0300682 static unsigned char tx[32];
683 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
684 rmr_bytes2xact(msg, tx, txLen);
ss412g3bac2da2020-01-05 11:52:19 +0200685 msg = rmr_send_msg(sctpParams.rmrCtx, msg);
ss412g1a79bdf2019-10-24 12:03:05 +0300686 if (msg == nullptr) {
aa7133@att.comc9575aa2020-04-02 11:40:09 +0300687 msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.ka_message_length);
ss412g1a79bdf2019-10-24 12:03:05 +0300688 } else if (msg->state == 0) {
ss412g1a79bdf2019-10-24 12:03:05 +0300689 rmr_free_msg(msg);
ss412g3bac2da2020-01-05 11:52:19 +0200690 if (mdclog_level_get() >= MDCLOG_INFO) {
aa7133@att.com409f2232020-10-29 13:06:45 +0300691 mdclog_write(MDCLOG_INFO, "E2_TERM_INIT successfully sent ");
ss412g3bac2da2020-01-05 11:52:19 +0200692 }
693 return;
ss412g1a79bdf2019-10-24 12:03:05 +0300694 } else {
695 if (count % 100 == 0) {
aa7133@att.com11b17d42020-03-22 11:35:16 +0200696 mdclog_write(MDCLOG_ERR, "Error sending E2_TERM_INIT cause : %s ", translateRmrErrorMessages(msg->state).c_str());
ss412g1a79bdf2019-10-24 12:03:05 +0300697 }
698 sleep(1);
699 }
700 count++;
701 }
ss412g3bac2da2020-01-05 11:52:19 +0200702}
703
704/**
705 *
706 * @param argc
707 * @param argv
708 * @param sctpParams
709 * @return
710 */
711cxxopts::ParseResult parse(int argc, char *argv[], sctp_params_t &sctpParams) {
712 cxxopts::Options options(argv[0], "e2 term help");
713 options.positional_help("[optional args]").show_positional_help();
714 options.allow_unrecognised_options().add_options()
715 ("p,path", "config file path", cxxopts::value<std::string>(sctpParams.configFilePath)->default_value("config"))
716 ("f,file", "config file name", cxxopts::value<std::string>(sctpParams.configFileName)->default_value("config.conf"))
717 ("h,help", "Print help");
718
aa7133@att.comde40d1c2020-08-26 16:19:20 +0300719 auto result = options.parse(argc, (const char **&)argv);
ss412g3bac2da2020-01-05 11:52:19 +0200720
721 if (result.count("help")) {
722 std::cout << options.help({""}) << std::endl;
723 exit(0);
724 }
725 return result;
726}
727
728/**
729 *
730 * @param sctpParams
731 * @return -1 failed 0 success
732 */
733int buildInotify(sctp_params_t &sctpParams) {
734 sctpParams.inotifyFD = inotify_init1(IN_NONBLOCK);
735 if (sctpParams.inotifyFD == -1) {
736 mdclog_write(MDCLOG_ERR, "Failed to init inotify (inotify_init1) %s", strerror(errno));
ss412g3bac2da2020-01-05 11:52:19 +0200737 return -1;
ss412g1a79bdf2019-10-24 12:03:05 +0300738 }
739
ss412g3bac2da2020-01-05 11:52:19 +0200740 sctpParams.inotifyWD = inotify_add_watch(sctpParams.inotifyFD,
aa7133@att.com96c9b882020-03-25 14:50:40 +0200741 (const char *)sctpParams.configFilePath.c_str(),
aa7133@att.com84bd3342020-03-16 18:04:57 +0200742 (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 +0200743 if (sctpParams.inotifyWD == -1) {
744 mdclog_write(MDCLOG_ERR, "Failed to add directory : %s to inotify (inotify_add_watch) %s",
aa7133@att.com96c9b882020-03-25 14:50:40 +0200745 sctpParams.configFilePath.c_str(),
746 strerror(errno));
ss412g3bac2da2020-01-05 11:52:19 +0200747 close(sctpParams.inotifyFD);
748 return -1;
749 }
750
751 struct epoll_event event{};
752 event.events = (EPOLLIN);
753 event.data.fd = sctpParams.inotifyFD;
754 // add listening RMR FD to epoll
755 if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.inotifyFD, &event)) {
756 mdclog_write(MDCLOG_ERR, "Failed to add inotify FD to epoll");
757 close(sctpParams.inotifyFD);
758 return -1;
759 }
ss412g1a79bdf2019-10-24 12:03:05 +0300760 return 0;
761}
762
763/**
764 *
765 * @param args
766 * @return
767 */
768void listener(sctp_params_t *params) {
ss412g1a79bdf2019-10-24 12:03:05 +0300769 int num_of_SCTP_messages = 0;
ss412g1a79bdf2019-10-24 12:03:05 +0300770 auto totalTime = 0.0;
ss412g1a79bdf2019-10-24 12:03:05 +0300771 std::thread::id this_id = std::this_thread::get_id();
772 //save cout
dhirajverma5f132832021-06-17 17:27:54 +0530773 auto pod_name = std::getenv("POD_NAME");
774 auto container_name = std::getenv("CONTAINER_NAME");
775 auto service_name = std::getenv("SERVICE_NAME");
776 auto host_name = std::getenv("HOST_NAME");
777 auto system_name = std::getenv("SYSTEM_NAME");
778 auto pid = std::to_string(getpid()).c_str();
ss412g1a79bdf2019-10-24 12:03:05 +0300779 streambuf *oldCout = cout.rdbuf();
780 ostringstream memCout;
781 // create new cout
782 cout.rdbuf(memCout.rdbuf());
783 cout << this_id;
784 //return to the normal cout
785 cout.rdbuf(oldCout);
786
787 char tid[32];
788 memcpy(tid, memCout.str().c_str(), memCout.str().length() < 32 ? memCout.str().length() : 31);
789 tid[memCout.str().length()] = 0;
dhirajverma5f132832021-06-17 17:27:54 +0530790 mdclog_mdc_add("SYSTEM_NAME", system_name);
791 mdclog_mdc_add("HOST_NAME", host_name);
792 mdclog_mdc_add("SERVICE_NAME", service_name);
793 mdclog_mdc_add("CONTAINER_NAME", container_name);
794 mdclog_mdc_add("POD_NAME", pod_name);
795 mdclog_mdc_add("PID", pid);
ss412g1a79bdf2019-10-24 12:03:05 +0300796
797 if (mdclog_level_get() >= MDCLOG_DEBUG) {
798 mdclog_write(MDCLOG_DEBUG, "started thread number %s", tid);
799 }
800
801 RmrMessagesBuffer_t rmrMessageBuffer{};
802 //create and init RMR
803 rmrMessageBuffer.rmrCtx = params->rmrCtx;
804
805 auto *events = (struct epoll_event *) calloc(MAXEVENTS, sizeof(struct epoll_event));
806 struct timespec end{0, 0};
807 struct timespec start{0, 0};
808
809 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
810 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
811
ss412g3bac2da2020-01-05 11:52:19 +0200812 memcpy(rmrMessageBuffer.ka_message, params->ka_message, params->ka_message_length);
813 rmrMessageBuffer.ka_message_len = params->ka_message_length;
814 rmrMessageBuffer.ka_message[rmrMessageBuffer.ka_message_len] = 0;
815
816 if (mdclog_level_get() >= MDCLOG_DEBUG) {
817 mdclog_write(MDCLOG_DEBUG, "keep alive message is : %s", rmrMessageBuffer.ka_message);
818 }
819
ss412g1a79bdf2019-10-24 12:03:05 +0300820 ReportingMessages_t message {};
821
aa7133@att.com409f2232020-10-29 13:06:45 +0300822// for (int i = 0; i < MAX_RMR_BUFF_ARRAY; i++) {
aa7133@att.com7c3e4c02020-03-25 16:37:19 +0200823// rmrMessageBuffer.rcvBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
824// rmrMessageBuffer.sendBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
825// }
ss412g1a79bdf2019-10-24 12:03:05 +0300826
827 while (true) {
828 if (mdclog_level_get() >= MDCLOG_DEBUG) {
ss412g4aeeda22020-06-16 14:12:41 +0300829 mdclog_write(MDCLOG_DEBUG, "Start EPOLL Wait. Timeout = %d", params->epollTimeOut);
ss412g1a79bdf2019-10-24 12:03:05 +0300830 }
dhirajverma6cf28612021-06-23 04:53:34 -0400831#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +0300832 auto numOfEvents = epoll_wait(params->epoll_fd, events, MAXEVENTS, params->epollTimeOut);
dhirajverma6cf28612021-06-23 04:53:34 -0400833#else
834 auto numOfEvents = 1;
835#endif
aa7133@att.comb92748d2020-06-29 11:52:30 +0300836 if (numOfEvents == 0) { // time out
dhirajverma93b6d9c2021-07-10 00:49:13 -0400837#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comb92748d2020-06-29 11:52:30 +0300838 if (mdclog_level_get() >= MDCLOG_DEBUG) {
839 mdclog_write(MDCLOG_DEBUG, "got epoll timeout");
ss412g1a79bdf2019-10-24 12:03:05 +0300840 }
841 continue;
ss412g4aeeda22020-06-16 14:12:41 +0300842 } else if (numOfEvents < 0) {
843 if (errno == EINTR) {
844 if (mdclog_level_get() >= MDCLOG_DEBUG) {
845 mdclog_write(MDCLOG_DEBUG, "got EINTR : %s", strerror(errno));
846 }
847 continue;
848 }
ss412g1a79bdf2019-10-24 12:03:05 +0300849 mdclog_write(MDCLOG_ERR, "Epoll wait failed, errno = %s", strerror(errno));
dhirajvermab55bc172021-11-09 02:15:08 -0500850 if(events)
851 {
852 free(events);
sandeekuea662102022-11-08 18:51:20 +0530853 events = nullptr;
dhirajvermab55bc172021-11-09 02:15:08 -0500854 }
ss412g1a79bdf2019-10-24 12:03:05 +0300855 return;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400856#endif
ss412g1a79bdf2019-10-24 12:03:05 +0300857 }
858 for (auto i = 0; i < numOfEvents; i++) {
859 if (mdclog_level_get() >= MDCLOG_DEBUG) {
860 mdclog_write(MDCLOG_DEBUG, "handling epoll event %d out of %d", i + 1, numOfEvents);
861 }
862 clock_gettime(CLOCK_MONOTONIC, &message.message.time);
863 start.tv_sec = message.message.time.tv_sec;
864 start.tv_nsec = message.message.time.tv_nsec;
ss412g3bac2da2020-01-05 11:52:19 +0200865
866
ss412g1a79bdf2019-10-24 12:03:05 +0300867 if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP)) {
aa7133@att.combe92d712020-03-18 17:30:39 +0200868 handlepoll_error(events[i], message, rmrMessageBuffer, params);
ss412g1a79bdf2019-10-24 12:03:05 +0300869 } else if (events[i].events & EPOLLOUT) {
aa7133@att.combe92d712020-03-18 17:30:39 +0200870 handleEinprogressMessages(events[i], message, rmrMessageBuffer, params);
aa7133@att.com84bd3342020-03-16 18:04:57 +0200871 } else if (params->listenFD == events[i].data.fd) {
aa7133@att.com6680c3b2020-03-22 12:06:58 +0200872 if (mdclog_level_get() >= MDCLOG_INFO) {
873 mdclog_write(MDCLOG_INFO, "New connection request from sctp network\n");
874 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200875 // new connection is requested from RAN start build connection
876 while (true) {
877 struct sockaddr in_addr {};
878 socklen_t in_len;
879 char hostBuff[NI_MAXHOST];
880 char portBuff[NI_MAXSERV];
881
882 in_len = sizeof(in_addr);
883 auto *peerInfo = (ConnectedCU_t *)calloc(1, sizeof(ConnectedCU_t));
aa7133@att.com409f2232020-10-29 13:06:45 +0300884 if(peerInfo == nullptr){
swc58d4f5d2020-10-20 15:08:38 +0900885 mdclog_write(MDCLOG_ERR, "calloc failed");
886 break;
887 }
aa7133@att.com84bd3342020-03-16 18:04:57 +0200888 peerInfo->sctpParams = params;
889 peerInfo->fileDescriptor = accept(params->listenFD, &in_addr, &in_len);
890 if (peerInfo->fileDescriptor == -1) {
dhirajverma93b6d9c2021-07-10 00:49:13 -0400891#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +0200892 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
893 /* We have processed all incoming connections. */
dhirajverma9f59b572021-07-23 02:36:13 -0400894 if(peerInfo)
895 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530896 peerInfo = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200897 break;
898 } else {
dhirajverma9f59b572021-07-23 02:36:13 -0400899 if(peerInfo)
900 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530901 peerInfo = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200902 mdclog_write(MDCLOG_ERR, "Accept error, errno = %s", strerror(errno));
903 break;
904 }
905 }
906 if (setSocketNoBlocking(peerInfo->fileDescriptor) == -1) {
907 mdclog_write(MDCLOG_ERR, "setSocketNoBlocking failed to set new connection %s on port %s\n", hostBuff, portBuff);
908 close(peerInfo->fileDescriptor);
dhirajverma9f59b572021-07-23 02:36:13 -0400909 if(peerInfo)
910 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530911 peerInfo = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200912 break;
dhirajverma93b6d9c2021-07-10 00:49:13 -0400913#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +0200914 }
czichy2175dd32022-05-17 15:24:51 +0300915 struct sctp_event_subscribe sctpevents;
916 memset( (void *)&sctpevents, 0, sizeof(sctpevents) );
917 sctpevents.sctp_data_io_event = 1;
918 setsockopt(peerInfo->fileDescriptor, SOL_SCTP, SCTP_EVENTS,(const void *)&sctpevents, sizeof(sctpevents) );
919
aa7133@att.com84bd3342020-03-16 18:04:57 +0200920 auto ans = getnameinfo(&in_addr, in_len,
aa7133@att.com96c9b882020-03-25 14:50:40 +0200921 peerInfo->hostName, NI_MAXHOST,
922 peerInfo->portNumber, NI_MAXSERV, (unsigned )((unsigned int)NI_NUMERICHOST | (unsigned int)NI_NUMERICSERV));
aa7133@att.com84bd3342020-03-16 18:04:57 +0200923 if (ans < 0) {
924 mdclog_write(MDCLOG_ERR, "Failed to get info on connection request. %s\n", strerror(errno));
925 close(peerInfo->fileDescriptor);
dhirajverma9f59b572021-07-23 02:36:13 -0400926 if(peerInfo)
927 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530928 peerInfo = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200929 break;
930 }
931 if (mdclog_level_get() >= MDCLOG_DEBUG) {
932 mdclog_write(MDCLOG_DEBUG, "Accepted connection on descriptor %d (host=%s, port=%s)\n", peerInfo->fileDescriptor, peerInfo->hostName, peerInfo->portNumber);
933 }
934 peerInfo->isConnected = false;
935 peerInfo->gotSetup = false;
936 if (addToEpoll(params->epoll_fd,
937 peerInfo,
938 (EPOLLIN | EPOLLET),
939 params->sctpMap, nullptr,
aa7133@att.combe92d712020-03-18 17:30:39 +0200940 0) != 0) {
dhirajverma9f59b572021-07-23 02:36:13 -0400941 if(peerInfo)
942 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +0530943 peerInfo = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200944 break;
945 }
aa7133@att.com6680c3b2020-03-22 12:06:58 +0200946 break;
aa7133@att.com84bd3342020-03-16 18:04:57 +0200947 }
ss412g1a79bdf2019-10-24 12:03:05 +0300948 } else if (params->rmrListenFd == events[i].data.fd) {
949 // got message from XAPP
aa7133@att.comde40d1c2020-08-26 16:19:20 +0300950 //num_of_XAPP_messages.fetch_add(1, std::memory_order_release);
ss412g1a79bdf2019-10-24 12:03:05 +0300951 num_of_messages.fetch_add(1, std::memory_order_release);
952 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comf13529a2020-08-27 11:21:16 +0300953 mdclog_write(MDCLOG_DEBUG, "new RMR message");
ss412g1a79bdf2019-10-24 12:03:05 +0300954 }
aa7133@att.com6680c3b2020-03-22 12:06:58 +0200955 if (receiveXappMessages(params->sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +0300956 rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +0200957 message.message.time) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +0300958 mdclog_write(MDCLOG_ERR, "Error handling Xapp message");
959 }
ss412g3bac2da2020-01-05 11:52:19 +0200960 } else if (params->inotifyFD == events[i].data.fd) {
961 mdclog_write(MDCLOG_INFO, "Got event from inotify (configuration update)");
962 handleConfigChange(params);
ss412g1a79bdf2019-10-24 12:03:05 +0300963 } else {
964 /* We RMR_ERR_RETRY have data on the fd waiting to be read. Read and display it.
965 * We must read whatever data is available completely, as we are running
966 * in edge-triggered mode and won't get a notification again for the same data. */
967 num_of_messages.fetch_add(1, std::memory_order_release);
968 if (mdclog_level_get() >= MDCLOG_DEBUG) {
969 mdclog_write(MDCLOG_DEBUG, "new message from SCTP, epoll flags are : %0x", events[i].events);
970 }
971 receiveDataFromSctp(&events[i],
972 params->sctpMap,
973 num_of_SCTP_messages,
974 rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +0200975 message.message.time);
ss412g1a79bdf2019-10-24 12:03:05 +0300976 }
977
978 clock_gettime(CLOCK_MONOTONIC, &end);
979 if (mdclog_level_get() >= MDCLOG_INFO) {
980 totalTime += ((end.tv_sec + 1.0e-9 * end.tv_nsec) -
981 ((double) start.tv_sec + 1.0e-9 * start.tv_nsec));
982 }
983 if (mdclog_level_get() >= MDCLOG_DEBUG) {
984 mdclog_write(MDCLOG_DEBUG, "message handling is %ld seconds %ld nanoseconds",
985 end.tv_sec - start.tv_sec,
986 end.tv_nsec - start.tv_nsec);
987 }
988 }
dhirajverma6cf28612021-06-23 04:53:34 -0400989#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -0400990 break;
dhirajverma6cf28612021-06-23 04:53:34 -0400991#endif
ss412g1a79bdf2019-10-24 12:03:05 +0300992 }
ss412g1a79bdf2019-10-24 12:03:05 +0300993}
994
995/**
996 *
ss412g3bac2da2020-01-05 11:52:19 +0200997 * @param sctpParams
998 */
999void handleConfigChange(sctp_params_t *sctpParams) {
1000 char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event))));
1001 const struct inotify_event *event;
1002 char *ptr;
dhirajverma60f8bef2021-06-29 07:22:58 -04001003#ifdef UNIT_TEST
1004 struct inotify_event tmpEvent;
1005#endif
ss412g3bac2da2020-01-05 11:52:19 +02001006 path p = (sctpParams->configFilePath + "/" + sctpParams->configFileName).c_str();
1007 auto endlessLoop = true;
1008 while (endlessLoop) {
dhirajverma93b6d9c2021-07-10 00:49:13 -04001009#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
1010 auto len = read(sctpParams->inotifyFD, buf, sizeof buf);
dhirajverma60f8bef2021-06-29 07:22:58 -04001011#else
1012 auto len=10;
1013#endif
ss412g3bac2da2020-01-05 11:52:19 +02001014 if (len == -1) {
dhirajverma93b6d9c2021-07-10 00:49:13 -04001015#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001016 if (errno != EAGAIN) {
1017 mdclog_write(MDCLOG_ERR, "read %s ", strerror(errno));
1018 endlessLoop = false;
1019 continue;
1020 }
1021 else {
1022 endlessLoop = false;
1023 continue;
1024 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001025#endif
ss412g3bac2da2020-01-05 11:52:19 +02001026 }
1027
1028 for (ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + event->len) {
dhirajverma60f8bef2021-06-29 07:22:58 -04001029#ifndef UNIT_TEST
1030 event = (const struct inotify_event *)ptr;
1031#else
1032 tmpEvent.mask = (uint32_t)IN_CLOSE_WRITE;
1033 event = &tmpEvent;
1034#endif
ss412g3bac2da2020-01-05 11:52:19 +02001035 if (event->mask & (uint32_t)IN_ISDIR) {
1036 continue;
1037 }
1038
1039 // the directory name
1040 if (sctpParams->inotifyWD == event->wd) {
1041 // not the directory
1042 }
1043 if (event->len) {
dhirajverma93b6d9c2021-07-10 00:49:13 -04001044#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.comdfc1db92020-03-31 17:32:04 +03001045 auto retVal = strcmp(sctpParams->configFileName.c_str(), event->name);
1046 if (retVal != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001047 continue;
1048 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001049#endif
ss412g3bac2da2020-01-05 11:52:19 +02001050 }
1051 // only the file we want
1052 if (event->mask & (uint32_t)IN_CLOSE_WRITE) {
aa7133@att.comdfc1db92020-03-31 17:32:04 +03001053 if (mdclog_level_get() >= MDCLOG_INFO) {
1054 mdclog_write(MDCLOG_INFO, "Configuration file changed");
1055 }
ss412g3bac2da2020-01-05 11:52:19 +02001056 if (exists(p)) {
1057 const int size = 2048;
1058 auto fileSize = file_size(p);
1059 if (fileSize > size) {
1060 mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size);
1061 return;
1062 }
1063 } else {
1064 mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str());
1065 return;
1066 }
1067
1068 ReadConfigFile conf;
1069 if (conf.openConfigFile(p.string()) == -1) {
1070 mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s",
1071 p.string().c_str(), strerror(errno));
1072 return;
1073 }
ss412g3bac2da2020-01-05 11:52:19 +02001074 auto tmpStr = conf.getStringValue("loglevel");
1075 if (tmpStr.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +03001076 mdclog_write(MDCLOG_ERR, "illegal loglevel. Set loglevel to MDCLOG_INFO");
ss412g3bac2da2020-01-05 11:52:19 +02001077 tmpStr = "info";
1078 }
1079 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
1080
1081 if ((tmpStr.compare("debug")) == 0) {
1082 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_DEBUG");
1083 sctpParams->logLevel = MDCLOG_DEBUG;
dhirajverma93b6d9c2021-07-10 00:49:13 -04001084 }
1085#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
1086 else if ((tmpStr.compare("info")) == 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001087 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_INFO");
1088 sctpParams->logLevel = MDCLOG_INFO;
1089 } else if ((tmpStr.compare("warning")) == 0) {
1090 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_WARN");
1091 sctpParams->logLevel = MDCLOG_WARN;
1092 } else if ((tmpStr.compare("error")) == 0) {
1093 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_ERR");
1094 sctpParams->logLevel = MDCLOG_ERR;
1095 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03001096 mdclog_write(MDCLOG_ERR, "illegal loglevel = %s. Set loglevel to MDCLOG_INFO", tmpStr.c_str());
ss412g3bac2da2020-01-05 11:52:19 +02001097 sctpParams->logLevel = MDCLOG_INFO;
1098 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001099#endif
ss412g3bac2da2020-01-05 11:52:19 +02001100 mdclog_level_set(sctpParams->logLevel);
ss412g3bac2da2020-01-05 11:52:19 +02001101 tmpStr = conf.getStringValue("trace");
1102 if (tmpStr.length() == 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +03001103 mdclog_write(MDCLOG_ERR, "illegal trace. Set trace to stop");
ss412g3bac2da2020-01-05 11:52:19 +02001104 tmpStr = "stop";
1105 }
1106
1107 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
1108 if ((tmpStr.compare("start")) == 0) {
1109 mdclog_write(MDCLOG_INFO, "Trace set to: start");
1110 sctpParams->trace = true;
1111 } else if ((tmpStr.compare("stop")) == 0) {
1112 mdclog_write(MDCLOG_INFO, "Trace set to: stop");
1113 sctpParams->trace = false;
1114 } else {
1115 mdclog_write(MDCLOG_ERR, "Trace was set to wrong value %s, set to stop", tmpStr.c_str());
1116 sctpParams->trace = false;
1117 }
1118 jsonTrace = sctpParams->trace;
ss412g4aeeda22020-06-16 14:12:41 +03001119
ss412g4aeeda22020-06-16 14:12:41 +03001120
ss412g3bac2da2020-01-05 11:52:19 +02001121 endlessLoop = false;
1122 }
dhirajverma60f8bef2021-06-29 07:22:58 -04001123#ifdef UNIT_TEST
1124 break;
1125#endif
ss412g3bac2da2020-01-05 11:52:19 +02001126 }
1127 }
1128}
1129
1130/**
1131 *
1132 * @param event
1133 * @param message
1134 * @param rmrMessageBuffer
1135 * @param params
ss412g3bac2da2020-01-05 11:52:19 +02001136 */
1137void handleEinprogressMessages(struct epoll_event &event,
1138 ReportingMessages_t &message,
1139 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001140 sctp_params_t *params) {
ss412g3bac2da2020-01-05 11:52:19 +02001141 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
1142 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1143
1144 mdclog_write(MDCLOG_INFO, "file descriptor %d got EPOLLOUT", peerInfo->fileDescriptor);
1145 auto retVal = 0;
1146 socklen_t retValLen = 0;
1147 auto rc = getsockopt(peerInfo->fileDescriptor, SOL_SOCKET, SO_ERROR, &retVal, &retValLen);
1148 if (rc != 0 || retVal != 0) {
dhirajverma93b6d9c2021-07-10 00:49:13 -04001149#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001150 if (rc != 0) {
1151 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1152 "%s|Failed SCTP Connection, after EINPROGRESS the getsockopt%s",
1153 peerInfo->enodbName, strerror(errno));
1154 } else if (retVal != 0) {
1155 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1156 "%s|Failed SCTP Connection after EINPROGRESS, SO_ERROR",
1157 peerInfo->enodbName);
1158 }
1159
1160 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1161 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
1162 mdclog_write(MDCLOG_ERR, "%s", rmrMessageBuffer.sendMessage->payload);
1163 message.message.direction = 'N';
aa7133@att.combe92d712020-03-18 17:30:39 +02001164 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001165 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1166 }
dhirajverma31768a92021-05-06 12:38:49 +05301167#endif
ss412g3bac2da2020-01-05 11:52:19 +02001168 memset(peerInfo->asnData, 0, peerInfo->asnLength);
1169 peerInfo->asnLength = 0;
1170 peerInfo->mtype = 0;
ss412g3bac2da2020-01-05 11:52:19 +02001171 return;
1172 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001173#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001174 peerInfo->isConnected = true;
1175
1176 if (modifyToEpoll(params->epoll_fd, peerInfo, (EPOLLIN | EPOLLET), params->sctpMap, peerInfo->enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02001177 peerInfo->mtype) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001178 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_MOD");
ss412g3bac2da2020-01-05 11:52:19 +02001179 return;
1180 }
1181
1182 message.message.asndata = (unsigned char *)peerInfo->asnData;
1183 message.message.asnLength = peerInfo->asnLength;
1184 message.message.messageType = peerInfo->mtype;
1185 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1186 num_of_messages.fetch_add(1, std::memory_order_release);
1187 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1188 mdclog_write(MDCLOG_DEBUG, "send the delayed SETUP/ENDC SETUP to sctp for %s",
1189 message.message.enodbName);
1190 }
aa7133@att.combe92d712020-03-18 17:30:39 +02001191 if (sendSctpMsg(peerInfo, message, params->sctpMap) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001192 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1193 mdclog_write(MDCLOG_DEBUG, "Error write to SCTP %s %d", __func__, __LINE__);
1194 }
ss412g3bac2da2020-01-05 11:52:19 +02001195 return;
1196 }
1197
1198 memset(peerInfo->asnData, 0, peerInfo->asnLength);
1199 peerInfo->asnLength = 0;
1200 peerInfo->mtype = 0;
dhirajverma93b6d9c2021-07-10 00:49:13 -04001201#endif
ss412g3bac2da2020-01-05 11:52:19 +02001202}
1203
1204
1205void handlepoll_error(struct epoll_event &event,
1206 ReportingMessages_t &message,
1207 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001208 sctp_params_t *params) {
sandeekuea662102022-11-08 18:51:20 +05301209 if ((event.data.fd != params->rmrListenFd) && (event.data.ptr != nullptr)) {
ss412g3bac2da2020-01-05 11:52:19 +02001210 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
1211 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on fd %d, RAN NAME : %s",
1212 event.events, peerInfo->fileDescriptor, peerInfo->enodbName);
dhirajverma93b6d9c2021-07-10 00:49:13 -04001213#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02001214 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
1215 "%s|Failed SCTP Connection",
1216 peerInfo->enodbName);
1217 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1218 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
1219
1220 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
1221 message.message.direction = 'N';
aa7133@att.combe92d712020-03-18 17:30:39 +02001222 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g3bac2da2020-01-05 11:52:19 +02001223 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1224 }
dhirajverma31768a92021-05-06 12:38:49 +05301225#endif
ss412g3bac2da2020-01-05 11:52:19 +02001226 close(peerInfo->fileDescriptor);
sandeekuea662102022-11-08 18:51:20 +05301227 //params->sctpMap->erase(peerInfo->enodbName);
aa7133@att.combe92d712020-03-18 17:30:39 +02001228 cleanHashEntry((ConnectedCU_t *) event.data.ptr, params->sctpMap);
ss412g3bac2da2020-01-05 11:52:19 +02001229 } else {
1230 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on RMR FD", event.events);
1231 }
ss412g3bac2da2020-01-05 11:52:19 +02001232}
1233/**
1234 *
ss412g1a79bdf2019-10-24 12:03:05 +03001235 * @param socket
1236 * @return
1237 */
1238int setSocketNoBlocking(int socket) {
1239 auto flags = fcntl(socket, F_GETFL, 0);
1240
1241 if (flags == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +03001242 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03001243 return -1;
1244 }
1245
1246 flags = (unsigned) flags | (unsigned) O_NONBLOCK;
1247 if (fcntl(socket, F_SETFL, flags) == -1) {
ss412g1a79bdf2019-10-24 12:03:05 +03001248 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03001249 return -1;
1250 }
1251
1252 return 0;
1253}
1254
1255/**
1256 *
1257 * @param val
1258 * @param m
ss412g1a79bdf2019-10-24 12:03:05 +03001259 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001260void cleanHashEntry(ConnectedCU_t *val, Sctp_Map_t *m) {
sandeekuea662102022-11-08 18:51:20 +05301261 if(val != nullptr)
1262 {
ss412g1a79bdf2019-10-24 12:03:05 +03001263 char *dummy;
1264 auto port = (uint16_t) strtol(val->portNumber, &dummy, 10);
aa7133@att.com84bd3342020-03-16 18:04:57 +02001265 char searchBuff[2048]{};
ss412g1a79bdf2019-10-24 12:03:05 +03001266
1267 snprintf(searchBuff, sizeof searchBuff, "host:%s:%d", val->hostName, port);
sandeekuea662102022-11-08 18:51:20 +05301268 if(m->find(searchBuff))
1269 {
ss412g1a79bdf2019-10-24 12:03:05 +03001270 m->erase(searchBuff);
sandeekuea662102022-11-08 18:51:20 +05301271 }
ss412g1a79bdf2019-10-24 12:03:05 +03001272
sandeekuea662102022-11-08 18:51:20 +05301273 if(m->find(val->enodbName))
1274 {
1275 mdclog_write(MDCLOG_DEBUG, "remove key enodbName = %s from %s at line %d", val->enodbName, __FUNCTION__, __LINE__);
ss412g1a79bdf2019-10-24 12:03:05 +03001276 m->erase(val->enodbName);
sandeekuea662102022-11-08 18:51:20 +05301277 }
dhirajverma31768a92021-05-06 12:38:49 +05301278#ifndef UNIT_TEST
sandeekuea662102022-11-08 18:51:20 +05301279 if(val) {
1280 free(val);
1281 val = nullptr;
1282 }
dhirajverma31768a92021-05-06 12:38:49 +05301283#endif
sandeekuea662102022-11-08 18:51:20 +05301284 }
ss412g1a79bdf2019-10-24 12:03:05 +03001285}
1286
1287/**
1288 *
aa7133@att.com409f2232020-10-29 13:06:45 +03001289 * @param fd file descriptor
ss412g1a79bdf2019-10-24 12:03:05 +03001290 * @param data the asn data to send
1291 * @param len length of the data
1292 * @param enodbName the enodbName as in the map for printing purpose
1293 * @param m map host information
1294 * @param mtype message number
aa7133@att.com409f2232020-10-29 13:06:45 +03001295 * @return 0 success, a negative number on fail
ss412g1a79bdf2019-10-24 12:03:05 +03001296 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001297int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_t *m) {
ss412g1a79bdf2019-10-24 12:03:05 +03001298 auto loglevel = mdclog_level_get();
dhirajverma99990292021-07-05 10:03:59 -04001299#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001300 int fd = peerInfo->fileDescriptor;
czichy2175dd32022-05-17 15:24:51 +03001301 int streamId = fetchStreamId(peerInfo,message);
dhirajverma99990292021-07-05 10:03:59 -04001302#else
1303 int fd = FILE_DESCRIPTOR;
czichy2175dd32022-05-17 15:24:51 +03001304 int streamId = 0;
dhirajverma99990292021-07-05 10:03:59 -04001305#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001306 if (loglevel >= MDCLOG_DEBUG) {
1307 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for CU %s, %s",
1308 message.message.enodbName, __FUNCTION__);
1309 }
1310
1311 while (true) {
czichy2175dd32022-05-17 15:24:51 +03001312 if (sctp_sendmsg(fd,message.message.asndata, message.message.asnLength,(struct sockaddr *) NULL, 0, 0, 0,streamId,0,0) < 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03001313 if (errno == EINTR) {
1314 continue;
1315 }
1316 mdclog_write(MDCLOG_ERR, "error writing to CU a message, %s ", strerror(errno));
dhirajverma93b6d9c2021-07-10 00:49:13 -04001317#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.com84bd3342020-03-16 18:04:57 +02001318 if (!peerInfo->isConnected) {
1319 mdclog_write(MDCLOG_ERR, "connection to CU %s is still in progress.", message.message.enodbName);
aa7133@att.com84bd3342020-03-16 18:04:57 +02001320 return -1;
1321 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04001322#endif
1323#ifndef UNIT_TEST
aa7133@att.combe92d712020-03-18 17:30:39 +02001324 cleanHashEntry(peerInfo, m);
dhirajvermac40ea1f2021-07-08 12:52:30 -04001325 close(fd);
dhirajverma93b6d9c2021-07-10 00:49:13 -04001326#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001327 char key[MAX_ENODB_NAME_SIZE * 2];
1328 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName,
1329 message.message.messageType);
1330 if (loglevel >= MDCLOG_DEBUG) {
1331 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
1332 }
aa7133@att.com96c9b882020-03-25 14:50:40 +02001333 auto tmp = m->find(key);
ss412g1a79bdf2019-10-24 12:03:05 +03001334 if (tmp) {
1335 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05301336 tmp = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03001337 }
1338 m->erase(key);
dhirajverma6cf28612021-06-23 04:53:34 -04001339#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001340 return -1;
dhirajverma6cf28612021-06-23 04:53:34 -04001341#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001342 }
1343 message.message.direction = 'D';
1344 // send report.buffer of size
1345 buildJsonMessage(message);
1346
1347 if (loglevel >= MDCLOG_DEBUG) {
1348 mdclog_write(MDCLOG_DEBUG,
1349 "SCTP message for CU %s sent from %s",
1350 message.message.enodbName,
1351 __FUNCTION__);
1352 }
ss412g1a79bdf2019-10-24 12:03:05 +03001353 return 0;
1354 }
1355}
1356
1357/**
1358 *
1359 * @param message
1360 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03001361 */
aa7133@att.combe92d712020-03-18 17:30:39 +02001362void getRequestMetaData(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03001363 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
1364 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
1365
1366 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1367 mdclog_write(MDCLOG_DEBUG, "Message from Xapp RAN name = %s message length = %ld",
1368 message.message.enodbName, (unsigned long) message.message.asnLength);
1369 }
ss412g1a79bdf2019-10-24 12:03:05 +03001370}
1371
1372
ss412g1a79bdf2019-10-24 12:03:05 +03001373
1374/**
1375 *
1376 * @param events
1377 * @param sctpMap
1378 * @param numOfMessages
1379 * @param rmrMessageBuffer
1380 * @param ts
ss412g1a79bdf2019-10-24 12:03:05 +03001381 * @return
1382 */
1383int receiveDataFromSctp(struct epoll_event *events,
1384 Sctp_Map_t *sctpMap,
1385 int &numOfMessages,
1386 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02001387 struct timespec &ts) {
ss412g1a79bdf2019-10-24 12:03:05 +03001388 /* We have data on the fd waiting to be read. Read and display it.
1389 * We must read whatever data is available completely, as we are running
1390 * in edge-triggered mode and won't get a notification again for the same data. */
aa7133@att.com84bd3342020-03-16 18:04:57 +02001391 ReportingMessages_t message {};
1392 auto done = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03001393 auto loglevel = mdclog_level_get();
czichy2175dd32022-05-17 15:24:51 +03001394 struct sctp_sndrcvinfo sndrcvinfo;
1395 int flags;
1396 int streamId;
aa7133@att.com84bd3342020-03-16 18:04:57 +02001397
ss412g1a79bdf2019-10-24 12:03:05 +03001398 // get the identity of the interface
sandeekuea662102022-11-08 18:51:20 +05301399 if (events->data.ptr != nullptr){
aa7133@att.com84bd3342020-03-16 18:04:57 +02001400 message.peerInfo = (ConnectedCU_t *)events->data.ptr;
sandeekuea662102022-11-08 18:51:20 +05301401 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001402
ss412g1a79bdf2019-10-24 12:03:05 +03001403 struct timespec start{0, 0};
aa7133@att.com409f2232020-10-29 13:06:45 +03001404 struct timespec decodeStart{0, 0};
ss412g1a79bdf2019-10-24 12:03:05 +03001405 struct timespec end{0, 0};
1406
1407 E2AP_PDU_t *pdu = nullptr;
1408
ss412g1a79bdf2019-10-24 12:03:05 +03001409 while (true) {
1410 if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001411 mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP %d fd", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001412 clock_gettime(CLOCK_MONOTONIC, &start);
1413 }
1414 // read the buffer directly to rmr payload
1415 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
dhirajverma99990292021-07-05 10:03:59 -04001416#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001417 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
czichy2175dd32022-05-17 15:24:51 +03001418 sctp_recvmsg(message.peerInfo->fileDescriptor, rmrMessageBuffer.sendMessage->payload, RECEIVE_SCTP_BUFFER_SIZE,(struct sockaddr *) NULL, 0, &sndrcvinfo, &flags);
1419 mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP fd %d stream %d ", message.peerInfo->fileDescriptor, sndrcvinfo.sinfo_stream);
1420 streamId = sndrcvinfo.sinfo_stream;
dhirajverma99990292021-07-05 10:03:59 -04001421#else
1422 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
czichy2175dd32022-05-17 15:24:51 +03001423 streamId = 0;
dhirajverma99990292021-07-05 10:03:59 -04001424#endif
aa7133@att.com84bd3342020-03-16 18:04:57 +02001425
ss412g1a79bdf2019-10-24 12:03:05 +03001426 if (loglevel >= MDCLOG_DEBUG) {
1427 mdclog_write(MDCLOG_DEBUG, "Finish Read from SCTP %d fd message length = %ld",
aa7133@att.com96c9b882020-03-25 14:50:40 +02001428 message.peerInfo->fileDescriptor, message.message.asnLength);
ss412g1a79bdf2019-10-24 12:03:05 +03001429 }
aa7133@att.com16c799b2020-03-24 18:01:51 +02001430
aa7133@att.com84bd3342020-03-16 18:04:57 +02001431 memcpy(message.message.enodbName, message.peerInfo->enodbName, sizeof(message.peerInfo->enodbName));
ss412g1a79bdf2019-10-24 12:03:05 +03001432 message.message.direction = 'U';
1433 message.message.time.tv_nsec = ts.tv_nsec;
1434 message.message.time.tv_sec = ts.tv_sec;
1435
1436 if (message.message.asnLength < 0) {
1437 if (errno == EINTR) {
1438 continue;
1439 }
1440 /* If errno == EAGAIN, that means we have read all
aa7133@att.com84bd3342020-03-16 18:04:57 +02001441 data. So goReportingMessages_t back to the main loop. */
ss412g1a79bdf2019-10-24 12:03:05 +03001442 if (errno != EAGAIN) {
1443 mdclog_write(MDCLOG_ERR, "Read error, %s ", strerror(errno));
1444 done = 1;
1445 } else if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001446 mdclog_write(MDCLOG_DEBUG, "EAGAIN - descriptor = %d", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001447 }
1448 break;
1449 } else if (message.message.asnLength == 0) {
1450 /* End of file. The remote has closed the connection. */
1451 if (loglevel >= MDCLOG_INFO) {
1452 mdclog_write(MDCLOG_INFO, "END of File Closed connection - descriptor = %d",
aa7133@att.com84bd3342020-03-16 18:04:57 +02001453 message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001454 }
1455 done = 1;
1456 break;
1457 }
1458
ss412g1a79bdf2019-10-24 12:03:05 +03001459 if (loglevel >= MDCLOG_DEBUG) {
swc58d4f5d2020-10-20 15:08:38 +09001460 char printBuffer[RECEIVE_SCTP_BUFFER_SIZE]{};
ss412g1a79bdf2019-10-24 12:03:05 +03001461 char *tmp = printBuffer;
1462 for (size_t i = 0; i < (size_t)message.message.asnLength; ++i) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001463 snprintf(tmp, 3, "%02x", message.message.asndata[i]);
ss412g1a79bdf2019-10-24 12:03:05 +03001464 tmp += 2;
1465 }
1466 printBuffer[message.message.asnLength] = 0;
1467 clock_gettime(CLOCK_MONOTONIC, &end);
1468 mdclog_write(MDCLOG_DEBUG, "Before Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds",
aa7133@att.com84bd3342020-03-16 18:04:57 +02001469 message.peerInfo->enodbName, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001470 mdclog_write(MDCLOG_DEBUG, "PDU buffer length = %ld, data = : %s", message.message.asnLength,
1471 printBuffer);
aa7133@att.com409f2232020-10-29 13:06:45 +03001472 clock_gettime(CLOCK_MONOTONIC, &decodeStart);
ss412g1a79bdf2019-10-24 12:03:05 +03001473 }
dhirajverma99990292021-07-05 10:03:59 -04001474#ifndef UNIT_TEST
aa7133@att.com7b437f72020-03-30 13:25:54 +03001475 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu,
dhirajverma99990292021-07-05 10:03:59 -04001476 message.message.asndata, message.message.asnLength);
1477#else
1478 asn_dec_rval_t rval = {RC_OK, 0};
1479 pdu = (E2AP_PDU_t*)rmrMessageBuffer.sendMessage->tp_buf;
1480#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001481 if (rval.code != RC_OK) {
1482 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from RAN : %s", rval.code,
aa7133@att.com84bd3342020-03-16 18:04:57 +02001483 message.peerInfo->enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04001484 if (pdu != nullptr) {
1485 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1486 pdu = nullptr;
1487 }
ss412g1a79bdf2019-10-24 12:03:05 +03001488 break;
1489 }
1490
1491 if (loglevel >= MDCLOG_DEBUG) {
1492 clock_gettime(CLOCK_MONOTONIC, &end);
1493 mdclog_write(MDCLOG_DEBUG, "After Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds",
aa7133@att.com409f2232020-10-29 13:06:45 +03001494 message.peerInfo->enodbName, end.tv_sec - decodeStart.tv_sec, end.tv_nsec - decodeStart.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001495 char *printBuffer;
1496 size_t size;
1497 FILE *stream = open_memstream(&printBuffer, &size);
1498 asn_fprint(stream, &asn_DEF_E2AP_PDU, pdu);
1499 mdclog_write(MDCLOG_DEBUG, "Encoding E2AP PDU past : %s", printBuffer);
aa7133@att.com409f2232020-10-29 13:06:45 +03001500 clock_gettime(CLOCK_MONOTONIC, &decodeStart);
Byonggon Chuncae9bd52020-11-18 13:37:29 +09001501
1502 fclose(stream);
1503 free(printBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001504 }
1505
1506 switch (pdu->present) {
1507 case E2AP_PDU_PR_initiatingMessage: {//initiating message
czichy2175dd32022-05-17 15:24:51 +03001508 asnInitiatingRequest(pdu, sctpMap,message, rmrMessageBuffer, streamId);
ss412g1a79bdf2019-10-24 12:03:05 +03001509 break;
1510 }
1511 case E2AP_PDU_PR_successfulOutcome: { //successful outcome
aa7133@att.com409f2232020-10-29 13:06:45 +03001512 asnSuccessfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001513 break;
1514 }
1515 case E2AP_PDU_PR_unsuccessfulOutcome: { //Unsuccessful Outcome
aa7133@att.com7b437f72020-03-30 13:25:54 +03001516 asnUnSuccsesfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03001517 break;
1518 }
1519 default:
1520 mdclog_write(MDCLOG_ERR, "Unknown index %d in E2AP PDU", pdu->present);
1521 break;
1522 }
1523 if (loglevel >= MDCLOG_DEBUG) {
1524 clock_gettime(CLOCK_MONOTONIC, &end);
1525 mdclog_write(MDCLOG_DEBUG,
1526 "After processing message and sent to rmr for : %s, Read time is : %ld seconds, %ld nanoseconds",
aa7133@att.com409f2232020-10-29 13:06:45 +03001527 message.peerInfo->enodbName, end.tv_sec - decodeStart.tv_sec, end.tv_nsec - decodeStart.tv_nsec);
ss412g1a79bdf2019-10-24 12:03:05 +03001528 }
1529 numOfMessages++;
dhirajverma9f59b572021-07-23 02:36:13 -04001530#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03001531 if (pdu != nullptr) {
dhirajverma9f59b572021-07-23 02:36:13 -04001532 // ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); /* With reset we were not freeing the memory and was causing the leak here. */
1533 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1534 pdu = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03001535 }
dhirajverma9f59b572021-07-23 02:36:13 -04001536#else
dhirajverma99990292021-07-05 10:03:59 -04001537 done = 1;
1538 break;
1539#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001540 }
ss412g1a79bdf2019-10-24 12:03:05 +03001541
1542 if (done) {
1543 if (loglevel >= MDCLOG_INFO) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001544 mdclog_write(MDCLOG_INFO, "Closed connection - descriptor = %d", message.peerInfo->fileDescriptor);
ss412g1a79bdf2019-10-24 12:03:05 +03001545 }
1546 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
1547 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
aa7133@att.com96c9b882020-03-25 14:50:40 +02001548 256,
1549 "%s|CU disconnected unexpectedly",
1550 message.peerInfo->enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03001551 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
dhirajverma93b6d9c2021-07-10 00:49:13 -04001552#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03001553 if (sendRequestToXapp(message,
1554 RIC_SCTP_CONNECTION_FAILURE,
aa7133@att.combe92d712020-03-18 17:30:39 +02001555 rmrMessageBuffer) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03001556 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1557 }
dhirajverma99990292021-07-05 10:03:59 -04001558#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001559
1560 /* Closing descriptor make epoll remove it from the set of descriptors which are monitored. */
sandeekuea662102022-11-08 18:51:20 +05301561#ifndef UNIT_TEST
1562 pthread_mutex_lock(&thread_lock);
1563 if (fcntl(message.peerInfo->fileDescriptor, F_GETFD) != -1) {
1564 mdclog_write(MDCLOG_DEBUG, "Closing connection - descriptor = %d", message.peerInfo->fileDescriptor);
1565 close(message.peerInfo->fileDescriptor);
1566 cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap);
1567 }
1568 pthread_mutex_unlock(&thread_lock);
1569#else
aa7133@att.com84bd3342020-03-16 18:04:57 +02001570 close(message.peerInfo->fileDescriptor);
aa7133@att.combe92d712020-03-18 17:30:39 +02001571 cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap);
sandeekuea662102022-11-08 18:51:20 +05301572#endif
ss412g1a79bdf2019-10-24 12:03:05 +03001573 }
1574 if (loglevel >= MDCLOG_DEBUG) {
1575 clock_gettime(CLOCK_MONOTONIC, &end);
1576 mdclog_write(MDCLOG_DEBUG, "from receive SCTP to send RMR time is %ld seconds and %ld nanoseconds",
1577 end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
1578
1579 }
ss412g1a79bdf2019-10-24 12:03:05 +03001580 return 0;
1581}
1582
aa7133@att.com409f2232020-10-29 13:06:45 +03001583static void buildAndSendSetupRequest(ReportingMessages_t &message,
aa7133@att.com84bd3342020-03-16 18:04:57 +02001584 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001585 E2AP_PDU_t *pdu/*,
ss412g4aeeda22020-06-16 14:12:41 +03001586 string const &messageName,
1587 string const &ieName,
1588 vector<string> &functionsToAdd_v,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001589 vector<string> &functionsToModified_v*/) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02001590 auto logLevel = mdclog_level_get();
aa7133@att.com84bd3342020-03-16 18:04:57 +02001591 // now we can send the data to e2Mgr
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001592
ss412g4aeeda22020-06-16 14:12:41 +03001593 asn_enc_rval_t er;
1594 auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
Byonggon Chun51885f32020-11-18 15:31:04 +09001595 unsigned char *buffer = nullptr;
1596 buffer = (unsigned char *) calloc(buffer_size, sizeof(unsigned char));
1597 if(!buffer)
1598 {
dhirajverma93b6d9c2021-07-10 00:49:13 -04001599#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
Byonggon Chun51885f32020-11-18 15:31:04 +09001600 mdclog_write(MDCLOG_ERR, "Allocating buffer for %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1601 return;
dhirajverma93b6d9c2021-07-10 00:49:13 -04001602#endif
Byonggon Chun51885f32020-11-18 15:31:04 +09001603 }
ss412g4aeeda22020-06-16 14:12:41 +03001604 while (true) {
ss412g4aeeda22020-06-16 14:12:41 +03001605 er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size);
1606 if (er.encoded == -1) {
dhirajverma93b6d9c2021-07-10 00:49:13 -04001607#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g4aeeda22020-06-16 14:12:41 +03001608 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1609 return;
dhirajverma93b6d9c2021-07-10 00:49:13 -04001610#endif
ss412g4aeeda22020-06-16 14:12:41 +03001611 } else if (er.encoded > (ssize_t) buffer_size) {
1612 buffer_size = er.encoded + 128;
dhirajverma93b6d9c2021-07-10 00:49:13 -04001613#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g4aeeda22020-06-16 14:12:41 +03001614 mdclog_write(MDCLOG_WARN, "Buffer of size %d is to small for %s. Reallocate buffer of size %d",
1615 (int) buffer_size,
1616 asn_DEF_E2AP_PDU.name, buffer_size);
1617 buffer_size = er.encoded + 128;
Byonggon Chun51885f32020-11-18 15:31:04 +09001618
1619 unsigned char *newBuffer = nullptr;
1620 newBuffer = (unsigned char *) realloc(buffer, buffer_size);
1621 if (!newBuffer)
1622 {
1623 // out of memory
1624 mdclog_write(MDCLOG_ERR, "Reallocating buffer for %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1625 free(buffer);
sandeekuea662102022-11-08 18:51:20 +05301626 buffer = nullptr;
Byonggon Chun51885f32020-11-18 15:31:04 +09001627 return;
1628 }
1629 buffer = newBuffer;
ss412g4aeeda22020-06-16 14:12:41 +03001630 continue;
dhirajverma93b6d9c2021-07-10 00:49:13 -04001631#endif
ss412g4aeeda22020-06-16 14:12:41 +03001632 }
1633 buffer[er.encoded] = '\0';
1634 break;
1635 }
1636 // encode to xml
1637
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001638 string res((char *)buffer);
1639 res.erase(std::remove(res.begin(), res.end(), '\n'), res.end());
1640 res.erase(std::remove(res.begin(), res.end(), '\t'), res.end());
1641 res.erase(std::remove(res.begin(), res.end(), ' '), res.end());
1642
1643// string res {};
1644// if (!functionsToAdd_v.empty() || !functionsToModified_v.empty()) {
1645// res = buildXmlData(messageName, ieName, functionsToAdd_v, functionsToModified_v, buffer, (size_t) er.encoded);
1646// }
ss412g4aeeda22020-06-16 14:12:41 +03001647 rmr_mbuf_t *rmrMsg;
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001648// if (res.length() == 0) {
1649// rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size + 256);
1650// rmrMsg->len = snprintf((char *) rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s",
1651// message.peerInfo->sctpParams->myIP.c_str(),
1652// message.peerInfo->sctpParams->rmrPort,
1653// buffer);
1654// } else {
ss412g4aeeda22020-06-16 14:12:41 +03001655 rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, (int)res.length() + 256);
1656 rmrMsg->len = snprintf((char *) rmrMsg->payload, res.length() + 256, "%s:%d|%s",
1657 message.peerInfo->sctpParams->myIP.c_str(),
1658 message.peerInfo->sctpParams->rmrPort,
1659 res.c_str());
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001660// }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001661
ss412g4aeeda22020-06-16 14:12:41 +03001662 if (logLevel >= MDCLOG_DEBUG) {
1663 mdclog_write(MDCLOG_DEBUG, "Setup request of size %d :\n %s\n", rmrMsg->len, rmrMsg->payload);
1664 }
1665 // send to RMR
1666 rmrMsg->mtype = message.message.messageType;
1667 rmrMsg->state = 0;
1668 rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName));
aa7133@att.com84bd3342020-03-16 18:04:57 +02001669
ss412g4aeeda22020-06-16 14:12:41 +03001670 static unsigned char tx[32];
1671 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1672 rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx));
dhirajverma60f8bef2021-06-29 07:22:58 -04001673#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +03001674 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
dhirajverma60f8bef2021-06-29 07:22:58 -04001675#endif
ss412g4aeeda22020-06-16 14:12:41 +03001676 if (rmrMsg == nullptr) {
1677 mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr");
1678 } else if (rmrMsg->state != 0) {
1679 char meid[RMR_MAX_MEID]{};
1680 if (rmrMsg->state == RMR_ERR_RETRY) {
1681 usleep(5);
1682 rmrMsg->state = 0;
1683 mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s",
1684 rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid));
dhirajverma60f8bef2021-06-29 07:22:58 -04001685#ifndef UNIT_TEST
ss412g4aeeda22020-06-16 14:12:41 +03001686 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
dhirajverma60f8bef2021-06-29 07:22:58 -04001687#endif
ss412g4aeeda22020-06-16 14:12:41 +03001688 if (rmrMsg == nullptr) {
1689 mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr");
1690 } else if (rmrMsg->state != 0) {
1691 mdclog_write(MDCLOG_ERR,
1692 "RMR Retry failed %s sending request %d to Xapp from %s",
aa7133@att.com84bd3342020-03-16 18:04:57 +02001693 translateRmrErrorMessages(rmrMsg->state).c_str(),
1694 rmrMsg->mtype,
1695 rmr_get_meid(rmrMsg, (unsigned char *) meid));
1696 }
ss412g4aeeda22020-06-16 14:12:41 +03001697 } else {
1698 mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s",
1699 translateRmrErrorMessages(rmrMsg->state).c_str(),
1700 rmrMsg->mtype,
1701 rmr_get_meid(rmrMsg, (unsigned char *) meid));
aa7133@att.combc110772020-03-25 09:45:14 +02001702 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02001703 }
ss412g4aeeda22020-06-16 14:12:41 +03001704 message.peerInfo->gotSetup = true;
1705 buildJsonMessage(message);
Byonggon Chun51885f32020-11-18 15:31:04 +09001706
ss412g4aeeda22020-06-16 14:12:41 +03001707 if (rmrMsg != nullptr) {
1708 rmr_free_msg(rmrMsg);
1709 }
Byonggon Chun51885f32020-11-18 15:31:04 +09001710 free(buffer);
sandeekuea662102022-11-08 18:51:20 +05301711 buffer = nullptr;
Byonggon Chun51885f32020-11-18 15:31:04 +09001712
1713 return;
aa7133@att.com84bd3342020-03-16 18:04:57 +02001714}
aa7133@att.comc5a15202020-04-05 19:57:01 +03001715
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001716#if 0
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001717int RAN_Function_list_To_Vector(RANfunctions_List_t& list, vector <string> &runFunXML_v) {
1718 auto index = 0;
1719 runFunXML_v.clear();
1720 for (auto j = 0; j < list.list.count; j++) {
1721 auto *raNfunctionItemIEs = (RANfunction_ItemIEs_t *)list.list.array[j];
1722 if (raNfunctionItemIEs->id == ProtocolIE_ID_id_RANfunction_Item &&
1723 (raNfunctionItemIEs->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item)) {
1724 // encode to xml
1725 E2SM_gNB_NRT_RANfunction_Definition_t *ranFunDef = nullptr;
1726 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER,
1727 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1728 (void **)&ranFunDef,
1729 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.buf,
1730 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.size);
1731 if (rval.code != RC_OK) {
1732 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2SM message from : %s",
1733 rval.code,
1734 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name);
1735 return -1;
1736 }
1737
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001738 auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1739 unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
ss412g4aeeda22020-06-16 14:12:41 +03001740 memset(xml_buffer, 0, RECEIVE_SCTP_BUFFER_SIZE * 2);
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001741 // encode to xml
1742 auto er = asn_encode_to_buffer(nullptr,
1743 ATS_BASIC_XER,
1744 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1745 ranFunDef,
1746 xml_buffer,
1747 xml_buffer_size);
1748 if (er.encoded == -1) {
1749 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s",
1750 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1751 strerror(errno));
1752 } else if (er.encoded > (ssize_t)xml_buffer_size) {
1753 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
1754 (int) xml_buffer_size,
1755 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, __func__, __LINE__);
1756 } else {
1757 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1758 mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU number %d : %s",
1759 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1760 index++,
1761 xml_buffer);
1762 }
ss412g4aeeda22020-06-16 14:12:41 +03001763
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001764 string runFuncs = (char *)(xml_buffer);
1765 runFunXML_v.emplace_back(runFuncs);
1766 }
1767 }
1768 }
1769 return 0;
1770}
aa7133@att.comc5a15202020-04-05 19:57:01 +03001771
ss412g4aeeda22020-06-16 14:12:41 +03001772int collectServiceUpdate_RequestData(E2AP_PDU_t *pdu,
1773 Sctp_Map_t *sctpMap,
1774 ReportingMessages_t &message,
1775 vector <string> &RANfunctionsAdded_v,
1776 vector <string> &RANfunctionsModified_v) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03001777 memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE);
ss412g4aeeda22020-06-16 14:12:41 +03001778 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.count; i++) {
1779 auto *ie = pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.array[i];
1780 if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
1781 if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctionsID_List) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03001782 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001783 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
1784 ie->value.choice.RANfunctions_List.list.count);
aa7133@att.comc5a15202020-04-05 19:57:01 +03001785 }
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001786 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) {
1787 return -1;
1788 }
1789 }
1790 } else if (ie->id == ProtocolIE_ID_id_RANfunctionsModified) {
ss412g4aeeda22020-06-16 14:12:41 +03001791 if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List) {
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001792 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1793 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
1794 ie->value.choice.RANfunctions_List.list.count);
1795 }
1796 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsModified_v) != 0 ) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03001797 return -1;
aa7133@att.comc5a15202020-04-05 19:57:01 +03001798 }
1799 }
1800 }
1801 }
1802 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1803 mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries",
aa7133@att.com0829b8b2020-04-16 19:27:42 +03001804 RANfunctionsAdded_v.size());
aa7133@att.comc5a15202020-04-05 19:57:01 +03001805 }
1806 return 0;
1807}
ss412g4aeeda22020-06-16 14:12:41 +03001808
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001809#endif
ss412g4aeeda22020-06-16 14:12:41 +03001810
1811
Mohamed Abukar64f37242021-08-15 12:39:56 +00001812void buildE2TPrometheusCounters(sctp_params_t &sctpParams) {
1813 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestMsgs"}});
1814 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestBytes"}});
1815
1816 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupResponseMsgs"}});
1817 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupResponseBytes"}});
1818
1819 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestFailureMsgs"}});
1820 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestFailureBytes"}});
1821
czichy2175dd32022-05-17 15:24:51 +03001822 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateMsgs"}});
1823 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateBytes"}});
1824
1825 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateResponseMsgs"}});
1826 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateResponseBytes"}});
1827
1828 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateFailureMsgs"}});
1829 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateFailureBytes"}});
1830
Mohamed Abukar64f37242021-08-15 12:39:56 +00001831 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &sctpParams.prometheusFamily->Add({{"counter", "ErrorIndicationMsgs"}});
1832 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &sctpParams.prometheusFamily->Add({{"counter", "ErrorIndicationBytes"}});
1833
1834 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetRequestMsgs"}});
1835 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetRequestBytes"}});
1836
1837 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetAckMsgs"}});
1838 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetAckBytes"}});
1839
1840 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateMsgs"}});
1841 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateBytes"}});
1842
1843 sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateRespMsgs"}});
1844 sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateRespBytes"}});
1845
1846 sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateFailureMsgs"}});
1847 sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateFailureBytes"}});
1848
1849 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlMsgs"}});
1850 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlBytes"}});
1851
1852 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlAckMsgs"}});
1853 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlAckBytes"}});
1854
1855 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlFailureMsgs"}});
1856 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlFailureBytes"}});
1857
1858 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionMsgs"}});
1859 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionBytes"}});
1860
1861 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionAckMsgs"}});
1862 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionAckBytes"}});
1863
1864 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionFailureMsgs"}});
1865 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionFailureBytes"}});
1866
1867 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteMsgs"}});
1868 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteBytes"}});
1869
1870 sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteAckMsgs"}});
1871 sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteAckBytes"}});
1872
1873 sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteFailMsgs"}});
1874 sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteFailBytes"}});
1875
1876 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication] = &sctpParams.prometheusFamily->Add({{"counter", "RICIndicationMsgs"}});
1877 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication] = &sctpParams.prometheusFamily->Add({{"counter", "RICIndicationBytes"}});
1878
1879 sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceQueryMsgs"}});
1880 sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceQueryBytes"}});
gunjarastogi85f507f2023-01-18 16:27:55 +05301881
1882 sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteRequiredMsgs"}});
1883 sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteRequiredBytes"}});
1884
Mohamed Abukar64f37242021-08-15 12:39:56 +00001885}
1886
aa7133@att.com409f2232020-10-29 13:06:45 +03001887void buildPrometheusList(ConnectedCU_t *peerInfo, Family<Counter> *prometheusFamily) {
aa7133@att.coma4c80012020-06-24 16:36:47 +03001888 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Messages"}});
1889 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001890
czichy2175dd32022-05-17 15:24:51 +03001891 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"E2NodeConfigUpdate", "Messages"}});
1892 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"E2NodeConfigUpdate", "Bytes"}});
1893
aa7133@att.coma4c80012020-06-24 16:36:47 +03001894 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Messages"}});
1895 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001896
aa7133@att.coma4c80012020-06-24 16:36:47 +03001897 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICindication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Messages"}});
1898 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICindication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001899
aa7133@att.coma4c80012020-06-24 16:36:47 +03001900 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Messages"}});
1901 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001902
aa7133@att.coma4c80012020-06-24 16:36:47 +03001903 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Messages"}});
1904 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001905 // ---------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03001906 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Messages"}});
1907 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001908
aa7133@att.coma4c80012020-06-24 16:36:47 +03001909 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Messages"}});
1910 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001911
aa7133@att.coma4c80012020-06-24 16:36:47 +03001912 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Messages"}});
1913 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001914
aa7133@att.coma4c80012020-06-24 16:36:47 +03001915 peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Messages"}});
1916 peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001917 //-------------------------------------------------------------
1918
aa7133@att.coma4c80012020-06-24 16:36:47 +03001919 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Messages"}});
1920 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001921
aa7133@att.coma4c80012020-06-24 16:36:47 +03001922 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Messages"}});
1923 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001924
aa7133@att.coma4c80012020-06-24 16:36:47 +03001925 peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Messages"}});
1926 peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001927
1928 //====================================================================================
aa7133@att.coma4c80012020-06-24 16:36:47 +03001929 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Messages"}});
1930 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001931
aa7133@att.coma4c80012020-06-24 16:36:47 +03001932 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Messages"}});
1933 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001934
aa7133@att.coma4c80012020-06-24 16:36:47 +03001935 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Messages"}});
1936 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001937
aa7133@att.coma4c80012020-06-24 16:36:47 +03001938 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceQuery)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Messages"}});
1939 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceQuery)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001940
aa7133@att.coma4c80012020-06-24 16:36:47 +03001941 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Messages"}});
1942 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001943
aa7133@att.coma4c80012020-06-24 16:36:47 +03001944 peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Messages"}});
1945 peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001946 //---------------------------------------------------------------------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03001947 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Messages"}});
1948 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001949
czichy2175dd32022-05-17 15:24:51 +03001950 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateSuccess", "Messages"}});
1951 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateSuccess", "Bytes"}});
1952
aa7133@att.coma4c80012020-06-24 16:36:47 +03001953 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Messages"}});
1954 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001955
aa7133@att.coma4c80012020-06-24 16:36:47 +03001956 peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Messages"}});
1957 peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001958 //----------------------------------------------------------------------------------------------------------------
aa7133@att.coma4c80012020-06-24 16:36:47 +03001959 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Messages"}});
1960 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Bytes"}});
ss412g4aeeda22020-06-16 14:12:41 +03001961
czichy2175dd32022-05-17 15:24:51 +03001962 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateFailure", "Messages"}});
1963 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateFailure", "Bytes"}});
1964
aa7133@att.coma4c80012020-06-24 16:36:47 +03001965 peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Messages"}});
1966 peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Bytes"}});
gunjarastogi85f507f2023-01-18 16:27:55 +05301967
1968
1969 peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDeleteRequired)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteRequired", "Messages"}});
1970 peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDeleteRequired)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteRequired", "Bytes"}});
1971
ss412g4aeeda22020-06-16 14:12:41 +03001972}
Mohamed Abukar64f37242021-08-15 12:39:56 +00001973
ss412g4aeeda22020-06-16 14:12:41 +03001974/**
1975 *
1976 * @param pdu
1977 * @param sctpMap
1978 * @param message
1979 * @param RANfunctionsAdded_v
1980 * @return
1981 */
1982int collectSetupRequestData(E2AP_PDU_t *pdu,
1983 Sctp_Map_t *sctpMap,
aa7133@att.comdf4f1822020-06-16 16:23:53 +03001984 ReportingMessages_t &message /*, vector <string> &RANfunctionsAdded_v*/) {
ss412g4aeeda22020-06-16 14:12:41 +03001985 memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE);
1986 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) {
1987 auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i];
1988 if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) {
1989 // get the ran name for meid
1990 if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) {
1991 if (buildRanName(message.peerInfo->enodbName, ie) < 0) {
1992 mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n");
aa7133@att.com409f2232020-10-29 13:06:45 +03001993 // no message will be sent
ss412g4aeeda22020-06-16 14:12:41 +03001994 return -1;
1995 }
1996
1997 memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName));
1998 sctpMap->setkey(message.message.enodbName, message.peerInfo);
1999 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002000 } /*else if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
ss412g4aeeda22020-06-16 14:12:41 +03002001 if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) {
2002 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2003 mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries",
2004 ie->value.choice.RANfunctions_List.list.count);
2005 }
2006 if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) {
2007 return -1;
2008 }
2009 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002010 } */
ss412g4aeeda22020-06-16 14:12:41 +03002011 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002012// if (mdclog_level_get() >= MDCLOG_DEBUG) {
2013// mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries",
2014// RANfunctionsAdded_v.size());
2015// }
ss412g4aeeda22020-06-16 14:12:41 +03002016 return 0;
2017}
2018
2019int XML_From_PER(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
2020 E2AP_PDU_t *pdu = nullptr;
2021
2022 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2023 mdclog_write(MDCLOG_DEBUG, "got PER message of size %d is:%s",
2024 rmrMessageBuffer.sendMessage->len, rmrMessageBuffer.sendMessage->payload);
2025 }
2026 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu,
2027 rmrMessageBuffer.sendMessage->payload, rmrMessageBuffer.sendMessage->len);
2028 if (rval.code != RC_OK) {
2029 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
2030 rval.code,
2031 message.message.enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04002032 if (pdu != nullptr) {
2033 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2034 pdu = nullptr;
2035 }
ss412g4aeeda22020-06-16 14:12:41 +03002036 return -1;
2037 }
2038
2039 int buff_size = RECEIVE_XAPP_BUFFER_SIZE;
2040 auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu,
2041 rmrMessageBuffer.sendMessage->payload, buff_size);
2042 if (er.encoded == -1) {
2043 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
dhirajverma9f59b572021-07-23 02:36:13 -04002044 if (pdu != nullptr) {
2045 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2046 pdu = nullptr;
2047 }
ss412g4aeeda22020-06-16 14:12:41 +03002048 return -1;
2049 } else if (er.encoded > (ssize_t)buff_size) {
2050 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
2051 (int)rmrMessageBuffer.sendMessage->len,
2052 asn_DEF_E2AP_PDU.name,
2053 __func__,
2054 __LINE__);
dhirajverma9f59b572021-07-23 02:36:13 -04002055 if (pdu != nullptr) {
2056 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2057 pdu = nullptr;
2058 }
ss412g4aeeda22020-06-16 14:12:41 +03002059 return -1;
2060 }
2061 rmrMessageBuffer.sendMessage->len = er.encoded;
dhirajverma9f59b572021-07-23 02:36:13 -04002062 if (pdu != nullptr) {
2063 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2064 pdu = nullptr;
2065 }
ss412g4aeeda22020-06-16 14:12:41 +03002066 return 0;
2067
2068}
2069
ss412g1a79bdf2019-10-24 12:03:05 +03002070/**
2071 *
2072 * @param pdu
2073 * @param message
2074 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002075 */
2076void asnInitiatingRequest(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002077 Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002078 ReportingMessages_t &message,
czichy2175dd32022-05-17 15:24:51 +03002079 RmrMessagesBuffer_t &rmrMessageBuffer, int streamId) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002080 auto logLevel = mdclog_level_get();
ss412g1a79bdf2019-10-24 12:03:05 +03002081 auto procedureCode = ((InitiatingMessage_t *) pdu->choice.initiatingMessage)->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002082 if (logLevel >= MDCLOG_DEBUG) {
2083 mdclog_write(MDCLOG_DEBUG, "Initiating message %ld\n", procedureCode);
ss412g1a79bdf2019-10-24 12:03:05 +03002084 }
2085 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002086 case ProcedureCode_id_E2setup: {
2087 if (logLevel >= MDCLOG_DEBUG) {
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002088 mdclog_write(MDCLOG_DEBUG, "Got E2setup");
aa7133@att.com84bd3342020-03-16 18:04:57 +02002089 }
2090
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002091// vector <string> RANfunctionsAdded_v;
2092// vector <string> RANfunctionsModified_v;
2093// RANfunctionsAdded_v.clear();
2094// RANfunctionsModified_v.clear();
2095 if (collectSetupRequestData(pdu, sctpMap, message) != 0) {
aa7133@att.com7b437f72020-03-30 13:25:54 +03002096 break;
2097 }
czichy2175dd32022-05-17 15:24:51 +03002098 struct sctp_status status;
2099 int stat_size = sizeof(status);
2100 getsockopt( message.peerInfo->fileDescriptor, SOL_SCTP, SCTP_STATUS,(void *)&status, (socklen_t *)&stat_size );
2101 if (logLevel >= MDCLOG_DEBUG) {
2102 mdclog_write(MDCLOG_DEBUG, "Start from SCTP %d fd", message.peerInfo->fileDescriptor);
2103 mdclog_write(MDCLOG_DEBUG, "SCTP status assoc id %d instrms %d outstrms %d", status.sstat_assoc_id,
2104 status.sstat_instrms, status.sstat_outstrms);
2105 }
2106 if(status.sstat_outstrms == 1 || status.sstat_instrms == 1)
2107 {
2108 message.peerInfo->isSingleStream = true;
2109 message.peerInfo->singleStreamId = streamId;
2110 if (status.sstat_outstrms == 1 && status.sstat_instrms == 1){
2111 if (logLevel >= MDCLOG_DEBUG) {
2112 mdclog_write(MDCLOG_DEBUG, "Single SCTP stream is used for sending from now on, assoc id %d streamId %d #instrms %d #outstrms %d, %s",status.sstat_assoc_id, streamId, status.sstat_instrms, status.sstat_outstrms, __FUNCTION__);
2113 }
2114 }
2115 else {
2116 mdclog_write(MDCLOG_ERR, "Single SCTP stream used for sending messages even if there is a mismatch in number of in & out streams, assoc id %d instrms %d outstrms %d", status.sstat_assoc_id,
2117 status.sstat_instrms, status.sstat_outstrms);
2118 }
2119 }
aa7133@att.com7b437f72020-03-30 13:25:54 +03002120
aa7133@att.com409f2232020-10-29 13:06:45 +03002121 buildPrometheusList(message.peerInfo, message.peerInfo->sctpParams->prometheusFamily);
ss412g4aeeda22020-06-16 14:12:41 +03002122
2123 string messageName("E2setupRequest");
2124 string ieName("E2setupRequestIEs");
2125 message.message.messageType = RIC_E2_SETUP_REQ;
aa7133@att.coma4c80012020-06-24 16:36:47 +03002126 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2127 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002128
2129 // Update E2T instance level metrics
2130 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2131 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment((double)message.message.asnLength);
2132
aa7133@att.com409f2232020-10-29 13:06:45 +03002133 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
ss412g1a79bdf2019-10-24 12:03:05 +03002134 break;
2135 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002136 case ProcedureCode_id_RICserviceUpdate: {
2137 if (logLevel >= MDCLOG_DEBUG) {
2138 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
2139 }
aa7133@att.comdf4f1822020-06-16 16:23:53 +03002140// vector <string> RANfunctionsAdded_v;
2141// vector <string> RANfunctionsModified_v;
2142// RANfunctionsAdded_v.clear();
2143// RANfunctionsModified_v.clear();
2144// if (collectServiceUpdate_RequestData(pdu, sctpMap, message,
2145// RANfunctionsAdded_v, RANfunctionsModified_v) != 0) {
2146// break;
2147// }
ss412g4aeeda22020-06-16 14:12:41 +03002148
2149 string messageName("RICserviceUpdate");
2150 string ieName("RICserviceUpdateIEs");
2151 message.message.messageType = RIC_SERVICE_UPDATE;
dhirajverma93b6d9c2021-07-10 00:49:13 -04002152#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002153 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2154 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002155
2156 // Update E2T instance level metrics
2157 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2158 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002159#endif
aa7133@att.com409f2232020-10-29 13:06:45 +03002160 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002161 break;
2162 }
czichy2175dd32022-05-17 15:24:51 +03002163
2164case ProcedureCode_id_E2nodeConfigurationUpdate: {
2165 if (logLevel >= MDCLOG_DEBUG) {
2166 mdclog_write(MDCLOG_DEBUG, "Got E2nodeConfigurationUpdate %s", message.message.enodbName);
2167 }
2168
2169 string messageName("RICE2nodeConfigurationUpdate");
2170 string ieName("RICE2nodeConfigurationUpdateIEs");
2171 message.message.messageType = RIC_E2NODE_CONFIG_UPDATE;
2172#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2173 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2174 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment((double)message.message.asnLength);
2175
2176 // Update E2T instance level metrics
2177 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2178 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment((double)message.message.asnLength);
2179#endif
2180 buildAndSendSetupRequest(message, rmrMessageBuffer, pdu);
2181 break;
2182 }
2183
aa7133@att.com84bd3342020-03-16 18:04:57 +02002184 case ProcedureCode_id_ErrorIndication: {
2185 if (logLevel >= MDCLOG_DEBUG) {
2186 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
2187 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002188#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002189 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2190 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002191
2192 // Update E2T instance level metrics
2193 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2194 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002195#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002196 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002197 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
ss412g1a79bdf2019-10-24 12:03:05 +03002198 }
2199 break;
2200 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002201 case ProcedureCode_id_Reset: {
2202 if (logLevel >= MDCLOG_DEBUG) {
2203 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002204 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002205#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002206 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2207 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002208
2209 // Update E2T instance level metrics
2210 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2211 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002212#endif
ss412g4aeeda22020-06-16 14:12:41 +03002213 if (XML_From_PER(message, rmrMessageBuffer) < 0) {
2214 break;
ss412g1a79bdf2019-10-24 12:03:05 +03002215 }
ss412g4aeeda22020-06-16 14:12:41 +03002216
2217 if (sendRequestToXapp(message, RIC_E2_RESET_REQ, rmrMessageBuffer) != 0) {
2218 mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_REQ message failed to send to xAPP");
aa7133@att.com84bd3342020-03-16 18:04:57 +02002219 }
2220 break;
2221 }
2222 case ProcedureCode_id_RICindication: {
2223 if (logLevel >= MDCLOG_DEBUG) {
2224 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
2225 }
2226 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
ss412g1a79bdf2019-10-24 12:03:05 +03002227 auto messageSent = false;
2228 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
aa7133@att.com84bd3342020-03-16 18:04:57 +02002229 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002230 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2231 }
2232 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002233 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002234 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2235 }
2236 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
2237 static unsigned char tx[32];
2238 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
2239 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2240 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
ss412g3bac2da2020-01-05 11:52:19 +02002241 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
aa7133@att.com84bd3342020-03-16 18:04:57 +02002242 (unsigned char *)message.message.enodbName,
2243 strlen(message.message.enodbName));
ss412g1a79bdf2019-10-24 12:03:05 +03002244 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.comc5a15202020-04-05 19:57:01 +03002245 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
2246
2247 //ie->value.choice.RICrequestID.ricInstanceID;
ss412g3bac2da2020-01-05 11:52:19 +02002248 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03002249 mdclog_write(MDCLOG_DEBUG, "sub id = %d, mtype = %d, ric instance id %ld, requestor id = %ld",
aa7133@att.com84bd3342020-03-16 18:04:57 +02002250 rmrMessageBuffer.sendMessage->sub_id,
aa7133@att.comc5a15202020-04-05 19:57:01 +03002251 rmrMessageBuffer.sendMessage->mtype,
2252 ie->value.choice.RICrequestID.ricInstanceID,
2253 ie->value.choice.RICrequestID.ricRequestorID);
ss412g3bac2da2020-01-05 11:52:19 +02002254 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002255#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002256 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication]->Increment();
2257 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002258
2259 // Update E2T instance level metrics
2260 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication]->Increment();
2261 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002262#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002263 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002264 messageSent = true;
2265 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002266 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002267 }
2268 }
2269 if (messageSent) {
2270 break;
2271 }
2272 }
2273 break;
2274 }
gunjarastogi85f507f2023-01-18 16:27:55 +05302275 case ProcedureCode_id_RICsubscriptionDeleteRequired: {
2276 if (logLevel >= MDCLOG_DEBUG) {
2277 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDeleteRequired %s", message.message.enodbName);
2278 }
2279 #if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2280 message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment();
2281 message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment((double)message.message.asnLength);
2282
2283 // Update E2T instance level metrics
2284 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment();
2285 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment((double)message.message.asnLength);
2286 #endif
2287 if (sendRequestToXapp(message, RIC_SUB_DEL_REQUIRED, rmrMessageBuffer) != 0) {
2288 mdclog_write(MDCLOG_ERR, "Subscription Delete Required message failed to send to xAPP");
2289 }
2290 break;
2291 }
2292
ss412g1a79bdf2019-10-24 12:03:05 +03002293 default: {
2294 mdclog_write(MDCLOG_ERR, "Undefined or not supported message = %ld", procedureCode);
2295 message.message.messageType = 0; // no RMR message type yet
2296
2297 buildJsonMessage(message);
2298
2299 break;
2300 }
2301 }
ss412g1a79bdf2019-10-24 12:03:05 +03002302}
2303
2304/**
2305 *
2306 * @param pdu
2307 * @param message
ss412g1a79bdf2019-10-24 12:03:05 +03002308 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002309 */
aa7133@att.com409f2232020-10-29 13:06:45 +03002310void asnSuccessfulMsg(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002311 Sctp_Map_t *sctpMap,
2312 ReportingMessages_t &message,
2313 RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002314 auto procedureCode = pdu->choice.successfulOutcome->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002315 auto logLevel = mdclog_level_get();
2316 if (logLevel >= MDCLOG_INFO) {
ss412g1a79bdf2019-10-24 12:03:05 +03002317 mdclog_write(MDCLOG_INFO, "Successful Outcome %ld", procedureCode);
2318 }
2319 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002320 case ProcedureCode_id_Reset: {
2321 if (logLevel >= MDCLOG_DEBUG) {
2322 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002323 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002324#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002325 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2326 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002327
2328 // Update E2T instance level metrics
2329 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2330 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002331#endif
ss412g4aeeda22020-06-16 14:12:41 +03002332 if (XML_From_PER(message, rmrMessageBuffer) < 0) {
2333 break;
2334 }
2335 if (sendRequestToXapp(message, RIC_E2_RESET_RESP, rmrMessageBuffer) != 0) {
2336 mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_RESP message failed to send to xAPP");
ss412g1a79bdf2019-10-24 12:03:05 +03002337 }
2338 break;
2339 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002340 case ProcedureCode_id_RICcontrol: {
2341 if (logLevel >= MDCLOG_DEBUG) {
2342 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002343 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002344 for (auto i = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03002345 i < pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; i++) {
2346 auto messageSent = false;
2347 RICcontrolAcknowledge_IEs_t *ie = pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[i];
2348 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2349 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2350 }
2351 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
2352 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2353 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2354 }
2355 if (ie->value.present == RICcontrolAcknowledge_IEs__value_PR_RICrequestID) {
2356 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_ACK;
2357 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002358// rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
2359 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
2360
ss412g1a79bdf2019-10-24 12:03:05 +03002361 static unsigned char tx[32];
2362 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2363 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
ss412g3bac2da2020-01-05 11:52:19 +02002364 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
aa7133@att.com84bd3342020-03-16 18:04:57 +02002365 (unsigned char *)message.message.enodbName,
2366 strlen(message.message.enodbName));
dhirajverma93b6d9c2021-07-10 00:49:13 -04002367#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002368 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2369 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002370
2371 // Update E2T instance level metrics
2372 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2373 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002374#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002375 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002376 messageSent = true;
2377 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002378 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002379 }
2380 }
2381 if (messageSent) {
2382 break;
2383 }
2384 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002385
2386 break;
2387 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002388 case ProcedureCode_id_RICsubscription: {
2389 if (logLevel >= MDCLOG_DEBUG) {
2390 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
2391 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002392#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002393 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2394 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002395
2396 // Update E2T instance level metrics
2397 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2398 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002399#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002400 if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002401 mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP");
2402 }
2403 break;
2404 }
2405 case ProcedureCode_id_RICsubscriptionDelete: {
2406 if (logLevel >= MDCLOG_DEBUG) {
2407 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
2408 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002409#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002410 message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2411 message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002412
2413 // Update E2T instance level metrics
2414 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2415 message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002416#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002417 if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002418 mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP");
2419 }
ss412g1a79bdf2019-10-24 12:03:05 +03002420 break;
2421 }
2422 default: {
2423 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
2424 message.message.messageType = 0; // no RMR message type yet
2425 buildJsonMessage(message);
2426
2427 break;
2428 }
2429 }
ss412g1a79bdf2019-10-24 12:03:05 +03002430}
2431
2432/**
2433 *
2434 * @param pdu
2435 * @param message
ss412g1a79bdf2019-10-24 12:03:05 +03002436 * @param rmrMessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002437 */
2438void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu,
aa7133@att.com7b437f72020-03-30 13:25:54 +03002439 Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002440 ReportingMessages_t &message,
aa7133@att.combe92d712020-03-18 17:30:39 +02002441 RmrMessagesBuffer_t &rmrMessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002442 auto procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode;
aa7133@att.com84bd3342020-03-16 18:04:57 +02002443 auto logLevel = mdclog_level_get();
2444 if (logLevel >= MDCLOG_INFO) {
ss412g1a79bdf2019-10-24 12:03:05 +03002445 mdclog_write(MDCLOG_INFO, "Unsuccessful Outcome %ld", procedureCode);
2446 }
2447 switch (procedureCode) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002448 case ProcedureCode_id_RICcontrol: {
2449 if (logLevel >= MDCLOG_DEBUG) {
2450 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03002451 }
2452 for (int i = 0;
2453 i < pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.count; i++) {
2454 auto messageSent = false;
2455 RICcontrolFailure_IEs_t *ie = pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.array[i];
aa7133@att.com84bd3342020-03-16 18:04:57 +02002456 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002457 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
2458 }
2459 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002460 if (logLevel >= MDCLOG_DEBUG) {
ss412g1a79bdf2019-10-24 12:03:05 +03002461 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
2462 }
2463 if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) {
2464 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_FAILURE;
2465 rmrMessageBuffer.sendMessage->state = 0;
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002466// rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricRequestorID;
2467 rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID;
ss412g1a79bdf2019-10-24 12:03:05 +03002468 static unsigned char tx[32];
2469 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2470 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
aa7133@att.com84bd3342020-03-16 18:04:57 +02002471 rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName,
2472 strlen(message.message.enodbName));
dhirajverma93b6d9c2021-07-10 00:49:13 -04002473#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002474 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2475 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002476
2477 // Update E2T instance level metrics
2478 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2479 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength);
dhirajverma99990292021-07-05 10:03:59 -04002480#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002481 sendRmrMessage(rmrMessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002482 messageSent = true;
2483 } else {
aa7133@att.com409f2232020-10-29 13:06:45 +03002484 mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request");
ss412g1a79bdf2019-10-24 12:03:05 +03002485 }
2486 }
2487 if (messageSent) {
2488 break;
2489 }
2490 }
2491 break;
2492 }
aa7133@att.com84bd3342020-03-16 18:04:57 +02002493 case ProcedureCode_id_RICsubscription: {
2494 if (logLevel >= MDCLOG_DEBUG) {
2495 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
2496 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002497#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002498 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2499 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002500
2501 // Update E2T instance level metrics
2502 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2503 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002504#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002505 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002506 mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP");
2507 }
2508 break;
2509 }
2510 case ProcedureCode_id_RICsubscriptionDelete: {
2511 if (logLevel >= MDCLOG_DEBUG) {
2512 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
2513 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002514#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002515 message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2516 message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002517
2518 // Update E2T instance level metrics
2519 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2520 message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength);
dhirajverma6cf28612021-06-23 04:53:34 -04002521#endif
ss412g4aeeda22020-06-16 14:12:41 +03002522 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
aa7133@att.com84bd3342020-03-16 18:04:57 +02002523 mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP");
2524 }
2525 break;
2526 }
ss412g1a79bdf2019-10-24 12:03:05 +03002527 default: {
2528 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
2529 message.message.messageType = 0; // no RMR message type yet
dhirajverma93b6d9c2021-07-10 00:49:13 -04002530#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03002531 buildJsonMessage(message);
dhirajverma99990292021-07-05 10:03:59 -04002532#endif
ss412g1a79bdf2019-10-24 12:03:05 +03002533 break;
2534 }
2535 }
ss412g1a79bdf2019-10-24 12:03:05 +03002536}
2537
2538/**
2539 *
2540 * @param message
2541 * @param requestId
2542 * @param rmrMmessageBuffer
ss412g1a79bdf2019-10-24 12:03:05 +03002543 * @return
2544 */
2545int sendRequestToXapp(ReportingMessages_t &message,
2546 int requestId,
aa7133@att.combe92d712020-03-18 17:30:39 +02002547 RmrMessagesBuffer_t &rmrMmessageBuffer) {
ss412g1a79bdf2019-10-24 12:03:05 +03002548 rmr_bytes2meid(rmrMmessageBuffer.sendMessage,
2549 (unsigned char *)message.message.enodbName,
2550 strlen(message.message.enodbName));
2551 message.message.messageType = rmrMmessageBuffer.sendMessage->mtype = requestId;
2552 rmrMmessageBuffer.sendMessage->state = 0;
2553 static unsigned char tx[32];
2554 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2555 rmr_bytes2xact(rmrMmessageBuffer.sendMessage, tx, strlen((const char *) tx));
2556
aa7133@att.combe92d712020-03-18 17:30:39 +02002557 auto rc = sendRmrMessage(rmrMmessageBuffer, message);
ss412g1a79bdf2019-10-24 12:03:05 +03002558 return rc;
2559}
2560
ss412g4aeeda22020-06-16 14:12:41 +03002561/**
2562 *
2563 * @param pSctpParams
2564 */
aa7133@att.combe92d712020-03-18 17:30:39 +02002565void getRmrContext(sctp_params_t &pSctpParams) {
ss412g3bac2da2020-01-05 11:52:19 +02002566 pSctpParams.rmrCtx = nullptr;
aa7133@att.comab0e0f42020-04-06 17:13:58 +03002567 pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RECEIVE_XAPP_BUFFER_SIZE, RMRFL_NONE);
ss412g3bac2da2020-01-05 11:52:19 +02002568 if (pSctpParams.rmrCtx == nullptr) {
2569 mdclog_write(MDCLOG_ERR, "Failed to initialize RMR");
ss412g3bac2da2020-01-05 11:52:19 +02002570 return;
ss412g1a79bdf2019-10-24 12:03:05 +03002571 }
2572
ss412g3bac2da2020-01-05 11:52:19 +02002573 rmr_set_stimeout(pSctpParams.rmrCtx, 0); // disable retries for any send operation
ss412g1a79bdf2019-10-24 12:03:05 +03002574 // we need to find that routing table exist and we can run
2575 if (mdclog_level_get() >= MDCLOG_INFO) {
2576 mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready");
2577 }
2578 int rmrReady = 0;
2579 int count = 0;
2580 while (!rmrReady) {
ss412g3bac2da2020-01-05 11:52:19 +02002581 if ((rmrReady = rmr_ready(pSctpParams.rmrCtx)) == 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002582 sleep(1);
2583 }
2584 count++;
2585 if (count % 60 == 0) {
2586 mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count);
2587 }
2588 }
2589 if (mdclog_level_get() >= MDCLOG_INFO) {
2590 mdclog_write(MDCLOG_INFO, "RMR running");
2591 }
ss412g3bac2da2020-01-05 11:52:19 +02002592 rmr_init_trace(pSctpParams.rmrCtx, 200);
2593 // get the RMR fd for the epoll
2594 pSctpParams.rmrListenFd = rmr_get_rcvfd(pSctpParams.rmrCtx);
2595 struct epoll_event event{};
2596 // add RMR fd to epoll
2597 event.events = (EPOLLIN);
2598 event.data.fd = pSctpParams.rmrListenFd;
2599 // add listening RMR FD to epoll
2600 if (epoll_ctl(pSctpParams.epoll_fd, EPOLL_CTL_ADD, pSctpParams.rmrListenFd, &event)) {
2601 mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll");
2602 close(pSctpParams.rmrListenFd);
2603 rmr_close(pSctpParams.rmrCtx);
2604 pSctpParams.rmrCtx = nullptr;
2605 }
ss412g1a79bdf2019-10-24 12:03:05 +03002606}
2607
ss412g4aeeda22020-06-16 14:12:41 +03002608/**
2609 *
2610 * @param message
2611 * @param rmrMessageBuffer
2612 * @return
2613 */
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002614int PER_FromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
aa7133@att.com07e256f2020-04-20 15:59:51 +03002615 E2AP_PDU_t *pdu = nullptr;
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002616
2617 if (mdclog_level_get() >= MDCLOG_DEBUG) {
ss412g4aeeda22020-06-16 14:12:41 +03002618 mdclog_write(MDCLOG_DEBUG, "got xml Format data from xApp of size %d is:%s",
aa7133@att.com07e256f2020-04-20 15:59:51 +03002619 rmrMessageBuffer.rcvMessage->len, rmrMessageBuffer.rcvMessage->payload);
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002620 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002621 auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &pdu,
2622 rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len);
aa7133@att.com409f2232020-10-29 13:06:45 +03002623 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2624 mdclog_write(MDCLOG_DEBUG, "%s After decoding the XML to PDU", __func__ );
2625 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002626 if (rval.code != RC_OK) {
dhirajvermac40ea1f2021-07-08 12:52:30 -04002627#ifdef UNIT_TEST
2628 return 0;
2629#endif
aa7133@att.com1c4f50f2020-03-30 14:30:52 +03002630 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
aa7133@att.com1fecb052020-03-29 09:44:09 +03002631 rval.code,
2632 message.message.enodbName);
dhirajverma9f59b572021-07-23 02:36:13 -04002633 if (pdu != nullptr) {
2634 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2635 pdu = nullptr;
2636 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002637 return -1;
2638 }
2639
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002640 int buff_size = RECEIVE_XAPP_BUFFER_SIZE;
2641 auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu,
2642 rmrMessageBuffer.rcvMessage->payload, buff_size);
aa7133@att.com409f2232020-10-29 13:06:45 +03002643 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2644 mdclog_write(MDCLOG_DEBUG, "%s After encoding PDU to PER", __func__ );
2645 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002646 if (er.encoded == -1) {
2647 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
dhirajverma9f59b572021-07-23 02:36:13 -04002648 if (pdu != nullptr) {
2649 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2650 pdu = nullptr;
2651 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002652 return -1;
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002653 } else if (er.encoded > (ssize_t)buff_size) {
2654 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
aa7133@att.com1fecb052020-03-29 09:44:09 +03002655 (int)rmrMessageBuffer.rcvMessage->len,
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002656 asn_DEF_E2AP_PDU.name,
2657 __func__,
2658 __LINE__);
dhirajverma9f59b572021-07-23 02:36:13 -04002659 if (pdu != nullptr) {
2660 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2661 pdu = nullptr;
2662 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002663 return -1;
2664 }
aa7133@att.coma0f0db62020-04-01 16:52:50 +03002665 rmrMessageBuffer.rcvMessage->len = er.encoded;
dhirajverma9f59b572021-07-23 02:36:13 -04002666 if (pdu != nullptr) {
2667 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
2668 pdu = nullptr;
2669 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002670 return 0;
2671}
2672
ss412g1a79bdf2019-10-24 12:03:05 +03002673/**
2674 *
ss412g1a79bdf2019-10-24 12:03:05 +03002675 * @param sctpMap
2676 * @param rmrMessageBuffer
2677 * @param ts
ss412g1a79bdf2019-10-24 12:03:05 +03002678 * @return
2679 */
aa7133@att.com6680c3b2020-03-22 12:06:58 +02002680int receiveXappMessages(Sctp_Map_t *sctpMap,
ss412g1a79bdf2019-10-24 12:03:05 +03002681 RmrMessagesBuffer_t &rmrMessageBuffer,
aa7133@att.combe92d712020-03-18 17:30:39 +02002682 struct timespec &ts) {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002683 int loglevel = mdclog_level_get();
ss412g1a79bdf2019-10-24 12:03:05 +03002684 if (rmrMessageBuffer.rcvMessage == nullptr) {
2685 //we have error
2686 mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno));
ss412g1a79bdf2019-10-24 12:03:05 +03002687 return -1;
2688 }
2689
aa7133@att.comf13529a2020-08-27 11:21:16 +03002690// if (loglevel >= MDCLOG_DEBUG) {
2691// mdclog_write(MDCLOG_DEBUG, "Call to rmr_rcv_msg");
2692// }
ss412g1a79bdf2019-10-24 12:03:05 +03002693 rmrMessageBuffer.rcvMessage = rmr_rcv_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
2694 if (rmrMessageBuffer.rcvMessage == nullptr) {
aa7133@att.com409f2232020-10-29 13:06:45 +03002695 mdclog_write(MDCLOG_ERR, "RMR Receiving message with null pointer, Reallocated rmr message buffer");
ss412g1a79bdf2019-10-24 12:03:05 +03002696 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g1a79bdf2019-10-24 12:03:05 +03002697 return -2;
2698 }
2699 ReportingMessages_t message;
2700 message.message.direction = 'D';
2701 message.message.time.tv_nsec = ts.tv_nsec;
2702 message.message.time.tv_sec = ts.tv_sec;
2703
2704 // get message payload
2705 //auto msgData = msg->payload;
dhirajverma60f8bef2021-06-29 07:22:58 -04002706#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04002707 rmrMessageBuffer.rcvMessage->state = 0;
dhirajverma60f8bef2021-06-29 07:22:58 -04002708#endif
ss412g1a79bdf2019-10-24 12:03:05 +03002709 if (rmrMessageBuffer.rcvMessage->state != 0) {
aa7133@att.com409f2232020-10-29 13:06:45 +03002710 mdclog_write(MDCLOG_ERR, "RMR Receiving message with stat = %d", rmrMessageBuffer.rcvMessage->state);
ss412g1a79bdf2019-10-24 12:03:05 +03002711 return -1;
2712 }
aa7133@att.com1fecb052020-03-29 09:44:09 +03002713 rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)message.message.enodbName);
ss412g4aeeda22020-06-16 14:12:41 +03002714 message.peerInfo = (ConnectedCU_t *) sctpMap->find(message.message.enodbName);
2715 if (message.peerInfo == nullptr) {
2716 auto type = rmrMessageBuffer.rcvMessage->mtype;
2717 switch (type) {
2718 case RIC_SCTP_CLEAR_ALL:
2719 case E2_TERM_KEEP_ALIVE_REQ:
2720 case RIC_HEALTH_CHECK_REQ:
2721 break;
2722 default:
dhirajverma99990292021-07-05 10:03:59 -04002723#ifdef UNIT_TEST
2724 break;
2725#endif
ss412g4aeeda22020-06-16 14:12:41 +03002726 mdclog_write(MDCLOG_ERR, "Failed to send message no CU entry %s", message.message.enodbName);
2727 return -1;
2728 }
2729 }
2730
aa7133@att.comde40d1c2020-08-26 16:19:20 +03002731 if (rmrMessageBuffer.rcvMessage->mtype != RIC_HEALTH_CHECK_REQ) {
2732 num_of_XAPP_messages.fetch_add(1, std::memory_order_release);
2733
2734 }
ss412g1a79bdf2019-10-24 12:03:05 +03002735 switch (rmrMessageBuffer.rcvMessage->mtype) {
aa7133@att.combe92d712020-03-18 17:30:39 +02002736 case RIC_E2_SETUP_RESP : {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002737 if (loglevel >= MDCLOG_DEBUG) {
2738 mdclog_write(MDCLOG_DEBUG, "RIC_E2_SETUP_RESP");
2739 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002740 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com1fecb052020-03-29 09:44:09 +03002741 break;
2742 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002743#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002744 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2745 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002746
2747 // Update E2T instance level metrics
2748 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2749 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002750#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002751 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2752 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_RESP");
2753 return -6;
ss412g1a79bdf2019-10-24 12:03:05 +03002754 }
2755 break;
2756 }
aa7133@att.combe92d712020-03-18 17:30:39 +02002757 case RIC_E2_SETUP_FAILURE : {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002758 if (loglevel >= MDCLOG_DEBUG) {
2759 mdclog_write(MDCLOG_DEBUG, "RIC_E2_SETUP_FAILURE");
2760 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002761 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com1fecb052020-03-29 09:44:09 +03002762 break;
2763 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002764#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002765 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2766 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002767
2768 // Update E2T instance level metrics
2769 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment();
2770 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002771#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002772 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2773 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_FAILURE");
2774 return -6;
ss412g1a79bdf2019-10-24 12:03:05 +03002775 }
2776 break;
2777 }
czichy2175dd32022-05-17 15:24:51 +03002778
2779 case RIC_E2NODE_CONFIG_UPDATE_ACK: {
2780 if (loglevel >= MDCLOG_DEBUG) {
2781 mdclog_write(MDCLOG_DEBUG, "RIC_E2NODE_CONFIG_UPDATE_ACK");
2782 }
2783 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2784 break;
2785 }
2786#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2787 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2788 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2789
2790 // Update E2T instance level metrics
2791 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2792 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2793#endif
2794 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2795 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2NODE_CONFIG_UPDATE_ACK");
2796 return -6;
2797 }
2798 break;
2799 }
2800
2801 case RIC_E2NODE_CONFIG_UPDATE_FAILURE: {
2802 if (loglevel >= MDCLOG_DEBUG) {
2803 mdclog_write(MDCLOG_DEBUG, "RIC_E2NODE_CONFIG_UPDATE_FAILURE");
2804 }
2805 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2806 break;
2807 }
2808#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
2809 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2810 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2811
2812 // Update E2T instance level metrics
2813 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment();
2814 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
2815#endif
2816 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2817 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2NODE_CONFIG_UPDATE_FAILURE");
2818 return -6;
2819 }
2820 break;
2821 }
2822
aa7133@att.combe92d712020-03-18 17:30:39 +02002823 case RIC_ERROR_INDICATION: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002824 if (loglevel >= MDCLOG_DEBUG) {
2825 mdclog_write(MDCLOG_DEBUG, "RIC_ERROR_INDICATION");
2826 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002827#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002828 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2829 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002830
2831 // Update E2T instance level metrics
2832 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment();
2833 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002834#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002835 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2836 mdclog_write(MDCLOG_ERR, "Failed to send RIC_ERROR_INDICATION");
ss412g1a79bdf2019-10-24 12:03:05 +03002837 return -6;
2838 }
2839 break;
2840 }
2841 case RIC_SUB_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002842 if (loglevel >= MDCLOG_DEBUG) {
2843 mdclog_write(MDCLOG_DEBUG, "RIC_SUB_REQ");
2844 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002845#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002846 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2847 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002848
2849 // Update E2T instance level metrics
2850 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment();
2851 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002852#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002853 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002854 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002855 return -6;
2856 }
2857 break;
2858 }
2859 case RIC_SUB_DEL_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002860 if (loglevel >= MDCLOG_DEBUG) {
2861 mdclog_write(MDCLOG_DEBUG, "RIC_SUB_DEL_REQ");
2862 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002863#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002864 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2865 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002866
2867 // Update E2T instance level metrics
2868 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment();
2869 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002870#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002871 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002872 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_DEL_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002873 return -6;
2874 }
2875 break;
2876 }
2877 case RIC_CONTROL_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002878 if (loglevel >= MDCLOG_DEBUG) {
2879 mdclog_write(MDCLOG_DEBUG, "RIC_CONTROL_REQ");
2880 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002881#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002882 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2883 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002884
2885 // Update E2T instance level metrics
2886 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment();
2887 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002888#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002889 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002890 mdclog_write(MDCLOG_ERR, "Failed to send RIC_CONTROL_REQ");
ss412g1a79bdf2019-10-24 12:03:05 +03002891 return -6;
2892 }
2893 break;
2894 }
2895 case RIC_SERVICE_QUERY: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002896 if (loglevel >= MDCLOG_DEBUG) {
2897 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_QUERY");
2898 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002899 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2900 break;
2901 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002902#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002903 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment();
2904 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002905
2906 // Update E2T instance level metrics
2907 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment();
2908 message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002909#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002910 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002911 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY");
ss412g1a79bdf2019-10-24 12:03:05 +03002912 return -6;
2913 }
2914 break;
2915 }
2916 case RIC_SERVICE_UPDATE_ACK: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002917 if (loglevel >= MDCLOG_DEBUG) {
2918 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_UPDATE_ACK");
2919 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002920 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
aa7133@att.com54885fe2020-10-29 17:24:49 +03002921 mdclog_write(MDCLOG_ERR, "error in PER_FromXML");
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002922 break;
2923 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002924#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002925 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
aa7133@att.com52771912020-10-29 17:45:01 +03002926 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002927
2928 // Update E2T instance level metrics
2929 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2930 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002931#endif
aa7133@att.com54885fe2020-10-29 17:24:49 +03002932 if (loglevel >= MDCLOG_DEBUG) {
2933 mdclog_write(MDCLOG_DEBUG, "Before sending to CU");
2934 }
aa7133@att.combe92d712020-03-18 17:30:39 +02002935 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002936 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK");
ss412g1a79bdf2019-10-24 12:03:05 +03002937 return -6;
2938 }
2939 break;
2940 }
2941 case RIC_SERVICE_UPDATE_FAILURE: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002942 if (loglevel >= MDCLOG_DEBUG) {
2943 mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_UPDATE_FAILURE");
2944 }
aa7133@att.com0793fcb2020-04-16 11:34:26 +03002945 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2946 break;
2947 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002948#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002949 message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
aa7133@att.com7c07fee2020-10-29 17:54:38 +03002950 message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002951
2952 // Update E2T instance level metrics
2953 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment();
2954 message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002955#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002956 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03002957 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE");
ss412g1a79bdf2019-10-24 12:03:05 +03002958 return -6;
2959 }
2960 break;
2961 }
ss412g4aeeda22020-06-16 14:12:41 +03002962 case RIC_E2_RESET_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002963 if (loglevel >= MDCLOG_DEBUG) {
2964 mdclog_write(MDCLOG_DEBUG, "RIC_E2_RESET_REQ");
2965 }
ss412g4aeeda22020-06-16 14:12:41 +03002966 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2967 break;
2968 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002969#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002970 message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2971 message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002972
2973 // Update E2T instance level metrics
2974 message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2975 message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002976#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002977 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03002978 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET");
ss412g1a79bdf2019-10-24 12:03:05 +03002979 return -6;
2980 }
2981 break;
2982 }
ss412g4aeeda22020-06-16 14:12:41 +03002983 case RIC_E2_RESET_RESP: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03002984 if (loglevel >= MDCLOG_DEBUG) {
2985 mdclog_write(MDCLOG_DEBUG, "RIC_E2_RESET_RESP");
2986 }
ss412g4aeeda22020-06-16 14:12:41 +03002987 if (PER_FromXML(message, rmrMessageBuffer) != 0) {
2988 break;
2989 }
dhirajverma93b6d9c2021-07-10 00:49:13 -04002990#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
aa7133@att.coma4c80012020-06-24 16:36:47 +03002991 message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2992 message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
Mohamed Abukar64f37242021-08-15 12:39:56 +00002993
2994 // Update E2T instance level metrics
2995 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment();
2996 message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len);
dhirajverma99990292021-07-05 10:03:59 -04002997#endif
aa7133@att.combe92d712020-03-18 17:30:39 +02002998 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03002999 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET_RESP");
ss412g1a79bdf2019-10-24 12:03:05 +03003000 return -6;
3001 }
3002 break;
3003 }
3004 case RIC_SCTP_CLEAR_ALL: {
3005 mdclog_write(MDCLOG_INFO, "RIC_SCTP_CLEAR_ALL");
3006 // loop on all keys and close socket and then erase all map.
3007 vector<char *> v;
3008 sctpMap->getKeys(v);
3009 for (auto const &iter : v) { //}; iter != sctpMap.end(); iter++) {
3010 if (!boost::starts_with((string) (iter), "host:") && !boost::starts_with((string) (iter), "msg:")) {
3011 auto *peerInfo = (ConnectedCU_t *) sctpMap->find(iter);
3012 if (peerInfo == nullptr) {
3013 continue;
3014 }
3015 close(peerInfo->fileDescriptor);
3016 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
3017 message.message.direction = 'D';
3018 message.message.time.tv_nsec = ts.tv_nsec;
3019 message.message.time.tv_sec = ts.tv_sec;
3020
3021 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
3022 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
aa7133@att.com96c9b882020-03-25 14:50:40 +02003023 256,
3024 "%s|RIC_SCTP_CLEAR_ALL",
3025 peerInfo->enodbName);
ss412g1a79bdf2019-10-24 12:03:05 +03003026 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
3027 mdclog_write(MDCLOG_INFO, "%s", message.message.asndata);
aa7133@att.combe92d712020-03-18 17:30:39 +02003028 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
ss412g1a79bdf2019-10-24 12:03:05 +03003029 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
3030 }
3031 free(peerInfo);
sandeekuea662102022-11-08 18:51:20 +05303032 peerInfo = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03003033 }
3034 }
3035
3036 sleep(1);
3037 sctpMap->clear();
3038 break;
3039 }
ss412g3bac2da2020-01-05 11:52:19 +02003040 case E2_TERM_KEEP_ALIVE_REQ: {
3041 // send message back
ss412g3bac2da2020-01-05 11:52:19 +02003042 rmr_bytes2payload(rmrMessageBuffer.sendMessage,
aa7133@att.com96c9b882020-03-25 14:50:40 +02003043 (unsigned char *)rmrMessageBuffer.ka_message,
3044 rmrMessageBuffer.ka_message_len);
ss412g3bac2da2020-01-05 11:52:19 +02003045 rmrMessageBuffer.sendMessage->mtype = E2_TERM_KEEP_ALIVE_RESP;
3046 rmrMessageBuffer.sendMessage->state = 0;
3047 static unsigned char tx[32];
3048 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
3049 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, txLen);
dhirajverma93b6d9c2021-07-10 00:49:13 -04003050#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g3bac2da2020-01-05 11:52:19 +02003051 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003052#endif
ss412g3bac2da2020-01-05 11:52:19 +02003053 if (rmrMessageBuffer.sendMessage == nullptr) {
3054 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
aa7133@att.com77fff432020-01-27 12:01:20 +02003055 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP RMR message returned NULL");
ss412g3bac2da2020-01-05 11:52:19 +02003056 } else if (rmrMessageBuffer.sendMessage->state != 0) {
aa7133@att.com77fff432020-01-27 12:01:20 +02003057 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP, on RMR state = %d ( %s)",
aa7133@att.com96c9b882020-03-25 14:50:40 +02003058 rmrMessageBuffer.sendMessage->state, translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str());
aa7133@att.comf13529a2020-08-27 11:21:16 +03003059 } else if (loglevel >= MDCLOG_DEBUG) {
aa7133@att.combc110772020-03-25 09:45:14 +02003060 mdclog_write(MDCLOG_DEBUG, "Got Keep Alive Request send : %s", rmrMessageBuffer.ka_message);
ss412g3bac2da2020-01-05 11:52:19 +02003061 }
aa7133@att.com342843e2020-01-26 12:53:34 +02003062
ss412g3bac2da2020-01-05 11:52:19 +02003063 break;
3064 }
ss412g4aeeda22020-06-16 14:12:41 +03003065 case RIC_HEALTH_CHECK_REQ: {
aa7133@att.comf13529a2020-08-27 11:21:16 +03003066 static int counter = 0;
ss412g4aeeda22020-06-16 14:12:41 +03003067 // send message back
aa7133@att.comc18fe532020-06-30 12:40:18 +03003068 rmr_bytes2payload(rmrMessageBuffer.rcvMessage,
ss412g4aeeda22020-06-16 14:12:41 +03003069 (unsigned char *)"OK",
3070 2);
aa7133@att.comc18fe532020-06-30 12:40:18 +03003071 rmrMessageBuffer.rcvMessage->mtype = RIC_HEALTH_CHECK_RESP;
3072 rmrMessageBuffer.rcvMessage->state = 0;
ss412g4aeeda22020-06-16 14:12:41 +03003073 static unsigned char tx[32];
3074 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
aa7133@att.comc18fe532020-06-30 12:40:18 +03003075 rmr_bytes2xact(rmrMessageBuffer.rcvMessage, tx, txLen);
3076 rmrMessageBuffer.rcvMessage = rmr_rts_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
3077 //rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
3078 if (rmrMessageBuffer.rcvMessage == nullptr) {
3079 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g4aeeda22020-06-16 14:12:41 +03003080 mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP RMR message returned NULL");
aa7133@att.comc18fe532020-06-30 12:40:18 +03003081 } else if (rmrMessageBuffer.rcvMessage->state != 0) {
ss412g4aeeda22020-06-16 14:12:41 +03003082 mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP, on RMR state = %d ( %s)",
aa7133@att.comc18fe532020-06-30 12:40:18 +03003083 rmrMessageBuffer.rcvMessage->state, translateRmrErrorMessages(rmrMessageBuffer.rcvMessage->state).c_str());
dhirajvermab55bc172021-11-09 02:15:08 -05003084 } else if (loglevel >= MDCLOG_DEBUG && (++counter % 100 == 0)) {
aa7133@att.comf13529a2020-08-27 11:21:16 +03003085 mdclog_write(MDCLOG_DEBUG, "Got %d RIC_HEALTH_CHECK_REQ Request send : OK", counter);
ss412g4aeeda22020-06-16 14:12:41 +03003086 }
3087
3088 break;
3089 }
3090
ss412g1a79bdf2019-10-24 12:03:05 +03003091 default:
aa7133@att.com409f2232020-10-29 13:06:45 +03003092 mdclog_write(MDCLOG_WARN, "Message Type : %d is not supported", rmrMessageBuffer.rcvMessage->mtype);
ss412g1a79bdf2019-10-24 12:03:05 +03003093 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
3094 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
3095 message.message.time.tv_nsec = ts.tv_nsec;
3096 message.message.time.tv_sec = ts.tv_sec;
3097 message.message.messageType = rmrMessageBuffer.rcvMessage->mtype;
3098
3099 buildJsonMessage(message);
3100
3101
ss412g1a79bdf2019-10-24 12:03:05 +03003102 return -7;
3103 }
3104 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3105 mdclog_write(MDCLOG_DEBUG, "EXIT OK from %s", __FUNCTION__);
3106 }
ss412g1a79bdf2019-10-24 12:03:05 +03003107 return 0;
3108}
3109
3110/**
3111 * Send message to the CU that is not expecting for successful or unsuccessful results
3112 * @param messageBuffer
3113 * @param message
3114 * @param failedMsgId
3115 * @param sctpMap
ss412g1a79bdf2019-10-24 12:03:05 +03003116 * @return
3117 */
3118int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer,
3119 ReportingMessages_t &message,
3120 int failedMsgId,
aa7133@att.combe92d712020-03-18 17:30:39 +02003121 Sctp_Map_t *sctpMap) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003122 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3123 mdclog_write(MDCLOG_DEBUG, "send message: %d to %s address", message.message.messageType, message.message.enodbName);
3124 }
ss412g1a79bdf2019-10-24 12:03:05 +03003125
aa7133@att.combe92d712020-03-18 17:30:39 +02003126 getRequestMetaData(message, messageBuffer);
ss412g1a79bdf2019-10-24 12:03:05 +03003127 if (mdclog_level_get() >= MDCLOG_INFO) {
3128 mdclog_write(MDCLOG_INFO, "send message to %s address", message.message.enodbName);
3129 }
3130
aa7133@att.combe92d712020-03-18 17:30:39 +02003131 auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId);
ss412g1a79bdf2019-10-24 12:03:05 +03003132 return rc;
3133}
3134
3135/**
3136 *
3137 * @param sctpMap
3138 * @param messageBuffer
3139 * @param message
3140 * @param failedMesgId
ss412g1a79bdf2019-10-24 12:03:05 +03003141 * @return
3142 */
3143int sendMessagetoCu(Sctp_Map_t *sctpMap,
3144 RmrMessagesBuffer_t &messageBuffer,
3145 ReportingMessages_t &message,
aa7133@att.combe92d712020-03-18 17:30:39 +02003146 int failedMesgId) {
ss412g1a79bdf2019-10-24 12:03:05 +03003147 // get the FD
3148 message.message.messageType = messageBuffer.rcvMessage->mtype;
ss412g4aeeda22020-06-16 14:12:41 +03003149 auto rc = sendSctpMsg(message.peerInfo, message, sctpMap);
ss412g1a79bdf2019-10-24 12:03:05 +03003150 return rc;
3151}
3152
ss412g1a79bdf2019-10-24 12:03:05 +03003153
3154/**
3155 *
3156 * @param epoll_fd
3157 * @param peerInfo
3158 * @param events
3159 * @param sctpMap
3160 * @param enodbName
3161 * @param msgType
ss412g1a79bdf2019-10-24 12:03:05 +03003162 * @return
3163 */
3164int addToEpoll(int epoll_fd,
3165 ConnectedCU_t *peerInfo,
3166 uint32_t events,
3167 Sctp_Map_t *sctpMap,
3168 char *enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02003169 int msgType) {
ss412g1a79bdf2019-10-24 12:03:05 +03003170 // Add to Epol
3171 struct epoll_event event{};
3172 event.data.ptr = peerInfo;
3173 event.events = events;
3174 if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peerInfo->fileDescriptor, &event) < 0) {
dhirajverma93b6d9c2021-07-10 00:49:13 -04003175#if !(defined(UNIT_TEST) || defined(MODULE_TEST))
ss412g1a79bdf2019-10-24 12:03:05 +03003176 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003177 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here), %s, %s %d",
ss412g1a79bdf2019-10-24 12:03:05 +03003178 strerror(errno), __func__, __LINE__);
3179 }
3180 close(peerInfo->fileDescriptor);
aa7133@att.com84bd3342020-03-16 18:04:57 +02003181 if (enodbName != nullptr) {
aa7133@att.combe92d712020-03-18 17:30:39 +02003182 cleanHashEntry(peerInfo, sctpMap);
aa7133@att.com84bd3342020-03-16 18:04:57 +02003183 char key[MAX_ENODB_NAME_SIZE * 2];
3184 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
3185 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3186 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
3187 }
3188 auto tmp = sctpMap->find(key);
3189 if (tmp) {
3190 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05303191 tmp = nullptr;
aa7133@att.com84bd3342020-03-16 18:04:57 +02003192 sctpMap->erase(key);
3193 }
3194 } else {
3195 peerInfo->enodbName[0] = 0;
ss412g1a79bdf2019-10-24 12:03:05 +03003196 }
aa7133@att.com409f2232020-10-29 13:06:45 +03003197 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here)");
ss412g1a79bdf2019-10-24 12:03:05 +03003198 return -1;
dhirajverma93b6d9c2021-07-10 00:49:13 -04003199#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003200 }
ss412g1a79bdf2019-10-24 12:03:05 +03003201 return 0;
3202}
3203
3204/**
3205 *
3206 * @param epoll_fd
3207 * @param peerInfo
3208 * @param events
3209 * @param sctpMap
3210 * @param enodbName
3211 * @param msgType
ss412g1a79bdf2019-10-24 12:03:05 +03003212 * @return
3213 */
3214int modifyToEpoll(int epoll_fd,
3215 ConnectedCU_t *peerInfo,
3216 uint32_t events,
3217 Sctp_Map_t *sctpMap,
3218 char *enodbName,
aa7133@att.combe92d712020-03-18 17:30:39 +02003219 int msgType) {
ss412g1a79bdf2019-10-24 12:03:05 +03003220 // Add to Epol
3221 struct epoll_event event{};
3222 event.data.ptr = peerInfo;
3223 event.events = events;
3224 if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, peerInfo->fileDescriptor, &event) < 0) {
3225 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.com409f2232020-10-29 13:06:45 +03003226 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_MOD (may check not to quit here), %s, %s %d",
ss412g1a79bdf2019-10-24 12:03:05 +03003227 strerror(errno), __func__, __LINE__);
3228 }
3229 close(peerInfo->fileDescriptor);
aa7133@att.combe92d712020-03-18 17:30:39 +02003230 cleanHashEntry(peerInfo, sctpMap);
ss412g1a79bdf2019-10-24 12:03:05 +03003231 char key[MAX_ENODB_NAME_SIZE * 2];
3232 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
3233 if (mdclog_level_get() >= MDCLOG_DEBUG) {
3234 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
3235 }
aa7133@att.com96c9b882020-03-25 14:50:40 +02003236 auto tmp = sctpMap->find(key);
ss412g1a79bdf2019-10-24 12:03:05 +03003237 if (tmp) {
3238 free(tmp);
sandeekuea662102022-11-08 18:51:20 +05303239 tmp = nullptr;
ss412g1a79bdf2019-10-24 12:03:05 +03003240 sctpMap->erase(key);
sandeekuea662102022-11-08 18:51:20 +05303241 }
aa7133@att.com409f2232020-10-29 13:06:45 +03003242 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here)");
ss412g1a79bdf2019-10-24 12:03:05 +03003243 return -1;
3244 }
ss412g1a79bdf2019-10-24 12:03:05 +03003245 return 0;
3246}
3247
3248
aa7133@att.combe92d712020-03-18 17:30:39 +02003249int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message) {
ss412g1a79bdf2019-10-24 12:03:05 +03003250 buildJsonMessage(message);
dhirajverma60f8bef2021-06-29 07:22:58 -04003251#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03003252 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003253#else
dhirajverma99990292021-07-05 10:03:59 -04003254 rmrMessageBuffer.sendMessage->state = RMR_ERR_RETRY;
dhirajverma60f8bef2021-06-29 07:22:58 -04003255#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003256 if (rmrMessageBuffer.sendMessage == nullptr) {
3257 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
3258 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
ss412g1a79bdf2019-10-24 12:03:05 +03003259 return -1;
3260 }
3261
3262 if (rmrMessageBuffer.sendMessage->state != 0) {
3263 char meid[RMR_MAX_MEID]{};
3264 if (rmrMessageBuffer.sendMessage->state == RMR_ERR_RETRY) {
3265 usleep(5);
3266 rmrMessageBuffer.sendMessage->state = 0;
3267 mdclog_write(MDCLOG_INFO, "RETRY sending Message type %d to Xapp from %s",
3268 rmrMessageBuffer.sendMessage->mtype,
3269 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
dhirajverma60f8bef2021-06-29 07:22:58 -04003270#ifndef UNIT_TEST
ss412g1a79bdf2019-10-24 12:03:05 +03003271 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
dhirajverma60f8bef2021-06-29 07:22:58 -04003272#endif
ss412g1a79bdf2019-10-24 12:03:05 +03003273 if (rmrMessageBuffer.sendMessage == nullptr) {
3274 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
3275 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
ss412g1a79bdf2019-10-24 12:03:05 +03003276 return -1;
3277 } else if (rmrMessageBuffer.sendMessage->state != 0) {
3278 mdclog_write(MDCLOG_ERR,
3279 "Message state %s while sending request %d to Xapp from %s after retry of 10 microseconds",
3280 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
3281 rmrMessageBuffer.sendMessage->mtype,
3282 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
3283 auto rc = rmrMessageBuffer.sendMessage->state;
ss412g1a79bdf2019-10-24 12:03:05 +03003284 return rc;
3285 }
3286 } else {
3287 mdclog_write(MDCLOG_ERR, "Message state %s while sending request %d to Xapp from %s",
3288 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
3289 rmrMessageBuffer.sendMessage->mtype,
3290 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
ss412g1a79bdf2019-10-24 12:03:05 +03003291 return rmrMessageBuffer.sendMessage->state;
3292 }
3293 }
3294 return 0;
3295}
3296
3297void buildJsonMessage(ReportingMessages_t &message) {
dhirajverma60f8bef2021-06-29 07:22:58 -04003298#ifdef UNIT_TEST
dhirajverma99990292021-07-05 10:03:59 -04003299 jsonTrace = true;
dhirajverma60f8bef2021-06-29 07:22:58 -04003300#endif
ss412g3bac2da2020-01-05 11:52:19 +02003301 if (jsonTrace) {
3302 message.outLen = sizeof(message.base64Data);
3303 base64::encode((const unsigned char *) message.message.asndata,
3304 (const int) message.message.asnLength,
3305 message.base64Data,
3306 message.outLen);
3307 if (mdclog_level_get() >= MDCLOG_DEBUG) {
aa7133@att.comc5a15202020-04-05 19:57:01 +03003308 mdclog_write(MDCLOG_DEBUG, "Tracing: ASN length = %d, base64 message length = %d ",
ss412g3bac2da2020-01-05 11:52:19 +02003309 (int) message.message.asnLength,
3310 (int) message.outLen);
3311 }
3312
3313 snprintf(message.buffer, sizeof(message.buffer),
aa7133@att.com96c9b882020-03-25 14:50:40 +02003314 "{\"header\": {\"ts\": \"%ld.%09ld\","
3315 "\"ranName\": \"%s\","
3316 "\"messageType\": %d,"
3317 "\"direction\": \"%c\"},"
3318 "\"base64Length\": %d,"
3319 "\"asnBase64\": \"%s\"}",
3320 message.message.time.tv_sec,
3321 message.message.time.tv_nsec,
3322 message.message.enodbName,
3323 message.message.messageType,
3324 message.message.direction,
3325 (int) message.outLen,
3326 message.base64Data);
ss412g3bac2da2020-01-05 11:52:19 +02003327 static src::logger_mt &lg = my_logger::get();
3328
3329 BOOST_LOG(lg) << message.buffer;
ss412g1a79bdf2019-10-24 12:03:05 +03003330 }
ss412g1a79bdf2019-10-24 12:03:05 +03003331}
3332
3333
3334/**
3335 * take RMR error code to string
3336 * @param state
3337 * @return
3338 */
3339string translateRmrErrorMessages(int state) {
3340 string str = {};
3341 switch (state) {
3342 case RMR_OK:
3343 str = "RMR_OK - state is good";
3344 break;
3345 case RMR_ERR_BADARG:
aa7133@att.com409f2232020-10-29 13:06:45 +03003346 str = "RMR_ERR_BADARG - argument passed to function was unusable";
ss412g1a79bdf2019-10-24 12:03:05 +03003347 break;
3348 case RMR_ERR_NOENDPT:
3349 str = "RMR_ERR_NOENDPT - send//call could not find an endpoint based on msg type";
3350 break;
3351 case RMR_ERR_EMPTY:
3352 str = "RMR_ERR_EMPTY - msg received had no payload; attempt to send an empty message";
3353 break;
3354 case RMR_ERR_NOHDR:
3355 str = "RMR_ERR_NOHDR - message didn't contain a valid header";
3356 break;
3357 case RMR_ERR_SENDFAILED:
3358 str = "RMR_ERR_SENDFAILED - send failed; errno has nano reason";
3359 break;
3360 case RMR_ERR_CALLFAILED:
3361 str = "RMR_ERR_CALLFAILED - unable to send call() message";
3362 break;
3363 case RMR_ERR_NOWHOPEN:
3364 str = "RMR_ERR_NOWHOPEN - no wormholes are open";
3365 break;
3366 case RMR_ERR_WHID:
3367 str = "RMR_ERR_WHID - wormhole id was invalid";
3368 break;
3369 case RMR_ERR_OVERFLOW:
3370 str = "RMR_ERR_OVERFLOW - operation would have busted through a buffer/field size";
3371 break;
3372 case RMR_ERR_RETRY:
3373 str = "RMR_ERR_RETRY - request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)";
3374 break;
3375 case RMR_ERR_RCVFAILED:
3376 str = "RMR_ERR_RCVFAILED - receive failed (hard error)";
3377 break;
3378 case RMR_ERR_TIMEOUT:
3379 str = "RMR_ERR_TIMEOUT - message processing call timed out";
3380 break;
3381 case RMR_ERR_UNSET:
3382 str = "RMR_ERR_UNSET - the message hasn't been populated with a transport buffer";
3383 break;
3384 case RMR_ERR_TRUNC:
3385 str = "RMR_ERR_TRUNC - received message likely truncated";
3386 break;
3387 case RMR_ERR_INITFAILED:
3388 str = "RMR_ERR_INITFAILED - initialisation of something (probably message) failed";
3389 break;
3390 case RMR_ERR_NOTSUPP:
3391 str = "RMR_ERR_NOTSUPP - the request is not supported, or RMr was not initialised for the request";
3392 break;
3393 default:
3394 char buf[128]{};
3395 snprintf(buf, sizeof buf, "UNDOCUMENTED RMR_ERR : %d", state);
3396 str = buf;
3397 break;
3398 }
3399 return str;
3400}
czichy2175dd32022-05-17 15:24:51 +03003401int fetchStreamId(ConnectedCU_t *peerInfo, ReportingMessages_t &message)
3402{
3403 auto loglevel = mdclog_level_get();
3404 int streamId = INVALID_STREAM_ID;
3405 if(message.peerInfo->isSingleStream != false)
3406 {
3407 streamId = message.peerInfo->singleStreamId;
3408 if (loglevel >= MDCLOG_DEBUG) {
3409 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for SINGLE_STREAM streamId %d , Messeage Type %d ,%s",
3410 streamId,message.message.messageType, __FUNCTION__);
3411 }
3412 return streamId;
3413 }
3414 int msgType = message.message.messageType;
3415 switch (msgType){
3416 case RIC_E2_RESET_REQ:
3417 case RIC_E2_RESET_RESP:
3418 case RIC_E2_SETUP_RESP:
3419 case RIC_E2_SETUP_FAILURE:
3420 case RIC_ERROR_INDICATION:
3421 case RIC_SERVICE_QUERY:
3422 case RIC_SERVICE_UPDATE_ACK:
3423 case RIC_SERVICE_UPDATE_FAILURE:
3424 streamId = 0;
3425 break;
3426 case RIC_SUB_REQ:
3427 case RIC_SUB_DEL_REQ:
3428 case RIC_CONTROL_REQ:
3429 streamId = 1;
3430 break;
3431 default:
3432 streamId = 0;
3433 break;
3434 }
3435 if (loglevel >= MDCLOG_DEBUG) {
3436 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for streamId %d Messeage Type %d, %s",
3437 streamId, message.message.messageType, __FUNCTION__);
3438 }
3439 return streamId;
3440}