#include "general-utilities.h"
#include "debug.h"
-#include <arpa/inet.h>
-#include <string.h>
+#include <arpa/inet.h> // ntohl etc.
+#include <string.h> // memcpy
void hcton64(uint64_t num, uint8_t *p) {
uint64_t numc = num;
// specialised stuff should go in the nqptp-utilities
#include <inttypes.h>
+#include <sys/socket.h>
#include <time.h>
// struct sockaddr_in6 is bigger than struct sockaddr. derp
#include "nqptp-clock-sources.h"
#include "debug.h"
-#include "nqptp-ptp-definitions.h"
#include "general-utilities.h"
+#include "nqptp-ptp-definitions.h"
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <string.h>
int best_so_far = -1;
int timing_peer_count = 0;
- uint32_t acceptance_mask = (1 << clock_is_qualified) | (1 << clock_is_a_timing_peer) | (1 << clock_is_valid);
+ uint32_t acceptance_mask =
+ (1 << clock_is_qualified) | (1 << clock_is_a_timing_peer) | (1 << clock_is_valid);
for (i = 0; i < MAX_CLOCKS; i++) {
if ((clocks_private[i].flags & acceptance_mask) == acceptance_mask) {
// found a possible clock candidate
debug(2, "No timing peer list found");
else
debug(1, "No master clock not found!");
- } else {
- // we found a master clock
- clocks_private[best_so_far].flags |= (1 << clock_is_master);
+ } else {
+ // we found a master clock
+ clocks_private[best_so_far].flags |= (1 << clock_is_master);
- if (old_master != best_so_far) {
+ if (old_master != best_so_far) {
// clang-format off
// Now we use the last few samples to calculate the best offset for the
// new master clock.
clocks_private[best_so_far].mastership_start_time);
// clang-format on
- clocks_private[best_so_far].previous_offset_time = 0; // resync
+ clocks_private[best_so_far].previous_offset_time = 0; // resync
}
}
// 8 samples per seconds
#define MAX_TIMING_SAMPLES 47
- typedef struct {
- uint64_t local_time, clock_time;
- } timing_samples;
+typedef struct {
+ uint64_t local_time, clock_time;
+} timing_samples;
// information about each clock source
typedef struct {
int next_sample_goes_here; // point to where in the timing samples array the next entries should
// go
-
// these are for finding the best clock to use
// See Figure 27 and 27 pp 89 -- 90 for the Data set comparison algorithm
*
* Commercial licensing is also available.
*/
-#include <arpa/inet.h>
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
+#include <string.h> //strsep
#include "debug.h"
#include "general-utilities.h"
void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
clock_source_private_data *clock_private_info, uint64_t reception_time) {
- clock_private_info->flags |= (1 << clock_is_valid); // valid because it has at least one follow_up
- struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf;
+ clock_private_info->flags |= (1 << clock_is_valid); // valid because it has at least one follow_up
+ struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf;
- uint16_t seconds_hi = nctohs(&msg->follow_up.preciseOriginTimestamp[0]);
- uint32_t seconds_low = nctohl(&msg->follow_up.preciseOriginTimestamp[2]);
- uint32_t nanoseconds = nctohl(&msg->follow_up.preciseOriginTimestamp[6]);
- uint64_t preciseOriginTimestamp = seconds_hi;
- preciseOriginTimestamp = preciseOriginTimestamp << 32;
- preciseOriginTimestamp = preciseOriginTimestamp + seconds_low;
- preciseOriginTimestamp = preciseOriginTimestamp * 1000000000L;
- preciseOriginTimestamp = preciseOriginTimestamp + nanoseconds;
+ uint16_t seconds_hi = nctohs(&msg->follow_up.preciseOriginTimestamp[0]);
+ uint32_t seconds_low = nctohl(&msg->follow_up.preciseOriginTimestamp[2]);
+ uint32_t nanoseconds = nctohl(&msg->follow_up.preciseOriginTimestamp[6]);
+ uint64_t preciseOriginTimestamp = seconds_hi;
+ preciseOriginTimestamp = preciseOriginTimestamp << 32;
+ preciseOriginTimestamp = preciseOriginTimestamp + seconds_low;
+ preciseOriginTimestamp = preciseOriginTimestamp * 1000000000L;
+ preciseOriginTimestamp = preciseOriginTimestamp + nanoseconds;
- // update our sample information
+ // update our sample information
- clock_private_info->samples[clock_private_info->next_sample_goes_here].local_time =
- reception_time;
- clock_private_info->samples[clock_private_info->next_sample_goes_here]
- .clock_time = preciseOriginTimestamp;
+ clock_private_info->samples[clock_private_info->next_sample_goes_here].local_time =
+ reception_time;
+ clock_private_info->samples[clock_private_info->next_sample_goes_here].clock_time =
+ preciseOriginTimestamp;
- if (clock_private_info->vacant_samples > 0)
- clock_private_info->vacant_samples--;
+ if (clock_private_info->vacant_samples > 0)
+ clock_private_info->vacant_samples--;
- clock_private_info->next_sample_goes_here++;
- // if we have need to wrap.
- if (clock_private_info->next_sample_goes_here == MAX_TIMING_SAMPLES)
- clock_private_info->next_sample_goes_here = 0;
+ clock_private_info->next_sample_goes_here++;
+ // if we have need to wrap.
+ if (clock_private_info->next_sample_goes_here == MAX_TIMING_SAMPLES)
+ clock_private_info->next_sample_goes_here = 0;
-
-// if ((clock_private_info->flags & (1 << clock_is_master)) != 0) {
+ // if ((clock_private_info->flags & (1 << clock_is_master)) != 0) {
if (1) {
debug(2, "FOLLOWUP from %" PRIx64 ", %s.", clock_private_info->clock_id,
&clock_private_info->ip);
uint32_t old_flags = clock_private_info->flags;
- //if ((clock_private_info->flags & (1 << clock_is_valid)) == 0) {
+ // if ((clock_private_info->flags & (1 << clock_is_valid)) == 0) {
// debug(1, "clock %" PRIx64 " is now valid at: %s", packet_clock_id, clock_private_info->ip);
//}
#ifndef NQPTP_MESSAGE_HANDLERS_H
#define NQPTP_MESSAGE_HANDLERS_H
-#include "general-utilities.h"
#include "nqptp-clock-sources.h"
-#include "nqptp-shm-structures.h"
void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
uint64_t reception_time);
// The IPs will become the new list of timing peers, replacing any previous
#include <inttypes.h>
-#include <netinet/in.h>
#include <pthread.h>
struct shm_structure {
*/
#include "nqptp-utilities.h"
-#include "general-utilities.h"
-#include "nqptp-ptp-definitions.h"
#include <errno.h>
-#include <fcntl.h>
-#include <ifaddrs.h>
-#include <linux/if_packet.h>
-#include <linux/net_tstamp.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <sys/types.h>
+#include <fcntl.h> // fcntl etc.
+#include <ifaddrs.h> // getifaddrs
+#include <linux/if_packet.h> // sockaddr_ll
+#include <linux/net_tstamp.h> // SOF_TIMESTAMPING_TX_HARDWARE and friends
+#include <netdb.h> // getaddrinfo etc.
+#include <stdio.h> // snprintf
+#include <stdlib.h> // malloc, free
+#include <string.h> // memset strcpy, etc.
#include "debug.h"
#ifndef NQPTP_UTILITIES_H
#define NQPTP_UTILITIES_H
+
#include "nqptp.h"
-#include <stddef.h>
+#include <inttypes.h>
+#include <pthread.h>
+
// functions that are specific to NQPTP
// general stuff should go in the general-utilities
#include "gitversion.h"
#endif
-#include <arpa/inet.h>
-#include <stdio.h> //printf
-#include <stdlib.h> //malloc;
-#include <string.h> //memset
-#include <sys/socket.h>
-#include <unistd.h> // close
-
-#include <ifaddrs.h>
-#include <pthread.h>
-#include <sys/types.h>
+#include <arpa/inet.h> // inet_ntop
+#include <stdio.h> // printf
+#include <stdlib.h> // malloc;
+#include <string.h> // memset
#include <errno.h>
-#include <netdb.h>
-#include <time.h>
-
-#include <linux/if_packet.h>
-#include <net/ethernet.h> /* the L2 protocols */
-#include <sys/ioctl.h>
-
-#include <inttypes.h>
-
-#include <asm/types.h>
-#include <linux/errqueue.h>
-#include <linux/net_tstamp.h>
+#include <unistd.h> // close
-#include <fcntl.h> /* For O_* constants */
-#include <sys/mman.h>
-#include <sys/stat.h> /* For mode constants */
+#include <fcntl.h> /* For O_* constants */
+#include <sys/mman.h> // for shared memory stuff
+#include <sys/stat.h> // umask
-#include <grp.h>
+#include <grp.h> // group stuff
-#include <signal.h>
+#include <signal.h> // SIGTERM and stuff like that
#include <sys/epoll.h>
#ifndef FIELD_SIZEOF
#ifdef CONFIG_USE_GIT_VERSION_STRING
if (git_version_string[0] != '\0')
fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", git_version_string,
- NQPTP_SHM_STRUCTURES_VERSION);
+ NQPTP_SHM_STRUCTURES_VERSION);
else
#endif
- fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", VERSION,
- NQPTP_SHM_STRUCTURES_VERSION);
+ fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", VERSION,
+ NQPTP_SHM_STRUCTURES_VERSION);
exit(EXIT_SUCCESS);
} else if (strcmp(argv[i] + 1, "vvv") == 0) {
debug_level = 3;
#ifndef NQPTP_H
#define NQPTP_H
+#include <inttypes.h>
+#include <pthread.h>
+
#include "nqptp-shm-structures.h"
#define MAX_OPEN_SOCKETS 16
uint64_t local_to_master_offset, uint64_t mastership_start_time);
#endif
-