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",
1233 asn_DEF_E2AP_PDU.name);
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",
1317 (int)setup_xml_buffer_size,
1318 asn_DEF_E2AP_PDU.name);
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 E2AP PDU past : %s", printBuffer);
1367 auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2;
1368 unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2];
1370 er = asn_encode_to_buffer(nullptr,
1372 &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition,
1376 if (er.encoded == -1) {
1377 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s",
1378 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name,
1380 } else if (er.encoded > (ssize_t)xml_buffer_size) {
1381 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s",
1382 (int) xml_buffer_size,
1383 asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name);
1400 //build all parts and send the XML (need to copy the XML with the header to the rmrMessageBuffer payload
1401 //TODO replace with new function
1402 buildAndsendSetupRequest(message, rmrMessageBuffer, pdu);
1405 case ProcedureCode_id_ErrorIndication: {
1406 if (logLevel >= MDCLOG_DEBUG) {
1407 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
1409 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
1410 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
1414 case ProcedureCode_id_Reset: {
1415 if (logLevel >= MDCLOG_DEBUG) {
1416 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
1418 if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) {
1419 mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP");
1423 case ProcedureCode_id_RICcontrol: {
1424 if (logLevel >= MDCLOG_DEBUG) {
1425 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
1429 case ProcedureCode_id_RICindication: {
1430 if (logLevel >= MDCLOG_DEBUG) {
1431 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
1433 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
1434 auto messageSent = false;
1435 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
1436 if (logLevel >= MDCLOG_DEBUG) {
1437 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1439 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1440 if (logLevel >= MDCLOG_DEBUG) {
1441 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1443 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
1444 static unsigned char tx[32];
1445 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
1446 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1447 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1448 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1449 (unsigned char *)message.message.enodbName,
1450 strlen(message.message.enodbName));
1451 rmrMessageBuffer.sendMessage->state = 0;
1452 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1453 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1454 mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d",
1455 rmrMessageBuffer.sendMessage->sub_id,
1456 rmrMessageBuffer.sendMessage->mtype);
1458 sendRmrMessage(rmrMessageBuffer, message);
1461 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1470 case ProcedureCode_id_RICserviceQuery: {
1471 if (logLevel >= MDCLOG_DEBUG) {
1472 mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName);
1476 case ProcedureCode_id_RICserviceUpdate: {
1477 if (logLevel >= MDCLOG_DEBUG) {
1478 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
1480 if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) {
1481 mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP");
1485 case ProcedureCode_id_RICsubscription: {
1486 if (logLevel >= MDCLOG_DEBUG) {
1487 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
1491 case ProcedureCode_id_RICsubscriptionDelete: {
1492 if (logLevel >= MDCLOG_DEBUG) {
1493 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
1498 mdclog_write(MDCLOG_ERR, "Undefined or not supported message = %ld", procedureCode);
1499 message.message.messageType = 0; // no RMR message type yet
1501 buildJsonMessage(message);
1512 * @param rmrMessageBuffer
1514 void asnSuccsesfulMsg(E2AP_PDU_t *pdu,
1515 Sctp_Map_t *sctpMap,
1516 ReportingMessages_t &message,
1517 RmrMessagesBuffer_t &rmrMessageBuffer) {
1518 auto procedureCode = pdu->choice.successfulOutcome->procedureCode;
1519 auto logLevel = mdclog_level_get();
1520 if (logLevel >= MDCLOG_INFO) {
1521 mdclog_write(MDCLOG_INFO, "Successful Outcome %ld", procedureCode);
1523 switch (procedureCode) {
1524 case ProcedureCode_id_E2setup: {
1525 if (logLevel >= MDCLOG_DEBUG) {
1526 mdclog_write(MDCLOG_DEBUG, "Got E2setup\n");
1530 case ProcedureCode_id_ErrorIndication: {
1531 if (logLevel >= MDCLOG_DEBUG) {
1532 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
1534 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
1535 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
1539 case ProcedureCode_id_Reset: {
1540 if (logLevel >= MDCLOG_DEBUG) {
1541 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
1543 if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) {
1544 mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP");
1548 case ProcedureCode_id_RICcontrol: {
1549 if (logLevel >= MDCLOG_DEBUG) {
1550 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
1553 i < pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; i++) {
1554 auto messageSent = false;
1555 RICcontrolAcknowledge_IEs_t *ie = pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[i];
1556 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1557 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1559 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1560 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1561 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1563 if (ie->value.present == RICcontrolAcknowledge_IEs__value_PR_RICrequestID) {
1564 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_ACK;
1565 rmrMessageBuffer.sendMessage->state = 0;
1566 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1567 static unsigned char tx[32];
1568 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1569 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1570 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1571 (unsigned char *)message.message.enodbName,
1572 strlen(message.message.enodbName));
1574 sendRmrMessage(rmrMessageBuffer, message);
1577 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1587 case ProcedureCode_id_RICindication: {
1588 if (logLevel >= MDCLOG_DEBUG) {
1589 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
1591 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
1592 auto messageSent = false;
1593 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
1594 if (logLevel >= MDCLOG_DEBUG) {
1595 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1597 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1598 if (logLevel >= MDCLOG_DEBUG) {
1599 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1601 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
1602 static unsigned char tx[32];
1603 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
1604 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1605 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1606 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1607 (unsigned char *)message.message.enodbName,
1608 strlen(message.message.enodbName));
1609 rmrMessageBuffer.sendMessage->state = 0;
1610 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1611 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1612 mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d",
1613 rmrMessageBuffer.sendMessage->sub_id,
1614 rmrMessageBuffer.sendMessage->mtype);
1616 sendRmrMessage(rmrMessageBuffer, message);
1619 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1628 case ProcedureCode_id_RICserviceQuery: {
1629 if (logLevel >= MDCLOG_DEBUG) {
1630 mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName);
1634 case ProcedureCode_id_RICserviceUpdate: {
1635 if (logLevel >= MDCLOG_DEBUG) {
1636 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
1638 if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) {
1639 mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP");
1643 case ProcedureCode_id_RICsubscription: {
1644 if (logLevel >= MDCLOG_DEBUG) {
1645 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
1647 if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer) != 0) {
1648 mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP");
1652 case ProcedureCode_id_RICsubscriptionDelete: {
1653 if (logLevel >= MDCLOG_DEBUG) {
1654 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
1656 if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer) != 0) {
1657 mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP");
1662 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
1663 message.message.messageType = 0; // no RMR message type yet
1664 buildJsonMessage(message);
1675 * @param rmrMessageBuffer
1677 void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu,
1678 Sctp_Map_t *sctpMap,
1679 ReportingMessages_t &message,
1680 RmrMessagesBuffer_t &rmrMessageBuffer) {
1681 auto procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode;
1682 auto logLevel = mdclog_level_get();
1683 if (logLevel >= MDCLOG_INFO) {
1684 mdclog_write(MDCLOG_INFO, "Unsuccessful Outcome %ld", procedureCode);
1686 switch (procedureCode) {
1687 case ProcedureCode_id_E2setup: {
1688 if (logLevel >= MDCLOG_DEBUG) {
1689 mdclog_write(MDCLOG_DEBUG, "Got E2setup\n");
1693 case ProcedureCode_id_ErrorIndication: {
1694 if (logLevel >= MDCLOG_DEBUG) {
1695 mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName);
1697 if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) {
1698 mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP");
1702 case ProcedureCode_id_Reset: {
1703 if (logLevel >= MDCLOG_DEBUG) {
1704 mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName);
1706 if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) {
1707 mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP");
1711 case ProcedureCode_id_RICcontrol: {
1712 if (logLevel >= MDCLOG_DEBUG) {
1713 mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName);
1716 i < pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.count; i++) {
1717 auto messageSent = false;
1718 RICcontrolFailure_IEs_t *ie = pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.array[i];
1719 if (logLevel >= MDCLOG_DEBUG) {
1720 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1722 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1723 if (logLevel >= MDCLOG_DEBUG) {
1724 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1726 if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) {
1727 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_FAILURE;
1728 rmrMessageBuffer.sendMessage->state = 0;
1729 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1730 static unsigned char tx[32];
1731 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1732 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1733 rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName,
1734 strlen(message.message.enodbName));
1735 sendRmrMessage(rmrMessageBuffer, message);
1738 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1747 case ProcedureCode_id_RICindication: {
1748 if (logLevel >= MDCLOG_DEBUG) {
1749 mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName);
1751 for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) {
1752 auto messageSent = false;
1753 RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i];
1754 if (logLevel >= MDCLOG_DEBUG) {
1755 mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id);
1757 if (ie->id == ProtocolIE_ID_id_RICrequestID) {
1758 if (logLevel >= MDCLOG_DEBUG) {
1759 mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id);
1761 if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) {
1762 static unsigned char tx[32];
1763 message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION;
1764 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1765 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx));
1766 rmr_bytes2meid(rmrMessageBuffer.sendMessage,
1767 (unsigned char *)message.message.enodbName,
1768 strlen(message.message.enodbName));
1769 rmrMessageBuffer.sendMessage->state = 0;
1770 rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID;
1771 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1772 mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d",
1773 rmrMessageBuffer.sendMessage->sub_id,
1774 rmrMessageBuffer.sendMessage->mtype);
1776 sendRmrMessage(rmrMessageBuffer, message);
1779 mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request");
1788 case ProcedureCode_id_RICserviceQuery: {
1789 if (logLevel >= MDCLOG_DEBUG) {
1790 mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName);
1794 case ProcedureCode_id_RICserviceUpdate: {
1795 if (logLevel >= MDCLOG_DEBUG) {
1796 mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName);
1798 if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) {
1799 mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP");
1803 case ProcedureCode_id_RICsubscription: {
1804 if (logLevel >= MDCLOG_DEBUG) {
1805 mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName);
1807 if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) {
1808 mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP");
1812 case ProcedureCode_id_RICsubscriptionDelete: {
1813 if (logLevel >= MDCLOG_DEBUG) {
1814 mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName);
1816 if (sendRequestToXapp(message, RIC_SUB_DEL_FAILURE, rmrMessageBuffer) != 0) {
1817 mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP");
1822 mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode);
1823 message.message.messageType = 0; // no RMR message type yet
1825 buildJsonMessage(message);
1836 * @param rmrMmessageBuffer
1839 int sendRequestToXapp(ReportingMessages_t &message,
1841 RmrMessagesBuffer_t &rmrMmessageBuffer) {
1842 rmr_bytes2meid(rmrMmessageBuffer.sendMessage,
1843 (unsigned char *)message.message.enodbName,
1844 strlen(message.message.enodbName));
1845 message.message.messageType = rmrMmessageBuffer.sendMessage->mtype = requestId;
1846 rmrMmessageBuffer.sendMessage->state = 0;
1847 static unsigned char tx[32];
1848 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
1849 rmr_bytes2xact(rmrMmessageBuffer.sendMessage, tx, strlen((const char *) tx));
1851 auto rc = sendRmrMessage(rmrMmessageBuffer, message);
1856 void getRmrContext(sctp_params_t &pSctpParams) {
1857 pSctpParams.rmrCtx = nullptr;
1858 pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RMR_MAX_RCV_BYTES, RMRFL_NONE);
1859 if (pSctpParams.rmrCtx == nullptr) {
1860 mdclog_write(MDCLOG_ERR, "Failed to initialize RMR");
1864 rmr_set_stimeout(pSctpParams.rmrCtx, 0); // disable retries for any send operation
1865 // we need to find that routing table exist and we can run
1866 if (mdclog_level_get() >= MDCLOG_INFO) {
1867 mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready");
1872 if ((rmrReady = rmr_ready(pSctpParams.rmrCtx)) == 0) {
1876 if (count % 60 == 0) {
1877 mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count);
1880 if (mdclog_level_get() >= MDCLOG_INFO) {
1881 mdclog_write(MDCLOG_INFO, "RMR running");
1883 rmr_init_trace(pSctpParams.rmrCtx, 200);
1884 // get the RMR fd for the epoll
1885 pSctpParams.rmrListenFd = rmr_get_rcvfd(pSctpParams.rmrCtx);
1886 struct epoll_event event{};
1887 // add RMR fd to epoll
1888 event.events = (EPOLLIN);
1889 event.data.fd = pSctpParams.rmrListenFd;
1890 // add listening RMR FD to epoll
1891 if (epoll_ctl(pSctpParams.epoll_fd, EPOLL_CTL_ADD, pSctpParams.rmrListenFd, &event)) {
1892 mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll");
1893 close(pSctpParams.rmrListenFd);
1894 rmr_close(pSctpParams.rmrCtx);
1895 pSctpParams.rmrCtx = nullptr;
1899 int BuildPERSetupResponseMessaeFromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) {
1902 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1903 mdclog_write(MDCLOG_DEBUG, "got xml setup response \n %s\n", rmrMessageBuffer.rcvMessage->payload);
1905 auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &pdu,
1906 rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len);
1907 if (rval.code != RC_OK) {
1908 mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s",
1910 message.message.enodbName);
1914 auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu,
1915 rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len);
1916 if (er.encoded == -1) {
1917 mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno));
1919 } else if (er.encoded > (ssize_t)rmrMessageBuffer.rcvMessage->len) {
1920 mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s",
1921 (int)rmrMessageBuffer.rcvMessage->len,
1922 asn_DEF_E2AP_PDU.name);
1931 * @param rmrMessageBuffer
1935 int receiveXappMessages(Sctp_Map_t *sctpMap,
1936 RmrMessagesBuffer_t &rmrMessageBuffer,
1937 struct timespec &ts) {
1938 if (rmrMessageBuffer.rcvMessage == nullptr) {
1940 mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno));
1944 if (mdclog_level_get() >= MDCLOG_DEBUG) {
1945 mdclog_write(MDCLOG_DEBUG, "Call to rmr_rcv_msg");
1947 rmrMessageBuffer.rcvMessage = rmr_rcv_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage);
1948 if (rmrMessageBuffer.rcvMessage == nullptr) {
1949 mdclog_write(MDCLOG_ERR, "RMR Receving message with null pointer, Realloc rmr mesage buffer");
1950 rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
1953 ReportingMessages_t message;
1954 message.message.direction = 'D';
1955 message.message.time.tv_nsec = ts.tv_nsec;
1956 message.message.time.tv_sec = ts.tv_sec;
1958 // get message payload
1959 //auto msgData = msg->payload;
1960 if (rmrMessageBuffer.rcvMessage->state != 0) {
1961 mdclog_write(MDCLOG_ERR, "RMR Receving message with stat = %d", rmrMessageBuffer.rcvMessage->state);
1964 rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)message.message.enodbName);
1965 switch (rmrMessageBuffer.rcvMessage->mtype) {
1966 case RIC_E2_SETUP_RESP : {
1967 if (BuildPERSetupResponseMessaeFromXML(message, rmrMessageBuffer) != 0) {
1971 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1972 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_RESP");
1977 case RIC_E2_SETUP_FAILURE : {
1978 if (BuildPERSetupResponseMessaeFromXML(message, rmrMessageBuffer) != 0) {
1981 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1982 mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_FAILURE");
1987 case RIC_ERROR_INDICATION: {
1988 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1989 mdclog_write(MDCLOG_ERR, "Failed to send RIC_ERROR_INDICATION");
1995 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
1996 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_REQ");
2001 case RIC_SUB_DEL_REQ: {
2002 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2003 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_DEL_REQ");
2008 case RIC_CONTROL_REQ: {
2009 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2010 mdclog_write(MDCLOG_ERR, "Failed to send RIC_CONTROL_REQ");
2015 case RIC_SERVICE_QUERY: {
2016 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2017 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY");
2022 case RIC_SERVICE_UPDATE_ACK: {
2023 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2024 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK");
2029 case RIC_SERVICE_UPDATE_FAILURE: {
2030 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2031 mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE");
2036 case RIC_X2_RESET: {
2037 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2038 mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET");
2043 case RIC_X2_RESET_RESP: {
2044 if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) {
2045 mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET_RESP");
2050 case RIC_SCTP_CLEAR_ALL: {
2051 mdclog_write(MDCLOG_INFO, "RIC_SCTP_CLEAR_ALL");
2052 // loop on all keys and close socket and then erase all map.
2054 sctpMap->getKeys(v);
2055 for (auto const &iter : v) { //}; iter != sctpMap.end(); iter++) {
2056 if (!boost::starts_with((string) (iter), "host:") && !boost::starts_with((string) (iter), "msg:")) {
2057 auto *peerInfo = (ConnectedCU_t *) sctpMap->find(iter);
2058 if (peerInfo == nullptr) {
2061 close(peerInfo->fileDescriptor);
2062 memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName));
2063 message.message.direction = 'D';
2064 message.message.time.tv_nsec = ts.tv_nsec;
2065 message.message.time.tv_sec = ts.tv_sec;
2067 message.message.asnLength = rmrMessageBuffer.sendMessage->len =
2068 snprintf((char *)rmrMessageBuffer.sendMessage->payload,
2070 "%s|RIC_SCTP_CLEAR_ALL",
2071 peerInfo->enodbName);
2072 message.message.asndata = rmrMessageBuffer.sendMessage->payload;
2073 mdclog_write(MDCLOG_INFO, "%s", message.message.asndata);
2074 if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) {
2075 mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP");
2085 case E2_TERM_KEEP_ALIVE_REQ: {
2086 // send message back
2087 rmr_bytes2payload(rmrMessageBuffer.sendMessage,
2088 (unsigned char *)rmrMessageBuffer.ka_message,
2089 rmrMessageBuffer.ka_message_len);
2090 rmrMessageBuffer.sendMessage->mtype = E2_TERM_KEEP_ALIVE_RESP;
2091 rmrMessageBuffer.sendMessage->state = 0;
2092 static unsigned char tx[32];
2093 auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2094 rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, txLen);
2095 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
2096 if (rmrMessageBuffer.sendMessage == nullptr) {
2097 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
2098 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP RMR message returned NULL");
2099 } else if (rmrMessageBuffer.sendMessage->state != 0) {
2100 mdclog_write(MDCLOG_ERR, "Failed to send E2_TERM_KEEP_ALIVE_RESP, on RMR state = %d ( %s)",
2101 rmrMessageBuffer.sendMessage->state, translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str());
2102 } else if (mdclog_level_get() >= MDCLOG_DEBUG) {
2103 mdclog_write(MDCLOG_DEBUG, "Got Keep Alive Request send : %s", rmrMessageBuffer.ka_message);
2109 mdclog_write(MDCLOG_WARN, "Message Type : %d is not seported", rmrMessageBuffer.rcvMessage->mtype);
2110 message.message.asndata = rmrMessageBuffer.rcvMessage->payload;
2111 message.message.asnLength = rmrMessageBuffer.rcvMessage->len;
2112 message.message.time.tv_nsec = ts.tv_nsec;
2113 message.message.time.tv_sec = ts.tv_sec;
2114 message.message.messageType = rmrMessageBuffer.rcvMessage->mtype;
2116 buildJsonMessage(message);
2121 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2122 mdclog_write(MDCLOG_DEBUG, "EXIT OK from %s", __FUNCTION__);
2128 * Send message to the CU that is not expecting for successful or unsuccessful results
2129 * @param messageBuffer
2131 * @param failedMsgId
2135 int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer,
2136 ReportingMessages_t &message,
2138 Sctp_Map_t *sctpMap) {
2140 getRequestMetaData(message, messageBuffer);
2141 if (mdclog_level_get() >= MDCLOG_INFO) {
2142 mdclog_write(MDCLOG_INFO, "send message to %s address", message.message.enodbName);
2145 auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId);
2152 * @param messageBuffer
2154 * @param failedMesgId
2157 int sendMessagetoCu(Sctp_Map_t *sctpMap,
2158 RmrMessagesBuffer_t &messageBuffer,
2159 ReportingMessages_t &message,
2161 auto *peerInfo = (ConnectedCU_t *) sctpMap->find(message.message.enodbName);
2162 if (peerInfo == nullptr) {
2163 if (failedMesgId != 0) {
2164 sendFailedSendingMessagetoXapp(messageBuffer, message, failedMesgId);
2166 mdclog_write(MDCLOG_ERR, "Failed to send message no CU entry %s", message.message.enodbName);
2172 message.message.messageType = messageBuffer.rcvMessage->mtype;
2173 auto rc = sendSctpMsg(peerInfo, message, sctpMap);
2179 * @param rmrCtx the rmr context to send and receive
2180 * @param msg the msg we got fromxApp
2181 * @param metaData data from xApp in ordered struct
2182 * @param failedMesgId the return message type error
2185 sendFailedSendingMessagetoXapp(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message, int failedMesgId) {
2186 rmr_mbuf_t *msg = rmrMessageBuffer.sendMessage;
2187 msg->len = snprintf((char *) msg->payload, 200, "the gNb/eNode name %s not found",
2188 message.message.enodbName);
2189 if (mdclog_level_get() >= MDCLOG_INFO) {
2190 mdclog_write(MDCLOG_INFO, "%s", msg->payload);
2192 msg->mtype = failedMesgId;
2195 static unsigned char tx[32];
2196 snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++);
2197 rmr_bytes2xact(msg, tx, strlen((const char *) tx));
2199 sendRmrMessage(rmrMessageBuffer, message);
2214 int addToEpoll(int epoll_fd,
2215 ConnectedCU_t *peerInfo,
2217 Sctp_Map_t *sctpMap,
2221 struct epoll_event event{};
2222 event.data.ptr = peerInfo;
2223 event.events = events;
2224 if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peerInfo->fileDescriptor, &event) < 0) {
2225 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2226 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here), %s, %s %d",
2227 strerror(errno), __func__, __LINE__);
2229 close(peerInfo->fileDescriptor);
2230 if (enodbName != nullptr) {
2231 cleanHashEntry(peerInfo, sctpMap);
2232 char key[MAX_ENODB_NAME_SIZE * 2];
2233 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
2234 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2235 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
2237 auto tmp = sctpMap->find(key);
2240 sctpMap->erase(key);
2243 peerInfo->enodbName[0] = 0;
2245 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here)");
2261 int modifyToEpoll(int epoll_fd,
2262 ConnectedCU_t *peerInfo,
2264 Sctp_Map_t *sctpMap,
2268 struct epoll_event event{};
2269 event.data.ptr = peerInfo;
2270 event.events = events;
2271 if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, peerInfo->fileDescriptor, &event) < 0) {
2272 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2273 mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_MOD (may chack not to quit here), %s, %s %d",
2274 strerror(errno), __func__, __LINE__);
2276 close(peerInfo->fileDescriptor);
2277 cleanHashEntry(peerInfo, sctpMap);
2278 char key[MAX_ENODB_NAME_SIZE * 2];
2279 snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType);
2280 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2281 mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__);
2283 auto tmp = sctpMap->find(key);
2287 sctpMap->erase(key);
2288 mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here)");
2295 int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message) {
2296 buildJsonMessage(message);
2298 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
2300 if (rmrMessageBuffer.sendMessage == nullptr) {
2301 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
2302 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
2306 if (rmrMessageBuffer.sendMessage->state != 0) {
2307 char meid[RMR_MAX_MEID]{};
2308 if (rmrMessageBuffer.sendMessage->state == RMR_ERR_RETRY) {
2310 rmrMessageBuffer.sendMessage->state = 0;
2311 mdclog_write(MDCLOG_INFO, "RETRY sending Message type %d to Xapp from %s",
2312 rmrMessageBuffer.sendMessage->mtype,
2313 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
2314 rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage);
2315 if (rmrMessageBuffer.sendMessage == nullptr) {
2316 mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer");
2317 rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE);
2319 } else if (rmrMessageBuffer.sendMessage->state != 0) {
2320 mdclog_write(MDCLOG_ERR,
2321 "Message state %s while sending request %d to Xapp from %s after retry of 10 microseconds",
2322 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
2323 rmrMessageBuffer.sendMessage->mtype,
2324 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
2325 auto rc = rmrMessageBuffer.sendMessage->state;
2329 mdclog_write(MDCLOG_ERR, "Message state %s while sending request %d to Xapp from %s",
2330 translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(),
2331 rmrMessageBuffer.sendMessage->mtype,
2332 rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid));
2333 return rmrMessageBuffer.sendMessage->state;
2339 void buildJsonMessage(ReportingMessages_t &message) {
2341 message.outLen = sizeof(message.base64Data);
2342 base64::encode((const unsigned char *) message.message.asndata,
2343 (const int) message.message.asnLength,
2346 if (mdclog_level_get() >= MDCLOG_DEBUG) {
2347 mdclog_write(MDCLOG_DEBUG, "asn data length = %d, base64 message length = %d ",
2348 (int) message.message.asnLength,
2349 (int) message.outLen);
2352 snprintf(message.buffer, sizeof(message.buffer),
2353 "{\"header\": {\"ts\": \"%ld.%09ld\","
2354 "\"ranName\": \"%s\","
2355 "\"messageType\": %d,"
2356 "\"direction\": \"%c\"},"
2357 "\"base64Length\": %d,"
2358 "\"asnBase64\": \"%s\"}",
2359 message.message.time.tv_sec,
2360 message.message.time.tv_nsec,
2361 message.message.enodbName,
2362 message.message.messageType,
2363 message.message.direction,
2364 (int) message.outLen,
2365 message.base64Data);
2366 static src::logger_mt &lg = my_logger::get();
2368 BOOST_LOG(lg) << message.buffer;
2374 * take RMR error code to string
2378 string translateRmrErrorMessages(int state) {
2382 str = "RMR_OK - state is good";
2384 case RMR_ERR_BADARG:
2385 str = "RMR_ERR_BADARG - argument passd to function was unusable";
2387 case RMR_ERR_NOENDPT:
2388 str = "RMR_ERR_NOENDPT - send//call could not find an endpoint based on msg type";
2391 str = "RMR_ERR_EMPTY - msg received had no payload; attempt to send an empty message";
2394 str = "RMR_ERR_NOHDR - message didn't contain a valid header";
2396 case RMR_ERR_SENDFAILED:
2397 str = "RMR_ERR_SENDFAILED - send failed; errno has nano reason";
2399 case RMR_ERR_CALLFAILED:
2400 str = "RMR_ERR_CALLFAILED - unable to send call() message";
2402 case RMR_ERR_NOWHOPEN:
2403 str = "RMR_ERR_NOWHOPEN - no wormholes are open";
2406 str = "RMR_ERR_WHID - wormhole id was invalid";
2408 case RMR_ERR_OVERFLOW:
2409 str = "RMR_ERR_OVERFLOW - operation would have busted through a buffer/field size";
2412 str = "RMR_ERR_RETRY - request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)";
2414 case RMR_ERR_RCVFAILED:
2415 str = "RMR_ERR_RCVFAILED - receive failed (hard error)";
2417 case RMR_ERR_TIMEOUT:
2418 str = "RMR_ERR_TIMEOUT - message processing call timed out";
2421 str = "RMR_ERR_UNSET - the message hasn't been populated with a transport buffer";
2424 str = "RMR_ERR_TRUNC - received message likely truncated";
2426 case RMR_ERR_INITFAILED:
2427 str = "RMR_ERR_INITFAILED - initialisation of something (probably message) failed";
2429 case RMR_ERR_NOTSUPP:
2430 str = "RMR_ERR_NOTSUPP - the request is not supported, or RMr was not initialised for the request";
2434 snprintf(buf, sizeof buf, "UNDOCUMENTED RMR_ERR : %d", state);