Commit f69e05bb authored by Aurelio Colosimo's avatar Aurelio Colosimo

struct pp_instance: foreign master related fields moved back to pp_instance

This partially reverts commit 16707d53, since the IEEE spec states that foreign
masters list must be kept updated for each link, then Ebest search among all
links must be performed.
Signed-off-by: Aurelio Colosimo's avatarAurelio Colosimo <aurelio@aureliocolosimo.it>
parent 2b322a96
......@@ -82,8 +82,8 @@ int main(int argc, char **argv)
ppg->pp_instances = calloc(ppg->nlinks, sizeof(struct pp_instance));
if ((!ppg->defaultDS) || (!ppg->currentDS) || (!ppg->parentDS)
|| (!ppg->timePropertiesDS) || (!ppg->frgn_master)
|| (!ppg->arch_data) || (!ppg->pp_instances))
|| (!ppg->timePropertiesDS) || (!ppg->arch_data)
|| (!ppg->pp_instances))
exit(__LINE__);
ppg->servo = calloc(1, sizeof(*ppg->servo));
......
......@@ -158,6 +158,14 @@ struct pp_instance {
TimeInternal cField; /* transp. clocks */
TimeInternal last_rcv_time, last_snt_time; /* two temporaries */
/* Page 85: each port shall maintain an implementation-specific
* foreignMasterDS data set for the purposes of qualifying Announce
* messages */
UInteger16 frgn_rec_num;
Integer16 frgn_rec_i;
Integer16 frgn_rec_best;
struct pp_frgn_master frgn_master[PP_NR_FOREIGN_RECORDS];
DSPort *portDS; /* page 72 */
unsigned long timeouts[__PP_TO_ARRAY_SIZE];
......@@ -194,10 +202,6 @@ struct pp_link {
*/
struct pp_globals {
struct pp_instance *pp_instances;
UInteger16 frgn_rec_num;
Integer16 frgn_rec_i;
Integer16 frgn_rec_best;
struct pp_frgn_master frgn_master[PP_NR_FOREIGN_RECORDS];
struct pp_servo *servo;
......
......@@ -183,7 +183,7 @@ static int bmc_state_decision(struct pp_instance *ppi, struct pp_frgn_master *m)
if (ppi->slave_only)
goto slave;
if ((!GLBS(ppi)->frgn_rec_num) && (ppi->state == PPS_LISTENING))
if ((!ppi->frgn_rec_num) && (ppi->state == PPS_LISTENING))
return PPS_LISTENING;
/* copy local information to a foreign_master structure */
......@@ -225,22 +225,23 @@ slave:
int bmc(struct pp_instance *ppi)
{
struct pp_frgn_master *frgn_master = GLBS(ppi)->frgn_master;
struct pp_frgn_master *frgn_master = ppi->frgn_master;
int i, best;
if (!GLBS(ppi)->frgn_rec_num)
if (!ppi->frgn_rec_num)
if (ppi->state == PPS_MASTER) {
m1(ppi);
return ppi->state;
}
for (i = 1, best = 0; i < GLBS(ppi)->frgn_rec_num; i++)
/* Find Erbest, 9.3.2.3 */
for (i = 1, best = 0; i < ppi->frgn_rec_num; i++)
if (bmc_dataset_cmp(ppi, &frgn_master[i], &frgn_master[best])
< 0)
best = i;
pp_diag(ppi, bmc, 1,"Best foreign master is %i\n", best);
GLBS(ppi)->frgn_rec_best = best;
ppi->frgn_rec_best = best;
return bmc_state_decision(ppi, &frgn_master[best]);
}
......@@ -45,8 +45,8 @@ int st_com_execute_slave(struct pp_instance *ppi)
return ret;
if (pp_timeout_z(ppi, PP_TO_ANN_RECEIPT)) {
GLBS(ppi)->frgn_rec_num = 0;
GLBS(ppi)->frgn_rec_i = 0;
ppi->frgn_rec_num = 0;
ppi->frgn_rec_i = 0;
if (!DSDEF(ppi)->slaveOnly &&
DSDEF(ppi)->clockQuality.clockClass != 255) {
m1(ppi);
......@@ -66,38 +66,38 @@ static void st_com_add_foreign(struct pp_instance *ppi, unsigned char *buf)
MsgHeader *hdr = &ppi->received_ptp_header;
/* Check if foreign master is already known */
for (i = 0; i < GLBS(ppi)->frgn_rec_num; i++) {
for (i = 0; i < ppi->frgn_rec_num; i++) {
if (!memcmp(&hdr->sourcePortIdentity,
&GLBS(ppi)->frgn_master[i].port_id,
&ppi->frgn_master[i].port_id,
sizeof(hdr->sourcePortIdentity))) {
/* already in Foreign master data set, update info */
msg_copy_header(&GLBS(ppi)->frgn_master[i].hdr, hdr);
msg_unpack_announce(buf, &GLBS(ppi)->frgn_master[i].ann);
msg_copy_header(&ppi->frgn_master[i].hdr, hdr);
msg_unpack_announce(buf, &ppi->frgn_master[i].ann);
return;
}
}
/* New foreign master */
if (GLBS(ppi)->frgn_rec_num < PP_NR_FOREIGN_RECORDS)
GLBS(ppi)->frgn_rec_num++;
if (ppi->frgn_rec_num < PP_NR_FOREIGN_RECORDS)
ppi->frgn_rec_num++;
/* FIXME: replace the worst */
i = GLBS(ppi)->frgn_rec_i;
i = ppi->frgn_rec_i;
/* Copy new foreign master data set from announce message */
memcpy(&GLBS(ppi)->frgn_master[i].port_id,
memcpy(&ppi->frgn_master[i].port_id,
&hdr->sourcePortIdentity, sizeof(hdr->sourcePortIdentity));
/*
* header and announce field of each Foreign Master are
* useful to run Best Master Clock Algorithm
*/
msg_copy_header(&GLBS(ppi)->frgn_master[i].hdr, hdr);
msg_unpack_announce(buf, &GLBS(ppi)->frgn_master[i].ann);
msg_copy_header(&ppi->frgn_master[i].hdr, hdr);
msg_unpack_announce(buf, &ppi->frgn_master[i].ann);
pp_diag(ppi, bmc, 2, "New foreign Master added\n");
GLBS(ppi)->frgn_rec_i = (GLBS(ppi)->frgn_rec_i+1) %
ppi->frgn_rec_i = (ppi->frgn_rec_i+1) %
PP_NR_FOREIGN_RECORDS;
}
......
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