config: convert the fault interval options to the new scheme.

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 <richardcochran@gmail.com>
master
Richard Cochran 2015-08-15 18:44:31 +02:00
parent 76f8d5eb48
commit bbd8d62bec
4 changed files with 47 additions and 44 deletions

View File

@ -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),
@ -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;
int i, val;
const char *str, *fault_options[2] = {
"fault_badpeernet_interval",
"fault_reset_interval",
};
int fault_values[2] = {
0, FRI_ASAP,
};
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
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,
@ -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;
@ -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;

1
ds.h
View File

@ -116,7 +116,6 @@ struct portDS {
#define FRI_ASAP (-128)
struct port_defaults {
struct fault_interval flt_interval_pertype[FT_CNT];
};
#endif

18
port.c
View File

@ -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 */
@ -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;
}
@ -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;
@ -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"));

View File

@ -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;
@ -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];