Commit 05e49d81 authored by Aurelio Colosimo's avatar Aurelio Colosimo

handling of recv packet timestamp

parent 41bbe03b
......@@ -7,7 +7,8 @@
*/
extern int bare_open_ch(struct pp_instance *ppi, char *name);
extern int bare_recv_packet(struct pp_instance *ppi, void *pkt, int len);
extern int bare_recv_packet(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t);
extern int bare_send_packet(struct pp_instance *ppi, void *pkt, int len,
int chtype);
......
......@@ -8,7 +8,8 @@
#include "bare-linux.h"
/* FIXME: which socket we receive and send with? */
int bare_recv_packet(struct pp_instance *ppi, void *pkt, int len)
int bare_recv_packet(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t)
{
return sys_recv(NP(ppi)->ch[PP_NP_GEN].fd, pkt, len, 0);
}
......@@ -18,7 +19,7 @@ int bare_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype)
return sys_send(NP(ppi)->ch[chtype].fd, pkt, len, 0);
}
int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len)
int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len, TimeInternal *t)
__attribute__((alias("bare_recv_packet")));
int pp_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype)
__attribute__((alias("bare_send_packet")));
......
......@@ -28,6 +28,8 @@ void bare_main_loop(struct pp_instance *ppi)
{
int delay_ms;
set_TimeInternal(ppi->last_rcv_time, 0, 0);
/*
* The main loop here is based on select. While we are not
* doing anything else but the protocol, this allows extra stuff
......@@ -69,7 +71,10 @@ void bare_main_loop(struct pp_instance *ppi)
*
* FIXME: we don't know which socket to receive from
*/
i = bare_recv_packet(ppi, packet, sizeof(packet));
i = bare_recv_packet(ppi, packet, sizeof(packet),
&ppi->last_rcv_time);
ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset;
/* FIXME: PP_PROTO_NR is a legacy number */
if (((struct bare_ethhdr *)packet)->h_proto
!= htons(PP_PROTO_NR))
......
......@@ -18,6 +18,8 @@ void posix_main_loop(struct pp_instance *ppi)
{
int delay_ms;
set_TimeInternal(&ppi->last_rcv_time, 0, 0);
/*
* The main loop here is based on select. While we are not
* doing anything else but the protocol, this allows extra stuff
......@@ -44,7 +46,10 @@ void posix_main_loop(struct pp_instance *ppi)
* We got a packet. If it's not ours, continue consuming
* the pending timeout
*/
i = posix_recv_packet(ppi, packet, sizeof(packet));
i = posix_recv_packet(ppi, packet, sizeof(packet),
&ppi->last_rcv_time);
ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset;
if (i < PP_PACKET_SIZE) {
delay_ms = -1;
......
......@@ -22,7 +22,8 @@
static int ch_check_stat = 0;
/* Receive and send is *not* so trivial */
int posix_recv_packet(struct pp_instance *ppi, void *pkt, int len)
int posix_recv_packet(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t)
{
struct pp_channel *ch1 = NULL, *ch2 = NULL;
......@@ -56,7 +57,7 @@ int posix_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype)
return send(NP(ppi)->ch[chtype].fd, pkt, len, 0);
}
int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len)
int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len, TimeInternal *t)
__attribute__((alias("posix_recv_packet")));
int pp_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype)
__attribute__((alias("posix_send_packet")));
......
......@@ -15,7 +15,8 @@ extern int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms);
extern int posix_open_ch(struct pp_instance *ppi, char *name);
extern int posix_recv_packet(struct pp_instance *ppi, void *pkt, int len);
extern int posix_recv_packet(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t);
extern int posix_send_packet(struct pp_instance *ppi, void *pkt, int len,
int chtype);
......
......@@ -23,7 +23,8 @@ int spec_open_ch(struct pp_instance *ppi)
}
/* To receive and send packets, we call the minic low-level stuff */
int spec_recv_packet(struct pp_instance *ppi, void *pkt, int len)
int spec_recv_packet(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t)
{
static int led;
......@@ -41,7 +42,7 @@ int spec_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype)
return minic_tx_frame(pkt, pkt + 14, len, NULL);
}
int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len)
int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len, TimeInternal *t)
__attribute__((alias("spec_recv_packet")));
int pp_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype)
__attribute__((alias("spec_send_packet")));
......@@ -7,7 +7,8 @@
*/
extern int spec_open_ch(struct pp_instance *ppi);
extern int spec_recv_packet(struct pp_instance *ppi, void *pkt, int len);
extern int spec_recv_packet(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t);
extern int spec_send_packet(struct pp_instance *ppi, void *pkt, int len);
extern void spec_main_loop(struct pp_instance *ppi);
......
......@@ -134,6 +134,9 @@ struct pp_instance {
Octet *buf_in; /* FIXME really useful? Probably not*/
TimeInternal sync_receive_time;
UInteger16 recv_sync_sequence_id;
TimeInternal last_rcv_time; /* used to store timestamp retreived from
* received packet */
TimeInternal last_sync_corr_field;
TimeInternal last_pdelay_req_corr_field;
TimeInternal last_pdelay_resp_corr_field;
......@@ -188,7 +191,8 @@ extern int pp_parse_cmdline(struct pp_instance *ppi, int argc, char **argv);
/* Network stuff */
extern int pp_net_init(struct pp_instance *ppi);
extern int pp_net_shutdown(struct pp_instance *ppi);
extern int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len);
extern int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t);
extern int pp_send_packet(struct pp_instance *ppi, void *pkt, int len,
int chtype); /* chtype: PP_NP_GEN || PP_NP_EVT */
......@@ -265,6 +269,7 @@ extern int from_TimeInternal(TimeInternal *internal, Timestamp *external);
extern int to_TimeInternal(TimeInternal *internal, Timestamp *external);
extern void add_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y);
extern void sub_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y);
extern void set_TimeInternal(TimeInternal *t, Integer32 s, Integer32 ns);
/* Get and Set system timestamp */
extern void pp_get_tstamp(TimeInternal *t);
......
......@@ -93,3 +93,9 @@ void sub_TimeInternal(TimeInternal *r, TimeInternal *x, TimeInternal *y)
normalize_TimeInternal(r);
}
void set_TimeInternal(TimeInternal *t, Integer32 s, Integer32 ns)
{
t->seconds = s;
t->nanoseconds = ns;
}
......@@ -160,8 +160,9 @@ int st_com_slave_handle_announce(struct pp_instance *ppi, unsigned char *buf,
}
int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
int len, TimeInternal *time)
int len)
{
TimeInternal *time;
TimeInternal origin_tstamp;
TimeInternal correction_field;
MsgHeader *hdr = &ppi->msg_tmp_header;
......@@ -172,6 +173,8 @@ int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
if (ppi->is_from_self)
return 0;
time = &ppi->last_rcv_time;
if (ppi->is_from_cur_par) {
ppi->sync_receive_time.seconds = time->seconds;
ppi->sync_receive_time.nanoseconds = time->nanoseconds;
......@@ -262,8 +265,9 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
int st_com_handle_pdelay_req(struct pp_instance *ppi, unsigned char *buf,
int len, TimeInternal *time)
int len)
{
TimeInternal *time;
MsgHeader *hdr = &ppi->msg_tmp_header;
if (len < PP_PDELAY_REQ_LENGTH)
......@@ -272,6 +276,8 @@ int st_com_handle_pdelay_req(struct pp_instance *ppi, unsigned char *buf,
if (ppi->rt_opts->e2e_mode)
return 0;
time = &ppi->last_rcv_time;
if (ppi->is_from_self) {
/* Get sending timestamp from IP stack
* with So_TIMESTAMP */
......@@ -313,14 +319,17 @@ int st_com_master_handle_announce(struct pp_instance *ppi, unsigned char *buf,
}
int st_com_master_handle_sync(struct pp_instance *ppi, unsigned char *buf,
int len, TimeInternal *time)
int len)
{
TimeInternal *time;
if (len < PP_SYNC_LENGTH)
return -1;
if (!ppi->is_from_self)
return 0;
time = &ppi->last_rcv_time;
/* Add latency */
add_TimeInternal(time, time, &ppi->rt_opts->outbound_latency);
msg_issue_followup(ppi, time);
......
......@@ -25,13 +25,13 @@ int st_com_master_handle_announce(struct pp_instance *ppi, unsigned char *buf,
int len);
int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
int len, TimeInternal *time);
int len);
int st_com_master_handle_sync(struct pp_instance *ppi, unsigned char *buf,
int len, TimeInternal *time);
int len);
int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
int len);
int st_com_handle_pdelay_req(struct pp_instance *ppi, unsigned char *buf,
int len, TimeInternal *time);
int len);
......@@ -8,7 +8,6 @@
int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
TimeInternal time; /* TODO: handle it, see handle(...) in protocol.c */
int e = 0; /* error var, to check errors in msg handling */
if (ppi->is_new_state)
......@@ -24,7 +23,7 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
break;
case PPM_SYNC:
e = st_com_master_handle_sync(ppi, pkt, plen, &time);
e = st_com_master_handle_sync(ppi, pkt, plen);
break;
default:
......
......@@ -9,7 +9,7 @@
int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
TimeInternal time; /* TODO: handle it, see handle(...) in protocol.c */
TimeInternal *time;
TimeInternal req_rec_tstamp;
TimeInternal correction_field;
TimeInternal resp_orig_tstamp;
......@@ -17,6 +17,8 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
int e = 0; /* error var, to check errors in msg handling */
MsgHeader *hdr = &ppi->msg_tmp_header;
time = &ppi->last_rcv_time;
if (ppi->is_new_state) {
pp_timer_start(1 << DSPOR(ppi)->logSyncInterval,
ppi->timers[PP_TIMER_SYNC]);
......@@ -64,16 +66,16 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
break;
case PPM_SYNC:
e = st_com_master_handle_sync(ppi, pkt, plen, &time);
e = st_com_master_handle_sync(ppi, pkt, plen);
break;
case PPM_DELAY_REQ:
msg_copy_header(&ppi->delay_req_hdr, hdr);
msg_issue_delay_resp(ppi, &time);
msg_issue_delay_resp(ppi, time);
break;
case PPM_PDELAY_REQ:
e = st_com_handle_pdelay_req(ppi, pkt, plen, &time);
e = st_com_handle_pdelay_req(ppi, pkt, plen);
break;
case PPM_PDELAY_RESP:
......@@ -83,10 +85,10 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (ppi->is_from_self) {
/*Add latency*/
add_TimeInternal(&time, &time,
add_TimeInternal(time, time,
&ppi->rt_opts->outbound_latency);
e = msg_issue_pdelay_resp_follow_up(ppi,&time);
e = msg_issue_pdelay_resp_follow_up(ppi, time);
break;
}
msg_unpack_pdelay_resp(pkt, &ppi->msg_tmp.presp);
......@@ -104,9 +106,9 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
/* Two Step Clock */
/* Store t4 (Fig 35) */
ppi->pdelay_resp_receive_time.seconds =
time.seconds;
time->seconds;
ppi->pdelay_resp_receive_time.nanoseconds =
time.nanoseconds;
time->nanoseconds;
/* Store t2 (Fig 35) */
to_TimeInternal(&req_rec_tstamp,
&ppi->msg_tmp.presp.
......@@ -127,9 +129,9 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
/* One step Clock */
/* Store t4 (Fig 35)*/
ppi->pdelay_resp_receive_time.seconds =
time.seconds;
time->seconds;
ppi->pdelay_resp_receive_time.nanoseconds =
time.nanoseconds;
time->nanoseconds;
int64_to_TimeInternal(
hdr->correctionfield,
......
......@@ -8,7 +8,6 @@
int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
TimeInternal time; /* TODO: handle it, see handle(...) in protocol.c */
int e = 0; /* error var, to check errors in msg handling */
if (ppi->is_new_state) {
......@@ -28,11 +27,11 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
break;
case PPM_PDELAY_REQ:
e = st_com_handle_pdelay_req(ppi, pkt, plen, &time);
e = st_com_handle_pdelay_req(ppi, pkt, plen);
break;
case PPM_SYNC:
e = st_com_master_handle_sync(ppi, pkt, plen, &time);
e = st_com_master_handle_sync(ppi, pkt, plen);
break;
default:
......
......@@ -10,12 +10,14 @@
int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
int e = 0; /* error var, to check errors in msg handling */
TimeInternal time; /* TODO: handle it, see handle(...) in protocol.c */
TimeInternal *time;
TimeInternal req_rec_tstamp;
TimeInternal correction_field;
TimeInternal resp_orig_tstamp;
MsgHeader *hdr = &ppi->msg_tmp_header;
time = &ppi->last_rcv_time;
if (ppi->is_new_state) {
pp_init_clock(ppi);
......@@ -50,7 +52,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
break;
case PPM_SYNC:
e = st_com_slave_handle_sync(ppi, pkt, plen, &time);
e = st_com_slave_handle_sync(ppi, pkt, plen);
break;
case PPM_FOLLOW_UP:
......@@ -66,9 +68,9 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
* with So_TIMESTAMP */
ppi->delay_req_send_time.seconds =
time.seconds;
time->seconds;
ppi->delay_req_send_time.nanoseconds =
time.nanoseconds;
time->nanoseconds;
/* Add latency */
add_TimeInternal(&ppi->delay_req_send_time,
......@@ -125,7 +127,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
break;
case PPM_PDELAY_REQ:
e = st_com_handle_pdelay_req(ppi, pkt, plen, &time);
e = st_com_handle_pdelay_req(ppi, pkt, plen);
break;
case PPM_PDELAY_RESP:
......@@ -160,9 +162,9 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
/* Two Step Clock */
/* Store t4 (Fig 35) */
ppi->pdelay_resp_receive_time.seconds =
time.seconds;
time->seconds;
ppi->pdelay_resp_receive_time.nanoseconds =
time.nanoseconds;
time->nanoseconds;
/* Store t2 (Fig 35) */
to_TimeInternal(&req_rec_tstamp,
&ppi->msg_tmp.presp.
......@@ -182,9 +184,9 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
/* One step Clock */
/* Store t4 (Fig 35) */
ppi->pdelay_resp_receive_time.seconds =
time.seconds;
time->seconds;
ppi->pdelay_resp_receive_time.nanoseconds =
time.nanoseconds;
time->nanoseconds;
int64_to_TimeInternal(hdr->correctionfield,
&correction_field);
......
......@@ -9,7 +9,6 @@
int pp_uncalibrated(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
int e = 0; /* error var, to check errors in msg handling */
TimeInternal time; /* TODO: handle it, see handle(...) in protocol.c */
switch (ppi->msg_tmp_header.messageType) {
......@@ -18,7 +17,7 @@ int pp_uncalibrated(struct pp_instance *ppi, unsigned char *pkt, int plen)
break;
case PPM_SYNC:
e = st_com_slave_handle_sync(ppi, pkt, plen, &time);
e = st_com_slave_handle_sync(ppi, pkt, plen);
break;
case PPM_FOLLOW_UP:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment