From: <wow...@us...> - 2013-11-19 14:16:35
|
Revision: 424 http://sourceforge.net/p/ptpd/code/424 Author: wowczarek Date: 2013-11-19 14:16:26 +0000 (Tue, 19 Nov 2013) Log Message: ----------- Last minute bug fixes + version tag updates to 2.3.0 - Fix for bug #59 - added ability to sync RTC on clock step - Fix for bug #60 - added ability to send periodic IGMP joins when in master state - fixes issue with link flap causing a port to remain in master state forever - Added ability to clear counters on SIGUSR2 - Ptpd can now only step clock on SIGUSR1 when in slave state - Added ability to apply an arbitrary offset to offset from master to allow calibration Modified Paths: -------------- trunk/configure.ac trunk/m4/version.m4 trunk/packagebuild/rpm-rh/ptpd.spec trunk/src/constants.h trunk/src/datatypes.h trunk/src/dep/daemonconfig.c trunk/src/dep/ipv4_acl.c trunk/src/dep/ptpd_dep.h trunk/src/dep/servo.c trunk/src/dep/startup.c trunk/src/dep/sys.c trunk/src/protocol.c trunk/src/ptpd.h Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/configure.ac 2013-11-19 14:16:26 UTC (rev 424) @@ -180,7 +180,7 @@ # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h netinet/ether.h stdlib.h string.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h unistd.h glob.h sched.h utmp.h utmpx.h pcap/pcap.h pcap.h]) +AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h netinet/ether.h stdlib.h string.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h unistd.h glob.h sched.h utmp.h utmpx.h pcap/pcap.h pcap.h linux/rtc.h]) # MUST chck for cpuset AFTER the check for param as the latter needs # the former to pass the compile check. Modified: trunk/m4/version.m4 =================================================================== --- trunk/m4/version.m4 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/m4/version.m4 2013-11-19 14:16:26 UTC (rev 424) @@ -1,3 +1,3 @@ m4_define([PTPD_URL],[http://ptpd.sourceforge.net]) m4_define([RELEASE_DATE],[October, 2013]) -m4_define([VERSION_NUMBER],[2.3.0-RC2]) +m4_define([VERSION_NUMBER],[2.3.0]) Modified: trunk/packagebuild/rpm-rh/ptpd.spec =================================================================== --- trunk/packagebuild/rpm-rh/ptpd.spec 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/packagebuild/rpm-rh/ptpd.spec 2013-11-19 14:16:26 UTC (rev 424) @@ -12,11 +12,11 @@ Summary: Synchronises system time using the Precision Time Protocol (PTP) implementing the IEEE 1588-2008 (PTP v 2) standard Name: ptpd Version: 2.3.0 -Release: 0.99.rc2%{distver} +Release: 1%{distver} License: distributable Group: System Environment/Daemons Vendor: PTPd project team -Source0: ptpd-2.3.0-RC2.tar.gz +Source0: ptpd-2.3.0.tar.gz Source1: ptpd.init Source2: ptpd.sysconfig Source3: ptpd.conf @@ -42,7 +42,7 @@ %prep -%setup -n ptpd-2.3.0-RC2 +%setup -n ptpd-2.3.0 %build Modified: trunk/src/constants.h =================================================================== --- trunk/src/constants.h 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/src/constants.h 2013-11-19 14:16:26 UTC (rev 424) @@ -27,7 +27,7 @@ #define REVISION \ ";;2.3" #define USER_VERSION \ - "2.3.0-RC2" + "2.3.0" #define USER_DESCRIPTION \ "PTPDv2" #define USER_DESCRIPTION_MAX 128 @@ -176,6 +176,7 @@ NTPD_CHECK_TIMER, NTPD_FAILOVER_TIMER, #endif + MASTER_NETREFRESH_TIMER, TIMER_ARRAY_SIZE }; Modified: trunk/src/datatypes.h =================================================================== --- trunk/src/datatypes.h 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/src/datatypes.h 2013-11-19 14:16:26 UTC (rev 424) @@ -816,6 +816,16 @@ Octet ifaceName[IFACE_NAME_LENGTH]; Boolean noResetClock; +#ifdef linux + Boolean setRtc; +#endif /* linux */ + +#ifdef DBG_SIGUSR2_DUMP_COUNTERS + Boolean clearCounters; +#endif + + Integer8 masterRefreshInterval; + Integer32 maxReset; /* Maximum number of nanoseconds to reset */ Integer32 maxDelay; /* Maximum number of nanoseconds of delay */ Integer32 origMaxDelay; /* Lower bound of nanoseconds of delay */ @@ -824,7 +834,7 @@ Boolean displayPackets; Octet unicastAddress[MAXHOSTNAMELEN]; Integer16 s; - TimeInternal inboundLatency, outboundLatency; + TimeInternal inboundLatency, outboundLatency, ofmShift; Integer16 max_foreign_records; Enumeration8 delayMechanism; Boolean offset_first_updated; Modified: trunk/src/dep/daemonconfig.c =================================================================== --- trunk/src/dep/daemonconfig.c 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/src/dep/daemonconfig.c 2013-11-19 14:16:26 UTC (rev 424) @@ -834,11 +834,20 @@ rtOpts->ttl = 64; rtOpts->delayMechanism = DEFAULT_DELAY_MECHANISM; rtOpts->noResetClock = DEFAULT_NO_RESET_CLOCK; +#ifdef HAVE_LINUX_RTC_H + rtOpts->setRtc = FALSE; +#endif /* HAVE_LINUX_RTC_H */ + +#ifdef DBG_SIGUSR2_DUMP_COUNTERS + rtOpts->clearCounters = FALSE; +#endif /* DBG_SIGUSR2_DUMP_COUNTERS */ rtOpts->statisticsLogInterval = 0; rtOpts->initial_delayreq = DEFAULT_DELAYREQ_INTERVAL; rtOpts->subsequent_delayreq = DEFAULT_DELAYREQ_INTERVAL; // this will be updated if -g is given + rtOpts->masterRefreshInterval = 60; + rtOpts->drift_recovery_method = DRIFT_KERNEL; strncpy(rtOpts->lockDirectory, DEFAULT_LOCKDIR, PATH_MAX); strncpy(rtOpts->driftFile, DEFAULT_DRIFTFILE, PATH_MAX); @@ -1164,11 +1173,18 @@ "Slave only mode (sets clock class to 255, overriding value from preset)"); CONFIG_MAP_INT( "ptpengine:inbound_latency",rtOpts->inboundLatency.nanoseconds,rtOpts->inboundLatency.nanoseconds, - "Specify latency correction for incoming packets"); + "Specify latency correction (nanoseconds) for incoming packets"); CONFIG_MAP_INT( "ptpengine:outbound_latency",rtOpts->outboundLatency.nanoseconds,rtOpts->outboundLatency.nanoseconds, - "Specify latency correction for outgoing packets"); + "Specify latency correction (nanoseconds) for outgoing packets"); + CONFIG_MAP_INT( "ptpengine:offset_shift",rtOpts->ofmShift.nanoseconds,rtOpts->ofmShift.nanoseconds, + "Apply an arbitrary shift (nanoseconds) to offset from master when\n" + " in slave state. Value can be positive or negative - useful for\n" + " correcting for of antenna latencies and IP stack latencies. This will\n" + " not be visible in the offset from master value - only in the\n" + " resulting clock correction."); + CONFIG_MAP_BOOLEAN("ptpengine:always_respect_utc_offset",rtOpts->alwaysRespectUtcOffset, rtOpts->alwaysRespectUtcOffset, "Compatibility option: In slave state, always respect UTC offset\n" " announced by best master, even if the the\n" @@ -1354,8 +1370,13 @@ "Accept SET and COMMAND management messages"); CONFIG_MAP_BOOLEAN("ptpengine:igmp_refresh",rtOpts->do_IGMP_refresh,rtOpts->do_IGMP_refresh, - "Send explicit IGMP joins between engine resets"); + "Send explicit IGMP joins between engine resets and periodically in master state"); + CONFIG_MAP_INT_RANGE("ptpengine:master_igmp_refresh_interval",rtOpts->masterRefreshInterval,rtOpts->masterRefreshInterval, + "Periodic IGMP join interval (seconds) in master state when running IPv4 multicast:\n" + " when set below 10 or when ptpengine:igmp_refresh is disabled,\n" + " this setting has no effect.",0,255); + CONFIG_MAP_INT_RANGE("ptpengine:multicast_ttl",rtOpts->ttl,rtOpts->ttl, "Multicast time to live for multicast PTP packets (ignored and set to 1\n" " for peer to peer messages)",1,64); @@ -1477,6 +1498,12 @@ #endif /* PTPD_NTPDC */ +#ifdef DBG_SIGUSR2_DUMP_COUNTERS + CONFIG_MAP_BOOLEAN("ptpengine:sigusr2_clears_counters",rtOpts->clearCounters,rtOpts->clearCounters, + "When compiled with --enable-sigusr2=counters, clear counters after dumping all counter values\n"); +#endif /* DBG_SIGUSR2_DUMP_COUNTERS */ + + /* Defining the ACLs enables ACL matching */ CONFIG_KEY_TRIGGER("ptpengine:timing_acl_permit",rtOpts->timingAclEnabled,TRUE,rtOpts->timingAclEnabled); CONFIG_KEY_TRIGGER("ptpengine:timing_acl_deny",rtOpts->timingAclEnabled,TRUE,rtOpts->timingAclEnabled); @@ -1544,6 +1571,13 @@ CONFIG_MAP_BOOLEAN("clock:no_reset",rtOpts->noResetClock,rtOpts->noResetClock, "Do not reset the clock - only slew"); +#ifdef HAVE_LINUX_RTC_H + CONFIG_MAP_BOOLEAN("clock:set_rtc_on_step",rtOpts->setRtc,rtOpts->setRtc, + "Attempt setting the RTC when stepping clock (Linux only - FreeBSD does this for us)\n" + " WARNING: this will always set the RTC to OS clock time regardless of time zones,\n" + " so this assumes that RTC runs in UTC - true on most single-boot x86 Linux systems"); +#endif /* HAVE_LINUX_RTC_H */ + CONFIG_MAP_SELECTVALUE("clock:drift_handling",rtOpts->drift_recovery_method,rtOpts->drift_recovery_method, "Observed drift handling method between servo restarts:\n" " reset: set to zero (not recommended)\n" @@ -2591,14 +2625,21 @@ COMPONENT_RESTART_REQUIRED("ptpengine:use_libpcap", PTPD_RESTART_NETWORK ); COMPONENT_RESTART_REQUIRED("ptpengine:delay_mechanism", PTPD_RESTART_PROTOCOL ); COMPONENT_RESTART_REQUIRED("ptpengine:domain", PTPD_RESTART_PROTOCOL ); -// COMPONENT_RESTART_REQUIRED("ptpengine:inbound_latency", PTPD_RESTART_NONE ); -// COMPONENT_RESTART_REQUIRED("ptpengine:outbound_latency", PTPD_RESTART_NONE ); +// COMPONENT_RESTART_REQUIRED("ptpengine:inbound_latency", PTPD_RESTART_NONE ); +// COMPONENT_RESTART_REQUIRED("ptpengine:outbound_latency", PTPD_RESTART_NONE ); +// COMPONENT_RESTART_REQUIRED("ptpengine:offset_shift", PTPD_RESTART_NONE ); + COMPONENT_RESTART_REQUIRED("ptpengine:pid_as_clock_idendity", PTPD_RESTART_PROTOCOL ); COMPONENT_RESTART_REQUIRED("ptpengine:ptp_slaveonly", PTPD_RESTART_PROTOCOL ); COMPONENT_RESTART_REQUIRED("ptpengine:log_announce_interval", PTPD_UPDATE_DATASETS ); COMPONENT_RESTART_REQUIRED("ptpengine:announce_receipt_timeout", PTPD_UPDATE_DATASETS ); COMPONENT_RESTART_REQUIRED("ptpengine:log_sync_interval", PTPD_UPDATE_DATASETS ); + COMPONENT_RESTART_REQUIRED("ptpengine:master_igmp_refresh_interval", PTPD_RESTART_PROTOCOL ); // COMPONENT_RESTART_REQUIRED("ptpengine:log_delayreq_interval_initial",PTPD_RESTART_NONE ); +#ifdef DBG_SIGUSR2_DUMP_COUNTERS +// COMPONENT_RESTART_REQUIRED("ptpengine:sigusr2_clears_counters", PTPD_RESTART_NONE ); +#endif /* DBG_SIGUSR2_DUMP_COUNTERS */ + COMPONENT_RESTART_REQUIRED("ptpengine:log_delayreq_interval", PTPD_UPDATE_DATASETS ); COMPONENT_RESTART_REQUIRED("ptpengine:log_delayreq_override", PTPD_UPDATE_DATASETS ); COMPONENT_RESTART_REQUIRED("ptpengine:foreignrecord_capacity", PTPD_RESTART_DAEMON ); @@ -2658,6 +2699,9 @@ // COMPONENT_RESTART_REQUIRED("clock:no_adjust", PTPD_RESTART_NONE ); // COMPONENT_RESTART_REQUIRED("clock:no_reset", PTPD_RESTART_NONE ); +#ifdef HAVE_LINUX_RTC_H +// COMPONENT_RESTART_REQUIRED("clock:set_rtc_on_step", PTPD_RESTART_NONE ); +#endif /* HAVE_LINUX_RTC_H */ // COMPONENT_RESTART_REQUIRED("clock:drift_file", PTPD_RESTART_NONE ); // COMPONENT_RESTART_REQUIRED("clock:drift_handling", PTPD_RESTART_NONE ); // COMPONENT_RESTART_REQUIRED("clock:max_offset_ppm", PTPD_RESTART_NONE ); Modified: trunk/src/dep/ipv4_acl.c =================================================================== --- trunk/src/dep/ipv4_acl.c 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/src/dep/ipv4_acl.c 2013-11-19 14:16:26 UTC (rev 424) @@ -343,4 +343,4 @@ clearMaskTableCounters(acl->permitEntries); clearMaskTableCounters(acl->denyEntries); -} \ No newline at end of file +} Modified: trunk/src/dep/ptpd_dep.h =================================================================== --- trunk/src/dep/ptpd_dep.h 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/src/dep/ptpd_dep.h 2013-11-19 14:16:26 UTC (rev 424) @@ -371,6 +371,9 @@ Boolean nanoSleep(TimeInternal*); void getTime(TimeInternal*); void setTime(TimeInternal*); +#ifdef linux +void setRtc(TimeInternal *); +#endif /* linux */ double getRand(void); int lockFile(int fd); int checkLockStatus(int fd, short lockType, int *lockPid); Modified: trunk/src/dep/servo.c =================================================================== --- trunk/src/dep/servo.c 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/src/dep/servo.c 2013-11-19 14:16:26 UTC (rev 424) @@ -486,6 +486,10 @@ ofm_filt->nsec_prev = ptpClock->offsetFromMaster.nanoseconds; ptpClock->offsetFromMaster.nanoseconds = ofm_filt->y; + /* Apply the offset shift */ + subTime(&ptpClock->offsetFromMaster, &ptpClock->offsetFromMaster, + &rtOpts->ofmShift); + DBGV("offset filter %d\n", ofm_filt->y); /* @@ -509,6 +513,13 @@ subTime(&newTime, &oldTime, &ptpClock->offsetFromMaster); setTime(&newTime); + +#ifdef HAVE_LINUX_RTC_H + if(rtOpts->setRtc) { + setRtc(&newTime); + } +#endif /* HAVE_LINUX_RTC_H */ + initClock(rtOpts, ptpClock); /* restoreDrift is not defined for Apple */ #ifndef __APPLE__ Modified: trunk/src/dep/startup.c =================================================================== --- trunk/src/dep/startup.c 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/src/dep/startup.c 2013-11-19 14:16:26 UTC (rev 424) @@ -147,6 +147,14 @@ NOTIFY("SIGHUP received\n"); +#ifdef RUNTIME_DEBUG + if(rtOpts->transport == UDP_IPV4 && rtOpts->ip_mode != IPMODE_UNICAST) { + DBG("SIGHUP - running an ipv4 multicast based mode, re-sending IGMP joins\n"); + netRefreshIGMP(&ptpClock->netPath, rtOpts, ptpClock); + } +#endif /* RUNTIME_DEBUG */ + + /* if we don't have a config file specified, we're done - just reopen log files*/ if(strlen(rtOpts->configFile) == 0) goto end; @@ -359,8 +367,12 @@ } if(sigusr1_received){ - WARNING("SIGUSR1 received, stepping clock to current known OFM\n"); - servo_perform_clock_step(rtOpts, ptpClock); + if(ptpClock->portState == PTP_SLAVE){ + WARNING("SIGUSR1 received, stepping clock to current known OFM\n"); + servo_perform_clock_step(rtOpts, ptpClock); + } else { + ERROR("SIGUSR1 received - will not step clock, not in PTP_SLAVE state\n"); + } sigusr1_received = 0; } @@ -404,6 +416,10 @@ INFO("** Management message ACL:\n"); dumpIpv4AccessList(ptpClock->netPath.managementAcl); } + if(rtOpts->clearCounters) { + clearCounters(ptpClock); + NOTIFY("PTP engine counters cleared\n"); + } sigusr2_received = 0; } #endif Modified: trunk/src/dep/sys.c =================================================================== --- trunk/src/dep/sys.c 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/src/dep/sys.c 2013-11-19 14:16:26 UTC (rev 424) @@ -1211,7 +1211,78 @@ } +#ifdef HAVE_LINUX_RTC_H +/* Set the RTC to the desired time time */ +void setRtc(TimeInternal *timeToSet) +{ + + static Boolean deviceFound = FALSE; + static char* rtcDev; + struct tm* tmTime; + time_t seconds; + int rtcFd; + struct stat statBuf; + + if (!deviceFound) { + if(stat("/dev/misc/rtc", &statBuf) == 0) { + rtcDev="/dev/misc/rtc\0"; + deviceFound = TRUE; + } else if(stat("/dev/rtc", &statBuf) == 0) { + rtcDev="/dev/rtc\0"; + deviceFound = TRUE; + } else if(stat("/dev/rtc0", &statBuf) == 0) { + rtcDev="/dev/rtc0\0"; + deviceFound = TRUE; + } else { + + ERROR("Could not set RTC time - no suitable rtc device found\n"); + return; + } + + if(!S_ISCHR(statBuf.st_mode)) { + ERROR("Could not set RTC time - device %s is not a character device\n", + rtcDev); + deviceFound = FALSE; + return; + } + + } + + DBGV("Usable RTC device: %s\n",rtcDev); + + if(timeToSet->seconds == 0 && timeToSet->nanoseconds==0) { + getTime(timeToSet); + } + + + + if((rtcFd = open(rtcDev, O_RDONLY)) < 0) { + PERROR("Could not set RTC time: error opening %s", rtcDev); + return; + } + + seconds = (time_t)timeToSet->seconds; + if(timeToSet->nanoseconds >= 500000) seconds++; + tmTime = gmtime(&seconds); + + DBGV("Set RTC from %d seconds to y: %d m: %d d: %d \n",timeToSet->seconds,tmTime->tm_year,tmTime->tm_mon,tmTime->tm_mday); + + if(ioctl(rtcFd, RTC_SET_TIME, tmTime) < 0) { + PERROR("Could not set RTC time on %s - ioctl failed", rtcDev); + goto cleanup; + } + + NOTIFY("Succesfully set RTC time using %s\n", rtcDev); + +cleanup: + + close(rtcFd); + +} + +#endif /* HAVE_LINUX_RTC_H */ + /* returns a double beween 0.0 and 1.0 */ double getRand(void) Modified: trunk/src/protocol.c =================================================================== --- trunk/src/protocol.c 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/src/protocol.c 2013-11-19 14:16:26 UTC (rev 424) @@ -90,8 +90,6 @@ void addForeign(Octet*,MsgHeader*,PtpClock*); -void clearCounters(PtpClock *); - /* 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 'port_state' by calling toState(), but once they are done we loop around @@ -313,6 +311,7 @@ timerStop(SYNC_INTERVAL_TIMER, ptpClock->itimer); timerStop(ANNOUNCE_INTERVAL_TIMER, ptpClock->itimer); timerStop(PDELAYREQ_INTERVAL_TIMER, ptpClock->itimer); + timerStop(MASTER_NETREFRESH_TIMER, ptpClock->itimer); break; case PTP_SLAVE: @@ -473,6 +472,13 @@ timerStart(PDELAYREQ_INTERVAL_TIMER, pow(2,ptpClock->logMinPdelayReqInterval), ptpClock->itimer); + if( rtOpts->do_IGMP_refresh && + rtOpts->transport == UDP_IPV4 && + rtOpts->ip_mode != IPMODE_UNICAST && + rtOpts->masterRefreshInterval > 9 ); + timerStart(MASTER_NETREFRESH_TIMER, + rtOpts->masterRefreshInterval, + ptpClock->itimer); ptpClock->portState = PTP_MASTER; displayStatus(ptpClock, "Now in state: "); break; @@ -902,7 +908,7 @@ DBGV("event ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES\n"); issueAnnounce(rtOpts, ptpClock); } - + if (ptpClock->delayMechanism == P2P) { if (timerExpired(PDELAYREQ_INTERVAL_TIMER, ptpClock->itimer)) { @@ -910,13 +916,24 @@ issuePDelayReq(rtOpts,ptpClock); } } - + + if(rtOpts->do_IGMP_refresh && + rtOpts->transport == UDP_IPV4 && + rtOpts->ip_mode != IPMODE_UNICAST && + rtOpts->masterRefreshInterval > 9 && + timerExpired(MASTER_NETREFRESH_TIMER, ptpClock->itimer)) { + DBGV("Master state periodic IGMP refresh - next in %d seconds...\n", + rtOpts->masterRefreshInterval); + netRefreshIGMP(&ptpClock->netPath, rtOpts, ptpClock); + + } + // TODO: why is handle() below expiretimer, while in slave is the opposite handle(rtOpts, ptpClock); if (ptpClock->slaveOnly || ptpClock->clockQuality.clockClass == SLAVE_ONLY_CLOCK_CLASS) toState(PTP_LISTENING, rtOpts, ptpClock); - + break; case PTP_DISABLED: Modified: trunk/src/ptpd.h =================================================================== --- trunk/src/ptpd.h 2013-11-15 21:18:42 UTC (rev 423) +++ trunk/src/ptpd.h 2013-11-19 14:16:26 UTC (rev 424) @@ -123,6 +123,9 @@ #define min(a,b) (((a)<(b))?(a):(b)) #define max(a,b) (((a)>(b))?(a):(b)) +#ifdef HAVE_LINUX_RTC_H +#include <linux/rtc.h> +#endif /* HAVE_LINUX_RTC_H */ /** \name arith.c * -Timing management and arithmetic*/ @@ -307,6 +310,7 @@ void displayCounters(const PtpClock*); void displayStatistics(const PtpClock*); +void clearCounters(PtpClock *); void msgHeader_display(const MsgHeader*); void msgAnnounce_display(const MsgAnnounce*); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |