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