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