Skip to content

Commit

Permalink
Maintain one Sync sequence counter per destination address.
Browse files Browse the repository at this point in the history
According to IEEE 1588, each destination should have its own, unique
message sequence with respect to the sequenceId field.  The current
code will generate skips in the number sequence in the presence of
unicast clients.  Fix the issue by giving each client its own
sequence of Sync messages.

Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Nov 3, 2021
1 parent 8018892 commit 24220e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 7 additions & 9 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ int port_tx_announce(struct port *p, struct address *dst, uint16_t sequence_id)
return err;
}

int port_tx_sync(struct port *p, struct address *dst)
int port_tx_sync(struct port *p, struct address *dst, uint16_t sequence_id)
{
struct ptp_message *msg, *fup;
int err, event;
Expand Down Expand Up @@ -1557,7 +1557,7 @@ int port_tx_sync(struct port *p, struct address *dst)
msg->header.messageLength = sizeof(struct sync_msg);
msg->header.domainNumber = clock_domain_number(p->clock);
msg->header.sourcePortIdentity = p->portIdentity;
msg->header.sequenceId = p->seqnum.sync++;
msg->header.sequenceId = sequence_id;
msg->header.control = CTL_SYNC;
msg->header.logMessageInterval = p->logSyncInterval;

Expand Down Expand Up @@ -1593,7 +1593,7 @@ int port_tx_sync(struct port *p, struct address *dst)
fup->header.messageLength = sizeof(struct follow_up_msg);
fup->header.domainNumber = clock_domain_number(p->clock);
fup->header.sourcePortIdentity = p->portIdentity;
fup->header.sequenceId = p->seqnum.sync - 1;
fup->header.sequenceId = sequence_id;
fup->header.control = CTL_FOLLOW_UP;
fup->header.logMessageInterval = p->logSyncInterval;

Expand Down Expand Up @@ -1913,8 +1913,8 @@ int process_announce(struct port *p, struct ptp_message *m)

static int process_delay_req(struct port *p, struct ptp_message *m)
{
int err, nsm, saved_seqnum_sync;
struct ptp_message *msg;
int err, nsm;

nsm = port_nsm_reply(p, m);

Expand Down Expand Up @@ -1964,10 +1964,7 @@ static int process_delay_req(struct port *p, struct ptp_message *m)
goto out;
}
if (nsm) {
saved_seqnum_sync = p->seqnum.sync;
p->seqnum.sync = m->header.sequenceId;
err = port_tx_sync(p, &m->address);
p->seqnum.sync = saved_seqnum_sync;
err = port_tx_sync(p, &m->address, m->header.sequenceId);
}
out:
msg_put(msg);
Expand Down Expand Up @@ -2712,7 +2709,8 @@ static enum fsm_event bc_event(struct port *p, int fd_index)
case FD_SYNC_TX_TIMER:
pr_debug("%s: master sync timeout", p->log_name);
port_set_sync_tx_tmo(p);
return port_tx_sync(p, NULL) ? EV_FAULT_DETECTED : EV_NONE;
return port_tx_sync(p, NULL, p->seqnum.sync++) ?
EV_FAULT_DETECTED : EV_NONE;

case FD_UNICAST_SRV_TIMER:
pr_debug("%s: unicast service timeout", p->log_name);
Expand Down
2 changes: 1 addition & 1 deletion port_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int port_tx_interval_request(struct port *p,
Integer8 announceInterval,
Integer8 timeSyncInterval,
Integer8 linkDelayInterval);
int port_tx_sync(struct port *p, struct address *dst);
int port_tx_sync(struct port *p, struct address *dst, uint16_t sequence_id);
int process_announce(struct port *p, struct ptp_message *m);
void process_delay_resp(struct port *p, struct ptp_message *m);
void process_follow_up(struct port *p, struct ptp_message *m);
Expand Down
4 changes: 3 additions & 1 deletion unicast_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct unicast_client_address {
struct PortIdentity portIdentity;
struct {
UInteger16 announce;
UInteger16 sync;
} seqnum;
unsigned int message_types;
struct address addr;
Expand Down Expand Up @@ -190,7 +191,8 @@ static int unicast_service_clients(struct port *p,
}
}
if (client->message_types & (1 << SYNC)) {
if (port_tx_sync(p, &client->addr)) {
if (port_tx_sync(p, &client->addr,
client->seqnum.sync++)) {
err = -1;
}
}
Expand Down

0 comments on commit 24220e8

Please sign in to comment.