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