clock_source_private_data clocks_private[MAX_CLOCKS];
-int find_clock_source_record(char *sender_string,
- clock_source_private_data *clocks_private_info) {
+int find_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info) {
// return the index of the clock in the clock information arrays or -1
int response = -1;
int i = 0;
if (found == 1) {
response = i;
memset(&clocks_private_info[i], 0, sizeof(clock_source_private_data));
- strncpy((char *)&clocks_private_info[i].ip, sender_string, FIELD_SIZEOF(clock_source_private_data, ip) - 1);
+ strncpy((char *)&clocks_private_info[i].ip, sender_string,
+ FIELD_SIZEOF(clock_source_private_data, ip) - 1);
clocks_private_info[i].in_use = 1;
clocks_private_info[i].t2 = 0;
clocks_private_info[i].current_stage = waiting_for_sync;
return response;
}
-void manage_clock_sources(uint64_t reception_time,
- clock_source_private_data *clocks_private_info) {
+void manage_clock_sources(uint64_t reception_time, clock_source_private_data *clocks_private_info) {
debug(3, "manage_clock_sources");
int i;
// do a garbage collect for clock records no longer in use
} clock_source_private_data;
-int find_clock_source_record(char *sender_string,
- clock_source_private_data *clocks_private_info);
+int find_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info);
-int create_clock_source_record(char *sender_string,
- clock_source_private_data *clocks_private_info);
+int create_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info);
void update_clock_self_identifications(clock_source_private_data *clocks_private_info);
-void manage_clock_sources(uint64_t reception_time,
- clock_source_private_data *clocks_private_info);
+void manage_clock_sources(uint64_t reception_time, clock_source_private_data *clocks_private_info);
extern clock_source_private_data clocks_private[MAX_CLOCKS];
for (i = 0; i < MAX_CLOCKS; i++) {
if ((clock_private_info[i].flags & (1 << clock_is_master)) != 0)
if (old_master == -1)
- old_master = i; // find old master
+ old_master = i; // find old master
clock_private_info[i].flags &= ~(1 << clock_is_master); // turn them all off
}
}
}
if (best_so_far != -1) {
- // we found a master clock
+ // we found a master clock
clock_private_info[best_so_far].flags |= (1 << clock_is_master);
// master_clock_index = best_so_far;
if (old_master != best_so_far) {
- update_master_clock_info(clock_private_info[best_so_far].clock_id, clock_private_info[best_so_far].local_time, clock_private_info[best_so_far].local_to_source_time_offset);
+ update_master_clock_info(clock_private_info[best_so_far].clock_id,
+ clock_private_info[best_so_far].local_time,
+ clock_private_info[best_so_far].local_to_source_time_offset);
}
} else {
if (timing_peer_count == 0)
- debug(1, "No timing peer list found");
+ debug(2, "No timing peer list found");
else
debug(1, "No master clock not found!");
}
// check
for (i = 0; i < MAX_CLOCKS; i++) {
if ((clock_private_info[i].flags & (1 << clock_is_master)) != 0)
- debug(2,"leaving with %d as master", i);
+ debug(2, "leaving with %d as master", i);
}
-
}
-void update_master() {
- update_master_old(clocks_private);
-}
+void update_master() { update_master_old(clocks_private); }
void handle_control_port_messages(char *buf, ssize_t recv_len,
clock_source_private_data *clock_private_info) {
if (recv_len != -1) {
buf[recv_len - 1] = 0; // make sure there's a null in it!
- debug(1,"Received a new timing peer list message: \"%s\".", buf);
+ debug(2, "Received a new timing peer list message: \"%s\".", buf);
if (buf[0] == 'T') {
char *ip_list = buf + 1;
// turn off all is_timing_peer flags
int i;
for (i = 0; i < MAX_CLOCKS; i++) {
- clock_private_info[i].flags &= ~(1 << clock_is_a_timing_peer); // turn off peer flag (but not the master flag!)
+ clock_private_info[i].flags &=
+ ~(1 << clock_is_a_timing_peer); // turn off peer flag (but not the master flag!)
}
while (ip_list != NULL) {
}
}
-void handle_announce(char *buf, ssize_t recv_len,
- clock_source_private_data *clock_private_info, uint64_t reception_time) {
+void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
+ uint64_t reception_time) {
// reject Announce messages from self
if (clock_private_info->is_one_of_ours == 0) {
// debug_print_buffer(1, buf, (size_t) recv_len);
}
void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
- clock_source_private_data *clock_private_info, __attribute__((unused)) uint64_t reception_time) {
+ clock_source_private_data *clock_private_info,
+ __attribute__((unused)) uint64_t reception_time) {
struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf;
if ((clock_private_info->current_stage == sync_seen) &&
}
*/
- // int64_t estimated_variation = estimated_offset - clock_private_info->previous_estimated_offset;
- // debug(1, "clock: %" PRIx64 ", estimated_jitter: %+f ms, divergence: %+f.",
- // clock_info->clock_id,
+ // int64_t estimated_variation = estimated_offset -
+ // clock_private_info->previous_estimated_offset; debug(1, "clock: %" PRIx64 ",
+ // estimated_jitter: %+f ms, divergence: %+f.", clock_info->clock_id,
// estimated_variation * 0.000001, divergence * 0.000001);
clock_private_info->previous_estimated_offset = estimated_offset;
-
clock_private_info->clock_id = packet_clock_id;
clock_private_info->flags |= (1 << clock_is_valid);
clock_private_info->local_time = clock_private_info->t2;
clock_private_info->local_to_source_time_offset = estimated_offset;
if ((clock_private_info->flags & (1 << clock_is_master)) != 0) {
- update_master_clock_info(clock_private_info->clock_id, clock_private_info->local_time, clock_private_info->local_to_source_time_offset);
+ update_master_clock_info(clock_private_info->clock_id, clock_private_info->local_time,
+ clock_private_info->local_to_source_time_offset);
}
clock_private_info->next_sample_goes_here++;
#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);
+void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
+ uint64_t reception_time);
-void handle_sync(char *buf, ssize_t recv_len,
- clock_source_private_data *clock_private_info, uint64_t reception_time);
+void handle_sync(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
+ uint64_t reception_time);
-void handle_follow_up(char *buf, ssize_t recv_len,
- clock_source_private_data *clock_private_info, uint64_t reception_time);
+void handle_follow_up(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
+ uint64_t reception_time);
void handle_control_port_messages(char *buf, ssize_t recv_len,
clock_source_private_data *clock_private_info);
#include <pthread.h>
struct shm_structure {
- pthread_mutex_t shm_mutex; // for safely accessing the structure
- uint16_t version; // deprecated -- check this is equal to NQPTP_SHM_STRUCTURES_VERSION
- uint32_t flags; // unused
- uint64_t master_clock_id; // the current master clock
- uint64_t local_time; // the time when the offset was calculated
+ pthread_mutex_t shm_mutex; // for safely accessing the structure
+ uint16_t version; // deprecated -- check this is equal to NQPTP_SHM_STRUCTURES_VERSION
+ uint32_t flags; // unused
+ uint64_t master_clock_id; // the current master clock
+ uint64_t local_time; // the time when the offset was calculated
uint64_t local_to_master_time_offset; // add this to the local time to get master clock time
};
struct shm_structure *shared_memory = NULL; // this is where public clock info is available
int epoll_fd;
-void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time, uint64_t local_to_master_offset) {
+void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time,
+ uint64_t local_to_master_offset) {
if (shared_memory->master_clock_id != master_clock_id)
- debug(1,"Master clock is: %" PRIx64 ", local_to_ptp_time_offset: %" PRIx64 ".", shared_memory->master_clock_id, shared_memory->local_to_master_time_offset);
+ debug(1, "Master clock is: %" PRIx64".", master_clock_id);
int rc = pthread_mutex_lock(&shared_memory->shm_mutex);
if (rc != 0)
warn("Can't acquire mutex to update master clock!");
memset(sender_string, 0, sizeof(sender_string));
inet_ntop(connection_ip_family, sender_addr, sender_string, sizeof(sender_string));
// now, find or create a record for this ip
- int the_clock =
- find_clock_source_record(sender_string,
- (clock_source_private_data *)&clocks_private);
+ int the_clock = find_clock_source_record(
+ sender_string, (clock_source_private_data *)&clocks_private);
// not sure about requiring a Sync before creating it...
if ((the_clock == -1) && ((buf[0] & 0xF) == Sync)) {
the_clock = create_clock_source_record(
- sender_string,
- (clock_source_private_data *)&clocks_private);
+ sender_string, (clock_source_private_data *)&clocks_private);
}
if (the_clock != -1) {
clocks_private[the_clock].time_of_last_use =
switch (buf[0] & 0xF) {
case Announce:
// needed to reject messages coming from self
- update_clock_self_identifications(
- (clock_source_private_data *)&clocks_private);
- handle_announce(buf, recv_len,
- &clocks_private[the_clock], reception_time);
+ update_clock_self_identifications((clock_source_private_data *)&clocks_private);
+ handle_announce(buf, recv_len, &clocks_private[the_clock], reception_time);
break;
case Sync: { // if it's a sync
- handle_sync(buf, recv_len,
- &clocks_private[the_clock], reception_time);
+ handle_sync(buf, recv_len, &clocks_private[the_clock], reception_time);
} break;
case Follow_Up: {
- handle_follow_up(buf, recv_len,
- &clocks_private[the_clock], reception_time);
+ handle_follow_up(buf, recv_len, &clocks_private[the_clock], reception_time);
} break;
default:
break;
}
}
}
- manage_clock_sources(reception_time,
- (clock_source_private_data *)&clocks_private);
+ manage_clock_sources(reception_time, (clock_source_private_data *)&clocks_private);
}
}
#define NQPTP_H
// 0 means no debug messages. 3 means lots!
-#define DEBUG_LEVEL 0
+#define DEBUG_LEVEL 1
#include "nqptp-shm-structures.h"
#define MAX_OPEN_SOCKETS 16
-
// When a new timing peer group is created, one of the clocks in the
// group becomes the master and its native time becomes the "master time".
// This is what is provided to the client.
extern int master_clock_index;
extern struct shm_structure *shared_memory;
-void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time, uint64_t local_to_master_offset);
+void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time,
+ uint64_t local_to_master_offset);
#endif
\ No newline at end of file