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" |
| 28 | |
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++; |
| 1158 | // remove the break for EAGAIN |
| 1159 | //break; |
| 1160 | if (pdu != nullptr) { |
| 1161 | //TODO need to test ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); to get better performance |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 1162 | ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); |
| 1163 | //ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
aa7133@att.com | 9dff4f0 | 2020-03-29 09:55:22 +0300 | [diff] [blame] | 1164 | //pdu = nullptr; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1165 | } |
| 1166 | //clock_gettime(CLOCK_MONOTONIC, &start); |
| 1167 | } |
| 1168 | // in case of break to avoid memory leak |
aa7133@att.com | 9dff4f0 | 2020-03-29 09:55:22 +0300 | [diff] [blame] | 1169 | // if (pdu != nullptr) { |
| 1170 | // //ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); |
| 1171 | // ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); |
| 1172 | // //pdu = nullptr; |
| 1173 | // } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1174 | |
| 1175 | if (done) { |
| 1176 | if (loglevel >= MDCLOG_INFO) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1177 | mdclog_write(MDCLOG_INFO, "Closed connection - descriptor = %d", message.peerInfo->fileDescriptor); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1178 | } |
| 1179 | message.message.asnLength = rmrMessageBuffer.sendMessage->len = |
| 1180 | snprintf((char *)rmrMessageBuffer.sendMessage->payload, |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 1181 | 256, |
| 1182 | "%s|CU disconnected unexpectedly", |
| 1183 | message.peerInfo->enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1184 | message.message.asndata = rmrMessageBuffer.sendMessage->payload; |
| 1185 | |
| 1186 | if (sendRequestToXapp(message, |
| 1187 | RIC_SCTP_CONNECTION_FAILURE, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1188 | rmrMessageBuffer) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1189 | mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP"); |
| 1190 | } |
| 1191 | |
| 1192 | /* 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] | 1193 | close(message.peerInfo->fileDescriptor); |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1194 | cleanHashEntry((ConnectedCU_t *) events->data.ptr, sctpMap); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1195 | } |
| 1196 | if (loglevel >= MDCLOG_DEBUG) { |
| 1197 | clock_gettime(CLOCK_MONOTONIC, &end); |
| 1198 | mdclog_write(MDCLOG_DEBUG, "from receive SCTP to send RMR time is %ld seconds and %ld nanoseconds", |
| 1199 | end.tv_sec - start.tv_sec, end.tv_nsec - start.tv_nsec); |
| 1200 | |
| 1201 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1202 | return 0; |
| 1203 | } |
| 1204 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1205 | static void buildAndsendSetupRequest(ReportingMessages_t &message, |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1206 | RmrMessagesBuffer_t &rmrMessageBuffer, |
aa7133@att.com | 233facd | 2020-04-02 00:10:46 +0300 | [diff] [blame] | 1207 | E2AP_PDU_t *pdu, |
| 1208 | vector<string> repValues) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1209 | auto logLevel = mdclog_level_get(); |
| 1210 | |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1211 | // now we can send the data to e2Mgr |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 1212 | auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1213 | |
| 1214 | auto *rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size); |
| 1215 | // add addrees to message |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1216 | |
| 1217 | |
aa7133@att.com | bc11077 | 2020-03-25 09:45:14 +0200 | [diff] [blame] | 1218 | // unsigned char *buffer = &rmrMsg->payload[j]; |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 1219 | unsigned char buffer[RECEIVE_SCTP_BUFFER_SIZE * 2]; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1220 | // encode to xml |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 1221 | 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] | 1222 | if (er.encoded == -1) { |
| 1223 | mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); |
| 1224 | } else if (er.encoded > (ssize_t) buffer_size) { |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1225 | 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] | 1226 | (int) buffer_size, |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1227 | asn_DEF_E2AP_PDU.name, __func__, __LINE__); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1228 | } else { |
aa7133@att.com | 233facd | 2020-04-02 00:10:46 +0300 | [diff] [blame] | 1229 | // we have the XML |
| 1230 | pugi::xml_document doc; |
| 1231 | pugi::xml_parse_result result = doc.load_string((const char *)buffer); |
| 1232 | if (result) { |
| 1233 | unsigned int index = 0; |
| 1234 | for (auto tool : doc.child("E2AP-PDU") |
| 1235 | .child("initiatingMessage") |
| 1236 | .child("value") |
| 1237 | .child("E2setupRequest") |
| 1238 | .child("protocolIEs") |
| 1239 | .children("E2setupRequestIEs")) { |
| 1240 | for (auto n : tool.child("value").child("RANfunctions-List").child( |
| 1241 | "ProtocolIE-SingleContainer").children()) { |
| 1242 | //ProtocolIE-SingleContainer |
| 1243 | //cout << "\t1 " << n.name() << endl; |
| 1244 | if (strcmp(n.name(), "value") == 0) { |
| 1245 | for (auto l : tool.child("value").children()) { |
| 1246 | //cout << "\t\t2 " << l.name() << endl; |
| 1247 | for (auto f : l.children()) { |
| 1248 | //cout << "\t\t\t3 " << f.name() << endl; |
| 1249 | for (auto g : f.child("value").children()) { |
| 1250 | //cout << "\t\t\t\t4 " << g.name() << endl; |
| 1251 | for (auto a : g.children()) { |
| 1252 | if (strcmp(a.name(), "ranFunctionDefinition") == 0) { |
| 1253 | if (repValues.size() > index) { |
| 1254 | a.remove_children(); |
| 1255 | string val = repValues.at(index++); |
| 1256 | // here we get vector with counter |
| 1257 | a.append_child(pugi::node_pcdata).set_value(val.c_str()); |
| 1258 | |
| 1259 | } |
| 1260 | } |
| 1261 | //cout << "\t\t\t\t\t5 " << a.name() << " " << a.child_value() << endl; |
| 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | // memstream strinBuf(buffer, RECEIVE_SCTP_BUFFER_SIZE * 2); |
| 1271 | // |
| 1272 | // strinBuf.read(, RECEIVE_SCTP_BUFFER_SIZE * 2); |
| 1273 | |
| 1274 | streambuf *oldCout = cout.rdbuf(); |
| 1275 | ostringstream memCout; |
| 1276 | // create new cout |
| 1277 | cout.rdbuf(memCout.rdbuf()); |
| 1278 | doc.save(std::cout); |
| 1279 | //return to the normal cout |
| 1280 | cout.rdbuf(oldCout); |
| 1281 | memcpy(buffer, memCout.str().c_str(), memCout.str().length()); |
| 1282 | } |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 1283 | rmrMsg->len = snprintf((char *)rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s", |
| 1284 | message.peerInfo->sctpParams->myIP.c_str(), |
| 1285 | message.peerInfo->sctpParams->rmrPort, |
| 1286 | buffer); |
| 1287 | if (logLevel >= MDCLOG_DEBUG) { |
| 1288 | 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] | 1289 | } |
aa7133@att.com | 11b17d4 | 2020-03-22 11:35:16 +0200 | [diff] [blame] | 1290 | // send to RMR |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1291 | message.message.messageType = rmrMsg->mtype = RIC_E2_SETUP_REQ; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1292 | rmrMsg->state = 0; |
| 1293 | rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName)); |
| 1294 | |
| 1295 | static unsigned char tx[32]; |
| 1296 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 1297 | rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx)); |
| 1298 | |
| 1299 | rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg); |
| 1300 | if (rmrMsg == nullptr) { |
| 1301 | mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr"); |
| 1302 | } else if (rmrMsg->state != 0) { |
| 1303 | char meid[RMR_MAX_MEID]{}; |
| 1304 | if (rmrMsg->state == RMR_ERR_RETRY) { |
| 1305 | usleep(5); |
| 1306 | rmrMsg->state = 0; |
| 1307 | mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s", |
| 1308 | rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid)); |
| 1309 | rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg); |
| 1310 | if (rmrMsg == nullptr) { |
| 1311 | mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr"); |
| 1312 | } else if (rmrMsg->state != 0) { |
| 1313 | mdclog_write(MDCLOG_ERR, |
| 1314 | "RMR Retry failed %s sending request %d to Xapp from %s", |
| 1315 | translateRmrErrorMessages(rmrMsg->state).c_str(), |
| 1316 | rmrMsg->mtype, |
| 1317 | rmr_get_meid(rmrMsg, (unsigned char *) meid)); |
| 1318 | } |
| 1319 | } else { |
| 1320 | mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s", |
| 1321 | translateRmrErrorMessages(rmrMsg->state).c_str(), |
| 1322 | rmrMsg->mtype, |
| 1323 | rmr_get_meid(rmrMsg, (unsigned char *) meid)); |
| 1324 | } |
| 1325 | } |
| 1326 | message.peerInfo->gotSetup = true; |
| 1327 | buildJsonMessage(message); |
aa7133@att.com | bc11077 | 2020-03-25 09:45:14 +0200 | [diff] [blame] | 1328 | if (rmrMsg != nullptr) { |
| 1329 | rmr_free_msg(rmrMsg); |
| 1330 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1334 | /** |
| 1335 | * |
| 1336 | * @param pdu |
| 1337 | * @param message |
| 1338 | * @param rmrMessageBuffer |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1339 | */ |
| 1340 | void asnInitiatingRequest(E2AP_PDU_t *pdu, |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1341 | Sctp_Map_t *sctpMap, |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1342 | ReportingMessages_t &message, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1343 | RmrMessagesBuffer_t &rmrMessageBuffer) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1344 | auto logLevel = mdclog_level_get(); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1345 | auto procedureCode = ((InitiatingMessage_t *) pdu->choice.initiatingMessage)->procedureCode; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1346 | if (logLevel >= MDCLOG_DEBUG) { |
| 1347 | mdclog_write(MDCLOG_DEBUG, "Initiating message %ld\n", procedureCode); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1348 | } |
| 1349 | switch (procedureCode) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1350 | case ProcedureCode_id_E2setup: { |
| 1351 | if (logLevel >= MDCLOG_DEBUG) { |
| 1352 | mdclog_write(MDCLOG_DEBUG, "Got E2setup\n"); |
| 1353 | } |
| 1354 | |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1355 | // first get the message as XML buffer |
| 1356 | auto setup_xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; |
| 1357 | unsigned char setup_xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2]; |
| 1358 | //unsigned char *tmp_buff_cursor = setup_xml_buffer; |
| 1359 | |
| 1360 | auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, setup_xml_buffer, setup_xml_buffer_size); |
| 1361 | if (er.encoded == -1) { |
| 1362 | mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); |
| 1363 | } else if (er.encoded > (ssize_t) setup_xml_buffer_size) { |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1364 | 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] | 1365 | (int)setup_xml_buffer_size, |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1366 | asn_DEF_E2AP_PDU.name, __func__, __LINE__); |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1367 | } |
| 1368 | std::string xmlString(setup_xml_buffer_size, setup_xml_buffer_size + er.encoded); |
| 1369 | |
aa7133@att.com | 233facd | 2020-04-02 00:10:46 +0300 | [diff] [blame] | 1370 | vector <string> runFunDEFXML_v; |
| 1371 | runFunDEFXML_v.clear(); |
| 1372 | string runFuncStr = {}; |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1373 | auto failed = false; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1374 | memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE); |
| 1375 | for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) { |
| 1376 | auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i]; |
| 1377 | if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) { |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1378 | // get the ran name for meid |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1379 | if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) { |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1380 | if (buildRanName(message.peerInfo->enodbName, ie) < 0) { |
| 1381 | mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n"); |
| 1382 | // no mesage will be sent |
| 1383 | break; |
| 1384 | } |
| 1385 | memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName)); |
| 1386 | sctpMap->setkey(message.message.enodbName, message.peerInfo); |
| 1387 | } |
| 1388 | } |
| 1389 | // reformat RANFUNCTION Definition to XML |
| 1390 | if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) { |
| 1391 | if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) { |
| 1392 | for (auto j = 0; i < ie->value.choice.RANfunctions_List.list.count; i++) { |
| 1393 | auto *raNfunctionItemIEs = (RANfunction_ItemIEs_t *)ie->value.choice.RANfunctions_List.list.array[j]; |
aa7133@att.com | 1c4f50f | 2020-03-30 14:30:52 +0300 | [diff] [blame] | 1394 | if (raNfunctionItemIEs->id == ProtocolIE_ID_id_RANfunction_Item && |
| 1395 | (raNfunctionItemIEs->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item)) { |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1396 | // encode to xml |
| 1397 | E2SM_gNB_NRT_RANfunction_Definition_t *ranFunDef = nullptr; |
| 1398 | auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, |
| 1399 | &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, |
| 1400 | (void **)&ranFunDef, |
aa7133@att.com | 1c4f50f | 2020-03-30 14:30:52 +0300 | [diff] [blame] | 1401 | raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.buf, |
| 1402 | raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.size); |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1403 | if (rval.code != RC_OK) { |
aa7133@att.com | 1c4f50f | 2020-03-30 14:30:52 +0300 | [diff] [blame] | 1404 | mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2SM message from : %s", |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1405 | rval.code, |
| 1406 | asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name); |
| 1407 | failed = true; |
| 1408 | break; |
| 1409 | } |
| 1410 | |
| 1411 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1412 | char *printBuffer; |
| 1413 | size_t size; |
| 1414 | FILE *stream = open_memstream(&printBuffer, &size); |
aa7133@att.com | 82d36ed | 2020-03-31 23:20:16 +0300 | [diff] [blame] | 1415 | asn_fprint(stream, &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, ranFunDef); |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1416 | mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU past : %s", |
| 1417 | asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, |
| 1418 | printBuffer); |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1419 | } |
| 1420 | auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; |
| 1421 | unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2]; |
| 1422 | // encode to xml |
| 1423 | er = asn_encode_to_buffer(nullptr, |
| 1424 | ATS_BASIC_XER, |
| 1425 | &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, |
| 1426 | ranFunDef, |
| 1427 | xml_buffer, |
| 1428 | xml_buffer_size); |
| 1429 | if (er.encoded == -1) { |
| 1430 | mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", |
| 1431 | asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, |
| 1432 | strerror(errno)); |
aa7133@att.com | 1c4f50f | 2020-03-30 14:30:52 +0300 | [diff] [blame] | 1433 | } else if (er.encoded > (ssize_t)xml_buffer_size) { |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1434 | 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] | 1435 | (int) xml_buffer_size, |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1436 | asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, __func__, __LINE__); |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1437 | } else { |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1438 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1439 | mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU past : %s", |
| 1440 | asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, |
| 1441 | xml_buffer); |
| 1442 | } |
aa7133@att.com | 233facd | 2020-04-02 00:10:46 +0300 | [diff] [blame] | 1443 | //TODO replace the ranFunctionDefinition with the XML |
| 1444 | string runFuncs = (char *)(xml_buffer); |
| 1445 | runFunDEFXML_v.emplace_back(runFuncs); |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | } |
| 1449 | } |
| 1450 | if (failed) { |
| 1451 | break; |
| 1452 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1453 | } |
| 1454 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1455 | } |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1456 | if (failed) { |
| 1457 | break; |
| 1458 | } |
| 1459 | |
| 1460 | //build all parts and send the XML (need to copy the XML with the header to the rmrMessageBuffer payload |
| 1461 | //TODO replace with new function |
aa7133@att.com | 233facd | 2020-04-02 00:10:46 +0300 | [diff] [blame] | 1462 | buildAndsendSetupRequest(message, rmrMessageBuffer, pdu, runFunDEFXML_v); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1463 | break; |
| 1464 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1465 | case ProcedureCode_id_ErrorIndication: { |
| 1466 | if (logLevel >= MDCLOG_DEBUG) { |
| 1467 | mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName); |
| 1468 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1469 | if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1470 | mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1471 | } |
| 1472 | break; |
| 1473 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1474 | case ProcedureCode_id_Reset: { |
| 1475 | if (logLevel >= MDCLOG_DEBUG) { |
| 1476 | mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1477 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1478 | if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1479 | mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP"); |
| 1480 | } |
| 1481 | break; |
| 1482 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1483 | case ProcedureCode_id_RICcontrol: { |
| 1484 | if (logLevel >= MDCLOG_DEBUG) { |
| 1485 | mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName); |
| 1486 | } |
| 1487 | break; |
| 1488 | } |
| 1489 | case ProcedureCode_id_RICindication: { |
| 1490 | if (logLevel >= MDCLOG_DEBUG) { |
| 1491 | mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName); |
| 1492 | } |
| 1493 | 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] | 1494 | auto messageSent = false; |
| 1495 | 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] | 1496 | if (logLevel >= MDCLOG_DEBUG) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1497 | mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); |
| 1498 | } |
| 1499 | if (ie->id == ProtocolIE_ID_id_RICrequestID) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1500 | if (logLevel >= MDCLOG_DEBUG) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1501 | mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); |
| 1502 | } |
| 1503 | if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) { |
| 1504 | static unsigned char tx[32]; |
| 1505 | message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION; |
| 1506 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 1507 | rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1508 | rmr_bytes2meid(rmrMessageBuffer.sendMessage, |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1509 | (unsigned char *)message.message.enodbName, |
| 1510 | strlen(message.message.enodbName)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1511 | rmrMessageBuffer.sendMessage->state = 0; |
| 1512 | rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1513 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1514 | mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d", |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1515 | rmrMessageBuffer.sendMessage->sub_id, |
| 1516 | rmrMessageBuffer.sendMessage->mtype); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1517 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1518 | sendRmrMessage(rmrMessageBuffer, message); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1519 | messageSent = true; |
| 1520 | } else { |
| 1521 | mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request"); |
| 1522 | } |
| 1523 | } |
| 1524 | if (messageSent) { |
| 1525 | break; |
| 1526 | } |
| 1527 | } |
| 1528 | break; |
| 1529 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1530 | case ProcedureCode_id_RICserviceQuery: { |
| 1531 | if (logLevel >= MDCLOG_DEBUG) { |
| 1532 | mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1533 | } |
| 1534 | break; |
| 1535 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1536 | case ProcedureCode_id_RICserviceUpdate: { |
| 1537 | if (logLevel >= MDCLOG_DEBUG) { |
| 1538 | mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName); |
| 1539 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1540 | if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1541 | mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1542 | } |
| 1543 | break; |
| 1544 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1545 | case ProcedureCode_id_RICsubscription: { |
| 1546 | if (logLevel >= MDCLOG_DEBUG) { |
| 1547 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName); |
| 1548 | } |
| 1549 | break; |
| 1550 | } |
| 1551 | case ProcedureCode_id_RICsubscriptionDelete: { |
| 1552 | if (logLevel >= MDCLOG_DEBUG) { |
| 1553 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1554 | } |
| 1555 | break; |
| 1556 | } |
| 1557 | default: { |
| 1558 | mdclog_write(MDCLOG_ERR, "Undefined or not supported message = %ld", procedureCode); |
| 1559 | message.message.messageType = 0; // no RMR message type yet |
| 1560 | |
| 1561 | buildJsonMessage(message); |
| 1562 | |
| 1563 | break; |
| 1564 | } |
| 1565 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | /** |
| 1569 | * |
| 1570 | * @param pdu |
| 1571 | * @param message |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1572 | * @param rmrMessageBuffer |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1573 | */ |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1574 | void asnSuccsesfulMsg(E2AP_PDU_t *pdu, |
| 1575 | Sctp_Map_t *sctpMap, |
| 1576 | ReportingMessages_t &message, |
| 1577 | RmrMessagesBuffer_t &rmrMessageBuffer) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1578 | auto procedureCode = pdu->choice.successfulOutcome->procedureCode; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1579 | auto logLevel = mdclog_level_get(); |
| 1580 | if (logLevel >= MDCLOG_INFO) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1581 | mdclog_write(MDCLOG_INFO, "Successful Outcome %ld", procedureCode); |
| 1582 | } |
| 1583 | switch (procedureCode) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1584 | case ProcedureCode_id_E2setup: { |
| 1585 | if (logLevel >= MDCLOG_DEBUG) { |
| 1586 | mdclog_write(MDCLOG_DEBUG, "Got E2setup\n"); |
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_ErrorIndication: { |
| 1591 | if (logLevel >= MDCLOG_DEBUG) { |
| 1592 | mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1593 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1594 | if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1595 | mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1596 | } |
| 1597 | break; |
| 1598 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1599 | case ProcedureCode_id_Reset: { |
| 1600 | if (logLevel >= MDCLOG_DEBUG) { |
| 1601 | mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1602 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1603 | if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1604 | mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1605 | } |
| 1606 | break; |
| 1607 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1608 | case ProcedureCode_id_RICcontrol: { |
| 1609 | if (logLevel >= MDCLOG_DEBUG) { |
| 1610 | mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1611 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1612 | for (auto i = 0; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1613 | i < pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; i++) { |
| 1614 | auto messageSent = false; |
| 1615 | RICcontrolAcknowledge_IEs_t *ie = pdu->choice.successfulOutcome->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[i]; |
| 1616 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1617 | mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); |
| 1618 | } |
| 1619 | if (ie->id == ProtocolIE_ID_id_RICrequestID) { |
| 1620 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1621 | mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); |
| 1622 | } |
| 1623 | if (ie->value.present == RICcontrolAcknowledge_IEs__value_PR_RICrequestID) { |
| 1624 | message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_ACK; |
| 1625 | rmrMessageBuffer.sendMessage->state = 0; |
| 1626 | rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; |
| 1627 | static unsigned char tx[32]; |
| 1628 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 1629 | rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1630 | rmr_bytes2meid(rmrMessageBuffer.sendMessage, |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1631 | (unsigned char *)message.message.enodbName, |
| 1632 | strlen(message.message.enodbName)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1633 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1634 | sendRmrMessage(rmrMessageBuffer, message); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1635 | messageSent = true; |
| 1636 | } else { |
| 1637 | mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request"); |
| 1638 | } |
| 1639 | } |
| 1640 | if (messageSent) { |
| 1641 | break; |
| 1642 | } |
| 1643 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1644 | |
| 1645 | break; |
| 1646 | } |
| 1647 | case ProcedureCode_id_RICindication: { |
| 1648 | if (logLevel >= MDCLOG_DEBUG) { |
| 1649 | mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName); |
| 1650 | } |
| 1651 | for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) { |
| 1652 | auto messageSent = false; |
| 1653 | RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i]; |
| 1654 | if (logLevel >= MDCLOG_DEBUG) { |
| 1655 | mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); |
| 1656 | } |
| 1657 | if (ie->id == ProtocolIE_ID_id_RICrequestID) { |
| 1658 | if (logLevel >= MDCLOG_DEBUG) { |
| 1659 | mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); |
| 1660 | } |
| 1661 | if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) { |
| 1662 | static unsigned char tx[32]; |
| 1663 | message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION; |
| 1664 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 1665 | rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); |
| 1666 | rmr_bytes2meid(rmrMessageBuffer.sendMessage, |
| 1667 | (unsigned char *)message.message.enodbName, |
| 1668 | strlen(message.message.enodbName)); |
| 1669 | rmrMessageBuffer.sendMessage->state = 0; |
| 1670 | rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; |
| 1671 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1672 | mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d", |
| 1673 | rmrMessageBuffer.sendMessage->sub_id, |
| 1674 | rmrMessageBuffer.sendMessage->mtype); |
| 1675 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1676 | sendRmrMessage(rmrMessageBuffer, message); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1677 | messageSent = true; |
| 1678 | } else { |
| 1679 | mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request"); |
| 1680 | } |
| 1681 | } |
| 1682 | if (messageSent) { |
| 1683 | break; |
| 1684 | } |
| 1685 | } |
| 1686 | break; |
| 1687 | } |
| 1688 | case ProcedureCode_id_RICserviceQuery: { |
| 1689 | if (logLevel >= MDCLOG_DEBUG) { |
| 1690 | mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName); |
| 1691 | } |
| 1692 | break; |
| 1693 | } |
| 1694 | case ProcedureCode_id_RICserviceUpdate: { |
| 1695 | if (logLevel >= MDCLOG_DEBUG) { |
| 1696 | mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName); |
| 1697 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1698 | if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1699 | mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP"); |
| 1700 | } |
| 1701 | break; |
| 1702 | } |
| 1703 | case ProcedureCode_id_RICsubscription: { |
| 1704 | if (logLevel >= MDCLOG_DEBUG) { |
| 1705 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName); |
| 1706 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1707 | if (sendRequestToXapp(message, RIC_SUB_RESP, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1708 | mdclog_write(MDCLOG_ERR, "Subscription successful message failed to send to xAPP"); |
| 1709 | } |
| 1710 | break; |
| 1711 | } |
| 1712 | case ProcedureCode_id_RICsubscriptionDelete: { |
| 1713 | if (logLevel >= MDCLOG_DEBUG) { |
| 1714 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName); |
| 1715 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1716 | if (sendRequestToXapp(message, RIC_SUB_DEL_RESP, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1717 | mdclog_write(MDCLOG_ERR, "Subscription delete successful message failed to send to xAPP"); |
| 1718 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1719 | break; |
| 1720 | } |
| 1721 | default: { |
| 1722 | mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode); |
| 1723 | message.message.messageType = 0; // no RMR message type yet |
| 1724 | buildJsonMessage(message); |
| 1725 | |
| 1726 | break; |
| 1727 | } |
| 1728 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | /** |
| 1732 | * |
| 1733 | * @param pdu |
| 1734 | * @param message |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1735 | * @param rmrMessageBuffer |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1736 | */ |
| 1737 | void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu, |
aa7133@att.com | 7b437f7 | 2020-03-30 13:25:54 +0300 | [diff] [blame] | 1738 | Sctp_Map_t *sctpMap, |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1739 | ReportingMessages_t &message, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1740 | RmrMessagesBuffer_t &rmrMessageBuffer) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1741 | auto procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode; |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1742 | auto logLevel = mdclog_level_get(); |
| 1743 | if (logLevel >= MDCLOG_INFO) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1744 | mdclog_write(MDCLOG_INFO, "Unsuccessful Outcome %ld", procedureCode); |
| 1745 | } |
| 1746 | switch (procedureCode) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1747 | case ProcedureCode_id_E2setup: { |
| 1748 | if (logLevel >= MDCLOG_DEBUG) { |
| 1749 | mdclog_write(MDCLOG_DEBUG, "Got E2setup\n"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1750 | } |
| 1751 | break; |
| 1752 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1753 | case ProcedureCode_id_ErrorIndication: { |
| 1754 | if (logLevel >= MDCLOG_DEBUG) { |
| 1755 | mdclog_write(MDCLOG_DEBUG, "Got ErrorIndication %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1756 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1757 | if (sendRequestToXapp(message, RIC_ERROR_INDICATION, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1758 | mdclog_write(MDCLOG_ERR, "RIC_ERROR_INDICATION failed to send to xAPP"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1759 | } |
| 1760 | break; |
| 1761 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1762 | case ProcedureCode_id_Reset: { |
| 1763 | if (logLevel >= MDCLOG_DEBUG) { |
| 1764 | mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); |
| 1765 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1766 | if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1767 | mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1768 | } |
| 1769 | break; |
| 1770 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1771 | case ProcedureCode_id_RICcontrol: { |
| 1772 | if (logLevel >= MDCLOG_DEBUG) { |
| 1773 | mdclog_write(MDCLOG_DEBUG, "Got RICcontrol %s", message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1774 | } |
| 1775 | for (int i = 0; |
| 1776 | i < pdu->choice.unsuccessfulOutcome->value.choice.RICcontrolFailure.protocolIEs.list.count; i++) { |
| 1777 | auto messageSent = false; |
| 1778 | 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] | 1779 | if (logLevel >= MDCLOG_DEBUG) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1780 | mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); |
| 1781 | } |
| 1782 | if (ie->id == ProtocolIE_ID_id_RICrequestID) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1783 | if (logLevel >= MDCLOG_DEBUG) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1784 | mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); |
| 1785 | } |
| 1786 | if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) { |
| 1787 | message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_FAILURE; |
| 1788 | rmrMessageBuffer.sendMessage->state = 0; |
| 1789 | rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; |
| 1790 | static unsigned char tx[32]; |
| 1791 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 1792 | rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1793 | rmr_bytes2meid(rmrMessageBuffer.sendMessage, (unsigned char *) message.message.enodbName, |
| 1794 | strlen(message.message.enodbName)); |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1795 | sendRmrMessage(rmrMessageBuffer, message); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1796 | messageSent = true; |
| 1797 | } else { |
| 1798 | mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request"); |
| 1799 | } |
| 1800 | } |
| 1801 | if (messageSent) { |
| 1802 | break; |
| 1803 | } |
| 1804 | } |
| 1805 | break; |
| 1806 | } |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1807 | case ProcedureCode_id_RICindication: { |
| 1808 | if (logLevel >= MDCLOG_DEBUG) { |
| 1809 | mdclog_write(MDCLOG_DEBUG, "Got RICindication %s", message.message.enodbName); |
| 1810 | } |
| 1811 | for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.count; i++) { |
| 1812 | auto messageSent = false; |
| 1813 | RICindication_IEs_t *ie = pdu->choice.initiatingMessage->value.choice.RICindication.protocolIEs.list.array[i]; |
| 1814 | if (logLevel >= MDCLOG_DEBUG) { |
| 1815 | mdclog_write(MDCLOG_DEBUG, "ie type (ProtocolIE_ID) = %ld", ie->id); |
| 1816 | } |
| 1817 | if (ie->id == ProtocolIE_ID_id_RICrequestID) { |
| 1818 | if (logLevel >= MDCLOG_DEBUG) { |
| 1819 | mdclog_write(MDCLOG_DEBUG, "Got RIC requestId entry, ie type (ProtocolIE_ID) = %ld", ie->id); |
| 1820 | } |
| 1821 | if (ie->value.present == RICindication_IEs__value_PR_RICrequestID) { |
| 1822 | static unsigned char tx[32]; |
| 1823 | message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_INDICATION; |
| 1824 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 1825 | rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); |
| 1826 | rmr_bytes2meid(rmrMessageBuffer.sendMessage, |
| 1827 | (unsigned char *)message.message.enodbName, |
| 1828 | strlen(message.message.enodbName)); |
| 1829 | rmrMessageBuffer.sendMessage->state = 0; |
| 1830 | rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; |
| 1831 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1832 | mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d", |
| 1833 | rmrMessageBuffer.sendMessage->sub_id, |
| 1834 | rmrMessageBuffer.sendMessage->mtype); |
| 1835 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1836 | sendRmrMessage(rmrMessageBuffer, message); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1837 | messageSent = true; |
| 1838 | } else { |
| 1839 | mdclog_write(MDCLOG_ERR, "RIC request id missing illigal request"); |
| 1840 | } |
| 1841 | } |
| 1842 | if (messageSent) { |
| 1843 | break; |
| 1844 | } |
| 1845 | } |
| 1846 | break; |
| 1847 | } |
| 1848 | case ProcedureCode_id_RICserviceQuery: { |
| 1849 | if (logLevel >= MDCLOG_DEBUG) { |
| 1850 | mdclog_write(MDCLOG_DEBUG, "Got RICserviceQuery %s", message.message.enodbName); |
| 1851 | } |
| 1852 | break; |
| 1853 | } |
| 1854 | case ProcedureCode_id_RICserviceUpdate: { |
| 1855 | if (logLevel >= MDCLOG_DEBUG) { |
| 1856 | mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName); |
| 1857 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1858 | if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1859 | mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP"); |
| 1860 | } |
| 1861 | break; |
| 1862 | } |
| 1863 | case ProcedureCode_id_RICsubscription: { |
| 1864 | if (logLevel >= MDCLOG_DEBUG) { |
| 1865 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName); |
| 1866 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1867 | if (sendRequestToXapp(message, RIC_SUB_FAILURE, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1868 | mdclog_write(MDCLOG_ERR, "Subscription unsuccessful message failed to send to xAPP"); |
| 1869 | } |
| 1870 | break; |
| 1871 | } |
| 1872 | case ProcedureCode_id_RICsubscriptionDelete: { |
| 1873 | if (logLevel >= MDCLOG_DEBUG) { |
| 1874 | mdclog_write(MDCLOG_DEBUG, "Got RICsubscriptionDelete %s", message.message.enodbName); |
| 1875 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1876 | if (sendRequestToXapp(message, RIC_SUB_DEL_FAILURE, rmrMessageBuffer) != 0) { |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 1877 | mdclog_write(MDCLOG_ERR, "Subscription Delete unsuccessful message failed to send to xAPP"); |
| 1878 | } |
| 1879 | break; |
| 1880 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1881 | default: { |
| 1882 | mdclog_write(MDCLOG_WARN, "Undefined or not supported message = %ld", procedureCode); |
| 1883 | message.message.messageType = 0; // no RMR message type yet |
| 1884 | |
| 1885 | buildJsonMessage(message); |
| 1886 | |
| 1887 | break; |
| 1888 | } |
| 1889 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | /** |
| 1893 | * |
| 1894 | * @param message |
| 1895 | * @param requestId |
| 1896 | * @param rmrMmessageBuffer |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1897 | * @return |
| 1898 | */ |
| 1899 | int sendRequestToXapp(ReportingMessages_t &message, |
| 1900 | int requestId, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1901 | RmrMessagesBuffer_t &rmrMmessageBuffer) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1902 | rmr_bytes2meid(rmrMmessageBuffer.sendMessage, |
| 1903 | (unsigned char *)message.message.enodbName, |
| 1904 | strlen(message.message.enodbName)); |
| 1905 | message.message.messageType = rmrMmessageBuffer.sendMessage->mtype = requestId; |
| 1906 | rmrMmessageBuffer.sendMessage->state = 0; |
| 1907 | static unsigned char tx[32]; |
| 1908 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 1909 | rmr_bytes2xact(rmrMmessageBuffer.sendMessage, tx, strlen((const char *) tx)); |
| 1910 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1911 | auto rc = sendRmrMessage(rmrMmessageBuffer, message); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1912 | return rc; |
| 1913 | } |
| 1914 | |
| 1915 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 1916 | void getRmrContext(sctp_params_t &pSctpParams) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1917 | pSctpParams.rmrCtx = nullptr; |
| 1918 | pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RMR_MAX_RCV_BYTES, RMRFL_NONE); |
| 1919 | if (pSctpParams.rmrCtx == nullptr) { |
| 1920 | mdclog_write(MDCLOG_ERR, "Failed to initialize RMR"); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1921 | return; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1922 | } |
| 1923 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1924 | rmr_set_stimeout(pSctpParams.rmrCtx, 0); // disable retries for any send operation |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1925 | // we need to find that routing table exist and we can run |
| 1926 | if (mdclog_level_get() >= MDCLOG_INFO) { |
| 1927 | mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready"); |
| 1928 | } |
| 1929 | int rmrReady = 0; |
| 1930 | int count = 0; |
| 1931 | while (!rmrReady) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1932 | if ((rmrReady = rmr_ready(pSctpParams.rmrCtx)) == 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1933 | sleep(1); |
| 1934 | } |
| 1935 | count++; |
| 1936 | if (count % 60 == 0) { |
| 1937 | mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count); |
| 1938 | } |
| 1939 | } |
| 1940 | if (mdclog_level_get() >= MDCLOG_INFO) { |
| 1941 | mdclog_write(MDCLOG_INFO, "RMR running"); |
| 1942 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 1943 | rmr_init_trace(pSctpParams.rmrCtx, 200); |
| 1944 | // get the RMR fd for the epoll |
| 1945 | pSctpParams.rmrListenFd = rmr_get_rcvfd(pSctpParams.rmrCtx); |
| 1946 | struct epoll_event event{}; |
| 1947 | // add RMR fd to epoll |
| 1948 | event.events = (EPOLLIN); |
| 1949 | event.data.fd = pSctpParams.rmrListenFd; |
| 1950 | // add listening RMR FD to epoll |
| 1951 | if (epoll_ctl(pSctpParams.epoll_fd, EPOLL_CTL_ADD, pSctpParams.rmrListenFd, &event)) { |
| 1952 | mdclog_write(MDCLOG_ERR, "Failed to add RMR descriptor to epoll"); |
| 1953 | close(pSctpParams.rmrListenFd); |
| 1954 | rmr_close(pSctpParams.rmrCtx); |
| 1955 | pSctpParams.rmrCtx = nullptr; |
| 1956 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1957 | } |
| 1958 | |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 1959 | int BuildPERSetupResponseMessaeFromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) { |
| 1960 | E2AP_PDU_t *pdu; |
aa7133@att.com | 1c4f50f | 2020-03-30 14:30:52 +0300 | [diff] [blame] | 1961 | |
| 1962 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 1963 | mdclog_write(MDCLOG_DEBUG, "got xml setup response \n %s\n", rmrMessageBuffer.rcvMessage->payload); |
| 1964 | } |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 1965 | auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &pdu, |
| 1966 | rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len); |
| 1967 | if (rval.code != RC_OK) { |
aa7133@att.com | 1c4f50f | 2020-03-30 14:30:52 +0300 | [diff] [blame] | 1968 | 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] | 1969 | rval.code, |
| 1970 | message.message.enodbName); |
| 1971 | return -1; |
| 1972 | } |
| 1973 | |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1974 | int buff_size = RECEIVE_XAPP_BUFFER_SIZE; |
| 1975 | auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu, |
| 1976 | rmrMessageBuffer.rcvMessage->payload, buff_size); |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 1977 | if (er.encoded == -1) { |
| 1978 | mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); |
| 1979 | return -1; |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1980 | } else if (er.encoded > (ssize_t)buff_size) { |
| 1981 | 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] | 1982 | (int)rmrMessageBuffer.rcvMessage->len, |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1983 | asn_DEF_E2AP_PDU.name, |
| 1984 | __func__, |
| 1985 | __LINE__); |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 1986 | return -1; |
| 1987 | } |
aa7133@att.com | a0f0db6 | 2020-04-01 16:52:50 +0300 | [diff] [blame] | 1988 | rmrMessageBuffer.rcvMessage->len = er.encoded; |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 1989 | return 0; |
| 1990 | } |
| 1991 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1992 | /** |
| 1993 | * |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1994 | * @param sctpMap |
| 1995 | * @param rmrMessageBuffer |
| 1996 | * @param ts |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 1997 | * @return |
| 1998 | */ |
aa7133@att.com | 6680c3b | 2020-03-22 12:06:58 +0200 | [diff] [blame] | 1999 | int receiveXappMessages(Sctp_Map_t *sctpMap, |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2000 | RmrMessagesBuffer_t &rmrMessageBuffer, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2001 | struct timespec &ts) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2002 | if (rmrMessageBuffer.rcvMessage == nullptr) { |
| 2003 | //we have error |
| 2004 | mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2005 | return -1; |
| 2006 | } |
| 2007 | |
| 2008 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2009 | mdclog_write(MDCLOG_DEBUG, "Call to rmr_rcv_msg"); |
| 2010 | } |
| 2011 | rmrMessageBuffer.rcvMessage = rmr_rcv_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.rcvMessage); |
| 2012 | if (rmrMessageBuffer.rcvMessage == nullptr) { |
| 2013 | mdclog_write(MDCLOG_ERR, "RMR Receving message with null pointer, Realloc rmr mesage buffer"); |
| 2014 | rmrMessageBuffer.rcvMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2015 | return -2; |
| 2016 | } |
| 2017 | ReportingMessages_t message; |
| 2018 | message.message.direction = 'D'; |
| 2019 | message.message.time.tv_nsec = ts.tv_nsec; |
| 2020 | message.message.time.tv_sec = ts.tv_sec; |
| 2021 | |
| 2022 | // get message payload |
| 2023 | //auto msgData = msg->payload; |
| 2024 | if (rmrMessageBuffer.rcvMessage->state != 0) { |
| 2025 | mdclog_write(MDCLOG_ERR, "RMR Receving message with stat = %d", rmrMessageBuffer.rcvMessage->state); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2026 | return -1; |
| 2027 | } |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2028 | rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)message.message.enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2029 | switch (rmrMessageBuffer.rcvMessage->mtype) { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2030 | case RIC_E2_SETUP_RESP : { |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2031 | if (BuildPERSetupResponseMessaeFromXML(message, rmrMessageBuffer) != 0) { |
| 2032 | break; |
| 2033 | } |
| 2034 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2035 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
| 2036 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_RESP"); |
| 2037 | return -6; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2038 | } |
| 2039 | break; |
| 2040 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2041 | case RIC_E2_SETUP_FAILURE : { |
aa7133@att.com | 1fecb05 | 2020-03-29 09:44:09 +0300 | [diff] [blame] | 2042 | if (BuildPERSetupResponseMessaeFromXML(message, rmrMessageBuffer) != 0) { |
| 2043 | break; |
| 2044 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2045 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
| 2046 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_SETUP_FAILURE"); |
| 2047 | return -6; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2048 | } |
| 2049 | break; |
| 2050 | } |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2051 | case RIC_ERROR_INDICATION: { |
| 2052 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
| 2053 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_ERROR_INDICATION"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2054 | return -6; |
| 2055 | } |
| 2056 | break; |
| 2057 | } |
| 2058 | case RIC_SUB_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_SUB_REQ"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2061 | return -6; |
| 2062 | } |
| 2063 | break; |
| 2064 | } |
| 2065 | case RIC_SUB_DEL_REQ: { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2066 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2067 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_SUB_DEL_REQ"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2068 | return -6; |
| 2069 | } |
| 2070 | break; |
| 2071 | } |
| 2072 | case RIC_CONTROL_REQ: { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2073 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2074 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_CONTROL_REQ"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2075 | return -6; |
| 2076 | } |
| 2077 | break; |
| 2078 | } |
| 2079 | case RIC_SERVICE_QUERY: { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2080 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2081 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2082 | return -6; |
| 2083 | } |
| 2084 | break; |
| 2085 | } |
| 2086 | case RIC_SERVICE_UPDATE_ACK: { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2087 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2088 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2089 | return -6; |
| 2090 | } |
| 2091 | break; |
| 2092 | } |
| 2093 | case RIC_SERVICE_UPDATE_FAILURE: { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2094 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2095 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2096 | return -6; |
| 2097 | } |
| 2098 | break; |
| 2099 | } |
| 2100 | case RIC_X2_RESET: { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2101 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2102 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2103 | return -6; |
| 2104 | } |
| 2105 | break; |
| 2106 | } |
| 2107 | case RIC_X2_RESET_RESP: { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2108 | if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2109 | mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET_RESP"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2110 | return -6; |
| 2111 | } |
| 2112 | break; |
| 2113 | } |
| 2114 | case RIC_SCTP_CLEAR_ALL: { |
| 2115 | mdclog_write(MDCLOG_INFO, "RIC_SCTP_CLEAR_ALL"); |
| 2116 | // loop on all keys and close socket and then erase all map. |
| 2117 | vector<char *> v; |
| 2118 | sctpMap->getKeys(v); |
| 2119 | for (auto const &iter : v) { //}; iter != sctpMap.end(); iter++) { |
| 2120 | if (!boost::starts_with((string) (iter), "host:") && !boost::starts_with((string) (iter), "msg:")) { |
| 2121 | auto *peerInfo = (ConnectedCU_t *) sctpMap->find(iter); |
| 2122 | if (peerInfo == nullptr) { |
| 2123 | continue; |
| 2124 | } |
| 2125 | close(peerInfo->fileDescriptor); |
| 2126 | memcpy(message.message.enodbName, peerInfo->enodbName, sizeof(peerInfo->enodbName)); |
| 2127 | message.message.direction = 'D'; |
| 2128 | message.message.time.tv_nsec = ts.tv_nsec; |
| 2129 | message.message.time.tv_sec = ts.tv_sec; |
| 2130 | |
| 2131 | message.message.asnLength = rmrMessageBuffer.sendMessage->len = |
| 2132 | snprintf((char *)rmrMessageBuffer.sendMessage->payload, |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 2133 | 256, |
| 2134 | "%s|RIC_SCTP_CLEAR_ALL", |
| 2135 | peerInfo->enodbName); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2136 | message.message.asndata = rmrMessageBuffer.sendMessage->payload; |
| 2137 | mdclog_write(MDCLOG_INFO, "%s", message.message.asndata); |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2138 | if (sendRequestToXapp(message, RIC_SCTP_CONNECTION_FAILURE, rmrMessageBuffer) != 0) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2139 | mdclog_write(MDCLOG_ERR, "SCTP_CONNECTION_FAIL message failed to send to xAPP"); |
| 2140 | } |
| 2141 | free(peerInfo); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | sleep(1); |
| 2146 | sctpMap->clear(); |
| 2147 | break; |
| 2148 | } |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2149 | case E2_TERM_KEEP_ALIVE_REQ: { |
| 2150 | // send message back |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2151 | rmr_bytes2payload(rmrMessageBuffer.sendMessage, |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 2152 | (unsigned char *)rmrMessageBuffer.ka_message, |
| 2153 | rmrMessageBuffer.ka_message_len); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2154 | rmrMessageBuffer.sendMessage->mtype = E2_TERM_KEEP_ALIVE_RESP; |
| 2155 | rmrMessageBuffer.sendMessage->state = 0; |
| 2156 | static unsigned char tx[32]; |
| 2157 | auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 2158 | rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, txLen); |
| 2159 | rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage); |
| 2160 | if (rmrMessageBuffer.sendMessage == nullptr) { |
| 2161 | rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
aa7133@att.com | 77fff43 | 2020-01-27 12:01:20 +0200 | [diff] [blame] | 2162 | 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] | 2163 | } else if (rmrMessageBuffer.sendMessage->state != 0) { |
aa7133@att.com | 77fff43 | 2020-01-27 12:01:20 +0200 | [diff] [blame] | 2164 | 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] | 2165 | rmrMessageBuffer.sendMessage->state, translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str()); |
aa7133@att.com | bc11077 | 2020-03-25 09:45:14 +0200 | [diff] [blame] | 2166 | } else if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2167 | mdclog_write(MDCLOG_DEBUG, "Got Keep Alive Request send : %s", rmrMessageBuffer.ka_message); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2168 | } |
aa7133@att.com | 342843e | 2020-01-26 12:53:34 +0200 | [diff] [blame] | 2169 | |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2170 | break; |
| 2171 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2172 | default: |
| 2173 | mdclog_write(MDCLOG_WARN, "Message Type : %d is not seported", rmrMessageBuffer.rcvMessage->mtype); |
| 2174 | message.message.asndata = rmrMessageBuffer.rcvMessage->payload; |
| 2175 | message.message.asnLength = rmrMessageBuffer.rcvMessage->len; |
| 2176 | message.message.time.tv_nsec = ts.tv_nsec; |
| 2177 | message.message.time.tv_sec = ts.tv_sec; |
| 2178 | message.message.messageType = rmrMessageBuffer.rcvMessage->mtype; |
| 2179 | |
| 2180 | buildJsonMessage(message); |
| 2181 | |
| 2182 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2183 | return -7; |
| 2184 | } |
| 2185 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2186 | mdclog_write(MDCLOG_DEBUG, "EXIT OK from %s", __FUNCTION__); |
| 2187 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2188 | return 0; |
| 2189 | } |
| 2190 | |
| 2191 | /** |
| 2192 | * Send message to the CU that is not expecting for successful or unsuccessful results |
| 2193 | * @param messageBuffer |
| 2194 | * @param message |
| 2195 | * @param failedMsgId |
| 2196 | * @param sctpMap |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2197 | * @return |
| 2198 | */ |
| 2199 | int sendDirectionalSctpMsg(RmrMessagesBuffer_t &messageBuffer, |
| 2200 | ReportingMessages_t &message, |
| 2201 | int failedMsgId, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2202 | Sctp_Map_t *sctpMap) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2203 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2204 | getRequestMetaData(message, messageBuffer); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2205 | if (mdclog_level_get() >= MDCLOG_INFO) { |
| 2206 | mdclog_write(MDCLOG_INFO, "send message to %s address", message.message.enodbName); |
| 2207 | } |
| 2208 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2209 | auto rc = sendMessagetoCu(sctpMap, messageBuffer, message, failedMsgId); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2210 | return rc; |
| 2211 | } |
| 2212 | |
| 2213 | /** |
| 2214 | * |
| 2215 | * @param sctpMap |
| 2216 | * @param messageBuffer |
| 2217 | * @param message |
| 2218 | * @param failedMesgId |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2219 | * @return |
| 2220 | */ |
| 2221 | int sendMessagetoCu(Sctp_Map_t *sctpMap, |
| 2222 | RmrMessagesBuffer_t &messageBuffer, |
| 2223 | ReportingMessages_t &message, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2224 | int failedMesgId) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2225 | auto *peerInfo = (ConnectedCU_t *) sctpMap->find(message.message.enodbName); |
| 2226 | if (peerInfo == nullptr) { |
| 2227 | if (failedMesgId != 0) { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2228 | sendFailedSendingMessagetoXapp(messageBuffer, message, failedMesgId); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2229 | } else { |
| 2230 | mdclog_write(MDCLOG_ERR, "Failed to send message no CU entry %s", message.message.enodbName); |
| 2231 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2232 | return -1; |
| 2233 | } |
| 2234 | |
| 2235 | // get the FD |
| 2236 | message.message.messageType = messageBuffer.rcvMessage->mtype; |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2237 | auto rc = sendSctpMsg(peerInfo, message, sctpMap); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2238 | return rc; |
| 2239 | } |
| 2240 | |
| 2241 | /** |
| 2242 | * |
| 2243 | * @param rmrCtx the rmr context to send and receive |
| 2244 | * @param msg the msg we got fromxApp |
| 2245 | * @param metaData data from xApp in ordered struct |
| 2246 | * @param failedMesgId the return message type error |
| 2247 | */ |
| 2248 | void |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2249 | sendFailedSendingMessagetoXapp(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message, int failedMesgId) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2250 | rmr_mbuf_t *msg = rmrMessageBuffer.sendMessage; |
| 2251 | msg->len = snprintf((char *) msg->payload, 200, "the gNb/eNode name %s not found", |
| 2252 | message.message.enodbName); |
| 2253 | if (mdclog_level_get() >= MDCLOG_INFO) { |
| 2254 | mdclog_write(MDCLOG_INFO, "%s", msg->payload); |
| 2255 | } |
| 2256 | msg->mtype = failedMesgId; |
| 2257 | msg->state = 0; |
| 2258 | |
| 2259 | static unsigned char tx[32]; |
| 2260 | snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); |
| 2261 | rmr_bytes2xact(msg, tx, strlen((const char *) tx)); |
| 2262 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2263 | sendRmrMessage(rmrMessageBuffer, message); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2264 | } |
| 2265 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2266 | |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2267 | |
| 2268 | /** |
| 2269 | * |
| 2270 | * @param epoll_fd |
| 2271 | * @param peerInfo |
| 2272 | * @param events |
| 2273 | * @param sctpMap |
| 2274 | * @param enodbName |
| 2275 | * @param msgType |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2276 | * @return |
| 2277 | */ |
| 2278 | int addToEpoll(int epoll_fd, |
| 2279 | ConnectedCU_t *peerInfo, |
| 2280 | uint32_t events, |
| 2281 | Sctp_Map_t *sctpMap, |
| 2282 | char *enodbName, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2283 | int msgType) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2284 | // Add to Epol |
| 2285 | struct epoll_event event{}; |
| 2286 | event.data.ptr = peerInfo; |
| 2287 | event.events = events; |
| 2288 | if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, peerInfo->fileDescriptor, &event) < 0) { |
| 2289 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2290 | mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_ADD (may chack not to quit here), %s, %s %d", |
| 2291 | strerror(errno), __func__, __LINE__); |
| 2292 | } |
| 2293 | close(peerInfo->fileDescriptor); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2294 | if (enodbName != nullptr) { |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2295 | cleanHashEntry(peerInfo, sctpMap); |
aa7133@att.com | 84bd334 | 2020-03-16 18:04:57 +0200 | [diff] [blame] | 2296 | char key[MAX_ENODB_NAME_SIZE * 2]; |
| 2297 | snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType); |
| 2298 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2299 | mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__); |
| 2300 | } |
| 2301 | auto tmp = sctpMap->find(key); |
| 2302 | if (tmp) { |
| 2303 | free(tmp); |
| 2304 | sctpMap->erase(key); |
| 2305 | } |
| 2306 | } else { |
| 2307 | peerInfo->enodbName[0] = 0; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2308 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2309 | 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] | 2310 | return -1; |
| 2311 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2312 | return 0; |
| 2313 | } |
| 2314 | |
| 2315 | /** |
| 2316 | * |
| 2317 | * @param epoll_fd |
| 2318 | * @param peerInfo |
| 2319 | * @param events |
| 2320 | * @param sctpMap |
| 2321 | * @param enodbName |
| 2322 | * @param msgType |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2323 | * @return |
| 2324 | */ |
| 2325 | int modifyToEpoll(int epoll_fd, |
| 2326 | ConnectedCU_t *peerInfo, |
| 2327 | uint32_t events, |
| 2328 | Sctp_Map_t *sctpMap, |
| 2329 | char *enodbName, |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2330 | int msgType) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2331 | // Add to Epol |
| 2332 | struct epoll_event event{}; |
| 2333 | event.data.ptr = peerInfo; |
| 2334 | event.events = events; |
| 2335 | if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, peerInfo->fileDescriptor, &event) < 0) { |
| 2336 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2337 | mdclog_write(MDCLOG_DEBUG, "epoll_ctl EPOLL_CTL_MOD (may chack not to quit here), %s, %s %d", |
| 2338 | strerror(errno), __func__, __LINE__); |
| 2339 | } |
| 2340 | close(peerInfo->fileDescriptor); |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2341 | cleanHashEntry(peerInfo, sctpMap); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2342 | char key[MAX_ENODB_NAME_SIZE * 2]; |
| 2343 | snprintf(key, MAX_ENODB_NAME_SIZE * 2, "msg:%s|%d", enodbName, msgType); |
| 2344 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2345 | mdclog_write(MDCLOG_DEBUG, "remove key = %s from %s at line %d", key, __FUNCTION__, __LINE__); |
| 2346 | } |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 2347 | auto tmp = sctpMap->find(key); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2348 | if (tmp) { |
| 2349 | free(tmp); |
| 2350 | } |
| 2351 | sctpMap->erase(key); |
| 2352 | 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] | 2353 | return -1; |
| 2354 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2355 | return 0; |
| 2356 | } |
| 2357 | |
| 2358 | |
aa7133@att.com | be92d71 | 2020-03-18 17:30:39 +0200 | [diff] [blame] | 2359 | int sendRmrMessage(RmrMessagesBuffer_t &rmrMessageBuffer, ReportingMessages_t &message) { |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2360 | buildJsonMessage(message); |
| 2361 | |
| 2362 | rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage); |
| 2363 | |
| 2364 | if (rmrMessageBuffer.sendMessage == nullptr) { |
| 2365 | rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
| 2366 | mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer"); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2367 | return -1; |
| 2368 | } |
| 2369 | |
| 2370 | if (rmrMessageBuffer.sendMessage->state != 0) { |
| 2371 | char meid[RMR_MAX_MEID]{}; |
| 2372 | if (rmrMessageBuffer.sendMessage->state == RMR_ERR_RETRY) { |
| 2373 | usleep(5); |
| 2374 | rmrMessageBuffer.sendMessage->state = 0; |
| 2375 | mdclog_write(MDCLOG_INFO, "RETRY sending Message type %d to Xapp from %s", |
| 2376 | rmrMessageBuffer.sendMessage->mtype, |
| 2377 | rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid)); |
| 2378 | rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage); |
| 2379 | if (rmrMessageBuffer.sendMessage == nullptr) { |
| 2380 | mdclog_write(MDCLOG_ERR, "RMR failed send message returned with NULL pointer"); |
| 2381 | rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2382 | return -1; |
| 2383 | } else if (rmrMessageBuffer.sendMessage->state != 0) { |
| 2384 | mdclog_write(MDCLOG_ERR, |
| 2385 | "Message state %s while sending request %d to Xapp from %s after retry of 10 microseconds", |
| 2386 | translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(), |
| 2387 | rmrMessageBuffer.sendMessage->mtype, |
| 2388 | rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid)); |
| 2389 | auto rc = rmrMessageBuffer.sendMessage->state; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2390 | return rc; |
| 2391 | } |
| 2392 | } else { |
| 2393 | mdclog_write(MDCLOG_ERR, "Message state %s while sending request %d to Xapp from %s", |
| 2394 | translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str(), |
| 2395 | rmrMessageBuffer.sendMessage->mtype, |
| 2396 | rmr_get_meid(rmrMessageBuffer.sendMessage, (unsigned char *)meid)); |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2397 | return rmrMessageBuffer.sendMessage->state; |
| 2398 | } |
| 2399 | } |
| 2400 | return 0; |
| 2401 | } |
| 2402 | |
| 2403 | void buildJsonMessage(ReportingMessages_t &message) { |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2404 | if (jsonTrace) { |
| 2405 | message.outLen = sizeof(message.base64Data); |
| 2406 | base64::encode((const unsigned char *) message.message.asndata, |
| 2407 | (const int) message.message.asnLength, |
| 2408 | message.base64Data, |
| 2409 | message.outLen); |
| 2410 | if (mdclog_level_get() >= MDCLOG_DEBUG) { |
| 2411 | mdclog_write(MDCLOG_DEBUG, "asn data length = %d, base64 message length = %d ", |
| 2412 | (int) message.message.asnLength, |
| 2413 | (int) message.outLen); |
| 2414 | } |
| 2415 | |
| 2416 | snprintf(message.buffer, sizeof(message.buffer), |
aa7133@att.com | 96c9b88 | 2020-03-25 14:50:40 +0200 | [diff] [blame] | 2417 | "{\"header\": {\"ts\": \"%ld.%09ld\"," |
| 2418 | "\"ranName\": \"%s\"," |
| 2419 | "\"messageType\": %d," |
| 2420 | "\"direction\": \"%c\"}," |
| 2421 | "\"base64Length\": %d," |
| 2422 | "\"asnBase64\": \"%s\"}", |
| 2423 | message.message.time.tv_sec, |
| 2424 | message.message.time.tv_nsec, |
| 2425 | message.message.enodbName, |
| 2426 | message.message.messageType, |
| 2427 | message.message.direction, |
| 2428 | (int) message.outLen, |
| 2429 | message.base64Data); |
ss412g | 3bac2da | 2020-01-05 11:52:19 +0200 | [diff] [blame] | 2430 | static src::logger_mt &lg = my_logger::get(); |
| 2431 | |
| 2432 | BOOST_LOG(lg) << message.buffer; |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2433 | } |
ss412g | 1a79bdf | 2019-10-24 12:03:05 +0300 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | |
| 2437 | /** |
| 2438 | * take RMR error code to string |
| 2439 | * @param state |
| 2440 | * @return |
| 2441 | */ |
| 2442 | string translateRmrErrorMessages(int state) { |
| 2443 | string str = {}; |
| 2444 | switch (state) { |
| 2445 | case RMR_OK: |
| 2446 | str = "RMR_OK - state is good"; |
| 2447 | break; |
| 2448 | case RMR_ERR_BADARG: |
| 2449 | str = "RMR_ERR_BADARG - argument passd to function was unusable"; |
| 2450 | break; |
| 2451 | case RMR_ERR_NOENDPT: |
| 2452 | str = "RMR_ERR_NOENDPT - send//call could not find an endpoint based on msg type"; |
| 2453 | break; |
| 2454 | case RMR_ERR_EMPTY: |
| 2455 | str = "RMR_ERR_EMPTY - msg received had no payload; attempt to send an empty message"; |
| 2456 | break; |
| 2457 | case RMR_ERR_NOHDR: |
| 2458 | str = "RMR_ERR_NOHDR - message didn't contain a valid header"; |
| 2459 | break; |
| 2460 | case RMR_ERR_SENDFAILED: |
| 2461 | str = "RMR_ERR_SENDFAILED - send failed; errno has nano reason"; |
| 2462 | break; |
| 2463 | case RMR_ERR_CALLFAILED: |
| 2464 | str = "RMR_ERR_CALLFAILED - unable to send call() message"; |
| 2465 | break; |
| 2466 | case RMR_ERR_NOWHOPEN: |
| 2467 | str = "RMR_ERR_NOWHOPEN - no wormholes are open"; |
| 2468 | break; |
| 2469 | case RMR_ERR_WHID: |
| 2470 | str = "RMR_ERR_WHID - wormhole id was invalid"; |
| 2471 | break; |
| 2472 | case RMR_ERR_OVERFLOW: |
| 2473 | str = "RMR_ERR_OVERFLOW - operation would have busted through a buffer/field size"; |
| 2474 | break; |
| 2475 | case RMR_ERR_RETRY: |
| 2476 | str = "RMR_ERR_RETRY - request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)"; |
| 2477 | break; |
| 2478 | case RMR_ERR_RCVFAILED: |
| 2479 | str = "RMR_ERR_RCVFAILED - receive failed (hard error)"; |
| 2480 | break; |
| 2481 | case RMR_ERR_TIMEOUT: |
| 2482 | str = "RMR_ERR_TIMEOUT - message processing call timed out"; |
| 2483 | break; |
| 2484 | case RMR_ERR_UNSET: |
| 2485 | str = "RMR_ERR_UNSET - the message hasn't been populated with a transport buffer"; |
| 2486 | break; |
| 2487 | case RMR_ERR_TRUNC: |
| 2488 | str = "RMR_ERR_TRUNC - received message likely truncated"; |
| 2489 | break; |
| 2490 | case RMR_ERR_INITFAILED: |
| 2491 | str = "RMR_ERR_INITFAILED - initialisation of something (probably message) failed"; |
| 2492 | break; |
| 2493 | case RMR_ERR_NOTSUPP: |
| 2494 | str = "RMR_ERR_NOTSUPP - the request is not supported, or RMr was not initialised for the request"; |
| 2495 | break; |
| 2496 | default: |
| 2497 | char buf[128]{}; |
| 2498 | snprintf(buf, sizeof buf, "UNDOCUMENTED RMR_ERR : %d", state); |
| 2499 | str = buf; |
| 2500 | break; |
| 2501 | } |
| 2502 | return str; |
| 2503 | } |
| 2504 | |
| 2505 | |