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 'tos_event' and 'tos_general' to address that issue and to be able to set the DSCP priority separately for PTP event messages and PTP general messages.
[ RC: - Changed sk.c method to operate on a single socket. - Arranged new sk.c method in alphabetical order. ] [HJ: - renamed 'tos_*' config options to 'dhcp_*'] Signed-off-by: Henry Jesuiter <henry.jesui...@alcnetworx.de> Signed-off-by: Richard Cochran <richardcoch...@gmail.com> --- config.c | 2 ++ default.cfg | 2 ++ ptp4l.8 | 14 ++++++++++++++ sk.c | 23 +++++++++++++++++++++++ sk.h | 8 ++++++++ udp.c | 11 +++++++++++ udp6.c | 11 +++++++++++ 7 files changed, 71 insertions(+) diff -rwbBu -p a/config.c b/config.c --- a/config.c 2016-07-12 13:37:59.373539521 +0200 +++ b/config.c 2016-07-12 13:44:52.198468963 +0200 @@ -180,6 +180,8 @@ struct config_item config_tab[] = { PORT_ITEM_ENU("delay_filter", FILTER_MOVING_MEDIAN, delay_filter_enu), PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX), PORT_ITEM_ENU("delay_mechanism", DM_E2E, delay_mech_enu), + GLOB_ITEM_INT("dhcp_event", 0, 0, 63), + GLOB_ITEM_INT("dhcp_general", 0, 0, 63), GLOB_ITEM_INT("domainNumber", 0, 0, 127), PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX), PORT_ITEM_INT("fault_badpeernet_interval", 16, INT32_MIN, INT32_MAX), diff -rwbBu -p a/default.cfg b/default.cfg --- a/default.cfg 2016-07-12 13:37:59.373539521 +0200 +++ b/default.cfg 2016-07-12 13:42:35.550239675 +0200 @@ -12,6 +12,8 @@ clockAccuracy 0xFE offsetScaledLogVariance 0xFFFF free_running 0 freq_est_interval 1 +dhcp_event 0 +dhcp_general 0 # # Port Data Set # diff -rwbBu -p a/ptp4l.8 b/ptp4l.8 --- a/ptp4l.8 2016-07-12 13:37:59.373539521 +0200 +++ b/ptp4l.8 2016-07-12 13:42:48.066263314 +0200 @@ -448,6 +448,20 @@ is only relevant with IPv6 transport. S Specifies the address of the UNIX domain socket for receiving local management messages. The default is /var/run/ptp4l. .TP +.B dhcp_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 dhcp_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 The maximum logging level of messages which should be printed. The default is 6 (LOG_INFO). diff -rwbBu -p a/sk.c b/sk.c --- a/sk.c 2016-07-12 13:37:59.373539521 +0200 +++ b/sk.c 2016-07-12 13:41:28.406102486 +0200 @@ -298,6 +298,29 @@ int sk_receive(int fd, void *buf, int bu 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, enum transport_type transport) { diff -rwbBu -p a/sk.h b/sk.h --- a/sk.h 2016-07-12 13:37:59.373539521 +0200 +++ b/sk.h 2016-07-12 13:41:28.406102486 +0200 @@ -94,6 +94,14 @@ int sk_receive(int fd, void *buf, int bu 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. * @param fd An open socket. * @param device The name of the network interface to configure. diff -rwbBu -p a/udp6.c b/udp6.c --- a/udp6.c 2016-07-12 13:37:59.373539521 +0200 +++ b/udp6.c 2016-07-12 13:43:44.778363475 +0200 @@ -165,6 +165,7 @@ static int udp6_open(struct transport *t enum timestamp_type ts_type) { struct udp6 *udp6 = container_of(t, struct udp6, t); + uint8_t event_dscp, general_dscp; int efd, gfd, hop_limit; hop_limit = config_get_int(t->cfg, name, "udp_ttl"); @@ -196,6 +197,16 @@ static int udp6_open(struct transport *t if (sk_general_init(gfd)) goto no_timestamping; + event_dscp = config_get_int(t->cfg, NULL, "dhcp_event"); + general_dscp = config_get_int(t->cfg, NULL, "dhcp_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_GENERAL] = gfd; return 0; diff -rwbBu -p a/udp.c b/udp.c --- a/udp.c 2016-07-12 13:37:59.373539521 +0200 +++ b/udp.c 2016-07-12 13:43:14.546311464 +0200 @@ -157,6 +157,7 @@ static int udp_open(struct transport *t, enum timestamp_type ts_type) { struct udp *udp = container_of(t, struct udp, t); + uint8_t event_dscp, general_dscp; int efd, gfd, ttl; ttl = config_get_int(t->cfg, name, "udp_ttl"); @@ -186,6 +187,16 @@ static int udp_open(struct transport *t, if (sk_general_init(gfd)) goto no_timestamping; + event_dscp = config_get_int(t->cfg, NULL, "dhcp_event"); + general_dscp = config_get_int(t->cfg, NULL, "dhcp_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_GENERAL] = gfd; return 0; --- ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports.http://sdm.link/zohodev2dev _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel