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 if (!(sctpParams->configFileName.compare(event->name))) {
733 // only the file we want
734 if (event->mask & (uint32_t)IN_CLOSE_WRITE) {
736 const int size = 2048;
737 auto fileSize = file_size(p);
738 if (fileSize > size) {
739 mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size);
743 mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str());
748 if (conf.openConfigFile(p.string()) == -1) {
749 mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s",
750 p.string().c_str(), strerror(errno));
754 auto tmpStr = conf.getStringValue("loglevel");
755 if (tmpStr.length() == 0) {
756 mdclog_write(MDCLOG_ERR, "illigal loglevel. Set loglevel to MDCLOG_INFO");
759 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
761 if ((tmpStr.compare("debug")) == 0) {
762 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_DEBUG");
763 sctpParams->logLevel = MDCLOG_DEBUG;
764 } else if ((tmpStr.compare("info")) == 0) {
765 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_INFO");
766 sctpParams->logLevel = MDCLOG_INFO;
767 } else if ((tmpStr.compare("warning")) == 0) {
768 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_WARN");
769 sctpParams->logLevel = MDCLOG_WARN;
770 } else if ((tmpStr.compare("error")) == 0) {
771 mdclog_write(MDCLOG_INFO, "Log level set to MDCLOG_ERR");
772 sctpParams->logLevel = MDCLOG_ERR;
774 mdclog_write(MDCLOG_ERR, "illigal loglevel = %s. Set loglevel to MDCLOG_INFO", tmpStr.c_str());
775 sctpParams->logLevel = MDCLOG_INFO;
777 mdclog_level_set(sctpParams->logLevel);
780 tmpStr = conf.getStringValue("trace");
781 if (tmpStr.length() == 0) {
782 mdclog_write(MDCLOG_ERR, "illigal trace. Set trace to stop");
786 transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);
787 if ((tmpStr.compare("start")) == 0) {
788 mdclog_write(MDCLOG_INFO, "Trace set to: start");
789 sctpParams->trace = true;
790 } else if ((tmpStr.compare("stop")) == 0) {
791 mdclog_write(MDCLOG_INFO, "Trace set to: stop");
792 sctpParams->trace = false;
794 mdclog_write(MDCLOG_ERR, "Trace was set to wrong value %s, set to stop", tmpStr.c_str());
795 sctpParams->trace = false;
797 jsonTrace = sctpParams->trace;
808 * @param rmrMessageBuffer
811 void handleEinprogressMessages(struct epoll_event &event,
812 ReportingMessages_t &message,
813 RmrMessagesBuffer_t &rmrMessageBuffer,
814 sctp_params_t *params) {
815 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
816 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
818 mdclog_write(MDCLOG_INFO, "file descriptor %d got EPOLLOUT", peerInfo->fileDescriptor);
820 socklen_t retValLen = 0;
821 auto rc = getsockopt(peerInfo->fileDescriptor, SOL_SOCKET, SO_ERROR, &retVal, &retValLen);
822 if (rc != 0 || retVal != 0) {
824 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
825 "%s|Failed SCTP Connection, after EINPROGRESS the getsockopt%s",
826 peerInfo->enodbName, strerror(errno));
827 } else if (retVal != 0) {
828 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
829 "%s|Failed SCTP Connection after EINPROGRESS, SO_ERROR",
830 peerInfo->enodbName);
833 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
834 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
835 mdclog_write(MDCLOG_ERR, "%s", rmrMessageBuffer.sendMessage->payload);
836 message.message.direction = 'N';
837 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
838 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
840 memset(peerInfo->asnData, 0, peerInfo->asnLength);
841 peerInfo->asnLength = 0;
846 peerInfo->isConnected = true;
848 if (modifyToEpoll(params->epoll_fd, peerInfo, (EPOLLIN | EPOLLET), params->sctpMap, peerInfo->enodbName,
849 peerInfo->mtype) != 0) {
850 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_MOD");
854 message.message.asndata = (unsigned char *)peerInfo->asnData;
855 message.message.asnLength = peerInfo->asnLength;
856 message.message.messageType = peerInfo->mtype;
857 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
858 num_of_messages.fetch_add(1, std::memory_order_release);
859 if (mdclog_level_get() >= MDCLOG_DEBUG) {
860 mdclog_write(MDCLOG_DEBUG, "send the delayed SETUP/ENDC SETUP to sctp for %s",
861 message.message.enodbName);
863 if (sendSctpMsg(peerInfo, message, params->sctpMap) != 0) {
864 if (mdclog_level_get() >= MDCLOG_DEBUG) {
865 mdclog_write(MDCLOG_DEBUG, "Error write to SCTP %s %d", __func__, __LINE__);
870 memset(peerInfo->asnData, 0, peerInfo->asnLength);
871 peerInfo->asnLength = 0;
876 void handlepoll_error(struct epoll_event &event,
877 ReportingMessages_t &message,
878 RmrMessagesBuffer_t &rmrMessageBuffer,
879 sctp_params_t *params) {
880 if (event.data.fd != params->rmrListenFd) {
881 auto *peerInfo = (ConnectedCU_t *)event.data.ptr;
882 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on fd %d, RAN NAME : %s",
883 event.events, peerInfo->fileDescriptor, peerInfo->enodbName);
885 rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256,
886 "%s|Failed SCTP Connection",
887 peerInfo->enodbName);
888 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
889 message.message.asnLength = rmrMessageBuffer.sendMessage->len;
891 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
892 message.message.direction = 'N';
893 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
894 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
897 close(peerInfo->fileDescriptor);
898 params->sctpMap->erase(peerInfo->enodbName);
899 cleanHashEntry((ConnectedCU_t *) event.data.ptr, params->sctpMap);
901 mdclog_write(MDCLOG_ERR, "epoll error, events %0x on RMR FD", event.events);
909 int setSocketNoBlocking(int socket) {
910 auto flags = fcntl(socket, F_GETFL, 0);
913 mdclog_mdc_add("func", "fcntl");
914 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
919 flags = (unsigned) flags | (unsigned) O_NONBLOCK;
920 if (fcntl(socket, F_SETFL, flags) == -1) {
921 mdclog_mdc_add("func", "fcntl");
922 mdclog_write(MDCLOG_ERR, "%s, %s", __FUNCTION__, strerror(errno));
935 void cleanHashEntry(ConnectedCU_t *val, Sctp_Map_t *m) {
937 auto port = (uint16_t) strtol(val->portNumber, &dummy, 10);
938 char searchBuff[2048]{};
940 snprintf(searchBuff, sizeof searchBuff, "host:%s:%d", val->hostName, port);
941 m->erase(searchBuff);
943 m->erase(val->enodbName);
949 * @param fd file discriptor
950 * @param data the asn data to send
951 * @param len length of the data
952 * @param enodbName the enodbName as in the map for printing purpose
953 * @param m map host information
954 * @param mtype message number
955 * @return 0 success, anegative number on fail
957 int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_t *m) {
958 auto loglevel = mdclog_level_get();
959 int fd = peerInfo->fileDescriptor;
960 if (loglevel >= MDCLOG_DEBUG) {
961 mdclog_write(MDCLOG_DEBUG, "Send SCTP message for CU %s, %s",
962 message.message.enodbName, __FUNCTION__);
966 if (send(fd,message.message.asndata, message.message.asnLength,MSG_NOSIGNAL) < 0) {
967 if (errno == EINTR) {
970 mdclog_write(MDCLOG_ERR, "error writing to CU a message, %s ", strerror(errno));
971 if (!peerInfo->isConnected) {
972 mdclog_write(MDCLOG_ERR, "connection to CU %s is still in progress.", message.message.enodbName);
975 cleanHashEntry(peerInfo, m);
977 char key[MAX_ENODB_NAME_SIZE * 2];
978 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName,
979 message.message.messageType);
980 if (loglevel >= MDCLOG_DEBUG) {
981 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
983 auto tmp = m->find(key);
990 message.statCollector->incSentMessage(string(message.message.enodbName));
991 message.message.direction = 'D';
992 // send report.buffer of size
993 buildJsonMessage(message);
995 if (loglevel >= MDCLOG_DEBUG) {
996 mdclog_write(MDCLOG_DEBUG,
997 "SCTP message for CU %s sent from %s",
998 message.message.enodbName,
1008 * @param rmrMessageBuffer
1010 void getRequestMetaData(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
1011 rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *) (message.message.enodbName));
1013 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
1014 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
1016 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1017 mdclog_write(MDCLOG_DEBUG, "Message from Xapp RAN name = %s message length = %ld",
1018 message.message.enodbName, (unsigned long) message.message.asnLength);
1028 * @param numOfMessages
1029 * @param rmrMessageBuffer
1033 int receiveDataFromSctp(struct epoll_event *events,
1034 Sctp_Map_t *sctpMap,
1036 RmrMessagesBuffer_t &rmrMessageBuffer,
1037 struct timespec &ts) {
1038 /* We have data on the fd waiting to be read. Read and display it.
1039 * We must read whatever data is available completely, as we are running
1040 * in edge-triggered mode and won't get a notification again for the same data. */
1041 ReportingMessages_t message {};
1043 auto loglevel = mdclog_level_get();
1045 // get the identity of the interface
1046 message.peerInfo = (ConnectedCU_t *)events->data.ptr;
1048 message.statCollector = StatCollector::GetInstance();
1049 struct timespec start{0, 0};
1050 struct timespec decodestart{0, 0};
1051 struct timespec end{0, 0};
1053 E2AP_PDU_t *pdu = nullptr;
1057 if (loglevel >= MDCLOG_DEBUG) {
1058 mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP %d fd", message.peerInfo->fileDescriptor);
1059 clock_gettime(CLOCK_MONOTONIC, &start);
1061 // read the buffer directly to rmr payload
1062 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1063 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
1064 read(message.peerInfo->fileDescriptor, rmrMessageBuffer.sendMessage->payload, RECEIVE_SCTP_BUFFER_SIZE);
1066 if (loglevel >= MDCLOG_DEBUG) {
1067 mdclog_write(MDCLOG_DEBUG, "Finish Read from SCTP %d fd message length = %ld",
1068 message.peerInfo->fileDescriptor, message.message.asnLength);
1071 memcpy(message.message.enodbName, message.peerInfo->enodbName, sizeof(message.peerInfo->enodbName));
1072 message.statCollector->incRecvMessage(string(message.message.enodbName));
1073 message.message.direction = 'U';
1074 message.message.time.tv_nsec = ts.tv_nsec;
1075 message.message.time.tv_sec = ts.tv_sec;
1077 if (message.message.asnLength < 0) {
1078 if (errno == EINTR) {
1081 /* If errno == EAGAIN, that means we have read all
1082 data. So goReportingMessages_t back to the main loop. */
1083 if (errno != EAGAIN) {
1084 mdclog_write(MDCLOG_ERR, "Read error, %s ", strerror(errno));
1086 } else if (loglevel >= MDCLOG_DEBUG) {
1087 mdclog_write(MDCLOG_DEBUG, "EAGAIN - descriptor = %d", message.peerInfo->fileDescriptor);
1090 } else if (message.message.asnLength == 0) {
1091 /* End of file. The remote has closed the connection. */
1092 if (loglevel >= MDCLOG_INFO) {
1093 mdclog_write(MDCLOG_INFO, "END of File Closed connection - descriptor = %d",
1094 message.peerInfo->fileDescriptor);
1100 if (loglevel >= MDCLOG_DEBUG) {
1101 char printBuffer[4096]{};
1102 char *tmp = printBuffer;
1103 for (size_t i = 0; i < (size_t)message.message.asnLength; ++i) {
1104 snprintf(tmp, 3, "%02x", message.message.asndata[i]);
1107 printBuffer[message.message.asnLength] = 0;
1108 clock_gettime(CLOCK_MONOTONIC, &end);
1109 mdclog_write(MDCLOG_DEBUG, "Before Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds",
1110 message.peerInfo->enodbName, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
1111 mdclog_write(MDCLOG_DEBUG, "PDU buffer length = %ld, data = : %s", message.message.asnLength,
1113 clock_gettime(CLOCK_MONOTONIC, &decodestart);
1116 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu,
1117 message.message.asndata, message.message.asnLength);
1118 if (rval.code != RC_OK) {
1119 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from RAN : %s", rval.code,
1120 message.peerInfo->enodbName);
1121 //todo may need reset to pdu
1125 if (loglevel >= MDCLOG_DEBUG) {
1126 clock_gettime(CLOCK_MONOTONIC, &end);
1127 mdclog_write(MDCLOG_DEBUG, "After Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds",
1128 message.peerInfo->enodbName, end.tv_sec - decodestart.tv_sec, end.tv_nsec - decodestart.tv_nsec);
1131 FILE *stream = open_memstream(&printBuffer, &size);
1132 asn_fprint(stream, &asn_DEF_E2AP_PDU, pdu);
1133 mdclog_write(MDCLOG_DEBUG, "Encoding E2AP PDU past : %s", printBuffer);
1134 clock_gettime(CLOCK_MONOTONIC, &decodestart);
1137 switch (pdu->present) {
1138 case E2AP_PDU_PR_initiatingMessage: {//initiating message
1139 asnInitiatingRequest(pdu, sctpMap,message, rmrMessageBuffer);
1142 case E2AP_PDU_PR_successfulOutcome: { //successful outcome
1143 asnSuccsesfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
1146 case E2AP_PDU_PR_unsuccessfulOutcome: { //Unsuccessful Outcome
1147 asnUnSuccsesfulMsg(pdu, sctpMap, message, rmrMessageBuffer);
1151 mdclog_write(MDCLOG_ERR, "Unknown index %d in E2AP PDU", pdu->present);
1154 if (loglevel >= MDCLOG_DEBUG) {
1155 clock_gettime(CLOCK_MONOTONIC, &end);
1156 mdclog_write(MDCLOG_DEBUG,
1157 "After processing message and sent to rmr for : %s, Read time is : %ld seconds, %ld nanoseconds",
1158 message.peerInfo->enodbName, end.tv_sec - decodestart.tv_sec, end.tv_nsec - decodestart.tv_nsec);
1161 // remove the break for EAGAIN
1163 if (pdu != nullptr) {
1164 //TODO need to test ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); to get better performance
1165 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
1166 //ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1169 //clock_gettime(CLOCK_MONOTONIC, &start);
1171 // in case of break to avoid memory leak
1172 // if (pdu != nullptr) {
1173 // //ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
1174 // ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu);
1179 if (loglevel >= MDCLOG_INFO) {
1180 mdclog_write(MDCLOG_INFO, "Closed connection - descriptor = %d", message.peerInfo->fileDescriptor);
1182 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
1183 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
1185 "%s|CU disconnected unexpectedly",
1186 message.peerInfo->enodbName);
1187 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
1189 if (sendRequestToXapp(message,
1190 RIC_SCTP_CONNECTION_FAILURE,
1191 rmrMessageBuffer) != 0) {
1192 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
1195 /* Closing descriptor make epoll remove it from the set of descriptors which are monitored. */
1196 close(message.peerInfo->fileDescriptor);
1197 cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap);
1199 if (loglevel >= MDCLOG_DEBUG) {
1200 clock_gettime(CLOCK_MONOTONIC, &end);
1201 mdclog_write(MDCLOG_DEBUG, "from receive SCTP to send RMR time is %ld seconds and %ld nanoseconds",
1202 end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec);
1208 static void buildAndsendSetupRequest(ReportingMessages_t &message,
1209 RmrMessagesBuffer_t &rmrMessageBuffer,
1211 auto logLevel = mdclog_level_get();
1213 // now we can send the data to e2Mgr
1214 auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1216 auto *rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size);
1217 // add addrees to message
1220 // unsigned char *buffer = &rmrMsg->payload[j];
1221 unsigned char buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
1223 auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size);
1224 if (er.encoded == -1) {
1225 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1226 } else if (er.encoded > (ssize_t) buffer_size) {
1227 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s",
1229 asn_DEF_E2AP_PDU.name);
1231 rmrMsg->len = snprintf((char *)rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s",
1232 message.peerInfo->sctpParams->myIP.c_str(),
1233 message.peerInfo->sctpParams->rmrPort,
1235 if (logLevel >= MDCLOG_DEBUG) {
1236 mdclog_write(MDCLOG_DEBUG, "Setup request of size %d :\n %s\n", rmrMsg->len, rmrMsg->payload);
1239 message.message.messageType = rmrMsg->mtype = RIC_E2_SETUP_REQ;
1241 rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName));
1243 static unsigned char tx[32];
1244 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1245 rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx));
1247 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
1248 if (rmrMsg == nullptr) {
1249 mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr");
1250 } else if (rmrMsg->state != 0) {
1251 char meid[RMR_MAX_MEID]{};
1252 if (rmrMsg->state == RMR_ERR_RETRY) {
1255 mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s",
1256 rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid));
1257 rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg);
1258 if (rmrMsg == nullptr) {
1259 mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr");
1260 } else if (rmrMsg->state != 0) {
1261 mdclog_write(MDCLOG_ERR,
1262 "RMR Retry failed %s sending request %d to Xapp from %s",
1263 translateRmrErrorMessages(rmrMsg->state).c_str(),
1265 rmr_get_meid(rmrMsg, (unsigned char *) meid));
1268 mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s",
1269 translateRmrErrorMessages(rmrMsg->state).c_str(),
1271 rmr_get_meid(rmrMsg, (unsigned char *) meid));
1274 message.peerInfo->gotSetup = true;
1275 buildJsonMessage(message);
1276 if (rmrMsg != nullptr) {
1277 rmr_free_msg(rmrMsg);
1286 * @param rmrMessageBuffer
1288 void asnInitiatingRequest(E2AP_PDU_t *pdu,
1289 Sctp_Map_t *sctpMap,
1290 ReportingMessages_t &message,
1291 RmrMessagesBuffer_t &rmrMessageBuffer) {
1292 auto logLevel = mdclog_level_get();
1293 auto procedureCode = ((InitiatingMessage_t *) pdu->choice.initiatingMessage)->procedureCode;
1294 if (logLevel >= MDCLOG_DEBUG) {
1295 mdclog_write(MDCLOG_DEBUG, "Initiating message %ld\n", procedureCode);
1297 switch (procedureCode) {
1298 case ProcedureCode_id_E2setup: {
1299 if (logLevel >= MDCLOG_DEBUG) {
1300 mdclog_write(MDCLOG_DEBUG, "Got E2setup\n");
1303 // first get the message as XML buffer
1304 auto setup_xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1305 unsigned char setup_xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
1306 //unsigned char *tmp_buff_cursor = setup_xml_buffer;
1308 auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, setup_xml_buffer, setup_xml_buffer_size);
1309 if (er.encoded == -1) {
1310 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1311 } else if (er.encoded > (ssize_t) setup_xml_buffer_size) {
1312 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s",
1313 (int)setup_xml_buffer_size,
1314 asn_DEF_E2AP_PDU.name);
1316 std::string xmlString(setup_xml_buffer_size, setup_xml_buffer_size + er.encoded);
1318 auto failed = false;
1319 memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE);
1320 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) {
1321 auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i];
1322 if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) {
1323 // get the ran name for meid
1324 if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) {
1325 if (buildRanName(message.peerInfo->enodbName, ie) < 0) {
1326 mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n");
1327 // no mesage will be sent
1330 memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName));
1331 sctpMap->setkey(message.message.enodbName, message.peerInfo);
1334 // reformat RANFUNCTION Definition to XML
1335 if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
1336 if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) {
1337 for (auto j = 0; i < ie->value.choice.RANfunctions_List.list.count; i++) {
1338 auto *raNfunctionItemIEs = (RANfunction_ItemIEs_t *)ie->value.choice.RANfunctions_List.list.array[j];
1339 if (raNfunctionItemIEs->id == ProtocolIE_ID_id_RANfunction_Item &&
1340 (raNfunctionItemIEs->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item)) {
1342 E2SM_gNB_NRT_RANfunction_Definition_t *ranFunDef = nullptr;
1343 auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER,
1344 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1345 (void **)&ranFunDef,
1346 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.buf,
1347 raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.size);
1348 if (rval.code != RC_OK) {
1349 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2SM message from : %s",
1351 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name);
1356 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1359 FILE *stream = open_memstream(&printBuffer, &size);
1360 asn_fprint(stream, &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, pdu);
1361 mdclog_write(MDCLOG_DEBUG, "Encoding E2AP PDU past : %s", printBuffer);
1363 auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1364 unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
1366 er = asn_encode_to_buffer(nullptr,
1368 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1372 if (er.encoded == -1) {
1373 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s",
1374 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1376 } else if (er.encoded > (ssize_t)xml_buffer_size) {
1377 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s",
1378 (int) xml_buffer_size,
1379 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name);
1396 //build all parts and send the XML (need to copy the XML with the header to the rmrMessageBuffer payload
1397 //TODO replace with new function
1398 buildAndsendSetupRequest(message, rmrMessageBuffer, pdu);
1401 case ProcedureCode_id_ErrorIndication: {
1402 if (logLevel >= MDCLOG_DEBUG) {
1403 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
1405 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
1406 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
1410 case ProcedureCode_id_Reset: {
1411 if (logLevel >= MDCLOG_DEBUG) {
1412 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
1414 if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) {
1415 mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP");
1419 case ProcedureCode_id_RICcontrol: {
1420 if (logLevel >= MDCLOG_DEBUG) {
1421 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
1425 case ProcedureCode_id_RICindication: {
1426 if (logLevel >= MDCLOG_DEBUG) {
1427 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
1429 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
1430 auto messageSent = false;
1431 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
1432 if (logLevel >= MDCLOG_DEBUG) {
1433 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1435 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1436 if (logLevel >= MDCLOG_DEBUG) {
1437 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1439 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
1440 static unsigned char tx[32];
1441 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
1442 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1443 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1444 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1445 (unsigned char *)message.message.enodbName,
1446 strlen(message.message.enodbName));
1447 rmrMessageBuffer.sendMessage->state = 0;
1448 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1449 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1450 mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d",
1451 rmrMessageBuffer.sendMessage->sub_id,
1452 rmrMessageBuffer.sendMessage->mtype);
1454 sendRmrMessage(rmrMessageBuffer, message);
1457 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1466 case ProcedureCode_id_RICserviceQuery: {
1467 if (logLevel >= MDCLOG_DEBUG) {
1468 mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName);
1472 case ProcedureCode_id_RICserviceUpdate: {
1473 if (logLevel >= MDCLOG_DEBUG) {
1474 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
1476 if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) {
1477 mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP");
1481 case ProcedureCode_id_RICsubscription: {
1482 if (logLevel >= MDCLOG_DEBUG) {
1483 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
1487 case ProcedureCode_id_RICsubscriptionDelete: {
1488 if (logLevel >= MDCLOG_DEBUG) {
1489 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
1494 mdclog_write(MDCLOG_ERR, "Undefined or not supported message = %ld", procedureCode);
1495 message.message.messageType = 0; // no RMR message type yet
1497 buildJsonMessage(message);
1508 * @param rmrMessageBuffer
1510 void asnSuccsesfulMsg(E2AP_PDU_t *pdu,
1511 Sctp_Map_t *sctpMap,
1512 ReportingMessages_t &message,
1513 RmrMessagesBuffer_t &rmrMessageBuffer) {
1514 auto procedureCode = pdu->choice.successfulOutcome->procedureCode;
1515 auto logLevel = mdclog_level_get();
1516 if (logLevel >= MDCLOG_INFO) {
1517 mdclog_write(MDCLOG_INFO, "Successful Outcome %ld", procedureCode);
1519 switch (procedureCode) {
1520 case ProcedureCode_id_E2setup: {
1521 if (logLevel >= MDCLOG_DEBUG) {
1522 mdclog_write(MDCLOG_DEBUG, "Got E2setup\n");
1526 case ProcedureCode_id_ErrorIndication: {
1527 if (logLevel >= MDCLOG_DEBUG) {
1528 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
1530 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
1531 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
1535 case ProcedureCode_id_Reset: {
1536 if (logLevel >= MDCLOG_DEBUG) {
1537 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
1539 if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) {
1540 mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP");
1544 case ProcedureCode_id_RICcontrol: {
1545 if (logLevel >= MDCLOG_DEBUG) {
1546 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
1549 i < pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; i++) {
1550 auto messageSent = false;
1551 RICcontrolAcknowledge_IEs_t *ie = pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[i];
1552 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1553 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1555 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1556 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1557 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1559 if (ie->value.present == RICcontrolAcknowledge_IEs__value_PR_RICrequestID) {
1560 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_ACK;
1561 rmrMessageBuffer.sendMessage->state = 0;
1562 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1563 static unsigned char tx[32];
1564 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1565 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1566 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1567 (unsigned char *)message.message.enodbName,
1568 strlen(message.message.enodbName));
1570 sendRmrMessage(rmrMessageBuffer, message);
1573 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1583 case ProcedureCode_id_RICindication: {
1584 if (logLevel >= MDCLOG_DEBUG) {
1585 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
1587 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
1588 auto messageSent = false;
1589 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
1590 if (logLevel >= MDCLOG_DEBUG) {
1591 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1593 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1594 if (logLevel >= MDCLOG_DEBUG) {
1595 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1597 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
1598 static unsigned char tx[32];
1599 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
1600 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1601 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1602 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1603 (unsigned char *)message.message.enodbName,
1604 strlen(message.message.enodbName));
1605 rmrMessageBuffer.sendMessage->state = 0;
1606 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1607 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1608 mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d",
1609 rmrMessageBuffer.sendMessage->sub_id,
1610 rmrMessageBuffer.sendMessage->mtype);
1612 sendRmrMessage(rmrMessageBuffer, message);
1615 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1624 case ProcedureCode_id_RICserviceQuery: {
1625 if (logLevel >= MDCLOG_DEBUG) {
1626 mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName);
1630 case ProcedureCode_id_RICserviceUpdate: {
1631 if (logLevel >= MDCLOG_DEBUG) {
1632 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
1634 if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) {
1635 mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP");
1639 case ProcedureCode_id_RICsubscription: {
1640 if (logLevel >= MDCLOG_DEBUG) {
1641 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
1643 if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer) != 0) {
1644 mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP");
1648 case ProcedureCode_id_RICsubscriptionDelete: {
1649 if (logLevel >= MDCLOG_DEBUG) {
1650 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
1652 if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer) != 0) {
1653 mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP");
1658 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
1659 message.message.messageType = 0; // no RMR message type yet
1660 buildJsonMessage(message);
1671 * @param rmrMessageBuffer
1673 void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu,
1674 Sctp_Map_t *sctpMap,
1675 ReportingMessages_t &message,
1676 RmrMessagesBuffer_t &rmrMessageBuffer) {
1677 auto procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode;
1678 auto logLevel = mdclog_level_get();
1679 if (logLevel >= MDCLOG_INFO) {
1680 mdclog_write(MDCLOG_INFO, "Unsuccessful Outcome %ld", procedureCode);
1682 switch (procedureCode) {
1683 case ProcedureCode_id_E2setup: {
1684 if (logLevel >= MDCLOG_DEBUG) {
1685 mdclog_write(MDCLOG_DEBUG, "Got E2setup\n");
1689 case ProcedureCode_id_ErrorIndication: {
1690 if (logLevel >= MDCLOG_DEBUG) {
1691 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
1693 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
1694 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
1698 case ProcedureCode_id_Reset: {
1699 if (logLevel >= MDCLOG_DEBUG) {
1700 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
1702 if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) {
1703 mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP");
1707 case ProcedureCode_id_RICcontrol: {
1708 if (logLevel >= MDCLOG_DEBUG) {
1709 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
1712 i < pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.count; i++) {
1713 auto messageSent = false;
1714 RICcontrolFailure_IEs_t *ie = pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.array[i];
1715 if (logLevel >= MDCLOG_DEBUG) {
1716 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1718 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1719 if (logLevel >= MDCLOG_DEBUG) {
1720 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1722 if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) {
1723 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_FAILURE;
1724 rmrMessageBuffer.sendMessage->state = 0;
1725 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1726 static unsigned char tx[32];
1727 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1728 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1729 rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName,
1730 strlen(message.message.enodbName));
1731 sendRmrMessage(rmrMessageBuffer, message);
1734 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1743 case ProcedureCode_id_RICindication: {
1744 if (logLevel >= MDCLOG_DEBUG) {
1745 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
1747 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
1748 auto messageSent = false;
1749 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
1750 if (logLevel >= MDCLOG_DEBUG) {
1751 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1753 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1754 if (logLevel >= MDCLOG_DEBUG) {
1755 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1757 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
1758 static unsigned char tx[32];
1759 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
1760 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1761 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1762 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1763 (unsigned char *)message.message.enodbName,
1764 strlen(message.message.enodbName));
1765 rmrMessageBuffer.sendMessage->state = 0;
1766 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1767 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1768 mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d",
1769 rmrMessageBuffer.sendMessage->sub_id,
1770 rmrMessageBuffer.sendMessage->mtype);
1772 sendRmrMessage(rmrMessageBuffer, message);
1775 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1784 case ProcedureCode_id_RICserviceQuery: {
1785 if (logLevel >= MDCLOG_DEBUG) {
1786 mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName);
1790 case ProcedureCode_id_RICserviceUpdate: {
1791 if (logLevel >= MDCLOG_DEBUG) {
1792 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
1794 if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) {
1795 mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP");
1799 case ProcedureCode_id_RICsubscription: {
1800 if (logLevel >= MDCLOG_DEBUG) {
1801 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
1803 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
1804 mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP");
1808 case ProcedureCode_id_RICsubscriptionDelete: {
1809 if (logLevel >= MDCLOG_DEBUG) {
1810 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
1812 if (sendRequestToXapp(message, RIC_SUB_DEL_FAILURE, rmrMessageBuffer) != 0) {
1813 mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP");
1818 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
1819 message.message.messageType = 0; // no RMR message type yet
1821 buildJsonMessage(message);
1832 * @param rmrMmessageBuffer
1835 int sendRequestToXapp(ReportingMessages_t &message,
1837 RmrMessagesBuffer_t &rmrMmessageBuffer) {
1838 rmr_bytes2meid(rmrMmessageBuffer.sendMessage,
1839 (unsigned char *)message.message.enodbName,
1840 strlen(message.message.enodbName));
1841 message.message.messageType = rmrMmessageBuffer.sendMessage->mtype = requestId;
1842 rmrMmessageBuffer.sendMessage->state = 0;
1843 static unsigned char tx[32];
1844 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1845 rmr_bytes2xact(rmrMmessageBuffer.sendMessage, tx, strlen((const char *) tx));
1847 auto rc = sendRmrMessage(rmrMmessageBuffer, message);
1852 void getRmrContext(sctp_params_t &pSctpParams) {
1853 pSctpParams.rmrCtx = nullptr;
1854 pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RMR_MAX_RCV_BYTES, RMRFL_NONE);
1855 if (pSctpParams.rmrCtx == nullptr) {
1856 mdclog_write(MDCLOG_ERR, "Failed to initialize RMR");
1860 rmr_set_stimeout(pSctpParams.rmrCtx, 0); // disable retries for any send operation
1861 // we need to find that routing table exist and we can run
1862 if (mdclog_level_get() >= MDCLOG_INFO) {
1863 mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready");
1868 if ((rmrReady = rmr_ready(pSctpParams.rmrCtx)) == 0) {
1872 if (count % 60 == 0) {
1873 mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count);
1876 if (mdclog_level_get() >= MDCLOG_INFO) {
1877 mdclog_write(MDCLOG_INFO, "RMR running");
1879 rmr_init_trace(pSctpParams.rmrCtx, 200);
1880 // get the RMR fd for the epoll
1881 pSctpParams.rmrListenFd = rmr_get_rcvfd(pSctpParams.rmrCtx);
1882 struct epoll_event event{};
1883 // add RMR fd to epoll
1884 event.events = (EPOLLIN);
1885 event.data.fd = pSctpParams.rmrListenFd;
1886 // add listening RMR FD to epoll
1887 if (epoll_ctl(pSctpParams.epoll_fd, EPOLL_CTL_ADD, pSctpParams.rmrListenFd, &event)) {
1888 mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll");
1889 close(pSctpParams.rmrListenFd);
1890 rmr_close(pSctpParams.rmrCtx);
1891 pSctpParams.rmrCtx = nullptr;
1895 int BuildPERSetupResponseMessaeFromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
1898 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1899 mdclog_write(MDCLOG_DEBUG, "got xml setup response \n %s\n", rmrMessageBuffer.rcvMessage->payload);
1901 auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &pdu,
1902 rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len);
1903 if (rval.code != RC_OK) {
1904 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
1906 message.message.enodbName);
1910 auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu,
1911 rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len);
1912 if (er.encoded == -1) {
1913 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1915 } else if (er.encoded > (ssize_t)rmrMessageBuffer.rcvMessage->len) {
1916 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s",
1917 (int)rmrMessageBuffer.rcvMessage->len,
1918 asn_DEF_E2AP_PDU.name);
1927 * @param rmrMessageBuffer
1931 int receiveXappMessages(Sctp_Map_t *sctpMap,
1932 RmrMessagesBuffer_t &rmrMessageBuffer,
1933 struct timespec &ts) {
1934 if (rmrMessageBuffer.rcvMessage == nullptr) {
1936 mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno));
1940 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1941 mdclog_write(MDCLOG_DEBUG, "Call to rmr_rcv_msg");
1943 rmrMessageBuffer.rcvMessage = rmr_rcv_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
1944 if (rmrMessageBuffer.rcvMessage == nullptr) {
1945 mdclog_write(MDCLOG_ERR, "RMR Receving message with null pointer, Realloc rmr mesage buffer");
1946 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
1949 ReportingMessages_t message;
1950 message.message.direction = 'D';
1951 message.message.time.tv_nsec = ts.tv_nsec;
1952 message.message.time.tv_sec = ts.tv_sec;
1954 // get message payload
1955 //auto msgData = msg->payload;
1956 if (rmrMessageBuffer.rcvMessage->state != 0) {
1957 mdclog_write(MDCLOG_ERR, "RMR Receving message with stat = %d", rmrMessageBuffer.rcvMessage->state);
1960 rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)message.message.enodbName);
1961 switch (rmrMessageBuffer.rcvMessage->mtype) {
1962 case RIC_E2_SETUP_RESP : {
1963 if (BuildPERSetupResponseMessaeFromXML(message, rmrMessageBuffer) != 0) {
1967 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1968 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_RESP");
1973 case RIC_E2_SETUP_FAILURE : {
1974 if (BuildPERSetupResponseMessaeFromXML(message, rmrMessageBuffer) != 0) {
1977 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1978 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_FAILURE");
1983 case RIC_ERROR_INDICATION: {
1984 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1985 mdclog_write(MDCLOG_ERR, "Failed to send RIC_ERROR_INDICATION");
1991 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1992 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_REQ");
1997 case RIC_SUB_DEL_REQ: {
1998 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1999 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_DEL_REQ");
2004 case RIC_CONTROL_REQ: {
2005 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2006 mdclog_write(MDCLOG_ERR, "Failed to send RIC_CONTROL_REQ");
2011 case RIC_SERVICE_QUERY: {
2012 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2013 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY");
2018 case RIC_SERVICE_UPDATE_ACK: {
2019 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2020 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK");
2025 case RIC_SERVICE_UPDATE_FAILURE: {
2026 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2027 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE");
2032 case RIC_X2_RESET: {
2033 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2034 mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET");
2039 case RIC_X2_RESET_RESP: {
2040 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2041 mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET_RESP");
2046 case RIC_SCTP_CLEAR_ALL: {
2047 mdclog_write(MDCLOG_INFO, "RIC_SCTP_CLEAR_ALL");
2048 // loop on all keys and close socket and then erase all map.
2050 sctpMap->getKeys(v);
2051 for (auto const &iter : v) { //}; iter != sctpMap.end(); iter++) {
2052 if (!boost::starts_with((string) (iter), "host:") && !boost::starts_with((string) (iter), "msg:")) {
2053 auto *peerInfo = (ConnectedCU_t *) sctpMap->find(iter);
2054 if (peerInfo == nullptr) {
2057 close(peerInfo->fileDescriptor);
2058 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
2059 message.message.direction = 'D';
2060 message.message.time.tv_nsec = ts.tv_nsec;
2061 message.message.time.tv_sec = ts.tv_sec;
2063 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
2064 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
2066 "%s|RIC_SCTP_CLEAR_ALL",
2067 peerInfo->enodbName);
2068 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
2069 mdclog_write(MDCLOG_INFO, "%s", message.message.asndata);
2070 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
2071 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
2081 case E2_TERM_KEEP_ALIVE_REQ: {
2082 // send message back
2083 rmr_bytes2payload(rmrMessageBuffer.sendMessage,
2084 (unsigned char *)rmrMessageBuffer.ka_message,
2085 rmrMessageBuffer.ka_message_len);
2086 rmrMessageBuffer.sendMessage->mtype = E2_TERM_KEEP_ALIVE_RESP;
2087 rmrMessageBuffer.sendMessage->state = 0;
2088 static unsigned char tx[32];
2089 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2090 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, txLen);
2091 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
2092 if (rmrMessageBuffer.sendMessage == nullptr) {
2093 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
2094 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP RMR message returned NULL");
2095 } else if (rmrMessageBuffer.sendMessage->state != 0) {
2096 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP, on RMR state = %d ( %s)",
2097 rmrMessageBuffer.sendMessage->state, translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str());
2098 } else if (mdclog_level_get() >= MDCLOG_DEBUG) {
2099 mdclog_write(MDCLOG_DEBUG, "Got Keep Alive Request send : %s", rmrMessageBuffer.ka_message);
2105 mdclog_write(MDCLOG_WARN, "Message Type : %d is not seported", rmrMessageBuffer.rcvMessage->mtype);
2106 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
2107 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
2108 message.message.time.tv_nsec = ts.tv_nsec;
2109 message.message.time.tv_sec = ts.tv_sec;
2110 message.message.messageType = rmrMessageBuffer.rcvMessage->mtype;
2112 buildJsonMessage(message);
2117 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2118 mdclog_write(MDCLOG_DEBUG, "EXIT OK from %s", __FUNCTION__);
2124 * Send message to the CU that is not expecting for successful or unsuccessful results
2125 * @param messageBuffer
2127 * @param failedMsgId
2131 int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer,
2132 ReportingMessages_t &message,
2134 Sctp_Map_t *sctpMap) {
2136 getRequestMetaData(message, messageBuffer);
2137 if (mdclog_level_get() >= MDCLOG_INFO) {
2138 mdclog_write(MDCLOG_INFO, "send message to %s address", message.message.enodbName);
2141 auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId);
2148 * @param messageBuffer
2150 * @param failedMesgId
2153 int sendMessagetoCu(Sctp_Map_t *sctpMap,
2154 RmrMessagesBuffer_t &messageBuffer,
2155 ReportingMessages_t &message,
2157 auto *peerInfo = (ConnectedCU_t *) sctpMap->find(message.message.enodbName);
2158 if (peerInfo == nullptr) {
2159 if (failedMesgId != 0) {
2160 sendFailedSendingMessagetoXapp(messageBuffer, message, failedMesgId);
2162 mdclog_write(MDCLOG_ERR, "Failed to send message no CU entry %s", message.message.enodbName);
2168 message.message.messageType = messageBuffer.rcvMessage->mtype;
2169 auto rc = sendSctpMsg(peerInfo, message, sctpMap);
2175 * @param rmrCtx the rmr context to send and receive
2176 * @param msg the msg we got fromxApp
2177 * @param metaData data from xApp in ordered struct
2178 * @param failedMesgId the return message type error
2181 sendFailedSendingMessagetoXapp(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message, int failedMesgId) {
2182 rmr_mbuf_t *msg = rmrMessageBuffer.sendMessage;
2183 msg->len = snprintf((char *) msg->payload, 200, "the gNb/eNode name %s not found",
2184 message.message.enodbName);
2185 if (mdclog_level_get() >= MDCLOG_INFO) {
2186 mdclog_write(MDCLOG_INFO, "%s", msg->payload);
2188 msg->mtype = failedMesgId;
2191 static unsigned char tx[32];
2192 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2193 rmr_bytes2xact(msg, tx, strlen((const char *) tx));
2195 sendRmrMessage(rmrMessageBuffer, message);
2210 int addToEpoll(int epoll_fd,
2211 ConnectedCU_t *peerInfo,
2213 Sctp_Map_t *sctpMap,
2217 struct epoll_event event{};
2218 event.data.ptr = peerInfo;
2219 event.events = events;
2220 if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peerInfo->fileDescriptor, &event) < 0) {
2221 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2222 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here), %s, %s %d",
2223 strerror(errno), __func__, __LINE__);
2225 close(peerInfo->fileDescriptor);
2226 if (enodbName != nullptr) {
2227 cleanHashEntry(peerInfo, sctpMap);
2228 char key[MAX_ENODB_NAME_SIZE * 2];
2229 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
2230 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2231 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
2233 auto tmp = sctpMap->find(key);
2236 sctpMap->erase(key);
2239 peerInfo->enodbName[0] = 0;
2241 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here)");
2257 int modifyToEpoll(int epoll_fd,
2258 ConnectedCU_t *peerInfo,
2260 Sctp_Map_t *sctpMap,
2264 struct epoll_event event{};
2265 event.data.ptr = peerInfo;
2266 event.events = events;
2267 if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, peerInfo->fileDescriptor, &event) < 0) {
2268 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2269 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_MOD (may chack not to quit here), %s, %s %d",
2270 strerror(errno), __func__, __LINE__);
2272 close(peerInfo->fileDescriptor);
2273 cleanHashEntry(peerInfo, sctpMap);
2274 char key[MAX_ENODB_NAME_SIZE * 2];
2275 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
2276 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2277 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
2279 auto tmp = sctpMap->find(key);
2283 sctpMap->erase(key);
2284 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here)");
2291 int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message) {
2292 buildJsonMessage(message);
2294 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
2296 if (rmrMessageBuffer.sendMessage == nullptr) {
2297 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
2298 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
2302 if (rmrMessageBuffer.sendMessage->state != 0) {
2303 char meid[RMR_MAX_MEID]{};
2304 if (rmrMessageBuffer.sendMessage->state == RMR_ERR_RETRY) {
2306 rmrMessageBuffer.sendMessage->state = 0;
2307 mdclog_write(MDCLOG_INFO, "RETRY sending Message type %d to Xapp from %s",
2308 rmrMessageBuffer.sendMessage->mtype,
2309 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
2310 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
2311 if (rmrMessageBuffer.sendMessage == nullptr) {
2312 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
2313 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
2315 } else if (rmrMessageBuffer.sendMessage->state != 0) {
2316 mdclog_write(MDCLOG_ERR,
2317 "Message state %s while sending request %d to Xapp from %s after retry of 10 microseconds",
2318 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
2319 rmrMessageBuffer.sendMessage->mtype,
2320 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
2321 auto rc = rmrMessageBuffer.sendMessage->state;
2325 mdclog_write(MDCLOG_ERR, "Message state %s while sending request %d to Xapp from %s",
2326 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
2327 rmrMessageBuffer.sendMessage->mtype,
2328 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
2329 return rmrMessageBuffer.sendMessage->state;
2335 void buildJsonMessage(ReportingMessages_t &message) {
2337 message.outLen = sizeof(message.base64Data);
2338 base64::encode((const unsigned char *) message.message.asndata,
2339 (const int) message.message.asnLength,
2342 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2343 mdclog_write(MDCLOG_DEBUG, "asn data length = %d, base64 message length = %d ",
2344 (int) message.message.asnLength,
2345 (int) message.outLen);
2348 snprintf(message.buffer, sizeof(message.buffer),
2349 "{\"header\": {\"ts\": \"%ld.%09ld\","
2350 "\"ranName\": \"%s\","
2351 "\"messageType\": %d,"
2352 "\"direction\": \"%c\"},"
2353 "\"base64Length\": %d,"
2354 "\"asnBase64\": \"%s\"}",
2355 message.message.time.tv_sec,
2356 message.message.time.tv_nsec,
2357 message.message.enodbName,
2358 message.message.messageType,
2359 message.message.direction,
2360 (int) message.outLen,
2361 message.base64Data);
2362 static src::logger_mt &lg = my_logger::get();
2364 BOOST_LOG(lg) << message.buffer;
2370 * take RMR error code to string
2374 string translateRmrErrorMessages(int state) {
2378 str = "RMR_OK - state is good";
2380 case RMR_ERR_BADARG:
2381 str = "RMR_ERR_BADARG - argument passd to function was unusable";
2383 case RMR_ERR_NOENDPT:
2384 str = "RMR_ERR_NOENDPT - send//call could not find an endpoint based on msg type";
2387 str = "RMR_ERR_EMPTY - msg received had no payload; attempt to send an empty message";
2390 str = "RMR_ERR_NOHDR - message didn't contain a valid header";
2392 case RMR_ERR_SENDFAILED:
2393 str = "RMR_ERR_SENDFAILED - send failed; errno has nano reason";
2395 case RMR_ERR_CALLFAILED:
2396 str = "RMR_ERR_CALLFAILED - unable to send call() message";
2398 case RMR_ERR_NOWHOPEN:
2399 str = "RMR_ERR_NOWHOPEN - no wormholes are open";
2402 str = "RMR_ERR_WHID - wormhole id was invalid";
2404 case RMR_ERR_OVERFLOW:
2405 str = "RMR_ERR_OVERFLOW - operation would have busted through a buffer/field size";
2408 str = "RMR_ERR_RETRY - request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)";
2410 case RMR_ERR_RCVFAILED:
2411 str = "RMR_ERR_RCVFAILED - receive failed (hard error)";
2413 case RMR_ERR_TIMEOUT:
2414 str = "RMR_ERR_TIMEOUT - message processing call timed out";
2417 str = "RMR_ERR_UNSET - the message hasn't been populated with a transport buffer";
2420 str = "RMR_ERR_TRUNC - received message likely truncated";
2422 case RMR_ERR_INITFAILED:
2423 str = "RMR_ERR_INITFAILED - initialisation of something (probably message) failed";
2425 case RMR_ERR_NOTSUPP:
2426 str = "RMR_ERR_NOTSUPP - the request is not supported, or RMr was not initialised for the request";
2430 snprintf(buf, sizeof buf, "UNDOCUMENTED RMR_ERR : %d", state);