Add possibility to set clockIdentity

Currently the clockIdentity is generated from the mac address of the first
interface/port in config file. This patch add the possibility to set it in
config file.
The reason is if the stack is restarted with a different set of ports, it
may be circumstances when clockIdentity needs to be equal as before
restart even if the port setup is different.

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
master
Anders Selhammer 2018-09-14 11:14:58 +02:00 committed by Richard Cochran
parent 1173e774dd
commit 57b98c216a
5 changed files with 47 additions and 3 deletions

16
clock.c
View File

@ -988,9 +988,19 @@ struct clock *clock_create(enum clock_type type, struct config *config,
pr_info("selected /dev/ptp%d as PTP clock", phc_index); pr_info("selected /dev/ptp%d as PTP clock", phc_index);
} }
if (generate_clock_identity(&c->dds.clockIdentity, iface->name)) { if (strcmp(config_get_string(config, NULL, "clockIdentity"),
pr_err("failed to generate a clock identity"); "000000.0000.000000") == 0) {
return NULL; if (generate_clock_identity(&c->dds.clockIdentity,
iface->name)) {
pr_err("failed to generate a clock identity");
return NULL;
}
} else {
if (str2cid(config_get_string(config, NULL, "clockIdentity"),
&c->dds.clockIdentity)) {
pr_err("failed to set clock identity");
return NULL;
}
} }
/* Configure the UDS. */ /* Configure the UDS. */

View File

@ -202,6 +202,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1), GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX), GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX),
GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX), GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
GLOB_ITEM_STR("clockIdentity", "000000.0000.000000"),
GLOB_ITEM_ENU("clock_servo", CLOCK_SERVO_PI, clock_servo_enu), GLOB_ITEM_ENU("clock_servo", CLOCK_SERVO_PI, clock_servo_enu),
GLOB_ITEM_ENU("clock_type", CLOCK_TYPE_ORDINARY, clock_type_enu), GLOB_ITEM_ENU("clock_type", CLOCK_TYPE_ORDINARY, clock_type_enu),
GLOB_ITEM_ENU("dataset_comparison", DS_CMP_IEEE1588, dataset_comp_enu), GLOB_ITEM_ENU("dataset_comparison", DS_CMP_IEEE1588, dataset_comp_enu),

View File

@ -395,6 +395,15 @@ The clockAccuracy attribute of the local clock. It is used in the best master
selection algorithm. selection algorithm.
The default is 0xFE. The default is 0xFE.
.TP .TP
.B clockIdentity
The clockIdentity attribute of the local clock.
The clockIdentity is an 8-octet array and should in this configuration be
written in textual form, see default. It should be unique since it is used to
identify the specific clock.
If default is used or if not set at all, the clockIdentity will be automtically
generated.
The default is "000000.0000.000000"
.TP
.B offsetScaledLogVariance .B offsetScaledLogVariance
The offsetScaledLogVariance attribute of the local clock. It characterizes the The offsetScaledLogVariance attribute of the local clock. It characterizes the
stability of the clock. stability of the clock.

15
util.c
View File

@ -218,6 +218,21 @@ int str2mac(const char *s, unsigned char mac[MAC_LEN])
return 0; return 0;
} }
int str2cid(const char *s, struct ClockIdentity *result)
{
struct ClockIdentity cid;
unsigned char *ptr = cid.id;
int c;
c = sscanf(s, " %02hhx%02hhx%02hhx.%02hhx%02hhx.%02hhx%02hhx%02hhx",
&ptr[0], &ptr[1], &ptr[2], &ptr[3],
&ptr[4], &ptr[5], &ptr[6], &ptr[7]);
if (c == 8) {
*result = cid;
return 0;
}
return -1;
}
int str2pid(const char *s, struct PortIdentity *result) int str2pid(const char *s, struct PortIdentity *result)
{ {
struct PortIdentity pid; struct PortIdentity pid;

9
util.h
View File

@ -133,6 +133,15 @@ int str2addr(enum transport_type type, const char *s, struct address *addr);
*/ */
int str2mac(const char *s, unsigned char mac[MAC_LEN]); int str2mac(const char *s, unsigned char mac[MAC_LEN]);
/**
* Scan a string containing a clock identity and convert it into binary form.
*
* @param s String in human readable form.
* @param result Pointer to a buffer to hold the result.
* @return Zero on success, or -1 if the string is incorrectly formatted.
*/
int str2cid(const char *s, struct ClockIdentity *result);
/** /**
* Scan a string containing a port identity and convert it into binary form. * Scan a string containing a port identity and convert it into binary form.
* *