|
From: <wow...@us...> - 2015-10-14 19:46:44
|
Revision: 593
http://sourceforge.net/p/ptpd/code/593
Author: wowczarek
Date: 2015-10-14 19:46:42 +0000 (Wed, 14 Oct 2015)
Log Message:
-----------
- added getBestMaster() function
todo: maintain a pointer to best master
- master source addresses now maintained
in the FMR: fixes master IP display bug
where old master IP is displayed when
changing master as a result of current
master's announce
Modified Paths:
--------------
trunk/src/bmc.c
trunk/src/datatypes.h
trunk/src/dep/net.c
trunk/src/protocol.c
trunk/src/ptpd.h
Modified: trunk/src/bmc.c
===================================================================
--- trunk/src/bmc.c 2015-10-14 16:50:33 UTC (rev 592)
+++ trunk/src/bmc.c 2015-10-14 19:46:42 UTC (rev 593)
@@ -623,7 +623,7 @@
}
if (newBM) {
- ptpClock->masterAddr = ptpClock->netPath.lastSourceAddr;
+ ptpClock->masterAddr = getBestMaster(ptpClock)->sourceAddr;
displayPortIdentity(&header->sourcePortIdentity,
"New best master selected:");
@@ -658,7 +658,7 @@
} else if (comp > 0) {
s1(header,announce,ptpClock, rtOpts);
if (newBM) {
- ptpClock->masterAddr = ptpClock->netPath.lastSourceAddr;
+ ptpClock->masterAddr = getBestMaster(ptpClock)->sourceAddr;
displayPortIdentity(&header->sourcePortIdentity,
"New best master selected:");
ptpClock->counters.masterChanges++;
@@ -680,7 +680,7 @@
"New best master selected:");
ptpClock->counters.masterChanges++;
if(ptpClock->portState == PTP_SLAVE)
- ptpClock->masterAddr = ptpClock->netPath.lastSourceAddr;
+ ptpClock->masterAddr = getBestMaster(ptpClock)->sourceAddr;
displayStatus(ptpClock, "State: ");
if(rtOpts->calibrationDelay) {
ptpClock->isCalibrated = FALSE;
@@ -733,25 +733,11 @@
rtOpts,ptpClock));
}
+/* retrieve curent best master */
+ForeignMasterRecord
+*getBestMaster(PtpClock *ptpClock) {
+ return(&(ptpClock->foreign[ptpClock->foreign_record_best]));
-/*
+}
-13.3.2.6, page 126
-
-PTPv2 valid flags per packet type:
-
-ALL:
- .... .0.. .... .... = PTP_UNICAST
-SYNC+Pdelay Resp:
- .... ..0. .... .... = PTP_TWO_STEP
-
-Announce only:
- .... .... ..0. .... = FREQUENCY_TRACEABLE
- .... .... ...0 .... = TIME_TRACEABLE
- .... .... .... 0... = PTP_TIMESCALE
- .... .... .... .0.. = PTP_UTC_REASONABLE
- .... .... .... ..0. = PTP_LI_59
- .... .... .... ...0 = PTP_LI_61
-
-*/
Modified: trunk/src/datatypes.h
===================================================================
--- trunk/src/datatypes.h 2015-10-14 16:50:33 UTC (rev 592)
+++ trunk/src/datatypes.h 2015-10-14 19:46:42 UTC (rev 593)
@@ -495,7 +495,7 @@
MsgAnnounce announce; /* announce message -> all datasets */
MsgHeader header; /* header -> some datasets */
UInteger8 localPreference; /* local preference - only used by telecom profile */
-
+ UInteger32 sourceAddr; /* source address */
} ForeignMasterRecord;
/**
Modified: trunk/src/dep/net.c
===================================================================
--- trunk/src/dep/net.c 2015-10-14 16:50:33 UTC (rev 592)
+++ trunk/src/dep/net.c 2015-10-14 19:46:42 UTC (rev 593)
@@ -1719,6 +1719,7 @@
#endif
ret=recvfrom(netPath->generalSock, buf, PACKET_SIZE, MSG_DONTWAIT, (struct sockaddr*)&from_addr, &from_addr_len);
netPath->lastSourceAddr = from_addr.sin_addr.s_addr;
+
/* do not report "from self" */
if(!netPath->lastSourceAddr || (netPath->lastSourceAddr != netPath->interfaceAddr.s_addr)) {
netPath->receivedPackets++;
Modified: trunk/src/protocol.c
===================================================================
--- trunk/src/protocol.c 2015-10-14 16:50:33 UTC (rev 592)
+++ trunk/src/protocol.c 2015-10-14 19:46:42 UTC (rev 593)
@@ -192,7 +192,7 @@
}
-void addForeign(Octet*,MsgHeader*,PtpClock*, UInteger8);
+void addForeign(Octet*,MsgHeader*,PtpClock*, UInteger8, UInteger32);
/* loop forever. doState() has a switch for the actions and events to be
checked for 'port_state'. the actions and events may or may not change
@@ -1570,7 +1570,7 @@
}
/* save the master address for display purposes or hybrid mode */
- ptpClock->masterAddr = ptpClock->netPath.lastSourceAddr;
+ ptpClock->masterAddr = getBestMaster(ptpClock)->sourceAddr;
break;
@@ -1587,7 +1587,7 @@
* the slave will sit idle if current parent
* is not announcing, but another GM is
*/
- addForeign(ptpClock->msgIbuf,header,ptpClock,localPreference);
+ addForeign(ptpClock->msgIbuf,header,ptpClock,localPreference,ptpClock->netPath.lastSourceAddr);
break;
default:
@@ -1633,7 +1633,7 @@
/* update datasets (file bmc.c) */
s1(header,&ptpClock->msgTmp.announce,ptpClock, rtOpts);
- ptpClock->masterAddr = ptpClock->netPath.lastSourceAddr;
+ ptpClock->masterAddr = getBestMaster(ptpClock)->sourceAddr;
DBG("___ Announce: received Announce from current Master, so reset the Announce timer\n\n");
@@ -1650,7 +1650,7 @@
DBG("___ Announce: received Announce from another master, will add to the list, as it might be better\n\n");
DBGV("this is to be decided immediatly by bmc())\n\n");
- addForeign(ptpClock->msgIbuf,header,ptpClock,localPreference);
+ addForeign(ptpClock->msgIbuf,header,ptpClock,localPreference,ptpClock->netPath.lastSourceAddr);
}
break;
@@ -1668,7 +1668,7 @@
}
ptpClock->counters.announceMessagesReceived++;
DBGV("Announce message from another foreign master\n");
- addForeign(ptpClock->msgIbuf,header,ptpClock, localPreference);
+ addForeign(ptpClock->msgIbuf,header,ptpClock, localPreference,ptpClock->netPath.lastSourceAddr);
ptpClock->record_update = TRUE; /* run BMC() as soon as possible */
break;
@@ -1733,7 +1733,6 @@
if (ptpClock->syncWaiting) {
ptpClock->syncWaiting = FALSE;
-
NOTICE("Received first Sync from Master\n");
if (ptpClock->delayMechanism == E2E)
@@ -3564,7 +3563,7 @@
}
void
-addForeign(Octet *buf,MsgHeader *header,PtpClock *ptpClock, UInteger8 localPreference)
+addForeign(Octet *buf,MsgHeader *header,PtpClock *ptpClock, UInteger8 localPreference, UInteger32 sourceAddr)
{
int i,j;
Boolean found = FALSE;
@@ -3616,7 +3615,7 @@
header->sourcePortIdentity.portNumber;
ptpClock->foreign[j].foreignMasterAnnounceMessages = 0;
ptpClock->foreign[j].localPreference = localPreference;
-
+ ptpClock->foreign[j].sourceAddr = sourceAddr;
/*
* header and announce field of each Foreign Master are
* usefull to run Best Master Clock Algorithm
Modified: trunk/src/ptpd.h
===================================================================
--- trunk/src/ptpd.h 2015-10-14 16:50:33 UTC (rev 592)
+++ trunk/src/ptpd.h 2015-10-14 19:46:42 UTC (rev 593)
@@ -280,6 +280,8 @@
Boolean portIdentityEmpty(PortIdentity *portIdentity);
/* check if portIdentity is all ones */
Boolean portIdentityAllOnes(PortIdentity *portIdentity);
+/* retrieve best master */
+ForeignMasterRecord *getBestMaster(PtpClock *ptpClock);
/**
* \brief When recommended state is Master, copy local data into parent and grandmaster dataset
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|