Introduce options to set DSCP values in PTP messages.

In the last years there are several media streaming standards
evolving that are relying on PTP. These standards make requirements
about the DSCP priority of PTP messages. This patch introduces two
new configuration options 'dscp_event' and 'dscp_general' to address
that issue and to be able to set the DSCP priority separately for
PTP event messages and PTP general messages.

Signed-off-by: Henry Jesuiter <henry.jesuiter@alcnetworx.de>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Jesuiter, Henry (ALC NetworX GmbH) 2016-07-12 11:52:48 +00:00 committed by Richard Cochran
parent dc09312ce7
commit 1e667ff7fb
7 changed files with 71 additions and 0 deletions

View File

@ -180,6 +180,8 @@ struct config_item config_tab[] = {
PORT_ITEM_ENU("delay_filter", FILTER_MOVING_MEDIAN, delay_filter_enu), PORT_ITEM_ENU("delay_filter", FILTER_MOVING_MEDIAN, delay_filter_enu),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX), PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
PORT_ITEM_ENU("delay_mechanism", DM_E2E, delay_mech_enu), PORT_ITEM_ENU("delay_mechanism", DM_E2E, delay_mech_enu),
GLOB_ITEM_INT("dscp_event", 0, 0, 63),
GLOB_ITEM_INT("dscp_general", 0, 0, 63),
GLOB_ITEM_INT("domainNumber", 0, 0, 127), GLOB_ITEM_INT("domainNumber", 0, 0, 127),
PORT_ITEM_INT("egressLatency", 0, INT_MIN, 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_badpeernet_interval", 16, INT32_MIN, INT32_MAX),

View File

@ -12,6 +12,8 @@ clockAccuracy 0xFE
offsetScaledLogVariance 0xFFFF offsetScaledLogVariance 0xFFFF
free_running 0 free_running 0
freq_est_interval 1 freq_est_interval 1
dscp_event 0
dscp_general 0
# #
# Port Data Set # Port Data Set
# #

14
ptp4l.8
View File

@ -448,6 +448,20 @@ is only relevant with IPv6 transport. See RFC 4291. The default is
Specifies the address of the UNIX domain socket for receiving local Specifies the address of the UNIX domain socket for receiving local
management messages. The default is /var/run/ptp4l. management messages. The default is /var/run/ptp4l.
.TP .TP
.B dscp_event
Defines the Differentiated Services Codepoint (DSCP) to be used for PTP
event messages. Must be a value between 0 and 63. There are several media
streaming standards out there that require specific values for this option.
For example 46 (EF PHB) in AES67 or 48 (CS6 PHB) in RAVENNA. The default
is 0.
.TP
.B dscp_general
Defines the Differentiated Services Codepoint (DSCP) to be used for PTP
general messages. Must be a value between 0 and 63. There are several media
streaming standards out there that recommend specific values for this option.
For example 34 (AF41 PHB) in AES67 or 46 (EF PHB) in RAVENNA. The default
is 0.
.TP
.B logging_level .B logging_level
The maximum logging level of messages which should be printed. The maximum logging level of messages which should be printed.
The default is 6 (LOG_INFO). The default is 6 (LOG_INFO).

23
sk.c
View File

@ -298,6 +298,29 @@ int sk_receive(int fd, void *buf, int buflen,
return cnt; return cnt;
} }
int sk_set_priority(int fd, uint8_t dscp)
{
int tos;
socklen_t tos_len;
tos_len = sizeof(tos);
if (getsockopt(fd, SOL_IP, IP_TOS, &tos, &tos_len) < 0) {
tos = 0;
}
/* clear old DSCP value */
tos &= ~0xFC;
/* set new DSCP value */
tos |= dscp<<2;
tos_len = sizeof(tos);
if (setsockopt(fd, SOL_IP, IP_TOS, &tos, tos_len) < 0) {
return -1;
}
return 0;
}
int sk_timestamping_init(int fd, const char *device, enum timestamp_type type, int sk_timestamping_init(int fd, const char *device, enum timestamp_type type,
enum transport_type transport) enum transport_type transport)
{ {

8
sk.h
View File

@ -93,6 +93,14 @@ int sk_interface_addr(const char *name, int family, struct address *addr);
int sk_receive(int fd, void *buf, int buflen, int sk_receive(int fd, void *buf, int buflen,
struct address *addr, struct hw_timestamp *hwts, int flags); struct address *addr, struct hw_timestamp *hwts, int flags);
/**
* Set DSCP value for socket.
* @param fd An open socket.
* @param dscp The desired DSCP code.
* @return Zero on success, negative on failure
*/
int sk_set_priority(int fd, uint8_t dscp);
/** /**
* Enable time stamping on a given network interface. * Enable time stamping on a given network interface.
* @param fd An open socket. * @param fd An open socket.

11
udp.c
View File

@ -157,6 +157,7 @@ static int udp_open(struct transport *t, const char *name, struct fdarray *fda,
enum timestamp_type ts_type) enum timestamp_type ts_type)
{ {
struct udp *udp = container_of(t, struct udp, t); struct udp *udp = container_of(t, struct udp, t);
uint8_t event_dscp, general_dscp;
int efd, gfd, ttl; int efd, gfd, ttl;
ttl = config_get_int(t->cfg, name, "udp_ttl"); ttl = config_get_int(t->cfg, name, "udp_ttl");
@ -186,6 +187,16 @@ static int udp_open(struct transport *t, const char *name, struct fdarray *fda,
if (sk_general_init(gfd)) if (sk_general_init(gfd))
goto no_timestamping; goto no_timestamping;
event_dscp = config_get_int(t->cfg, NULL, "dscp_event");
general_dscp = config_get_int(t->cfg, NULL, "dscp_general");
if (event_dscp && sk_set_priority(efd, event_dscp)) {
pr_warning("Failed to set event DSCP priority.");
}
if (general_dscp && sk_set_priority(gfd, general_dscp)) {
pr_warning("Failed to set general DSCP priority.");
}
fda->fd[FD_EVENT] = efd; fda->fd[FD_EVENT] = efd;
fda->fd[FD_GENERAL] = gfd; fda->fd[FD_GENERAL] = gfd;
return 0; return 0;

11
udp6.c
View File

@ -165,6 +165,7 @@ static int udp6_open(struct transport *t, const char *name, struct fdarray *fda,
enum timestamp_type ts_type) enum timestamp_type ts_type)
{ {
struct udp6 *udp6 = container_of(t, struct udp6, t); struct udp6 *udp6 = container_of(t, struct udp6, t);
uint8_t event_dscp, general_dscp;
int efd, gfd, hop_limit; int efd, gfd, hop_limit;
hop_limit = config_get_int(t->cfg, name, "udp_ttl"); hop_limit = config_get_int(t->cfg, name, "udp_ttl");
@ -196,6 +197,16 @@ static int udp6_open(struct transport *t, const char *name, struct fdarray *fda,
if (sk_general_init(gfd)) if (sk_general_init(gfd))
goto no_timestamping; goto no_timestamping;
event_dscp = config_get_int(t->cfg, NULL, "dscp_event");
general_dscp = config_get_int(t->cfg, NULL, "dscp_general");
if (event_dscp && sk_set_priority(efd, event_dscp)) {
pr_warning("Failed to set event DSCP priority.");
}
if (general_dscp && sk_set_priority(gfd, general_dscp)) {
pr_warning("Failed to set general DSCP priority.");
}
fda->fd[FD_EVENT] = efd; fda->fd[FD_EVENT] = efd;
fda->fd[FD_GENERAL] = gfd; fda->fd[FD_GENERAL] = gfd;
return 0; return 0;