Skip to content

Commit

Permalink
config: convert the fault interval options to the new scheme.
Browse files Browse the repository at this point in the history
This conversion is not straightforward due to the fact that these options
can take a value of "ASAP" or a number.  We check for the special ASAP
case in a helper function and leave the numbers to the generic code.

Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Aug 23, 2015
1 parent 76f8d5e commit bbd8d62
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 45 deletions.
66 changes: 31 additions & 35 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("fault_badpeernet_interval", 16, INT32_MIN, INT32_MAX),
PORT_ITEM_INT("fault_reset_interval", 4, INT8_MIN, INT8_MAX),
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
PORT_ITEM_INT("follow_up_info", 0, 0, 1),
GLOB_ITEM_INT("free_running", 0, 0, 1),
Expand Down Expand Up @@ -276,39 +278,35 @@ static enum parser_result parse_item(struct config *cfg,
return PARSED_OK;
}

static enum parser_result parse_pod_setting(const char *option,
const char *value,
struct port_defaults *pod)
static enum parser_result parse_fault_interval(struct config *cfg,
const char *section,
const char *option,
const char *value)
{
int val;
enum parser_result r;

if (!strcmp(option, "fault_badpeernet_interval")) {
pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].type = FTMO_LINEAR_SECONDS;
if (!strcasecmp("ASAP", value)) {
pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].val = 0;
} else {
r = get_ranged_int(value, &val, INT32_MIN, INT32_MAX);
if (r != PARSED_OK)
return r;
pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].val = val;
}

} else if (!strcmp(option, "fault_reset_interval")) {
pod->flt_interval_pertype[FT_UNSPECIFIED].type = FTMO_LOG2_SECONDS;
if (!strcasecmp("ASAP", value)) {
pod->flt_interval_pertype[FT_UNSPECIFIED].val = FRI_ASAP;
} else {
r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
if (r != PARSED_OK)
return r;
pod->flt_interval_pertype[FT_UNSPECIFIED].val = val;
}

} else
int i, val;
const char *str, *fault_options[2] = {
"fault_badpeernet_interval",
"fault_reset_interval",
};
int fault_values[2] = {
0, FRI_ASAP,
};

if (strcasecmp("ASAP", value)) {
return NOT_PARSED;

return PARSED_OK;
}
for (i = 0; i < 2; i++) {
str = fault_options[i];
val = fault_values[i];
if (!strcmp(option, str)) {
if (config_set_section_int(cfg, section, str, val)) {
pr_err("bug: failed to set option %s!", option);
exit(-1);
}
return PARSED_OK;
}
}
return NOT_PARSED;
}

static enum parser_result parse_port_setting(struct config *cfg,
Expand All @@ -318,7 +316,7 @@ static enum parser_result parse_port_setting(struct config *cfg,
{
enum parser_result r;

r = parse_pod_setting(option, value, &iface->pod);
r = parse_fault_interval(cfg, iface->name, option, value);
if (r != NOT_PARSED)
return r;

Expand Down Expand Up @@ -389,11 +387,9 @@ static enum parser_result parse_global_setting(const char *option,
unsigned char oui[OUI_LEN];

struct defaultDS *dds = &cfg->dds.dds;
struct port_defaults *pod = &cfg->pod;

enum parser_result r;

r = parse_pod_setting(option, value, pod);
r = parse_fault_interval(cfg, NULL, option, value);
if (r != NOT_PARSED)
return r;

Expand Down
1 change: 0 additions & 1 deletion ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
struct fault_interval flt_interval_pertype[FT_CNT];
};

#endif
18 changes: 16 additions & 2 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ struct port {
int path_trace_enabled;
int rx_timestamp_offset;
int tx_timestamp_offset;
struct fault_interval flt_interval_pertype[FT_CNT];
enum fault_type last_fault_type;
unsigned int versionNumber; /*UInteger4*/
/* foreignMasterDS */
Expand Down Expand Up @@ -202,8 +203,8 @@ int fault_interval(struct port *port, enum fault_type ft,
return -EINVAL;
if (ft < 0 || ft >= FT_CNT)
return -EINVAL;
i->type = port->pod.flt_interval_pertype[ft].type;
i->val = port->pod.flt_interval_pertype[ft].val;
i->type = port->flt_interval_pertype[ft].type;
i->val = port->flt_interval_pertype[ft].val;
return 0;
}

Expand Down Expand Up @@ -2506,6 +2507,7 @@ struct port *port_open(int phc_index,
{
struct config *cfg = clock_config(clock);
struct port *p = malloc(sizeof(*p));
int i;

if (!p)
return NULL;
Expand Down Expand Up @@ -2551,6 +2553,18 @@ struct port *port_open(int phc_index,
p->delayMechanism = interface->dm;
p->versionNumber = PTP_VERSION;

/* Set fault timeouts to a default value */
for (i = 0; i < FT_CNT; i++) {
p->flt_interval_pertype[i].type = FTMO_LOG2_SECONDS;
p->flt_interval_pertype[i].val = 4;
}
p->flt_interval_pertype[FT_BAD_PEER_NETWORK].type = FTMO_LINEAR_SECONDS;
p->flt_interval_pertype[FT_BAD_PEER_NETWORK].val =
config_get_int(cfg, p->name, "fault_badpeernet_interval");

p->flt_interval_pertype[FT_UNSPECIFIED].val =
config_get_int(cfg, p->name, "fault_reset_interval");

p->tsproc = tsproc_create(interface->tsproc_mode,
interface->delay_filter,
config_get_int(cfg, p->name, "delay_filter_length"));
Expand Down
8 changes: 1 addition & 7 deletions ptp4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
char *config = NULL, *req_phc = NULL, *progname;
int c, i;
int c;
struct interface *iface;
int *cfg_ignore = &cfg_settings.cfg_ignore;
enum delay_mechanism *dm = &cfg_settings.dm;
Expand All @@ -136,12 +136,6 @@ int main(int argc, char *argv[])
return -1;
}

/* Set fault timeouts to a default value */
for (i = 0; i < FT_CNT; i++) {
cfg_settings.pod.flt_interval_pertype[i].type = FTMO_LOG2_SECONDS;
cfg_settings.pod.flt_interval_pertype[i].val = 4;
}

/* Process the command line arguments. */
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
Expand Down

0 comments on commit bbd8d62

Please sign in to comment.