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