| 1 | // SPDX-License-Identifier: BSD-2-Clause |
| 2 | /* |
| 3 | * Copyright (C) 2020-2025 Linutronix GmbH |
| 4 | * Author Kurt Kanzenbach <[email protected]> |
| 5 | */ |
| 6 | |
| 7 | #include <errno.h> |
| 8 | #include <inttypes.h> |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
| 12 | #include <yaml.h> |
| 13 | |
| 14 | #include <linux/if_ether.h> |
| 15 | |
| 16 | #include "config.h" |
| 17 | #include "net_def.h" |
| 18 | #include "security.h" |
| 19 | #include "stat.h" |
| 20 | #include "utils.h" |
| 21 | |
| 22 | #include "dcp_thread.h" |
| 23 | #include "layer2_thread.h" |
| 24 | #include "lldp_thread.h" |
| 25 | #include "rta_thread.h" |
| 26 | #include "rtc_thread.h" |
| 27 | #include "tsn_thread.h" |
| 28 | #include "udp_thread.h" |
| 29 | |
| 30 | struct application_config app_config; |
| 31 | |
| 32 | static bool str_match_second(const char *opt, const char *s) |
| 33 | { |
| 34 | return !strncmp(opt, s, strlen(s)); |
| 35 | } |
| 36 | |
| 37 | static enum stat_frame_type config_opt_to_type(const char *opt) |
| 38 | { |
| 39 | if (str_match_second(opt, "TsnHigh")) |
| 40 | return TSN_HIGH_FRAME_TYPE; |
| 41 | if (str_match_second(opt, "TsnLow")) |
| 42 | return TSN_LOW_FRAME_TYPE; |
| 43 | if (str_match_second(opt, "Rtc")) |
| 44 | return RTC_FRAME_TYPE; |
| 45 | if (str_match_second(opt, "Rta")) |
| 46 | return RTA_FRAME_TYPE; |
| 47 | if (str_match_second(opt, "Dcp")) |
| 48 | return DCP_FRAME_TYPE; |
| 49 | if (str_match_second(opt, "Lldp")) |
| 50 | return LLDP_FRAME_TYPE; |
| 51 | if (str_match_second(opt, "UdpHigh")) |
| 52 | return UDP_HIGH_FRAME_TYPE; |
| 53 | if (str_match_second(opt, "UdpLow")) |
| 54 | return UDP_LOW_FRAME_TYPE; |
| 55 | if (str_match_second(opt, "GenericL2")) |
| 56 | return GENERICL2_FRAME_TYPE; |
| 57 | |
| 58 | /* Not a traffic class option */ |
| 59 | fprintf(stderr, "BUG: Invalid option '%s' found!\n", opt); |
| 60 | return NUM_FRAME_TYPES; |
| 61 | } |
| 62 | |
| 63 | bool config_is_traffic_class_active(const char *traffic_class) |
| 64 | { |
| 65 | enum stat_frame_type type = config_opt_to_type(traffic_class); |
| 66 | |
| 67 | return app_config.classes[type].enabled && |
| 68 | app_config.classes[type].num_frames_per_cycle > 0; |
| 69 | } |
| 70 | |
| 71 | static int config_parse_bool(const char *value, bool *ret) |
| 72 | { |
| 73 | if (!strcmp(value, "0") || !strcasecmp(value, "false")) |
| 74 | *ret = false; |
| 75 | else if (!strcmp(value, "1") || !strcasecmp(value, "true")) |
| 76 | *ret = true; |
| 77 | else |
| 78 | return -EINVAL; |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static int config_parse_int(const char *value, long *ret) |
| 84 | { |
| 85 | char *endptr; |
| 86 | |
| 87 | *ret = strtol(value, &endptr, 10); |
| 88 | if (errno != 0 || endptr == value || *endptr != '\0') |
| 89 | return -ERANGE; |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int config_parse_ulong(const char *value, unsigned long long *ret) |
| 95 | { |
| 96 | char *endptr; |
| 97 | |
| 98 | *ret = strtoull(value, &endptr, 10); |
| 99 | if (errno != 0 || endptr == value || *endptr != '\0') |
| 100 | return -ERANGE; |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static int config_parse_time(const char *value, uint64_t *ret) |
| 106 | { |
| 107 | unsigned long long tmp; |
| 108 | char *endptr; |
| 109 | |
| 110 | tmp = strtoull(value, &endptr, 10); |
| 111 | if (errno != 0 || endptr == value) |
| 112 | return -ERANGE; |
| 113 | |
| 114 | /* Nanoseconds without unit. */ |
| 115 | if (*endptr == '\0') { |
| 116 | *ret = tmp; |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | /* Seconds */ |
| 121 | if (!strcmp(endptr, "s")) { |
| 122 | if (__builtin_mul_overflow(tmp, NSEC_PER_SEC, &tmp)) |
| 123 | return -ERANGE; |
| 124 | *ret = tmp; |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | /* Milliseconds */ |
| 129 | if (!strcmp(endptr, "ms")) { |
| 130 | if (__builtin_mul_overflow(tmp, USEC_PER_SEC, &tmp)) |
| 131 | return -ERANGE; |
| 132 | *ret = tmp; |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | /* Microseconds */ |
| 137 | if (!strcmp(endptr, "us")) { |
| 138 | if (__builtin_mul_overflow(tmp, MSEC_PER_SEC, &tmp)) |
| 139 | return -ERANGE; |
| 140 | *ret = tmp; |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | return -EINVAL; |
| 145 | } |
| 146 | |
| 147 | /* The configuration file is YAML based. Use libyaml to parse it. */ |
| 148 | int config_read_from_file(const char *config_file) |
| 149 | { |
| 150 | bool base_time_seen = false; |
| 151 | int ret, state_key = 0; |
| 152 | yaml_parser_t parser; |
| 153 | yaml_token_t token; |
| 154 | const char *value; |
| 155 | char *key = NULL; |
| 156 | FILE *f; |
| 157 | |
| 158 | if (!config_file) |
| 159 | return -EINVAL; |
| 160 | |
| 161 | f = fopen(config_file, "r"); |
| 162 | if (!f) { |
| 163 | perror("fopen() failed"); |
| 164 | return -EIO; |
| 165 | } |
| 166 | |
| 167 | ret = yaml_parser_initialize(&parser); |
| 168 | if (!ret) { |
| 169 | ret = -EINVAL; |
| 170 | fprintf(stderr, "Failed to initialize YAML parser\n"); |
| 171 | goto err_yaml; |
| 172 | } |
| 173 | |
| 174 | yaml_parser_set_input_file(&parser, f); |
| 175 | |
| 176 | do { |
| 177 | char *endptr; |
| 178 | |
| 179 | ret = yaml_parser_scan(&parser, &token); |
| 180 | if (!ret) { |
| 181 | ret = -EINVAL; |
| 182 | fprintf(stderr, "Failed to parse YAML file!\n"); |
| 183 | goto err_parse; |
| 184 | } |
| 185 | |
| 186 | switch (token.type) { |
| 187 | case YAML_KEY_TOKEN: |
| 188 | state_key = 1; |
| 189 | break; |
| 190 | case YAML_VALUE_TOKEN: |
| 191 | state_key = 0; |
| 192 | break; |
| 193 | case YAML_SCALAR_TOKEN: |
| 194 | value = (const char *)token.data.scalar.value; |
| 195 | if (state_key) { |
| 196 | /* Save key */ |
| 197 | key = strdup(value); |
| 198 | if (!key) { |
| 199 | fprintf(stderr, "No memory left!\n"); |
| 200 | goto err_parse; |
| 201 | } |
| 202 | |
| 203 | continue; |
| 204 | } |
| 205 | |
| 206 | if (!key) |
| 207 | continue; |
| 208 | |
| 209 | /* Switch value */ |
| 210 | CONFIG_STORE_CLOCKID_PARAM(ApplicationClockId, application_clock_id); |
| 211 | CONFIG_STORE_TIME_PARAM(ApplicationBaseCycleTimeNS, |
| 212 | application_base_cycle_time_ns); |
| 213 | CONFIG_STORE_TIME_PARAM(ApplicationBaseStartTimeNS, |
| 214 | application_base_start_time_ns); |
| 215 | CONFIG_STORE_TIME_PARAM(ApplicationBaseStartOffsetNS, |
| 216 | application_base_start_offset_ns); |
| 217 | CONFIG_STORE_TIME_PARAM(ApplicationTxBaseOffsetNS, |
| 218 | application_tx_base_offset_ns); |
| 219 | CONFIG_STORE_TIME_PARAM(ApplicationRxBaseOffsetNS, |
| 220 | application_rx_base_offset_ns); |
| 221 | CONFIG_STORE_STRING_PARAM(ApplicationXdpProgram, application_xdp_program); |
| 222 | |
| 223 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighEnabled, enabled); |
| 224 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighXdpEnabled, xdp_enabled); |
| 225 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighXdpSkbMode, xdp_skb_mode); |
| 226 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighXdpZcMode, xdp_zc_mode); |
| 227 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighXdpWakeupMode, xdp_wakeup_mode); |
| 228 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighXdpBusyPollMode, xdp_busy_poll_mode); |
| 229 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighTxTimeEnabled, tx_time_enabled); |
| 230 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighIgnoreRxErrors, ignore_rx_errors); |
| 231 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighTxTimeStampEnabled, |
| 232 | tx_hwtstamp_enabled); |
| 233 | CONFIG_STORE_TIME_PARAM_CLASS(TsnHighTxTimeOffsetNS, tx_time_offset_ns); |
| 234 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighVid, vid); |
| 235 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighPcp, pcp); |
| 236 | CONFIG_STORE_ULONG_PARAM_CLASS(TsnHighNumFramesPerCycle, |
| 237 | num_frames_per_cycle); |
| 238 | CONFIG_STORE_STRING_PARAM_CLASS(TsnHighPayloadPattern, payload_pattern); |
| 239 | CONFIG_STORE_ULONG_PARAM_CLASS(TsnHighFrameLength, frame_length); |
| 240 | CONFIG_STORE_SECURITY_MODE_PARAM_CLASS(TsnHighSecurityMode, security_mode); |
| 241 | CONFIG_STORE_SECURITY_ALGORITHM_PARAM_CLASS(TsnHighSecurityAlgorithm, |
| 242 | security_algorithm); |
| 243 | CONFIG_STORE_STRING_PARAM_CLASS(TsnHighSecurityKey, security_key); |
| 244 | CONFIG_STORE_STRING_PARAM_CLASS(TsnHighSecurityIvPrefix, |
| 245 | security_iv_prefix); |
| 246 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighRxQueue, rx_queue); |
| 247 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighTxQueue, tx_queue); |
| 248 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighSocketPriority, socket_priority); |
| 249 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighTxThreadPriority, tx_thread_priority); |
| 250 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighRxThreadPriority, rx_thread_priority); |
| 251 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighTxThreadCpu, tx_thread_cpu); |
| 252 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighRxThreadCpu, rx_thread_cpu); |
| 253 | CONFIG_STORE_INTERFACE_PARAM_CLASS(TsnHighInterface, interface); |
| 254 | CONFIG_STORE_MAC_PARAM_CLASS(TsnHighDestination, l2_destination); |
| 255 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighRxWorkloadEnabled, |
| 256 | rx_workload_enabled); |
| 257 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnHighRxWorkloadPrewarm, |
| 258 | rx_workload_prewarm); |
| 259 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighRxWorkloadSkipCount, |
| 260 | rx_workload_skip_count); |
| 261 | CONFIG_STORE_STRING_PARAM_CLASS(TsnHighRxWorkloadFile, workload_file); |
| 262 | CONFIG_STORE_STRING_PARAM_CLASS(TsnHighRxWorkloadSetupFunction, |
| 263 | workload_setup_function); |
| 264 | CONFIG_STORE_STRING_PARAM_CLASS(TsnHighRxWorkloadSetupArguments, |
| 265 | workload_setup_arguments); |
| 266 | CONFIG_STORE_STRING_PARAM_CLASS(TsnHighRxWorkloadFunction, |
| 267 | workload_function); |
| 268 | CONFIG_STORE_STRING_PARAM_CLASS(TsnHighRxWorkloadArguments, |
| 269 | workload_arguments); |
| 270 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighRxWorkloadThreadCpu, |
| 271 | workload_thread_cpu); |
| 272 | CONFIG_STORE_INT_PARAM_CLASS(TsnHighRxWorkloadThreadPriority, |
| 273 | workload_thread_priority); |
| 274 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnLowEnabled, enabled); |
| 275 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnLowXdpEnabled, xdp_enabled); |
| 276 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnLowXdpSkbMode, xdp_skb_mode); |
| 277 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnLowXdpZcMode, xdp_zc_mode); |
| 278 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnLowXdpWakeupMode, xdp_wakeup_mode); |
| 279 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnLowXdpBusyPollMode, xdp_busy_poll_mode); |
| 280 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnLowTxTimeEnabled, tx_time_enabled); |
| 281 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnLowIgnoreRxErrors, ignore_rx_errors); |
| 282 | CONFIG_STORE_BOOL_PARAM_CLASS(TsnLowTxTimeStampEnabled, |
| 283 | tx_hwtstamp_enabled); |
| 284 | CONFIG_STORE_TIME_PARAM_CLASS(TsnLowTxTimeOffsetNS, tx_time_offset_ns); |
| 285 | CONFIG_STORE_INT_PARAM_CLASS(TsnLowVid, vid); |
| 286 | CONFIG_STORE_INT_PARAM_CLASS(TsnLowPcp, pcp); |
| 287 | CONFIG_STORE_ULONG_PARAM_CLASS(TsnLowNumFramesPerCycle, |
| 288 | num_frames_per_cycle); |
| 289 | CONFIG_STORE_STRING_PARAM_CLASS(TsnLowPayloadPattern, payload_pattern); |
| 290 | CONFIG_STORE_ULONG_PARAM_CLASS(TsnLowFrameLength, frame_length); |
| 291 | CONFIG_STORE_SECURITY_MODE_PARAM_CLASS(TsnLowSecurityMode, security_mode); |
| 292 | CONFIG_STORE_SECURITY_ALGORITHM_PARAM_CLASS(TsnLowSecurityAlgorithm, |
| 293 | security_algorithm); |
| 294 | CONFIG_STORE_STRING_PARAM_CLASS(TsnLowSecurityKey, security_key); |
| 295 | CONFIG_STORE_STRING_PARAM_CLASS(TsnLowSecurityIvPrefix, security_iv_prefix); |
| 296 | CONFIG_STORE_INT_PARAM_CLASS(TsnLowRxQueue, rx_queue); |
| 297 | CONFIG_STORE_INT_PARAM_CLASS(TsnLowTxQueue, tx_queue); |
| 298 | CONFIG_STORE_INT_PARAM_CLASS(TsnLowSocketPriority, socket_priority); |
| 299 | CONFIG_STORE_INT_PARAM_CLASS(TsnLowTxThreadPriority, tx_thread_priority); |
| 300 | CONFIG_STORE_INT_PARAM_CLASS(TsnLowRxThreadPriority, rx_thread_priority); |
| 301 | CONFIG_STORE_INT_PARAM_CLASS(TsnLowTxThreadCpu, tx_thread_cpu); |
| 302 | CONFIG_STORE_INT_PARAM_CLASS(TsnLowRxThreadCpu, rx_thread_cpu); |
| 303 | CONFIG_STORE_INTERFACE_PARAM_CLASS(TsnLowInterface, interface); |
| 304 | CONFIG_STORE_MAC_PARAM_CLASS(TsnLowDestination, l2_destination); |
| 305 | |
| 306 | CONFIG_STORE_BOOL_PARAM_CLASS(RtcEnabled, enabled); |
| 307 | CONFIG_STORE_BOOL_PARAM_CLASS(RtcXdpEnabled, xdp_enabled); |
| 308 | CONFIG_STORE_BOOL_PARAM_CLASS(RtcXdpSkbMode, xdp_skb_mode); |
| 309 | CONFIG_STORE_BOOL_PARAM_CLASS(RtcXdpZcMode, xdp_zc_mode); |
| 310 | CONFIG_STORE_BOOL_PARAM_CLASS(RtcXdpWakeupMode, xdp_wakeup_mode); |
| 311 | CONFIG_STORE_BOOL_PARAM_CLASS(RtcXdpBusyPollMode, xdp_busy_poll_mode); |
| 312 | CONFIG_STORE_BOOL_PARAM_CLASS(RtcIgnoreRxErrors, ignore_rx_errors); |
| 313 | CONFIG_STORE_BOOL_PARAM_CLASS(RtcTxTimeStampEnabled, tx_hwtstamp_enabled); |
| 314 | CONFIG_STORE_INT_PARAM_CLASS(RtcVid, vid); |
| 315 | CONFIG_STORE_INT_PARAM_CLASS(RtcPcp, pcp); |
| 316 | CONFIG_STORE_ULONG_PARAM_CLASS(RtcNumFramesPerCycle, num_frames_per_cycle); |
| 317 | CONFIG_STORE_STRING_PARAM_CLASS(RtcPayloadPattern, payload_pattern); |
| 318 | CONFIG_STORE_ULONG_PARAM_CLASS(RtcFrameLength, frame_length); |
| 319 | CONFIG_STORE_SECURITY_MODE_PARAM_CLASS(RtcSecurityMode, security_mode); |
| 320 | CONFIG_STORE_SECURITY_ALGORITHM_PARAM_CLASS(RtcSecurityAlgorithm, |
| 321 | security_algorithm); |
| 322 | CONFIG_STORE_STRING_PARAM_CLASS(RtcSecurityKey, security_key); |
| 323 | CONFIG_STORE_STRING_PARAM_CLASS(RtcSecurityIvPrefix, security_iv_prefix); |
| 324 | CONFIG_STORE_INT_PARAM_CLASS(RtcRxQueue, rx_queue); |
| 325 | CONFIG_STORE_INT_PARAM_CLASS(RtcTxQueue, tx_queue); |
| 326 | CONFIG_STORE_INT_PARAM_CLASS(RtcSocketPriority, socket_priority); |
| 327 | CONFIG_STORE_INT_PARAM_CLASS(RtcTxThreadPriority, tx_thread_priority); |
| 328 | CONFIG_STORE_INT_PARAM_CLASS(RtcRxThreadPriority, rx_thread_priority); |
| 329 | CONFIG_STORE_INT_PARAM_CLASS(RtcTxThreadCpu, tx_thread_cpu); |
| 330 | CONFIG_STORE_INT_PARAM_CLASS(RtcRxThreadCpu, rx_thread_cpu); |
| 331 | CONFIG_STORE_INTERFACE_PARAM_CLASS(RtcInterface, interface); |
| 332 | CONFIG_STORE_MAC_PARAM_CLASS(RtcDestination, l2_destination); |
| 333 | |
| 334 | CONFIG_STORE_BOOL_PARAM_CLASS(RtaEnabled, enabled); |
| 335 | CONFIG_STORE_BOOL_PARAM_CLASS(RtaXdpEnabled, xdp_enabled); |
| 336 | CONFIG_STORE_BOOL_PARAM_CLASS(RtaXdpSkbMode, xdp_skb_mode); |
| 337 | CONFIG_STORE_BOOL_PARAM_CLASS(RtaXdpZcMode, xdp_zc_mode); |
| 338 | CONFIG_STORE_BOOL_PARAM_CLASS(RtaXdpWakeupMode, xdp_wakeup_mode); |
| 339 | CONFIG_STORE_BOOL_PARAM_CLASS(RtaXdpBusyPollMode, xdp_busy_poll_mode); |
| 340 | CONFIG_STORE_BOOL_PARAM_CLASS(RtaIgnoreRxErrors, ignore_rx_errors); |
| 341 | CONFIG_STORE_BOOL_PARAM_CLASS(RtaTxTimeStampEnabled, tx_hwtstamp_enabled); |
| 342 | CONFIG_STORE_INT_PARAM_CLASS(RtaVid, vid); |
| 343 | CONFIG_STORE_INT_PARAM_CLASS(RtaPcp, pcp); |
| 344 | CONFIG_STORE_TIME_PARAM_CLASS(RtaBurstPeriodNS, burst_period_ns); |
| 345 | CONFIG_STORE_ULONG_PARAM_CLASS(RtaNumFramesPerCycle, num_frames_per_cycle); |
| 346 | CONFIG_STORE_STRING_PARAM_CLASS(RtaPayloadPattern, payload_pattern); |
| 347 | CONFIG_STORE_ULONG_PARAM_CLASS(RtaFrameLength, frame_length); |
| 348 | CONFIG_STORE_SECURITY_MODE_PARAM_CLASS(RtaSecurityMode, security_mode); |
| 349 | CONFIG_STORE_SECURITY_ALGORITHM_PARAM_CLASS(RtaSecurityAlgorithm, |
| 350 | security_algorithm); |
| 351 | CONFIG_STORE_STRING_PARAM_CLASS(RtaSecurityKey, security_key); |
| 352 | CONFIG_STORE_STRING_PARAM_CLASS(RtaSecurityIvPrefix, security_iv_prefix); |
| 353 | CONFIG_STORE_INT_PARAM_CLASS(RtaRxQueue, rx_queue); |
| 354 | CONFIG_STORE_INT_PARAM_CLASS(RtaTxQueue, tx_queue); |
| 355 | CONFIG_STORE_INT_PARAM_CLASS(RtaSocketPriority, socket_priority); |
| 356 | CONFIG_STORE_INT_PARAM_CLASS(RtaTxThreadPriority, tx_thread_priority); |
| 357 | CONFIG_STORE_INT_PARAM_CLASS(RtaRxThreadPriority, rx_thread_priority); |
| 358 | CONFIG_STORE_INT_PARAM_CLASS(RtaTxThreadCpu, tx_thread_cpu); |
| 359 | CONFIG_STORE_INT_PARAM_CLASS(RtaRxThreadCpu, rx_thread_cpu); |
| 360 | CONFIG_STORE_INTERFACE_PARAM_CLASS(RtaInterface, interface); |
| 361 | CONFIG_STORE_MAC_PARAM_CLASS(RtaDestination, l2_destination); |
| 362 | |
| 363 | CONFIG_STORE_BOOL_PARAM_CLASS(DcpEnabled, enabled); |
| 364 | CONFIG_STORE_BOOL_PARAM_CLASS(DcpIgnoreRxErrors, ignore_rx_errors); |
| 365 | CONFIG_STORE_INT_PARAM_CLASS(DcpVid, vid); |
| 366 | CONFIG_STORE_INT_PARAM_CLASS(DcpPcp, pcp); |
| 367 | CONFIG_STORE_TIME_PARAM_CLASS(DcpBurstPeriodNS, burst_period_ns); |
| 368 | CONFIG_STORE_ULONG_PARAM_CLASS(DcpNumFramesPerCycle, num_frames_per_cycle); |
| 369 | CONFIG_STORE_STRING_PARAM_CLASS(DcpPayloadPattern, payload_pattern); |
| 370 | CONFIG_STORE_ULONG_PARAM_CLASS(DcpFrameLength, frame_length); |
| 371 | CONFIG_STORE_INT_PARAM_CLASS(DcpRxQueue, rx_queue); |
| 372 | CONFIG_STORE_INT_PARAM_CLASS(DcpTxQueue, tx_queue); |
| 373 | CONFIG_STORE_INT_PARAM_CLASS(DcpSocketPriority, socket_priority); |
| 374 | CONFIG_STORE_INT_PARAM_CLASS(DcpTxThreadPriority, tx_thread_priority); |
| 375 | CONFIG_STORE_INT_PARAM_CLASS(DcpRxThreadPriority, rx_thread_priority); |
| 376 | CONFIG_STORE_INT_PARAM_CLASS(DcpTxThreadCpu, tx_thread_cpu); |
| 377 | CONFIG_STORE_INT_PARAM_CLASS(DcpRxThreadCpu, rx_thread_cpu); |
| 378 | CONFIG_STORE_INTERFACE_PARAM_CLASS(DcpInterface, interface); |
| 379 | CONFIG_STORE_MAC_PARAM_CLASS(DcpDestination, l2_destination); |
| 380 | |
| 381 | CONFIG_STORE_BOOL_PARAM_CLASS(LldpEnabled, enabled); |
| 382 | CONFIG_STORE_BOOL_PARAM_CLASS(LldpIgnoreRxErrors, ignore_rx_errors); |
| 383 | CONFIG_STORE_TIME_PARAM_CLASS(LldpBurstPeriodNS, burst_period_ns); |
| 384 | CONFIG_STORE_ULONG_PARAM_CLASS(LldpNumFramesPerCycle, num_frames_per_cycle); |
| 385 | CONFIG_STORE_STRING_PARAM_CLASS(LldpPayloadPattern, payload_pattern); |
| 386 | CONFIG_STORE_ULONG_PARAM_CLASS(LldpFrameLength, frame_length); |
| 387 | CONFIG_STORE_INT_PARAM_CLASS(LldpRxQueue, rx_queue); |
| 388 | CONFIG_STORE_INT_PARAM_CLASS(LldpTxQueue, tx_queue); |
| 389 | CONFIG_STORE_INT_PARAM_CLASS(LldpSocketPriority, socket_priority); |
| 390 | CONFIG_STORE_INT_PARAM_CLASS(LldpTxThreadPriority, tx_thread_priority); |
| 391 | CONFIG_STORE_INT_PARAM_CLASS(LldpRxThreadPriority, rx_thread_priority); |
| 392 | CONFIG_STORE_INT_PARAM_CLASS(LldpTxThreadCpu, tx_thread_cpu); |
| 393 | CONFIG_STORE_INT_PARAM_CLASS(LldpRxThreadCpu, rx_thread_cpu); |
| 394 | CONFIG_STORE_INTERFACE_PARAM_CLASS(LldpInterface, interface); |
| 395 | CONFIG_STORE_MAC_PARAM_CLASS(LldpDestination, l2_destination); |
| 396 | |
| 397 | CONFIG_STORE_BOOL_PARAM_CLASS(UdpHighEnabled, enabled); |
| 398 | CONFIG_STORE_BOOL_PARAM_CLASS(UdpHighIgnoreRxErrors, ignore_rx_errors); |
| 399 | CONFIG_STORE_TIME_PARAM_CLASS(UdpHighBurstPeriodNS, burst_period_ns); |
| 400 | CONFIG_STORE_ULONG_PARAM_CLASS(UdpHighNumFramesPerCycle, |
| 401 | num_frames_per_cycle); |
| 402 | CONFIG_STORE_STRING_PARAM_CLASS(UdpHighPayloadPattern, payload_pattern); |
| 403 | CONFIG_STORE_ULONG_PARAM_CLASS(UdpHighFrameLength, frame_length); |
| 404 | CONFIG_STORE_INT_PARAM_CLASS(UdpHighRxQueue, rx_queue); |
| 405 | CONFIG_STORE_INT_PARAM_CLASS(UdpHighTxQueue, tx_queue); |
| 406 | CONFIG_STORE_INT_PARAM_CLASS(UdpHighSocketPriority, socket_priority); |
| 407 | CONFIG_STORE_INT_PARAM_CLASS(UdpHighTxThreadPriority, tx_thread_priority); |
| 408 | CONFIG_STORE_INT_PARAM_CLASS(UdpHighRxThreadPriority, rx_thread_priority); |
| 409 | CONFIG_STORE_INT_PARAM_CLASS(UdpHighTxThreadCpu, tx_thread_cpu); |
| 410 | CONFIG_STORE_INT_PARAM_CLASS(UdpHighRxThreadCpu, rx_thread_cpu); |
| 411 | CONFIG_STORE_INTERFACE_PARAM_CLASS(UdpHighInterface, interface); |
| 412 | CONFIG_STORE_STRING_PARAM_CLASS(UdpHighPort, l3_port); |
| 413 | CONFIG_STORE_STRING_PARAM_CLASS(UdpHighDestination, l3_destination); |
| 414 | CONFIG_STORE_STRING_PARAM_CLASS(UdpHighSource, l3_source); |
| 415 | |
| 416 | CONFIG_STORE_BOOL_PARAM_CLASS(UdpLowEnabled, enabled); |
| 417 | CONFIG_STORE_BOOL_PARAM_CLASS(UdpLowIgnoreRxErrors, ignore_rx_errors); |
| 418 | CONFIG_STORE_TIME_PARAM_CLASS(UdpLowBurstPeriodNS, burst_period_ns); |
| 419 | CONFIG_STORE_ULONG_PARAM_CLASS(UdpLowNumFramesPerCycle, |
| 420 | num_frames_per_cycle); |
| 421 | CONFIG_STORE_STRING_PARAM_CLASS(UdpLowPayloadPattern, payload_pattern); |
| 422 | CONFIG_STORE_ULONG_PARAM_CLASS(UdpLowFrameLength, frame_length); |
| 423 | CONFIG_STORE_INT_PARAM_CLASS(UdpLowRxQueue, rx_queue); |
| 424 | CONFIG_STORE_INT_PARAM_CLASS(UdpLowTxQueue, tx_queue); |
| 425 | CONFIG_STORE_INT_PARAM_CLASS(UdpLowSocketPriority, socket_priority); |
| 426 | CONFIG_STORE_INT_PARAM_CLASS(UdpLowTxThreadPriority, tx_thread_priority); |
| 427 | CONFIG_STORE_INT_PARAM_CLASS(UdpLowRxThreadPriority, rx_thread_priority); |
| 428 | CONFIG_STORE_INT_PARAM_CLASS(UdpLowTxThreadCpu, tx_thread_cpu); |
| 429 | CONFIG_STORE_INT_PARAM_CLASS(UdpLowRxThreadCpu, rx_thread_cpu); |
| 430 | CONFIG_STORE_INTERFACE_PARAM_CLASS(UdpLowInterface, interface); |
| 431 | CONFIG_STORE_STRING_PARAM_CLASS(UdpLowPort, l3_port); |
| 432 | CONFIG_STORE_STRING_PARAM_CLASS(UdpLowDestination, l3_destination); |
| 433 | CONFIG_STORE_STRING_PARAM_CLASS(UdpLowSource, l3_source); |
| 434 | |
| 435 | CONFIG_STORE_STRING_PARAM_CLASS(GenericL2Name, name); |
| 436 | CONFIG_STORE_BOOL_PARAM_CLASS(GenericL2Enabled, enabled); |
| 437 | CONFIG_STORE_BOOL_PARAM_CLASS(GenericL2XdpEnabled, xdp_enabled); |
| 438 | CONFIG_STORE_BOOL_PARAM_CLASS(GenericL2XdpSkbMode, xdp_skb_mode); |
| 439 | CONFIG_STORE_BOOL_PARAM_CLASS(GenericL2XdpZcMode, xdp_zc_mode); |
| 440 | CONFIG_STORE_BOOL_PARAM_CLASS(GenericL2XdpWakeupMode, xdp_wakeup_mode); |
| 441 | CONFIG_STORE_BOOL_PARAM_CLASS(GenericL2XdpBusyPollMode, xdp_busy_poll_mode); |
| 442 | CONFIG_STORE_BOOL_PARAM_CLASS(GenericL2TxTimeEnabled, tx_time_enabled); |
| 443 | CONFIG_STORE_BOOL_PARAM_CLASS(GenericL2IgnoreRxErrors, ignore_rx_errors); |
| 444 | CONFIG_STORE_BOOL_PARAM_CLASS(GenericL2TxTimeStampEnabled, |
| 445 | tx_hwtstamp_enabled); |
| 446 | CONFIG_STORE_TIME_PARAM_CLASS(GenericL2TxTimeOffsetNS, tx_time_offset_ns); |
| 447 | CONFIG_STORE_INT_PARAM_CLASS(GenericL2Vid, vid); |
| 448 | CONFIG_STORE_INT_PARAM_CLASS(GenericL2Pcp, pcp); |
| 449 | CONFIG_STORE_ETHER_TYPE_CLASS(GenericL2EtherType, ether_type); |
| 450 | CONFIG_STORE_ULONG_PARAM_CLASS(GenericL2NumFramesPerCycle, |
| 451 | num_frames_per_cycle); |
| 452 | CONFIG_STORE_STRING_PARAM_CLASS(GenericL2PayloadPattern, payload_pattern); |
| 453 | CONFIG_STORE_ULONG_PARAM_CLASS(GenericL2FrameLength, frame_length); |
| 454 | CONFIG_STORE_INT_PARAM_CLASS(GenericL2RxQueue, rx_queue); |
| 455 | CONFIG_STORE_INT_PARAM_CLASS(GenericL2TxQueue, tx_queue); |
| 456 | CONFIG_STORE_INT_PARAM_CLASS(GenericL2SocketPriority, socket_priority); |
| 457 | CONFIG_STORE_INT_PARAM_CLASS(GenericL2TxThreadPriority, tx_thread_priority); |
| 458 | CONFIG_STORE_INT_PARAM_CLASS(GenericL2RxThreadPriority, rx_thread_priority); |
| 459 | CONFIG_STORE_INT_PARAM_CLASS(GenericL2TxThreadCpu, tx_thread_cpu); |
| 460 | CONFIG_STORE_INT_PARAM_CLASS(GenericL2RxThreadCpu, rx_thread_cpu); |
| 461 | CONFIG_STORE_INTERFACE_PARAM_CLASS(GenericL2Interface, interface); |
| 462 | CONFIG_STORE_MAC_PARAM_CLASS(GenericL2Destination, l2_destination); |
| 463 | |
| 464 | CONFIG_STORE_INT_PARAM(LogThreadPriority, log_thread_priority); |
| 465 | CONFIG_STORE_INT_PARAM(LogThreadCpu, log_thread_cpu); |
| 466 | CONFIG_STORE_STRING_PARAM(LogFile, log_file); |
| 467 | CONFIG_STORE_STRING_PARAM(LogLevel, log_level); |
| 468 | |
| 469 | CONFIG_STORE_BOOL_PARAM(DebugStopTraceOnOutlier, |
| 470 | debug_stop_trace_on_outlier); |
| 471 | CONFIG_STORE_BOOL_PARAM(DebugStopTraceOnError, debug_stop_trace_on_error); |
| 472 | CONFIG_STORE_BOOL_PARAM(DebugMonitorMode, debug_monitor_mode); |
| 473 | CONFIG_STORE_MAC_PARAM(DebugMonitorDestination, debug_monitor_destination); |
| 474 | |
| 475 | CONFIG_STORE_BOOL_PARAM(StatsHistogramEnabled, stats_histogram_enabled); |
| 476 | CONFIG_STORE_TIME_PARAM(StatsHistogramMinimumNS, |
| 477 | stats_histogram_minimum_ns); |
| 478 | CONFIG_STORE_TIME_PARAM(StatsHistogramMaximumNS, |
| 479 | stats_histogram_maximum_ns); |
| 480 | CONFIG_STORE_STRING_PARAM(StatsHistogramFile, stats_histogram_file); |
| 481 | CONFIG_STORE_TIME_PARAM(StatsCollectionIntervalNS, |
| 482 | stats_collection_interval_ns); |
| 483 | |
| 484 | CONFIG_STORE_BOOL_PARAM(LogMqtt, log_mqtt); |
| 485 | CONFIG_STORE_INT_PARAM(LogMqttThreadPriority, log_mqtt_thread_priority); |
| 486 | CONFIG_STORE_INT_PARAM(LogMqttThreadCpu, log_mqtt_thread_cpu); |
| 487 | CONFIG_STORE_STRING_PARAM(LogMqttBrokerIP, log_mqtt_broker_ip); |
| 488 | CONFIG_STORE_INT_PARAM(LogMqttBrokerPort, log_mqtt_broker_port); |
| 489 | CONFIG_STORE_INT_PARAM(LogMqttKeepAliveSecs, log_mqtt_keep_alive_secs); |
| 490 | CONFIG_STORE_STRING_PARAM(LogMqttMeasurementName, |
| 491 | log_mqtt_measurement_name); |
| 492 | |
| 493 | CONFIG_STORE_BOOL_PARAM(LogJson, log_json); |
| 494 | CONFIG_STORE_INT_PARAM(LogJsonThreadPriority, log_json_thread_priority); |
| 495 | CONFIG_STORE_INT_PARAM(LogJsonThreadCpu, log_json_thread_cpu); |
| 496 | CONFIG_STORE_STRING_PARAM(LogJsonHost, log_json_host); |
| 497 | CONFIG_STORE_STRING_PARAM(LogJsonPort, log_json_port); |
| 498 | CONFIG_STORE_STRING_PARAM(LogJsonMeasurementName, |
| 499 | log_json_measurement_name); |
| 500 | |
| 501 | if (!strcmp(key, "ApplicationBaseStartTimeNS")) |
| 502 | base_time_seen = true; |
| 503 | |
| 504 | if (key) |
| 505 | free(key); |
| 506 | |
| 507 | default: |
| 508 | break; |
| 509 | } |
| 510 | |
| 511 | if (token.type != YAML_STREAM_END_TOKEN) |
| 512 | yaml_token_delete(&token); |
| 513 | |
| 514 | } while (token.type != YAML_STREAM_END_TOKEN); |
| 515 | |
| 516 | /* |
| 517 | * Re-calculate default base start time. There is one case where this necessary: |
| 518 | * - The user provided a different clock_id than TAI in yaml file |
| 519 | * - The user did not provide a base time in yaml file |
| 520 | * |
| 521 | * In that case the default base time calculated by config_set_defaults() is based on |
| 522 | * TAI. That has to be re-done by using the user provided clock id. |
| 523 | */ |
| 524 | if (app_config.application_clock_id != CLOCK_TAI && !base_time_seen) { |
| 525 | struct timespec current; |
| 526 | |
| 527 | clock_gettime(app_config.application_clock_id, ¤t); |
| 528 | app_config.application_base_start_time_ns = (current.tv_sec + 30) * NSEC_PER_SEC; |
| 529 | } |
| 530 | |
| 531 | ret = 0; |
| 532 | |
| 533 | err_parse: |
| 534 | yaml_token_delete(&token); |
| 535 | yaml_parser_delete(&parser); |
| 536 | |
| 537 | err_yaml: |
| 538 | fclose(f); |
| 539 | |
| 540 | return ret; |
| 541 | } |
| 542 | |
| 543 | void config_print_values(void) |
| 544 | { |
| 545 | const struct traffic_class_config *conf; |
| 546 | |
| 547 | printf("--------------------------------------------------------------------------------" |
| 548 | "\n"); |
| 549 | printf("ApplicationClockId=%s\n", |
| 550 | app_config.application_clock_id == CLOCK_TAI ? "CLOCK_TAI" : "CLOCK_MONOTONIC"); |
| 551 | printf("ApplicationBaseCycleTimeNS=%" PRIu64 "\n", |
| 552 | app_config.application_base_cycle_time_ns); |
| 553 | printf("ApplicationBaseStartTimeNS=%" PRIu64 "\n", |
| 554 | app_config.application_base_start_time_ns); |
| 555 | printf("ApplicationBaseStartOffsetNS=%" PRIu64 "\n", |
| 556 | app_config.application_base_start_offset_ns); |
| 557 | printf("ApplicationTxBaseOffsetNS=%" PRIu64 "\n", app_config.application_tx_base_offset_ns); |
| 558 | printf("ApplicationRxBaseOffsetNS=%" PRIu64 "\n", app_config.application_rx_base_offset_ns); |
| 559 | printf("ApplicationXdpProgram=%s\n", app_config.application_xdp_program); |
| 560 | printf("--------------------------------------------------------------------------------" |
| 561 | "\n"); |
| 562 | |
| 563 | conf = &app_config.classes[TSN_HIGH_FRAME_TYPE]; |
| 564 | printf("TsnHighEnabled=%s\n", conf->enabled ? "True" : "False"); |
| 565 | printf("TsnHighRxMirrorEnabled=%s\n", conf->rx_mirror_enabled ? "True" : "False"); |
| 566 | printf("TsnHighXdpEnabled=%s\n", conf->xdp_enabled ? "True" : "False"); |
| 567 | printf("TsnHighXdpSkbMode=%s\n", conf->xdp_skb_mode ? "True" : "False"); |
| 568 | printf("TsnHighXdpZcMode=%s\n", conf->xdp_zc_mode ? "True" : "False"); |
| 569 | printf("TsnHighXdpWakeupMode=%s\n", conf->xdp_wakeup_mode ? "True" : "False"); |
| 570 | printf("TsnHighXdpBusyPollMode=%s\n", conf->xdp_busy_poll_mode ? "True" : "False"); |
| 571 | printf("TsnHighTxTimeEnabled=%s\n", conf->tx_time_enabled ? "True" : "False"); |
| 572 | printf("TsnHighIgnoreRxErrors=%s\n", conf->ignore_rx_errors ? "True" : "False"); |
| 573 | printf("TsnHighTxTimeOffsetNS=%" PRIu64 "\n", conf->tx_time_offset_ns); |
| 574 | printf("TsnHighTxTimeStampEnabled=%s\n", conf->tx_hwtstamp_enabled ? "True" : "False"); |
| 575 | printf("TsnHighVid=%d\n", conf->vid); |
| 576 | printf("TsnHighPcp=%d\n", conf->pcp); |
| 577 | printf("TsnHighNumFramesPerCycle=%zu\n", conf->num_frames_per_cycle); |
| 578 | printf("TsnHighPayloadPattern="); |
| 579 | print_payload_pattern(conf->payload_pattern, conf->payload_pattern_length); |
| 580 | printf("\n"); |
| 581 | printf("TsnHighFrameLength=%zu\n", conf->frame_length); |
| 582 | printf("TsnHighSecurityMode=%s\n", security_mode_to_string(conf->security_mode)); |
| 583 | printf("TsnHighSecurityAlgorithm=%s\n", |
| 584 | security_algorithm_to_string(conf->security_algorithm)); |
| 585 | printf("TsnHighSecurityKey=%s\n", conf->security_key); |
| 586 | printf("TsnHighSecurityIvPrefix=%s\n", conf->security_iv_prefix); |
| 587 | printf("TsnHighRxQueue=%d\n", conf->rx_queue); |
| 588 | printf("TsnHighTxQueue=%d\n", conf->tx_queue); |
| 589 | printf("TsnHighSocketPriority=%d\n", conf->socket_priority); |
| 590 | printf("TsnHighTxThreadPriority=%d\n", conf->tx_thread_priority); |
| 591 | printf("TsnHighRxThreadPriority=%d\n", conf->rx_thread_priority); |
| 592 | printf("TsnHighTxThreadCpu=%d\n", conf->tx_thread_cpu); |
| 593 | printf("TsnHighRxThreadCpu=%d\n", conf->rx_thread_cpu); |
| 594 | printf("TsnHighInterface=%s\n", conf->interface); |
| 595 | printf("TsnHighDestination="); |
| 596 | print_mac_address(conf->l2_destination); |
| 597 | printf("\n"); |
| 598 | printf("TsnHighRxWorkloadEnabled=%s\n", conf->rx_workload_enabled ? "True" : "False"); |
| 599 | printf("TsnHighRxWorkloadPrewarm=%s\n", conf->rx_workload_prewarm ? "True" : "False"); |
| 600 | printf("TsnHighRxWorkloadSkipCount=%d\n", conf->rx_workload_skip_count); |
| 601 | printf("TsnHighRxWorkloadFile=%s\n", conf->workload_file); |
| 602 | printf("TsnHighRxWorkloadSetupFunction=%s\n", conf->workload_setup_function); |
| 603 | printf("TsnHighRxWorkloadSetupArguments=%s\n", conf->workload_setup_arguments); |
| 604 | printf("TsnHighRxWorkloadFunction=%s\n", conf->workload_function); |
| 605 | printf("TsnHighRxWorkloadArguments=%s\n", conf->workload_arguments); |
| 606 | printf("TsnHighRxWorkloadThreadCpu=%d\n", conf->workload_thread_cpu); |
| 607 | printf("TsnHighRxWorkloadThreadPriority=%d\n", conf->workload_thread_priority); |
| 608 | printf("--------------------------------------------------------------------------------" |
| 609 | "\n"); |
| 610 | |
| 611 | conf = &app_config.classes[TSN_LOW_FRAME_TYPE]; |
| 612 | printf("TsnLowEnabled=%s\n", conf->enabled ? "True" : "False"); |
| 613 | printf("TsnLowRxMirrorEnabled=%s\n", conf->rx_mirror_enabled ? "True" : "False"); |
| 614 | printf("TsnLowXdpEnabled=%s\n", conf->xdp_enabled ? "True" : "False"); |
| 615 | printf("TsnLowXdpSkbMode=%s\n", conf->xdp_skb_mode ? "True" : "False"); |
| 616 | printf("TsnLowXdpZcMode=%s\n", conf->xdp_zc_mode ? "True" : "False"); |
| 617 | printf("TsnLowXdpWakeupMode=%s\n", conf->xdp_wakeup_mode ? "True" : "False"); |
| 618 | printf("TsnLowXdpBusyPollMode=%s\n", conf->xdp_busy_poll_mode ? "True" : "False"); |
| 619 | printf("TsnLowTxTimeEnabled=%s\n", conf->tx_time_enabled ? "True" : "False"); |
| 620 | printf("TsnLowIgnoreRxErrors=%s\n", conf->ignore_rx_errors ? "True" : "False"); |
| 621 | printf("TsnLowTxTimeOffsetNS=%" PRIu64 "\n", conf->tx_time_offset_ns); |
| 622 | printf("TsnLowTxTimeStampEnabled=%s\n", conf->tx_hwtstamp_enabled ? "True" : "False"); |
| 623 | printf("TsnLowVid=%d\n", conf->vid); |
| 624 | printf("TsnLowPcp=%d\n", conf->pcp); |
| 625 | printf("TsnLowNumFramesPerCycle=%zu\n", conf->num_frames_per_cycle); |
| 626 | printf("TsnLowPayloadPattern="); |
| 627 | print_payload_pattern(conf->payload_pattern, conf->payload_pattern_length); |
| 628 | printf("\n"); |
| 629 | printf("TsnLowFrameLength=%zu\n", conf->frame_length); |
| 630 | printf("TsnLowSecurityMode=%s\n", security_mode_to_string(conf->security_mode)); |
| 631 | printf("TsnLowSecurityAlgorithm=%s\n", |
| 632 | security_algorithm_to_string(conf->security_algorithm)); |
| 633 | printf("TsnLowSecurityKey=%s\n", conf->security_key); |
| 634 | printf("TsnLowSecurityIvPrefix=%s\n", conf->security_iv_prefix); |
| 635 | printf("TsnLowRxQueue=%d\n", conf->rx_queue); |
| 636 | printf("TsnLowTxQueue=%d\n", conf->tx_queue); |
| 637 | printf("TsnLowSocketPriority=%d\n", conf->socket_priority); |
| 638 | printf("TsnLowTxThreadPriority=%d\n", conf->tx_thread_priority); |
| 639 | printf("TsnLowRxThreadPriority=%d\n", conf->rx_thread_priority); |
| 640 | printf("TsnLowTxThreadCpu=%d\n", conf->tx_thread_cpu); |
| 641 | printf("TsnLowRxThreadCpu=%d\n", conf->rx_thread_cpu); |
| 642 | printf("TsnLowInterface=%s\n", conf->interface); |
| 643 | printf("TsnLowDestination="); |
| 644 | print_mac_address(conf->l2_destination); |
| 645 | printf("\n"); |
| 646 | printf("--------------------------------------------------------------------------------" |
| 647 | "\n"); |
| 648 | |
| 649 | conf = &app_config.classes[RTC_FRAME_TYPE]; |
| 650 | printf("RtcEnabled=%s\n", conf->enabled ? "True" : "False"); |
| 651 | printf("RtcRxMirrorEnabled=%s\n", conf->rx_mirror_enabled ? "True" : "False"); |
| 652 | printf("RtcXdpEnabled=%s\n", conf->xdp_enabled ? "True" : "False"); |
| 653 | printf("RtcXdpSkbMode=%s\n", conf->xdp_skb_mode ? "True" : "False"); |
| 654 | printf("RtcXdpZcMode=%s\n", conf->xdp_zc_mode ? "True" : "False"); |
| 655 | printf("RtcXdpWakeupMode=%s\n", conf->xdp_wakeup_mode ? "True" : "False"); |
| 656 | printf("RtcXdpBusyPollMode=%s\n", conf->xdp_busy_poll_mode ? "True" : "False"); |
| 657 | printf("RtcIgnoreRxErrors=%s\n", conf->ignore_rx_errors ? "True" : "False"); |
| 658 | printf("RtcTxTimeStampEnabled=%s\n", conf->tx_hwtstamp_enabled ? "True" : "False"); |
| 659 | printf("RtcVid=%d\n", conf->vid); |
| 660 | printf("RtcPcp=%d\n", conf->pcp); |
| 661 | printf("RtcNumFramesPerCycle=%zu\n", conf->num_frames_per_cycle); |
| 662 | printf("RtcPayloadPattern="); |
| 663 | print_payload_pattern(conf->payload_pattern, conf->payload_pattern_length); |
| 664 | printf("\n"); |
| 665 | printf("RtcFrameLength=%zu\n", conf->frame_length); |
| 666 | printf("RtcSecurityMode=%s\n", security_mode_to_string(conf->security_mode)); |
| 667 | printf("RtcSecurityAlgorithm=%s\n", security_algorithm_to_string(conf->security_algorithm)); |
| 668 | printf("RtcSecurityKey=%s\n", conf->security_key); |
| 669 | printf("RtcSecurityIvPrefix=%s\n", conf->security_iv_prefix); |
| 670 | printf("RtcRxQueue=%d\n", conf->rx_queue); |
| 671 | printf("RtcTxQueue=%d\n", conf->tx_queue); |
| 672 | printf("RtcSocketPriority=%d\n", conf->socket_priority); |
| 673 | printf("RtcTxThreadPriority=%d\n", conf->tx_thread_priority); |
| 674 | printf("RtcRxThreadPriority=%d\n", conf->rx_thread_priority); |
| 675 | printf("RtcTxThreadCpu=%d\n", conf->tx_thread_cpu); |
| 676 | printf("RtcRxThreadCpu=%d\n", conf->rx_thread_cpu); |
| 677 | printf("RtcInterface=%s\n", conf->interface); |
| 678 | printf("RtcDestination="); |
| 679 | print_mac_address(conf->l2_destination); |
| 680 | printf("\n"); |
| 681 | printf("--------------------------------------------------------------------------------" |
| 682 | "\n"); |
| 683 | |
| 684 | conf = &app_config.classes[RTA_FRAME_TYPE]; |
| 685 | printf("RtaEnabled=%s\n", conf->enabled ? "True" : "False"); |
| 686 | printf("RtaRxMirrorEnabled=%s\n", conf->rx_mirror_enabled ? "True" : "False"); |
| 687 | printf("RtaXdpEnabled=%s\n", conf->xdp_enabled ? "True" : "False"); |
| 688 | printf("RtaXdpSkbMode=%s\n", conf->xdp_skb_mode ? "True" : "False"); |
| 689 | printf("RtaXdpZcMode=%s\n", conf->xdp_zc_mode ? "True" : "False"); |
| 690 | printf("RtaXdpWakeupMode=%s\n", conf->xdp_wakeup_mode ? "True" : "False"); |
| 691 | printf("RtaXdpBusyPollMode=%s\n", conf->xdp_busy_poll_mode ? "True" : "False"); |
| 692 | printf("RtaIgnoreRxErrors=%s\n", conf->ignore_rx_errors ? "True" : "False"); |
| 693 | printf("RtaTxTimeStampEnabled=%s\n", conf->tx_hwtstamp_enabled ? "True" : "False"); |
| 694 | printf("RtaVid=%d\n", conf->vid); |
| 695 | printf("RtaPcp=%d\n", conf->pcp); |
| 696 | printf("RtaBurstPeriodNS=%" PRIu64 "\n", conf->burst_period_ns); |
| 697 | printf("RtaNumFramesPerCycle=%zu\n", conf->num_frames_per_cycle); |
| 698 | printf("RtaPayloadPattern="); |
| 699 | print_payload_pattern(conf->payload_pattern, conf->payload_pattern_length); |
| 700 | printf("\n"); |
| 701 | printf("RtaFrameLength=%zu\n", conf->frame_length); |
| 702 | printf("RtaSecurityMode=%s\n", security_mode_to_string(conf->security_mode)); |
| 703 | printf("RtaSecurityAlgorithm=%s\n", security_algorithm_to_string(conf->security_algorithm)); |
| 704 | printf("RtaSecurityKey=%s\n", conf->security_key); |
| 705 | printf("RtaSecurityIvPrefix=%s\n", conf->security_iv_prefix); |
| 706 | printf("RtaRxQueue=%d\n", conf->rx_queue); |
| 707 | printf("RtaTxQueue=%d\n", conf->tx_queue); |
| 708 | printf("RtaSocketPriority=%d\n", conf->socket_priority); |
| 709 | printf("RtaTxThreadPriority=%d\n", conf->tx_thread_priority); |
| 710 | printf("RtaRxThreadPriority=%d\n", conf->rx_thread_priority); |
| 711 | printf("RtaTxThreadCpu=%d\n", conf->tx_thread_cpu); |
| 712 | printf("RtaRxThreadCpu=%d\n", conf->rx_thread_cpu); |
| 713 | printf("RtaInterface=%s\n", conf->interface); |
| 714 | printf("RtaDestination="); |
| 715 | print_mac_address(conf->l2_destination); |
| 716 | printf("\n"); |
| 717 | printf("--------------------------------------------------------------------------------" |
| 718 | "\n"); |
| 719 | |
| 720 | conf = &app_config.classes[DCP_FRAME_TYPE]; |
| 721 | printf("DcpEnabled=%s\n", conf->enabled ? "True" : "False"); |
| 722 | printf("DcpRxMirrorEnabled=%s\n", conf->rx_mirror_enabled ? "True" : "False"); |
| 723 | printf("DcpIgnoreRxErrors=%s\n", conf->ignore_rx_errors ? "True" : "False"); |
| 724 | printf("DcpVid=%d\n", conf->vid); |
| 725 | printf("DcpPcp=%d\n", conf->pcp); |
| 726 | printf("DcpBurstPeriodNS=%" PRIu64 "\n", conf->burst_period_ns); |
| 727 | printf("DcpNumFramesPerCycle=%zu\n", conf->num_frames_per_cycle); |
| 728 | printf("DcpPayloadPattern="); |
| 729 | print_payload_pattern(conf->payload_pattern, conf->payload_pattern_length); |
| 730 | printf("\n"); |
| 731 | printf("DcpFrameLength=%zu\n", conf->frame_length); |
| 732 | printf("DcpRxQueue=%d\n", conf->rx_queue); |
| 733 | printf("DcpTxQueue=%d\n", conf->tx_queue); |
| 734 | printf("DcpSocketPriority=%d\n", conf->socket_priority); |
| 735 | printf("DcpTxThreadPriority=%d\n", conf->tx_thread_priority); |
| 736 | printf("DcpRxThreadPriority=%d\n", conf->rx_thread_priority); |
| 737 | printf("DcpTxThreadCpu=%d\n", conf->tx_thread_cpu); |
| 738 | printf("DcpRxThreadCpu=%d\n", conf->rx_thread_cpu); |
| 739 | printf("DcpInterface=%s\n", conf->interface); |
| 740 | printf("DcpDestination="); |
| 741 | print_mac_address(conf->l2_destination); |
| 742 | printf("\n"); |
| 743 | printf("--------------------------------------------------------------------------------" |
| 744 | "\n"); |
| 745 | |
| 746 | conf = &app_config.classes[LLDP_FRAME_TYPE]; |
| 747 | printf("LldpEnabled=%s\n", conf->enabled ? "True" : "False"); |
| 748 | printf("LldpRxMirrorEnabled=%s\n", conf->rx_mirror_enabled ? "True" : "False"); |
| 749 | printf("LldpIgnoreRxErrors=%s\n", conf->ignore_rx_errors ? "True" : "False"); |
| 750 | printf("LldpBurstPeriodNS=%" PRIu64 "\n", conf->burst_period_ns); |
| 751 | printf("LldpNumFramesPerCycle=%zu\n", conf->num_frames_per_cycle); |
| 752 | printf("LldpPayloadPattern="); |
| 753 | print_payload_pattern(conf->payload_pattern, conf->payload_pattern_length); |
| 754 | printf("\n"); |
| 755 | printf("LldpFrameLength=%zu\n", conf->frame_length); |
| 756 | printf("LldpRxQueue=%d\n", conf->rx_queue); |
| 757 | printf("LldpTxQueue=%d\n", conf->tx_queue); |
| 758 | printf("LldpSocketPriority=%d\n", conf->socket_priority); |
| 759 | printf("LldpTxThreadPriority=%d\n", conf->tx_thread_priority); |
| 760 | printf("LldpRxThreadPriority=%d\n", conf->rx_thread_priority); |
| 761 | printf("LldpTxThreadCpu=%d\n", conf->tx_thread_cpu); |
| 762 | printf("LldpRxThreadCpu=%d\n", conf->rx_thread_cpu); |
| 763 | printf("LldpInterface=%s\n", conf->interface); |
| 764 | printf("LldpDestination="); |
| 765 | print_mac_address(conf->l2_destination); |
| 766 | printf("\n"); |
| 767 | printf("--------------------------------------------------------------------------------" |
| 768 | "\n"); |
| 769 | |
| 770 | conf = &app_config.classes[UDP_HIGH_FRAME_TYPE]; |
| 771 | printf("UdpHighEnabled=%s\n", conf->enabled ? "True" : "False"); |
| 772 | printf("UdpHighRxMirrorEnabled=%s\n", conf->rx_mirror_enabled ? "True" : "False"); |
| 773 | printf("UdpHighIgnoreRxErrors=%s\n", conf->ignore_rx_errors ? "True" : "False"); |
| 774 | printf("UdpHighBurstPeriodNS=%" PRIu64 "\n", conf->burst_period_ns); |
| 775 | printf("UdpHighNumFramesPerCycle=%zu\n", conf->num_frames_per_cycle); |
| 776 | printf("UdpHighPayloadPattern="); |
| 777 | print_payload_pattern(conf->payload_pattern, conf->payload_pattern_length); |
| 778 | printf("\n"); |
| 779 | printf("UdpHighFrameLength=%zu\n", conf->frame_length); |
| 780 | printf("UdpHighRxQueue=%d\n", conf->rx_queue); |
| 781 | printf("UdpHighTxQueue=%d\n", conf->tx_queue); |
| 782 | printf("UdpHighSocketPriority=%d\n", conf->socket_priority); |
| 783 | printf("UdpHighTxThreadPriority=%d\n", conf->tx_thread_priority); |
| 784 | printf("UdpHighRxThreadPriority=%d\n", conf->rx_thread_priority); |
| 785 | printf("UdpHighTxThreadCpu=%d\n", conf->tx_thread_cpu); |
| 786 | printf("UdpHighRxThreadCpu=%d\n", conf->rx_thread_cpu); |
| 787 | printf("UdpHighInterface=%s\n", conf->interface); |
| 788 | printf("UdpHighPort=%s\n", conf->l3_port); |
| 789 | printf("UdpHighDestination=%s\n", conf->l3_destination); |
| 790 | printf("UdpHighSource=%s\n", conf->l3_source); |
| 791 | printf("--------------------------------------------------------------------------------" |
| 792 | "\n"); |
| 793 | |
| 794 | conf = &app_config.classes[UDP_LOW_FRAME_TYPE]; |
| 795 | printf("UdpLowEnabled=%s\n", conf->enabled ? "True" : "False"); |
| 796 | printf("UdpLowRxMirrorEnabled=%s\n", conf->rx_mirror_enabled ? "True" : "False"); |
| 797 | printf("UdpLowIgnoreRxErrors=%s\n", conf->ignore_rx_errors ? "True" : "False"); |
| 798 | printf("UdpLowBurstPeriodNS=%" PRIu64 "\n", conf->burst_period_ns); |
| 799 | printf("UdpLowNumFramesPerCycle=%zu\n", conf->num_frames_per_cycle); |
| 800 | printf("UdpLowPayloadPattern="); |
| 801 | print_payload_pattern(conf->payload_pattern, conf->payload_pattern_length); |
| 802 | printf("\n"); |
| 803 | printf("UdpLowFrameLength=%zu\n", conf->frame_length); |
| 804 | printf("UdpLowRxQueue=%d\n", conf->rx_queue); |
| 805 | printf("UdpLowTxQueue=%d\n", conf->tx_queue); |
| 806 | printf("UdpLowSocketPriority=%d\n", conf->socket_priority); |
| 807 | printf("UdpLowTxThreadPriority=%d\n", conf->tx_thread_priority); |
| 808 | printf("UdpLowRxThreadPriority=%d\n", conf->rx_thread_priority); |
| 809 | printf("UdpLowTxThreadCpu=%d\n", conf->tx_thread_cpu); |
| 810 | printf("UdpLowRxThreadCpu=%d\n", conf->rx_thread_cpu); |
| 811 | printf("UdpLowInterface=%s\n", conf->interface); |
| 812 | printf("UdpLowPort=%s\n", conf->l3_port); |
| 813 | printf("UdpLowDestination=%s\n", conf->l3_destination); |
| 814 | printf("UdpLowSource=%s\n", conf->l3_source); |
| 815 | printf("--------------------------------------------------------------------------------" |
| 816 | "\n"); |
| 817 | |
| 818 | conf = &app_config.classes[GENERICL2_FRAME_TYPE]; |
| 819 | printf("GenericL2Name=%s\n", conf->name); |
| 820 | printf("GenericL2Enabled=%s\n", conf->enabled ? "True" : "False"); |
| 821 | printf("GenericL2RxMirrorEnabled=%s\n", conf->rx_mirror_enabled ? "True" : "False"); |
| 822 | printf("GenericL2XdpEnabled=%s\n", conf->xdp_enabled ? "True" : "False"); |
| 823 | printf("GenericL2XdpSkbMode=%s\n", conf->xdp_skb_mode ? "True" : "False"); |
| 824 | printf("GenericL2XdpZcMode=%s\n", conf->xdp_zc_mode ? "True" : "False"); |
| 825 | printf("GenericL2XdpWakeupMode=%s\n", conf->xdp_wakeup_mode ? "True" : "False"); |
| 826 | printf("GenericL2XdpBusyPollMode=%s\n", conf->xdp_busy_poll_mode ? "True" : "False"); |
| 827 | printf("GenericL2TxTimeEnabled=%s\n", conf->tx_time_enabled ? "True" : "False"); |
| 828 | printf("GenericL2IgnoreRxErrors=%s\n", conf->ignore_rx_errors ? "True" : "False"); |
| 829 | printf("GenericL2TxTimeOffsetNS=%" PRIu64 "\n", conf->tx_time_offset_ns); |
| 830 | printf("GenericL2TxTimeStampEnabled=%s\n", conf->tx_hwtstamp_enabled ? "True" : "False"); |
| 831 | printf("GenericL2Vid=%d\n", conf->vid); |
| 832 | printf("GenericL2Pcp=%d\n", conf->pcp); |
| 833 | printf("GenericL2EtherType=0x%04x\n", conf->ether_type); |
| 834 | printf("GenericL2NumFramesPerCycle=%zu\n", conf->num_frames_per_cycle); |
| 835 | printf("GenericL2PayloadPattern="); |
| 836 | print_payload_pattern(conf->payload_pattern, conf->payload_pattern_length); |
| 837 | printf("\n"); |
| 838 | printf("GenericL2FrameLength=%zu\n", conf->frame_length); |
| 839 | printf("GenericL2RxQueue=%d\n", conf->rx_queue); |
| 840 | printf("GenericL2TxQueue=%d\n", conf->tx_queue); |
| 841 | printf("GenericL2SocketPriority=%d\n", conf->socket_priority); |
| 842 | printf("GenericL2TxThreadPriority=%d\n", conf->tx_thread_priority); |
| 843 | printf("GenericL2RxThreadPriority=%d\n", conf->rx_thread_priority); |
| 844 | printf("GenericL2TxThreadCpu=%d\n", conf->tx_thread_cpu); |
| 845 | printf("GenericL2RxThreadCpu=%d\n", conf->rx_thread_cpu); |
| 846 | printf("GenericL2Interface=%s\n", conf->interface); |
| 847 | printf("GenericL2Destination="); |
| 848 | print_mac_address(conf->l2_destination); |
| 849 | printf("\n"); |
| 850 | printf("--------------------------------------------------------------------------------" |
| 851 | "\n"); |
| 852 | |
| 853 | printf("LogThreadPriority=%d\n", app_config.log_thread_priority); |
| 854 | printf("LogThreadCpu=%d\n", app_config.log_thread_cpu); |
| 855 | printf("LogFile=%s\n", app_config.log_file); |
| 856 | printf("LogLevel=%s\n", app_config.log_level); |
| 857 | printf("--------------------------------------------------------------------------------" |
| 858 | "\n"); |
| 859 | |
| 860 | printf("DebugStopTraceOnOutlier=%s\n", |
| 861 | app_config.debug_stop_trace_on_outlier ? "True" : "False"); |
| 862 | printf("DebugStopTraceOnError=%s\n", |
| 863 | app_config.debug_stop_trace_on_error ? "True" : "False"); |
| 864 | printf("DebugMonitorMode=%s\n", app_config.debug_monitor_mode ? "True" : "False"); |
| 865 | printf("DebugMonitorDestination="); |
| 866 | print_mac_address(app_config.debug_monitor_destination); |
| 867 | printf("\n"); |
| 868 | printf("--------------------------------------------------------------------------------" |
| 869 | "\n"); |
| 870 | |
| 871 | printf("StatsHistogramEnabled=%s\n", app_config.stats_histogram_enabled ? "True" : "False"); |
| 872 | printf("StatsHistogramMinimumNS=%" PRIu64 "\n", app_config.stats_histogram_minimum_ns); |
| 873 | printf("StatsHistogramMaximumNS=%" PRIu64 "\n", app_config.stats_histogram_maximum_ns); |
| 874 | printf("StatsHistogramFile=%s\n", app_config.stats_histogram_file); |
| 875 | printf("StatsCollectionIntervalNS=%" PRIu64 "\n", app_config.stats_collection_interval_ns); |
| 876 | printf("--------------------------------------------------------------------------------" |
| 877 | "\n"); |
| 878 | |
| 879 | printf("LogMqtt=%s\n", app_config.log_mqtt ? "True" : "False"); |
| 880 | printf("LogMqttThreadPriority=%d\n", app_config.log_mqtt_thread_priority); |
| 881 | printf("LogMqttThreadCpu=%d\n", app_config.log_mqtt_thread_cpu); |
| 882 | printf("LogMqttBrokerIP=%s\n", app_config.log_mqtt_broker_ip); |
| 883 | printf("LogMqttBrokerPort=%d\n", app_config.log_mqtt_broker_port); |
| 884 | printf("LogMqttKeepAliveSecs=%d\n", app_config.log_mqtt_keep_alive_secs); |
| 885 | printf("LogMqttMeasurementName=%s\n", app_config.log_mqtt_measurement_name); |
| 886 | printf("--------------------------------------------------------------------------------" |
| 887 | "\n"); |
| 888 | |
| 889 | printf("LogJson=%s\n", app_config.log_json ? "True" : "False"); |
| 890 | printf("LogJsonThreadPriority=%d\n", app_config.log_json_thread_priority); |
| 891 | printf("LogJsonThreadCpu=%d\n", app_config.log_json_thread_cpu); |
| 892 | printf("LogJsonHost=%s\n", app_config.log_json_host); |
| 893 | printf("LogJsonPort=%s\n", app_config.log_json_port); |
| 894 | printf("LogJsonMeasurementName=%s\n", app_config.log_json_measurement_name); |
| 895 | printf("--------------------------------------------------------------------------------" |
| 896 | "\n"); |
| 897 | } |
| 898 | |
| 899 | int config_set_defaults(bool mirror_enabled) |
| 900 | { |
| 901 | static unsigned char default_debug_montitor_destination[] = {0x44, 0x44, 0x44, |
| 902 | 0x44, 0x44, 0x44}; |
| 903 | static unsigned char default_lldp_destination[] = {0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e}; |
| 904 | static unsigned char default_destination[] = {0xa8, 0xa1, 0x59, 0x2c, 0xa8, 0xdb}; |
| 905 | static unsigned char default_dcp_identify[] = {0x01, 0x0e, 0xcf, 0x00, 0x00, 0x00}; |
| 906 | static const char *default_log_mqtt_measurement_name = "reference"; |
| 907 | static const char *default_udp_low_destination = "192.168.2.120"; |
| 908 | static const char *default_log_mqtt_broker_ip = "127.0.0.1"; |
| 909 | static const char *default_udp_low_source = "192.168.2.119"; |
| 910 | static const char *default_payload_pattern = "Payload"; |
| 911 | static const char *default_hist_file = "histogram.txt"; |
| 912 | static const char *default_json_host = "localhost"; |
| 913 | static const char *default_udp_low_port = "6666"; |
| 914 | static const char *default_json_port = "58415"; |
| 915 | static const char *default_log_level = "Debug"; |
| 916 | struct traffic_class_config *conf; |
| 917 | struct timespec current; |
| 918 | int ret = -ENOMEM; |
| 919 | |
| 920 | clock_gettime(CLOCK_TAI, ¤t); |
| 921 | |
| 922 | /* Application scheduling configuration */ |
| 923 | app_config.application_clock_id = CLOCK_TAI; |
| 924 | app_config.application_base_cycle_time_ns = 500000; |
| 925 | app_config.application_base_start_time_ns = (current.tv_sec + 30) * NSEC_PER_SEC; |
| 926 | app_config.application_base_start_offset_ns = 0; |
| 927 | app_config.application_tx_base_offset_ns = 400000; |
| 928 | app_config.application_rx_base_offset_ns = 200000; |
| 929 | app_config.application_xdp_program = NULL; |
| 930 | |
| 931 | /* TSN High */ |
| 932 | conf = &app_config.classes[TSN_HIGH_FRAME_TYPE]; |
| 933 | conf->enabled = false; |
| 934 | conf->rx_mirror_enabled = mirror_enabled; |
| 935 | conf->xdp_enabled = false; |
| 936 | conf->xdp_skb_mode = false; |
| 937 | conf->xdp_zc_mode = false; |
| 938 | conf->xdp_wakeup_mode = true; |
| 939 | conf->xdp_busy_poll_mode = false; |
| 940 | conf->tx_time_enabled = false; |
| 941 | conf->ignore_rx_errors = false; |
| 942 | conf->tx_time_offset_ns = 0; |
| 943 | conf->tx_hwtstamp_enabled = false; |
| 944 | conf->vid = TSN_HIGH_VID_VALUE; |
| 945 | conf->pcp = TSN_HIGH_PCP_VALUE; |
| 946 | conf->num_frames_per_cycle = 0; |
| 947 | conf->payload_pattern = strdup(default_payload_pattern); |
| 948 | if (!conf->payload_pattern) |
| 949 | goto out; |
| 950 | conf->payload_pattern_length = strlen(conf->payload_pattern); |
| 951 | conf->frame_length = 200; |
| 952 | conf->security_mode = SECURITY_MODE_NONE; |
| 953 | conf->security_algorithm = SECURITY_ALGORITHM_AES256_GCM; |
| 954 | conf->security_key = NULL; |
| 955 | conf->security_iv_prefix = NULL; |
| 956 | conf->rx_queue = 1; |
| 957 | conf->tx_queue = 1; |
| 958 | conf->socket_priority = 1; |
| 959 | conf->tx_thread_priority = 98; |
| 960 | conf->rx_thread_priority = 98; |
| 961 | conf->tx_thread_cpu = 0; |
| 962 | conf->rx_thread_cpu = 0; |
| 963 | conf->rx_workload_enabled = false; |
| 964 | conf->rx_workload_prewarm = false; |
| 965 | conf->rx_workload_skip_count = 0; |
| 966 | conf->workload_file = NULL; |
| 967 | conf->workload_function = NULL; |
| 968 | conf->workload_arguments = NULL; |
| 969 | conf->workload_setup_function = NULL; |
| 970 | conf->workload_setup_arguments = NULL; |
| 971 | conf->workload_thread_cpu = 0; |
| 972 | conf->workload_thread_priority = 98; |
| 973 | strncpy(conf->interface, "enp3s0", sizeof(conf->interface) - 1); |
| 974 | memcpy((void *)conf->l2_destination, default_destination, ETH_ALEN); |
| 975 | |
| 976 | /* TSN Low */ |
| 977 | conf = &app_config.classes[TSN_LOW_FRAME_TYPE]; |
| 978 | conf->enabled = false; |
| 979 | conf->rx_mirror_enabled = mirror_enabled; |
| 980 | conf->xdp_enabled = false; |
| 981 | conf->xdp_skb_mode = false; |
| 982 | conf->xdp_zc_mode = false; |
| 983 | conf->xdp_wakeup_mode = true; |
| 984 | conf->xdp_busy_poll_mode = false; |
| 985 | conf->tx_time_enabled = false; |
| 986 | conf->ignore_rx_errors = false; |
| 987 | conf->tx_time_offset_ns = 0; |
| 988 | conf->tx_hwtstamp_enabled = false; |
| 989 | conf->vid = TSN_LOW_VID_VALUE; |
| 990 | conf->pcp = TSN_LOW_PCP_VALUE; |
| 991 | conf->num_frames_per_cycle = 0; |
| 992 | conf->payload_pattern = strdup(default_payload_pattern); |
| 993 | if (!conf->payload_pattern) |
| 994 | goto out; |
| 995 | conf->payload_pattern_length = strlen(conf->payload_pattern); |
| 996 | conf->frame_length = 200; |
| 997 | conf->security_mode = SECURITY_MODE_NONE; |
| 998 | conf->security_algorithm = SECURITY_ALGORITHM_AES256_GCM; |
| 999 | conf->security_key = NULL; |
| 1000 | conf->security_iv_prefix = NULL; |
| 1001 | conf->rx_queue = 1; |
| 1002 | conf->tx_queue = 1; |
| 1003 | conf->socket_priority = 1; |
| 1004 | conf->tx_thread_priority = 98; |
| 1005 | conf->rx_thread_priority = 98; |
| 1006 | conf->tx_thread_cpu = 0; |
| 1007 | conf->rx_thread_cpu = 0; |
| 1008 | strncpy(conf->interface, "enp3s0", sizeof(conf->interface) - 1); |
| 1009 | memcpy((void *)conf->l2_destination, default_destination, ETH_ALEN); |
| 1010 | |
| 1011 | /* Real Time Cyclic (RTC) */ |
| 1012 | conf = &app_config.classes[RTC_FRAME_TYPE]; |
| 1013 | conf->enabled = false; |
| 1014 | conf->rx_mirror_enabled = mirror_enabled; |
| 1015 | conf->xdp_enabled = false; |
| 1016 | conf->xdp_skb_mode = false; |
| 1017 | conf->xdp_zc_mode = false; |
| 1018 | conf->xdp_wakeup_mode = true; |
| 1019 | conf->xdp_busy_poll_mode = false; |
| 1020 | conf->ignore_rx_errors = false; |
| 1021 | conf->tx_hwtstamp_enabled = false; |
| 1022 | conf->vid = PROFINET_RT_VID_VALUE; |
| 1023 | conf->pcp = RTC_PCP_VALUE; |
| 1024 | conf->num_frames_per_cycle = 0; |
| 1025 | conf->payload_pattern = strdup(default_payload_pattern); |
| 1026 | if (!conf->payload_pattern) |
| 1027 | goto out; |
| 1028 | conf->payload_pattern_length = strlen(conf->payload_pattern); |
| 1029 | conf->frame_length = 200; |
| 1030 | conf->security_mode = SECURITY_MODE_NONE; |
| 1031 | conf->security_algorithm = SECURITY_ALGORITHM_AES256_GCM; |
| 1032 | conf->security_key = NULL; |
| 1033 | conf->security_iv_prefix = NULL; |
| 1034 | conf->rx_queue = 1; |
| 1035 | conf->tx_queue = 1; |
| 1036 | conf->socket_priority = 1; |
| 1037 | conf->tx_thread_priority = 98; |
| 1038 | conf->rx_thread_priority = 98; |
| 1039 | conf->tx_thread_cpu = 0; |
| 1040 | conf->rx_thread_cpu = 0; |
| 1041 | strncpy(conf->interface, "enp3s0", sizeof(conf->interface) - 1); |
| 1042 | memcpy((void *)conf->l2_destination, default_destination, ETH_ALEN); |
| 1043 | |
| 1044 | /* Real Time Acyclic (RTA) */ |
| 1045 | conf = &app_config.classes[RTA_FRAME_TYPE]; |
| 1046 | conf->enabled = false; |
| 1047 | conf->rx_mirror_enabled = mirror_enabled; |
| 1048 | conf->xdp_enabled = false; |
| 1049 | conf->xdp_skb_mode = false; |
| 1050 | conf->xdp_zc_mode = false; |
| 1051 | conf->xdp_wakeup_mode = true; |
| 1052 | conf->xdp_busy_poll_mode = false; |
| 1053 | conf->ignore_rx_errors = false; |
| 1054 | conf->tx_hwtstamp_enabled = false; |
| 1055 | conf->vid = PROFINET_RT_VID_VALUE; |
| 1056 | conf->pcp = RTA_PCP_VALUE; |
| 1057 | conf->burst_period_ns = 200000000; |
| 1058 | conf->num_frames_per_cycle = 0; |
| 1059 | conf->payload_pattern = strdup(default_payload_pattern); |
| 1060 | if (!conf->payload_pattern) |
| 1061 | goto out; |
| 1062 | conf->payload_pattern_length = strlen(conf->payload_pattern); |
| 1063 | conf->frame_length = 200; |
| 1064 | conf->security_mode = SECURITY_MODE_NONE; |
| 1065 | conf->security_algorithm = SECURITY_ALGORITHM_AES256_GCM; |
| 1066 | conf->security_key = NULL; |
| 1067 | conf->security_iv_prefix = NULL; |
| 1068 | conf->rx_queue = 1; |
| 1069 | conf->tx_queue = 1; |
| 1070 | conf->socket_priority = 1; |
| 1071 | conf->tx_thread_priority = 98; |
| 1072 | conf->rx_thread_priority = 98; |
| 1073 | conf->tx_thread_cpu = 0; |
| 1074 | conf->rx_thread_cpu = 0; |
| 1075 | strncpy(conf->interface, "enp3s0", sizeof(conf->interface) - 1); |
| 1076 | memcpy((void *)conf->l2_destination, default_destination, ETH_ALEN); |
| 1077 | |
| 1078 | /* Discovery and Configuration Protocol (DCP) */ |
| 1079 | conf = &app_config.classes[DCP_FRAME_TYPE]; |
| 1080 | conf->enabled = false; |
| 1081 | conf->ignore_rx_errors = false; |
| 1082 | conf->rx_mirror_enabled = mirror_enabled; |
| 1083 | conf->vid = PROFINET_RT_VID_VALUE; |
| 1084 | conf->pcp = DCP_PCP_VALUE; |
| 1085 | conf->burst_period_ns = 2000000000; |
| 1086 | conf->num_frames_per_cycle = 0; |
| 1087 | conf->payload_pattern = strdup(default_payload_pattern); |
| 1088 | if (!conf->payload_pattern) |
| 1089 | goto out; |
| 1090 | conf->payload_pattern_length = strlen(conf->payload_pattern); |
| 1091 | conf->frame_length = 200; |
| 1092 | conf->rx_queue = 1; |
| 1093 | conf->tx_queue = 1; |
| 1094 | conf->socket_priority = 1; |
| 1095 | conf->tx_thread_priority = 98; |
| 1096 | conf->rx_thread_priority = 98; |
| 1097 | conf->tx_thread_cpu = 3; |
| 1098 | conf->rx_thread_cpu = 3; |
| 1099 | strncpy(conf->interface, "enp3s0", sizeof(conf->interface) - 1); |
| 1100 | memcpy((void *)conf->l2_destination, default_dcp_identify, ETH_ALEN); |
| 1101 | |
| 1102 | /* Link Layer Discovery Protocol (LLDP) */ |
| 1103 | conf = &app_config.classes[LLDP_FRAME_TYPE]; |
| 1104 | conf->enabled = false; |
| 1105 | conf->ignore_rx_errors = false; |
| 1106 | conf->rx_mirror_enabled = mirror_enabled; |
| 1107 | conf->burst_period_ns = 5000000000; |
| 1108 | conf->num_frames_per_cycle = 0; |
| 1109 | conf->payload_pattern = strdup(default_payload_pattern); |
| 1110 | if (!conf->payload_pattern) |
| 1111 | goto out; |
| 1112 | conf->payload_pattern_length = strlen(conf->payload_pattern); |
| 1113 | conf->frame_length = 200; |
| 1114 | conf->rx_queue = 1; |
| 1115 | conf->tx_queue = 1; |
| 1116 | conf->socket_priority = 1; |
| 1117 | conf->tx_thread_priority = 98; |
| 1118 | conf->rx_thread_priority = 98; |
| 1119 | conf->tx_thread_cpu = 4; |
| 1120 | conf->rx_thread_cpu = 4; |
| 1121 | strncpy(conf->interface, "enp3s0", sizeof(conf->interface) - 1); |
| 1122 | memcpy((void *)conf->l2_destination, default_lldp_destination, ETH_ALEN); |
| 1123 | |
| 1124 | /* User Datagram Protocol (UDP) High */ |
| 1125 | conf = &app_config.classes[UDP_HIGH_FRAME_TYPE]; |
| 1126 | conf->enabled = false; |
| 1127 | conf->ignore_rx_errors = false; |
| 1128 | conf->rx_mirror_enabled = mirror_enabled; |
| 1129 | conf->burst_period_ns = 1000000000; |
| 1130 | conf->num_frames_per_cycle = 0; |
| 1131 | conf->payload_pattern = strdup(default_payload_pattern); |
| 1132 | if (!conf->payload_pattern) |
| 1133 | goto out; |
| 1134 | conf->payload_pattern_length = strlen(conf->payload_pattern); |
| 1135 | conf->frame_length = 1400; |
| 1136 | conf->rx_queue = 0; |
| 1137 | conf->tx_queue = 0; |
| 1138 | conf->socket_priority = 0; |
| 1139 | conf->tx_thread_priority = 98; |
| 1140 | conf->rx_thread_priority = 98; |
| 1141 | conf->tx_thread_cpu = 5; |
| 1142 | conf->rx_thread_cpu = 5; |
| 1143 | strncpy(conf->interface, "enp3s0", sizeof(conf->interface) - 1); |
| 1144 | conf->l3_port = strdup(default_udp_low_port); |
| 1145 | if (!conf->l3_port) |
| 1146 | goto out; |
| 1147 | conf->l3_destination = strdup(default_udp_low_destination); |
| 1148 | if (!conf->l3_destination) |
| 1149 | goto out; |
| 1150 | conf->l3_source = strdup(default_udp_low_source); |
| 1151 | if (!conf->l3_source) |
| 1152 | goto out; |
| 1153 | |
| 1154 | /* User Datagram Protocol (UDP) Low */ |
| 1155 | conf = &app_config.classes[UDP_LOW_FRAME_TYPE]; |
| 1156 | conf->enabled = false; |
| 1157 | conf->ignore_rx_errors = false; |
| 1158 | conf->rx_mirror_enabled = mirror_enabled; |
| 1159 | conf->burst_period_ns = 1000000000; |
| 1160 | conf->num_frames_per_cycle = 0; |
| 1161 | conf->payload_pattern = strdup(default_payload_pattern); |
| 1162 | if (!conf->payload_pattern) |
| 1163 | goto out; |
| 1164 | conf->payload_pattern_length = strlen(conf->payload_pattern); |
| 1165 | conf->frame_length = 1400; |
| 1166 | conf->rx_queue = 0; |
| 1167 | conf->tx_queue = 0; |
| 1168 | conf->socket_priority = 0; |
| 1169 | conf->tx_thread_priority = 98; |
| 1170 | conf->rx_thread_priority = 98; |
| 1171 | conf->tx_thread_cpu = 5; |
| 1172 | conf->rx_thread_cpu = 5; |
| 1173 | strncpy(conf->interface, "enp3s0", sizeof(conf->interface) - 1); |
| 1174 | conf->l3_port = strdup(default_udp_low_port); |
| 1175 | if (!conf->l3_port) |
| 1176 | goto out; |
| 1177 | conf->l3_destination = strdup(default_udp_low_destination); |
| 1178 | if (!conf->l3_destination) |
| 1179 | goto out; |
| 1180 | conf->l3_source = strdup(default_udp_low_source); |
| 1181 | if (!conf->l3_source) |
| 1182 | goto out; |
| 1183 | |
| 1184 | /* Generic L2 */ |
| 1185 | conf = &app_config.classes[GENERICL2_FRAME_TYPE]; |
| 1186 | conf->name = strdup("GenericL2"); |
| 1187 | if (!conf->name) |
| 1188 | goto out; |
| 1189 | conf->enabled = false; |
| 1190 | conf->rx_mirror_enabled = mirror_enabled; |
| 1191 | conf->xdp_enabled = false; |
| 1192 | conf->xdp_skb_mode = false; |
| 1193 | conf->xdp_zc_mode = false; |
| 1194 | conf->xdp_wakeup_mode = true; |
| 1195 | conf->xdp_busy_poll_mode = false; |
| 1196 | conf->tx_time_enabled = false; |
| 1197 | conf->ignore_rx_errors = false; |
| 1198 | conf->tx_time_offset_ns = 0; |
| 1199 | conf->tx_hwtstamp_enabled = false; |
| 1200 | conf->vid = 100; |
| 1201 | conf->pcp = 6; |
| 1202 | conf->ether_type = 0xb62c; |
| 1203 | conf->num_frames_per_cycle = 0; |
| 1204 | conf->payload_pattern = strdup(default_payload_pattern); |
| 1205 | if (!conf->payload_pattern) |
| 1206 | goto out; |
| 1207 | conf->payload_pattern_length = strlen(conf->payload_pattern); |
| 1208 | conf->frame_length = 200; |
| 1209 | conf->rx_queue = 1; |
| 1210 | conf->tx_queue = 1; |
| 1211 | conf->socket_priority = 1; |
| 1212 | conf->tx_thread_priority = 90; |
| 1213 | conf->rx_thread_priority = 90; |
| 1214 | conf->tx_thread_cpu = 0; |
| 1215 | conf->rx_thread_cpu = 0; |
| 1216 | strncpy(conf->interface, "enp3s0", sizeof(conf->interface) - 1); |
| 1217 | memcpy((void *)conf->l2_destination, default_destination, ETH_ALEN); |
| 1218 | |
| 1219 | /* Logging */ |
| 1220 | app_config.log_thread_priority = 1; |
| 1221 | app_config.log_thread_cpu = 7; |
| 1222 | app_config.log_file = strdup("reference.log"); |
| 1223 | if (!app_config.log_file) |
| 1224 | goto out; |
| 1225 | app_config.log_level = strdup(default_log_level); |
| 1226 | if (!app_config.log_level) |
| 1227 | goto out; |
| 1228 | |
| 1229 | /* Debug */ |
| 1230 | app_config.debug_stop_trace_on_outlier = false; |
| 1231 | app_config.debug_stop_trace_on_error = false; |
| 1232 | app_config.debug_monitor_mode = false; |
| 1233 | memcpy((void *)app_config.debug_monitor_destination, default_debug_montitor_destination, |
| 1234 | ETH_ALEN); |
| 1235 | |
| 1236 | /* Stats */ |
| 1237 | app_config.stats_histogram_enabled = false; |
| 1238 | app_config.stats_histogram_minimum_ns = 1 * 1e6; |
| 1239 | app_config.stats_histogram_maximum_ns = 10 * 1e6; |
| 1240 | app_config.stats_histogram_file = strdup(default_hist_file); |
| 1241 | if (!app_config.stats_histogram_file) |
| 1242 | goto out; |
| 1243 | app_config.stats_histogram_file_length = strlen(default_hist_file); |
| 1244 | app_config.stats_collection_interval_ns = 1e9; |
| 1245 | |
| 1246 | /* LogMqtt */ |
| 1247 | app_config.log_mqtt = false; |
| 1248 | app_config.log_mqtt_broker_port = 1883; |
| 1249 | app_config.log_mqtt_thread_priority = 1; |
| 1250 | app_config.log_mqtt_thread_cpu = 7; |
| 1251 | app_config.log_mqtt_keep_alive_secs = 60; |
| 1252 | app_config.log_mqtt_broker_ip = strdup(default_log_mqtt_broker_ip); |
| 1253 | if (!app_config.log_mqtt_broker_ip) |
| 1254 | goto out; |
| 1255 | app_config.log_mqtt_measurement_name = strdup(default_log_mqtt_measurement_name); |
| 1256 | if (!app_config.log_mqtt_measurement_name) |
| 1257 | goto out; |
| 1258 | |
| 1259 | app_config.log_json = false; |
| 1260 | app_config.log_json_thread_cpu = 0; |
| 1261 | app_config.log_json_thread_priority = 1; |
| 1262 | app_config.log_json_host = strdup(default_json_host); |
| 1263 | if (!app_config.log_json_host) |
| 1264 | goto out; |
| 1265 | app_config.log_json_port = strdup(default_json_port); |
| 1266 | if (!app_config.log_json_port) |
| 1267 | goto out; |
| 1268 | app_config.log_json_measurement_name = strdup(default_log_mqtt_measurement_name); |
| 1269 | if (!app_config.log_json_measurement_name) |
| 1270 | goto out; |
| 1271 | |
| 1272 | return 0; |
| 1273 | out: |
| 1274 | config_free(); |
| 1275 | return ret; |
| 1276 | } |
| 1277 | |
| 1278 | static bool config_check_keys(const char *traffic_class, enum security_mode mode, |
| 1279 | enum security_algorithm algorithm, size_t key_len, |
| 1280 | size_t iv_prefix_len) |
| 1281 | { |
| 1282 | const size_t expected_key_len = algorithm == SECURITY_ALGORITHM_AES128_GCM ? 16 : 32; |
| 1283 | |
| 1284 | if (mode == SECURITY_MODE_NONE) |
| 1285 | return true; |
| 1286 | |
| 1287 | if (iv_prefix_len != SECURITY_IV_PREFIX_LEN) { |
| 1288 | fprintf(stderr, "%s IV prefix length should be %d!\n", traffic_class, |
| 1289 | SECURITY_IV_PREFIX_LEN); |
| 1290 | return false; |
| 1291 | } |
| 1292 | |
| 1293 | if (expected_key_len != key_len) { |
| 1294 | fprintf(stderr, "%s key length mismatch!. Have %zu expected %zu for %s!\n", |
| 1295 | traffic_class, key_len, expected_key_len, |
| 1296 | security_algorithm_to_string(algorithm)); |
| 1297 | return false; |
| 1298 | } |
| 1299 | |
| 1300 | return true; |
| 1301 | } |
| 1302 | |
| 1303 | /* |
| 1304 | * Perform configuration sanity checks. This includes: |
| 1305 | * - Traffic classes |
| 1306 | * - Frame lengths |
| 1307 | * - Limitations |
| 1308 | */ |
| 1309 | bool config_sanity_check(void) |
| 1310 | { |
| 1311 | const size_t min_secure_profinet_frame_size = sizeof(struct vlan_ethernet_header) + |
| 1312 | sizeof(struct profinet_secure_header) + |
| 1313 | sizeof(struct security_checksum); |
| 1314 | const size_t min_profinet_frame_size = |
| 1315 | sizeof(struct vlan_ethernet_header) + sizeof(struct profinet_rt_header); |
| 1316 | size_t min_frame_size; |
| 1317 | |
| 1318 | /* Either GenericL2 or PROFINET should be active. */ |
| 1319 | if (config_is_traffic_class_active("GenericL2") && |
| 1320 | (config_is_traffic_class_active("TsnHigh") || |
| 1321 | config_is_traffic_class_active("TsnLow") || config_is_traffic_class_active("Rtc") || |
| 1322 | config_is_traffic_class_active("Rta") || config_is_traffic_class_active("Dcp") || |
| 1323 | config_is_traffic_class_active("Lldp") || config_is_traffic_class_active("UdpHigh") || |
| 1324 | config_is_traffic_class_active("UdpLow"))) { |
| 1325 | fprintf(stderr, "Either use PROFINET or GenericL2!\n"); |
| 1326 | fprintf(stderr, "For simulation of PROFINET and other middlewares in parallel " |
| 1327 | "start multiple instances of ref&mirror application(s) with " |
| 1328 | "different profiles!\n"); |
| 1329 | return false; |
| 1330 | } |
| 1331 | |
| 1332 | /* Tx and Rx offset should be <= cycle time */ |
| 1333 | if (app_config.application_rx_base_offset_ns > app_config.application_base_cycle_time_ns || |
| 1334 | app_config.application_tx_base_offset_ns > app_config.application_base_cycle_time_ns) { |
| 1335 | fprintf(stderr, "Application(Tx|Rx)BaseOffsetNS should be less than " |
| 1336 | "ApplicationBaseCycleTimeNS!\n"); |
| 1337 | return false; |
| 1338 | } |
| 1339 | |
| 1340 | /* Frame lengths */ |
| 1341 | if (app_config.classes[GENERICL2_FRAME_TYPE].frame_length > MAX_FRAME_SIZE || |
| 1342 | app_config.classes[GENERICL2_FRAME_TYPE].frame_length < |
| 1343 | (sizeof(struct vlan_ethernet_header) + sizeof(struct generic_l2_header) + |
| 1344 | app_config.classes[GENERICL2_FRAME_TYPE].payload_pattern_length)) { |
| 1345 | fprintf(stderr, "GenericL2FrameLength is invalid!\n"); |
| 1346 | return false; |
| 1347 | } |
| 1348 | |
| 1349 | min_frame_size = app_config.classes[TSN_HIGH_FRAME_TYPE].security_mode == SECURITY_MODE_NONE |
| 1350 | ? min_profinet_frame_size |
| 1351 | : min_secure_profinet_frame_size; |
| 1352 | if (app_config.classes[TSN_HIGH_FRAME_TYPE].frame_length > MAX_FRAME_SIZE || |
| 1353 | app_config.classes[TSN_HIGH_FRAME_TYPE].frame_length < |
| 1354 | (min_frame_size + |
| 1355 | app_config.classes[TSN_HIGH_FRAME_TYPE].payload_pattern_length)) { |
| 1356 | fprintf(stderr, "TsnHighFrameLength is invalid!\n"); |
| 1357 | return false; |
| 1358 | } |
| 1359 | |
| 1360 | min_frame_size = app_config.classes[TSN_LOW_FRAME_TYPE].security_mode == SECURITY_MODE_NONE |
| 1361 | ? min_profinet_frame_size |
| 1362 | : min_secure_profinet_frame_size; |
| 1363 | if (app_config.classes[TSN_LOW_FRAME_TYPE].frame_length > MAX_FRAME_SIZE || |
| 1364 | app_config.classes[TSN_LOW_FRAME_TYPE].frame_length < |
| 1365 | (min_frame_size + |
| 1366 | app_config.classes[TSN_LOW_FRAME_TYPE].payload_pattern_length)) { |
| 1367 | fprintf(stderr, "TsnLowFrameLength is invalid!\n"); |
| 1368 | return false; |
| 1369 | } |
| 1370 | |
| 1371 | min_frame_size = app_config.classes[RTC_FRAME_TYPE].security_mode == SECURITY_MODE_NONE |
| 1372 | ? min_profinet_frame_size |
| 1373 | : min_secure_profinet_frame_size; |
| 1374 | if (app_config.classes[RTC_FRAME_TYPE].frame_length > MAX_FRAME_SIZE || |
| 1375 | app_config.classes[RTC_FRAME_TYPE].frame_length < |
| 1376 | (min_frame_size + app_config.classes[RTC_FRAME_TYPE].payload_pattern_length)) { |
| 1377 | fprintf(stderr, "RtcFrameLength is invalid!\n"); |
| 1378 | return false; |
| 1379 | } |
| 1380 | |
| 1381 | min_frame_size = app_config.classes[RTA_FRAME_TYPE].security_mode == SECURITY_MODE_NONE |
| 1382 | ? min_profinet_frame_size |
| 1383 | : min_secure_profinet_frame_size; |
| 1384 | if (app_config.classes[RTA_FRAME_TYPE].frame_length > MAX_FRAME_SIZE || |
| 1385 | app_config.classes[RTA_FRAME_TYPE].frame_length < |
| 1386 | (min_frame_size + app_config.classes[RTA_FRAME_TYPE].payload_pattern_length)) { |
| 1387 | fprintf(stderr, "RtaFrameLength is invalid!\n"); |
| 1388 | return false; |
| 1389 | } |
| 1390 | |
| 1391 | if (app_config.classes[DCP_FRAME_TYPE].frame_length > MAX_FRAME_SIZE || |
| 1392 | app_config.classes[DCP_FRAME_TYPE].frame_length < |
| 1393 | (min_profinet_frame_size + |
| 1394 | app_config.classes[DCP_FRAME_TYPE].payload_pattern_length)) { |
| 1395 | fprintf(stderr, "DcpFrameLength is invalid!\n"); |
| 1396 | return false; |
| 1397 | } |
| 1398 | |
| 1399 | if (app_config.classes[LLDP_FRAME_TYPE].frame_length > MAX_FRAME_SIZE || |
| 1400 | app_config.classes[LLDP_FRAME_TYPE].frame_length < |
| 1401 | (sizeof(struct ethhdr) + sizeof(struct reference_meta_data) + |
| 1402 | app_config.classes[LLDP_FRAME_TYPE].payload_pattern_length)) { |
| 1403 | fprintf(stderr, "LldpFrameLength is invalid!\n"); |
| 1404 | return false; |
| 1405 | } |
| 1406 | |
| 1407 | if (app_config.classes[UDP_HIGH_FRAME_TYPE].frame_length > MAX_FRAME_SIZE || |
| 1408 | app_config.classes[UDP_HIGH_FRAME_TYPE].frame_length < |
| 1409 | (sizeof(struct reference_meta_data) + |
| 1410 | app_config.classes[UDP_HIGH_FRAME_TYPE].payload_pattern_length)) { |
| 1411 | fprintf(stderr, "UdpHighFrameLength is invalid!\n"); |
| 1412 | return false; |
| 1413 | } |
| 1414 | |
| 1415 | if (app_config.classes[UDP_LOW_FRAME_TYPE].frame_length > MAX_FRAME_SIZE || |
| 1416 | app_config.classes[UDP_LOW_FRAME_TYPE].frame_length < |
| 1417 | (sizeof(struct reference_meta_data) + |
| 1418 | app_config.classes[UDP_LOW_FRAME_TYPE].payload_pattern_length)) { |
| 1419 | fprintf(stderr, "UdpLowFrameLength is invalid!\n"); |
| 1420 | return false; |
| 1421 | } |
| 1422 | |
| 1423 | /* XDP and TxLauchTime combined doesn't work */ |
| 1424 | if (!config_have_xdp_tx_time() && |
| 1425 | ((app_config.classes[GENERICL2_FRAME_TYPE].tx_time_enabled && |
| 1426 | app_config.classes[GENERICL2_FRAME_TYPE].xdp_enabled) || |
| 1427 | (app_config.classes[TSN_HIGH_FRAME_TYPE].tx_time_enabled && |
| 1428 | app_config.classes[TSN_HIGH_FRAME_TYPE].xdp_enabled) || |
| 1429 | (app_config.classes[TSN_LOW_FRAME_TYPE].tx_time_enabled && |
| 1430 | app_config.classes[TSN_LOW_FRAME_TYPE].xdp_enabled))) { |
| 1431 | fprintf(stderr, |
| 1432 | "TxTime and XDP cannot be used at the same time on this platform!\n"); |
| 1433 | fprintf(stderr, "Update libxdp to >= v1.5.0 support it.\n"); |
| 1434 | return false; |
| 1435 | } |
| 1436 | |
| 1437 | if (!config_have_tx_timestamp() && |
| 1438 | ((app_config.classes[GENERICL2_FRAME_TYPE].tx_hwtstamp_enabled && |
| 1439 | app_config.classes[GENERICL2_FRAME_TYPE].xdp_enabled) || |
| 1440 | (app_config.classes[RTC_FRAME_TYPE].tx_hwtstamp_enabled && |
| 1441 | app_config.classes[RTC_FRAME_TYPE].xdp_enabled) || |
| 1442 | (app_config.classes[RTA_FRAME_TYPE].tx_hwtstamp_enabled && |
| 1443 | app_config.classes[RTA_FRAME_TYPE].xdp_enabled) || |
| 1444 | (app_config.classes[TSN_HIGH_FRAME_TYPE].tx_hwtstamp_enabled && |
| 1445 | app_config.classes[TSN_HIGH_FRAME_TYPE].xdp_enabled) || |
| 1446 | (app_config.classes[TSN_LOW_FRAME_TYPE].tx_hwtstamp_enabled && |
| 1447 | app_config.classes[TSN_LOW_FRAME_TYPE].xdp_enabled))) { |
| 1448 | fprintf(stderr, "XDP Tx HW Timestamp requires TX_TIMESTAMP build support!\n"); |
| 1449 | fprintf(stderr, "Rebuild with -DTX_TIMESTAMP=ON (requires libxdp >= v1.4.1 and " |
| 1450 | "Linux kernel >= v6.8).\n"); |
| 1451 | return false; |
| 1452 | } |
| 1453 | |
| 1454 | /* XDP busy polling only works beginning with Linux kernel version v5.11 */ |
| 1455 | if (!config_have_busy_poll() && |
| 1456 | (app_config.classes[TSN_HIGH_FRAME_TYPE].xdp_busy_poll_mode || |
| 1457 | app_config.classes[TSN_LOW_FRAME_TYPE].xdp_busy_poll_mode || |
| 1458 | app_config.classes[RTC_FRAME_TYPE].xdp_busy_poll_mode || |
| 1459 | app_config.classes[RTA_FRAME_TYPE].xdp_busy_poll_mode || |
| 1460 | app_config.classes[GENERICL2_FRAME_TYPE].xdp_busy_poll_mode)) { |
| 1461 | fprintf(stderr, "XDP busy polling selected, but not supported!\n"); |
| 1462 | return false; |
| 1463 | } |
| 1464 | |
| 1465 | if (!config_have_mosquitto() && app_config.log_mqtt) { |
| 1466 | fprintf(stderr, "Log via Mosquito enabled, but not supported!\n"); |
| 1467 | return false; |
| 1468 | } |
| 1469 | |
| 1470 | /* Check keys and IV */ |
| 1471 | if (!config_check_keys("TsnHigh", app_config.classes[TSN_HIGH_FRAME_TYPE].security_mode, |
| 1472 | app_config.classes[TSN_HIGH_FRAME_TYPE].security_algorithm, |
| 1473 | app_config.classes[TSN_HIGH_FRAME_TYPE].security_key_length, |
| 1474 | app_config.classes[TSN_HIGH_FRAME_TYPE].security_iv_prefix_length)) |
| 1475 | return false; |
| 1476 | if (!config_check_keys("TsnLow", app_config.classes[TSN_LOW_FRAME_TYPE].security_mode, |
| 1477 | app_config.classes[TSN_LOW_FRAME_TYPE].security_algorithm, |
| 1478 | app_config.classes[TSN_LOW_FRAME_TYPE].security_key_length, |
| 1479 | app_config.classes[TSN_LOW_FRAME_TYPE].security_iv_prefix_length)) |
| 1480 | return false; |
| 1481 | if (!config_check_keys("Rtc", app_config.classes[RTC_FRAME_TYPE].security_mode, |
| 1482 | app_config.classes[RTC_FRAME_TYPE].security_algorithm, |
| 1483 | app_config.classes[RTC_FRAME_TYPE].security_key_length, |
| 1484 | app_config.classes[RTC_FRAME_TYPE].security_iv_prefix_length)) |
| 1485 | return false; |
| 1486 | if (!config_check_keys("Rta", app_config.classes[RTA_FRAME_TYPE].security_mode, |
| 1487 | app_config.classes[RTA_FRAME_TYPE].security_algorithm, |
| 1488 | app_config.classes[RTA_FRAME_TYPE].security_key_length, |
| 1489 | app_config.classes[RTA_FRAME_TYPE].security_iv_prefix_length)) |
| 1490 | return false; |
| 1491 | |
| 1492 | /* Stats */ |
| 1493 | if (app_config.stats_histogram_minimum_ns > app_config.stats_histogram_maximum_ns) { |
| 1494 | fprintf(stderr, "Histogram minimum and maximum values are invalid!\n"); |
| 1495 | return false; |
| 1496 | } |
| 1497 | |
| 1498 | return true; |
| 1499 | } |
| 1500 | |
| 1501 | void config_free(void) |
| 1502 | { |
| 1503 | free(app_config.application_xdp_program); |
| 1504 | |
| 1505 | free(app_config.classes[TSN_HIGH_FRAME_TYPE].payload_pattern); |
| 1506 | free(app_config.classes[TSN_HIGH_FRAME_TYPE].security_key); |
| 1507 | free(app_config.classes[TSN_HIGH_FRAME_TYPE].security_iv_prefix); |
| 1508 | |
| 1509 | free(app_config.classes[TSN_LOW_FRAME_TYPE].payload_pattern); |
| 1510 | free(app_config.classes[TSN_LOW_FRAME_TYPE].security_key); |
| 1511 | free(app_config.classes[TSN_LOW_FRAME_TYPE].security_iv_prefix); |
| 1512 | |
| 1513 | free(app_config.classes[RTC_FRAME_TYPE].payload_pattern); |
| 1514 | free(app_config.classes[RTC_FRAME_TYPE].security_key); |
| 1515 | free(app_config.classes[RTC_FRAME_TYPE].security_iv_prefix); |
| 1516 | |
| 1517 | free(app_config.classes[RTA_FRAME_TYPE].payload_pattern); |
| 1518 | free(app_config.classes[RTA_FRAME_TYPE].security_key); |
| 1519 | free(app_config.classes[RTA_FRAME_TYPE].security_iv_prefix); |
| 1520 | |
| 1521 | free(app_config.classes[DCP_FRAME_TYPE].payload_pattern); |
| 1522 | |
| 1523 | free(app_config.classes[LLDP_FRAME_TYPE].payload_pattern); |
| 1524 | |
| 1525 | free(app_config.classes[UDP_HIGH_FRAME_TYPE].payload_pattern); |
| 1526 | free(app_config.classes[UDP_HIGH_FRAME_TYPE].l3_port); |
| 1527 | free(app_config.classes[UDP_HIGH_FRAME_TYPE].l3_destination); |
| 1528 | free(app_config.classes[UDP_HIGH_FRAME_TYPE].l3_source); |
| 1529 | |
| 1530 | free(app_config.classes[UDP_LOW_FRAME_TYPE].payload_pattern); |
| 1531 | free(app_config.classes[UDP_LOW_FRAME_TYPE].l3_port); |
| 1532 | free(app_config.classes[UDP_LOW_FRAME_TYPE].l3_destination); |
| 1533 | free(app_config.classes[UDP_LOW_FRAME_TYPE].l3_source); |
| 1534 | |
| 1535 | free(app_config.classes[GENERICL2_FRAME_TYPE].name); |
| 1536 | free(app_config.classes[GENERICL2_FRAME_TYPE].payload_pattern); |
| 1537 | |
| 1538 | free(app_config.stats_histogram_file); |
| 1539 | |
| 1540 | free(app_config.log_file); |
| 1541 | free(app_config.log_level); |
| 1542 | |
| 1543 | free(app_config.log_mqtt_broker_ip); |
| 1544 | free(app_config.log_mqtt_measurement_name); |
| 1545 | |
| 1546 | free(app_config.log_json_host); |
| 1547 | free(app_config.log_json_port); |
| 1548 | free(app_config.log_json_measurement_name); |
| 1549 | } |