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