Commit 4dc9a628 authored by Sven Meier's avatar Sven Meier Committed by Adam Wujek

bmc: added debug info and changed fsm, workaround for htons

The FSM order was changed in order to leave the fsm on a state change and re-enter the fsm directly afterward,
this makes sure no state decision is overwritten by the state handling and each state dicision is handled at least once,
There seems to be an issue with htons on unaligned addresses, which is the case for stepsRemoved in an announce,
a workaround of a manual 16bit conversion was added.
parent 280580e7
......@@ -243,6 +243,7 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
ppi->next_delay = 0;
if (ppi->is_new_state)
pp_diag_fsm(ppi, ip->name, STATE_ENTER, plen);
/*
* Possibly filter out packet and maybe update port state
*/
......@@ -254,11 +255,6 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
}
}
/* run bmc independent of state, and since not message driven do this
* here 9.2.6.8 */
if (pp_timeout(ppi, PP_TO_BMC))
ppi->next_state = bmc(ppi);
if (ppi->state != ppi->next_state)
return leave_current_state(ppi);
......@@ -274,6 +270,16 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
if (ppi->state != ppi->next_state)
return leave_current_state(ppi);
/* run bmc independent of state, and since not message driven do this
* here 9.2.6.8 */
if (pp_timeout(ppi, PP_TO_BMC)) {
ppi->next_state = bmc(ppi);
/* done: if new state mark it, and enter it now (0 ms) */
if (ppi->state != ppi->next_state)
return leave_current_state(ppi);
}
pp_diag_fsm(ppi, ip->name, STATE_LOOP, 0);
/* check if the BMC timeout is the next to run */
......
......@@ -38,10 +38,10 @@
#define PP_DEFAULT_CLOCK_ACCURACY 0xFE
#define PP_DEFAULT_PRIORITY1 128
#define PP_DEFAULT_PRIORITY2 128
#define PP_DEFAULT_CLOCK_VARIANCE -4000 /* To be determined in
* 802.1AS. We use the
* same value as in ptpdv1
*/
#define PP_DEFAULT_CLOCK_VARIANCE 0x8000 /* take the middle
* between min and max
*/
#define PP_NR_FOREIGN_RECORDS 5
#define PP_FOREIGN_MASTER_TIME_WINDOW 4
#define PP_FOREIGN_MASTER_THRESHOLD 2
......
......@@ -210,22 +210,47 @@ static int bmc_gm_cmp(struct pp_instance *ppi,
qa = &aa->grandmasterClockQuality;
qb = &ab->grandmasterClockQuality;
if (aa->grandmasterPriority1 != ab->grandmasterPriority1)
if (aa->grandmasterPriority1 != ab->grandmasterPriority1) {
pp_diag(ppi, bmc, 3, "Priority1 A: %i, Priority1 B: %i\n",
aa->grandmasterPriority1, ab->grandmasterPriority1);
return aa->grandmasterPriority1 - ab->grandmasterPriority1;
}
if (qa->clockClass != qb->clockClass)
if (qa->clockClass != qb->clockClass) {
pp_diag(ppi, bmc, 3, "ClockClass A: %i, ClockClass B: %i\n",
qa->clockClass, qb->clockClass);
return qa->clockClass - qb->clockClass;
}
if (qa->clockAccuracy != qb->clockAccuracy)
if (qa->clockAccuracy != qb->clockAccuracy) {
pp_diag(ppi, bmc, 3, "ClockAccuracy A: %i, ClockAccuracy B: %i\n",
qa->clockAccuracy, qb->clockAccuracy);
return qa->clockAccuracy - qb->clockAccuracy;
}
if (qa->offsetScaledLogVariance != qb->offsetScaledLogVariance)
if (qa->offsetScaledLogVariance != qb->offsetScaledLogVariance) {
pp_diag(ppi, bmc, 3, "Variance A: %i, Variance B: %i\n",
qa->offsetScaledLogVariance, qb->offsetScaledLogVariance);
return qa->offsetScaledLogVariance
- qb->offsetScaledLogVariance;
}
if (aa->grandmasterPriority2 != ab->grandmasterPriority2)
if (aa->grandmasterPriority2 != ab->grandmasterPriority2) {
pp_diag(ppi, bmc, 3, "Priority2 A: %i, Priority2 B: %i\n",
aa->grandmasterPriority2, ab->grandmasterPriority2);
return aa->grandmasterPriority2 - ab->grandmasterPriority2;
}
pp_diag(ppi, bmc, 3, "GmId A: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x,\n"
"GmId B: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
aa->grandmasterIdentity.id[0], aa->grandmasterIdentity.id[1],
aa->grandmasterIdentity.id[2], aa->grandmasterIdentity.id[3],
aa->grandmasterIdentity.id[4], aa->grandmasterIdentity.id[5],
aa->grandmasterIdentity.id[6], aa->grandmasterIdentity.id[7],
ab->grandmasterIdentity.id[0], ab->grandmasterIdentity.id[1],
ab->grandmasterIdentity.id[2], ab->grandmasterIdentity.id[3],
ab->grandmasterIdentity.id[4], ab->grandmasterIdentity.id[5],
ab->grandmasterIdentity.id[6], ab->grandmasterIdentity.id[7]);
return idcmp(&aa->grandmasterIdentity, &ab->grandmasterIdentity);
}
......@@ -278,8 +303,11 @@ static int bmc_topology_cmp(struct pp_instance *ppi,
}
diff = aa->stepsRemoved - ab->stepsRemoved;
if (diff > 1 || diff < -1)
if (diff > 1 || diff < -1) {
pp_diag(ppi, bmc, 3, "StepsRemoved A: %i, StepsRemoved B: %i\n",
aa->stepsRemoved, ab->stepsRemoved);
return diff;
}
if (diff > 0) {
if (!pidcmp(pidtxa, pidrxa)) {
......@@ -287,6 +315,8 @@ static int bmc_topology_cmp(struct pp_instance *ppi,
__func__, __LINE__);
return 0;
}
pp_diag(ppi, bmc, 3, "StepsRemoved A: %i, StepsRemoved B: %i\n",
aa->stepsRemoved, ab->stepsRemoved);
return 1;
}
......@@ -296,15 +326,42 @@ static int bmc_topology_cmp(struct pp_instance *ppi,
__func__, __LINE__);
return 0;
}
pp_diag(ppi, bmc, 3, "StepsRemoved A: %i, StepsRemoved B: %i\n",
aa->stepsRemoved, ab->stepsRemoved);
return -1;
}
/* stepsRemoved is equal, compare identities */
diff = pidcmp(pidtxa, pidtxb);
if (diff)
if (diff) {
pp_diag(ppi, bmc, 3, "TxId A: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x.%04x,\n"
"TxId B: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x.%04x\n",
pidtxa->clockIdentity.id[0], pidtxa->clockIdentity.id[1],
pidtxa->clockIdentity.id[2], pidtxa->clockIdentity.id[3],
pidtxa->clockIdentity.id[4], pidtxa->clockIdentity.id[5],
pidtxa->clockIdentity.id[6], pidtxa->clockIdentity.id[7],
pidtxa->portNumber,
pidtxb->clockIdentity.id[0], pidtxb->clockIdentity.id[1],
pidtxb->clockIdentity.id[2], pidtxb->clockIdentity.id[3],
pidtxb->clockIdentity.id[4], pidtxb->clockIdentity.id[5],
pidtxb->clockIdentity.id[6], pidtxb->clockIdentity.id[7],
pidtxb->portNumber);
return diff;
}
/* sourcePortIdentity is equal, compare receive port identites, which
* is the last decision maker, which has to be different */
pp_diag(ppi, bmc, 3, "RxId A: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x.%04x,\n"
"RxId B: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x.%04x\n",
pidrxa->clockIdentity.id[0], pidrxa->clockIdentity.id[1],
pidrxa->clockIdentity.id[2], pidrxa->clockIdentity.id[3],
pidrxa->clockIdentity.id[4], pidrxa->clockIdentity.id[5],
pidrxa->clockIdentity.id[6], pidrxa->clockIdentity.id[7],
pidrxa->portNumber,
pidrxb->clockIdentity.id[0], pidrxb->clockIdentity.id[1],
pidrxb->clockIdentity.id[2], pidrxb->clockIdentity.id[3],
pidrxb->clockIdentity.id[4], pidrxb->clockIdentity.id[5],
pidrxb->clockIdentity.id[6], pidrxb->clockIdentity.id[7],
pidrxb->portNumber);
return pidcmp(pidrxa, pidrxb);
}
......
......@@ -115,6 +115,8 @@ static void __lib_add_foreign(struct pp_instance *ppi, unsigned char *buf)
struct pp_frgn_master frgn_master;
MsgHeader *hdr = &ppi->received_ptp_header;
pp_diag(ppi, bmc, 2, "%s\n", __func__);
/* if we are a configured master don't add*/
if (ppi->role == PPSI_ROLE_MASTER)
return;
......@@ -136,12 +138,18 @@ static void __lib_add_foreign(struct pp_instance *ppi, unsigned char *buf)
/* Check if announce from a port from this clock 9.3.2.5 a) */
if (!memcmp(&hdr->sourcePortIdentity.clockIdentity,
&DSDEF(ppi)->clockIdentity,
sizeof(DSDEF(ppi)->clockIdentity)))
sizeof(DSDEF(ppi)->clockIdentity))) {
pp_diag(ppi, bmc, 2, "Announce frame from this clock\n");
return;
}
/* Check if announce has steps removed larger than 255 9.3.2.5 d) */
if (frgn_master.ann.stepsRemoved >= 255)
if (frgn_master.ann.stepsRemoved >= 255) {
pp_diag(ppi, bmc, 2, "Announce frame steps removed"
"larger or equal 255: %i\n",
frgn_master.ann.stepsRemoved);
return;
}
/* Check if foreign master is already known */
for (i = 0; i < ppi->frgn_rec_num; i++) {
......
......@@ -211,7 +211,9 @@ void msg_unpack_announce(void *buf, MsgAnnounce *ann)
ann->grandmasterPriority2 = *(UInteger8 *) (buf + 52);
memcpy(&ann->grandmasterIdentity, (buf + 53),
PP_CLOCK_IDENTITY_LENGTH);
ann->stepsRemoved = htons(*(UInteger16 *) (buf + 61));
/* WORKAROUND htons doesn't seem to work on unaligned addresses */
ann->stepsRemoved = *(UInteger8 *)(buf + 61);
ann->stepsRemoved = (ann->stepsRemoved << 8) + *(UInteger8 *)(buf + 62);
ann->timeSource = *(Enumeration8 *) (buf + 63);
if (pp_hooks.unpack_announce)
......
......@@ -45,7 +45,7 @@ int pp_master(struct pp_instance *ppi, uint8_t *pkt, int plen)
int e = 0; /* error var, to check errors in msg handling */
pp_timeout_set(ppi, PP_TO_FAULT); /* no fault as long as we are
* passive */
* master */
/* upgrade from pre-master to master */
if (pre && pp_timeout(ppi, PP_TO_QUALIFICATION)) {
......
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