ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1 | // 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 | |
nm755n | 2e26814 | 2019-11-28 16:40:23 +0000 | [diff] [blame] | 16 | // This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 17 | // platform project (RICP). |
| 18 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 19 | // TODO: High-level file comment. |
| 20 | |
| 21 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 22 | |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 23 | #include <3rdparty/oranE2/RANfunctions-List.h> |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 24 | #include "sctpThread.h" |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 25 | #include "BuildRunName.h" |
dhirajverma | 5f13283 | 2021-06-17 17:27:54 +0530 | [diff] [blame] | 26 | #include <unistd.h> |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 27 | //#include "3rdparty/oranE2SM/E2SM-gNB-NRT-RANfunction-Definition.h" |
| 28 | //#include "BuildXml.h" |
| 29 | //#include "pugixml/src/pugixml.hpp" |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 30 | #include <pthread.h> |
| 31 | #include <sys/time.h> |
| 32 | #include <sys/inotify.h> |
| 33 | #include <errno.h> |
| 34 | #include <sys/stat.h> |
czichy | 6dd00bc | 2023-03-03 15:43:29 +0200 | [diff] [blame] | 35 | #include <arpa/inet.h> |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 36 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 37 | using namespace std; |
| 38 | //using namespace std::placeholders; |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 39 | using namespace boost::filesystem; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 40 | using namespace prometheus; |
| 41 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 42 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 43 | //#ifdef __cplusplus |
| 44 | //extern "C" |
| 45 | //{ |
| 46 | //#endif |
| 47 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 48 | // need to expose without the include of gcov |
| 49 | extern "C" void __gcov_flush(void); |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 50 | #define LOG_FILE_CONFIG_MAP "CONFIG_MAP_NAME" |
czichy | 6dd00bc | 2023-03-03 15:43:29 +0200 | [diff] [blame] | 51 | #define E2AP_PPID 70 // as per E2GAP chapter 6.1 |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 52 | |
| 53 | static void catch_function(int signal) { |
| 54 | __gcov_flush(); |
| 55 | exit(signal); |
| 56 | } |
| 57 | |
| 58 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 59 | BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::logger_mt) |
| 60 | |
| 61 | boost::shared_ptr<sinks::synchronous_sink<sinks::text_file_backend>> boostLogger; |
pwpmurthy | b187706 | 2023-04-12 14:49:58 +0000 | [diff] [blame] | 62 | // double cpuClock = 0.0; |
aa7133@att.com | 41fcb3f | 2020-11-29 13:48:25 +0200 | [diff] [blame] | 63 | bool jsonTrace = false; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 64 | |
wahidw | 1d1a9b7 | 2021-09-24 17:35:28 +0000 | [diff] [blame] | 65 | char* getinterfaceip() |
| 66 | { |
| 67 | char hostname[256]; |
| 68 | char *IP; |
| 69 | struct hostent *host_entry; |
| 70 | int retVal; |
| 71 | retVal = gethostname(hostname, sizeof(hostname)); |
| 72 | if ( retVal == -1 ) |
| 73 | return NULL; |
| 74 | host_entry = gethostbyname(hostname); |
| 75 | if ( host_entry == NULL ) |
| 76 | return NULL; |
| 77 | IP = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0])); |
| 78 | return IP; |
| 79 | } |
| 80 | |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 81 | |
| 82 | static int enable_log_change_notify(const char* fileName) |
| 83 | { |
| 84 | int ret = -1; |
| 85 | struct stat fileInfo; |
| 86 | if ( lstat(fileName,&fileInfo) == 0 ) |
| 87 | { |
| 88 | ret = register_log_change_notify(fileName); |
| 89 | } |
| 90 | return ret; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | static int register_log_change_notify(const char *fileName) |
| 95 | { |
| 96 | pthread_attr_t cb_attr; |
| 97 | pthread_t tid; |
| 98 | pthread_attr_init(&cb_attr); |
| 99 | pthread_attr_setdetachstate(&cb_attr,PTHREAD_CREATE_DETACHED); |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 100 | return pthread_create(&tid, &cb_attr,&monitor_loglevel_change_handler,(void *)fileName); |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
| 104 | static void * monitor_loglevel_change_handler(void* arg) |
| 105 | { |
| 106 | char *fileName = (char*) arg; |
| 107 | int ifd; // the inotify file des |
| 108 | int wfd; // the watched file des |
| 109 | ssize_t n = 0; |
| 110 | char rbuf[4096]; // large read buffer as the event is var len |
| 111 | fd_set fds; |
| 112 | int res = 0; |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 113 | char* dname=NULL; // directory name |
| 114 | char* bname = NULL; // basename |
| 115 | char* tok=NULL; |
| 116 | char* log_level=NULL; |
| 117 | |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 118 | dname = strdup( fileName ); // defrock the file name into dir and basename |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 119 | if( (tok = strrchr( dname, '/' )) != NULL ) { |
| 120 | *tok = '\0'; |
| 121 | bname = strdup( tok+1 ); |
| 122 | } |
| 123 | |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 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 { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 133 | FD_ZERO (&fds); |
| 134 | FD_SET (ifd, &fds); |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 135 | while( 1 ) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 136 | res = select (ifd + 1, &fds, NULL, NULL, NULL); |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 137 | if(res) |
| 138 | { |
| 139 | n = read( ifd, rbuf, sizeof( rbuf ) ); // read the event |
| 140 | if( n < 0 ) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 141 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 142 | if( errno == EAGAIN ) { |
| 143 | } else { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 144 | fprintf( stderr, "### CRIT ### config listener read err: %s\n", strerror( errno ) ); |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 145 | } |
| 146 | continue; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 147 | #endif |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | //Retrieving Log Level from configmap by parsing configmap file |
| 151 | log_level = parse_file(fileName); |
| 152 | update_mdc_log_level_severity(log_level); //setting log level |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 153 | if(log_level != NULL) { |
| 154 | mdclog_write(MDCLOG_INFO, "MDC log level updated to %s", log_level); |
| 155 | free(log_level); |
| 156 | } |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | inotify_rm_watch(ifd,wfd); |
| 160 | } |
| 161 | close(ifd); |
| 162 | } |
| 163 | free(bname); |
| 164 | free(dname); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 165 | free(fileName); |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 166 | |
| 167 | pthread_exit(NULL); |
| 168 | } |
| 169 | |
| 170 | void update_mdc_log_level_severity(char* log_level) |
| 171 | { |
| 172 | mdclog_severity_t level = MDCLOG_ERR; |
| 173 | |
| 174 | if(log_level == NULL) |
| 175 | { |
| 176 | printf("### ERR ### Invalid Log-Level Configuration in ConfigMap, Default Log-Level Applied: %d\n",level); |
| 177 | } |
| 178 | else if(strcasecmp(log_level,"1")==0) |
| 179 | { |
| 180 | level = MDCLOG_ERR; |
| 181 | } |
| 182 | else if(strcasecmp(log_level,"2")==0) |
| 183 | { |
| 184 | level = MDCLOG_WARN; |
| 185 | } |
| 186 | else if(strcasecmp(log_level,"3")==0) |
| 187 | { |
| 188 | level = MDCLOG_INFO; |
| 189 | } |
| 190 | else if(strcasecmp(log_level,"4")==0) |
| 191 | { |
| 192 | level = MDCLOG_DEBUG; |
| 193 | } |
| 194 | |
| 195 | mdclog_level_set(level); |
| 196 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * @brief Remove leading and trailing spaces from s. |
| 200 | * |
| 201 | * If the string was allocated dynamically, the caller cannot |
| 202 | * overwrite the returned pointer. |
| 203 | * |
| 204 | * @param s the string we want to remove spaces. |
| 205 | * @return Returns a null-terminated substring of "s". |
| 206 | */ |
| 207 | static inline char *trim(char *s) |
| 208 | { |
| 209 | char *end; |
| 210 | /* skip leading spaces */ |
| 211 | while (isspace(*s)) s++; |
| 212 | |
| 213 | /* all spaces */ |
| 214 | if (*s == '\0') return s; |
| 215 | |
| 216 | /* skip trailing spaces */ |
| 217 | end = s + strlen(s) - 1; |
| 218 | while (end > s && isspace(*end)) end--; |
| 219 | |
| 220 | /* write null character */ |
| 221 | *(end+1) = '\0'; |
| 222 | |
| 223 | return s; |
| 224 | } |
| 225 | |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 226 | static char* parse_file(char* filename) |
| 227 | { |
| 228 | char *token=NULL; |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 229 | bool found = false; |
| 230 | FILE *file = fopen ( filename, "r" ); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 231 | |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 232 | if ( file != NULL ) |
| 233 | { |
| 234 | char line [ 128 ]; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 235 | while ( fgets ( line, sizeof(line), file ) != NULL ) |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 236 | { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 237 | token = strtok(line, ":"); |
| 238 | token = trim(token); |
| 239 | if (strcmp(token,"log-level") == 0) { |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 240 | found = true; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 241 | token = strtok(NULL, "\n"); |
| 242 | token = trim(token); |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 243 | break; |
| 244 | } |
| 245 | } |
| 246 | fclose ( file ); |
| 247 | } |
| 248 | if(found) |
| 249 | return(strdup(token)); |
| 250 | else |
| 251 | return(NULL); |
| 252 | } |
| 253 | |
| 254 | char *read_env_param(const char*envkey) |
| 255 | { |
| 256 | if(envkey) |
| 257 | { |
| 258 | char *value = getenv(envkey); |
| 259 | if(value) |
| 260 | return strdup(value); |
| 261 | } |
| 262 | return NULL; |
| 263 | } |
| 264 | |
| 265 | void dynamic_log_level_change() |
| 266 | { |
| 267 | char *logFile_Name = read_env_param(LOG_FILE_CONFIG_MAP); |
| 268 | char* log_level_init=NULL; |
| 269 | if(logFile_Name) |
| 270 | { |
| 271 | log_level_init = parse_file(logFile_Name); |
| 272 | update_mdc_log_level_severity(log_level_init); //setting log level |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 273 | mdclog_write(MDCLOG_INFO, "MDC log level set to %s", log_level_init); |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 274 | free(log_level_init); |
| 275 | |
| 276 | } |
| 277 | enable_log_change_notify(logFile_Name); |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 278 | } |
| 279 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 280 | void init_log() { |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 281 | int log_change_monitor = 0; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 282 | mdclog_attr_t *attr; |
| 283 | mdclog_attr_init(&attr); |
| 284 | mdclog_attr_set_ident(attr, "E2Terminator"); |
| 285 | mdclog_init(attr); |
dhirajverma | 5f13283 | 2021-06-17 17:27:54 +0530 | [diff] [blame] | 286 | if(mdclog_format_initialize(log_change_monitor)!=0) |
| 287 | mdclog_write(MDCLOG_ERR, "Failed to intialize MDC log format !!!"); |
dhirajverma | 55e755b | 2021-06-29 02:01:47 +0530 | [diff] [blame] | 288 | dynamic_log_level_change(); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 289 | mdclog_attr_destroy(attr); |
| 290 | } |
pwpmurthy | b187706 | 2023-04-12 14:49:58 +0000 | [diff] [blame] | 291 | //auto start_time = std::chrono::high_resolution_clock::now(); |
| 292 | //typedef std::chrono::duration<double, std::ratio<1,1>> seconds_t; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 293 | |
pwpmurthy | b187706 | 2023-04-12 14:49:58 +0000 | [diff] [blame] | 294 | //double age() { |
| 295 | // return seconds_t(std::chrono::high_resolution_clock::now() - start_time).count(); |
| 296 | //} |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 297 | |
pwpmurthy | b187706 | 2023-04-12 14:49:58 +0000 | [diff] [blame] | 298 | // If model name in "/proc/cpuinfo" is happens to be "Common KVM processor" then |
| 299 | // approx_CPU_MHz() results in "SIGILL - Illegal Instruction" signal. |
| 300 | // |
| 301 | // double approx_CPU_MHz(unsigned sleepTime) { |
| 302 | // using namespace std::chrono_literals; |
| 303 | // uint32_t aux = 0; |
| 304 | // uint64_t cycles_start = rdtscp(aux); |
| 305 | // double time_start = age(); |
| 306 | // std::this_thread::sleep_for(sleepTime * 1ms); |
| 307 | // uint64_t elapsed_cycles = rdtscp(aux) - cycles_start; |
| 308 | // double elapsed_time = age() - time_start; |
| 309 | // return elapsed_cycles / elapsed_time; |
| 310 | //} |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 311 | |
| 312 | //std::atomic<int64_t> rmrCounter{0}; |
| 313 | std::atomic<int64_t> num_of_messages{0}; |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 314 | std::atomic<int64_t> num_of_XAPP_messages{0}; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 315 | static long transactionCounter = 0; |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 316 | pthread_mutex_t thread_lock; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 317 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 318 | int buildListeningPort(sctp_params_t &sctpParams) { |
aa7133@att.com | f211f19 | 2020-06-23 12:50:10 +0300 | [diff] [blame] | 319 | sctpParams.listenFD = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP); |
| 320 | if (sctpParams.listenFD <= 0) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 321 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | f211f19 | 2020-06-23 12:50:10 +0300 | [diff] [blame] | 322 | mdclog_write(MDCLOG_ERR, "Error Opening socket, %s", strerror(errno)); |
| 323 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 324 | #endif |
aa7133@att.com | f211f19 | 2020-06-23 12:50:10 +0300 | [diff] [blame] | 325 | } |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 326 | struct sctp_initmsg initmsg; |
| 327 | memset (&initmsg, 0, sizeof (initmsg)); |
| 328 | initmsg.sinit_num_ostreams = 2; |
| 329 | initmsg.sinit_max_instreams = 2; |
| 330 | initmsg.sinit_max_attempts = 4; |
| 331 | setsockopt (sctpParams.listenFD, IPPROTO_SCTP, SCTP_INITMSG, &initmsg, sizeof (initmsg)); |
aa7133@att.com | f211f19 | 2020-06-23 12:50:10 +0300 | [diff] [blame] | 332 | |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 333 | struct sockaddr_in6 serverAddress {}; |
| 334 | serverAddress.sin6_family = AF_INET6; |
| 335 | serverAddress.sin6_addr = in6addr_any; |
| 336 | serverAddress.sin6_port = htons(sctpParams.sctpPort); |
| 337 | if (bind(sctpParams.listenFD, (SA *)&serverAddress, sizeof(serverAddress)) < 0 ) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 338 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | f211f19 | 2020-06-23 12:50:10 +0300 | [diff] [blame] | 339 | mdclog_write(MDCLOG_ERR, "Error binding port %d. %s", sctpParams.sctpPort, strerror(errno)); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 340 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 341 | #endif |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 342 | } |
| 343 | if (setSocketNoBlocking(sctpParams.listenFD) == -1) { |
| 344 | //mdclog_write(MDCLOG_ERR, "Error binding. %s", strerror(errno)); |
| 345 | return -1; |
| 346 | } |
| 347 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 348 | struct sockaddr_in6 clientAddress {}; |
| 349 | socklen_t len = sizeof(clientAddress); |
| 350 | getsockname(sctpParams.listenFD, (SA *)&clientAddress, &len); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 351 | char buff[1024] {}; |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 352 | inet_ntop(AF_INET6, &clientAddress.sin6_addr, buff, sizeof(buff)); |
| 353 | mdclog_write(MDCLOG_DEBUG, "My address: %s, port %d\n", buff, htons(clientAddress.sin6_port)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 354 | } |
| 355 | |
pwpmurthy | 9f9d750 | 2023-04-20 16:55:30 +0000 | [diff] [blame] | 356 | // SCTP_HB_INTERVAL is in milisec |
| 357 | char *sctp_hb_interval = std::getenv("SCTP_HB_INTERVAL"); |
| 358 | if (sctp_hb_interval) { |
| 359 | // Setting the heartbeat interval timeout value |
| 360 | struct sctp_paddrparams sckt_parms; |
| 361 | memset(&sckt_parms, 0, sizeof(sckt_parms)); |
| 362 | unsigned int sckt_parms_size = sizeof(sckt_parms); |
| 363 | sckt_parms.spp_address.ss_family = AF_INET6; |
| 364 | sckt_parms.spp_flags |= SPP_HB_ENABLE; |
| 365 | sctp_opt_info(sctpParams.listenFD, 0, SCTP_PEER_ADDR_PARAMS, &sckt_parms, &sckt_parms_size); |
| 366 | if (sckt_parms_size != sizeof(sckt_parms)) { |
| 367 | fprintf(stderr, "Invalid size of sctp_paddrparams socket option: {} / {}", sckt_parms_size, (socklen_t)sizeof(sckt_parms)); |
| 368 | } else { |
| 369 | sckt_parms.spp_hbinterval = atoi(sctp_hb_interval); |
| 370 | setsockopt(sctpParams.listenFD, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &sckt_parms, sizeof(sckt_parms)); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | char *sctp_max_retries = std::getenv("SCTP_MAX_RETRIES"); |
| 375 | if (sctp_max_retries) { |
| 376 | // Setting the max retries config for the socket if rechability loss |
| 377 | struct sctp_assocparams sckt_assoc; |
| 378 | memset(&sckt_assoc, 0, sizeof(sckt_assoc)); |
| 379 | unsigned int str_assoc_size = sizeof(sckt_assoc); |
| 380 | sctp_opt_info(sctpParams.listenFD, 0, SCTP_ASSOCINFO, &sckt_assoc, &str_assoc_size); |
| 381 | if (str_assoc_size != sizeof(sckt_assoc)) { |
| 382 | fprintf(stderr, "Invalid size of sctp_assocparams socket option: {} / {}", str_assoc_size, (socklen_t)sizeof(sckt_assoc)); |
| 383 | } else { |
| 384 | sckt_assoc.sasoc_asocmaxrxt = atoi(sctp_max_retries); |
| 385 | setsockopt(sctpParams.listenFD, IPPROTO_SCTP, SCTP_ASSOCINFO, &sckt_assoc, sizeof(sckt_assoc)); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 390 | if (listen(sctpParams.listenFD, SOMAXCONN) < 0) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 391 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 392 | mdclog_write(MDCLOG_ERR, "Error listening. %s\n", strerror(errno)); |
| 393 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 394 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 395 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 396 | struct epoll_event event {}; |
| 397 | event.events = EPOLLIN | EPOLLET; |
| 398 | event.data.fd = sctpParams.listenFD; |
| 399 | |
| 400 | // add listening port to epoll |
| 401 | if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.listenFD, &event)) { |
dhirajverma | 93b6d9c | 2021-07-10 00:49:13 -0400 | [diff] [blame] | 402 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 403 | printf("Failed to add descriptor to epoll\n"); |
| 404 | mdclog_write(MDCLOG_ERR, "Failed to add descriptor to epoll. %s\n", strerror(errno)); |
| 405 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 406 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 407 | } |
| 408 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 409 | return 0; |
| 410 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 411 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 412 | int buildConfiguration(sctp_params_t &sctpParams) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 413 | path p = (sctpParams.configFilePath + "/" + sctpParams.configFileName).c_str(); |
| 414 | if (exists(p)) { |
| 415 | const int size = 2048; |
| 416 | auto fileSize = file_size(p); |
| 417 | if (fileSize > size) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 418 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 419 | mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 420 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 421 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 422 | } |
| 423 | } else { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 424 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 425 | mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str()); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 426 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 427 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 428 | } |
| 429 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 430 | ReadConfigFile conf; |
| 431 | if (conf.openConfigFile(p.string()) == -1) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 432 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 433 | mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s", |
| 434 | p.string().c_str(), strerror(errno)); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 435 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 436 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 437 | } |
| 438 | int rmrPort = conf.getIntValue("nano"); |
| 439 | if (rmrPort == -1) { |
dhirajverma | 93b6d9c | 2021-07-10 00:49:13 -0400 | [diff] [blame] | 440 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 441 | mdclog_write(MDCLOG_ERR, "illegal RMR port "); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 442 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 443 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 444 | } |
| 445 | sctpParams.rmrPort = (uint16_t)rmrPort; |
| 446 | snprintf(sctpParams.rmrAddress, sizeof(sctpParams.rmrAddress), "%d", (int) (sctpParams.rmrPort)); |
dhirajverma | 5f13283 | 2021-06-17 17:27:54 +0530 | [diff] [blame] | 447 | auto tmpStr = conf.getStringValue("volume"); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 448 | if (tmpStr.length() == 0) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 449 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 450 | mdclog_write(MDCLOG_ERR, "illegal volume."); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 451 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 452 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 453 | } |
| 454 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 455 | char tmpLogFilespec[VOLUME_URL_SIZE]; |
| 456 | tmpLogFilespec[0] = 0; |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 457 | sctpParams.volume[0] = 0; |
| 458 | snprintf(sctpParams.volume, VOLUME_URL_SIZE, "%s", tmpStr.c_str()); |
| 459 | // copy the name to temp file as well |
| 460 | snprintf(tmpLogFilespec, VOLUME_URL_SIZE, "%s", tmpStr.c_str()); |
| 461 | |
| 462 | |
| 463 | // define the file name in the tmp directory under the volume |
| 464 | strcat(tmpLogFilespec,"/tmp/E2Term_%Y-%m-%d_%H-%M-%S.%N.tmpStr"); |
| 465 | |
| 466 | sctpParams.myIP = conf.getStringValue("local-ip"); |
| 467 | if (sctpParams.myIP.length() == 0) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 468 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 469 | mdclog_write(MDCLOG_ERR, "illegal local-ip."); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 470 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 471 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 472 | } |
| 473 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 474 | int sctpPort = conf.getIntValue("sctp-port"); |
| 475 | if (sctpPort == -1) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 476 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 477 | mdclog_write(MDCLOG_ERR, "illegal SCTP port "); |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 478 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 479 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 480 | } |
| 481 | sctpParams.sctpPort = (uint16_t)sctpPort; |
| 482 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 483 | sctpParams.fqdn = conf.getStringValue("external-fqdn"); |
| 484 | if (sctpParams.fqdn.length() == 0) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 485 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 486 | mdclog_write(MDCLOG_ERR, "illegal external-fqdn"); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 487 | return -1; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 488 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 489 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 490 | |
aa7133@att.com | 342843e | 2020-01-26 12:53:34 +0200 | [diff] [blame] | 491 | std::string pod = conf.getStringValue("pod_name"); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 492 | #ifndef UNIT_TEST |
aa7133@att.com | 342843e | 2020-01-26 12:53:34 +0200 | [diff] [blame] | 493 | if (pod.length() == 0) { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 494 | mdclog_write(MDCLOG_ERR, "illegal pod_name in config file"); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 495 | return -1; |
aa7133@att.com | 342843e | 2020-01-26 12:53:34 +0200 | [diff] [blame] | 496 | } |
| 497 | auto *podName = getenv(pod.c_str()); |
| 498 | if (podName == nullptr) { |
aa7133@att.com | 54885fe | 2020-10-29 17:24:49 +0300 | [diff] [blame] | 499 | mdclog_write(MDCLOG_ERR, "illegal pod_name or environment variable not exists : %s", pod.c_str()); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 500 | return -1; |
aa7133@att.com | 342843e | 2020-01-26 12:53:34 +0200 | [diff] [blame] | 501 | |
| 502 | } else { |
| 503 | sctpParams.podName.assign(podName); |
| 504 | if (sctpParams.podName.length() == 0) { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 505 | mdclog_write(MDCLOG_ERR, "illegal pod_name"); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 506 | return -1; |
aa7133@att.com | 342843e | 2020-01-26 12:53:34 +0200 | [diff] [blame] | 507 | } |
| 508 | } |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 509 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 510 | tmpStr = conf.getStringValue("trace"); |
| 511 | transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower); |
| 512 | if ((tmpStr.compare("start")) == 0) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 513 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 514 | mdclog_write(MDCLOG_INFO, "Trace set to: start"); |
| 515 | sctpParams.trace = true; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 516 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 517 | } else if ((tmpStr.compare("stop")) == 0) { |
| 518 | mdclog_write(MDCLOG_INFO, "Trace set to: stop"); |
| 519 | sctpParams.trace = false; |
aa7133@att.com | 41fcb3f | 2020-11-29 13:48:25 +0200 | [diff] [blame] | 520 | } else { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 521 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | 41fcb3f | 2020-11-29 13:48:25 +0200 | [diff] [blame] | 522 | mdclog_write(MDCLOG_ERR, "Trace was set to wrong value %s, set to stop", tmpStr.c_str()); |
aa7133@att.com | 92aeebe | 2020-11-29 14:22:09 +0200 | [diff] [blame] | 523 | sctpParams.trace = false; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 524 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 525 | } |
| 526 | jsonTrace = sctpParams.trace; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 527 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 528 | sctpParams.epollTimeOut = -1; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 529 | |
| 530 | tmpStr = conf.getStringValue("prometheusPort"); |
| 531 | if (tmpStr.length() != 0) { |
| 532 | sctpParams.prometheusPort = tmpStr; |
| 533 | } |
| 534 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 535 | sctpParams.ka_message_length = snprintf(sctpParams.ka_message, KA_MESSAGE_SIZE, "{\"address\": \"%s:%d\"," |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 536 | "\"fqdn\": \"%s\"," |
| 537 | "\"pod_name\": \"%s\"}", |
aa7133@att.com | 342843e | 2020-01-26 12:53:34 +0200 | [diff] [blame] | 538 | (const char *)sctpParams.myIP.c_str(), |
| 539 | sctpParams.rmrPort, |
| 540 | sctpParams.fqdn.c_str(), |
| 541 | sctpParams.podName.c_str()); |
| 542 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 543 | if (mdclog_level_get() >= MDCLOG_INFO) { |
dhirajverma | 5f13283 | 2021-06-17 17:27:54 +0530 | [diff] [blame] | 544 | mdclog_write(MDCLOG_DEBUG,"RMR Port: %s", to_string(sctpParams.rmrPort).c_str()); |
dhirajverma | 5f13283 | 2021-06-17 17:27:54 +0530 | [diff] [blame] | 545 | mdclog_write(MDCLOG_DEBUG,"volume: %s", sctpParams.volume); |
| 546 | mdclog_write(MDCLOG_DEBUG,"tmpLogFilespec: %s", tmpLogFilespec); |
| 547 | mdclog_write(MDCLOG_DEBUG,"my ip: %s", sctpParams.myIP.c_str()); |
| 548 | mdclog_write(MDCLOG_DEBUG,"pod name: %s", sctpParams.podName.c_str()); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 549 | |
aa7133@att.com | 342843e | 2020-01-26 12:53:34 +0200 | [diff] [blame] | 550 | mdclog_write(MDCLOG_INFO, "running parameters for instance : %s", sctpParams.ka_message); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 551 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 552 | |
| 553 | // Files written to the current working directory |
| 554 | boostLogger = logging::add_file_log( |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 555 | keywords::file_name = tmpLogFilespec, // to temp directory |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 556 | keywords::rotation_size = 10 * 1024 * 1024, |
| 557 | keywords::time_based_rotation = sinks::file::rotation_at_time_interval(posix_time::hours(1)), |
| 558 | keywords::format = "%Message%" |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 559 | //keywords::format = "[%TimeStamp%]: %Message%" // use each tmpStr with time stamp |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 560 | ); |
| 561 | |
aa7133@att.com | 54885fe | 2020-10-29 17:24:49 +0300 | [diff] [blame] | 562 | // Setup a destination folder for collecting rotated (closed) files --since the same volume can use rename() |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 563 | boostLogger->locked_backend()->set_file_collector(sinks::file::make_collector( |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 564 | keywords::target = sctpParams.volume |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 565 | )); |
| 566 | |
| 567 | // Upon restart, scan the directory for files matching the file_name pattern |
| 568 | boostLogger->locked_backend()->scan_for_files(); |
| 569 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 570 | // Enable auto-flushing after each tmpStr record written |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 571 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 572 | boostLogger->locked_backend()->auto_flush(true); |
| 573 | } |
| 574 | |
| 575 | return 0; |
| 576 | } |
| 577 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 578 | void startPrometheus(sctp_params_t &sctpParams) { |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 579 | auto podName = std::getenv("POD_NAME"); |
| 580 | string metric = "E2TBeta"; |
| 581 | if (strstr(podName, "alpha") != NULL) { |
| 582 | metric = "E2TAlpha"; |
| 583 | } |
wahidw | 1d1a9b7 | 2021-09-24 17:35:28 +0000 | [diff] [blame] | 584 | //Get eth0 interface IP |
| 585 | char* host = getinterfaceip(); |
| 586 | string hostip = host; |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 587 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 588 | sctpParams.prometheusFamily = &BuildCounter() |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 589 | .Name(metric.c_str()) |
| 590 | .Help("E2T instance metrics") |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 591 | .Labels({{"POD_NAME", sctpParams.podName}}) |
| 592 | .Register(*sctpParams.prometheusRegistry); |
aa7133@att.com | 16c799b | 2020-03-24 18:01:51 +0200 | [diff] [blame] | 593 | |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 594 | // Build E2T instance level metrics |
| 595 | buildE2TPrometheusCounters(sctpParams); |
| 596 | |
wahidw | 1d1a9b7 | 2021-09-24 17:35:28 +0000 | [diff] [blame] | 597 | string prometheusPath; |
| 598 | if (hostip.empty()) |
| 599 | prometheusPath = sctpParams.prometheusPort + "," + "[::]:" + sctpParams.prometheusPort; |
| 600 | else |
| 601 | prometheusPath = hostip + ":" + sctpParams.prometheusPort; |
| 602 | |
aa7133@att.com | b92748d | 2020-06-29 11:52:30 +0300 | [diff] [blame] | 603 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
aa7133@att.com | 54885fe | 2020-10-29 17:24:49 +0300 | [diff] [blame] | 604 | mdclog_write(MDCLOG_DEBUG, "Start Prometheus Pull mode on %s", prometheusPath.c_str()); |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 605 | } |
aa7133@att.com | 54885fe | 2020-10-29 17:24:49 +0300 | [diff] [blame] | 606 | sctpParams.prometheusExposer = new Exposer(prometheusPath, 1); |
aa7133@att.com | b92748d | 2020-06-29 11:52:30 +0300 | [diff] [blame] | 607 | sctpParams.prometheusExposer->RegisterCollectable(sctpParams.prometheusRegistry); |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 608 | } |
dhirajverma | 31768a9 | 2021-05-06 12:38:49 +0530 | [diff] [blame] | 609 | #ifndef UNIT_TEST |
dhirajverma | 5f13283 | 2021-06-17 17:27:54 +0530 | [diff] [blame] | 610 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 611 | int main(const int argc, char **argv) { |
| 612 | sctp_params_t sctpParams; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 613 | { |
| 614 | std::random_device device{}; |
| 615 | std::mt19937 generator(device()); |
| 616 | std::uniform_int_distribution<long> distribution(1, (long) 1e12); |
| 617 | transactionCounter = distribution(generator); |
| 618 | } |
| 619 | |
| 620 | // uint64_t st = 0; |
| 621 | // uint32_t aux1 = 0; |
| 622 | // st = rdtscp(aux1); |
| 623 | |
| 624 | unsigned num_cpus = std::thread::hardware_concurrency(); |
| 625 | init_log(); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 626 | if (std::signal(SIGINT, catch_function) == SIG_ERR) { |
| 627 | mdclog_write(MDCLOG_ERR, "Error initializing SIGINT"); |
| 628 | exit(1); |
| 629 | } |
| 630 | if (std::signal(SIGABRT, catch_function)== SIG_ERR) { |
| 631 | mdclog_write(MDCLOG_ERR, "Error initializing SIGABRT"); |
| 632 | exit(1); |
| 633 | } |
| 634 | if (std::signal(SIGTERM, catch_function)== SIG_ERR) { |
| 635 | mdclog_write(MDCLOG_ERR, "Error initializing SIGTERM"); |
| 636 | exit(1); |
| 637 | } |
| 638 | |
pwpmurthy | b187706 | 2023-04-12 14:49:58 +0000 | [diff] [blame] | 639 | // cpuClock = approx_CPU_MHz(100); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 640 | |
pwpmurthy | b187706 | 2023-04-12 14:49:58 +0000 | [diff] [blame] | 641 | // mdclog_write(MDCLOG_DEBUG, "CPU speed %11.11f", cpuClock); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 642 | |
| 643 | auto result = parse(argc, argv, sctpParams); |
| 644 | |
| 645 | if (buildConfiguration(sctpParams) != 0) { |
| 646 | exit(-1); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 647 | } |
| 648 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 649 | //auto registry = std::make_shared<Registry>(); |
| 650 | sctpParams.prometheusRegistry = std::make_shared<Registry>(); |
| 651 | |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 652 | //sctpParams.prometheusFamily = new Family<Counter>("E2T", "E2T message counter", {{"E", sctpParams.podName}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 653 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 654 | startPrometheus(sctpParams); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 655 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 656 | // start epoll |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 657 | sctpParams.epoll_fd = epoll_create1(0); |
| 658 | if (sctpParams.epoll_fd == -1) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 659 | mdclog_write(MDCLOG_ERR, "failed to open epoll descriptor"); |
| 660 | exit(-1); |
| 661 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 662 | getRmrContext(sctpParams); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 663 | if (sctpParams.rmrCtx == nullptr) { |
| 664 | close(sctpParams.epoll_fd); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 665 | exit(-1); |
| 666 | } |
| 667 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 668 | if (buildInotify(sctpParams) == -1) { |
| 669 | close(sctpParams.rmrListenFd); |
| 670 | rmr_close(sctpParams.rmrCtx); |
| 671 | close(sctpParams.epoll_fd); |
| 672 | exit(-1); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | if (buildListeningPort(sctpParams) != 0) { |
| 676 | close(sctpParams.rmrListenFd); |
| 677 | rmr_close(sctpParams.rmrCtx); |
| 678 | close(sctpParams.epoll_fd); |
| 679 | exit(-1); |
| 680 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 681 | |
| 682 | sctpParams.sctpMap = new mapWrapper(); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 683 | |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 684 | if (pthread_mutex_init(&thread_lock, NULL) != 0) { |
| 685 | mdclog_write(MDCLOG_ERR, "failed to init thread lock"); |
| 686 | exit(-1); |
| 687 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 688 | std::vector<std::thread> threads(num_cpus); |
| 689 | // std::vector<std::thread> threads; |
| 690 | |
aa7133@att.com | 24e9fa4 | 2020-11-13 20:32:53 +0200 | [diff] [blame] | 691 | num_cpus = 3; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 692 | for (unsigned int i = 0; i < num_cpus; i++) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 693 | threads[i] = std::thread(listener, &sctpParams); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 694 | |
| 695 | cpu_set_t cpuset; |
| 696 | CPU_ZERO(&cpuset); |
| 697 | CPU_SET(i, &cpuset); |
| 698 | int rc = pthread_setaffinity_np(threads[i].native_handle(), sizeof(cpu_set_t), &cpuset); |
| 699 | if (rc != 0) { |
| 700 | mdclog_write(MDCLOG_ERR, "Error calling pthread_setaffinity_np: %d", rc); |
| 701 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 702 | } |
| 703 | |
aa7133@att.com | 16c799b | 2020-03-24 18:01:51 +0200 | [diff] [blame] | 704 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 705 | //loop over term_init until first message from xApp |
| 706 | handleTermInit(sctpParams); |
| 707 | |
| 708 | for (auto &t : threads) { |
| 709 | t.join(); |
| 710 | } |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 711 | pthread_mutex_destroy(&thread_lock); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 712 | return 0; |
| 713 | } |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 714 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 715 | void handleTermInit(sctp_params_t &sctpParams) { |
| 716 | sendTermInit(sctpParams); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 717 | //send to e2 manager init of e2 term |
| 718 | //E2_TERM_INIT |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 719 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 720 | int count = 0; |
| 721 | while (true) { |
| 722 | auto xappMessages = num_of_XAPP_messages.load(std::memory_order_acquire); |
| 723 | if (xappMessages > 0) { |
| 724 | if (mdclog_level_get() >= MDCLOG_INFO) { |
aa7133@att.com | 54885fe | 2020-10-29 17:24:49 +0300 | [diff] [blame] | 725 | mdclog_write(MDCLOG_INFO, "Got a message from some application, stop sending E2_TERM_INIT"); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 726 | } |
| 727 | return; |
| 728 | } |
| 729 | usleep(100000); |
| 730 | count++; |
| 731 | if (count % 1000 == 0) { |
| 732 | mdclog_write(MDCLOG_ERR, "GOT No messages from any xApp"); |
| 733 | sendTermInit(sctpParams); |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | void sendTermInit(sctp_params_t &sctpParams) { |
| 739 | rmr_mbuf_t *msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.ka_message_length); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 740 | auto count = 0; |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 741 | while (true) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 742 | msg->mtype = E2_TERM_INIT; |
| 743 | msg->state = 0; |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 744 | rmr_bytes2payload(msg, (unsigned char *)sctpParams.ka_message, sctpParams.ka_message_length); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 745 | static unsigned char tx[32]; |
| 746 | auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 747 | rmr_bytes2xact(msg, tx, txLen); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 748 | msg = rmr_send_msg(sctpParams.rmrCtx, msg); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 749 | if (msg == nullptr) { |
aa7133@att.com | c9575aa | 2020-04-02 11:40:09 +0300 | [diff] [blame] | 750 | msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.ka_message_length); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 751 | } else if (msg->state == 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 752 | rmr_free_msg(msg); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 753 | if (mdclog_level_get() >= MDCLOG_INFO) { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 754 | mdclog_write(MDCLOG_INFO, "E2_TERM_INIT successfully sent "); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 755 | } |
| 756 | return; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 757 | } else { |
| 758 | if (count % 100 == 0) { |
aa7133@att.com | 11b17d4 | 2020-03-22 11:35:16 +0200 | [diff] [blame] | 759 | mdclog_write(MDCLOG_ERR, "Error sending E2_TERM_INIT cause : %s ", translateRmrErrorMessages(msg->state).c_str()); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 760 | } |
| 761 | sleep(1); |
| 762 | } |
| 763 | count++; |
| 764 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | /** |
| 768 | * |
| 769 | * @param argc |
| 770 | * @param argv |
| 771 | * @param sctpParams |
| 772 | * @return |
| 773 | */ |
| 774 | cxxopts::ParseResult parse(int argc, char *argv[], sctp_params_t &sctpParams) { |
| 775 | cxxopts::Options options(argv[0], "e2 term help"); |
| 776 | options.positional_help("[optional args]").show_positional_help(); |
| 777 | options.allow_unrecognised_options().add_options() |
| 778 | ("p,path", "config file path", cxxopts::value<std::string>(sctpParams.configFilePath)->default_value("config")) |
| 779 | ("f,file", "config file name", cxxopts::value<std::string>(sctpParams.configFileName)->default_value("config.conf")) |
| 780 | ("h,help", "Print help"); |
| 781 | |
aa7133@att.com | de40d1c | 2020-08-26 16:19:20 +0300 | [diff] [blame] | 782 | auto result = options.parse(argc, (const char **&)argv); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 783 | |
| 784 | if (result.count("help")) { |
| 785 | std::cout << options.help({""}) << std::endl; |
| 786 | exit(0); |
| 787 | } |
| 788 | return result; |
| 789 | } |
| 790 | |
| 791 | /** |
| 792 | * |
| 793 | * @param sctpParams |
| 794 | * @return -1 failed 0 success |
| 795 | */ |
| 796 | int buildInotify(sctp_params_t &sctpParams) { |
| 797 | sctpParams.inotifyFD = inotify_init1(IN_NONBLOCK); |
| 798 | if (sctpParams.inotifyFD == -1) { |
| 799 | mdclog_write(MDCLOG_ERR, "Failed to init inotify (inotify_init1) %s", strerror(errno)); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 800 | return -1; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 801 | } |
| 802 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 803 | sctpParams.inotifyWD = inotify_add_watch(sctpParams.inotifyFD, |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 804 | (const char *)sctpParams.configFilePath.c_str(), |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 805 | (unsigned)IN_OPEN | (unsigned)IN_CLOSE_WRITE | (unsigned)IN_CLOSE_NOWRITE); //IN_CLOSE = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 806 | if (sctpParams.inotifyWD == -1) { |
| 807 | mdclog_write(MDCLOG_ERR, "Failed to add directory : %s to inotify (inotify_add_watch) %s", |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 808 | sctpParams.configFilePath.c_str(), |
| 809 | strerror(errno)); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 810 | close(sctpParams.inotifyFD); |
| 811 | return -1; |
| 812 | } |
| 813 | |
| 814 | struct epoll_event event{}; |
| 815 | event.events = (EPOLLIN); |
| 816 | event.data.fd = sctpParams.inotifyFD; |
| 817 | // add listening RMR FD to epoll |
| 818 | if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.inotifyFD, &event)) { |
| 819 | mdclog_write(MDCLOG_ERR, "Failed to add inotify FD to epoll"); |
| 820 | close(sctpParams.inotifyFD); |
| 821 | return -1; |
| 822 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 823 | return 0; |
| 824 | } |
| 825 | |
| 826 | /** |
| 827 | * |
| 828 | * @param args |
| 829 | * @return |
| 830 | */ |
| 831 | void listener(sctp_params_t *params) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 832 | int num_of_SCTP_messages = 0; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 833 | auto totalTime = 0.0; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 834 | std::thread::id this_id = std::this_thread::get_id(); |
| 835 | //save cout |
dhirajverma | 5f13283 | 2021-06-17 17:27:54 +0530 | [diff] [blame] | 836 | auto pod_name = std::getenv("POD_NAME"); |
| 837 | auto container_name = std::getenv("CONTAINER_NAME"); |
| 838 | auto service_name = std::getenv("SERVICE_NAME"); |
| 839 | auto host_name = std::getenv("HOST_NAME"); |
| 840 | auto system_name = std::getenv("SYSTEM_NAME"); |
| 841 | auto pid = std::to_string(getpid()).c_str(); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 842 | streambuf *oldCout = cout.rdbuf(); |
| 843 | ostringstream memCout; |
| 844 | // create new cout |
| 845 | cout.rdbuf(memCout.rdbuf()); |
| 846 | cout << this_id; |
| 847 | //return to the normal cout |
| 848 | cout.rdbuf(oldCout); |
| 849 | |
| 850 | char tid[32]; |
| 851 | memcpy(tid, memCout.str().c_str(), memCout.str().length() < 32 ? memCout.str().length() : 31); |
| 852 | tid[memCout.str().length()] = 0; |
dhirajverma | 5f13283 | 2021-06-17 17:27:54 +0530 | [diff] [blame] | 853 | mdclog_mdc_add("SYSTEM_NAME", system_name); |
| 854 | mdclog_mdc_add("HOST_NAME", host_name); |
| 855 | mdclog_mdc_add("SERVICE_NAME", service_name); |
| 856 | mdclog_mdc_add("CONTAINER_NAME", container_name); |
| 857 | mdclog_mdc_add("POD_NAME", pod_name); |
| 858 | mdclog_mdc_add("PID", pid); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 859 | |
| 860 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 861 | mdclog_write(MDCLOG_DEBUG, "started thread number %s", tid); |
| 862 | } |
| 863 | |
| 864 | RmrMessagesBuffer_t rmrMessageBuffer{}; |
| 865 | //create and init RMR |
| 866 | rmrMessageBuffer.rmrCtx = params->rmrCtx; |
| 867 | |
| 868 | auto *events = (struct epoll_event *) calloc(MAXEVENTS, sizeof(struct epoll_event)); |
| 869 | struct timespec end{0, 0}; |
| 870 | struct timespec start{0, 0}; |
| 871 | |
| 872 | rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
| 873 | rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
| 874 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 875 | memcpy(rmrMessageBuffer.ka_message, params->ka_message, params->ka_message_length); |
| 876 | rmrMessageBuffer.ka_message_len = params->ka_message_length; |
| 877 | rmrMessageBuffer.ka_message[rmrMessageBuffer.ka_message_len] = 0; |
| 878 | |
| 879 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 880 | mdclog_write(MDCLOG_DEBUG, "keep alive message is : %s", rmrMessageBuffer.ka_message); |
| 881 | } |
| 882 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 883 | ReportingMessages_t message {}; |
| 884 | |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 885 | // for (int i = 0; i < MAX_RMR_BUFF_ARRAY; i++) { |
aa7133@att.com | 7c3e4c0 | 2020-03-25 16:37:19 +0200 | [diff] [blame] | 886 | // rmrMessageBuffer.rcvBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
| 887 | // rmrMessageBuffer.sendBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
| 888 | // } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 889 | |
| 890 | while (true) { |
| 891 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 892 | mdclog_write(MDCLOG_DEBUG, "Start EPOLL Wait. Timeout = %d", params->epollTimeOut); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 893 | } |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 894 | #ifndef UNIT_TEST |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 895 | auto numOfEvents = epoll_wait(params->epoll_fd, events, MAXEVENTS, params->epollTimeOut); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 896 | #else |
| 897 | auto numOfEvents = 1; |
| 898 | #endif |
aa7133@att.com | b92748d | 2020-06-29 11:52:30 +0300 | [diff] [blame] | 899 | if (numOfEvents == 0) { // time out |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 900 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | b92748d | 2020-06-29 11:52:30 +0300 | [diff] [blame] | 901 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 902 | mdclog_write(MDCLOG_DEBUG, "got epoll timeout"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 903 | } |
| 904 | continue; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 905 | } else if (numOfEvents < 0) { |
| 906 | if (errno == EINTR) { |
| 907 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 908 | mdclog_write(MDCLOG_DEBUG, "got EINTR : %s", strerror(errno)); |
| 909 | } |
| 910 | continue; |
| 911 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 912 | mdclog_write(MDCLOG_ERR, "Epoll wait failed, errno = %s", strerror(errno)); |
dhirajverma | b55bc17 | 2021-11-09 02:15:08 -0500 | [diff] [blame] | 913 | if(events) |
| 914 | { |
| 915 | free(events); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 916 | events = nullptr; |
dhirajverma | b55bc17 | 2021-11-09 02:15:08 -0500 | [diff] [blame] | 917 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 918 | return; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 919 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 920 | } |
| 921 | for (auto i = 0; i < numOfEvents; i++) { |
| 922 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 923 | mdclog_write(MDCLOG_DEBUG, "handling epoll event %d out of %d", i + 1, numOfEvents); |
| 924 | } |
| 925 | clock_gettime(CLOCK_MONOTONIC, &message.message.time); |
| 926 | start.tv_sec = message.message.time.tv_sec; |
| 927 | start.tv_nsec = message.message.time.tv_nsec; |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 928 | |
| 929 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 930 | if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP)) { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 931 | handlepoll_error(events[i], message, rmrMessageBuffer, params); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 932 | } else if (events[i].events & EPOLLOUT) { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 933 | handleEinprogressMessages(events[i], message, rmrMessageBuffer, params); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 934 | } else if (params->listenFD == events[i].data.fd) { |
aa7133@att.com | 6680c3b | 2020-03-22 12:06:58 +0200 | [diff] [blame] | 935 | if (mdclog_level_get() >= MDCLOG_INFO) { |
| 936 | mdclog_write(MDCLOG_INFO, "New connection request from sctp network\n"); |
| 937 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 938 | // new connection is requested from RAN start build connection |
| 939 | while (true) { |
| 940 | struct sockaddr in_addr {}; |
| 941 | socklen_t in_len; |
| 942 | char hostBuff[NI_MAXHOST]; |
| 943 | char portBuff[NI_MAXSERV]; |
| 944 | |
| 945 | in_len = sizeof(in_addr); |
| 946 | auto *peerInfo = (ConnectedCU_t *)calloc(1, sizeof(ConnectedCU_t)); |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 947 | if(peerInfo == nullptr){ |
swc | 58d4f5d | 2020-10-20 15:08:38 +0900 | [diff] [blame] | 948 | mdclog_write(MDCLOG_ERR, "calloc failed"); |
| 949 | break; |
| 950 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 951 | peerInfo->sctpParams = params; |
| 952 | peerInfo->fileDescriptor = accept(params->listenFD, &in_addr, &in_len); |
| 953 | if (peerInfo->fileDescriptor == -1) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 954 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 955 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { |
| 956 | /* We have processed all incoming connections. */ |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 957 | if(peerInfo) { |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 958 | free(peerInfo); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 959 | peerInfo = nullptr; |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 960 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 961 | break; |
| 962 | } else { |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 963 | if(peerInfo) { |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 964 | free(peerInfo); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 965 | peerInfo = nullptr; |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 966 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 967 | mdclog_write(MDCLOG_ERR, "Accept error, errno = %s", strerror(errno)); |
| 968 | break; |
| 969 | } |
| 970 | } |
| 971 | if (setSocketNoBlocking(peerInfo->fileDescriptor) == -1) { |
| 972 | mdclog_write(MDCLOG_ERR, "setSocketNoBlocking failed to set new connection %s on port %s\n", hostBuff, portBuff); |
| 973 | close(peerInfo->fileDescriptor); |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 974 | if(peerInfo) { |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 975 | free(peerInfo); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 976 | peerInfo = nullptr; |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 977 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 978 | break; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 979 | #endif |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 980 | } |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 981 | struct sctp_event_subscribe sctpevents; |
| 982 | memset( (void *)&sctpevents, 0, sizeof(sctpevents) ); |
| 983 | sctpevents.sctp_data_io_event = 1; |
| 984 | setsockopt(peerInfo->fileDescriptor, SOL_SCTP, SCTP_EVENTS,(const void *)&sctpevents, sizeof(sctpevents) ); |
| 985 | |
pwpmurthy | 7d6caa9 | 2023-05-19 15:39:41 +0000 | [diff] [blame] | 986 | { |
| 987 | char *value = getenv("SCTP_ASSOC_MAX_RETRANS"); |
| 988 | if (value) |
| 989 | { |
| 990 | int int_val = atoi(value); |
| 991 | mdclog_write(MDCLOG_INFO, "Changing sctp_association_max_retrans to %s, %d\n", value, int_val); |
| 992 | if (int_val > 0) |
| 993 | { |
| 994 | struct sctp_assocparams sctpassocparams; |
| 995 | memset((void *)&sctpassocparams, 0, sizeof(sctpassocparams)); |
| 996 | sctpassocparams.sasoc_asocmaxrxt = int_val; |
| 997 | setsockopt(peerInfo->fileDescriptor, SOL_SCTP, SCTP_ASSOCINFO, (const void *)&sctpassocparams, sizeof(sctpassocparams)); |
| 998 | } |
| 999 | } |
| 1000 | } |
| 1001 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1002 | auto ans = getnameinfo(&in_addr, in_len, |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 1003 | peerInfo->hostName, NI_MAXHOST, |
| 1004 | peerInfo->portNumber, NI_MAXSERV, (unsigned )((unsigned int)NI_NUMERICHOST | (unsigned int)NI_NUMERICSERV)); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1005 | if (ans < 0) { |
| 1006 | mdclog_write(MDCLOG_ERR, "Failed to get info on connection request. %s\n", strerror(errno)); |
| 1007 | close(peerInfo->fileDescriptor); |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 1008 | if(peerInfo) { |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 1009 | free(peerInfo); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1010 | peerInfo = nullptr; |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 1011 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1012 | break; |
| 1013 | } |
| 1014 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1015 | mdclog_write(MDCLOG_DEBUG, "Accepted connection on descriptor %d (host=%s, port=%s)\n", peerInfo->fileDescriptor, peerInfo->hostName, peerInfo->portNumber); |
| 1016 | } |
| 1017 | peerInfo->isConnected = false; |
| 1018 | peerInfo->gotSetup = false; |
| 1019 | if (addToEpoll(params->epoll_fd, |
| 1020 | peerInfo, |
| 1021 | (EPOLLIN | EPOLLET), |
| 1022 | params->sctpMap, nullptr, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1023 | 0) != 0) { |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 1024 | if(peerInfo) { |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 1025 | free(peerInfo); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1026 | peerInfo = nullptr; |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 1027 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1028 | break; |
| 1029 | } |
aa7133@att.com | 6680c3b | 2020-03-22 12:06:58 +0200 | [diff] [blame] | 1030 | break; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1031 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1032 | } else if (params->rmrListenFd == events[i].data.fd) { |
| 1033 | // got message from XAPP |
aa7133@att.com | de40d1c | 2020-08-26 16:19:20 +0300 | [diff] [blame] | 1034 | //num_of_XAPP_messages.fetch_add(1, std::memory_order_release); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1035 | num_of_messages.fetch_add(1, std::memory_order_release); |
| 1036 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 1037 | mdclog_write(MDCLOG_DEBUG, "new RMR message"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1038 | } |
aa7133@att.com | 6680c3b | 2020-03-22 12:06:58 +0200 | [diff] [blame] | 1039 | if (receiveXappMessages(params->sctpMap, |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1040 | rmrMessageBuffer, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1041 | message.message.time) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1042 | mdclog_write(MDCLOG_ERR, "Error handling Xapp message"); |
| 1043 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1044 | } else if (params->inotifyFD == events[i].data.fd) { |
| 1045 | mdclog_write(MDCLOG_INFO, "Got event from inotify (configuration update)"); |
| 1046 | handleConfigChange(params); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1047 | } else { |
| 1048 | /* We RMR_ERR_RETRY have data on the fd waiting to be read. Read and display it. |
| 1049 | * We must read whatever data is available completely, as we are running |
| 1050 | * in edge-triggered mode and won't get a notification again for the same data. */ |
| 1051 | num_of_messages.fetch_add(1, std::memory_order_release); |
| 1052 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1053 | mdclog_write(MDCLOG_DEBUG, "new message from SCTP, epoll flags are : %0x", events[i].events); |
| 1054 | } |
| 1055 | receiveDataFromSctp(&events[i], |
| 1056 | params->sctpMap, |
| 1057 | num_of_SCTP_messages, |
| 1058 | rmrMessageBuffer, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1059 | message.message.time); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | clock_gettime(CLOCK_MONOTONIC, &end); |
| 1063 | if (mdclog_level_get() >= MDCLOG_INFO) { |
| 1064 | totalTime += ((end.tv_sec + 1.0e-9 * end.tv_nsec) - |
| 1065 | ((double) start.tv_sec + 1.0e-9 * start.tv_nsec)); |
| 1066 | } |
| 1067 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1068 | mdclog_write(MDCLOG_DEBUG, "message handling is %ld seconds %ld nanoseconds", |
| 1069 | end.tv_sec - start.tv_sec, |
| 1070 | end.tv_nsec - start.tv_nsec); |
| 1071 | } |
| 1072 | } |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 1073 | #ifdef UNIT_TEST |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 1074 | break; |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 1075 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1076 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1081 | * @param sctpParams |
| 1082 | */ |
| 1083 | void handleConfigChange(sctp_params_t *sctpParams) { |
| 1084 | char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event)))); |
| 1085 | const struct inotify_event *event; |
| 1086 | char *ptr; |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 1087 | #ifdef UNIT_TEST |
| 1088 | struct inotify_event tmpEvent; |
| 1089 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1090 | path p = (sctpParams->configFilePath + "/" + sctpParams->configFileName).c_str(); |
| 1091 | auto endlessLoop = true; |
| 1092 | while (endlessLoop) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1093 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
dhirajverma | 93b6d9c | 2021-07-10 00:49:13 -0400 | [diff] [blame] | 1094 | auto len = read(sctpParams->inotifyFD, buf, sizeof buf); |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 1095 | #else |
| 1096 | auto len=10; |
| 1097 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1098 | if (len == -1) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1099 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1100 | if (errno != EAGAIN) { |
| 1101 | mdclog_write(MDCLOG_ERR, "read %s ", strerror(errno)); |
| 1102 | endlessLoop = false; |
| 1103 | continue; |
| 1104 | } |
| 1105 | else { |
| 1106 | endlessLoop = false; |
| 1107 | continue; |
| 1108 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1109 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | for (ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + event->len) { |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 1113 | #ifndef UNIT_TEST |
| 1114 | event = (const struct inotify_event *)ptr; |
| 1115 | #else |
| 1116 | tmpEvent.mask = (uint32_t)IN_CLOSE_WRITE; |
| 1117 | event = &tmpEvent; |
| 1118 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1119 | if (event->mask & (uint32_t)IN_ISDIR) { |
| 1120 | continue; |
| 1121 | } |
| 1122 | |
| 1123 | // the directory name |
| 1124 | if (sctpParams->inotifyWD == event->wd) { |
| 1125 | // not the directory |
| 1126 | } |
| 1127 | if (event->len) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1128 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | dfc1db9 | 2020-03-31 17:32:04 +0300 | [diff] [blame] | 1129 | auto retVal = strcmp(sctpParams->configFileName.c_str(), event->name); |
| 1130 | if (retVal != 0) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1131 | continue; |
| 1132 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1133 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1134 | } |
| 1135 | // only the file we want |
| 1136 | if (event->mask & (uint32_t)IN_CLOSE_WRITE) { |
aa7133@att.com | dfc1db9 | 2020-03-31 17:32:04 +0300 | [diff] [blame] | 1137 | if (mdclog_level_get() >= MDCLOG_INFO) { |
| 1138 | mdclog_write(MDCLOG_INFO, "Configuration file changed"); |
| 1139 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1140 | if (exists(p)) { |
| 1141 | const int size = 2048; |
| 1142 | auto fileSize = file_size(p); |
| 1143 | if (fileSize > size) { |
| 1144 | mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size); |
| 1145 | return; |
| 1146 | } |
| 1147 | } else { |
| 1148 | mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str()); |
| 1149 | return; |
| 1150 | } |
| 1151 | |
| 1152 | ReadConfigFile conf; |
| 1153 | if (conf.openConfigFile(p.string()) == -1) { |
| 1154 | mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s", |
| 1155 | p.string().c_str(), strerror(errno)); |
| 1156 | return; |
| 1157 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1158 | auto tmpStr = conf.getStringValue("trace"); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1159 | if (tmpStr.length() == 0) { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1160 | mdclog_write(MDCLOG_ERR, "illegal trace. Set trace to stop"); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1161 | tmpStr = "stop"; |
| 1162 | } |
| 1163 | |
| 1164 | transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower); |
| 1165 | if ((tmpStr.compare("start")) == 0) { |
| 1166 | mdclog_write(MDCLOG_INFO, "Trace set to: start"); |
| 1167 | sctpParams->trace = true; |
| 1168 | } else if ((tmpStr.compare("stop")) == 0) { |
| 1169 | mdclog_write(MDCLOG_INFO, "Trace set to: stop"); |
| 1170 | sctpParams->trace = false; |
| 1171 | } else { |
| 1172 | mdclog_write(MDCLOG_ERR, "Trace was set to wrong value %s, set to stop", tmpStr.c_str()); |
| 1173 | sctpParams->trace = false; |
| 1174 | } |
| 1175 | jsonTrace = sctpParams->trace; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1176 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1177 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1178 | endlessLoop = false; |
| 1179 | } |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 1180 | #ifdef UNIT_TEST |
| 1181 | break; |
| 1182 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | /** |
| 1188 | * |
| 1189 | * @param event |
| 1190 | * @param message |
| 1191 | * @param rmrMessageBuffer |
| 1192 | * @param params |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1193 | */ |
| 1194 | void handleEinprogressMessages(struct epoll_event &event, |
| 1195 | ReportingMessages_t &message, |
| 1196 | RmrMessagesBuffer_t &rmrMessageBuffer, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1197 | sctp_params_t *params) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1198 | auto *peerInfo = (ConnectedCU_t *)event.data.ptr; |
| 1199 | memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName)); |
| 1200 | |
| 1201 | mdclog_write(MDCLOG_INFO, "file descriptor %d got EPOLLOUT", peerInfo->fileDescriptor); |
| 1202 | auto retVal = 0; |
| 1203 | socklen_t retValLen = 0; |
| 1204 | auto rc = getsockopt(peerInfo->fileDescriptor, SOL_SOCKET, SO_ERROR, &retVal, &retValLen); |
| 1205 | if (rc != 0 || retVal != 0) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1206 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1207 | if (rc != 0) { |
| 1208 | rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256, |
| 1209 | "%s|Failed SCTP Connection, after EINPROGRESS the getsockopt%s", |
| 1210 | peerInfo->enodbName, strerror(errno)); |
| 1211 | } else if (retVal != 0) { |
| 1212 | rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256, |
| 1213 | "%s|Failed SCTP Connection after EINPROGRESS, SO_ERROR", |
| 1214 | peerInfo->enodbName); |
| 1215 | } |
| 1216 | |
| 1217 | message.message.asndata = rmrMessageBuffer.sendMessage->payload; |
| 1218 | message.message.asnLength = rmrMessageBuffer.sendMessage->len; |
| 1219 | mdclog_write(MDCLOG_ERR, "%s", rmrMessageBuffer.sendMessage->payload); |
| 1220 | message.message.direction = 'N'; |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1221 | if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1222 | mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP"); |
| 1223 | } |
dhirajverma | 31768a9 | 2021-05-06 12:38:49 +0530 | [diff] [blame] | 1224 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1225 | memset(peerInfo->asnData, 0, peerInfo->asnLength); |
| 1226 | peerInfo->asnLength = 0; |
| 1227 | peerInfo->mtype = 0; |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1228 | return; |
| 1229 | } |
dhirajverma | 93b6d9c | 2021-07-10 00:49:13 -0400 | [diff] [blame] | 1230 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1231 | peerInfo->isConnected = true; |
| 1232 | |
| 1233 | if (modifyToEpoll(params->epoll_fd, peerInfo, (EPOLLIN | EPOLLET), params->sctpMap, peerInfo->enodbName, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1234 | peerInfo->mtype) != 0) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1235 | mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_MOD"); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1236 | return; |
| 1237 | } |
| 1238 | |
| 1239 | message.message.asndata = (unsigned char *)peerInfo->asnData; |
| 1240 | message.message.asnLength = peerInfo->asnLength; |
| 1241 | message.message.messageType = peerInfo->mtype; |
| 1242 | memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName)); |
| 1243 | num_of_messages.fetch_add(1, std::memory_order_release); |
| 1244 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1245 | mdclog_write(MDCLOG_DEBUG, "send the delayed SETUP/ENDC SETUP to sctp for %s", |
| 1246 | message.message.enodbName); |
| 1247 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1248 | if (sendSctpMsg(peerInfo, message, params->sctpMap) != 0) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1249 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1250 | mdclog_write(MDCLOG_DEBUG, "Error write to SCTP %s %d", __func__, __LINE__); |
| 1251 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1252 | return; |
| 1253 | } |
| 1254 | |
| 1255 | memset(peerInfo->asnData, 0, peerInfo->asnLength); |
| 1256 | peerInfo->asnLength = 0; |
| 1257 | peerInfo->mtype = 0; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1258 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | |
| 1262 | void handlepoll_error(struct epoll_event &event, |
| 1263 | ReportingMessages_t &message, |
| 1264 | RmrMessagesBuffer_t &rmrMessageBuffer, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1265 | sctp_params_t *params) { |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1266 | if ((event.data.fd != params->rmrListenFd) && (event.data.ptr != nullptr)) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1267 | auto *peerInfo = (ConnectedCU_t *)event.data.ptr; |
| 1268 | mdclog_write(MDCLOG_ERR, "epoll error, events %0x on fd %d, RAN NAME : %s", |
| 1269 | event.events, peerInfo->fileDescriptor, peerInfo->enodbName); |
dhirajverma | 93b6d9c | 2021-07-10 00:49:13 -0400 | [diff] [blame] | 1270 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1271 | rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256, |
| 1272 | "%s|Failed SCTP Connection", |
| 1273 | peerInfo->enodbName); |
| 1274 | message.message.asndata = rmrMessageBuffer.sendMessage->payload; |
| 1275 | message.message.asnLength = rmrMessageBuffer.sendMessage->len; |
| 1276 | |
| 1277 | memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName)); |
| 1278 | message.message.direction = 'N'; |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1279 | if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1280 | mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP"); |
| 1281 | } |
dhirajverma | 31768a9 | 2021-05-06 12:38:49 +0530 | [diff] [blame] | 1282 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1283 | close(peerInfo->fileDescriptor); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1284 | //params->sctpMap->erase(peerInfo->enodbName); |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1285 | cleanHashEntry((ConnectedCU_t *) event.data.ptr, params->sctpMap); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1286 | } else { |
| 1287 | mdclog_write(MDCLOG_ERR, "epoll error, events %0x on RMR FD", event.events); |
| 1288 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1289 | } |
| 1290 | /** |
| 1291 | * |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1292 | * @param socket |
| 1293 | * @return |
| 1294 | */ |
| 1295 | int setSocketNoBlocking(int socket) { |
| 1296 | auto flags = fcntl(socket, F_GETFL, 0); |
| 1297 | |
| 1298 | if (flags == -1) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1299 | mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1300 | return -1; |
| 1301 | } |
| 1302 | |
| 1303 | flags = (unsigned) flags | (unsigned) O_NONBLOCK; |
| 1304 | if (fcntl(socket, F_SETFL, flags) == -1) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1305 | mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1306 | return -1; |
| 1307 | } |
| 1308 | |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
| 1312 | /** |
| 1313 | * |
| 1314 | * @param val |
| 1315 | * @param m |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1316 | */ |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1317 | void cleanHashEntry(ConnectedCU_t *val, Sctp_Map_t *m) { |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 1318 | if(val != nullptr) { |
| 1319 | char *dummy; |
| 1320 | auto port = (uint16_t) strtol(val->portNumber, &dummy, 10); |
| 1321 | char searchBuff[2048]{}; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1322 | |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 1323 | snprintf(searchBuff, sizeof searchBuff, "host:%s:%d", val->hostName, port); |
| 1324 | if(m->find(searchBuff)) { |
| 1325 | m->erase(searchBuff); |
| 1326 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1327 | |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 1328 | if(m->find(val->enodbName)) { |
| 1329 | mdclog_write(MDCLOG_DEBUG, "remove key enodbName = %s from %s at line %d", val->enodbName, __FUNCTION__, __LINE__); |
| 1330 | m->erase(val->enodbName); |
| 1331 | } |
dhirajverma | 31768a9 | 2021-05-06 12:38:49 +0530 | [diff] [blame] | 1332 | #ifndef UNIT_TEST |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 1333 | if(val) { |
| 1334 | free(val); |
| 1335 | val = nullptr; |
| 1336 | } |
dhirajverma | 31768a9 | 2021-05-06 12:38:49 +0530 | [diff] [blame] | 1337 | #endif |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1338 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | /** |
| 1342 | * |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1343 | * @param fd file descriptor |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1344 | * @param data the asn data to send |
| 1345 | * @param len length of the data |
| 1346 | * @param enodbName the enodbName as in the map for printing purpose |
| 1347 | * @param m map host information |
| 1348 | * @param mtype message number |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1349 | * @return 0 success, a negative number on fail |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1350 | */ |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1351 | int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_t *m) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1352 | auto loglevel = mdclog_level_get(); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1353 | #ifndef UNIT_TEST |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1354 | int fd = peerInfo->fileDescriptor; |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 1355 | int streamId = fetchStreamId(peerInfo,message); |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 1356 | #else |
| 1357 | int fd = FILE_DESCRIPTOR; |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 1358 | int streamId = 0; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1359 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1360 | if (loglevel >= MDCLOG_DEBUG) { |
| 1361 | mdclog_write(MDCLOG_DEBUG, "Send SCTP message for CU %s, %s", |
| 1362 | message.message.enodbName, __FUNCTION__); |
| 1363 | } |
| 1364 | |
| 1365 | while (true) { |
czichy | 6dd00bc | 2023-03-03 15:43:29 +0200 | [diff] [blame] | 1366 | if (sctp_sendmsg(fd,message.message.asndata, message.message.asnLength,(struct sockaddr *) NULL, 0, htonl(E2AP_PPID), 0,streamId,0,0) < 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1367 | if (errno == EINTR) { |
| 1368 | continue; |
| 1369 | } |
| 1370 | mdclog_write(MDCLOG_ERR, "error writing to CU a message, %s ", strerror(errno)); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1371 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1372 | if (!peerInfo->isConnected) { |
| 1373 | mdclog_write(MDCLOG_ERR, "connection to CU %s is still in progress.", message.message.enodbName); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1374 | return -1; |
| 1375 | } |
dhirajverma | 93b6d9c | 2021-07-10 00:49:13 -0400 | [diff] [blame] | 1376 | #endif |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1377 | #ifndef UNIT_TEST |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1378 | cleanHashEntry(peerInfo, m); |
dhirajverma | c40ea1f | 2021-07-08 12:52:30 -0400 | [diff] [blame] | 1379 | close(fd); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1380 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1381 | char key[MAX_ENODB_NAME_SIZE * 2]; |
| 1382 | snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName, |
| 1383 | message.message.messageType); |
| 1384 | if (loglevel >= MDCLOG_DEBUG) { |
| 1385 | mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__); |
| 1386 | } |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 1387 | auto tmp = m->find(key); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1388 | if (tmp) { |
| 1389 | free(tmp); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1390 | tmp = nullptr; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1391 | } |
| 1392 | m->erase(key); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 1393 | #ifndef UNIT_TEST |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1394 | return -1; |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 1395 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1396 | } |
| 1397 | message.message.direction = 'D'; |
| 1398 | // send report.buffer of size |
| 1399 | buildJsonMessage(message); |
| 1400 | |
| 1401 | if (loglevel >= MDCLOG_DEBUG) { |
| 1402 | mdclog_write(MDCLOG_DEBUG, |
| 1403 | "SCTP message for CU %s sent from %s", |
| 1404 | message.message.enodbName, |
| 1405 | __FUNCTION__); |
| 1406 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1407 | return 0; |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | /** |
| 1412 | * |
| 1413 | * @param message |
| 1414 | * @param rmrMessageBuffer |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1415 | */ |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1416 | void getRequestMetaData(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1417 | message.message.asndata = rmrMessageBuffer.rcvMessage->payload; |
| 1418 | message.message.asnLength = rmrMessageBuffer.rcvMessage->len; |
| 1419 | |
| 1420 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1421 | mdclog_write(MDCLOG_DEBUG, "Message from Xapp RAN name = %s message length = %ld", |
| 1422 | message.message.enodbName, (unsigned long) message.message.asnLength); |
| 1423 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1427 | |
| 1428 | /** |
| 1429 | * |
| 1430 | * @param events |
| 1431 | * @param sctpMap |
| 1432 | * @param numOfMessages |
| 1433 | * @param rmrMessageBuffer |
| 1434 | * @param ts |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1435 | * @return |
| 1436 | */ |
| 1437 | int receiveDataFromSctp(struct epoll_event *events, |
| 1438 | Sctp_Map_t *sctpMap, |
| 1439 | int &numOfMessages, |
| 1440 | RmrMessagesBuffer_t &rmrMessageBuffer, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1441 | struct timespec &ts) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1442 | /* We have data on the fd waiting to be read. Read and display it. |
| 1443 | * We must read whatever data is available completely, as we are running |
| 1444 | * in edge-triggered mode and won't get a notification again for the same data. */ |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1445 | ReportingMessages_t message {}; |
| 1446 | auto done = 0; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1447 | auto loglevel = mdclog_level_get(); |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 1448 | struct sctp_sndrcvinfo sndrcvinfo; |
| 1449 | int flags; |
| 1450 | int streamId; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1451 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1452 | // get the identity of the interface |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1453 | if (events->data.ptr != nullptr){ |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 1454 | message.peerInfo = (ConnectedCU_t *)events->data.ptr; |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1455 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1456 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1457 | struct timespec start{0, 0}; |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1458 | struct timespec decodeStart{0, 0}; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1459 | struct timespec end{0, 0}; |
| 1460 | |
| 1461 | E2AP_PDU_t *pdu = nullptr; |
| 1462 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1463 | while (true) { |
| 1464 | if (loglevel >= MDCLOG_DEBUG) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1465 | mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP %d fd", message.peerInfo->fileDescriptor); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1466 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 1467 | } |
| 1468 | // read the buffer directly to rmr payload |
| 1469 | message.message.asndata = rmrMessageBuffer.sendMessage->payload; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1470 | #ifndef UNIT_TEST |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1471 | message.message.asnLength = rmrMessageBuffer.sendMessage->len = |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 1472 | sctp_recvmsg(message.peerInfo->fileDescriptor, rmrMessageBuffer.sendMessage->payload, RECEIVE_SCTP_BUFFER_SIZE,(struct sockaddr *) NULL, 0, &sndrcvinfo, &flags); |
| 1473 | mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP fd %d stream %d ", message.peerInfo->fileDescriptor, sndrcvinfo.sinfo_stream); |
| 1474 | streamId = sndrcvinfo.sinfo_stream; |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 1475 | #else |
| 1476 | message.message.asnLength = rmrMessageBuffer.sendMessage->len; |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 1477 | streamId = 0; |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 1478 | #endif |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1479 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1480 | if (loglevel >= MDCLOG_DEBUG) { |
| 1481 | mdclog_write(MDCLOG_DEBUG, "Finish Read from SCTP %d fd message length = %ld", |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 1482 | message.peerInfo->fileDescriptor, message.message.asnLength); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1483 | } |
aa7133@att.com | 16c799b | 2020-03-24 18:01:51 +0200 | [diff] [blame] | 1484 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1485 | memcpy(message.message.enodbName, message.peerInfo->enodbName, sizeof(message.peerInfo->enodbName)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1486 | message.message.direction = 'U'; |
| 1487 | message.message.time.tv_nsec = ts.tv_nsec; |
| 1488 | message.message.time.tv_sec = ts.tv_sec; |
| 1489 | |
| 1490 | if (message.message.asnLength < 0) { |
| 1491 | if (errno == EINTR) { |
| 1492 | continue; |
| 1493 | } |
| 1494 | /* If errno == EAGAIN, that means we have read all |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1495 | data. So goReportingMessages_t back to the main loop. */ |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1496 | if (errno != EAGAIN) { |
| 1497 | mdclog_write(MDCLOG_ERR, "Read error, %s ", strerror(errno)); |
| 1498 | done = 1; |
| 1499 | } else if (loglevel >= MDCLOG_DEBUG) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1500 | mdclog_write(MDCLOG_DEBUG, "EAGAIN - descriptor = %d", message.peerInfo->fileDescriptor); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1501 | } |
| 1502 | break; |
| 1503 | } else if (message.message.asnLength == 0) { |
| 1504 | /* End of file. The remote has closed the connection. */ |
| 1505 | if (loglevel >= MDCLOG_INFO) { |
| 1506 | mdclog_write(MDCLOG_INFO, "END of File Closed connection - descriptor = %d", |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1507 | message.peerInfo->fileDescriptor); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1508 | } |
| 1509 | done = 1; |
| 1510 | break; |
| 1511 | } |
| 1512 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1513 | if (loglevel >= MDCLOG_DEBUG) { |
swc | 58d4f5d | 2020-10-20 15:08:38 +0900 | [diff] [blame] | 1514 | char printBuffer[RECEIVE_SCTP_BUFFER_SIZE]{}; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1515 | char *tmp = printBuffer; |
| 1516 | for (size_t i = 0; i < (size_t)message.message.asnLength; ++i) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1517 | snprintf(tmp, 3, "%02x", message.message.asndata[i]); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1518 | tmp += 2; |
| 1519 | } |
| 1520 | printBuffer[message.message.asnLength] = 0; |
| 1521 | clock_gettime(CLOCK_MONOTONIC, &end); |
| 1522 | mdclog_write(MDCLOG_DEBUG, "Before Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds", |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1523 | message.peerInfo->enodbName, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1524 | mdclog_write(MDCLOG_DEBUG, "PDU buffer length = %ld, data = : %s", message.message.asnLength, |
| 1525 | printBuffer); |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1526 | clock_gettime(CLOCK_MONOTONIC, &decodeStart); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1527 | } |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 1528 | #ifndef UNIT_TEST |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1529 | auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu, |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 1530 | message.message.asndata, message.message.asnLength); |
| 1531 | #else |
| 1532 | asn_dec_rval_t rval = {RC_OK, 0}; |
| 1533 | pdu = (E2AP_PDU_t*)rmrMessageBuffer.sendMessage->tp_buf; |
| 1534 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1535 | if (rval.code != RC_OK) { |
| 1536 | mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from RAN : %s", rval.code, |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1537 | message.peerInfo->enodbName); |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 1538 | if (pdu != nullptr) { |
| 1539 | ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 1540 | pdu = nullptr; |
| 1541 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1542 | break; |
| 1543 | } |
| 1544 | |
| 1545 | if (loglevel >= MDCLOG_DEBUG) { |
| 1546 | clock_gettime(CLOCK_MONOTONIC, &end); |
| 1547 | mdclog_write(MDCLOG_DEBUG, "After Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds", |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1548 | message.peerInfo->enodbName, end.tv_sec - decodeStart.tv_sec, end.tv_nsec - decodeStart.tv_nsec); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1549 | char *printBuffer; |
| 1550 | size_t size; |
| 1551 | FILE *stream = open_memstream(&printBuffer, &size); |
| 1552 | asn_fprint(stream, &asn_DEF_E2AP_PDU, pdu); |
| 1553 | mdclog_write(MDCLOG_DEBUG, "Encoding E2AP PDU past : %s", printBuffer); |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1554 | clock_gettime(CLOCK_MONOTONIC, &decodeStart); |
Byonggon Chun | cae9bd5 | 2020-11-18 13:37:29 +0900 | [diff] [blame] | 1555 | |
| 1556 | fclose(stream); |
| 1557 | free(printBuffer); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | switch (pdu->present) { |
| 1561 | case E2AP_PDU_PR_initiatingMessage: {//initiating message |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 1562 | asnInitiatingRequest(pdu, sctpMap,message, rmrMessageBuffer, streamId); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1563 | break; |
| 1564 | } |
| 1565 | case E2AP_PDU_PR_successfulOutcome: { //successful outcome |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1566 | asnSuccessfulMsg(pdu, sctpMap, message, rmrMessageBuffer); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1567 | break; |
| 1568 | } |
| 1569 | case E2AP_PDU_PR_unsuccessfulOutcome: { //Unsuccessful Outcome |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1570 | asnUnSuccsesfulMsg(pdu, sctpMap, message, rmrMessageBuffer); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1571 | break; |
| 1572 | } |
| 1573 | default: |
| 1574 | mdclog_write(MDCLOG_ERR, "Unknown index %d in E2AP PDU", pdu->present); |
| 1575 | break; |
| 1576 | } |
| 1577 | if (loglevel >= MDCLOG_DEBUG) { |
| 1578 | clock_gettime(CLOCK_MONOTONIC, &end); |
| 1579 | mdclog_write(MDCLOG_DEBUG, |
| 1580 | "After processing message and sent to rmr for : %s, Read time is : %ld seconds, %ld nanoseconds", |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1581 | message.peerInfo->enodbName, end.tv_sec - decodeStart.tv_sec, end.tv_nsec - decodeStart.tv_nsec); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1582 | } |
| 1583 | numOfMessages++; |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 1584 | #ifndef UNIT_TEST |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1585 | if (pdu != nullptr) { |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 1586 | // ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); /* With reset we were not freeing the memory and was causing the leak here. */ |
| 1587 | ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 1588 | pdu = nullptr; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1589 | } |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 1590 | #else |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 1591 | done = 1; |
| 1592 | break; |
| 1593 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1594 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1595 | |
| 1596 | if (done) { |
| 1597 | if (loglevel >= MDCLOG_INFO) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1598 | mdclog_write(MDCLOG_INFO, "Closed connection - descriptor = %d", message.peerInfo->fileDescriptor); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1599 | } |
| 1600 | message.message.asnLength = rmrMessageBuffer.sendMessage->len = |
| 1601 | snprintf((char *)rmrMessageBuffer.sendMessage->payload, |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 1602 | 256, |
| 1603 | "%s|CU disconnected unexpectedly", |
| 1604 | message.peerInfo->enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1605 | message.message.asndata = rmrMessageBuffer.sendMessage->payload; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1606 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1607 | if (sendRequestToXapp(message, |
| 1608 | RIC_SCTP_CONNECTION_FAILURE, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1609 | rmrMessageBuffer) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1610 | mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP"); |
| 1611 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1612 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1613 | |
| 1614 | /* Closing descriptor make epoll remove it from the set of descriptors which are monitored. */ |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1615 | #ifndef UNIT_TEST |
| 1616 | pthread_mutex_lock(&thread_lock); |
| 1617 | if (fcntl(message.peerInfo->fileDescriptor, F_GETFD) != -1) { |
| 1618 | mdclog_write(MDCLOG_DEBUG, "Closing connection - descriptor = %d", message.peerInfo->fileDescriptor); |
| 1619 | close(message.peerInfo->fileDescriptor); |
| 1620 | cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap); |
| 1621 | } |
| 1622 | pthread_mutex_unlock(&thread_lock); |
| 1623 | #else |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1624 | close(message.peerInfo->fileDescriptor); |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1625 | cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1626 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1627 | } |
| 1628 | if (loglevel >= MDCLOG_DEBUG) { |
| 1629 | clock_gettime(CLOCK_MONOTONIC, &end); |
| 1630 | mdclog_write(MDCLOG_DEBUG, "from receive SCTP to send RMR time is %ld seconds and %ld nanoseconds", |
| 1631 | end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec); |
| 1632 | |
| 1633 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1634 | return 0; |
| 1635 | } |
| 1636 | |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1637 | static void buildAndSendSetupRequest(ReportingMessages_t &message, |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1638 | RmrMessagesBuffer_t &rmrMessageBuffer, |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 1639 | E2AP_PDU_t *pdu/*, |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1640 | string const &messageName, |
| 1641 | string const &ieName, |
| 1642 | vector<string> &functionsToAdd_v, |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 1643 | vector<string> &functionsToModified_v*/) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1644 | auto logLevel = mdclog_level_get(); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1645 | // now we can send the data to e2Mgr |
aa7133@att.com | 0829b8b | 2020-04-16 19:27:42 +0300 | [diff] [blame] | 1646 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1647 | asn_enc_rval_t er; |
| 1648 | auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; |
Byonggon Chun | 51885f3 | 2020-11-18 15:31:04 +0900 | [diff] [blame] | 1649 | unsigned char *buffer = nullptr; |
| 1650 | buffer = (unsigned char *) calloc(buffer_size, sizeof(unsigned char)); |
| 1651 | if(!buffer) |
| 1652 | { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1653 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
Byonggon Chun | 51885f3 | 2020-11-18 15:31:04 +0900 | [diff] [blame] | 1654 | mdclog_write(MDCLOG_ERR, "Allocating buffer for %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); |
| 1655 | return; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1656 | #endif |
Byonggon Chun | 51885f3 | 2020-11-18 15:31:04 +0900 | [diff] [blame] | 1657 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1658 | while (true) { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1659 | er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size); |
| 1660 | if (er.encoded == -1) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1661 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1662 | mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); |
| 1663 | return; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1664 | #endif |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1665 | } else if (er.encoded > (ssize_t) buffer_size) { |
| 1666 | buffer_size = er.encoded + 128; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1667 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1668 | mdclog_write(MDCLOG_WARN, "Buffer of size %d is to small for %s. Reallocate buffer of size %d", |
| 1669 | (int) buffer_size, |
| 1670 | asn_DEF_E2AP_PDU.name, buffer_size); |
| 1671 | buffer_size = er.encoded + 128; |
Byonggon Chun | 51885f3 | 2020-11-18 15:31:04 +0900 | [diff] [blame] | 1672 | |
| 1673 | unsigned char *newBuffer = nullptr; |
| 1674 | newBuffer = (unsigned char *) realloc(buffer, buffer_size); |
| 1675 | if (!newBuffer) |
| 1676 | { |
| 1677 | // out of memory |
| 1678 | mdclog_write(MDCLOG_ERR, "Reallocating buffer for %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); |
| 1679 | free(buffer); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1680 | buffer = nullptr; |
Byonggon Chun | 51885f3 | 2020-11-18 15:31:04 +0900 | [diff] [blame] | 1681 | return; |
| 1682 | } |
| 1683 | buffer = newBuffer; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1684 | continue; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 1685 | #endif |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1686 | } |
| 1687 | buffer[er.encoded] = '\0'; |
| 1688 | break; |
| 1689 | } |
| 1690 | // encode to xml |
| 1691 | |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 1692 | string res((char *)buffer); |
| 1693 | res.erase(std::remove(res.begin(), res.end(), '\n'), res.end()); |
| 1694 | res.erase(std::remove(res.begin(), res.end(), '\t'), res.end()); |
| 1695 | res.erase(std::remove(res.begin(), res.end(), ' '), res.end()); |
| 1696 | |
| 1697 | // string res {}; |
| 1698 | // if (!functionsToAdd_v.empty() || !functionsToModified_v.empty()) { |
| 1699 | // res = buildXmlData(messageName, ieName, functionsToAdd_v, functionsToModified_v, buffer, (size_t) er.encoded); |
| 1700 | // } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1701 | rmr_mbuf_t *rmrMsg; |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 1702 | // if (res.length() == 0) { |
| 1703 | // rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size + 256); |
| 1704 | // rmrMsg->len = snprintf((char *) rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s", |
| 1705 | // message.peerInfo->sctpParams->myIP.c_str(), |
| 1706 | // message.peerInfo->sctpParams->rmrPort, |
| 1707 | // buffer); |
| 1708 | // } else { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1709 | rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, (int)res.length() + 256); |
| 1710 | rmrMsg->len = snprintf((char *) rmrMsg->payload, res.length() + 256, "%s:%d|%s", |
| 1711 | message.peerInfo->sctpParams->myIP.c_str(), |
| 1712 | message.peerInfo->sctpParams->rmrPort, |
| 1713 | res.c_str()); |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 1714 | // } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1715 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1716 | if (logLevel >= MDCLOG_DEBUG) { |
| 1717 | mdclog_write(MDCLOG_DEBUG, "Setup request of size %d :\n %s\n", rmrMsg->len, rmrMsg->payload); |
| 1718 | } |
| 1719 | // send to RMR |
| 1720 | rmrMsg->mtype = message.message.messageType; |
| 1721 | rmrMsg->state = 0; |
| 1722 | rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName)); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1723 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1724 | static unsigned char tx[32]; |
| 1725 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 1726 | rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx)); |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 1727 | #ifndef UNIT_TEST |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1728 | rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg); |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 1729 | #endif |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1730 | if (rmrMsg == nullptr) { |
| 1731 | mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr"); |
| 1732 | } else if (rmrMsg->state != 0) { |
| 1733 | char meid[RMR_MAX_MEID]{}; |
| 1734 | if (rmrMsg->state == RMR_ERR_RETRY) { |
| 1735 | usleep(5); |
| 1736 | rmrMsg->state = 0; |
| 1737 | mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s", |
| 1738 | rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid)); |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 1739 | #ifndef UNIT_TEST |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1740 | rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg); |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 1741 | #endif |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1742 | if (rmrMsg == nullptr) { |
| 1743 | mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr"); |
| 1744 | } else if (rmrMsg->state != 0) { |
| 1745 | mdclog_write(MDCLOG_ERR, |
| 1746 | "RMR Retry failed %s sending request %d to Xapp from %s", |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1747 | translateRmrErrorMessages(rmrMsg->state).c_str(), |
| 1748 | rmrMsg->mtype, |
| 1749 | rmr_get_meid(rmrMsg, (unsigned char *) meid)); |
| 1750 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1751 | } else { |
| 1752 | mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s", |
| 1753 | translateRmrErrorMessages(rmrMsg->state).c_str(), |
| 1754 | rmrMsg->mtype, |
| 1755 | rmr_get_meid(rmrMsg, (unsigned char *) meid)); |
aa7133@att.com | bc11077 | 2020-03-25 09:45:14 +0200 | [diff] [blame] | 1756 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1757 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1758 | message.peerInfo->gotSetup = true; |
| 1759 | buildJsonMessage(message); |
Byonggon Chun | 51885f3 | 2020-11-18 15:31:04 +0900 | [diff] [blame] | 1760 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1761 | if (rmrMsg != nullptr) { |
| 1762 | rmr_free_msg(rmrMsg); |
| 1763 | } |
Byonggon Chun | 51885f3 | 2020-11-18 15:31:04 +0900 | [diff] [blame] | 1764 | free(buffer); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 1765 | buffer = nullptr; |
Byonggon Chun | 51885f3 | 2020-11-18 15:31:04 +0900 | [diff] [blame] | 1766 | |
| 1767 | return; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1768 | } |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 1769 | |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 1770 | #if 0 |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 1771 | int RAN_Function_list_To_Vector(RANfunctions_List_t& list, vector <string> &runFunXML_v) { |
| 1772 | auto index = 0; |
| 1773 | runFunXML_v.clear(); |
| 1774 | for (auto j = 0; j < list.list.count; j++) { |
| 1775 | auto *raNfunctionItemIEs = (RANfunction_ItemIEs_t *)list.list.array[j]; |
| 1776 | if (raNfunctionItemIEs->id == ProtocolIE_ID_id_RANfunction_Item && |
| 1777 | (raNfunctionItemIEs->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item)) { |
| 1778 | // encode to xml |
| 1779 | E2SM_gNB_NRT_RANfunction_Definition_t *ranFunDef = nullptr; |
| 1780 | auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, |
| 1781 | &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, |
| 1782 | (void **)&ranFunDef, |
| 1783 | raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.buf, |
| 1784 | raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.size); |
| 1785 | if (rval.code != RC_OK) { |
| 1786 | mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2SM message from : %s", |
| 1787 | rval.code, |
| 1788 | asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name); |
| 1789 | return -1; |
| 1790 | } |
| 1791 | |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 1792 | auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; |
| 1793 | unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2]; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1794 | memset(xml_buffer, 0, RECEIVE_SCTP_BUFFER_SIZE * 2); |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 1795 | // encode to xml |
| 1796 | auto er = asn_encode_to_buffer(nullptr, |
| 1797 | ATS_BASIC_XER, |
| 1798 | &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, |
| 1799 | ranFunDef, |
| 1800 | xml_buffer, |
| 1801 | xml_buffer_size); |
| 1802 | if (er.encoded == -1) { |
| 1803 | mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", |
| 1804 | asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, |
| 1805 | strerror(errno)); |
| 1806 | } else if (er.encoded > (ssize_t)xml_buffer_size) { |
| 1807 | mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d", |
| 1808 | (int) xml_buffer_size, |
| 1809 | asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, __func__, __LINE__); |
| 1810 | } else { |
| 1811 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1812 | mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU number %d : %s", |
| 1813 | asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, |
| 1814 | index++, |
| 1815 | xml_buffer); |
| 1816 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1817 | |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 1818 | string runFuncs = (char *)(xml_buffer); |
| 1819 | runFunXML_v.emplace_back(runFuncs); |
| 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | return 0; |
| 1824 | } |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 1825 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1826 | int collectServiceUpdate_RequestData(E2AP_PDU_t *pdu, |
| 1827 | Sctp_Map_t *sctpMap, |
| 1828 | ReportingMessages_t &message, |
| 1829 | vector <string> &RANfunctionsAdded_v, |
| 1830 | vector <string> &RANfunctionsModified_v) { |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 1831 | memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1832 | for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.count; i++) { |
| 1833 | auto *ie = pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.array[i]; |
| 1834 | if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) { |
| 1835 | if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctionsID_List) { |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 1836 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 1837 | mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries", |
| 1838 | ie->value.choice.RANfunctions_List.list.count); |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 1839 | } |
aa7133@att.com | 0829b8b | 2020-04-16 19:27:42 +0300 | [diff] [blame] | 1840 | if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) { |
| 1841 | return -1; |
| 1842 | } |
| 1843 | } |
| 1844 | } else if (ie->id == ProtocolIE_ID_id_RANfunctionsModified) { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1845 | if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List) { |
aa7133@att.com | 0829b8b | 2020-04-16 19:27:42 +0300 | [diff] [blame] | 1846 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1847 | mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries", |
| 1848 | ie->value.choice.RANfunctions_List.list.count); |
| 1849 | } |
| 1850 | if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsModified_v) != 0 ) { |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 1851 | return -1; |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | } |
| 1855 | } |
| 1856 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1857 | mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries", |
aa7133@att.com | 0829b8b | 2020-04-16 19:27:42 +0300 | [diff] [blame] | 1858 | RANfunctionsAdded_v.size()); |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 1859 | } |
| 1860 | return 0; |
| 1861 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1862 | |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 1863 | #endif |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1864 | |
| 1865 | |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 1866 | void buildE2TPrometheusCounters(sctp_params_t &sctpParams) { |
| 1867 | sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestMsgs"}}); |
| 1868 | sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestBytes"}}); |
| 1869 | |
| 1870 | sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupResponseMsgs"}}); |
| 1871 | sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &sctpParams.prometheusFamily->Add({{"counter", "SetupResponseBytes"}}); |
| 1872 | |
| 1873 | sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestFailureMsgs"}}); |
| 1874 | sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup] = &sctpParams.prometheusFamily->Add({{"counter", "SetupRequestFailureBytes"}}); |
| 1875 | |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 1876 | sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateMsgs"}}); |
| 1877 | sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateBytes"}}); |
| 1878 | |
| 1879 | sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateResponseMsgs"}}); |
| 1880 | sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateResponseBytes"}}); |
| 1881 | |
| 1882 | sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateFailureMsgs"}}); |
| 1883 | sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "E2NodeConfigUpdateFailureBytes"}}); |
| 1884 | |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 1885 | sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &sctpParams.prometheusFamily->Add({{"counter", "ErrorIndicationMsgs"}}); |
| 1886 | sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &sctpParams.prometheusFamily->Add({{"counter", "ErrorIndicationBytes"}}); |
| 1887 | |
| 1888 | sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetRequestMsgs"}}); |
| 1889 | sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetRequestBytes"}}); |
| 1890 | |
| 1891 | sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetAckMsgs"}}); |
| 1892 | sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset] = &sctpParams.prometheusFamily->Add({{"counter", "ResetAckBytes"}}); |
| 1893 | |
| 1894 | sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateMsgs"}}); |
| 1895 | sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateBytes"}}); |
| 1896 | |
| 1897 | sctpParams.e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateRespMsgs"}}); |
| 1898 | sctpParams.e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateRespBytes"}}); |
| 1899 | |
| 1900 | sctpParams.e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateFailureMsgs"}}); |
| 1901 | sctpParams.e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceUpdateFailureBytes"}}); |
| 1902 | |
| 1903 | sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlMsgs"}}); |
| 1904 | sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlBytes"}}); |
| 1905 | |
| 1906 | sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlAckMsgs"}}); |
| 1907 | sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlAckBytes"}}); |
| 1908 | |
| 1909 | sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlFailureMsgs"}}); |
| 1910 | sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol] = &sctpParams.prometheusFamily->Add({{"counter", "RICControlFailureBytes"}}); |
| 1911 | |
| 1912 | sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionMsgs"}}); |
| 1913 | sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionBytes"}}); |
| 1914 | |
| 1915 | sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionAckMsgs"}}); |
| 1916 | sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionAckBytes"}}); |
| 1917 | |
| 1918 | sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionFailureMsgs"}}); |
| 1919 | sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionFailureBytes"}}); |
| 1920 | |
| 1921 | sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteMsgs"}}); |
| 1922 | sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteBytes"}}); |
| 1923 | |
| 1924 | sctpParams.e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteAckMsgs"}}); |
| 1925 | sctpParams.e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteAckBytes"}}); |
| 1926 | |
| 1927 | sctpParams.e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteFailMsgs"}}); |
| 1928 | sctpParams.e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteFailBytes"}}); |
| 1929 | |
| 1930 | sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication] = &sctpParams.prometheusFamily->Add({{"counter", "RICIndicationMsgs"}}); |
| 1931 | sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication] = &sctpParams.prometheusFamily->Add({{"counter", "RICIndicationBytes"}}); |
| 1932 | |
| 1933 | sctpParams.e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceQueryMsgs"}}); |
| 1934 | sctpParams.e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery] = &sctpParams.prometheusFamily->Add({{"counter", "RICServiceQueryBytes"}}); |
gunjarastogi | 85f507f | 2023-01-18 16:27:55 +0530 | [diff] [blame] | 1935 | |
| 1936 | sctpParams.e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteRequiredMsgs"}}); |
| 1937 | sctpParams.e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired] = &sctpParams.prometheusFamily->Add({{"counter", "RICSubscriptionDeleteRequiredBytes"}}); |
| 1938 | |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 1941 | void buildPrometheusList(ConnectedCU_t *peerInfo, Family<Counter> *prometheusFamily) { |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1942 | peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Messages"}}); |
| 1943 | peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1944 | |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 1945 | peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"E2NodeConfigUpdate", "Messages"}}); |
| 1946 | peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"E2NodeConfigUpdate", "Bytes"}}); |
| 1947 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1948 | peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Messages"}}); |
| 1949 | peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1950 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1951 | peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICindication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Messages"}}); |
| 1952 | peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICindication)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1953 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1954 | peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Messages"}}); |
| 1955 | peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1956 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1957 | peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Messages"}}); |
| 1958 | peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1959 | // --------------------------------------------- |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1960 | peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Messages"}}); |
| 1961 | peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1962 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1963 | peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Messages"}}); |
| 1964 | peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1965 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1966 | peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Messages"}}); |
| 1967 | peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1968 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1969 | peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Messages"}}); |
| 1970 | peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1971 | //------------------------------------------------------------- |
| 1972 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1973 | peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Messages"}}); |
| 1974 | peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1975 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1976 | peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Messages"}}); |
| 1977 | peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1978 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1979 | peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Messages"}}); |
| 1980 | peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1981 | |
| 1982 | //==================================================================================== |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1983 | peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Messages"}}); |
| 1984 | peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1985 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1986 | peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Messages"}}); |
| 1987 | peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1988 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1989 | peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Messages"}}); |
| 1990 | peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICcontrol)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1991 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1992 | peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceQuery)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Messages"}}); |
| 1993 | peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceQuery)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1994 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1995 | peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Messages"}}); |
| 1996 | peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscription)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 1997 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 1998 | peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Messages"}}); |
| 1999 | peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2000 | //--------------------------------------------------------------------------------------------------------- |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2001 | peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Messages"}}); |
| 2002 | peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2003 | |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 2004 | peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateSuccess", "Messages"}}); |
| 2005 | peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateSuccess", "Bytes"}}); |
| 2006 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2007 | peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Messages"}}); |
| 2008 | peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2009 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2010 | peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Messages"}}); |
| 2011 | peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2012 | //---------------------------------------------------------------------------------------------------------------- |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2013 | peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Messages"}}); |
| 2014 | peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Bytes"}}); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2015 | |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 2016 | peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateFailure", "Messages"}}); |
| 2017 | peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2nodeConfigurationUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"E2NodeConfigUpdateFailure", "Bytes"}}); |
| 2018 | |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2019 | peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Messages"}}); |
| 2020 | peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Bytes"}}); |
gunjarastogi | 85f507f | 2023-01-18 16:27:55 +0530 | [diff] [blame] | 2021 | |
| 2022 | |
| 2023 | peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDeleteRequired)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteRequired", "Messages"}}); |
| 2024 | peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDeleteRequired)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteRequired", "Bytes"}}); |
| 2025 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2026 | } |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2027 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2028 | /** |
| 2029 | * |
| 2030 | * @param pdu |
| 2031 | * @param sctpMap |
| 2032 | * @param message |
| 2033 | * @param RANfunctionsAdded_v |
| 2034 | * @return |
| 2035 | */ |
| 2036 | int collectSetupRequestData(E2AP_PDU_t *pdu, |
| 2037 | Sctp_Map_t *sctpMap, |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 2038 | ReportingMessages_t &message /*, vector <string> &RANfunctionsAdded_v*/) { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2039 | memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE); |
| 2040 | for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) { |
| 2041 | auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i]; |
| 2042 | if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) { |
| 2043 | // get the ran name for meid |
| 2044 | if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) { |
| 2045 | if (buildRanName(message.peerInfo->enodbName, ie) < 0) { |
| 2046 | mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n"); |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2047 | // no message will be sent |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2048 | return -1; |
| 2049 | } |
| 2050 | |
| 2051 | memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName)); |
| 2052 | sctpMap->setkey(message.message.enodbName, message.peerInfo); |
| 2053 | } |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 2054 | } /*else if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2055 | if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) { |
| 2056 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2057 | mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries", |
| 2058 | ie->value.choice.RANfunctions_List.list.count); |
| 2059 | } |
| 2060 | if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) { |
| 2061 | return -1; |
| 2062 | } |
| 2063 | } |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 2064 | } */ |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2065 | } |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 2066 | // if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2067 | // mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries", |
| 2068 | // RANfunctionsAdded_v.size()); |
| 2069 | // } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2070 | return 0; |
| 2071 | } |
| 2072 | |
| 2073 | int XML_From_PER(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) { |
| 2074 | E2AP_PDU_t *pdu = nullptr; |
| 2075 | |
| 2076 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2077 | mdclog_write(MDCLOG_DEBUG, "got PER message of size %d is:%s", |
| 2078 | rmrMessageBuffer.sendMessage->len, rmrMessageBuffer.sendMessage->payload); |
| 2079 | } |
| 2080 | auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu, |
| 2081 | rmrMessageBuffer.sendMessage->payload, rmrMessageBuffer.sendMessage->len); |
| 2082 | if (rval.code != RC_OK) { |
| 2083 | mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s", |
| 2084 | rval.code, |
| 2085 | message.message.enodbName); |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 2086 | if (pdu != nullptr) { |
| 2087 | ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 2088 | pdu = nullptr; |
| 2089 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2090 | return -1; |
| 2091 | } |
| 2092 | |
| 2093 | int buff_size = RECEIVE_XAPP_BUFFER_SIZE; |
| 2094 | auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, |
| 2095 | rmrMessageBuffer.sendMessage->payload, buff_size); |
| 2096 | if (er.encoded == -1) { |
| 2097 | mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 2098 | if (pdu != nullptr) { |
| 2099 | ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 2100 | pdu = nullptr; |
| 2101 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2102 | return -1; |
| 2103 | } else if (er.encoded > (ssize_t)buff_size) { |
| 2104 | mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d", |
| 2105 | (int)rmrMessageBuffer.sendMessage->len, |
| 2106 | asn_DEF_E2AP_PDU.name, |
| 2107 | __func__, |
| 2108 | __LINE__); |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 2109 | if (pdu != nullptr) { |
| 2110 | ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 2111 | pdu = nullptr; |
| 2112 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2113 | return -1; |
| 2114 | } |
| 2115 | rmrMessageBuffer.sendMessage->len = er.encoded; |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 2116 | if (pdu != nullptr) { |
| 2117 | ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 2118 | pdu = nullptr; |
| 2119 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2120 | return 0; |
| 2121 | |
| 2122 | } |
| 2123 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2124 | /** |
| 2125 | * |
| 2126 | * @param pdu |
| 2127 | * @param message |
| 2128 | * @param rmrMessageBuffer |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2129 | */ |
| 2130 | void asnInitiatingRequest(E2AP_PDU_t *pdu, |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 2131 | Sctp_Map_t *sctpMap, |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2132 | ReportingMessages_t &message, |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 2133 | RmrMessagesBuffer_t &rmrMessageBuffer, int streamId) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2134 | auto logLevel = mdclog_level_get(); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2135 | auto procedureCode = ((InitiatingMessage_t *) pdu->choice.initiatingMessage)->procedureCode; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2136 | if (logLevel >= MDCLOG_DEBUG) { |
| 2137 | mdclog_write(MDCLOG_DEBUG, "Initiating message %ld\n", procedureCode); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2138 | } |
| 2139 | switch (procedureCode) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2140 | case ProcedureCode_id_E2setup: { |
| 2141 | if (logLevel >= MDCLOG_DEBUG) { |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2142 | mdclog_write(MDCLOG_DEBUG, "Got E2setup"); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2143 | } |
| 2144 | |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 2145 | // vector <string> RANfunctionsAdded_v; |
| 2146 | // vector <string> RANfunctionsModified_v; |
| 2147 | // RANfunctionsAdded_v.clear(); |
| 2148 | // RANfunctionsModified_v.clear(); |
| 2149 | if (collectSetupRequestData(pdu, sctpMap, message) != 0) { |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 2150 | break; |
| 2151 | } |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 2152 | struct sctp_status status; |
| 2153 | int stat_size = sizeof(status); |
| 2154 | getsockopt( message.peerInfo->fileDescriptor, SOL_SCTP, SCTP_STATUS,(void *)&status, (socklen_t *)&stat_size ); |
| 2155 | if (logLevel >= MDCLOG_DEBUG) { |
| 2156 | mdclog_write(MDCLOG_DEBUG, "Start from SCTP %d fd", message.peerInfo->fileDescriptor); |
| 2157 | mdclog_write(MDCLOG_DEBUG, "SCTP status assoc id %d instrms %d outstrms %d", status.sstat_assoc_id, |
| 2158 | status.sstat_instrms, status.sstat_outstrms); |
| 2159 | } |
| 2160 | if(status.sstat_outstrms == 1 || status.sstat_instrms == 1) |
| 2161 | { |
| 2162 | message.peerInfo->isSingleStream = true; |
| 2163 | message.peerInfo->singleStreamId = streamId; |
| 2164 | if (status.sstat_outstrms == 1 && status.sstat_instrms == 1){ |
| 2165 | if (logLevel >= MDCLOG_DEBUG) { |
| 2166 | mdclog_write(MDCLOG_DEBUG, "Single SCTP stream is used for sending from now on, assoc id %d streamId %d #instrms %d #outstrms %d, %s",status.sstat_assoc_id, streamId, status.sstat_instrms, status.sstat_outstrms, __FUNCTION__); |
| 2167 | } |
| 2168 | } |
| 2169 | else { |
| 2170 | mdclog_write(MDCLOG_ERR, "Single SCTP stream used for sending messages even if there is a mismatch in number of in & out streams, assoc id %d instrms %d outstrms %d", status.sstat_assoc_id, |
| 2171 | status.sstat_instrms, status.sstat_outstrms); |
| 2172 | } |
| 2173 | } |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 2174 | |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2175 | buildPrometheusList(message.peerInfo, message.peerInfo->sctpParams->prometheusFamily); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2176 | |
| 2177 | string messageName("E2setupRequest"); |
| 2178 | string ieName("E2setupRequestIEs"); |
| 2179 | message.message.messageType = RIC_E2_SETUP_REQ; |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2180 | message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment(); |
| 2181 | message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2182 | |
| 2183 | // Update E2T instance level metrics |
| 2184 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment(); |
| 2185 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment((double)message.message.asnLength); |
| 2186 | |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2187 | buildAndSendSetupRequest(message, rmrMessageBuffer, pdu); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2188 | break; |
| 2189 | } |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2190 | case ProcedureCode_id_RICserviceUpdate: { |
| 2191 | if (logLevel >= MDCLOG_DEBUG) { |
| 2192 | mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName); |
| 2193 | } |
aa7133@att.com | df4f182 | 2020-06-16 16:23:53 +0300 | [diff] [blame] | 2194 | // vector <string> RANfunctionsAdded_v; |
| 2195 | // vector <string> RANfunctionsModified_v; |
| 2196 | // RANfunctionsAdded_v.clear(); |
| 2197 | // RANfunctionsModified_v.clear(); |
| 2198 | // if (collectServiceUpdate_RequestData(pdu, sctpMap, message, |
| 2199 | // RANfunctionsAdded_v, RANfunctionsModified_v) != 0) { |
| 2200 | // break; |
| 2201 | // } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2202 | |
| 2203 | string messageName("RICserviceUpdate"); |
| 2204 | string ieName("RICserviceUpdateIEs"); |
| 2205 | message.message.messageType = RIC_SERVICE_UPDATE; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2206 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2207 | message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(); |
| 2208 | message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2209 | |
| 2210 | // Update E2T instance level metrics |
| 2211 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(); |
| 2212 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment((double)message.message.asnLength); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 2213 | #endif |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2214 | buildAndSendSetupRequest(message, rmrMessageBuffer, pdu); |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2215 | break; |
| 2216 | } |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 2217 | |
| 2218 | case ProcedureCode_id_E2nodeConfigurationUpdate: { |
| 2219 | if (logLevel >= MDCLOG_DEBUG) { |
| 2220 | mdclog_write(MDCLOG_DEBUG, "Got E2nodeConfigurationUpdate %s", message.message.enodbName); |
| 2221 | } |
| 2222 | |
| 2223 | string messageName("RICE2nodeConfigurationUpdate"); |
| 2224 | string ieName("RICE2nodeConfigurationUpdateIEs"); |
| 2225 | message.message.messageType = RIC_E2NODE_CONFIG_UPDATE; |
| 2226 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
| 2227 | message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(); |
| 2228 | message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment((double)message.message.asnLength); |
| 2229 | |
| 2230 | // Update E2T instance level metrics |
| 2231 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(); |
| 2232 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment((double)message.message.asnLength); |
| 2233 | #endif |
| 2234 | buildAndSendSetupRequest(message, rmrMessageBuffer, pdu); |
| 2235 | break; |
| 2236 | } |
| 2237 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2238 | case ProcedureCode_id_ErrorIndication: { |
| 2239 | if (logLevel >= MDCLOG_DEBUG) { |
| 2240 | mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName); |
| 2241 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2242 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2243 | message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(); |
| 2244 | message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2245 | |
| 2246 | // Update E2T instance level metrics |
| 2247 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(); |
| 2248 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment((double)message.message.asnLength); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 2249 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2250 | if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2251 | mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2252 | } |
| 2253 | break; |
| 2254 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2255 | case ProcedureCode_id_Reset: { |
| 2256 | if (logLevel >= MDCLOG_DEBUG) { |
| 2257 | mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2258 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2259 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2260 | message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment(); |
| 2261 | message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2262 | |
| 2263 | // Update E2T instance level metrics |
| 2264 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment(); |
| 2265 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 2266 | #endif |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2267 | if (XML_From_PER(message, rmrMessageBuffer) < 0) { |
| 2268 | break; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2269 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2270 | |
| 2271 | if (sendRequestToXapp(message, RIC_E2_RESET_REQ, rmrMessageBuffer) != 0) { |
| 2272 | mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_REQ message failed to send to xAPP"); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2273 | } |
| 2274 | break; |
| 2275 | } |
| 2276 | case ProcedureCode_id_RICindication: { |
| 2277 | if (logLevel >= MDCLOG_DEBUG) { |
| 2278 | mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName); |
| 2279 | } |
| 2280 | for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2281 | auto messageSent = false; |
| 2282 | RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i]; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2283 | if (logLevel >= MDCLOG_DEBUG) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2284 | mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); |
| 2285 | } |
| 2286 | if (ie->id == ProtocolIE_ID_id_RICrequestID) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2287 | if (logLevel >= MDCLOG_DEBUG) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2288 | mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); |
| 2289 | } |
| 2290 | if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) { |
| 2291 | static unsigned char tx[32]; |
| 2292 | message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION; |
| 2293 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 2294 | rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2295 | rmr_bytes2meid(rmrMessageBuffer.sendMessage, |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2296 | (unsigned char *)message.message.enodbName, |
| 2297 | strlen(message.message.enodbName)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2298 | rmrMessageBuffer.sendMessage->state = 0; |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 2299 | rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID; |
| 2300 | |
| 2301 | //ie->value.choice.RICrequestID.ricInstanceID; |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2302 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 2303 | mdclog_write(MDCLOG_DEBUG, "sub id = %d, mtype = %d, ric instance id %ld, requestor id = %ld", |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2304 | rmrMessageBuffer.sendMessage->sub_id, |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 2305 | rmrMessageBuffer.sendMessage->mtype, |
| 2306 | ie->value.choice.RICrequestID.ricInstanceID, |
| 2307 | ie->value.choice.RICrequestID.ricRequestorID); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2308 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2309 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2310 | message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication]->Increment(); |
| 2311 | message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2312 | |
| 2313 | // Update E2T instance level metrics |
| 2314 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICindication]->Increment(); |
| 2315 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICindication]->Increment((double)message.message.asnLength); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 2316 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2317 | sendRmrMessage(rmrMessageBuffer, message); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2318 | messageSent = true; |
| 2319 | } else { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2320 | mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2321 | } |
| 2322 | } |
| 2323 | if (messageSent) { |
| 2324 | break; |
| 2325 | } |
| 2326 | } |
| 2327 | break; |
| 2328 | } |
gunjarastogi | 85f507f | 2023-01-18 16:27:55 +0530 | [diff] [blame] | 2329 | case ProcedureCode_id_RICsubscriptionDeleteRequired: { |
| 2330 | if (logLevel >= MDCLOG_DEBUG) { |
| 2331 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDeleteRequired %s", message.message.enodbName); |
| 2332 | } |
| 2333 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 2334 | message.peerInfo->counters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment(); |
| 2335 | message.peerInfo->counters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment((double)message.message.asnLength); |
gunjarastogi | 85f507f | 2023-01-18 16:27:55 +0530 | [diff] [blame] | 2336 | |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 2337 | // Update E2T instance level metrics |
| 2338 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment(); |
| 2339 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDeleteRequired]->Increment((double)message.message.asnLength); |
gunjarastogi | 85f507f | 2023-01-18 16:27:55 +0530 | [diff] [blame] | 2340 | #endif |
| 2341 | if (sendRequestToXapp(message, RIC_SUB_DEL_REQUIRED, rmrMessageBuffer) != 0) { |
| 2342 | mdclog_write(MDCLOG_ERR, "Subscription Delete Required message failed to send to xAPP"); |
| 2343 | } |
| 2344 | break; |
| 2345 | } |
| 2346 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2347 | default: { |
| 2348 | mdclog_write(MDCLOG_ERR, "Undefined or not supported message = %ld", procedureCode); |
| 2349 | message.message.messageType = 0; // no RMR message type yet |
| 2350 | |
| 2351 | buildJsonMessage(message); |
| 2352 | |
| 2353 | break; |
| 2354 | } |
| 2355 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | /** |
| 2359 | * |
| 2360 | * @param pdu |
| 2361 | * @param message |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2362 | * @param rmrMessageBuffer |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2363 | */ |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2364 | void asnSuccessfulMsg(E2AP_PDU_t *pdu, |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 2365 | Sctp_Map_t *sctpMap, |
| 2366 | ReportingMessages_t &message, |
| 2367 | RmrMessagesBuffer_t &rmrMessageBuffer) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2368 | auto procedureCode = pdu->choice.successfulOutcome->procedureCode; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2369 | auto logLevel = mdclog_level_get(); |
| 2370 | if (logLevel >= MDCLOG_INFO) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2371 | mdclog_write(MDCLOG_INFO, "Successful Outcome %ld", procedureCode); |
| 2372 | } |
| 2373 | switch (procedureCode) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2374 | case ProcedureCode_id_Reset: { |
| 2375 | if (logLevel >= MDCLOG_DEBUG) { |
| 2376 | mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2377 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2378 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2379 | message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment(); |
| 2380 | message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2381 | |
| 2382 | // Update E2T instance level metrics |
| 2383 | message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment(); |
| 2384 | message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment((double)message.message.asnLength); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 2385 | #endif |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2386 | if (XML_From_PER(message, rmrMessageBuffer) < 0) { |
| 2387 | break; |
| 2388 | } |
| 2389 | if (sendRequestToXapp(message, RIC_E2_RESET_RESP, rmrMessageBuffer) != 0) { |
| 2390 | mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_RESP message failed to send to xAPP"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2391 | } |
| 2392 | break; |
| 2393 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2394 | case ProcedureCode_id_RICcontrol: { |
| 2395 | if (logLevel >= MDCLOG_DEBUG) { |
| 2396 | mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2397 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2398 | for (auto i = 0; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2399 | i < pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; i++) { |
| 2400 | auto messageSent = false; |
| 2401 | RICcontrolAcknowledge_IEs_t *ie = pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[i]; |
| 2402 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2403 | mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); |
| 2404 | } |
| 2405 | if (ie->id == ProtocolIE_ID_id_RICrequestID) { |
| 2406 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2407 | mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); |
| 2408 | } |
| 2409 | if (ie->value.present == RICcontrolAcknowledge_IEs__value_PR_RICrequestID) { |
| 2410 | message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_ACK; |
| 2411 | rmrMessageBuffer.sendMessage->state = 0; |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2412 | // rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; |
| 2413 | rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID; |
| 2414 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2415 | static unsigned char tx[32]; |
| 2416 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 2417 | rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2418 | rmr_bytes2meid(rmrMessageBuffer.sendMessage, |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2419 | (unsigned char *)message.message.enodbName, |
| 2420 | strlen(message.message.enodbName)); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2421 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2422 | message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment(); |
| 2423 | message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2424 | |
| 2425 | // Update E2T instance level metrics |
| 2426 | message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment(); |
| 2427 | message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 2428 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2429 | sendRmrMessage(rmrMessageBuffer, message); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2430 | messageSent = true; |
| 2431 | } else { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2432 | mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | if (messageSent) { |
| 2436 | break; |
| 2437 | } |
| 2438 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2439 | |
| 2440 | break; |
| 2441 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2442 | case ProcedureCode_id_RICsubscription: { |
| 2443 | if (logLevel >= MDCLOG_DEBUG) { |
| 2444 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName); |
| 2445 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2446 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2447 | message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment(); |
| 2448 | message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2449 | |
| 2450 | // Update E2T instance level metrics |
| 2451 | message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment(); |
| 2452 | message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 2453 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2454 | if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2455 | mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP"); |
| 2456 | } |
| 2457 | break; |
| 2458 | } |
| 2459 | case ProcedureCode_id_RICsubscriptionDelete: { |
| 2460 | if (logLevel >= MDCLOG_DEBUG) { |
| 2461 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName); |
| 2462 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2463 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2464 | message.peerInfo->counters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(); |
| 2465 | message.peerInfo->counters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2466 | |
| 2467 | // Update E2T instance level metrics |
| 2468 | message.peerInfo->sctpParams->e2tCounters[IN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(); |
| 2469 | message.peerInfo->sctpParams->e2tCounters[IN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 2470 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2471 | if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2472 | mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP"); |
| 2473 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2474 | break; |
| 2475 | } |
| 2476 | default: { |
| 2477 | mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode); |
| 2478 | message.message.messageType = 0; // no RMR message type yet |
| 2479 | buildJsonMessage(message); |
| 2480 | |
| 2481 | break; |
| 2482 | } |
| 2483 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | /** |
| 2487 | * |
| 2488 | * @param pdu |
| 2489 | * @param message |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2490 | * @param rmrMessageBuffer |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2491 | */ |
| 2492 | void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu, |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 2493 | Sctp_Map_t *sctpMap, |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2494 | ReportingMessages_t &message, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2495 | RmrMessagesBuffer_t &rmrMessageBuffer) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2496 | auto procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2497 | auto logLevel = mdclog_level_get(); |
| 2498 | if (logLevel >= MDCLOG_INFO) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2499 | mdclog_write(MDCLOG_INFO, "Unsuccessful Outcome %ld", procedureCode); |
| 2500 | } |
| 2501 | switch (procedureCode) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2502 | case ProcedureCode_id_RICcontrol: { |
| 2503 | if (logLevel >= MDCLOG_DEBUG) { |
| 2504 | mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2505 | } |
| 2506 | for (int i = 0; |
| 2507 | i < pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.count; i++) { |
| 2508 | auto messageSent = false; |
| 2509 | RICcontrolFailure_IEs_t *ie = pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.array[i]; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2510 | if (logLevel >= MDCLOG_DEBUG) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2511 | mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); |
| 2512 | } |
| 2513 | if (ie->id == ProtocolIE_ID_id_RICrequestID) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2514 | if (logLevel >= MDCLOG_DEBUG) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2515 | mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); |
| 2516 | } |
| 2517 | if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) { |
| 2518 | message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_FAILURE; |
| 2519 | rmrMessageBuffer.sendMessage->state = 0; |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2520 | // rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricRequestorID; |
| 2521 | rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2522 | static unsigned char tx[32]; |
| 2523 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 2524 | rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2525 | rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName, |
| 2526 | strlen(message.message.enodbName)); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2527 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2528 | message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment(); |
| 2529 | message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2530 | |
| 2531 | // Update E2T instance level metrics |
| 2532 | message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment(); |
| 2533 | message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment((double)message.message.asnLength); |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 2534 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2535 | sendRmrMessage(rmrMessageBuffer, message); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2536 | messageSent = true; |
| 2537 | } else { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2538 | mdclog_write(MDCLOG_ERR, "RIC request id missing illegal request"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2539 | } |
| 2540 | } |
| 2541 | if (messageSent) { |
| 2542 | break; |
| 2543 | } |
| 2544 | } |
| 2545 | break; |
| 2546 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2547 | case ProcedureCode_id_RICsubscription: { |
| 2548 | if (logLevel >= MDCLOG_DEBUG) { |
| 2549 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName); |
| 2550 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2551 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2552 | message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment(); |
| 2553 | message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2554 | |
| 2555 | // Update E2T instance level metrics |
| 2556 | message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment(); |
| 2557 | message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment((double)message.message.asnLength); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 2558 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2559 | if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2560 | mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP"); |
| 2561 | } |
| 2562 | break; |
| 2563 | } |
| 2564 | case ProcedureCode_id_RICsubscriptionDelete: { |
| 2565 | if (logLevel >= MDCLOG_DEBUG) { |
| 2566 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName); |
| 2567 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2568 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2569 | message.peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(); |
| 2570 | message.peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2571 | |
| 2572 | // Update E2T instance level metrics |
| 2573 | message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(); |
| 2574 | message.peerInfo->sctpParams->e2tCounters[IN_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment((double)message.message.asnLength); |
dhirajverma | 6cf2861 | 2021-06-23 04:53:34 -0400 | [diff] [blame] | 2575 | #endif |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2576 | if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2577 | mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP"); |
| 2578 | } |
| 2579 | break; |
| 2580 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2581 | default: { |
| 2582 | mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode); |
| 2583 | message.message.messageType = 0; // no RMR message type yet |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2584 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2585 | buildJsonMessage(message); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2586 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2587 | break; |
| 2588 | } |
| 2589 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | /** |
| 2593 | * |
| 2594 | * @param message |
| 2595 | * @param requestId |
| 2596 | * @param rmrMmessageBuffer |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2597 | * @return |
| 2598 | */ |
| 2599 | int sendRequestToXapp(ReportingMessages_t &message, |
| 2600 | int requestId, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2601 | RmrMessagesBuffer_t &rmrMmessageBuffer) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2602 | rmr_bytes2meid(rmrMmessageBuffer.sendMessage, |
| 2603 | (unsigned char *)message.message.enodbName, |
| 2604 | strlen(message.message.enodbName)); |
| 2605 | message.message.messageType = rmrMmessageBuffer.sendMessage->mtype = requestId; |
| 2606 | rmrMmessageBuffer.sendMessage->state = 0; |
| 2607 | static unsigned char tx[32]; |
| 2608 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 2609 | rmr_bytes2xact(rmrMmessageBuffer.sendMessage, tx, strlen((const char *) tx)); |
| 2610 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2611 | auto rc = sendRmrMessage(rmrMmessageBuffer, message); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2612 | return rc; |
| 2613 | } |
| 2614 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2615 | /** |
| 2616 | * |
| 2617 | * @param pSctpParams |
| 2618 | */ |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2619 | void getRmrContext(sctp_params_t &pSctpParams) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2620 | pSctpParams.rmrCtx = nullptr; |
aa7133@att.com | ab0e0f4 | 2020-04-06 17:13:58 +0300 | [diff] [blame] | 2621 | pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RECEIVE_XAPP_BUFFER_SIZE, RMRFL_NONE); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2622 | if (pSctpParams.rmrCtx == nullptr) { |
| 2623 | mdclog_write(MDCLOG_ERR, "Failed to initialize RMR"); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2624 | return; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2625 | } |
| 2626 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2627 | rmr_set_stimeout(pSctpParams.rmrCtx, 0); // disable retries for any send operation |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2628 | // we need to find that routing table exist and we can run |
| 2629 | if (mdclog_level_get() >= MDCLOG_INFO) { |
| 2630 | mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready"); |
| 2631 | } |
| 2632 | int rmrReady = 0; |
| 2633 | int count = 0; |
| 2634 | while (!rmrReady) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2635 | if ((rmrReady = rmr_ready(pSctpParams.rmrCtx)) == 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2636 | sleep(1); |
| 2637 | } |
| 2638 | count++; |
| 2639 | if (count % 60 == 0) { |
| 2640 | mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count); |
| 2641 | } |
| 2642 | } |
| 2643 | if (mdclog_level_get() >= MDCLOG_INFO) { |
| 2644 | mdclog_write(MDCLOG_INFO, "RMR running"); |
| 2645 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2646 | rmr_init_trace(pSctpParams.rmrCtx, 200); |
| 2647 | // get the RMR fd for the epoll |
| 2648 | pSctpParams.rmrListenFd = rmr_get_rcvfd(pSctpParams.rmrCtx); |
| 2649 | struct epoll_event event{}; |
| 2650 | // add RMR fd to epoll |
| 2651 | event.events = (EPOLLIN); |
| 2652 | event.data.fd = pSctpParams.rmrListenFd; |
| 2653 | // add listening RMR FD to epoll |
| 2654 | if (epoll_ctl(pSctpParams.epoll_fd, EPOLL_CTL_ADD, pSctpParams.rmrListenFd, &event)) { |
| 2655 | mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll"); |
| 2656 | close(pSctpParams.rmrListenFd); |
| 2657 | rmr_close(pSctpParams.rmrCtx); |
| 2658 | pSctpParams.rmrCtx = nullptr; |
| 2659 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2660 | } |
| 2661 | |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2662 | /** |
| 2663 | * |
| 2664 | * @param message |
| 2665 | * @param rmrMessageBuffer |
| 2666 | * @return |
| 2667 | */ |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2668 | int PER_FromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) { |
aa7133@att.com | 07e256f | 2020-04-20 15:59:51 +0300 | [diff] [blame] | 2669 | E2AP_PDU_t *pdu = nullptr; |
aa7133@att.com | 1c4f50f | 2020-03-30 14:30:52 +0300 | [diff] [blame] | 2670 | |
| 2671 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2672 | mdclog_write(MDCLOG_DEBUG, "got xml Format data from xApp of size %d is:%s", |
aa7133@att.com | 07e256f | 2020-04-20 15:59:51 +0300 | [diff] [blame] | 2673 | rmrMessageBuffer.rcvMessage->len, rmrMessageBuffer.rcvMessage->payload); |
aa7133@att.com | 1c4f50f | 2020-03-30 14:30:52 +0300 | [diff] [blame] | 2674 | } |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2675 | auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &pdu, |
| 2676 | rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len); |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2677 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2678 | mdclog_write(MDCLOG_DEBUG, "%s After decoding the XML to PDU", __func__ ); |
| 2679 | } |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2680 | if (rval.code != RC_OK) { |
dhirajverma | c40ea1f | 2021-07-08 12:52:30 -0400 | [diff] [blame] | 2681 | #ifdef UNIT_TEST |
| 2682 | return 0; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2683 | #endif |
aa7133@att.com | 1c4f50f | 2020-03-30 14:30:52 +0300 | [diff] [blame] | 2684 | mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s", |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2685 | rval.code, |
| 2686 | message.message.enodbName); |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 2687 | if (pdu != nullptr) { |
| 2688 | ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 2689 | pdu = nullptr; |
| 2690 | } |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2691 | return -1; |
| 2692 | } |
| 2693 | |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 2694 | int buff_size = RECEIVE_XAPP_BUFFER_SIZE; |
| 2695 | auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu, |
| 2696 | rmrMessageBuffer.rcvMessage->payload, buff_size); |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2697 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2698 | mdclog_write(MDCLOG_DEBUG, "%s After encoding PDU to PER", __func__ ); |
| 2699 | } |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2700 | if (er.encoded == -1) { |
| 2701 | mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 2702 | if (pdu != nullptr) { |
| 2703 | ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 2704 | pdu = nullptr; |
| 2705 | } |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2706 | return -1; |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 2707 | } else if (er.encoded > (ssize_t)buff_size) { |
| 2708 | mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d", |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2709 | (int)rmrMessageBuffer.rcvMessage->len, |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 2710 | asn_DEF_E2AP_PDU.name, |
| 2711 | __func__, |
| 2712 | __LINE__); |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 2713 | if (pdu != nullptr) { |
| 2714 | ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 2715 | pdu = nullptr; |
| 2716 | } |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2717 | return -1; |
| 2718 | } |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 2719 | rmrMessageBuffer.rcvMessage->len = er.encoded; |
dhirajverma | 9f59b57 | 2021-07-23 02:36:13 -0400 | [diff] [blame] | 2720 | if (pdu != nullptr) { |
| 2721 | ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 2722 | pdu = nullptr; |
| 2723 | } |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2724 | return 0; |
| 2725 | } |
| 2726 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2727 | /** |
| 2728 | * |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2729 | * @param sctpMap |
| 2730 | * @param rmrMessageBuffer |
| 2731 | * @param ts |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2732 | * @return |
| 2733 | */ |
aa7133@att.com | 6680c3b | 2020-03-22 12:06:58 +0200 | [diff] [blame] | 2734 | int receiveXappMessages(Sctp_Map_t *sctpMap, |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2735 | RmrMessagesBuffer_t &rmrMessageBuffer, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2736 | struct timespec &ts) { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2737 | int loglevel = mdclog_level_get(); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2738 | if (rmrMessageBuffer.rcvMessage == nullptr) { |
| 2739 | //we have error |
| 2740 | mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2741 | return -1; |
| 2742 | } |
| 2743 | |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2744 | // if (loglevel >= MDCLOG_DEBUG) { |
| 2745 | // mdclog_write(MDCLOG_DEBUG, "Call to rmr_rcv_msg"); |
| 2746 | // } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2747 | rmrMessageBuffer.rcvMessage = rmr_rcv_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage); |
| 2748 | if (rmrMessageBuffer.rcvMessage == nullptr) { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2749 | mdclog_write(MDCLOG_ERR, "RMR Receiving message with null pointer, Reallocated rmr message buffer"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2750 | rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2751 | return -2; |
| 2752 | } |
| 2753 | ReportingMessages_t message; |
| 2754 | message.message.direction = 'D'; |
| 2755 | message.message.time.tv_nsec = ts.tv_nsec; |
| 2756 | message.message.time.tv_sec = ts.tv_sec; |
| 2757 | |
| 2758 | // get message payload |
| 2759 | //auto msgData = msg->payload; |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 2760 | #ifdef UNIT_TEST |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 2761 | rmrMessageBuffer.rcvMessage->state = 0; |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 2762 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2763 | if (rmrMessageBuffer.rcvMessage->state != 0) { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 2764 | mdclog_write(MDCLOG_ERR, "RMR Receiving message with stat = %d", rmrMessageBuffer.rcvMessage->state); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2765 | return -1; |
| 2766 | } |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2767 | rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)message.message.enodbName); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2768 | message.peerInfo = (ConnectedCU_t *) sctpMap->find(message.message.enodbName); |
| 2769 | if (message.peerInfo == nullptr) { |
| 2770 | auto type = rmrMessageBuffer.rcvMessage->mtype; |
| 2771 | switch (type) { |
| 2772 | case RIC_SCTP_CLEAR_ALL: |
| 2773 | case E2_TERM_KEEP_ALIVE_REQ: |
| 2774 | case RIC_HEALTH_CHECK_REQ: |
| 2775 | break; |
| 2776 | default: |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 2777 | #ifdef UNIT_TEST |
| 2778 | break; |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2779 | #endif |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 2780 | mdclog_write(MDCLOG_ERR, "Failed to send message no CU entry %s", message.message.enodbName); |
| 2781 | return -1; |
| 2782 | } |
| 2783 | } |
| 2784 | |
aa7133@att.com | de40d1c | 2020-08-26 16:19:20 +0300 | [diff] [blame] | 2785 | if (rmrMessageBuffer.rcvMessage->mtype != RIC_HEALTH_CHECK_REQ) { |
| 2786 | num_of_XAPP_messages.fetch_add(1, std::memory_order_release); |
| 2787 | |
| 2788 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2789 | switch (rmrMessageBuffer.rcvMessage->mtype) { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2790 | case RIC_E2_SETUP_RESP : { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2791 | if (loglevel >= MDCLOG_DEBUG) { |
| 2792 | mdclog_write(MDCLOG_DEBUG, "RIC_E2_SETUP_RESP"); |
| 2793 | } |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2794 | if (PER_FromXML(message, rmrMessageBuffer) != 0) { |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2795 | break; |
| 2796 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2797 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2798 | message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment(); |
| 2799 | message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2800 | |
| 2801 | // Update E2T instance level metrics |
| 2802 | message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment(); |
| 2803 | message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2804 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2805 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
| 2806 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_RESP"); |
| 2807 | return -6; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2808 | } |
| 2809 | break; |
| 2810 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2811 | case RIC_E2_SETUP_FAILURE : { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2812 | if (loglevel >= MDCLOG_DEBUG) { |
| 2813 | mdclog_write(MDCLOG_DEBUG, "RIC_E2_SETUP_FAILURE"); |
| 2814 | } |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2815 | if (PER_FromXML(message, rmrMessageBuffer) != 0) { |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2816 | break; |
| 2817 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2818 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2819 | message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment(); |
| 2820 | message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2821 | |
| 2822 | // Update E2T instance level metrics |
| 2823 | message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2setup]->Increment(); |
| 2824 | message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2setup]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2825 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2826 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
| 2827 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_FAILURE"); |
| 2828 | return -6; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2829 | } |
| 2830 | break; |
| 2831 | } |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 2832 | |
| 2833 | case RIC_E2NODE_CONFIG_UPDATE_ACK: { |
| 2834 | if (loglevel >= MDCLOG_DEBUG) { |
| 2835 | mdclog_write(MDCLOG_DEBUG, "RIC_E2NODE_CONFIG_UPDATE_ACK"); |
| 2836 | } |
| 2837 | if (PER_FromXML(message, rmrMessageBuffer) != 0) { |
| 2838 | break; |
| 2839 | } |
| 2840 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
| 2841 | message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(); |
| 2842 | message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len); |
| 2843 | |
| 2844 | // Update E2T instance level metrics |
| 2845 | message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(); |
| 2846 | message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len); |
| 2847 | #endif |
| 2848 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
| 2849 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2NODE_CONFIG_UPDATE_ACK"); |
| 2850 | return -6; |
| 2851 | } |
| 2852 | break; |
| 2853 | } |
| 2854 | |
| 2855 | case RIC_E2NODE_CONFIG_UPDATE_FAILURE: { |
| 2856 | if (loglevel >= MDCLOG_DEBUG) { |
| 2857 | mdclog_write(MDCLOG_DEBUG, "RIC_E2NODE_CONFIG_UPDATE_FAILURE"); |
| 2858 | } |
| 2859 | if (PER_FromXML(message, rmrMessageBuffer) != 0) { |
| 2860 | break; |
| 2861 | } |
| 2862 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
| 2863 | message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(); |
| 2864 | message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len); |
| 2865 | |
| 2866 | // Update E2T instance level metrics |
| 2867 | message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(); |
| 2868 | message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_E2nodeConfigurationUpdate]->Increment(rmrMessageBuffer.rcvMessage->len); |
| 2869 | #endif |
| 2870 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
| 2871 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2NODE_CONFIG_UPDATE_FAILURE"); |
| 2872 | return -6; |
| 2873 | } |
| 2874 | break; |
| 2875 | } |
| 2876 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2877 | case RIC_ERROR_INDICATION: { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2878 | if (loglevel >= MDCLOG_DEBUG) { |
| 2879 | mdclog_write(MDCLOG_DEBUG, "RIC_ERROR_INDICATION"); |
| 2880 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2881 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2882 | message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(); |
| 2883 | message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2884 | |
| 2885 | // Update E2T instance level metrics |
| 2886 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(); |
| 2887 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_ErrorIndication]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2888 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2889 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
| 2890 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_ERROR_INDICATION"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2891 | return -6; |
| 2892 | } |
| 2893 | break; |
| 2894 | } |
| 2895 | case RIC_SUB_REQ: { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2896 | if (loglevel >= MDCLOG_DEBUG) { |
| 2897 | mdclog_write(MDCLOG_DEBUG, "RIC_SUB_REQ"); |
| 2898 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2899 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2900 | message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment(); |
| 2901 | message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2902 | |
| 2903 | // Update E2T instance level metrics |
| 2904 | message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscription]->Increment(); |
| 2905 | message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscription]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2906 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2907 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2908 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_REQ"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2909 | return -6; |
| 2910 | } |
| 2911 | break; |
| 2912 | } |
| 2913 | case RIC_SUB_DEL_REQ: { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2914 | if (loglevel >= MDCLOG_DEBUG) { |
| 2915 | mdclog_write(MDCLOG_DEBUG, "RIC_SUB_DEL_REQ"); |
| 2916 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2917 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2918 | message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(); |
| 2919 | message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2920 | |
| 2921 | // Update E2T instance level metrics |
| 2922 | message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(); |
| 2923 | message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICsubscriptionDelete]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2924 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2925 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2926 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_DEL_REQ"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2927 | return -6; |
| 2928 | } |
| 2929 | break; |
| 2930 | } |
| 2931 | case RIC_CONTROL_REQ: { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2932 | if (loglevel >= MDCLOG_DEBUG) { |
| 2933 | mdclog_write(MDCLOG_DEBUG, "RIC_CONTROL_REQ"); |
| 2934 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2935 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2936 | message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment(); |
| 2937 | message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2938 | |
| 2939 | // Update E2T instance level metrics |
| 2940 | message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICcontrol]->Increment(); |
| 2941 | message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICcontrol]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2942 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2943 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2944 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_CONTROL_REQ"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2945 | return -6; |
| 2946 | } |
| 2947 | break; |
| 2948 | } |
| 2949 | case RIC_SERVICE_QUERY: { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2950 | if (loglevel >= MDCLOG_DEBUG) { |
| 2951 | mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_QUERY"); |
| 2952 | } |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2953 | if (PER_FromXML(message, rmrMessageBuffer) != 0) { |
| 2954 | break; |
| 2955 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2956 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2957 | message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(); |
| 2958 | message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2959 | |
| 2960 | // Update E2T instance level metrics |
| 2961 | message.peerInfo->sctpParams->e2tCounters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(); |
| 2962 | message.peerInfo->sctpParams->e2tCounters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_RICserviceQuery]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2963 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2964 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2965 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2966 | return -6; |
| 2967 | } |
| 2968 | break; |
| 2969 | } |
| 2970 | case RIC_SERVICE_UPDATE_ACK: { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2971 | if (loglevel >= MDCLOG_DEBUG) { |
| 2972 | mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_UPDATE_ACK"); |
| 2973 | } |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2974 | if (PER_FromXML(message, rmrMessageBuffer) != 0) { |
aa7133@att.com | 54885fe | 2020-10-29 17:24:49 +0300 | [diff] [blame] | 2975 | mdclog_write(MDCLOG_ERR, "error in PER_FromXML"); |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2976 | break; |
| 2977 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2978 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 2979 | message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(); |
aa7133@att.com | 5277191 | 2020-10-29 17:45:01 +0300 | [diff] [blame] | 2980 | message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 2981 | |
| 2982 | // Update E2T instance level metrics |
| 2983 | message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(); |
| 2984 | message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 2985 | #endif |
aa7133@att.com | 54885fe | 2020-10-29 17:24:49 +0300 | [diff] [blame] | 2986 | if (loglevel >= MDCLOG_DEBUG) { |
| 2987 | mdclog_write(MDCLOG_DEBUG, "Before sending to CU"); |
| 2988 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2989 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2990 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2991 | return -6; |
| 2992 | } |
| 2993 | break; |
| 2994 | } |
| 2995 | case RIC_SERVICE_UPDATE_FAILURE: { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 2996 | if (loglevel >= MDCLOG_DEBUG) { |
| 2997 | mdclog_write(MDCLOG_DEBUG, "RIC_SERVICE_UPDATE_FAILURE"); |
| 2998 | } |
aa7133@att.com | 0793fcb | 2020-04-16 11:34:26 +0300 | [diff] [blame] | 2999 | if (PER_FromXML(message, rmrMessageBuffer) != 0) { |
| 3000 | break; |
| 3001 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 3002 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 3003 | message.peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(); |
aa7133@att.com | 7c07fee | 2020-10-29 17:54:38 +0300 | [diff] [blame] | 3004 | message.peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 3005 | |
| 3006 | // Update E2T instance level metrics |
| 3007 | message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][MSG_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(); |
| 3008 | message.peerInfo->sctpParams->e2tCounters[OUT_UN_SUCC][BYTES_COUNTER][ProcedureCode_id_RICserviceUpdate]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 3009 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3010 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3011 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3012 | return -6; |
| 3013 | } |
| 3014 | break; |
| 3015 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3016 | case RIC_E2_RESET_REQ: { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 3017 | if (loglevel >= MDCLOG_DEBUG) { |
| 3018 | mdclog_write(MDCLOG_DEBUG, "RIC_E2_RESET_REQ"); |
| 3019 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3020 | if (PER_FromXML(message, rmrMessageBuffer) != 0) { |
| 3021 | break; |
| 3022 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 3023 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 3024 | message.peerInfo->counters[OUT_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment(); |
| 3025 | message.peerInfo->counters[OUT_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 3026 | |
| 3027 | // Update E2T instance level metrics |
| 3028 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][MSG_COUNTER][ProcedureCode_id_Reset]->Increment(); |
| 3029 | message.peerInfo->sctpParams->e2tCounters[IN_INITI][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 3030 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3031 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3032 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3033 | return -6; |
| 3034 | } |
| 3035 | break; |
| 3036 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3037 | case RIC_E2_RESET_RESP: { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 3038 | if (loglevel >= MDCLOG_DEBUG) { |
| 3039 | mdclog_write(MDCLOG_DEBUG, "RIC_E2_RESET_RESP"); |
| 3040 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3041 | if (PER_FromXML(message, rmrMessageBuffer) != 0) { |
| 3042 | break; |
| 3043 | } |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 3044 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
aa7133@att.com | a4c8001 | 2020-06-24 16:36:47 +0300 | [diff] [blame] | 3045 | message.peerInfo->counters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment(); |
| 3046 | message.peerInfo->counters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len); |
Mohamed Abukar | 64f3724 | 2021-08-15 12:39:56 +0000 | [diff] [blame] | 3047 | |
| 3048 | // Update E2T instance level metrics |
| 3049 | message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][MSG_COUNTER][ProcedureCode_id_Reset]->Increment(); |
| 3050 | message.peerInfo->sctpParams->e2tCounters[OUT_SUCC][BYTES_COUNTER][ProcedureCode_id_Reset]->Increment(rmrMessageBuffer.rcvMessage->len); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 3051 | #endif |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3052 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3053 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET_RESP"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3054 | return -6; |
| 3055 | } |
| 3056 | break; |
| 3057 | } |
| 3058 | case RIC_SCTP_CLEAR_ALL: { |
| 3059 | mdclog_write(MDCLOG_INFO, "RIC_SCTP_CLEAR_ALL"); |
| 3060 | // loop on all keys and close socket and then erase all map. |
| 3061 | vector<char *> v; |
| 3062 | sctpMap->getKeys(v); |
| 3063 | for (auto const &iter : v) { //}; iter != sctpMap.end(); iter++) { |
| 3064 | if (!boost::starts_with((string) (iter), "host:") && !boost::starts_with((string) (iter), "msg:")) { |
| 3065 | auto *peerInfo = (ConnectedCU_t *) sctpMap->find(iter); |
| 3066 | if (peerInfo == nullptr) { |
| 3067 | continue; |
| 3068 | } |
| 3069 | close(peerInfo->fileDescriptor); |
| 3070 | memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName)); |
| 3071 | message.message.direction = 'D'; |
| 3072 | message.message.time.tv_nsec = ts.tv_nsec; |
| 3073 | message.message.time.tv_sec = ts.tv_sec; |
| 3074 | |
| 3075 | message.message.asnLength = rmrMessageBuffer.sendMessage->len = |
| 3076 | snprintf((char *)rmrMessageBuffer.sendMessage->payload, |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 3077 | 256, |
| 3078 | "%s|RIC_SCTP_CLEAR_ALL", |
| 3079 | peerInfo->enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3080 | message.message.asndata = rmrMessageBuffer.sendMessage->payload; |
| 3081 | mdclog_write(MDCLOG_INFO, "%s", message.message.asndata); |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3082 | if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3083 | mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP"); |
| 3084 | } |
| 3085 | free(peerInfo); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 3086 | peerInfo = nullptr; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | sleep(1); |
| 3091 | sctpMap->clear(); |
| 3092 | break; |
| 3093 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3094 | case E2_TERM_KEEP_ALIVE_REQ: { |
| 3095 | // send message back |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3096 | rmr_bytes2payload(rmrMessageBuffer.sendMessage, |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 3097 | (unsigned char *)rmrMessageBuffer.ka_message, |
| 3098 | rmrMessageBuffer.ka_message_len); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3099 | rmrMessageBuffer.sendMessage->mtype = E2_TERM_KEEP_ALIVE_RESP; |
| 3100 | rmrMessageBuffer.sendMessage->state = 0; |
| 3101 | static unsigned char tx[32]; |
| 3102 | auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 3103 | rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, txLen); |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 3104 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3105 | rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage); |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 3106 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3107 | if (rmrMessageBuffer.sendMessage == nullptr) { |
| 3108 | rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
aa7133@att.com | 77fff43 | 2020-01-27 12:01:20 +0200 | [diff] [blame] | 3109 | mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP RMR message returned NULL"); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3110 | } else if (rmrMessageBuffer.sendMessage->state != 0) { |
aa7133@att.com | 77fff43 | 2020-01-27 12:01:20 +0200 | [diff] [blame] | 3111 | mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP, on RMR state = %d ( %s)", |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 3112 | rmrMessageBuffer.sendMessage->state, translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str()); |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 3113 | } else if (loglevel >= MDCLOG_DEBUG) { |
aa7133@att.com | bc11077 | 2020-03-25 09:45:14 +0200 | [diff] [blame] | 3114 | mdclog_write(MDCLOG_DEBUG, "Got Keep Alive Request send : %s", rmrMessageBuffer.ka_message); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3115 | } |
aa7133@att.com | 342843e | 2020-01-26 12:53:34 +0200 | [diff] [blame] | 3116 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3117 | break; |
| 3118 | } |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3119 | case RIC_HEALTH_CHECK_REQ: { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 3120 | static int counter = 0; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3121 | // send message back |
aa7133@att.com | c18fe53 | 2020-06-30 12:40:18 +0300 | [diff] [blame] | 3122 | rmr_bytes2payload(rmrMessageBuffer.rcvMessage, |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3123 | (unsigned char *)"OK", |
| 3124 | 2); |
aa7133@att.com | c18fe53 | 2020-06-30 12:40:18 +0300 | [diff] [blame] | 3125 | rmrMessageBuffer.rcvMessage->mtype = RIC_HEALTH_CHECK_RESP; |
| 3126 | rmrMessageBuffer.rcvMessage->state = 0; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3127 | static unsigned char tx[32]; |
| 3128 | auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
aa7133@att.com | c18fe53 | 2020-06-30 12:40:18 +0300 | [diff] [blame] | 3129 | rmr_bytes2xact(rmrMessageBuffer.rcvMessage, tx, txLen); |
| 3130 | rmrMessageBuffer.rcvMessage = rmr_rts_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage); |
| 3131 | //rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage); |
| 3132 | if (rmrMessageBuffer.rcvMessage == nullptr) { |
| 3133 | rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3134 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP RMR message returned NULL"); |
aa7133@att.com | c18fe53 | 2020-06-30 12:40:18 +0300 | [diff] [blame] | 3135 | } else if (rmrMessageBuffer.rcvMessage->state != 0) { |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3136 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP, on RMR state = %d ( %s)", |
aa7133@att.com | c18fe53 | 2020-06-30 12:40:18 +0300 | [diff] [blame] | 3137 | rmrMessageBuffer.rcvMessage->state, translateRmrErrorMessages(rmrMessageBuffer.rcvMessage->state).c_str()); |
dhirajverma | b55bc17 | 2021-11-09 02:15:08 -0500 | [diff] [blame] | 3138 | } else if (loglevel >= MDCLOG_DEBUG && (++counter % 100 == 0)) { |
aa7133@att.com | f13529a | 2020-08-27 11:21:16 +0300 | [diff] [blame] | 3139 | mdclog_write(MDCLOG_DEBUG, "Got %d RIC_HEALTH_CHECK_REQ Request send : OK", counter); |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | break; |
| 3143 | } |
| 3144 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3145 | default: |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 3146 | mdclog_write(MDCLOG_WARN, "Message Type : %d is not supported", rmrMessageBuffer.rcvMessage->mtype); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3147 | message.message.asndata = rmrMessageBuffer.rcvMessage->payload; |
| 3148 | message.message.asnLength = rmrMessageBuffer.rcvMessage->len; |
| 3149 | message.message.time.tv_nsec = ts.tv_nsec; |
| 3150 | message.message.time.tv_sec = ts.tv_sec; |
| 3151 | message.message.messageType = rmrMessageBuffer.rcvMessage->mtype; |
| 3152 | |
| 3153 | buildJsonMessage(message); |
| 3154 | |
| 3155 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3156 | return -7; |
| 3157 | } |
| 3158 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 3159 | mdclog_write(MDCLOG_DEBUG, "EXIT OK from %s", __FUNCTION__); |
| 3160 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3161 | return 0; |
| 3162 | } |
| 3163 | |
| 3164 | /** |
| 3165 | * Send message to the CU that is not expecting for successful or unsuccessful results |
| 3166 | * @param messageBuffer |
| 3167 | * @param message |
| 3168 | * @param failedMsgId |
| 3169 | * @param sctpMap |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3170 | * @return |
| 3171 | */ |
| 3172 | int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer, |
| 3173 | ReportingMessages_t &message, |
| 3174 | int failedMsgId, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3175 | Sctp_Map_t *sctpMap) { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 3176 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 3177 | mdclog_write(MDCLOG_DEBUG, "send message: %d to %s address", message.message.messageType, message.message.enodbName); |
| 3178 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3179 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3180 | getRequestMetaData(message, messageBuffer); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3181 | if (mdclog_level_get() >= MDCLOG_INFO) { |
| 3182 | mdclog_write(MDCLOG_INFO, "send message to %s address", message.message.enodbName); |
| 3183 | } |
| 3184 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3185 | auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3186 | return rc; |
| 3187 | } |
| 3188 | |
| 3189 | /** |
| 3190 | * |
| 3191 | * @param sctpMap |
| 3192 | * @param messageBuffer |
| 3193 | * @param message |
| 3194 | * @param failedMesgId |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3195 | * @return |
| 3196 | */ |
| 3197 | int sendMessagetoCu(Sctp_Map_t *sctpMap, |
| 3198 | RmrMessagesBuffer_t &messageBuffer, |
| 3199 | ReportingMessages_t &message, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3200 | int failedMesgId) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3201 | // get the FD |
| 3202 | message.message.messageType = messageBuffer.rcvMessage->mtype; |
ss412g | 4aeeda2 | 2020-06-16 14:12:41 +0300 | [diff] [blame] | 3203 | auto rc = sendSctpMsg(message.peerInfo, message, sctpMap); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3204 | return rc; |
| 3205 | } |
| 3206 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3207 | |
| 3208 | /** |
| 3209 | * |
| 3210 | * @param epoll_fd |
| 3211 | * @param peerInfo |
| 3212 | * @param events |
| 3213 | * @param sctpMap |
| 3214 | * @param enodbName |
| 3215 | * @param msgType |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3216 | * @return |
| 3217 | */ |
| 3218 | int addToEpoll(int epoll_fd, |
| 3219 | ConnectedCU_t *peerInfo, |
| 3220 | uint32_t events, |
| 3221 | Sctp_Map_t *sctpMap, |
| 3222 | char *enodbName, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3223 | int msgType) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3224 | // Add to Epol |
| 3225 | struct epoll_event event{}; |
| 3226 | event.data.ptr = peerInfo; |
| 3227 | event.events = events; |
| 3228 | if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peerInfo->fileDescriptor, &event) < 0) { |
Alexandre Huff | fff9794 | 2023-03-31 21:22:20 -0300 | [diff] [blame] | 3229 | #if !(defined(UNIT_TEST) || defined(MODULE_TEST)) |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3230 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 3231 | mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here), %s, %s %d", |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3232 | strerror(errno), __func__, __LINE__); |
| 3233 | } |
| 3234 | close(peerInfo->fileDescriptor); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 3235 | if (enodbName != nullptr) { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3236 | cleanHashEntry(peerInfo, sctpMap); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 3237 | char key[MAX_ENODB_NAME_SIZE * 2]; |
| 3238 | snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType); |
| 3239 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 3240 | mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__); |
| 3241 | } |
| 3242 | auto tmp = sctpMap->find(key); |
| 3243 | if (tmp) { |
| 3244 | free(tmp); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 3245 | tmp = nullptr; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 3246 | sctpMap->erase(key); |
| 3247 | } |
| 3248 | } else { |
| 3249 | peerInfo->enodbName[0] = 0; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3250 | } |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 3251 | mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here)"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3252 | return -1; |
dhirajverma | 93b6d9c | 2021-07-10 00:49:13 -0400 | [diff] [blame] | 3253 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3254 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3255 | return 0; |
| 3256 | } |
| 3257 | |
| 3258 | /** |
| 3259 | * |
| 3260 | * @param epoll_fd |
| 3261 | * @param peerInfo |
| 3262 | * @param events |
| 3263 | * @param sctpMap |
| 3264 | * @param enodbName |
| 3265 | * @param msgType |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3266 | * @return |
| 3267 | */ |
| 3268 | int modifyToEpoll(int epoll_fd, |
| 3269 | ConnectedCU_t *peerInfo, |
| 3270 | uint32_t events, |
| 3271 | Sctp_Map_t *sctpMap, |
| 3272 | char *enodbName, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3273 | int msgType) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3274 | // Add to Epol |
| 3275 | struct epoll_event event{}; |
| 3276 | event.data.ptr = peerInfo; |
| 3277 | event.events = events; |
| 3278 | if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, peerInfo->fileDescriptor, &event) < 0) { |
| 3279 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 3280 | mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_MOD (may check not to quit here), %s, %s %d", |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3281 | strerror(errno), __func__, __LINE__); |
| 3282 | } |
| 3283 | close(peerInfo->fileDescriptor); |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3284 | cleanHashEntry(peerInfo, sctpMap); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3285 | char key[MAX_ENODB_NAME_SIZE * 2]; |
| 3286 | snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType); |
| 3287 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 3288 | mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__); |
| 3289 | } |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 3290 | auto tmp = sctpMap->find(key); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3291 | if (tmp) { |
| 3292 | free(tmp); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 3293 | tmp = nullptr; |
Alexandre Huff | 019cb42 | 2023-04-11 10:56:48 -0300 | [diff] [blame] | 3294 | sctpMap->erase(key); |
sandeeku | ea66210 | 2022-11-08 18:51:20 +0530 | [diff] [blame] | 3295 | } |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 3296 | mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may check not to quit here)"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3297 | return -1; |
| 3298 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3299 | return 0; |
| 3300 | } |
| 3301 | |
| 3302 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 3303 | int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3304 | buildJsonMessage(message); |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 3305 | #ifndef UNIT_TEST |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3306 | rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage); |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 3307 | #else |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 3308 | rmrMessageBuffer.sendMessage->state = RMR_ERR_RETRY; |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 3309 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3310 | if (rmrMessageBuffer.sendMessage == nullptr) { |
| 3311 | rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
| 3312 | mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3313 | return -1; |
| 3314 | } |
| 3315 | |
| 3316 | if (rmrMessageBuffer.sendMessage->state != 0) { |
| 3317 | char meid[RMR_MAX_MEID]{}; |
| 3318 | if (rmrMessageBuffer.sendMessage->state == RMR_ERR_RETRY) { |
| 3319 | usleep(5); |
| 3320 | rmrMessageBuffer.sendMessage->state = 0; |
| 3321 | mdclog_write(MDCLOG_INFO, "RETRY sending Message type %d to Xapp from %s", |
| 3322 | rmrMessageBuffer.sendMessage->mtype, |
| 3323 | rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid)); |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 3324 | #ifndef UNIT_TEST |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3325 | rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage); |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 3326 | #endif |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3327 | if (rmrMessageBuffer.sendMessage == nullptr) { |
| 3328 | mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer"); |
| 3329 | rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3330 | return -1; |
| 3331 | } else if (rmrMessageBuffer.sendMessage->state != 0) { |
| 3332 | mdclog_write(MDCLOG_ERR, |
| 3333 | "Message state %s while sending request %d to Xapp from %s after retry of 10 microseconds", |
| 3334 | translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(), |
| 3335 | rmrMessageBuffer.sendMessage->mtype, |
| 3336 | rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid)); |
| 3337 | auto rc = rmrMessageBuffer.sendMessage->state; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3338 | return rc; |
| 3339 | } |
| 3340 | } else { |
| 3341 | mdclog_write(MDCLOG_ERR, "Message state %s while sending request %d to Xapp from %s", |
| 3342 | translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(), |
| 3343 | rmrMessageBuffer.sendMessage->mtype, |
| 3344 | rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3345 | return rmrMessageBuffer.sendMessage->state; |
| 3346 | } |
| 3347 | } |
| 3348 | return 0; |
| 3349 | } |
| 3350 | |
| 3351 | void buildJsonMessage(ReportingMessages_t &message) { |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 3352 | #ifdef UNIT_TEST |
dhirajverma | 9999029 | 2021-07-05 10:03:59 -0400 | [diff] [blame] | 3353 | jsonTrace = true; |
dhirajverma | 60f8bef | 2021-06-29 07:22:58 -0400 | [diff] [blame] | 3354 | #endif |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3355 | if (jsonTrace) { |
| 3356 | message.outLen = sizeof(message.base64Data); |
| 3357 | base64::encode((const unsigned char *) message.message.asndata, |
| 3358 | (const int) message.message.asnLength, |
| 3359 | message.base64Data, |
| 3360 | message.outLen); |
| 3361 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
aa7133@att.com | c5a1520 | 2020-04-05 19:57:01 +0300 | [diff] [blame] | 3362 | mdclog_write(MDCLOG_DEBUG, "Tracing: ASN length = %d, base64 message length = %d ", |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3363 | (int) message.message.asnLength, |
| 3364 | (int) message.outLen); |
| 3365 | } |
| 3366 | |
| 3367 | snprintf(message.buffer, sizeof(message.buffer), |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 3368 | "{\"header\": {\"ts\": \"%ld.%09ld\"," |
| 3369 | "\"ranName\": \"%s\"," |
| 3370 | "\"messageType\": %d," |
| 3371 | "\"direction\": \"%c\"}," |
| 3372 | "\"base64Length\": %d," |
| 3373 | "\"asnBase64\": \"%s\"}", |
| 3374 | message.message.time.tv_sec, |
| 3375 | message.message.time.tv_nsec, |
| 3376 | message.message.enodbName, |
| 3377 | message.message.messageType, |
| 3378 | message.message.direction, |
| 3379 | (int) message.outLen, |
| 3380 | message.base64Data); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 3381 | static src::logger_mt &lg = my_logger::get(); |
| 3382 | |
| 3383 | BOOST_LOG(lg) << message.buffer; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3384 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3385 | } |
| 3386 | |
| 3387 | |
| 3388 | /** |
| 3389 | * take RMR error code to string |
| 3390 | * @param state |
| 3391 | * @return |
| 3392 | */ |
| 3393 | string translateRmrErrorMessages(int state) { |
| 3394 | string str = {}; |
| 3395 | switch (state) { |
| 3396 | case RMR_OK: |
| 3397 | str = "RMR_OK - state is good"; |
| 3398 | break; |
| 3399 | case RMR_ERR_BADARG: |
aa7133@att.com | 409f223 | 2020-10-29 13:06:45 +0300 | [diff] [blame] | 3400 | str = "RMR_ERR_BADARG - argument passed to function was unusable"; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 3401 | break; |
| 3402 | case RMR_ERR_NOENDPT: |
| 3403 | str = "RMR_ERR_NOENDPT - send//call could not find an endpoint based on msg type"; |
| 3404 | break; |
| 3405 | case RMR_ERR_EMPTY: |
| 3406 | str = "RMR_ERR_EMPTY - msg received had no payload; attempt to send an empty message"; |
| 3407 | break; |
| 3408 | case RMR_ERR_NOHDR: |
| 3409 | str = "RMR_ERR_NOHDR - message didn't contain a valid header"; |
| 3410 | break; |
| 3411 | case RMR_ERR_SENDFAILED: |
| 3412 | str = "RMR_ERR_SENDFAILED - send failed; errno has nano reason"; |
| 3413 | break; |
| 3414 | case RMR_ERR_CALLFAILED: |
| 3415 | str = "RMR_ERR_CALLFAILED - unable to send call() message"; |
| 3416 | break; |
| 3417 | case RMR_ERR_NOWHOPEN: |
| 3418 | str = "RMR_ERR_NOWHOPEN - no wormholes are open"; |
| 3419 | break; |
| 3420 | case RMR_ERR_WHID: |
| 3421 | str = "RMR_ERR_WHID - wormhole id was invalid"; |
| 3422 | break; |
| 3423 | case RMR_ERR_OVERFLOW: |
| 3424 | str = "RMR_ERR_OVERFLOW - operation would have busted through a buffer/field size"; |
| 3425 | break; |
| 3426 | case RMR_ERR_RETRY: |
| 3427 | str = "RMR_ERR_RETRY - request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)"; |
| 3428 | break; |
| 3429 | case RMR_ERR_RCVFAILED: |
| 3430 | str = "RMR_ERR_RCVFAILED - receive failed (hard error)"; |
| 3431 | break; |
| 3432 | case RMR_ERR_TIMEOUT: |
| 3433 | str = "RMR_ERR_TIMEOUT - message processing call timed out"; |
| 3434 | break; |
| 3435 | case RMR_ERR_UNSET: |
| 3436 | str = "RMR_ERR_UNSET - the message hasn't been populated with a transport buffer"; |
| 3437 | break; |
| 3438 | case RMR_ERR_TRUNC: |
| 3439 | str = "RMR_ERR_TRUNC - received message likely truncated"; |
| 3440 | break; |
| 3441 | case RMR_ERR_INITFAILED: |
| 3442 | str = "RMR_ERR_INITFAILED - initialisation of something (probably message) failed"; |
| 3443 | break; |
| 3444 | case RMR_ERR_NOTSUPP: |
| 3445 | str = "RMR_ERR_NOTSUPP - the request is not supported, or RMr was not initialised for the request"; |
| 3446 | break; |
| 3447 | default: |
| 3448 | char buf[128]{}; |
| 3449 | snprintf(buf, sizeof buf, "UNDOCUMENTED RMR_ERR : %d", state); |
| 3450 | str = buf; |
| 3451 | break; |
| 3452 | } |
| 3453 | return str; |
| 3454 | } |
czichy | 2175dd3 | 2022-05-17 15:24:51 +0300 | [diff] [blame] | 3455 | int fetchStreamId(ConnectedCU_t *peerInfo, ReportingMessages_t &message) |
| 3456 | { |
| 3457 | auto loglevel = mdclog_level_get(); |
| 3458 | int streamId = INVALID_STREAM_ID; |
| 3459 | if(message.peerInfo->isSingleStream != false) |
| 3460 | { |
| 3461 | streamId = message.peerInfo->singleStreamId; |
| 3462 | if (loglevel >= MDCLOG_DEBUG) { |
| 3463 | mdclog_write(MDCLOG_DEBUG, "Send SCTP message for SINGLE_STREAM streamId %d , Messeage Type %d ,%s", |
| 3464 | streamId,message.message.messageType, __FUNCTION__); |
| 3465 | } |
| 3466 | return streamId; |
| 3467 | } |
| 3468 | int msgType = message.message.messageType; |
| 3469 | switch (msgType){ |
| 3470 | case RIC_E2_RESET_REQ: |
| 3471 | case RIC_E2_RESET_RESP: |
| 3472 | case RIC_E2_SETUP_RESP: |
| 3473 | case RIC_E2_SETUP_FAILURE: |
| 3474 | case RIC_ERROR_INDICATION: |
| 3475 | case RIC_SERVICE_QUERY: |
| 3476 | case RIC_SERVICE_UPDATE_ACK: |
| 3477 | case RIC_SERVICE_UPDATE_FAILURE: |
| 3478 | streamId = 0; |
| 3479 | break; |
| 3480 | case RIC_SUB_REQ: |
| 3481 | case RIC_SUB_DEL_REQ: |
| 3482 | case RIC_CONTROL_REQ: |
| 3483 | streamId = 1; |
| 3484 | break; |
| 3485 | default: |
| 3486 | streamId = 0; |
| 3487 | break; |
| 3488 | } |
| 3489 | if (loglevel >= MDCLOG_DEBUG) { |
| 3490 | mdclog_write(MDCLOG_DEBUG, "Send SCTP message for streamId %d Messeage Type %d, %s", |
| 3491 | streamId, message.message.messageType, __FUNCTION__); |
| 3492 | } |
| 3493 | return streamId; |
| 3494 | } |