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