Example #1
0
int main(int argc, char **argv)
{
   PtpPortDS *ptpPortDS;
   PtpClockDS ptpClockDS;
   Integer16 ret;

   /* start netif */
   if( !netStartup())
     return -1;

   /*Initialize run time options with command line arguments*/
   if( !(ptpPortDS = ptpdStartup(argc, argv, &ret, &rtOpts, &ptpClockDS)) )
     return ret;
    
   ptpd_init_exports();//from Tomeks'
   
   /* initialize data sets common to entire boundary clock*/
   initDataClock(&rtOpts, &ptpClockDS);
   
   /* show the options you are starting with*/
   displayConfigINFO(&rtOpts);
	
    /* do the protocol engine */
   if(rtOpts.portNumber > 0) 
     multiProtocol(&rtOpts, ptpPortDS); //forever loop for any number of ports
   else
     ptpdShutdown();

  return 1;
}
Example #2
0
int wrc_ptp_init()
{
	Integer16 ret;

	netStartup();

	ptpPortDS = ptpdStartup(0, NULL, &ret, &rtOpts, &ptpClockDS);
	initDataClock(&rtOpts, &ptpClockDS);

	//initialize sockets
	if (!netInit(&ptpPortDS->netPath, &rtOpts, ptpPortDS)) {
		PTPD_TRACE(TRACE_WRPC, NULL, "failed to initialize network\n");
		return -1;
	}

	ptpPortDS->linkUP = FALSE;
	ptp_enabled = 0;
	return 0;
}
Example #3
0
int
main(int argc, char **argv)
{
	PtpClock *ptpClock;
	Integer16 ret;

	/* initialize run-time options to reasonable values */
	rtOpts.syncInterval = DEFAULT_SYNC_INTERVAL;
	memcpy(rtOpts.subdomainName, DEFAULT_PTP_DOMAIN_NAME, PTP_SUBDOMAIN_NAME_LENGTH);
	memcpy(rtOpts.clockIdentifier, IDENTIFIER_DFLT, PTP_CODE_STRING_LENGTH);
	rtOpts.clockVariance = DEFAULT_CLOCK_VARIANCE;
	rtOpts.clockStratum = DEFAULT_CLOCK_STRATUM;
	rtOpts.unicastAddress[0] = 0;
	rtOpts.inboundLatency.nanoseconds = DEFAULT_INBOUND_LATENCY;
	rtOpts.outboundLatency.nanoseconds = DEFAULT_OUTBOUND_LATENCY;
	rtOpts.noResetClock = DEFAULT_NO_RESET_CLOCK;
	rtOpts.s = DEFAULT_DELAY_S;
	rtOpts.ap = DEFAULT_AP;
	rtOpts.ai = DEFAULT_AI;
	rtOpts.max_foreign_records = DEFAULT_MAX_FOREIGN_RECORDS;
	rtOpts.currentUtcOffset = DEFAULT_UTC_OFFSET;
	rtOpts.logFd = -1;
	rtOpts.recordFP = NULL;
	rtOpts.useSysLog = FALSE;
	rtOpts.ttl = 1;
	
	if (!(ptpClock = ptpdStartup(argc, argv, &ret, &rtOpts)))
		return ret;

	if (rtOpts.probe) {
		probe(&rtOpts, ptpClock);
	} else {
		/* do the protocol engine */
		protocol(&rtOpts, ptpClock);
	}

	ptpdShutdown();

	NOTIFY("self shutdown, probably due to an error\n");
	return 1;
}
Example #4
0
File: ptpd.c Project: zhlinh/ptpd2
int
main(int argc, char **argv)
{
	PtpClock *ptpClock;
	Integer16 ret;
	TimingService *ts;

	startupInProgress = TRUE;

	/**
	 * 将所选择的时间服务器及其他服务器信息存储到@timingDomain
	 */
	memset(&timingDomain, 0, sizeof(timingDomain));
	timingDomainSetup(&timingDomain);

	timingDomain.electionLeft = 10;

	/* Initialize run time options with command line arguments */
	/**
	 * 初始化配置,存储在结构体@rtOpts中
	 */
	if (!(ptpClock = ptpdStartup(argc, argv, &ret, &rtOpts))) {
		if (ret != 0 && !rtOpts.checkConfigOnly)
			ERROR(USER_DESCRIPTION" startup failed\n");
		return ret;
	}

	/**
	 * 设置同个时间域中选举时间服务器的最大延迟,防止抖动
	 */
	timingDomain.electionDelay = rtOpts.electionDelay;

	/* configure PTP TimeService */

	timingDomain.services[0] = &ptpClock->timingService;
	ts = timingDomain.services[0];
	strncpy(ts->id, "PTP0", TIMINGSERVICE_MAX_DESC);
	ts->dataSet.priority1 = rtOpts.preferNTP;
	ts->dataSet.type = TIMINGSERVICE_PTP;
	ts->config = &rtOpts;
	ts->controller = ptpClock;
	ts->timeout = rtOpts.idleTimeout;
	ts->updateInterval = 1;
	ts->holdTime = rtOpts.ntpOptions.failoverTimeout;
	timingDomain.serviceCount = 1;

	if (rtOpts.ntpOptions.enableEngine) {
		ntpSetup(&rtOpts, ptpClock);
	} else {
	    timingDomain.serviceCount = 1;
	    timingDomain.services[1] = NULL;
	}

	timingDomain.init(&timingDomain);
	/**
	 * 定义协议的各状态更新时间为1个时间单位,即一个US_TIMER_INTERVAL(62500us)
	 */
	timingDomain.updateInterval = 1;

	startupInProgress = FALSE;

	/* global variable for message(), please see comment on top of this file */
	G_ptpClock = ptpClock;

	/* do the protocol engine */
	/**
	 * 进入基于状态机的协议实现,无限循环
	 */
	protocol(&rtOpts, ptpClock);
	/* forever loop.. */

	/* this also calls ptpd shutdown */
	timingDomain.shutdown(&timingDomain);

	NOTIFY("Self shutdown\n");

	return 1;
}