X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=RIC-E2-TERMINATION%2FsctpThread.cpp;h=9fc72b460d7cf48c5250370d360e46f3577695bf;hb=16c799b750e66b24ff1ac71f5038c18757fd7028;hp=f4ed5363554e95e5ecdd20949cb2b440afe8f583;hpb=77fff437e22b0ac00466a486705b8bc24f06224d;p=ric-plt%2Fe2.git diff --git a/RIC-E2-TERMINATION/sctpThread.cpp b/RIC-E2-TERMINATION/sctpThread.cpp index f4ed536..9fc72b4 100644 --- a/RIC-E2-TERMINATION/sctpThread.cpp +++ b/RIC-E2-TERMINATION/sctpThread.cpp @@ -19,15 +19,14 @@ // TODO: High-level file comment. -#include "sctpThread.h" +#include "sctpThread.h" +#include "BuildRunName.h" -using namespace std::placeholders; +using namespace std; +//using namespace std::placeholders; using namespace boost::filesystem; -#ifdef __TRACING__ -using namespace opentracing; -#endif //#ifdef __cplusplus //extern "C" //{ @@ -78,78 +77,71 @@ std::atomic num_of_messages{0}; std::atomic num_of_XAPP_messages{0}; static long transactionCounter = 0; - -int main(const int argc, char **argv) { - sctp_params_t sctpParams; - - - -#ifdef __TRACING__ - opentracing::Tracer::InitGlobal(tracelibcpp::createTracer("E2 Terminator")); - auto span = opentracing::Tracer::Global()->StartSpan(__FUNCTION__); -#else - otSpan span = 0; -#endif - - { - std::random_device device{}; - std::mt19937 generator(device()); - std::uniform_int_distribution distribution(1, (long) 1e12); - transactionCounter = distribution(generator); - } - - uint64_t st = 0,en = 0; - uint32_t aux1 = 0; - uint32_t aux2 = 0; - st = rdtscp(aux1); - - unsigned num_cpus = std::thread::hardware_concurrency(); - init_log(); - mdclog_level_set(MDCLOG_INFO); - - if (std::signal(SIGINT, catch_function) == SIG_ERR) { - mdclog_write(MDCLOG_ERR, "Errir initializing SIGINT"); - exit(1); +int buildListeningPort(sctp_params_t &sctpParams) { + sctpParams.listenFD = socket (AF_INET6, SOCK_STREAM, IPPROTO_SCTP); + struct sockaddr_in6 servaddr {}; + servaddr.sin6_family = AF_INET6; + servaddr.sin6_addr = in6addr_any; + servaddr.sin6_port = htons(sctpParams.sctpPort); + if (bind(sctpParams.listenFD, (SA *)&servaddr, sizeof(servaddr)) < 0 ) { + mdclog_write(MDCLOG_ERR, "Error binding. %s\n", strerror(errno)); + return -1; } - if (std::signal(SIGABRT, catch_function)== SIG_ERR) { - mdclog_write(MDCLOG_ERR, "Errir initializing SIGABRT"); - exit(1); + if (setSocketNoBlocking(sctpParams.listenFD) == -1) { + //mdclog_write(MDCLOG_ERR, "Error binding. %s", strerror(errno)); + return -1; } - if (std::signal(SIGTERM, catch_function)== SIG_ERR) { - mdclog_write(MDCLOG_ERR, "Errir initializing SIGTERM"); - exit(1); + if (mdclog_level_get() >= MDCLOG_DEBUG) { + struct sockaddr_in6 cliaddr {}; + socklen_t len = sizeof(cliaddr); + getsockname(sctpParams.listenFD, (SA *)&cliaddr, &len); + char buff[1024] {}; + inet_ntop(AF_INET6, &cliaddr.sin6_addr, buff, sizeof(buff)); + mdclog_write(MDCLOG_DEBUG, "My address: %s, port %d\n", buff, htons(cliaddr.sin6_port)); } + if (listen(sctpParams.listenFD, SOMAXCONN) < 0) { + mdclog_write(MDCLOG_ERR, "Error listening. %s\n", strerror(errno)); + return -1; + } + struct epoll_event event {}; + event.events = EPOLLIN | EPOLLET; + event.data.fd = sctpParams.listenFD; - cpuClock = approx_CPU_MHz(100); + // add listening port to epoll + if (epoll_ctl(sctpParams.epoll_fd, EPOLL_CTL_ADD, sctpParams.listenFD, &event)) { + printf("Failed to add descriptor to epoll\n"); + mdclog_write(MDCLOG_ERR, "Failed to add descriptor to epoll. %s\n", strerror(errno)); + return -1; + } - mdclog_write(MDCLOG_DEBUG, "CPU speed %11.11f", cpuClock); - auto result = parse(argc, argv, sctpParams); + return 0; +} +int buildConfiguration(sctp_params_t &sctpParams) { path p = (sctpParams.configFilePath + "/" + sctpParams.configFileName).c_str(); if (exists(p)) { const int size = 2048; auto fileSize = file_size(p); if (fileSize > size) { mdclog_write(MDCLOG_ERR, "File %s larger than %d", p.string().c_str(), size); - exit(-1); + return -1; } } else { mdclog_write(MDCLOG_ERR, "Configuration File %s not exists", p.string().c_str()); - exit(-1); + return -1; } - ReadConfigFile conf; if (conf.openConfigFile(p.string()) == -1) { mdclog_write(MDCLOG_ERR, "Filed to open config file %s, %s", p.string().c_str(), strerror(errno)); - exit(-1); + return -1; } int rmrPort = conf.getIntValue("nano"); if (rmrPort == -1) { mdclog_write(MDCLOG_ERR, "illigal RMR port "); - exit(-1); + return -1; } sctpParams.rmrPort = (uint16_t)rmrPort; snprintf(sctpParams.rmrAddress, sizeof(sctpParams.rmrAddress), "%d", (int) (sctpParams.rmrPort)); @@ -178,7 +170,7 @@ int main(const int argc, char **argv) { tmpStr = conf.getStringValue("volume"); if (tmpStr.length() == 0) { mdclog_write(MDCLOG_ERR, "illigal volume."); - exit(-1); + return -1; } char tmpLogFilespec[VOLUME_URL_SIZE]; @@ -192,40 +184,40 @@ int main(const int argc, char **argv) { // define the file name in the tmp directory under the volume strcat(tmpLogFilespec,"/tmp/E2Term_%Y-%m-%d_%H-%M-%S.%N.tmpStr"); -// std::string localIP = conf.getStringValue("local-ip"); -// if (localIP.length() == 0) { -// mdclog_write(MDCLOG_ERR, "illigal local-ip. environment variable"); -// exit(-1); -// } - - //sctpParams.myIP.assign(getenv(localIP.c_str())); sctpParams.myIP = conf.getStringValue("local-ip"); if (sctpParams.myIP.length() == 0) { mdclog_write(MDCLOG_ERR, "illigal local-ip."); - exit(-1); + return -1; } - sctpParams.myIP = conf.getStringValue("external-fqdn"); - if (sctpParams.myIP.length() == 0) { - mdclog_write(MDCLOG_ERR, "illigal external-fqdn."); - exit(-1); + int sctpPort = conf.getIntValue("sctp-port"); + if (sctpPort == -1) { + mdclog_write(MDCLOG_ERR, "illigal SCTP port "); + return -1; + } + sctpParams.sctpPort = (uint16_t)sctpPort; + + sctpParams.fqdn = conf.getStringValue("external-fqdn"); + if (sctpParams.fqdn.length() == 0) { + mdclog_write(MDCLOG_ERR, "illigal external-fqdn"); + return -1; } std::string pod = conf.getStringValue("pod_name"); if (pod.length() == 0) { mdclog_write(MDCLOG_ERR, "illigal pod_name in config file"); - exit(-1); + return -1; } auto *podName = getenv(pod.c_str()); if (podName == nullptr) { mdclog_write(MDCLOG_ERR, "illigal pod_name or environment varible not exists : %s", pod.c_str()); - exit(-1); + return -1; } else { sctpParams.podName.assign(podName); if (sctpParams.podName.length() == 0) { mdclog_write(MDCLOG_ERR, "illigal pod_name"); - exit(-1); + return -1; } } @@ -240,14 +232,7 @@ int main(const int argc, char **argv) { } jsonTrace = sctpParams.trace; - en = rdtscp(aux2); - - mdclog_write(MDCLOG_INFO, "start = %lx end = %lx diff = %lx\n", st, en, en - st); - mdclog_write(MDCLOG_INFO, "start high = %lx start lo = %lx end high = %lx end lo = %lx\n", - st >> 32, st & 0xFFFFFFFF, (int64_t)en >> 32, en & 0xFFFFFFFF); - mdclog_write(MDCLOG_INFO, "ellapsed time = %5.9f\n", (double)(en - st)/cpuClock); - - sctpParams.ka_message_length = snprintf(sctpParams.ka_message, 4096, "{\"address\": \"%s:%d\"," + sctpParams.ka_message_length = snprintf(sctpParams.ka_message, KA_MESSAGE_SIZE, "{\"address\": \"%s:%d\"," "\"fqdn\": \"%s\"," "\"pod_name\": \"%s\"}", (const char *)sctpParams.myIP.c_str(), @@ -286,7 +271,53 @@ int main(const int argc, char **argv) { // Enable auto-flushing after each tmpStr record written if (mdclog_level_get() >= MDCLOG_DEBUG) { - boostLogger->locked_backend()->auto_flush(true); + boostLogger->locked_backend()->auto_flush(true); + } + + return 0; +} + + + +int main(const int argc, char **argv) { + sctp_params_t sctpParams; + + { + std::random_device device{}; + std::mt19937 generator(device()); + std::uniform_int_distribution distribution(1, (long) 1e12); + transactionCounter = distribution(generator); + } + +// uint64_t st = 0; +// uint32_t aux1 = 0; +// st = rdtscp(aux1); + + unsigned num_cpus = std::thread::hardware_concurrency(); + init_log(); + mdclog_level_set(MDCLOG_INFO); + + if (std::signal(SIGINT, catch_function) == SIG_ERR) { + mdclog_write(MDCLOG_ERR, "Error initializing SIGINT"); + exit(1); + } + if (std::signal(SIGABRT, catch_function)== SIG_ERR) { + mdclog_write(MDCLOG_ERR, "Error initializing SIGABRT"); + exit(1); + } + if (std::signal(SIGTERM, catch_function)== SIG_ERR) { + mdclog_write(MDCLOG_ERR, "Error initializing SIGTERM"); + exit(1); + } + + cpuClock = approx_CPU_MHz(100); + + mdclog_write(MDCLOG_DEBUG, "CPU speed %11.11f", cpuClock); + + auto result = parse(argc, argv, sctpParams); + + if (buildConfiguration(sctpParams) != 0) { + exit(-1); } // start epoll @@ -296,7 +327,7 @@ int main(const int argc, char **argv) { exit(-1); } - getRmrContext(sctpParams, &span); + getRmrContext(sctpParams); if (sctpParams.rmrCtx == nullptr) { close(sctpParams.epoll_fd); exit(-1); @@ -307,7 +338,14 @@ int main(const int argc, char **argv) { rmr_close(sctpParams.rmrCtx); close(sctpParams.epoll_fd); exit(-1); - } + } + + if (buildListeningPort(sctpParams) != 0) { + close(sctpParams.rmrListenFd); + rmr_close(sctpParams.rmrCtx); + close(sctpParams.epoll_fd); + exit(-1); + } sctpParams.sctpMap = new mapWrapper(); @@ -327,6 +365,9 @@ int main(const int argc, char **argv) { } } + auto statFlag = false; + auto statThread = std::thread(statColectorThread, (void *)&statFlag); + //loop over term_init until first message from xApp handleTermInit(sctpParams); @@ -334,9 +375,9 @@ int main(const int argc, char **argv) { t.join(); } -#ifdef __TRACING__ - opentracing::Tracer::Global()->Close(); -#endif + statFlag = true; + statThread.join(); + return 0; } @@ -350,7 +391,7 @@ void handleTermInit(sctp_params_t &sctpParams) { auto xappMessages = num_of_XAPP_messages.load(std::memory_order_acquire); if (xappMessages > 0) { if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got a message from some appliction, stop sending E@_TERM_INIT"); + mdclog_write(MDCLOG_INFO, "Got a message from some appliction, stop sending E2_TERM_INIT"); } return; } @@ -384,13 +425,12 @@ void sendTermInit(sctp_params_t &sctpParams) { return; } else { if (count % 100 == 0) { - mdclog_write(MDCLOG_ERR, "Error sending E2_TERM_INIT cause : %d ", msg->state); + mdclog_write(MDCLOG_ERR, "Error sending E2_TERM_INIT cause : %s ", translateRmrErrorMessages(msg->state).c_str()); } sleep(1); } count++; } - } /** @@ -434,7 +474,7 @@ int buildInotify(sctp_params_t &sctpParams) { sctpParams.inotifyWD = inotify_add_watch(sctpParams.inotifyFD, (const char *)sctpParams.configFilePath.c_str(), - IN_OPEN | IN_CLOSE); + (unsigned)IN_OPEN | (unsigned)IN_CLOSE_WRITE | (unsigned)IN_CLOSE_NOWRITE); //IN_CLOSE = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) if (sctpParams.inotifyWD == -1) { mdclog_write(MDCLOG_ERR, "Failed to add directory : %s to inotify (inotify_add_watch) %s", sctpParams.configFilePath.c_str(), @@ -461,11 +501,6 @@ int buildInotify(sctp_params_t &sctpParams) { * @return */ void listener(sctp_params_t *params) { -#ifdef __TRACING__ - auto span = opentracing::Tracer::Global()->StartSpan(__FUNCTION__); -#else - otSpan span = 0; -#endif int num_of_SCTP_messages = 0; auto totalTime = 0.0; mdclog_mdc_clean(); @@ -517,6 +552,8 @@ void listener(sctp_params_t *params) { rmrMessageBuffer.sendBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); } + message.statCollector = StatCollector::GetInstance(); + while (true) { if (mdclog_level_get() >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "Start EPOLL Wait"); @@ -542,9 +579,60 @@ void listener(sctp_params_t *params) { if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP)) { - handlepoll_error(events[i], message, rmrMessageBuffer, params, &span); + handlepoll_error(events[i], message, rmrMessageBuffer, params); } else if (events[i].events & EPOLLOUT) { - handleEinprogressMessages(events[i], message, rmrMessageBuffer, params, &span); + handleEinprogressMessages(events[i], message, rmrMessageBuffer, params); + } else if (params->listenFD == events[i].data.fd) { + if (mdclog_level_get() >= MDCLOG_INFO) { + mdclog_write(MDCLOG_INFO, "New connection request from sctp network\n"); + } + // new connection is requested from RAN start build connection + while (true) { + struct sockaddr in_addr {}; + socklen_t in_len; + char hostBuff[NI_MAXHOST]; + char portBuff[NI_MAXSERV]; + + in_len = sizeof(in_addr); + auto *peerInfo = (ConnectedCU_t *)calloc(1, sizeof(ConnectedCU_t)); + peerInfo->sctpParams = params; + peerInfo->fileDescriptor = accept(params->listenFD, &in_addr, &in_len); + if (peerInfo->fileDescriptor == -1) { + if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { + /* We have processed all incoming connections. */ + break; + } else { + mdclog_write(MDCLOG_ERR, "Accept error, errno = %s", strerror(errno)); + break; + } + } + if (setSocketNoBlocking(peerInfo->fileDescriptor) == -1) { + mdclog_write(MDCLOG_ERR, "setSocketNoBlocking failed to set new connection %s on port %s\n", hostBuff, portBuff); + close(peerInfo->fileDescriptor); + break; + } + auto ans = getnameinfo(&in_addr, in_len, + peerInfo->hostName, NI_MAXHOST, + peerInfo->portNumber, NI_MAXSERV, (unsigned )((unsigned int)NI_NUMERICHOST | (unsigned int)NI_NUMERICSERV)); + if (ans < 0) { + mdclog_write(MDCLOG_ERR, "Failed to get info on connection request. %s\n", strerror(errno)); + close(peerInfo->fileDescriptor); + break; + } + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Accepted connection on descriptor %d (host=%s, port=%s)\n", peerInfo->fileDescriptor, peerInfo->hostName, peerInfo->portNumber); + } + peerInfo->isConnected = false; + peerInfo->gotSetup = false; + if (addToEpoll(params->epoll_fd, + peerInfo, + (EPOLLIN | EPOLLET), + params->sctpMap, nullptr, + 0) != 0) { + break; + } + break; + } } else if (params->rmrListenFd == events[i].data.fd) { // got message from XAPP num_of_XAPP_messages.fetch_add(1, std::memory_order_release); @@ -552,11 +640,9 @@ void listener(sctp_params_t *params) { if (mdclog_level_get() >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "new message from RMR"); } - if (receiveXappMessages(params->epoll_fd, - params->sctpMap, + if (receiveXappMessages(params->sctpMap, rmrMessageBuffer, - message.message.time, - &span) != 0) { + message.message.time) != 0) { mdclog_write(MDCLOG_ERR, "Error handling Xapp message"); } } else if (params->inotifyFD == events[i].data.fd) { @@ -574,8 +660,7 @@ void listener(sctp_params_t *params) { params->sctpMap, num_of_SCTP_messages, rmrMessageBuffer, - message.message.time, - &span); + message.message.time); } clock_gettime(CLOCK_MONOTONIC, &end); @@ -590,11 +675,6 @@ void listener(sctp_params_t *params) { } } } -#ifdef __TRACING__ - span->Finish(); -#else - -#endif } /** @@ -714,19 +794,11 @@ void handleConfigChange(sctp_params_t *sctpParams) { * @param message * @param rmrMessageBuffer * @param params - * @param pSpan */ void handleEinprogressMessages(struct epoll_event &event, ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer, - sctp_params_t *params, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif + sctp_params_t *params) { auto *peerInfo = (ConnectedCU_t *)event.data.ptr; memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName)); @@ -749,26 +821,20 @@ void handleEinprogressMessages(struct epoll_event &event, message.message.asnLength = rmrMessageBuffer.sendMessage->len; mdclog_write(MDCLOG_ERR, "%s", rmrMessageBuffer.sendMessage->payload); message.message.direction = 'N'; - if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer, &lspan) != 0) { + if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) { mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP"); } memset(peerInfo->asnData, 0, peerInfo->asnLength); peerInfo->asnLength = 0; peerInfo->mtype = 0; -#ifdef __TRACING__ - lspan->Finish(); -#endif return; } peerInfo->isConnected = true; if (modifyToEpoll(params->epoll_fd, peerInfo, (EPOLLIN | EPOLLET), params->sctpMap, peerInfo->enodbName, - peerInfo->mtype, &lspan) != 0) { + peerInfo->mtype) != 0) { mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_MOD"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return; } @@ -781,36 +847,23 @@ void handleEinprogressMessages(struct epoll_event &event, mdclog_write(MDCLOG_DEBUG, "send the delayed SETUP/ENDC SETUP to sctp for %s", message.message.enodbName); } - if (sendSctpMsg(peerInfo, message, params->sctpMap, &lspan) != 0) { + if (sendSctpMsg(peerInfo, message, params->sctpMap) != 0) { if (mdclog_level_get() >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "Error write to SCTP %s %d", __func__, __LINE__); } -#ifdef __TRACING__ - lspan->Finish(); -#endif return; } memset(peerInfo->asnData, 0, peerInfo->asnLength); peerInfo->asnLength = 0; peerInfo->mtype = 0; -#ifdef __TRACING__ - lspan->Finish(); -#endif } void handlepoll_error(struct epoll_event &event, ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer, - sctp_params_t *params, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif + sctp_params_t *params) { if (event.data.fd != params->rmrListenFd) { auto *peerInfo = (ConnectedCU_t *)event.data.ptr; mdclog_write(MDCLOG_ERR, "epoll error, events %0x on fd %d, RAN NAME : %s", @@ -824,19 +877,15 @@ void handlepoll_error(struct epoll_event &event, memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName)); message.message.direction = 'N'; - if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer, &lspan) != 0) { + if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) { mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP"); } close(peerInfo->fileDescriptor); - cleanHashEntry((ConnectedCU_t *) event.data.ptr, params->sctpMap, &lspan); + cleanHashEntry((ConnectedCU_t *) event.data.ptr, params->sctpMap); } else { mdclog_write(MDCLOG_ERR, "epoll error, events %0x on RMR FD", event.events); } -#ifdef __TRACING__ - lspan->Finish(); -#endif - } /** * @@ -868,27 +917,17 @@ int setSocketNoBlocking(int socket) { * * @param val * @param m - * @param pSpan */ -void cleanHashEntry(ConnectedCU_t *val, Sctp_Map_t *m, otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else -// otSpan lspan = 0; -#endif +void cleanHashEntry(ConnectedCU_t *val, Sctp_Map_t *m) { char *dummy; auto port = (uint16_t) strtol(val->portNumber, &dummy, 10); - char searchBuff[256]{}; + char searchBuff[2048]{}; snprintf(searchBuff, sizeof searchBuff, "host:%s:%d", val->hostName, port); m->erase(searchBuff); m->erase(val->enodbName); free(val); -#ifdef __TRACING__ - lspan->Finish(); -#endif } /** @@ -901,13 +940,7 @@ void cleanHashEntry(ConnectedCU_t *val, Sctp_Map_t *m, otSpan *pSpan) { * @param mtype message number * @return 0 success, anegative number on fail */ -int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_t *m, otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif +int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_t *m) { auto loglevel = mdclog_level_get(); int fd = peerInfo->fileDescriptor; if (loglevel >= MDCLOG_DEBUG) { @@ -916,30 +949,16 @@ int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_ } while (true) { - //TODO add send to VES client or KAFKA - //format ts|mtype|direction(D/U)|length of asn data|raw data -// auto length = sizeof message.message.time -// + sizeof message.message.enodbName -// + sizeof message.message.messageType -// + sizeof message.message.direction -// + sizeof message.message.asnLength -// + message.message.asnLength; - if (send(fd,message.message.asndata, message.message.asnLength,MSG_NOSIGNAL) < 0) { if (errno == EINTR) { continue; } mdclog_write(MDCLOG_ERR, "error writing to CU a message, %s ", strerror(errno)); - // Prevent double free() of peerInfo in the event of connection failure. - // Returning failure will trigger, in x2/endc setup flow, RIC_SCTP_CONNECTION_FAILURE rmr message causing the E2M to retry. - if (!peerInfo->isConnected){ - mdclog_write(MDCLOG_ERR, "connection to CU %s is still in progress.", message.message.enodbName); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - cleanHashEntry(peerInfo, m, &lspan); + if (!peerInfo->isConnected) { + mdclog_write(MDCLOG_ERR, "connection to CU %s is still in progress.", message.message.enodbName); + return -1; + } + cleanHashEntry(peerInfo, m); close(fd); char key[MAX_ENODB_NAME_SIZE * 2]; snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName, @@ -952,11 +971,9 @@ int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_ free(tmp); } m->erase(key); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -1; } + message.statCollector->incSentMessage(string(message.message.enodbName)); message.message.direction = 'D'; // send report.buffer of size buildJsonMessage(message); @@ -967,10 +984,6 @@ int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_ message.message.enodbName, __FUNCTION__); } -#ifdef __TRACING__ - lspan->Finish(); -#endif - return 0; } } @@ -979,16 +992,9 @@ int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_ * * @param message * @param rmrMessageBuffer - * @param pSpan */ -void getRequestMetaData(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer, otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else -// otSpan lspan = 0; -#endif - rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)(message.message.enodbName)); +void getRequestMetaData(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) { + rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *) (message.message.enodbName)); message.message.asndata = rmrMessageBuffer.rcvMessage->payload; message.message.asnLength = rmrMessageBuffer.rcvMessage->len; @@ -997,103 +1003,9 @@ void getRequestMetaData(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMe mdclog_write(MDCLOG_DEBUG, "Message from Xapp RAN name = %s message length = %ld", message.message.enodbName, (unsigned long) message.message.asnLength); } -#ifdef __TRACING__ - lspan->Finish(); -#endif - } -/** - * - * @param metaData all the data strip to structure - * @param data the data recived from xAPP - * @return 0 success all other values are fault - */ -int getSetupRequestMetaData(ReportingMessages_t &message, char *data, char *host, uint16_t &port, otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else -// otSpan lspan = 0; -#endif - auto loglevel = mdclog_level_get(); - - char delimiter[4] {}; - memset(delimiter, 0, (size_t)4); - delimiter[0] = '|'; - char *tmp; - - char *val = strtok_r(data, delimiter, &tmp); - if (val != nullptr) { - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "SCTP ADDRESS parameter from message = %s", val); - } - memcpy(host, val, tmp - val ); - } else { - mdclog_write(MDCLOG_ERR, "wrong Host Name for setup request %s", data); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - - val = strtok_r(nullptr, delimiter, &tmp); - if (val != nullptr) { - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "PORT parameter from message = %s", val); - } - char *dummy; - port = (uint16_t)strtol(val, &dummy, 10); - } else { - mdclog_write(MDCLOG_ERR, "wrong Port for setup request %s", data); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -2; - } - - val = strtok_r(nullptr, delimiter, &tmp); - if (val != nullptr) { - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "RAN NAME parameter from message = %s", val); - } - memcpy(message.message.enodbName, val, tmp - val); - } else { - mdclog_write(MDCLOG_ERR, "wrong gNb/Enodeb name for setup request %s", data); -#ifdef __TRACING__ - lspan->Finish(); -#endif - - return -3; - } - val = strtok_r(nullptr, delimiter, &tmp); - if (val != nullptr) { - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "ASN length parameter from message = %s", val); - } - char *dummy; - message.message.asnLength = (uint16_t) strtol(val, &dummy, 10); - } else { - mdclog_write(MDCLOG_ERR, "wrong ASN length for setup request %s", data); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -4; - } - - message.message.asndata = (unsigned char *)tmp; // tmp is local but point to the location in data - - if (loglevel >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Message from Xapp RAN name = %s host address = %s port = %d", - message.message.enodbName, host, port); - } -#ifdef __TRACING__ - lspan->Finish(); -#endif - - return 0; -} /** * @@ -1102,50 +1014,48 @@ int getSetupRequestMetaData(ReportingMessages_t &message, char *data, char *host * @param numOfMessages * @param rmrMessageBuffer * @param ts - * @param pSpan * @return */ int receiveDataFromSctp(struct epoll_event *events, Sctp_Map_t *sctpMap, int &numOfMessages, RmrMessagesBuffer_t &rmrMessageBuffer, - struct timespec &ts, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif + struct timespec &ts) { /* We have data on the fd waiting to be read. Read and display it. * We must read whatever data is available completely, as we are running * in edge-triggered mode and won't get a notification again for the same data. */ - int done = 0; + ReportingMessages_t message {}; + auto done = 0; auto loglevel = mdclog_level_get(); + // get the identity of the interface - auto *peerInfo = (ConnectedCU_t *)events->data.ptr; + message.peerInfo = (ConnectedCU_t *)events->data.ptr; + + message.statCollector = StatCollector::GetInstance(); struct timespec start{0, 0}; struct timespec decodestart{0, 0}; struct timespec end{0, 0}; E2AP_PDU_t *pdu = nullptr; - ReportingMessages_t message {}; while (true) { if (loglevel >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP %d fd", peerInfo->fileDescriptor); + mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP %d fd", message.peerInfo->fileDescriptor); clock_gettime(CLOCK_MONOTONIC, &start); } // read the buffer directly to rmr payload message.message.asndata = rmrMessageBuffer.sendMessage->payload; message.message.asnLength = rmrMessageBuffer.sendMessage->len = - read(peerInfo->fileDescriptor, rmrMessageBuffer.sendMessage->payload, RECEIVE_SCTP_BUFFER_SIZE); + read(message.peerInfo->fileDescriptor, rmrMessageBuffer.sendMessage->payload, RECEIVE_SCTP_BUFFER_SIZE); + if (loglevel >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "Finish Read from SCTP %d fd message length = %ld", - peerInfo->fileDescriptor, message.message.asnLength); + message.peerInfo->fileDescriptor, message.message.asnLength); } - memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName)); + + memcpy(message.message.enodbName, message.peerInfo->enodbName, sizeof(message.peerInfo->enodbName)); + message.statCollector->incRecvMessage(string(message.message.enodbName)); message.message.direction = 'U'; message.message.time.tv_nsec = ts.tv_nsec; message.message.time.tv_sec = ts.tv_sec; @@ -1155,19 +1065,19 @@ int receiveDataFromSctp(struct epoll_event *events, continue; } /* If errno == EAGAIN, that means we have read all - data. So go back to the main loop. */ + data. So goReportingMessages_t back to the main loop. */ if (errno != EAGAIN) { mdclog_write(MDCLOG_ERR, "Read error, %s ", strerror(errno)); done = 1; } else if (loglevel >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "EAGAIN - descriptor = %d", peerInfo->fileDescriptor); + mdclog_write(MDCLOG_DEBUG, "EAGAIN - descriptor = %d", message.peerInfo->fileDescriptor); } break; } else if (message.message.asnLength == 0) { /* End of file. The remote has closed the connection. */ if (loglevel >= MDCLOG_INFO) { mdclog_write(MDCLOG_INFO, "END of File Closed connection - descriptor = %d", - peerInfo->fileDescriptor); + message.peerInfo->fileDescriptor); } done = 1; break; @@ -1178,13 +1088,13 @@ int receiveDataFromSctp(struct epoll_event *events, char printBuffer[4096]{}; char *tmp = printBuffer; for (size_t i = 0; i < (size_t)message.message.asnLength; ++i) { - snprintf(tmp, 2, "%02x", message.message.asndata[i]); + snprintf(tmp, 3, "%02x", message.message.asndata[i]); tmp += 2; } printBuffer[message.message.asnLength] = 0; clock_gettime(CLOCK_MONOTONIC, &end); mdclog_write(MDCLOG_DEBUG, "Before Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds", - peerInfo->enodbName, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec); + message.peerInfo->enodbName, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec); mdclog_write(MDCLOG_DEBUG, "PDU buffer length = %ld, data = : %s", message.message.asnLength, printBuffer); clock_gettime(CLOCK_MONOTONIC, &decodestart); @@ -1194,14 +1104,14 @@ int receiveDataFromSctp(struct epoll_event *events, message.message.asndata, message.message.asnLength); if (rval.code != RC_OK) { mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from RAN : %s", rval.code, - peerInfo->enodbName); + message.peerInfo->enodbName); break; } if (loglevel >= MDCLOG_DEBUG) { clock_gettime(CLOCK_MONOTONIC, &end); mdclog_write(MDCLOG_DEBUG, "After Encoding E2AP PDU for : %s, Read time is : %ld seconds, %ld nanoseconds", - peerInfo->enodbName, end.tv_sec - decodestart.tv_sec, end.tv_nsec - decodestart.tv_nsec); + message.peerInfo->enodbName, end.tv_sec - decodestart.tv_sec, end.tv_nsec - decodestart.tv_nsec); char *printBuffer; size_t size; FILE *stream = open_memstream(&printBuffer, &size); @@ -1212,15 +1122,15 @@ int receiveDataFromSctp(struct epoll_event *events, switch (pdu->present) { case E2AP_PDU_PR_initiatingMessage: {//initiating message - asnInitiatingRequest(pdu, message, rmrMessageBuffer, &lspan); + asnInitiatingRequest(pdu, message, rmrMessageBuffer); break; } case E2AP_PDU_PR_successfulOutcome: { //successful outcome - asnSuccsesfulMsg(pdu, message, sctpMap, rmrMessageBuffer, &lspan); + asnSuccsesfulMsg(pdu, message, rmrMessageBuffer); break; } case E2AP_PDU_PR_unsuccessfulOutcome: { //Unsuccessful Outcome - asnUnSuccsesfulMsg(pdu, message, sctpMap, rmrMessageBuffer, &lspan); + asnUnSuccsesfulMsg(pdu, message, rmrMessageBuffer); break; } default: @@ -1231,8 +1141,7 @@ int receiveDataFromSctp(struct epoll_event *events, clock_gettime(CLOCK_MONOTONIC, &end); mdclog_write(MDCLOG_DEBUG, "After processing message and sent to rmr for : %s, Read time is : %ld seconds, %ld nanoseconds", - peerInfo->enodbName, end.tv_sec - decodestart.tv_sec, end.tv_nsec - decodestart.tv_nsec); - + message.peerInfo->enodbName, end.tv_sec - decodestart.tv_sec, end.tv_nsec - decodestart.tv_nsec); } numOfMessages++; // remove the break for EAGAIN @@ -1253,25 +1162,24 @@ int receiveDataFromSctp(struct epoll_event *events, if (done) { if (loglevel >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Closed connection - descriptor = %d", peerInfo->fileDescriptor); + mdclog_write(MDCLOG_INFO, "Closed connection - descriptor = %d", message.peerInfo->fileDescriptor); } message.message.asnLength = rmrMessageBuffer.sendMessage->len = snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256, "%s|CU disconnected unexpectedly", - peerInfo->enodbName); + message.peerInfo->enodbName); message.message.asndata = rmrMessageBuffer.sendMessage->payload; if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, - rmrMessageBuffer, - &lspan) != 0) { + rmrMessageBuffer) != 0) { mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP"); } /* Closing descriptor make epoll remove it from the set of descriptors which are monitored. */ - close(peerInfo->fileDescriptor); - cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap, &lspan); + close(message.peerInfo->fileDescriptor); + cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap); } if (loglevel >= MDCLOG_DEBUG) { clock_gettime(CLOCK_MONOTONIC, &end); @@ -1279,117 +1187,152 @@ int receiveDataFromSctp(struct epoll_event *events, end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec); } -#ifdef __TRACING__ - lspan->Finish(); -#endif - return 0; } +static void buildAndsendSetupRequest(ReportingMessages_t &message, + E2setupRequestIEs_t *ie, + RmrMessagesBuffer_t &rmrMessageBuffer, + E2AP_PDU_t *pdu) { + auto logLevel = mdclog_level_get(); + + + if (buildRanName(message.peerInfo->enodbName, ie) < 0) { + mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n"); + } else { + memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName)); + } + // now we can send the data to e2Mgr + auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE; + + auto *rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size); + // add addrees to message + auto j = snprintf((char *)rmrMsg->payload, 256, "%s:%d|", message.peerInfo->sctpParams->myIP.c_str(), message.peerInfo->sctpParams->rmrPort); + + + unsigned char *buffer = &rmrMsg->payload[j]; + // encode to xml + asn_enc_rval_t er; + er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size - j); + if (er.encoded == -1) { + mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); + } else if (er.encoded > (ssize_t) buffer_size) { + mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s", + (int) buffer_size, + asn_DEF_E2AP_PDU.name); + } else { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Buffer of size %d, data = %s", (int) er.encoded, buffer); + } + // send to RMR + message.message.messageType = rmrMsg->mtype = RIC_E2_SETUP_REQ; + rmrMsg->state = 0; + rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName)); + + static unsigned char tx[32]; + snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); + rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx)); + + rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg); + if (rmrMsg == nullptr) { + mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr"); + } else if (rmrMsg->state != 0) { + char meid[RMR_MAX_MEID]{}; + if (rmrMsg->state == RMR_ERR_RETRY) { + usleep(5); + rmrMsg->state = 0; + mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s", + rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid)); + rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg); + if (rmrMsg == nullptr) { + mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr"); + } else if (rmrMsg->state != 0) { + mdclog_write(MDCLOG_ERR, + "RMR Retry failed %s sending request %d to Xapp from %s", + translateRmrErrorMessages(rmrMsg->state).c_str(), + rmrMsg->mtype, + rmr_get_meid(rmrMsg, (unsigned char *) meid)); + } + } else { + mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s", + translateRmrErrorMessages(rmrMsg->state).c_str(), + rmrMsg->mtype, + rmr_get_meid(rmrMsg, (unsigned char *) meid)); + } + } + message.peerInfo->gotSetup = true; + buildJsonMessage(message); + } + +} /** * * @param pdu * @param message * @param rmrMessageBuffer - * @param pSpan */ void asnInitiatingRequest(E2AP_PDU_t *pdu, ReportingMessages_t &message, - RmrMessagesBuffer_t &rmrMessageBuffer, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif - + RmrMessagesBuffer_t &rmrMessageBuffer) { + auto logLevel = mdclog_level_get(); auto procedureCode = ((InitiatingMessage_t *) pdu->choice.initiatingMessage)->procedureCode; - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Initiating message %ld", procedureCode); + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Initiating message %ld\n", procedureCode); } switch (procedureCode) { - case ProcedureCode_id_x2Setup: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got Setup Initiating message from CU - %s", - message.message.enodbName); - } - break; - } - case ProcedureCode_id_endcX2Setup: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got X2 EN-DC Setup Request from CU - %s", - message.message.enodbName); - } - break; - } - case ProcedureCode_id_ricSubscription: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got RIC Subscription Request message from CU - %s", - message.message.enodbName); - } - break; - } - case ProcedureCode_id_ricSubscriptionDelete: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got RIC Subscription Delete Request message from CU - %s", - message.message.enodbName); - } - break; - } - case ProcedureCode_id_endcConfigurationUpdate: { - if (sendRequestToXapp(message, RIC_ENDC_CONF_UPDATE, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "E2 EN-DC CONFIGURATION UPDATE message failed to send to xAPP"); + case ProcedureCode_id_E2setup: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got E2setup\n"); + } + + memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE); + for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) { + auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i]; + if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) { + if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) { + buildAndsendSetupRequest(message, ie, rmrMessageBuffer, pdu); + break; + } + } } break; } - case ProcedureCode_id_eNBConfigurationUpdate: { - if (sendRequestToXapp(message, RIC_ENB_CONF_UPDATE, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "E2 EN-BC CONFIGURATION UPDATE message failed to send to xAPP"); + case ProcedureCode_id_ErrorIndication: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName); } - break; - } - case ProcedureCode_id_x2Removal: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got E2 Removal Initiating message from CU - %s", - message.message.enodbName); + if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP"); } break; } - case ProcedureCode_id_loadIndication: { - if (sendRequestToXapp(message, RIC_ENB_LOAD_INFORMATION, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Load indication message failed to send to xAPP"); + case ProcedureCode_id_Reset: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); } - break; - } - case ProcedureCode_id_resourceStatusReportingInitiation: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got Status reporting initiation message from CU - %s", - message.message.enodbName); + if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP"); } break; } - case ProcedureCode_id_resourceStatusReporting: { - if (sendRequestToXapp(message, RIC_RESOURCE_STATUS_UPDATE, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Resource Status Reporting message failed to send to xAPP"); + case ProcedureCode_id_RICcontrol: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName); } break; } - case ProcedureCode_id_reset: { - if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP"); + case ProcedureCode_id_RICindication: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName); } - break; - } - case ProcedureCode_id_ricIndication: { - for (int i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) { + for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) { auto messageSent = false; RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i]; - if (mdclog_level_get() >= MDCLOG_DEBUG) { + if (logLevel >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); } if (ie->id == ProtocolIE_ID_id_RICrequestID) { - if (mdclog_level_get() >= MDCLOG_DEBUG) { + if (logLevel >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); } if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) { @@ -1398,16 +1341,16 @@ void asnInitiatingRequest(E2AP_PDU_t *pdu, snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); rmr_bytes2meid(rmrMessageBuffer.sendMessage, - (unsigned char *)message.message.enodbName, - strlen(message.message.enodbName)); + (unsigned char *)message.message.enodbName, + strlen(message.message.enodbName)); rmrMessageBuffer.sendMessage->state = 0; rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; if (mdclog_level_get() >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d", - rmrMessageBuffer.sendMessage->sub_id, - rmrMessageBuffer.sendMessage->mtype); + rmrMessageBuffer.sendMessage->sub_id, + rmrMessageBuffer.sendMessage->mtype); } - sendRmrMessage(rmrMessageBuffer, message, &lspan); + sendRmrMessage(rmrMessageBuffer, message); messageSent = true; } else { mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request"); @@ -1419,21 +1362,30 @@ void asnInitiatingRequest(E2AP_PDU_t *pdu, } break; } - case ProcedureCode_id_errorIndication: { - if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Error Indication message failed to send to xAPP"); + case ProcedureCode_id_RICserviceQuery: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName); + } + break; + } + case ProcedureCode_id_RICserviceUpdate: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName); + } + if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP"); } break; } - case ProcedureCode_id_ricServiceUpdate : { - if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Service Update message failed to send to xAPP"); + case ProcedureCode_id_RICsubscription: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName); } break; } - case ProcedureCode_id_gNBStatusIndication : { - if (sendRequestToXapp(message, RIC_GNB_STATUS_INDICATION, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "RIC_GNB_STATUS_INDICATION failed to send to xAPP"); + case ProcedureCode_id_RICsubscriptionDelete: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName); } break; } @@ -1446,124 +1398,50 @@ void asnInitiatingRequest(E2AP_PDU_t *pdu, break; } } -#ifdef __TRACING__ - lspan->Finish(); -#endif - } /** * * @param pdu * @param message - * @param sctpMap * @param rmrMessageBuffer - * @param pSpan */ -void asnSuccsesfulMsg(E2AP_PDU_t *pdu, ReportingMessages_t &message, Sctp_Map_t *sctpMap, - RmrMessagesBuffer_t &rmrMessageBuffer, otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif +void asnSuccsesfulMsg(E2AP_PDU_t *pdu, ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) { auto procedureCode = pdu->choice.successfulOutcome->procedureCode; - if (mdclog_level_get() >= MDCLOG_INFO) { + auto logLevel = mdclog_level_get(); + if (logLevel >= MDCLOG_INFO) { mdclog_write(MDCLOG_INFO, "Successful Outcome %ld", procedureCode); } switch (procedureCode) { - case ProcedureCode_id_x2Setup: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got Succesful Setup response from CU - %s", - message.message.enodbName); - } - if (sendResponseToXapp(message, RIC_X2_SETUP_RESP, - RIC_X2_SETUP_REQ, rmrMessageBuffer, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send Succesful Setup response for CU - %s", - message.message.enodbName); - } - break; - } - case ProcedureCode_id_endcX2Setup: { //X2_EN_DC_SETUP_REQUEST_FROM_CU - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got Succesful E2 EN-DC Setup response from CU - %s", - message.message.enodbName); - } - if (sendResponseToXapp(message, RIC_ENDC_X2_SETUP_RESP, - RIC_ENDC_X2_SETUP_REQ, rmrMessageBuffer, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send Succesful X2 EN DC Setup response for CU - %s", - message.message.enodbName); - } - break; - } - case ProcedureCode_id_endcConfigurationUpdate: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got Succesful E2 EN-DC CONFIGURATION UPDATE from CU - %s", - message.message.enodbName); - } - if (sendRequestToXapp(message, RIC_ENDC_CONF_UPDATE_ACK, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send Succesful E2 EN DC CONFIGURATION response for CU - %s", - message.message.enodbName); - } - break; - } - case ProcedureCode_id_eNBConfigurationUpdate: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got Succesful E2 ENB CONFIGURATION UPDATE from CU - %s", - message.message.enodbName); - } - if (sendRequestToXapp(message, RIC_ENB_CONF_UPDATE_ACK, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send Succesful E2 ENB CONFIGURATION response for CU - %s", - message.message.enodbName); + case ProcedureCode_id_E2setup: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got E2setup\n"); } break; } - case ProcedureCode_id_reset: { - if (sendRequestToXapp(message, RIC_X2_RESET_RESP, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send Succesful E2_RESET response for CU - %s", - message.message.enodbName); + case ProcedureCode_id_ErrorIndication: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName); } - break; - - } - case ProcedureCode_id_resourceStatusReportingInitiation: { - if (sendRequestToXapp(message, RIC_RES_STATUS_RESP, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, - "Failed to send Succesful 2_REQUEST_STATUS_REPORTING_INITIATION response for CU - %s", - message.message.enodbName); + if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP"); } break; } - case ProcedureCode_id_ricSubscription: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got Succesful RIC Subscription response from CU - %s", - message.message.enodbName); + case ProcedureCode_id_Reset: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); } - if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP"); + if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP"); } break; - } - case ProcedureCode_id_ricSubscriptionDelete: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, - "Got Succesful RIC Subscription Delete response from CU - %s", - message.message.enodbName); + case ProcedureCode_id_RICcontrol: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName); } - if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP"); - } - break; - } - case ProcedureCode_id_ricControl: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, - "Got Succesful RIC control response from CU - %s", - message.message.enodbName); - } - for (int i = 0; + for (auto i = 0; i < pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; i++) { auto messageSent = false; RICcontrolAcknowledge_IEs_t *ie = pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[i]; @@ -1582,10 +1460,10 @@ void asnSuccsesfulMsg(E2AP_PDU_t *pdu, ReportingMessages_t &message, Sctp_Map_t snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); rmr_bytes2meid(rmrMessageBuffer.sendMessage, - (unsigned char *)message.message.enodbName, - strlen(message.message.enodbName)); + (unsigned char *)message.message.enodbName, + strlen(message.message.enodbName)); - sendRmrMessage(rmrMessageBuffer, message, &lspan); + sendRmrMessage(rmrMessageBuffer, message); messageSent = true; } else { mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request"); @@ -1595,6 +1473,81 @@ void asnSuccsesfulMsg(E2AP_PDU_t *pdu, ReportingMessages_t &message, Sctp_Map_t break; } } + + break; + } + case ProcedureCode_id_RICindication: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName); + } + for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) { + auto messageSent = false; + RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i]; + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); + } + if (ie->id == ProtocolIE_ID_id_RICrequestID) { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); + } + if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) { + static unsigned char tx[32]; + message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION; + snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); + rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); + rmr_bytes2meid(rmrMessageBuffer.sendMessage, + (unsigned char *)message.message.enodbName, + strlen(message.message.enodbName)); + rmrMessageBuffer.sendMessage->state = 0; + rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d", + rmrMessageBuffer.sendMessage->sub_id, + rmrMessageBuffer.sendMessage->mtype); + } + sendRmrMessage(rmrMessageBuffer, message); + messageSent = true; + } else { + mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request"); + } + } + if (messageSent) { + break; + } + } + break; + } + case ProcedureCode_id_RICserviceQuery: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName); + } + break; + } + case ProcedureCode_id_RICserviceUpdate: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName); + } + if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP"); + } + break; + } + case ProcedureCode_id_RICsubscription: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName); + } + if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP"); + } + break; + } + case ProcedureCode_id_RICsubscriptionDelete: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName); + } + if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP"); + } break; } default: { @@ -1605,126 +1558,60 @@ void asnSuccsesfulMsg(E2AP_PDU_t *pdu, ReportingMessages_t &message, Sctp_Map_t break; } } -#ifdef __TRACING__ - lspan->Finish(); -#endif - } /** * * @param pdu * @param message - * @param sctpMap * @param rmrMessageBuffer - * @param pSpan */ void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu, ReportingMessages_t &message, - Sctp_Map_t *sctpMap, - RmrMessagesBuffer_t &rmrMessageBuffer, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif + RmrMessagesBuffer_t &rmrMessageBuffer) { auto procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode; - if (mdclog_level_get() >= MDCLOG_INFO) { + auto logLevel = mdclog_level_get(); + if (logLevel >= MDCLOG_INFO) { mdclog_write(MDCLOG_INFO, "Unsuccessful Outcome %ld", procedureCode); } switch (procedureCode) { - case ProcedureCode_id_x2Setup: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, - "Got Unsuccessful Setup response from CU - %s", - message.message.enodbName); - } - if (sendResponseToXapp(message, - RIC_X2_SETUP_FAILURE, RIC_X2_SETUP_REQ, - rmrMessageBuffer, - sctpMap, - &lspan) != 0) { - mdclog_write(MDCLOG_ERR, - "Failed to send Unsuccessful Setup response for CU - %s", - message.message.enodbName); - break; - } - break; - } - case ProcedureCode_id_endcX2Setup: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, - "Got Unsuccessful E2 EN-DC Setup response from CU - %s", - message.message.enodbName); - } - if (sendResponseToXapp(message, RIC_ENDC_X2_SETUP_FAILURE, - RIC_ENDC_X2_SETUP_REQ, - rmrMessageBuffer, - sctpMap, - &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send Unsuccessful E2 EN DC Setup response for CU - %s", - message.message.enodbName); - } - break; - } - case ProcedureCode_id_endcConfigurationUpdate: { - if (sendRequestToXapp(message, RIC_ENDC_CONF_UPDATE_FAILURE, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send Unsuccessful E2 EN DC CONFIGURATION response for CU - %s", - message.message.enodbName); - } - break; - } - case ProcedureCode_id_eNBConfigurationUpdate: { - if (sendRequestToXapp(message, RIC_ENB_CONF_UPDATE_FAILURE, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send Unsuccessful E2 ENB CONFIGURATION response for CU - %s", - message.message.enodbName); - } - break; - } - case ProcedureCode_id_resourceStatusReportingInitiation: { - if (sendRequestToXapp(message, RIC_RES_STATUS_FAILURE, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, - "Failed to send Succesful E2_REQUEST_STATUS_REPORTING_INITIATION response for CU - %s", - message.message.enodbName); + case ProcedureCode_id_E2setup: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got E2setup\n"); } break; } - case ProcedureCode_id_ricSubscription: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got Unsuccessful RIC Subscription Response from CU - %s", - message.message.enodbName); + case ProcedureCode_id_ErrorIndication: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName); } - if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP"); + if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP"); } break; } - case ProcedureCode_id_ricSubscriptionDelete: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got Unsuccessful RIC Subscription Delete Response from CU - %s", - message.message.enodbName); + case ProcedureCode_id_Reset: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); } - if (sendRequestToXapp(message, RIC_SUB_DEL_FAILURE, rmrMessageBuffer, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP"); + if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP"); } break; } - case ProcedureCode_id_ricControl: { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Got UNSuccesful RIC control response from CU - %s", - message.message.enodbName); + case ProcedureCode_id_RICcontrol: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName); } for (int i = 0; i < pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.count; i++) { auto messageSent = false; RICcontrolFailure_IEs_t *ie = pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.array[i]; - if (mdclog_level_get() >= MDCLOG_DEBUG) { + if (logLevel >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); } if (ie->id == ProtocolIE_ID_id_RICrequestID) { - if (mdclog_level_get() >= MDCLOG_DEBUG) { + if (logLevel >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); } if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) { @@ -1734,8 +1621,50 @@ void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu, static unsigned char tx[32]; snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); - rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *)message.message.enodbName, strlen(message.message.enodbName)); - sendRmrMessage(rmrMessageBuffer, message, &lspan); + rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName, + strlen(message.message.enodbName)); + sendRmrMessage(rmrMessageBuffer, message); + messageSent = true; + } else { + mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request"); + } + } + if (messageSent) { + break; + } + } + break; + } + case ProcedureCode_id_RICindication: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName); + } + for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) { + auto messageSent = false; + RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i]; + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); + } + if (ie->id == ProtocolIE_ID_id_RICrequestID) { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); + } + if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) { + static unsigned char tx[32]; + message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION; + snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); + rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); + rmr_bytes2meid(rmrMessageBuffer.sendMessage, + (unsigned char *)message.message.enodbName, + strlen(message.message.enodbName)); + rmrMessageBuffer.sendMessage->state = 0; + rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d", + rmrMessageBuffer.sendMessage->sub_id, + rmrMessageBuffer.sendMessage->mtype); + } + sendRmrMessage(rmrMessageBuffer, message); messageSent = true; } else { mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request"); @@ -1747,6 +1676,39 @@ void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu, } break; } + case ProcedureCode_id_RICserviceQuery: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName); + } + break; + } + case ProcedureCode_id_RICserviceUpdate: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName); + } + if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP"); + } + break; + } + case ProcedureCode_id_RICsubscription: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName); + } + if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP"); + } + break; + } + case ProcedureCode_id_RICsubscriptionDelete: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName); + } + if (sendRequestToXapp(message, RIC_SUB_DEL_FAILURE, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP"); + } + break; + } default: { mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode); message.message.messageType = 0; // no RMR message type yet @@ -1756,10 +1718,6 @@ void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu, break; } } -#ifdef __TRACING__ - lspan->Finish(); -#endif - } /** @@ -1767,19 +1725,11 @@ void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu, * @param message * @param requestId * @param rmrMmessageBuffer - * @param pSpan * @return */ int sendRequestToXapp(ReportingMessages_t &message, int requestId, - RmrMessagesBuffer_t &rmrMmessageBuffer, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif + RmrMessagesBuffer_t &rmrMmessageBuffer) { rmr_bytes2meid(rmrMmessageBuffer.sendMessage, (unsigned char *)message.message.enodbName, strlen(message.message.enodbName)); @@ -1789,29 +1739,16 @@ int sendRequestToXapp(ReportingMessages_t &message, snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); rmr_bytes2xact(rmrMmessageBuffer.sendMessage, tx, strlen((const char *) tx)); - auto rc = sendRmrMessage(rmrMmessageBuffer, message, &lspan); -#ifdef __TRACING__ - lspan->Finish(); -#endif - + auto rc = sendRmrMessage(rmrMmessageBuffer, message); return rc; } -void getRmrContext(sctp_params_t &pSctpParams, otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else -// otSpan lspan = 0; -#endif +void getRmrContext(sctp_params_t &pSctpParams) { pSctpParams.rmrCtx = nullptr; pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RMR_MAX_RCV_BYTES, RMRFL_NONE); if (pSctpParams.rmrCtx == nullptr) { mdclog_write(MDCLOG_ERR, "Failed to initialize RMR"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return; } @@ -1834,9 +1771,6 @@ void getRmrContext(sctp_params_t &pSctpParams, otSpan *pSpan) { if (mdclog_level_get() >= MDCLOG_INFO) { mdclog_write(MDCLOG_INFO, "RMR running"); } -#ifdef __TRACING__ - lspan->Finish(); -#endif rmr_init_trace(pSctpParams.rmrCtx, 200); // get the RMR fd for the epoll pSctpParams.rmrListenFd = rmr_get_rcvfd(pSctpParams.rmrCtx); @@ -1855,31 +1789,17 @@ void getRmrContext(sctp_params_t &pSctpParams, otSpan *pSpan) { /** * - * @param epoll_fd * @param sctpMap * @param rmrMessageBuffer * @param ts - * @param pSpan * @return */ -int receiveXappMessages(int epoll_fd, - Sctp_Map_t *sctpMap, +int receiveXappMessages(Sctp_Map_t *sctpMap, RmrMessagesBuffer_t &rmrMessageBuffer, - struct timespec &ts, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif + struct timespec &ts) { if (rmrMessageBuffer.rcvMessage == nullptr) { //we have error mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno)); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; } @@ -1890,10 +1810,6 @@ int receiveXappMessages(int epoll_fd, if (rmrMessageBuffer.rcvMessage == nullptr) { mdclog_write(MDCLOG_ERR, "RMR Receving message with null pointer, Realloc rmr mesage buffer"); rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -2; } ReportingMessages_t message; @@ -1905,212 +1821,82 @@ int receiveXappMessages(int epoll_fd, //auto msgData = msg->payload; if (rmrMessageBuffer.rcvMessage->state != 0) { mdclog_write(MDCLOG_ERR, "RMR Receving message with stat = %d", rmrMessageBuffer.rcvMessage->state); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; } switch (rmrMessageBuffer.rcvMessage->mtype) { - case RIC_X2_SETUP_REQ: { - if (connectToCUandSetUp(rmrMessageBuffer, message, epoll_fd, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "ERROR in connectToCUandSetUp on RIC_X2_SETUP_REQ"); - message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_SCTP_CONNECTION_FAILURE; - message.message.direction = 'N'; - message.message.asnLength = rmrMessageBuffer.sendMessage->len = - snprintf((char *)rmrMessageBuffer.sendMessage->payload, - 256, - "ERROR in connectToCUandSetUp on RIC_X2_SETUP_REQ"); - rmrMessageBuffer.sendMessage->state = 0; - message.message.asndata = rmrMessageBuffer.sendMessage->payload; - - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "start writing to rmr buffer"); - } - rmr_bytes2xact(rmrMessageBuffer.sendMessage, rmrMessageBuffer.rcvMessage->xaction, RMR_MAX_XID); - rmr_str2meid(rmrMessageBuffer.sendMessage, (unsigned char *)message.message.enodbName); - - sendRmrMessage(rmrMessageBuffer, message, &lspan); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -3; - } - break; - } - case RIC_ENDC_X2_SETUP_REQ: { - if (connectToCUandSetUp(rmrMessageBuffer, message, epoll_fd, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "ERROR in connectToCUandSetUp on RIC_ENDC_X2_SETUP_REQ"); - message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_SCTP_CONNECTION_FAILURE; - message.message.direction = 'N'; - message.message.asnLength = rmrMessageBuffer.sendMessage->len = - snprintf((char *)rmrMessageBuffer.sendMessage->payload, 256, - "ERROR in connectToCUandSetUp on RIC_ENDC_X2_SETUP_REQ"); - rmrMessageBuffer.sendMessage->state = 0; - message.message.asndata = rmrMessageBuffer.sendMessage->payload; - - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "start writing to rmr buffer"); - } - - rmr_bytes2xact(rmrMessageBuffer.sendMessage, rmrMessageBuffer.rcvMessage->xaction, RMR_MAX_XID); - rmr_str2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName); - - sendRmrMessage(rmrMessageBuffer, message, &lspan); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -3; - } - break; - } - case RIC_ENDC_CONF_UPDATE: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send RIC_ENDC_CONF_UPDATE"); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -4; - } - break; - } - case RIC_ENDC_CONF_UPDATE_ACK: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send RIC_ENDC_CONF_UPDATE_ACK"); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -4; - } - break; - } - case RIC_ENDC_CONF_UPDATE_FAILURE: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send RIC_ENDC_CONF_UPDATE_FAILURE"); -#ifdef __TRACING__ - lspan->Finish(); -#endif - - return -4; - } - break; - } - case RIC_ENB_CONF_UPDATE: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send RIC_ENDC_CONF_UPDATE"); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -4; - } - break; - } - case RIC_ENB_CONF_UPDATE_ACK: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send RIC_ENB_CONF_UPDATE_ACK"); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -4; + case RIC_E2_SETUP_RESP : { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { + mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_RESP"); + return -6; } break; } - case RIC_ENB_CONF_UPDATE_FAILURE: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send RIC_ENB_CONF_UPDATE_FAILURE"); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -4; + case RIC_E2_SETUP_FAILURE : { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { + mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_FAILURE"); + return -6; } break; } - case RIC_RES_STATUS_REQ: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send RIC_RES_STATUS_REQ"); -#ifdef __TRACING__ - lspan->Finish(); -#endif + case RIC_ERROR_INDICATION: { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { + mdclog_write(MDCLOG_ERR, "Failed to send RIC_ERROR_INDICATION"); return -6; } break; } case RIC_SUB_REQ: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_REQ"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -6; } break; } case RIC_SUB_DEL_REQ: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_DEL_REQ"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -6; } break; } case RIC_CONTROL_REQ: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_CONTROL_REQ"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -6; } break; } case RIC_SERVICE_QUERY: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -6; } break; } case RIC_SERVICE_UPDATE_ACK: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -6; } break; } case RIC_SERVICE_UPDATE_FAILURE: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -6; } break; } case RIC_X2_RESET: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -6; } break; } case RIC_X2_RESET_RESP: { - if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap, &lspan) != 0) { + if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET_RESP"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -6; } break; @@ -2139,8 +1925,7 @@ int receiveXappMessages(int epoll_fd, peerInfo->enodbName); message.message.asndata = rmrMessageBuffer.sendMessage->payload; mdclog_write(MDCLOG_INFO, "%s", message.message.asndata); - if (sendRequestToXapp(message, - RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer, &lspan) != 0) { + if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) { mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP"); } free(peerInfo); @@ -2185,17 +1970,11 @@ int receiveXappMessages(int epoll_fd, buildJsonMessage(message); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -7; } if (mdclog_level_get() >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "EXIT OK from %s", __FUNCTION__); } -#ifdef __TRACING__ - lspan->Finish(); -#endif return 0; } @@ -2205,31 +1984,19 @@ int receiveXappMessages(int epoll_fd, * @param message * @param failedMsgId * @param sctpMap - * @param pSpan * @return */ int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer, ReportingMessages_t &message, int failedMsgId, - Sctp_Map_t *sctpMap, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif - - getRequestMetaData(message, messageBuffer, &lspan); + Sctp_Map_t *sctpMap) { + + getRequestMetaData(message, messageBuffer); if (mdclog_level_get() >= MDCLOG_INFO) { mdclog_write(MDCLOG_INFO, "send message to %s address", message.message.enodbName); } - auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId, &lspan); -#ifdef __TRACING__ - lspan->Finish(); -#endif - + auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId); return rc; } @@ -2239,41 +2006,25 @@ int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer, * @param messageBuffer * @param message * @param failedMesgId - * @param pSpan * @return */ int sendMessagetoCu(Sctp_Map_t *sctpMap, RmrMessagesBuffer_t &messageBuffer, ReportingMessages_t &message, - int failedMesgId, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif + int failedMesgId) { auto *peerInfo = (ConnectedCU_t *) sctpMap->find(message.message.enodbName); if (peerInfo == nullptr) { if (failedMesgId != 0) { - sendFailedSendingMessagetoXapp(messageBuffer, message, failedMesgId, &lspan); + sendFailedSendingMessagetoXapp(messageBuffer, message, failedMesgId); } else { mdclog_write(MDCLOG_ERR, "Failed to send message no CU entry %s", message.message.enodbName); } -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; } // get the FD message.message.messageType = messageBuffer.rcvMessage->mtype; - auto rc = sendSctpMsg(peerInfo, message, sctpMap, &lspan); -#ifdef __TRACING__ - lspan->Finish(); -#endif - + auto rc = sendSctpMsg(peerInfo, message, sctpMap); return rc; } @@ -2285,14 +2036,7 @@ int sendMessagetoCu(Sctp_Map_t *sctpMap, * @param failedMesgId the return message type error */ void -sendFailedSendingMessagetoXapp(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message, int failedMesgId, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif +sendFailedSendingMessagetoXapp(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message, int failedMesgId) { rmr_mbuf_t *msg = rmrMessageBuffer.sendMessage; msg->len = snprintf((char *) msg->payload, 200, "the gNb/eNode name %s not found", message.message.enodbName); @@ -2306,359 +2050,10 @@ sendFailedSendingMessagetoXapp(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingM snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); rmr_bytes2xact(msg, tx, strlen((const char *) tx)); - sendRmrMessage(rmrMessageBuffer, message, &lspan); -#ifdef __TRACING__ - lspan->Finish();pLogSink -#endif - + sendRmrMessage(rmrMessageBuffer, message); } -/** - * Send Response back to xApp, message is used only when there was a request from the xApp - * - * @param enodbName the name of the gNb/eNodeB - * @param msgType the value of the message to the xApp - * @param requestType The request that was sent by the xAPP - * @param rmrCtx the rmr identifier - * @param sctpMap hash map holds data on the requestrs - * @param buf the buffer to send to xAPP - * @param size size of the buffer to send - * @return - */ -int sendResponseToXapp(ReportingMessages_t &message, - int msgType, - int requestType, - RmrMessagesBuffer_t &rmrMessageBuffer, - Sctp_Map_t *sctpMap, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif - char key[MAX_ENODB_NAME_SIZE * 2]; - snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName, requestType); - - auto xact = sctpMap->find(key); - if (xact == nullptr) { - mdclog_write(MDCLOG_ERR, "NO Request %s found for this response from CU: %s", key, - message.message.enodbName); -#ifdef __TRACING__ - lspan->Finish(); -#endif - - return -1; - } - sctpMap->erase(key); - - message.message.messageType = rmrMessageBuffer.sendMessage->mtype = msgType; //SETUP_RESPONSE_MESSAGE_TYPE; - rmr_bytes2payload(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.asndata, - message.message.asnLength); - rmr_bytes2xact(rmrMessageBuffer.sendMessage, (const unsigned char *)xact, strlen((const char *)xact)); - rmr_str2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName); - rmrMessageBuffer.sendMessage->state = 0; - - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__); - } - free(xact); - - auto rc = sendRmrMessage(rmrMessageBuffer, message, &lspan); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return rc; -} - -/** - * build the SCTP connection to eNodB or gNb - * @param rmrMessageBuffer - * @param message - * @param epoll_fd - * @param sctpMap - * @param pSpan - * @return - */ -int connectToCUandSetUp(RmrMessagesBuffer_t &rmrMessageBuffer, - ReportingMessages_t &message, - int epoll_fd, - Sctp_Map_t *sctpMap, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif - struct sockaddr_in6 servaddr{}; - struct addrinfo hints{}, *result; - auto msgData = rmrMessageBuffer.rcvMessage->payload; - unsigned char meid[RMR_MAX_MEID]{}; - char host[256]{}; - uint16_t port = 0; - - message.message.messageType = rmrMessageBuffer.rcvMessage->mtype; - rmr_mbuf_t *msg = rmrMessageBuffer.rcvMessage; - rmr_get_meid(msg, meid); - - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "message %d Received for MEID :%s. SETUP/EN-DC Setup Request from xApp, Message = %s", - msg->mtype, meid, msgData); - } - if (getSetupRequestMetaData(message, (char *)msgData, host, port, &lspan) < 0) { - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Error in setup parameters %s, %d", __func__, __LINE__); - } -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - - //// message asndata points to the start of the asndata of the message and not to start of payload - // search if the same host:port but not the same enodbname - char searchBuff[256]{}; - snprintf(searchBuff, sizeof searchBuff, "host:%s:%d", host, port); - auto e = (char *)sctpMap->find(searchBuff); - if (e != nullptr) { - // found one compare if not the same - if (strcmp(message.message.enodbName, e) != 0) { - mdclog_write(MDCLOG_ERR, - "Try to connect CU %s to Host %s but %s already connected", - message.message.enodbName, host, e); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - } - - // check if not alread connected. if connected send the request and return - auto *peerInfo = (ConnectedCU_t *)sctpMap->find(message.message.enodbName); - if (peerInfo != nullptr) { -// snprintf(strErr, -// 128, -// "Device %s already connected please remove and then setup again", -// message.message.enodbName); - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, - "Device already connected to %s", - message.message.enodbName); - } - message.message.messageType = msg->mtype; - auto rc = sendSctpMsg(peerInfo, message, sctpMap, &lspan); - if (rc != 0) { - mdclog_write(MDCLOG_ERR, "failed write to SCTP %s, %d", __func__, __LINE__); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - - char key[MAX_ENODB_NAME_SIZE * 2]; - snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName, msg->mtype); - int xaction_len = strlen((const char *) msg->xaction); - auto *xaction = (unsigned char *) calloc(1, xaction_len); - memcpy(xaction, msg->xaction, xaction_len); - sctpMap->setkey(key, xaction); - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "set key = %s from %s at line %d", key, __FUNCTION__, __LINE__); - } -#ifdef __TRACING__ - lspan->Finish(); -#endif - return 0; - } - - peerInfo = (ConnectedCU_t *) calloc(1, sizeof(ConnectedCU_t)); - memcpy(peerInfo->enodbName, message.message.enodbName, sizeof(message.message.enodbName)); - - // new connection - if ((peerInfo->fileDescriptor = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) { - mdclog_write(MDCLOG_ERR, "Socket Error, %s %s, %d", strerror(errno), __func__, __LINE__); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - - auto optval = 1; - if (setsockopt(peerInfo->fileDescriptor, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof optval) != 0) { - mdclog_write(MDCLOG_ERR, "setsockopt SO_REUSEPORT Error, %s %s, %d", strerror(errno), __func__, __LINE__); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - optval = 1; - if (setsockopt(peerInfo->fileDescriptor, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval) != 0) { - mdclog_write(MDCLOG_ERR, "setsockopt SO_REUSEADDR Error, %s %s, %d", strerror(errno), __func__, __LINE__); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - servaddr.sin6_family = AF_INET6; - - struct sockaddr_in6 localAddr {}; - localAddr.sin6_family = AF_INET6; - localAddr.sin6_addr = in6addr_any; - localAddr.sin6_port = htons(SRC_PORT); - - if (bind(peerInfo->fileDescriptor, (struct sockaddr*)&localAddr , sizeof(struct sockaddr_in6)) < 0) { - mdclog_write(MDCLOG_ERR, "bind Socket Error, %s %s, %d", strerror(errno), __func__, __LINE__); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - }//Ends the binding. - - memset(&hints, 0, sizeof hints); - hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(host, nullptr, &hints, &result) < 0) { - close(peerInfo->fileDescriptor); - mdclog_write(MDCLOG_ERR, "getaddrinfo error for %s, Error = %s", host, strerror(errno)); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - memcpy(&servaddr, result->ai_addr, sizeof(struct sockaddr_in6)); - freeaddrinfo(result); - - servaddr.sin6_port = htons(port); /* daytime server */ - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Send Connect FD = %d host : %s port %d", - peerInfo->fileDescriptor, - host, - port); - } - - // Add to Epol - if (addToEpoll(epoll_fd, peerInfo, (EPOLLOUT | EPOLLIN | EPOLLET), sctpMap, message.message.enodbName, - msg->mtype, &lspan) != 0) { -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - - char hostBuff[NI_MAXHOST]; - char portBuff[NI_MAXHOST]; - if (getnameinfo((SA *) &servaddr, sizeof(servaddr), - hostBuff, sizeof(hostBuff), - portBuff, sizeof(portBuff), - (uint) (NI_NUMERICHOST) | (uint) (NI_NUMERICSERV)) != 0) { - mdclog_write(MDCLOG_ERR, "getnameinfo() Error, %s %s %d", strerror(errno), __func__, __LINE__); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - - if (setSocketNoBlocking(peerInfo->fileDescriptor) != 0) { - mdclog_write(MDCLOG_ERR, "setSocketNoBlocking failed to set new connection %s on sctpPort %s", hostBuff, - portBuff); - close(peerInfo->fileDescriptor); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - - memcpy(peerInfo->hostName, hostBuff, strlen(hostBuff)); - peerInfo->hostName[strlen(hostBuff)] = 0; - memcpy(peerInfo->portNumber, portBuff, strlen(portBuff)); - peerInfo->portNumber[strlen(portBuff)] = 0; - - // map by enoodb/gnb name - sctpMap->setkey(message.message.enodbName, peerInfo); - //map host and port to enodeb - sctpMap->setkey(searchBuff, message.message.enodbName); - - // save message for the return values - char key[MAX_ENODB_NAME_SIZE * 2]; - snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", message.message.enodbName, msg->mtype); - int xaction_len = strlen((const char *) msg->xaction); - auto *xaction = (unsigned char *) calloc(1, xaction_len); - memcpy(xaction, msg->xaction, xaction_len); - sctpMap->setkey(key, xaction); - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "End building peerinfo: %s for CU %s", key, message.message.enodbName); - } - - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Send connect to FD %d, %s, %d", - peerInfo->fileDescriptor, __func__, __LINE__); - } - if (connect(peerInfo->fileDescriptor, (SA *) &servaddr, sizeof(servaddr)) < 0) { - if (errno != EINPROGRESS) { - mdclog_write(MDCLOG_ERR, "connect FD %d to host : %s port %d, %s", - peerInfo->fileDescriptor, host, port, strerror(errno)); - close(peerInfo->fileDescriptor); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, - "Connect to FD %d returned with EINPROGRESS : %s", - peerInfo->fileDescriptor, strerror(errno)); - } - // since message.message.asndata is pointing to the asndata in the rmr message payload we copy it like this - memcpy(peerInfo->asnData, message.message.asndata, message.message.asnLength); - peerInfo->asnLength = message.message.asnLength; - peerInfo->mtype = msg->mtype; -#ifdef __TRACING__ - lspan->Finish(); -#endif - return 0; - } - - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "Connect to FD %d returned OK without EINPROGRESS", peerInfo->fileDescriptor); - } - - peerInfo->isConnected = true; - - if (modifyToEpoll(epoll_fd, peerInfo, (EPOLLIN | EPOLLET), sctpMap, message.message.enodbName, msg->mtype, - &lspan) != 0) { -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Connected to host : %s port %d", host, port); - } - - message.message.messageType = msg->mtype; - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Send SCTP message to FD %d", peerInfo->fileDescriptor); - } - if (sendSctpMsg(peerInfo, message, sctpMap, &lspan) != 0) { - mdclog_write(MDCLOG_ERR, "Error write to SCTP %s %d", __func__, __LINE__); -#ifdef __TRACING__ - lspan->Finish(); -#endif - return -1; - } - memset(peerInfo->asnData, 0, message.message.asnLength); - peerInfo->asnLength = 0; - peerInfo->mtype = 0; - - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Sent message to SCTP for %s", message.message.enodbName); - } -#ifdef __TRACING__ - lspan->Finish(); -#endif - return 0; -} /** * @@ -2668,7 +2063,6 @@ int connectToCUandSetUp(RmrMessagesBuffer_t &rmrMessageBuffer, * @param sctpMap * @param enodbName * @param msgType - * @param pSpan * @return */ int addToEpoll(int epoll_fd, @@ -2676,14 +2070,7 @@ int addToEpoll(int epoll_fd, uint32_t events, Sctp_Map_t *sctpMap, char *enodbName, - int msgType, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif + int msgType) { // Add to Epol struct epoll_event event{}; event.data.ptr = peerInfo; @@ -2694,26 +2081,24 @@ int addToEpoll(int epoll_fd, strerror(errno), __func__, __LINE__); } close(peerInfo->fileDescriptor); - cleanHashEntry(peerInfo, sctpMap, &lspan); - char key[MAX_ENODB_NAME_SIZE * 2]; - snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType); - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__); - } - auto tmp = sctpMap->find(key); - if (tmp) { - free(tmp); + if (enodbName != nullptr) { + cleanHashEntry(peerInfo, sctpMap); + char key[MAX_ENODB_NAME_SIZE * 2]; + snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType); + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__); + } + auto tmp = sctpMap->find(key); + if (tmp) { + free(tmp); + sctpMap->erase(key); + } + } else { + peerInfo->enodbName[0] = 0; } - sctpMap->erase(key); mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here)"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -1; } -#ifdef __TRACING__ - lspan->Finish(); -#endif return 0; } @@ -2725,7 +2110,6 @@ int addToEpoll(int epoll_fd, * @param sctpMap * @param enodbName * @param msgType - * @param pSpan * @return */ int modifyToEpoll(int epoll_fd, @@ -2733,14 +2117,7 @@ int modifyToEpoll(int epoll_fd, uint32_t events, Sctp_Map_t *sctpMap, char *enodbName, - int msgType, - otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else - otSpan lspan = 0; -#endif + int msgType) { // Add to Epol struct epoll_event event{}; event.data.ptr = peerInfo; @@ -2751,7 +2128,7 @@ int modifyToEpoll(int epoll_fd, strerror(errno), __func__, __LINE__); } close(peerInfo->fileDescriptor); - cleanHashEntry(peerInfo, sctpMap, &lspan); + cleanHashEntry(peerInfo, sctpMap); char key[MAX_ENODB_NAME_SIZE * 2]; snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType); if (mdclog_level_get() >= MDCLOG_DEBUG) { @@ -2763,42 +2140,13 @@ int modifyToEpoll(int epoll_fd, } sctpMap->erase(key); mdclog_write(MDCLOG_ERR, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here)"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -1; } -#ifdef __TRACING__ - lspan->Finish(); -#endif return 0; } -int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message, otSpan *pSpan) { -#ifdef __TRACING__ - auto lspan = opentracing::Tracer::Global()->StartSpan( - __FUNCTION__, { opentracing::ChildOf(&pSpan->get()->context()) }); -#else -// otSpan lspan = 0; -#endif - //serialize the span -#ifdef __TRACING__ - std::unordered_map data; - RICCarrierWriter carrier(data); - opentracing::Tracer::Global()->Inject((lspan.get())->context(), carrier); - nlohmann::json j = data; - std::string str = j.dump(); - static auto maxTraceLength = 0; - - maxTraceLength = str.length() > maxTraceLength ? str.length() : maxTraceLength; - // serialized context can be put to RMR message using function: - if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "max trace length is %d trace data length = %ld data = %s", maxTraceLength, - str.length(), str.c_str()); - } - rmr_set_trace(rmrMessageBuffer.sendMessage, (const unsigned char *) str.c_str(), str.length()); -#endif +int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message) { buildJsonMessage(message); rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage); @@ -2806,9 +2154,6 @@ int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &m if (rmrMessageBuffer.sendMessage == nullptr) { rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer"); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -1; } @@ -2824,9 +2169,6 @@ int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &m if (rmrMessageBuffer.sendMessage == nullptr) { mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer"); rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); -#ifdef __TRACING__ - lspan->Finish(); -#endif return -1; } else if (rmrMessageBuffer.sendMessage->state != 0) { mdclog_write(MDCLOG_ERR, @@ -2835,9 +2177,6 @@ int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &m rmrMessageBuffer.sendMessage->mtype, rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid)); auto rc = rmrMessageBuffer.sendMessage->state; -#ifdef __TRACING__ - lspan->Finish(); -#endif return rc; } } else { @@ -2845,9 +2184,6 @@ int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &m translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(), rmrMessageBuffer.sendMessage->mtype, rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid)); -#ifdef __TRACING__ - lspan->Finish(); -#endif return rmrMessageBuffer.sendMessage->state; } }