Use the management message memory layout for the defaultDS.

Reforming the data structure in this way will greatly simplify the
implementation of the management message for this data set.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-11-30 21:52:37 +01:00
parent b26a36d493
commit d60ccc7484
6 changed files with 55 additions and 33 deletions

17
clock.c
View File

@ -67,6 +67,8 @@ struct clock {
int fault_fd[CLK_N_PORTS];
time_t fault_timeout;
int nports; /* does not include the UDS port */
int free_running;
int freq_est_interval;
int utc_timescale;
tmv_t master_offset;
tmv_t path_delay;
@ -398,7 +400,7 @@ UInteger8 clock_class(struct clock *c)
}
struct clock *clock_create(int phc_index, struct interface *iface, int count,
enum timestamp_type timestamping, struct defaultDS *ds,
enum timestamp_type timestamping, struct default_ds *dds,
enum servo_type servo)
{
int i, fadj = 0, max_adj = 0.0, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0;
@ -415,7 +417,10 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count,
if (c->nports)
clock_destroy(c);
if (c->dds.free_running) {
c->free_running = dds->free_running;
c->freq_est_interval = dds->freq_est_interval;
if (c->free_running) {
c->clkid = CLOCK_INVALID;
} else if (phc_index >= 0) {
snprintf(phc, 31, "/dev/ptp%d", phc_index);
@ -449,7 +454,7 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count,
return NULL;
}
c->dds = *ds;
c->dds = dds->dds;
/* Initialize the parentDS. */
clock_update_grandmaster(c);
@ -788,7 +793,7 @@ void clock_remove_fda(struct clock *c, struct port *p, struct fdarray fda)
int clock_slave_only(struct clock *c)
{
return c->dds.slaveOnly;
return c->dds.flags & DDS_SLAVE_ONLY;
}
UInteger16 clock_steps_removed(struct clock *c)
@ -828,7 +833,7 @@ enum servo_state clock_synchronize(struct clock *c,
if (!c->path_delay)
return state;
if (c->dds.free_running)
if (c->free_running)
return clock_no_adjust(c);
adj = servo_sample(c->servo, c->master_offset, ingress, &state);
@ -853,7 +858,7 @@ enum servo_state clock_synchronize(struct clock *c,
void clock_sync_interval(struct clock *c, int n)
{
int shift = c->dds.freq_est_interval - n;
int shift = c->freq_est_interval - n;
if (shift < 0)
shift = 0;

View File

@ -65,12 +65,12 @@ UInteger8 clock_class(struct clock *c);
* @param interface An array of network interfaces.
* @param count The number of elements in @a interfaces.
* @param timestamping The timestamping mode for this clock.
* @param ds A pointer to a default data set for the clock.
* @param dds A pointer to a default data set for the clock.
* @param servo The servo that this clock will use.
* @return A pointer to the single global clock instance.
*/
struct clock *clock_create(int phc_index, struct interface *iface, int count,
enum timestamp_type timestamping, struct defaultDS *ds,
enum timestamp_type timestamping, struct default_ds *dds,
enum servo_type servo);
/**

View File

@ -153,7 +153,7 @@ static enum parser_result parse_global_setting(const char *option,
UInteger8 u8;
unsigned char mac[MAC_LEN];
struct defaultDS *dds = &cfg->dds;
struct defaultDS *dds = &cfg->dds.dds;
struct port_defaults *pod = &cfg->pod;
enum parser_result r;
@ -165,13 +165,20 @@ static enum parser_result parse_global_setting(const char *option,
if (!strcmp(option, "twoStepFlag")) {
if (1 != sscanf(value, "%d", &val))
return BAD_VALUE;
dds->twoStepFlag = val ? 1 : 0;
if (val)
dds->flags |= DDS_TWO_STEP_FLAG;
else
dds->flags &= ~DDS_TWO_STEP_FLAG;
} else if (!strcmp(option, "slaveOnly")) {
if (1 != sscanf(value, "%d", &val))
return BAD_VALUE;
if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY))
dds->slaveOnly = val ? 1 : 0;
if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY)) {
if (val)
dds->flags |= DDS_SLAVE_ONLY;
else
dds->flags &= ~DDS_SLAVE_ONLY;
}
} else if (!strcmp(option, "priority1")) {
if (1 != sscanf(value, "%hhu", &u8))
@ -207,12 +214,12 @@ static enum parser_result parse_global_setting(const char *option,
} else if (!strcmp(option, "free_running")) {
if (1 != sscanf(value, "%d", &val))
return BAD_VALUE;
dds->free_running = val ? 1 : 0;
cfg->dds.free_running = val ? 1 : 0;
} else if (!strcmp(option, "freq_est_interval")) {
if (1 != sscanf(value, "%d", &val) || !(val >= 0))
return BAD_VALUE;
dds->freq_est_interval = val;
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;
} else if (!strcmp(option, "assume_two_step")) {

View File

@ -58,7 +58,7 @@ struct config {
enum transport_type transport;
enum delay_mechanism dm;
struct defaultDS dds;
struct default_ds dds;
struct port_defaults pod;
int *assume_two_step;
int *tx_timestamp_retries;

16
ds.h
View File

@ -24,17 +24,25 @@
/* clock data sets */
#define DDS_TWO_STEP_FLAG (1<<0)
#define DDS_SLAVE_ONLY (1<<1)
struct defaultDS {
Boolean twoStepFlag;
Boolean slaveOnly;
UInteger8 flags;
UInteger8 reserved1;
UInteger16 numberPorts;
UInteger8 priority1;
struct ClockQuality clockQuality;
UInteger8 priority2;
struct ClockIdentity clockIdentity;
UInteger8 domainNumber;
int free_running;
int freq_est_interval; /*log seconds*/
UInteger8 reserved2;
} PACKED;
struct default_ds {
struct defaultDS dds;
int free_running;
int freq_est_interval; /*log seconds*/
};
struct dataset {

30
ptp4l.c
View File

@ -40,14 +40,15 @@ static int running = 1;
static struct config cfg_settings = {
.dds = {
.twoStepFlag = TRUE,
.slaveOnly = FALSE,
.priority1 = 128,
.clockQuality.clockClass = 248,
.clockQuality.clockAccuracy = 0xfe,
.clockQuality.offsetScaledLogVariance = 0xffff,
.priority2 = 128,
.domainNumber = 0,
.dds = {
.flags = DDS_TWO_STEP_FLAG,
.priority1 = 128,
.clockQuality.clockClass = 248,
.clockQuality.clockAccuracy = 0xfe,
.clockQuality.offsetScaledLogVariance = 0xffff,
.priority2 = 128,
.domainNumber = 0,
},
.free_running = 0,
.freq_est_interval = 1,
},
@ -137,7 +138,7 @@ int main(int argc, char *argv[])
enum transport_type *transport = &cfg_settings.transport;
enum timestamp_type *timestamping = &cfg_settings.timestamping;
struct clock *clock;
struct defaultDS *ds = &cfg_settings.dds;
struct defaultDS *ds = &cfg_settings.dds.dds;
int phc_index = -1, required_modes = 0;
if (SIG_ERR == signal(SIGINT, handle_int_quit_term)) {
@ -205,7 +206,7 @@ int main(int argc, char *argv[])
req_phc = optarg;
break;
case 's':
ds->slaveOnly = TRUE;
ds->flags |= DDS_SLAVE_ONLY;
*cfg_ignore |= CFG_IGNORE_SLAVEONLY;
break;
case 'l':
@ -235,7 +236,7 @@ int main(int argc, char *argv[])
if (config && (c = config_read(config, &cfg_settings))) {
return c;
}
if (ds->slaveOnly) {
if (ds->flags & DDS_SLAVE_ONLY) {
ds->clockQuality.clockClass = 255;
}
@ -256,7 +257,7 @@ int main(int argc, char *argv[])
return -1;
}
if (!ds->twoStepFlag) {
if (!(ds->flags & DDS_TWO_STEP_FLAG)) {
switch (*timestamping) {
case TS_SOFTWARE:
case TS_LEGACY_HW:
@ -302,7 +303,7 @@ int main(int argc, char *argv[])
}
/* determine PHC Clock index */
if (ds->free_running) {
if (cfg_settings.dds.free_running) {
phc_index = -1;
} else if (*timestamping == TS_SOFTWARE || *timestamping == TS_LEGACY_HW) {
phc_index = -1;
@ -330,7 +331,8 @@ int main(int argc, char *argv[])
}
clock = clock_create(phc_index, iface, cfg_settings.nports,
*timestamping, ds, cfg_settings.clock_servo);
*timestamping, &cfg_settings.dds,
cfg_settings.clock_servo);
if (!clock) {
fprintf(stderr, "failed to create a clock\n");
return -1;