1 // Copyright 2019 AT&T Intellectual Property
2 // Copyright 2019 Nokia
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
16 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
17 // platform project (RICP).
19 // TODO: High-level file comment.
23 #include <3rdparty/oranE2/RANfunctions-List.h>
24 #include "sctpThread.h"
25 #include "BuildRunName.h"
27 //#define asn_DEF_E2SM_gNB_NRT_RANfunction_Definition e2sm_asn_DEF_E2SM_gNB_NRT_RANfunction_Definition
28 //#define __gcov_init e2sm___gcov_init
29 //#define __gcov_merge_add e2sm___gcov_merge_add
30 //#define calloc e2sm_calloc
32 #include "3rdparty/oranE2SM/E2SM-gNB-NRT-RANfunction-Definition.h"
35 //#undef __gcov_merge_add
37 //#undef asn_DEF_E2SM_gNB_NRT_RANfunction_Definition
40 //using namespace std::placeholders;
41 using namespace boost::filesystem;
48 // need to expose without the include of gcov
49 extern "C" void __gcov_flush(void);
51 static void catch_function(int signal) {
57 BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::logger_mt)
59 boost::shared_ptr<sinks::synchronous_sink<sinks::text_file_backend>> boostLogger;
60 double cpuClock = 0.0;
61 bool jsonTrace = true;
65 mdclog_attr_init(&attr);
66 mdclog_attr_set_ident(attr, "E2Terminator");
68 mdclog_attr_destroy(attr);
70 auto start_time = std::chrono::high_resolution_clock::now();
71 typedef std::chrono::duration<double, std::ratio<1,1>> seconds_t;
74 return seconds_t(std::chrono::high_resolution_clock::now() - start_time).count();
77 double approx_CPU_MHz(unsigned sleeptime) {
78 using namespace std::chrono_literals;
80 uint64_t cycles_start = rdtscp(aux);
81 double time_start = age();
82 std::this_thread::sleep_for(sleeptime * 1ms);
83 uint64_t elapsed_cycles = rdtscp(aux) - cycles_start;
84 double elapsed_time = age() - time_start;
85 return elapsed_cycles / elapsed_time;
88 //std::atomic<int64_t> rmrCounter{0};
89 std::atomic<int64_t> num_of_messages{0};
90 std::atomic<int64_t> num_of_XAPP_messages{0};
91 static long transactionCounter = 0;
93 int buildListeningPort(sctp_params_t &sctpParams) {
94 sctpParams.listenFD = socket (AF_INET6, SOCK_STREAM, IPPROTO_SCTP);
95 struct sockaddr_in6 servaddr {};
96 servaddr.sin6_family = AF_INET6;
97 servaddr.sin6_addr = in6addr_any;
98 servaddr.sin6_port = htons(sctpParams.sctpPort);
99 if (bind(sctpParams.listenFD, (SA *)&servaddr, sizeof(servaddr)) < 0 ) {
100 mdclog_write(MDCLOG_ERR, "Error binding. %s\n", strerror(errno));
103 if (setSocketNoBlocking(sctpParams.listenFD) == -1) {
104 //mdclog_write(MDCLOG_ERR, "Error binding. %s", strerror(errno));
107 if (mdclog_level_get() >= MDCLOG_DEBUG) {
108 struct sockaddr_in6 cliaddr {};
109 socklen_t len = sizeof(cliaddr);
110 getsockname(sctpParams.listenFD, (SA *)&cliaddr, &len);
112 inet_ntop(AF_INET6, &cliaddr.sin6_addr, buff, sizeof(buff));
113 mdclog_write(MDCLOG_DEBUG, "My address: %s, port %d\n", buff, htons(cliaddr.sin6_port));
116 if (listen(sctpParams.listenFD, SOMAXCONN) < 0) {
117 mdclog_write(MDCLOG_ERR, "Error listening. %s\n", strerror(errno));
120 struct epoll_event event {};
121 event.events = EPOLLIN | EPOLLET;
122 event.data.fd = sctpParams.listenFD;
124 // add listening port to epoll
125 if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.listenFD, &event)) {
126 printf("Failed to add descriptor to epoll\n");
127 mdclog_write(MDCLOG_ERR, "Failed to add descriptor to epoll. %s\n", strerror(errno));
134 int buildConfiguration(sctp_params_t &sctpParams) {
135 path p = (sctpParams.configFilePath + "/" + sctpParams.configFileName).c_str();
137 const int size = 2048;
138 auto fileSize = file_size(p);
139 if (fileSize > size) {
140 mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size);
144 mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str());
149 if (conf.openConfigFile(p.string()) == -1) {
150 mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s",
151 p.string().c_str(), strerror(errno));
154 int rmrPort = conf.getIntValue("nano");
156 mdclog_write(MDCLOG_ERR, "illigal RMR port ");
159 sctpParams.rmrPort = (uint16_t)rmrPort;
160 snprintf(sctpParams.rmrAddress, sizeof(sctpParams.rmrAddress), "%d", (int) (sctpParams.rmrPort));
162 auto tmpStr = conf.getStringValue("loglevel");
163 if (tmpStr.length() == 0) {
164 mdclog_write(MDCLOG_ERR, "illigal loglevel. Set loglevel to MDCLOG_INFO");
167 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
169 if ((tmpStr.compare("debug")) == 0) {
170 sctpParams.logLevel = MDCLOG_DEBUG;
171 } else if ((tmpStr.compare("info")) == 0) {
172 sctpParams.logLevel = MDCLOG_INFO;
173 } else if ((tmpStr.compare("warning")) == 0) {
174 sctpParams.logLevel = MDCLOG_WARN;
175 } else if ((tmpStr.compare("error")) == 0) {
176 sctpParams.logLevel = MDCLOG_ERR;
178 mdclog_write(MDCLOG_ERR, "illigal loglevel = %s. Set loglevel to MDCLOG_INFO", tmpStr.c_str());
179 sctpParams.logLevel = MDCLOG_INFO;
181 mdclog_level_set(sctpParams.logLevel);
183 tmpStr = conf.getStringValue("volume");
184 if (tmpStr.length() == 0) {
185 mdclog_write(MDCLOG_ERR, "illigal volume.");
189 char tmpLogFilespec[VOLUME_URL_SIZE];
190 tmpLogFilespec[0] = 0;
191 sctpParams.volume[0] = 0;
192 snprintf(sctpParams.volume, VOLUME_URL_SIZE, "%s", tmpStr.c_str());
193 // copy the name to temp file as well
194 snprintf(tmpLogFilespec, VOLUME_URL_SIZE, "%s", tmpStr.c_str());
197 // define the file name in the tmp directory under the volume
198 strcat(tmpLogFilespec,"/tmp/E2Term_%Y-%m-%d_%H-%M-%S.%N.tmpStr");
200 sctpParams.myIP = conf.getStringValue("local-ip");
201 if (sctpParams.myIP.length() == 0) {
202 mdclog_write(MDCLOG_ERR, "illigal local-ip.");
206 int sctpPort = conf.getIntValue("sctp-port");
207 if (sctpPort == -1) {
208 mdclog_write(MDCLOG_ERR, "illigal SCTP port ");
211 sctpParams.sctpPort = (uint16_t)sctpPort;
213 sctpParams.fqdn = conf.getStringValue("external-fqdn");
214 if (sctpParams.fqdn.length() == 0) {
215 mdclog_write(MDCLOG_ERR, "illigal external-fqdn");
219 std::string pod = conf.getStringValue("pod_name");
220 if (pod.length() == 0) {
221 mdclog_write(MDCLOG_ERR, "illigal pod_name in config file");
224 auto *podName = getenv(pod.c_str());
225 if (podName == nullptr) {
226 mdclog_write(MDCLOG_ERR, "illigal pod_name or environment varible not exists : %s", pod.c_str());
230 sctpParams.podName.assign(podName);
231 if (sctpParams.podName.length() == 0) {
232 mdclog_write(MDCLOG_ERR, "illigal pod_name");
237 tmpStr = conf.getStringValue("trace");
238 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
239 if ((tmpStr.compare("start")) == 0) {
240 mdclog_write(MDCLOG_INFO, "Trace set to: start");
241 sctpParams.trace = true;
242 } else if ((tmpStr.compare("stop")) == 0) {
243 mdclog_write(MDCLOG_INFO, "Trace set to: stop");
244 sctpParams.trace = false;
246 jsonTrace = sctpParams.trace;
248 sctpParams.ka_message_length = snprintf(sctpParams.ka_message, KA_MESSAGE_SIZE, "{\"address\": \"%s:%d\","
250 "\"pod_name\": \"%s\"}",
251 (const char *)sctpParams.myIP.c_str(),
253 sctpParams.fqdn.c_str(),
254 sctpParams.podName.c_str());
256 if (mdclog_level_get() >= MDCLOG_INFO) {
257 mdclog_mdc_add("RMR Port", to_string(sctpParams.rmrPort).c_str());
258 mdclog_mdc_add("LogLevel", to_string(sctpParams.logLevel).c_str());
259 mdclog_mdc_add("volume", sctpParams.volume);
260 mdclog_mdc_add("tmpLogFilespec", tmpLogFilespec);
261 mdclog_mdc_add("my ip", sctpParams.myIP.c_str());
262 mdclog_mdc_add("pod name", sctpParams.podName.c_str());
264 mdclog_write(MDCLOG_INFO, "running parameters for instance : %s", sctpParams.ka_message);
268 // Files written to the current working directory
269 boostLogger = logging::add_file_log(
270 keywords::file_name = tmpLogFilespec, // to temp directory
271 keywords::rotation_size = 10 * 1024 * 1024,
272 keywords::time_based_rotation = sinks::file::rotation_at_time_interval(posix_time::hours(1)),
273 keywords::format = "%Message%"
274 //keywords::format = "[%TimeStamp%]: %Message%" // use each tmpStr with time stamp
277 // Setup a destination folder for collecting rotated (closed) files --since the same volumn can use rename()
278 boostLogger->locked_backend()->set_file_collector(sinks::file::make_collector(
279 keywords::target = sctpParams.volume
282 // Upon restart, scan the directory for files matching the file_name pattern
283 boostLogger->locked_backend()->scan_for_files();
285 // Enable auto-flushing after each tmpStr record written
286 if (mdclog_level_get() >= MDCLOG_DEBUG) {
287 boostLogger->locked_backend()->auto_flush(true);
295 int main(const int argc, char **argv) {
296 sctp_params_t sctpParams;
299 std::random_device device{};
300 std::mt19937 generator(device());
301 std::uniform_int_distribution<long> distribution(1, (long) 1e12);
302 transactionCounter = distribution(generator);
306 // uint32_t aux1 = 0;
307 // st = rdtscp(aux1);
309 unsigned num_cpus = std::thread::hardware_concurrency();
311 mdclog_level_set(MDCLOG_INFO);
313 if (std::signal(SIGINT, catch_function) == SIG_ERR) {
314 mdclog_write(MDCLOG_ERR, "Error initializing SIGINT");
317 if (std::signal(SIGABRT, catch_function)== SIG_ERR) {
318 mdclog_write(MDCLOG_ERR, "Error initializing SIGABRT");
321 if (std::signal(SIGTERM, catch_function)== SIG_ERR) {
322 mdclog_write(MDCLOG_ERR, "Error initializing SIGTERM");
326 cpuClock = approx_CPU_MHz(100);
328 mdclog_write(MDCLOG_DEBUG, "CPU speed %11.11f", cpuClock);
330 auto result = parse(argc, argv, sctpParams);
332 if (buildConfiguration(sctpParams) != 0) {
337 sctpParams.epoll_fd = epoll_create1(0);
338 if (sctpParams.epoll_fd == -1) {
339 mdclog_write(MDCLOG_ERR, "failed to open epoll descriptor");
343 getRmrContext(sctpParams);
344 if (sctpParams.rmrCtx == nullptr) {
345 close(sctpParams.epoll_fd);
349 if (buildInotify(sctpParams) == -1) {
350 close(sctpParams.rmrListenFd);
351 rmr_close(sctpParams.rmrCtx);
352 close(sctpParams.epoll_fd);
356 if (buildListeningPort(sctpParams) != 0) {
357 close(sctpParams.rmrListenFd);
358 rmr_close(sctpParams.rmrCtx);
359 close(sctpParams.epoll_fd);
363 sctpParams.sctpMap = new mapWrapper();
365 std::vector<std::thread> threads(num_cpus);
366 // std::vector<std::thread> threads;
369 for (unsigned int i = 0; i < num_cpus; i++) {
370 threads[i] = std::thread(listener, &sctpParams);
375 int rc = pthread_setaffinity_np(threads[i].native_handle(), sizeof(cpu_set_t), &cpuset);
377 mdclog_write(MDCLOG_ERR, "Error calling pthread_setaffinity_np: %d", rc);
381 auto statFlag = false;
382 auto statThread = std::thread(statColectorThread, (void *)&statFlag);
384 //loop over term_init until first message from xApp
385 handleTermInit(sctpParams);
387 for (auto &t : threads) {
397 void handleTermInit(sctp_params_t &sctpParams) {
398 sendTermInit(sctpParams);
399 //send to e2 manager init of e2 term
404 auto xappMessages = num_of_XAPP_messages.load(std::memory_order_acquire);
405 if (xappMessages > 0) {
406 if (mdclog_level_get() >= MDCLOG_INFO) {
407 mdclog_write(MDCLOG_INFO, "Got a message from some appliction, stop sending E2_TERM_INIT");
413 if (count % 1000 == 0) {
414 mdclog_write(MDCLOG_ERR, "GOT No messages from any xApp");
415 sendTermInit(sctpParams);
420 void sendTermInit(sctp_params_t &sctpParams) {
421 rmr_mbuf_t *msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.ka_message_length);
424 msg->mtype = E2_TERM_INIT;
426 rmr_bytes2payload(msg, (unsigned char *)sctpParams.ka_message, sctpParams.ka_message_length);
427 static unsigned char tx[32];
428 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
429 rmr_bytes2xact(msg, tx, txLen);
430 msg = rmr_send_msg(sctpParams.rmrCtx, msg);
431 if (msg == nullptr) {
432 msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.myIP.length());
433 } else if (msg->state == 0) {
435 if (mdclog_level_get() >= MDCLOG_INFO) {
436 mdclog_write(MDCLOG_INFO, "E2_TERM_INIT succsesfuly sent ");
440 if (count % 100 == 0) {
441 mdclog_write(MDCLOG_ERR, "Error sending E2_TERM_INIT cause : %s ", translateRmrErrorMessages(msg->state).c_str());
456 cxxopts::ParseResult parse(int argc, char *argv[], sctp_params_t &sctpParams) {
457 cxxopts::Options options(argv[0], "e2 term help");
458 options.positional_help("[optional args]").show_positional_help();
459 options.allow_unrecognised_options().add_options()
460 ("p,path", "config file path", cxxopts::value<std::string>(sctpParams.configFilePath)->default_value("config"))
461 ("f,file", "config file name", cxxopts::value<std::string>(sctpParams.configFileName)->default_value("config.conf"))
462 ("h,help", "Print help");
464 auto result = options.parse(argc, argv);
466 if (result.count("help")) {
467 std::cout << options.help({""}) << std::endl;
476 * @return -1 failed 0 success
478 int buildInotify(sctp_params_t &sctpParams) {
479 sctpParams.inotifyFD = inotify_init1(IN_NONBLOCK);
480 if (sctpParams.inotifyFD == -1) {
481 mdclog_write(MDCLOG_ERR, "Failed to init inotify (inotify_init1) %s", strerror(errno));
482 close(sctpParams.rmrListenFd);
483 rmr_close(sctpParams.rmrCtx);
484 close(sctpParams.epoll_fd);
488 sctpParams.inotifyWD = inotify_add_watch(sctpParams.inotifyFD,
489 (const char *)sctpParams.configFilePath.c_str(),
490 (unsigned)IN_OPEN | (unsigned)IN_CLOSE_WRITE | (unsigned)IN_CLOSE_NOWRITE); //IN_CLOSE = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)
491 if (sctpParams.inotifyWD == -1) {
492 mdclog_write(MDCLOG_ERR, "Failed to add directory : %s to inotify (inotify_add_watch) %s",
493 sctpParams.configFilePath.c_str(),
495 close(sctpParams.inotifyFD);
499 struct epoll_event event{};
500 event.events = (EPOLLIN);
501 event.data.fd = sctpParams.inotifyFD;
502 // add listening RMR FD to epoll
503 if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.inotifyFD, &event)) {
504 mdclog_write(MDCLOG_ERR, "Failed to add inotify FD to epoll");
505 close(sctpParams.inotifyFD);
516 void listener(sctp_params_t *params) {
517 int num_of_SCTP_messages = 0;
518 auto totalTime = 0.0;
520 mdclog_level_set(params->logLevel);
522 std::thread::id this_id = std::this_thread::get_id();
524 streambuf *oldCout = cout.rdbuf();
525 ostringstream memCout;
527 cout.rdbuf(memCout.rdbuf());
529 //return to the normal cout
533 memcpy(tid, memCout.str().c_str(), memCout.str().length() < 32 ? memCout.str().length() : 31);
534 tid[memCout.str().length()] = 0;
535 mdclog_mdc_add("thread id", tid);
537 if (mdclog_level_get() >= MDCLOG_DEBUG) {
538 mdclog_write(MDCLOG_DEBUG, "started thread number %s", tid);
542 RmrMessagesBuffer_t rmrMessageBuffer{};
543 //create and init RMR
544 rmrMessageBuffer.rmrCtx = params->rmrCtx;
546 auto *events = (struct epoll_event *) calloc(MAXEVENTS, sizeof(struct epoll_event));
547 struct timespec end{0, 0};
548 struct timespec start{0, 0};
550 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
551 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
553 memcpy(rmrMessageBuffer.ka_message, params->ka_message, params->ka_message_length);
554 rmrMessageBuffer.ka_message_len = params->ka_message_length;
555 rmrMessageBuffer.ka_message[rmrMessageBuffer.ka_message_len] = 0;
557 if (mdclog_level_get() >= MDCLOG_DEBUG) {
558 mdclog_write(MDCLOG_DEBUG, "keep alive message is : %s", rmrMessageBuffer.ka_message);
561 ReportingMessages_t message {};
563 // for (int i = 0; i < MAX_RMR_BUFF_ARRY; i++) {
564 // rmrMessageBuffer.rcvBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
565 // rmrMessageBuffer.sendBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
568 message.statCollector = StatCollector::GetInstance();
571 if (mdclog_level_get() >= MDCLOG_DEBUG) {
572 mdclog_write(MDCLOG_DEBUG, "Start EPOLL Wait");
574 auto numOfEvents = epoll_wait(params->epoll_fd, events, MAXEVENTS, -1);
575 if (numOfEvents < 0 && errno == EINTR) {
576 if (mdclog_level_get() >= MDCLOG_DEBUG) {
577 mdclog_write(MDCLOG_DEBUG, "got EINTR : %s", strerror(errno));
581 if (numOfEvents < 0) {
582 mdclog_write(MDCLOG_ERR, "Epoll wait failed, errno = %s", strerror(errno));
585 for (auto i = 0; i < numOfEvents; i++) {
586 if (mdclog_level_get() >= MDCLOG_DEBUG) {
587 mdclog_write(MDCLOG_DEBUG, "handling epoll event %d out of %d", i + 1, numOfEvents);
589 clock_gettime(CLOCK_MONOTONIC, &message.message.time);
590 start.tv_sec = message.message.time.tv_sec;
591 start.tv_nsec = message.message.time.tv_nsec;
594 if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP)) {
595 handlepoll_error(events[i], message, rmrMessageBuffer, params);
596 } else if (events[i].events & EPOLLOUT) {
597 handleEinprogressMessages(events[i], message, rmrMessageBuffer, params);
598 } else if (params->listenFD == events[i].data.fd) {
599 if (mdclog_level_get() >= MDCLOG_INFO) {
600 mdclog_write(MDCLOG_INFO, "New connection request from sctp network\n");
602 // new connection is requested from RAN start build connection
604 struct sockaddr in_addr {};
606 char hostBuff[NI_MAXHOST];
607 char portBuff[NI_MAXSERV];
609 in_len = sizeof(in_addr);
610 auto *peerInfo = (ConnectedCU_t *)calloc(1, sizeof(ConnectedCU_t));
611 peerInfo->sctpParams = params;
612 peerInfo->fileDescriptor = accept(params->listenFD, &in_addr, &in_len);
613 if (peerInfo->fileDescriptor == -1) {
614 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
615 /* We have processed all incoming connections. */
618 mdclog_write(MDCLOG_ERR, "Accept error, errno = %s", strerror(errno));
622 if (setSocketNoBlocking(peerInfo->fileDescriptor) == -1) {
623 mdclog_write(MDCLOG_ERR, "setSocketNoBlocking failed to set new connection %s on port %s\n", hostBuff, portBuff);
624 close(peerInfo->fileDescriptor);
627 auto ans = getnameinfo(&in_addr, in_len,
628 peerInfo->hostName, NI_MAXHOST,
629 peerInfo->portNumber, NI_MAXSERV, (unsigned )((unsigned int)NI_NUMERICHOST | (unsigned int)NI_NUMERICSERV));
631 mdclog_write(MDCLOG_ERR, "Failed to get info on connection request. %s\n", strerror(errno));
632 close(peerInfo->fileDescriptor);
635 if (mdclog_level_get() >= MDCLOG_DEBUG) {
636 mdclog_write(MDCLOG_DEBUG, "Accepted connection on descriptor %d (host=%s, port=%s)\n", peerInfo->fileDescriptor, peerInfo->hostName, peerInfo->portNumber);
638 peerInfo->isConnected = false;
639 peerInfo->gotSetup = false;
640 if (addToEpoll(params->epoll_fd,
643 params->sctpMap, nullptr,
649 } else if (params->rmrListenFd == events[i].data.fd) {
650 // got message from XAPP
651 num_of_XAPP_messages.fetch_add(1, std::memory_order_release);
652 num_of_messages.fetch_add(1, std::memory_order_release);
653 if (mdclog_level_get() >= MDCLOG_DEBUG) {
654 mdclog_write(MDCLOG_DEBUG, "new message from RMR");
656 if (receiveXappMessages(params->sctpMap,
658 message.message.time) != 0) {
659 mdclog_write(MDCLOG_ERR, "Error handling Xapp message");
661 } else if (params->inotifyFD == events[i].data.fd) {
662 mdclog_write(MDCLOG_INFO, "Got event from inotify (configuration update)");
663 handleConfigChange(params);
665 /* We RMR_ERR_RETRY have data on the fd waiting to be read. Read and display it.
666 * We must read whatever data is available completely, as we are running
667 * in edge-triggered mode and won't get a notification again for the same data. */
668 num_of_messages.fetch_add(1, std::memory_order_release);
669 if (mdclog_level_get() >= MDCLOG_DEBUG) {
670 mdclog_write(MDCLOG_DEBUG, "new message from SCTP, epoll flags are : %0x", events[i].events);
672 receiveDataFromSctp(&events[i],
674 num_of_SCTP_messages,
676 message.message.time);
679 clock_gettime(CLOCK_MONOTONIC, &end);
680 if (mdclog_level_get() >= MDCLOG_INFO) {
681 totalTime += ((end.tv_sec + 1.0e-9 * end.tv_nsec) -
682 ((double) start.tv_sec + 1.0e-9 * start.tv_nsec));
684 if (mdclog_level_get() >= MDCLOG_DEBUG) {
685 mdclog_write(MDCLOG_DEBUG, "message handling is %ld seconds %ld nanoseconds",
686 end.tv_sec - start.tv_sec,
687 end.tv_nsec - start.tv_nsec);
697 void handleConfigChange(sctp_params_t *sctpParams) {
698 char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event))));
699 const struct inotify_event *event;
702 path p = (sctpParams->configFilePath + "/" + sctpParams->configFileName).c_str();
703 auto endlessLoop = true;
704 while (endlessLoop) {
705 auto len = read(sctpParams->inotifyFD, buf, sizeof buf);
707 if (errno != EAGAIN) {
708 mdclog_write(MDCLOG_ERR, "read %s ", strerror(errno));
718 for (ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + event->len) {
719 event = (const struct inotify_event *)ptr;
720 if (event->mask & (uint32_t)IN_ISDIR) {
724 // the directory name
725 if (sctpParams->inotifyWD == event->wd) {
729 auto retVal = strcmp(sctpParams->configFileName.c_str(), event->name);
734 // only the file we want
735 if (event->mask & (uint32_t)IN_CLOSE_WRITE) {
736 if (mdclog_level_get() >= MDCLOG_INFO) {
737 mdclog_write(MDCLOG_INFO, "Configuration file changed");
740 const int size = 2048;
741 auto fileSize = file_size(p);
742 if (fileSize > size) {
743 mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size);
747 mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str());
752 if (conf.openConfigFile(p.string()) == -1) {
753 mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s",
754 p.string().c_str(), strerror(errno));
758 auto tmpStr = conf.getStringValue("loglevel");
759 if (tmpStr.length() == 0) {
760 mdclog_write(MDCLOG_ERR, "illigal loglevel. Set loglevel to MDCLOG_INFO");
763 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
765 if ((tmpStr.compare("debug")) == 0) {
766 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_DEBUG");
767 sctpParams->logLevel = MDCLOG_DEBUG;
768 } else if ((tmpStr.compare("info")) == 0) {
769 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_INFO");
770 sctpParams->logLevel = MDCLOG_INFO;
771 } else if ((tmpStr.compare("warning")) == 0) {
772 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_WARN");
773 sctpParams->logLevel = MDCLOG_WARN;
774 } else if ((tmpStr.compare("error")) == 0) {
775 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_ERR");
776 sctpParams->logLevel = MDCLOG_ERR;
778 mdclog_write(MDCLOG_ERR, "illigal loglevel = %s. Set loglevel to MDCLOG_INFO", tmpStr.c_str());
779 sctpParams->logLevel = MDCLOG_INFO;
781 mdclog_level_set(sctpParams->logLevel);
784 tmpStr = conf.getStringValue("trace");
785 if (tmpStr.length() == 0) {
786 mdclog_write(MDCLOG_ERR, "illigal trace. Set trace to stop");
790 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
791 if ((tmpStr.compare("start")) == 0) {
792 mdclog_write(MDCLOG_INFO, "Trace set to: start");
793 sctpParams->trace = true;
794 } else if ((tmpStr.compare("stop")) == 0) {
795 mdclog_write(MDCLOG_INFO, "Trace set to: stop");
796 sctpParams->trace = false;
798 mdclog_write(MDCLOG_ERR, "Trace was set to wrong value %s, set to stop", tmpStr.c_str());
799 sctpParams->trace = false;
801 jsonTrace = sctpParams->trace;
812 * @param rmrMessageBuffer
815 void handleEinprogressMessages(struct epoll_event &event,
816 ReportingMessages_t &message,
817 RmrMessagesBuffer_t &rmrMessageBuffer,
818 sctp_params_t *params) {
819 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
820 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
822 mdclog_write(MDCLOG_INFO, "file descriptor %d got EPOLLOUT", peerInfo->fileDescriptor);
824 socklen_t retValLen = 0;
825 auto rc = getsockopt(peerInfo->fileDescriptor, SOL_SOCKET, SO_ERROR, &retVal, &retValLen);
826 if (rc != 0 || retVal != 0) {
828 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
829 "%s|Failed SCTP Connection, after EINPROGRESS the getsockopt%s",
830 peerInfo->enodbName, strerror(errno));
831 } else if (retVal != 0) {
832 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
833 "%s|Failed SCTP Connection after EINPROGRESS, SO_ERROR",
834 peerInfo->enodbName);
837 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
838 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
839 mdclog_write(MDCLOG_ERR, "%s", rmrMessageBuffer.sendMessage->payload);
840 message.message.direction = 'N';
841 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
842 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
844 memset(peerInfo->asnData, 0, peerInfo->asnLength);
845 peerInfo->asnLength = 0;
850 peerInfo->isConnected = true;
852 if (modifyToEpoll(params->epoll_fd, peerInfo, (EPOLLIN | EPOLLET), params->sctpMap, peerInfo->enodbName,
853 peerInfo->mtype) != 0) {
854 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_MOD");
858 message.message.asndata = (unsigned char *)peerInfo->asnData;
859 message.message.asnLength = peerInfo->asnLength;
860 message.message.messageType = peerInfo->mtype;
861 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
862 num_of_messages.fetch_add(1, std::memory_order_release);
863 if (mdclog_level_get() >= MDCLOG_DEBUG) {
864 mdclog_write(MDCLOG_DEBUG, "send the delayed SETUP/ENDC SETUP to sctp for %s",
865 message.message.enodbName);
867 if (sendSctpMsg(peerInfo, message, params->sctpMap) != 0) {
868 if (mdclog_level_get() >= MDCLOG_DEBUG) {
869 mdclog_write(MDCLOG_DEBUG, "Error write to SCTP %s %d", __func__, __LINE__);
874 memset(peerInfo->asnData, 0, peerInfo->asnLength);
875 peerInfo->asnLength = 0;
880 void handlepoll_error(struct epoll_event &event,
881 ReportingMessages_t &message,
882 RmrMessagesBuffer_t &rmrMessageBuffer,
883 sctp_params_t *params) {
884 if (event.data.fd != params->rmrListenFd) {
885 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
886 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on fd %d, RAN NAME : %s",
887 event.events, peerInfo->fileDescriptor, peerInfo->enodbName);
889 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
890 "%s|Failed SCTP Connection",
891 peerInfo->enodbName);
892 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
893 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
895 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
896 message.message.direction = 'N';
897 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
898 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
901 close(peerInfo->fileDescriptor);
902 params->sctpMap->erase(peerInfo->enodbName);
903 cleanHashEntry((ConnectedCU_t *) event.data.ptr, params->sctpMap);
905 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on RMR FD", event.events);
913 int setSocketNoBlocking(int socket) {
914 auto flags = fcntl(socket, F_GETFL, 0);
917 mdclog_mdc_add("func", "fcntl");
918 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
923 flags = (unsigned) flags | (unsigned) O_NONBLOCK;
924 if (fcntl(socket, F_SETFL, flags) == -1) {
925 mdclog_mdc_add("func", "fcntl");
926 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
939 void cleanHashEntry(ConnectedCU_t *val, Sctp_Map_t *m) {
941 auto port = (uint16_t) strtol(val->portNumber, &dummy, 10);
942 char searchBuff[2048]{};
944 snprintf(searchBuff, sizeof searchBuff, "host:%s:%d", val->hostName, port);
945 m->erase(searchBuff);
947 m->erase(val->enodbName);
953 * @param fd file discriptor
954 * @param data the asn data to send
955 * @param len length of the data
956 * @param enodbName the enodbName as in the map for printing purpose
957 * @param m map host information
958 * @param mtype message number
959 * @return 0 success, anegative number on fail
961 int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_t *m) {
962 auto loglevel = mdclog_level_get();
963 int fd = peerInfo->fileDescriptor;
964 if (loglevel >= MDCLOG_DEBUG) {
965 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for CU %s, %s",
966 message.message.enodbName, __FUNCTION__);
970 if (send(fd,message.message.asndata, message.message.asnLength,MSG_NOSIGNAL) < 0) {
971 if (errno == EINTR) {
974 mdclog_write(MDCLOG_ERR, "error writing to CU a message, %s ", strerror(errno));
975 if (!peerInfo->isConnected) {
976 mdclog_write(MDCLOG_ERR, "connection to CU %s is still in progress.", message.message.enodbName);
979 cleanHashEntry(peerInfo, m);
981 char key[MAX_ENODB_NAME_SIZE * 2];
982 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName,
983 message.message.messageType);
984 if (loglevel >= MDCLOG_DEBUG) {
985 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
987 auto tmp = m->find(key);
994 message.statCollector->incSentMessage(string(message.message.enodbName));
995 message.message.direction = 'D';
996 // send report.buffer of size
997 buildJsonMessage(message);
999 if (loglevel >= MDCLOG_DEBUG) {
1000 mdclog_write(MDCLOG_DEBUG,
1001 "SCTP message for CU %s sent from %s",
1002 message.message.enodbName,
1012 * @param rmrMessageBuffer
1014 void getRequestMetaData(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
1015 rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *) (message.message.enodbName));
1017 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
1018 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
1020 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1021 mdclog_write(MDCLOG_DEBUG, "Message from Xapp RAN name = %s message length = %ld",
1022 message.message.enodbName, (unsigned long) message.message.asnLength);
1032 * @param numOfMessages
1033 * @param rmrMessageBuffer
1037 int receiveDataFromSctp(struct epoll_event *events,
1038 Sctp_Map_t *sctpMap,
1040 RmrMessagesBuffer_t &rmrMessageBuffer,
1041 struct timespec &ts) {
1042 /* We have data on the fd waiting to be read. Read and display it.
1043 * We must read whatever data is available completely, as we are running
1044 * in edge-triggered mode and won't get a notification again for the same data. */
1045 ReportingMessages_t message {};
1047 auto loglevel = mdclog_level_get();
1049 // get the identity of the interface
1050 message.peerInfo = (ConnectedCU_t *)events->data.ptr;
1052 message.statCollector = StatCollector::GetInstance();
1053 struct timespec start{0, 0};
1054 struct timespec decodestart{0, 0};
1055 struct timespec end{0, 0};
1057 E2AP_PDU_t *pdu = nullptr;
1061 if (loglevel >= MDCLOG_DEBUG) {
1062 mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP %d fd", message.peerInfo->fileDescriptor);
1063 clock_gettime(CLOCK_MONOTONIC, &start);
1065 // read the buffer directly to rmr payload
1066 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1067 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
1068 read(message.peerInfo->fileDescriptor, rmrMessageBuffer.sendMessage->payload, RECEIVE_SCTP_BUFFER_SIZE);
1070 if (loglevel >= MDCLOG_DEBUG) {
1071 mdclog_write(MDCLOG_DEBUG, "Finish Read from SCTP %d fd message length = %ld",
1072 message.peerInfo->fileDescriptor, message.message.asnLength);
1075 memcpy(message.message.enodbName, message.peerInfo->enodbName, sizeof(message.peerInfo->enodbName));
1076 message.statCollector->incRecvMessage(string(message.message.enodbName));
1077 message.message.direction = 'U';
1078 message.message.time.tv_nsec = ts.tv_nsec;
1079 message.message.time.tv_sec = ts.tv_sec;
1081 if (message.message.asnLength < 0) {
1082 if (errno == EINTR) {
1085 /* If errno == EAGAIN, that means we have read all
1086 data. So goReportingMessages_t back to the main loop. */
1087 if (errno != EAGAIN) {
1088 mdclog_write(MDCLOG_ERR, "Read error, %s ", strerror(errno));
1090 } else if (loglevel >= MDCLOG_DEBUG) {
1091 mdclog_write(MDCLOG_DEBUG, "EAGAIN - descriptor = %d", message.peerInfo->fileDescriptor);
1094 } else if (message.message.asnLength == 0) {
1095 /* End of file. The remote has closed the connection. */
1096 if (loglevel >= MDCLOG_INFO) {
1097 mdclog_write(MDCLOG_INFO, "END of File Closed connection - descriptor = %d",
1098 message.peerInfo->fileDescriptor);
1104 if (loglevel >= MDCLOG_DEBUG) {
1105 char printBuffer[4096]{};
1106 char *tmp = printBuffer;
1107 for (size_t i = 0; i < (size_t)message.message.asnLength; ++i) {
1108 snprintf(tmp, 3, "%02x", message.message.asndata[i]);
1111 printBuffer[message.message.asnLength] = 0;
1112 clock_gettime(CLOCK_MONOTONIC, &end);
1113 mdclog_write(MDCLOG_DEBUG, "Before Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds",
1114 message.peerInfo->enodbName, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
1115 mdclog_write(MDCLOG_DEBUG, "PDU buffer length = %ld, data = : %s", message.message.asnLength,
1117 clock_gettime(CLOCK_MONOTONIC, &decodestart);
1120 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu,
1121 message.message.asndata, message.message.asnLength);
1122 if (rval.code != RC_OK) {
1123 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from RAN : %s", rval.code,
1124 message.peerInfo->enodbName);
1125 //todo may need reset to pdu
1129 if (loglevel >= MDCLOG_DEBUG) {
1130 clock_gettime(CLOCK_MONOTONIC, &end);
1131 mdclog_write(MDCLOG_DEBUG, "After Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds",
1132 message.peerInfo->enodbName, end.tv_sec - decodestart.tv_sec, end.tv_nsec - decodestart.tv_nsec);
1135 FILE *stream = open_memstream(&printBuffer, &size);
1136 asn_fprint(stream, &asn_DEF_E2AP_PDU, pdu);
1137 mdclog_write(MDCLOG_DEBUG, "Encoding E2AP PDU past : %s", printBuffer);
1138 clock_gettime(CLOCK_MONOTONIC, &decodestart);
1141 switch (pdu->present) {
1142 case E2AP_PDU_PR_initiatingMessage: {//initiating message
1143 asnInitiatingRequest(pdu, sctpMap,message, rmrMessageBuffer);
1146 case E2AP_PDU_PR_successfulOutcome: { //successful outcome
1147 asnSuccsesfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
1150 case E2AP_PDU_PR_unsuccessfulOutcome: { //Unsuccessful Outcome
1151 asnUnSuccsesfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
1155 mdclog_write(MDCLOG_ERR, "Unknown index %d in E2AP PDU", pdu->present);
1158 if (loglevel >= MDCLOG_DEBUG) {
1159 clock_gettime(CLOCK_MONOTONIC, &end);
1160 mdclog_write(MDCLOG_DEBUG,
1161 "After processing message and sent to rmr for : %s, Read time is : %ld seconds, %ld nanoseconds",
1162 message.peerInfo->enodbName, end.tv_sec - decodestart.tv_sec, end.tv_nsec - decodestart.tv_nsec);
1165 // remove the break for EAGAIN
1167 if (pdu != nullptr) {
1168 //TODO need to test ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); to get better performance
1169 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
1170 //ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1173 //clock_gettime(CLOCK_MONOTONIC, &start);
1175 // in case of break to avoid memory leak
1176 // if (pdu != nullptr) {
1177 // //ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1178 // ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
1183 if (loglevel >= MDCLOG_INFO) {
1184 mdclog_write(MDCLOG_INFO, "Closed connection - descriptor = %d", message.peerInfo->fileDescriptor);
1186 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
1187 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
1189 "%s|CU disconnected unexpectedly",
1190 message.peerInfo->enodbName);
1191 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1193 if (sendRequestToXapp(message,
1194 RIC_SCTP_CONNECTION_FAILURE,
1195 rmrMessageBuffer) != 0) {
1196 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1199 /* Closing descriptor make epoll remove it from the set of descriptors which are monitored. */
1200 close(message.peerInfo->fileDescriptor);
1201 cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap);
1203 if (loglevel >= MDCLOG_DEBUG) {
1204 clock_gettime(CLOCK_MONOTONIC, &end);
1205 mdclog_write(MDCLOG_DEBUG, "from receive SCTP to send RMR time is %ld seconds and %ld nanoseconds",
1206 end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
1212 static void buildAndsendSetupRequest(ReportingMessages_t &message,
1213 RmrMessagesBuffer_t &rmrMessageBuffer,
1215 auto logLevel = mdclog_level_get();
1217 // now we can send the data to e2Mgr
1218 auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1220 auto *rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size);
1221 // add addrees to message
1224 // unsigned char *buffer = &rmrMsg->payload[j];
1225 unsigned char buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
1227 auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size);
1228 if (er.encoded == -1) {
1229 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1230 } else if (er.encoded > (ssize_t) buffer_size) {
1231 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
1233 asn_DEF_E2AP_PDU.name, __func__, __LINE__);
1235 rmrMsg->len = snprintf((char *)rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s",
1236 message.peerInfo->sctpParams->myIP.c_str(),
1237 message.peerInfo->sctpParams->rmrPort,
1239 if (logLevel >= MDCLOG_DEBUG) {
1240 mdclog_write(MDCLOG_DEBUG, "Setup request of size %d :\n %s\n", rmrMsg->len, rmrMsg->payload);
1243 message.message.messageType = rmrMsg->mtype = RIC_E2_SETUP_REQ;
1245 rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName));
1247 static unsigned char tx[32];
1248 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1249 rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx));
1251 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
1252 if (rmrMsg == nullptr) {
1253 mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr");
1254 } else if (rmrMsg->state != 0) {
1255 char meid[RMR_MAX_MEID]{};
1256 if (rmrMsg->state == RMR_ERR_RETRY) {
1259 mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s",
1260 rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid));
1261 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
1262 if (rmrMsg == nullptr) {
1263 mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr");
1264 } else if (rmrMsg->state != 0) {
1265 mdclog_write(MDCLOG_ERR,
1266 "RMR Retry failed %s sending request %d to Xapp from %s",
1267 translateRmrErrorMessages(rmrMsg->state).c_str(),
1269 rmr_get_meid(rmrMsg, (unsigned char *) meid));
1272 mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s",
1273 translateRmrErrorMessages(rmrMsg->state).c_str(),
1275 rmr_get_meid(rmrMsg, (unsigned char *) meid));
1278 message.peerInfo->gotSetup = true;
1279 buildJsonMessage(message);
1280 if (rmrMsg != nullptr) {
1281 rmr_free_msg(rmrMsg);
1290 * @param rmrMessageBuffer
1292 void asnInitiatingRequest(E2AP_PDU_t *pdu,
1293 Sctp_Map_t *sctpMap,
1294 ReportingMessages_t &message,
1295 RmrMessagesBuffer_t &rmrMessageBuffer) {
1296 auto logLevel = mdclog_level_get();
1297 auto procedureCode = ((InitiatingMessage_t *) pdu->choice.initiatingMessage)->procedureCode;
1298 if (logLevel >= MDCLOG_DEBUG) {
1299 mdclog_write(MDCLOG_DEBUG, "Initiating message %ld\n", procedureCode);
1301 switch (procedureCode) {
1302 case ProcedureCode_id_E2setup: {
1303 if (logLevel >= MDCLOG_DEBUG) {
1304 mdclog_write(MDCLOG_DEBUG, "Got E2setup\n");
1307 // first get the message as XML buffer
1308 auto setup_xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1309 unsigned char setup_xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
1310 //unsigned char *tmp_buff_cursor = setup_xml_buffer;
1312 auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, setup_xml_buffer, setup_xml_buffer_size);
1313 if (er.encoded == -1) {
1314 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1315 } else if (er.encoded > (ssize_t) setup_xml_buffer_size) {
1316 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
1317 (int)setup_xml_buffer_size,
1318 asn_DEF_E2AP_PDU.name, __func__, __LINE__);
1320 std::string xmlString(setup_xml_buffer_size, setup_xml_buffer_size + er.encoded);
1322 auto failed = false;
1323 memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE);
1324 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) {
1325 auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i];
1326 if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) {
1327 // get the ran name for meid
1328 if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) {
1329 if (buildRanName(message.peerInfo->enodbName, ie) < 0) {
1330 mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n");
1331 // no mesage will be sent
1334 memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName));
1335 sctpMap->setkey(message.message.enodbName, message.peerInfo);
1338 // reformat RANFUNCTION Definition to XML
1339 if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
1340 if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) {
1341 for (auto j = 0; i < ie->value.choice.RANfunctions_List.list.count; i++) {
1342 auto *raNfunctionItemIEs = (RANfunction_ItemIEs_t *)ie->value.choice.RANfunctions_List.list.array[j];
1343 if (raNfunctionItemIEs->id == ProtocolIE_ID_id_RANfunction_Item &&
1344 (raNfunctionItemIEs->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item)) {
1346 E2SM_gNB_NRT_RANfunction_Definition_t *ranFunDef = nullptr;
1347 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER,
1348 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1349 (void **)&ranFunDef,
1350 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.buf,
1351 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.size);
1352 if (rval.code != RC_OK) {
1353 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2SM message from : %s",
1355 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name);
1360 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1363 FILE *stream = open_memstream(&printBuffer, &size);
1364 asn_fprint(stream, &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, ranFunDef);
1365 mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU past : %s",
1366 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1369 auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1370 unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
1372 er = asn_encode_to_buffer(nullptr,
1374 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1378 if (er.encoded == -1) {
1379 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s",
1380 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1382 } else if (er.encoded > (ssize_t)xml_buffer_size) {
1383 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
1384 (int) xml_buffer_size,
1385 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, __func__, __LINE__);
1387 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1388 mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU past : %s",
1389 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1392 //TODO replace the ranFunctionDefinition with the XML data
1407 //build all parts and send the XML (need to copy the XML with the header to the rmrMessageBuffer payload
1408 //TODO replace with new function
1409 buildAndsendSetupRequest(message, rmrMessageBuffer, pdu);
1412 case ProcedureCode_id_ErrorIndication: {
1413 if (logLevel >= MDCLOG_DEBUG) {
1414 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
1416 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
1417 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
1421 case ProcedureCode_id_Reset: {
1422 if (logLevel >= MDCLOG_DEBUG) {
1423 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
1425 if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) {
1426 mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP");
1430 case ProcedureCode_id_RICcontrol: {
1431 if (logLevel >= MDCLOG_DEBUG) {
1432 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
1436 case ProcedureCode_id_RICindication: {
1437 if (logLevel >= MDCLOG_DEBUG) {
1438 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
1440 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
1441 auto messageSent = false;
1442 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
1443 if (logLevel >= MDCLOG_DEBUG) {
1444 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1446 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1447 if (logLevel >= MDCLOG_DEBUG) {
1448 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1450 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
1451 static unsigned char tx[32];
1452 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
1453 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1454 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1455 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1456 (unsigned char *)message.message.enodbName,
1457 strlen(message.message.enodbName));
1458 rmrMessageBuffer.sendMessage->state = 0;
1459 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1460 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1461 mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d",
1462 rmrMessageBuffer.sendMessage->sub_id,
1463 rmrMessageBuffer.sendMessage->mtype);
1465 sendRmrMessage(rmrMessageBuffer, message);
1468 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1477 case ProcedureCode_id_RICserviceQuery: {
1478 if (logLevel >= MDCLOG_DEBUG) {
1479 mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName);
1483 case ProcedureCode_id_RICserviceUpdate: {
1484 if (logLevel >= MDCLOG_DEBUG) {
1485 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
1487 if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) {
1488 mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP");
1492 case ProcedureCode_id_RICsubscription: {
1493 if (logLevel >= MDCLOG_DEBUG) {
1494 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
1498 case ProcedureCode_id_RICsubscriptionDelete: {
1499 if (logLevel >= MDCLOG_DEBUG) {
1500 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
1505 mdclog_write(MDCLOG_ERR, "Undefined or not supported message = %ld", procedureCode);
1506 message.message.messageType = 0; // no RMR message type yet
1508 buildJsonMessage(message);
1519 * @param rmrMessageBuffer
1521 void asnSuccsesfulMsg(E2AP_PDU_t *pdu,
1522 Sctp_Map_t *sctpMap,
1523 ReportingMessages_t &message,
1524 RmrMessagesBuffer_t &rmrMessageBuffer) {
1525 auto procedureCode = pdu->choice.successfulOutcome->procedureCode;
1526 auto logLevel = mdclog_level_get();
1527 if (logLevel >= MDCLOG_INFO) {
1528 mdclog_write(MDCLOG_INFO, "Successful Outcome %ld", procedureCode);
1530 switch (procedureCode) {
1531 case ProcedureCode_id_E2setup: {
1532 if (logLevel >= MDCLOG_DEBUG) {
1533 mdclog_write(MDCLOG_DEBUG, "Got E2setup\n");
1537 case ProcedureCode_id_ErrorIndication: {
1538 if (logLevel >= MDCLOG_DEBUG) {
1539 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
1541 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
1542 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
1546 case ProcedureCode_id_Reset: {
1547 if (logLevel >= MDCLOG_DEBUG) {
1548 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
1550 if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) {
1551 mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP");
1555 case ProcedureCode_id_RICcontrol: {
1556 if (logLevel >= MDCLOG_DEBUG) {
1557 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
1560 i < pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; i++) {
1561 auto messageSent = false;
1562 RICcontrolAcknowledge_IEs_t *ie = pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[i];
1563 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1564 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1566 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1567 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1568 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1570 if (ie->value.present == RICcontrolAcknowledge_IEs__value_PR_RICrequestID) {
1571 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_ACK;
1572 rmrMessageBuffer.sendMessage->state = 0;
1573 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1574 static unsigned char tx[32];
1575 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1576 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1577 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1578 (unsigned char *)message.message.enodbName,
1579 strlen(message.message.enodbName));
1581 sendRmrMessage(rmrMessageBuffer, message);
1584 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1594 case ProcedureCode_id_RICindication: {
1595 if (logLevel >= MDCLOG_DEBUG) {
1596 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
1598 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
1599 auto messageSent = false;
1600 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
1601 if (logLevel >= MDCLOG_DEBUG) {
1602 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1604 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1605 if (logLevel >= MDCLOG_DEBUG) {
1606 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1608 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
1609 static unsigned char tx[32];
1610 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
1611 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1612 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1613 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1614 (unsigned char *)message.message.enodbName,
1615 strlen(message.message.enodbName));
1616 rmrMessageBuffer.sendMessage->state = 0;
1617 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1618 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1619 mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d",
1620 rmrMessageBuffer.sendMessage->sub_id,
1621 rmrMessageBuffer.sendMessage->mtype);
1623 sendRmrMessage(rmrMessageBuffer, message);
1626 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1635 case ProcedureCode_id_RICserviceQuery: {
1636 if (logLevel >= MDCLOG_DEBUG) {
1637 mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName);
1641 case ProcedureCode_id_RICserviceUpdate: {
1642 if (logLevel >= MDCLOG_DEBUG) {
1643 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
1645 if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) {
1646 mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP");
1650 case ProcedureCode_id_RICsubscription: {
1651 if (logLevel >= MDCLOG_DEBUG) {
1652 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
1654 if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer) != 0) {
1655 mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP");
1659 case ProcedureCode_id_RICsubscriptionDelete: {
1660 if (logLevel >= MDCLOG_DEBUG) {
1661 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
1663 if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer) != 0) {
1664 mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP");
1669 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
1670 message.message.messageType = 0; // no RMR message type yet
1671 buildJsonMessage(message);
1682 * @param rmrMessageBuffer
1684 void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu,
1685 Sctp_Map_t *sctpMap,
1686 ReportingMessages_t &message,
1687 RmrMessagesBuffer_t &rmrMessageBuffer) {
1688 auto procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode;
1689 auto logLevel = mdclog_level_get();
1690 if (logLevel >= MDCLOG_INFO) {
1691 mdclog_write(MDCLOG_INFO, "Unsuccessful Outcome %ld", procedureCode);
1693 switch (procedureCode) {
1694 case ProcedureCode_id_E2setup: {
1695 if (logLevel >= MDCLOG_DEBUG) {
1696 mdclog_write(MDCLOG_DEBUG, "Got E2setup\n");
1700 case ProcedureCode_id_ErrorIndication: {
1701 if (logLevel >= MDCLOG_DEBUG) {
1702 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
1704 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
1705 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
1709 case ProcedureCode_id_Reset: {
1710 if (logLevel >= MDCLOG_DEBUG) {
1711 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
1713 if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) {
1714 mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP");
1718 case ProcedureCode_id_RICcontrol: {
1719 if (logLevel >= MDCLOG_DEBUG) {
1720 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
1723 i < pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.count; i++) {
1724 auto messageSent = false;
1725 RICcontrolFailure_IEs_t *ie = pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.array[i];
1726 if (logLevel >= MDCLOG_DEBUG) {
1727 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1729 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1730 if (logLevel >= MDCLOG_DEBUG) {
1731 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1733 if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) {
1734 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_FAILURE;
1735 rmrMessageBuffer.sendMessage->state = 0;
1736 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1737 static unsigned char tx[32];
1738 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1739 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1740 rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName,
1741 strlen(message.message.enodbName));
1742 sendRmrMessage(rmrMessageBuffer, message);
1745 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1754 case ProcedureCode_id_RICindication: {
1755 if (logLevel >= MDCLOG_DEBUG) {
1756 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
1758 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
1759 auto messageSent = false;
1760 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
1761 if (logLevel >= MDCLOG_DEBUG) {
1762 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1764 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1765 if (logLevel >= MDCLOG_DEBUG) {
1766 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1768 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
1769 static unsigned char tx[32];
1770 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
1771 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1772 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1773 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1774 (unsigned char *)message.message.enodbName,
1775 strlen(message.message.enodbName));
1776 rmrMessageBuffer.sendMessage->state = 0;
1777 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1778 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1779 mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d",
1780 rmrMessageBuffer.sendMessage->sub_id,
1781 rmrMessageBuffer.sendMessage->mtype);
1783 sendRmrMessage(rmrMessageBuffer, message);
1786 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1795 case ProcedureCode_id_RICserviceQuery: {
1796 if (logLevel >= MDCLOG_DEBUG) {
1797 mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName);
1801 case ProcedureCode_id_RICserviceUpdate: {
1802 if (logLevel >= MDCLOG_DEBUG) {
1803 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
1805 if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) {
1806 mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP");
1810 case ProcedureCode_id_RICsubscription: {
1811 if (logLevel >= MDCLOG_DEBUG) {
1812 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
1814 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
1815 mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP");
1819 case ProcedureCode_id_RICsubscriptionDelete: {
1820 if (logLevel >= MDCLOG_DEBUG) {
1821 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
1823 if (sendRequestToXapp(message, RIC_SUB_DEL_FAILURE, rmrMessageBuffer) != 0) {
1824 mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP");
1829 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
1830 message.message.messageType = 0; // no RMR message type yet
1832 buildJsonMessage(message);
1843 * @param rmrMmessageBuffer
1846 int sendRequestToXapp(ReportingMessages_t &message,
1848 RmrMessagesBuffer_t &rmrMmessageBuffer) {
1849 rmr_bytes2meid(rmrMmessageBuffer.sendMessage,
1850 (unsigned char *)message.message.enodbName,
1851 strlen(message.message.enodbName));
1852 message.message.messageType = rmrMmessageBuffer.sendMessage->mtype = requestId;
1853 rmrMmessageBuffer.sendMessage->state = 0;
1854 static unsigned char tx[32];
1855 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1856 rmr_bytes2xact(rmrMmessageBuffer.sendMessage, tx, strlen((const char *) tx));
1858 auto rc = sendRmrMessage(rmrMmessageBuffer, message);
1863 void getRmrContext(sctp_params_t &pSctpParams) {
1864 pSctpParams.rmrCtx = nullptr;
1865 pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RMR_MAX_RCV_BYTES, RMRFL_NONE);
1866 if (pSctpParams.rmrCtx == nullptr) {
1867 mdclog_write(MDCLOG_ERR, "Failed to initialize RMR");
1871 rmr_set_stimeout(pSctpParams.rmrCtx, 0); // disable retries for any send operation
1872 // we need to find that routing table exist and we can run
1873 if (mdclog_level_get() >= MDCLOG_INFO) {
1874 mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready");
1879 if ((rmrReady = rmr_ready(pSctpParams.rmrCtx)) == 0) {
1883 if (count % 60 == 0) {
1884 mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count);
1887 if (mdclog_level_get() >= MDCLOG_INFO) {
1888 mdclog_write(MDCLOG_INFO, "RMR running");
1890 rmr_init_trace(pSctpParams.rmrCtx, 200);
1891 // get the RMR fd for the epoll
1892 pSctpParams.rmrListenFd = rmr_get_rcvfd(pSctpParams.rmrCtx);
1893 struct epoll_event event{};
1894 // add RMR fd to epoll
1895 event.events = (EPOLLIN);
1896 event.data.fd = pSctpParams.rmrListenFd;
1897 // add listening RMR FD to epoll
1898 if (epoll_ctl(pSctpParams.epoll_fd, EPOLL_CTL_ADD, pSctpParams.rmrListenFd, &event)) {
1899 mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll");
1900 close(pSctpParams.rmrListenFd);
1901 rmr_close(pSctpParams.rmrCtx);
1902 pSctpParams.rmrCtx = nullptr;
1906 int BuildPERSetupResponseMessaeFromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
1909 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1910 mdclog_write(MDCLOG_DEBUG, "got xml setup response \n %s\n", rmrMessageBuffer.rcvMessage->payload);
1912 auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &pdu,
1913 rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len);
1914 if (rval.code != RC_OK) {
1915 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
1917 message.message.enodbName);
1921 int buff_size = RECEIVE_XAPP_BUFFER_SIZE;
1922 auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu,
1923 rmrMessageBuffer.rcvMessage->payload, buff_size);
1924 if (er.encoded == -1) {
1925 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1927 } else if (er.encoded > (ssize_t)buff_size) {
1928 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d",
1929 (int)rmrMessageBuffer.rcvMessage->len,
1930 asn_DEF_E2AP_PDU.name,
1935 rmrMessageBuffer.rcvMessage->len = er.encoded;
1942 * @param rmrMessageBuffer
1946 int receiveXappMessages(Sctp_Map_t *sctpMap,
1947 RmrMessagesBuffer_t &rmrMessageBuffer,
1948 struct timespec &ts) {
1949 if (rmrMessageBuffer.rcvMessage == nullptr) {
1951 mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno));
1955 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1956 mdclog_write(MDCLOG_DEBUG, "Call to rmr_rcv_msg");
1958 rmrMessageBuffer.rcvMessage = rmr_rcv_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
1959 if (rmrMessageBuffer.rcvMessage == nullptr) {
1960 mdclog_write(MDCLOG_ERR, "RMR Receving message with null pointer, Realloc rmr mesage buffer");
1961 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
1964 ReportingMessages_t message;
1965 message.message.direction = 'D';
1966 message.message.time.tv_nsec = ts.tv_nsec;
1967 message.message.time.tv_sec = ts.tv_sec;
1969 // get message payload
1970 //auto msgData = msg->payload;
1971 if (rmrMessageBuffer.rcvMessage->state != 0) {
1972 mdclog_write(MDCLOG_ERR, "RMR Receving message with stat = %d", rmrMessageBuffer.rcvMessage->state);
1975 rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)message.message.enodbName);
1976 switch (rmrMessageBuffer.rcvMessage->mtype) {
1977 case RIC_E2_SETUP_RESP : {
1978 if (BuildPERSetupResponseMessaeFromXML(message, rmrMessageBuffer) != 0) {
1982 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1983 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_RESP");
1988 case RIC_E2_SETUP_FAILURE : {
1989 if (BuildPERSetupResponseMessaeFromXML(message, rmrMessageBuffer) != 0) {
1992 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1993 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_FAILURE");
1998 case RIC_ERROR_INDICATION: {
1999 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2000 mdclog_write(MDCLOG_ERR, "Failed to send RIC_ERROR_INDICATION");
2006 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2007 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_REQ");
2012 case RIC_SUB_DEL_REQ: {
2013 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2014 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_DEL_REQ");
2019 case RIC_CONTROL_REQ: {
2020 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2021 mdclog_write(MDCLOG_ERR, "Failed to send RIC_CONTROL_REQ");
2026 case RIC_SERVICE_QUERY: {
2027 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2028 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY");
2033 case RIC_SERVICE_UPDATE_ACK: {
2034 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2035 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK");
2040 case RIC_SERVICE_UPDATE_FAILURE: {
2041 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2042 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE");
2047 case RIC_X2_RESET: {
2048 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2049 mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET");
2054 case RIC_X2_RESET_RESP: {
2055 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2056 mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET_RESP");
2061 case RIC_SCTP_CLEAR_ALL: {
2062 mdclog_write(MDCLOG_INFO, "RIC_SCTP_CLEAR_ALL");
2063 // loop on all keys and close socket and then erase all map.
2065 sctpMap->getKeys(v);
2066 for (auto const &iter : v) { //}; iter != sctpMap.end(); iter++) {
2067 if (!boost::starts_with((string) (iter), "host:") && !boost::starts_with((string) (iter), "msg:")) {
2068 auto *peerInfo = (ConnectedCU_t *) sctpMap->find(iter);
2069 if (peerInfo == nullptr) {
2072 close(peerInfo->fileDescriptor);
2073 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
2074 message.message.direction = 'D';
2075 message.message.time.tv_nsec = ts.tv_nsec;
2076 message.message.time.tv_sec = ts.tv_sec;
2078 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
2079 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
2081 "%s|RIC_SCTP_CLEAR_ALL",
2082 peerInfo->enodbName);
2083 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
2084 mdclog_write(MDCLOG_INFO, "%s", message.message.asndata);
2085 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
2086 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
2096 case E2_TERM_KEEP_ALIVE_REQ: {
2097 // send message back
2098 rmr_bytes2payload(rmrMessageBuffer.sendMessage,
2099 (unsigned char *)rmrMessageBuffer.ka_message,
2100 rmrMessageBuffer.ka_message_len);
2101 rmrMessageBuffer.sendMessage->mtype = E2_TERM_KEEP_ALIVE_RESP;
2102 rmrMessageBuffer.sendMessage->state = 0;
2103 static unsigned char tx[32];
2104 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2105 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, txLen);
2106 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
2107 if (rmrMessageBuffer.sendMessage == nullptr) {
2108 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
2109 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP RMR message returned NULL");
2110 } else if (rmrMessageBuffer.sendMessage->state != 0) {
2111 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP, on RMR state = %d ( %s)",
2112 rmrMessageBuffer.sendMessage->state, translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str());
2113 } else if (mdclog_level_get() >= MDCLOG_DEBUG) {
2114 mdclog_write(MDCLOG_DEBUG, "Got Keep Alive Request send : %s", rmrMessageBuffer.ka_message);
2120 mdclog_write(MDCLOG_WARN, "Message Type : %d is not seported", rmrMessageBuffer.rcvMessage->mtype);
2121 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
2122 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
2123 message.message.time.tv_nsec = ts.tv_nsec;
2124 message.message.time.tv_sec = ts.tv_sec;
2125 message.message.messageType = rmrMessageBuffer.rcvMessage->mtype;
2127 buildJsonMessage(message);
2132 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2133 mdclog_write(MDCLOG_DEBUG, "EXIT OK from %s", __FUNCTION__);
2139 * Send message to the CU that is not expecting for successful or unsuccessful results
2140 * @param messageBuffer
2142 * @param failedMsgId
2146 int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer,
2147 ReportingMessages_t &message,
2149 Sctp_Map_t *sctpMap) {
2151 getRequestMetaData(message, messageBuffer);
2152 if (mdclog_level_get() >= MDCLOG_INFO) {
2153 mdclog_write(MDCLOG_INFO, "send message to %s address", message.message.enodbName);
2156 auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId);
2163 * @param messageBuffer
2165 * @param failedMesgId
2168 int sendMessagetoCu(Sctp_Map_t *sctpMap,
2169 RmrMessagesBuffer_t &messageBuffer,
2170 ReportingMessages_t &message,
2172 auto *peerInfo = (ConnectedCU_t *) sctpMap->find(message.message.enodbName);
2173 if (peerInfo == nullptr) {
2174 if (failedMesgId != 0) {
2175 sendFailedSendingMessagetoXapp(messageBuffer, message, failedMesgId);
2177 mdclog_write(MDCLOG_ERR, "Failed to send message no CU entry %s", message.message.enodbName);
2183 message.message.messageType = messageBuffer.rcvMessage->mtype;
2184 auto rc = sendSctpMsg(peerInfo, message, sctpMap);
2190 * @param rmrCtx the rmr context to send and receive
2191 * @param msg the msg we got fromxApp
2192 * @param metaData data from xApp in ordered struct
2193 * @param failedMesgId the return message type error
2196 sendFailedSendingMessagetoXapp(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message, int failedMesgId) {
2197 rmr_mbuf_t *msg = rmrMessageBuffer.sendMessage;
2198 msg->len = snprintf((char *) msg->payload, 200, "the gNb/eNode name %s not found",
2199 message.message.enodbName);
2200 if (mdclog_level_get() >= MDCLOG_INFO) {
2201 mdclog_write(MDCLOG_INFO, "%s", msg->payload);
2203 msg->mtype = failedMesgId;
2206 static unsigned char tx[32];
2207 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2208 rmr_bytes2xact(msg, tx, strlen((const char *) tx));
2210 sendRmrMessage(rmrMessageBuffer, message);
2225 int addToEpoll(int epoll_fd,
2226 ConnectedCU_t *peerInfo,
2228 Sctp_Map_t *sctpMap,
2232 struct epoll_event event{};
2233 event.data.ptr = peerInfo;
2234 event.events = events;
2235 if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peerInfo->fileDescriptor, &event) < 0) {
2236 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2237 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here), %s, %s %d",
2238 strerror(errno), __func__, __LINE__);
2240 close(peerInfo->fileDescriptor);
2241 if (enodbName != nullptr) {
2242 cleanHashEntry(peerInfo, sctpMap);
2243 char key[MAX_ENODB_NAME_SIZE * 2];
2244 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
2245 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2246 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
2248 auto tmp = sctpMap->find(key);
2251 sctpMap->erase(key);
2254 peerInfo->enodbName[0] = 0;
2256 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here)");
2272 int modifyToEpoll(int epoll_fd,
2273 ConnectedCU_t *peerInfo,
2275 Sctp_Map_t *sctpMap,
2279 struct epoll_event event{};
2280 event.data.ptr = peerInfo;
2281 event.events = events;
2282 if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, peerInfo->fileDescriptor, &event) < 0) {
2283 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2284 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_MOD (may chack not to quit here), %s, %s %d",
2285 strerror(errno), __func__, __LINE__);
2287 close(peerInfo->fileDescriptor);
2288 cleanHashEntry(peerInfo, sctpMap);
2289 char key[MAX_ENODB_NAME_SIZE * 2];
2290 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
2291 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2292 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
2294 auto tmp = sctpMap->find(key);
2298 sctpMap->erase(key);
2299 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here)");
2306 int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message) {
2307 buildJsonMessage(message);
2309 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
2311 if (rmrMessageBuffer.sendMessage == nullptr) {
2312 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
2313 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
2317 if (rmrMessageBuffer.sendMessage->state != 0) {
2318 char meid[RMR_MAX_MEID]{};
2319 if (rmrMessageBuffer.sendMessage->state == RMR_ERR_RETRY) {
2321 rmrMessageBuffer.sendMessage->state = 0;
2322 mdclog_write(MDCLOG_INFO, "RETRY sending Message type %d to Xapp from %s",
2323 rmrMessageBuffer.sendMessage->mtype,
2324 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
2325 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
2326 if (rmrMessageBuffer.sendMessage == nullptr) {
2327 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
2328 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
2330 } else if (rmrMessageBuffer.sendMessage->state != 0) {
2331 mdclog_write(MDCLOG_ERR,
2332 "Message state %s while sending request %d to Xapp from %s after retry of 10 microseconds",
2333 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
2334 rmrMessageBuffer.sendMessage->mtype,
2335 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
2336 auto rc = rmrMessageBuffer.sendMessage->state;
2340 mdclog_write(MDCLOG_ERR, "Message state %s while sending request %d to Xapp from %s",
2341 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
2342 rmrMessageBuffer.sendMessage->mtype,
2343 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
2344 return rmrMessageBuffer.sendMessage->state;
2350 void buildJsonMessage(ReportingMessages_t &message) {
2352 message.outLen = sizeof(message.base64Data);
2353 base64::encode((const unsigned char *) message.message.asndata,
2354 (const int) message.message.asnLength,
2357 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2358 mdclog_write(MDCLOG_DEBUG, "asn data length = %d, base64 message length = %d ",
2359 (int) message.message.asnLength,
2360 (int) message.outLen);
2363 snprintf(message.buffer, sizeof(message.buffer),
2364 "{\"header\": {\"ts\": \"%ld.%09ld\","
2365 "\"ranName\": \"%s\","
2366 "\"messageType\": %d,"
2367 "\"direction\": \"%c\"},"
2368 "\"base64Length\": %d,"
2369 "\"asnBase64\": \"%s\"}",
2370 message.message.time.tv_sec,
2371 message.message.time.tv_nsec,
2372 message.message.enodbName,
2373 message.message.messageType,
2374 message.message.direction,
2375 (int) message.outLen,
2376 message.base64Data);
2377 static src::logger_mt &lg = my_logger::get();
2379 BOOST_LOG(lg) << message.buffer;
2385 * take RMR error code to string
2389 string translateRmrErrorMessages(int state) {
2393 str = "RMR_OK - state is good";
2395 case RMR_ERR_BADARG:
2396 str = "RMR_ERR_BADARG - argument passd to function was unusable";
2398 case RMR_ERR_NOENDPT:
2399 str = "RMR_ERR_NOENDPT - send//call could not find an endpoint based on msg type";
2402 str = "RMR_ERR_EMPTY - msg received had no payload; attempt to send an empty message";
2405 str = "RMR_ERR_NOHDR - message didn't contain a valid header";
2407 case RMR_ERR_SENDFAILED:
2408 str = "RMR_ERR_SENDFAILED - send failed; errno has nano reason";
2410 case RMR_ERR_CALLFAILED:
2411 str = "RMR_ERR_CALLFAILED - unable to send call() message";
2413 case RMR_ERR_NOWHOPEN:
2414 str = "RMR_ERR_NOWHOPEN - no wormholes are open";
2417 str = "RMR_ERR_WHID - wormhole id was invalid";
2419 case RMR_ERR_OVERFLOW:
2420 str = "RMR_ERR_OVERFLOW - operation would have busted through a buffer/field size";
2423 str = "RMR_ERR_RETRY - request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)";
2425 case RMR_ERR_RCVFAILED:
2426 str = "RMR_ERR_RCVFAILED - receive failed (hard error)";
2428 case RMR_ERR_TIMEOUT:
2429 str = "RMR_ERR_TIMEOUT - message processing call timed out";
2432 str = "RMR_ERR_UNSET - the message hasn't been populated with a transport buffer";
2435 str = "RMR_ERR_TRUNC - received message likely truncated";
2437 case RMR_ERR_INITFAILED:
2438 str = "RMR_ERR_INITFAILED - initialisation of something (probably message) failed";
2440 case RMR_ERR_NOTSUPP:
2441 str = "RMR_ERR_NOTSUPP - the request is not supported, or RMr was not initialised for the request";
2445 snprintf(buf, sizeof buf, "UNDOCUMENTED RMR_ERR : %d", state);