Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/7375/?format=api
https://patches.dpdk.org/api/patches/7375/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1443799208-9408-4-git-send-email-danielx.t.mrzyglod@intel.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1443799208-9408-4-git-send-email-danielx.t.mrzyglod@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1443799208-9408-4-git-send-email-danielx.t.mrzyglod@intel.com", "date": "2015-10-02T15:20:08", "name": "[dpdk-dev,3/3] example: PTP client slave minimal implementation", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "69171184a2bd22bb9366c200f5c87c8ec60f69af", "submitter": { "id": 23, "url": "https://patches.dpdk.org/api/people/23/?format=api", "name": "Daniel Mrzyglod", "email": "danielx.t.mrzyglod@intel.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1443799208-9408-4-git-send-email-danielx.t.mrzyglod@intel.com/mbox/", "series": [], "comments": "https://patches.dpdk.org/api/patches/7375/comments/", "check": "pending", "checks": "https://patches.dpdk.org/api/patches/7375/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@dpdk.org", "Delivered-To": "patchwork@dpdk.org", "Received": [ "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 3F54D8E66;\n\tFri, 2 Oct 2015 17:26:00 +0200 (CEST)", "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id 9CDC78E5A\n\tfor <dev@dpdk.org>; Fri, 2 Oct 2015 17:25:58 +0200 (CEST)", "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby orsmga102.jf.intel.com with ESMTP; 02 Oct 2015 08:25:54 -0700", "from unknown ([10.217.248.93])\n\tby orsmga002.jf.intel.com with SMTP; 02 Oct 2015 08:25:52 -0700", "by (sSMTP sendmail emulation); Fri, 02 Oct 2015 17:24:27 +0200" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.17,623,1437462000\"; d=\"scan'208\";a=\"818016268\"", "From": "Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>", "To": "dev@dpdk.org", "Date": "Fri, 2 Oct 2015 17:20:08 +0200", "Message-Id": "<1443799208-9408-4-git-send-email-danielx.t.mrzyglod@intel.com>", "X-Mailer": "git-send-email 2.1.4", "In-Reply-To": "<1443799208-9408-1-git-send-email-danielx.t.mrzyglod@intel.com>", "References": "<1443799208-9408-1-git-send-email-danielx.t.mrzyglod@intel.com>", "Subject": "[dpdk-dev] [PATCH 3/3] example: PTP client slave minimal\n\timplementation", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "patches and discussions about DPDK <dev.dpdk.org>", "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://dpdk.org/ml/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "Add a sample application that acts as a PTP slave using the\nDPDK ieee1588 functions.\n\nSigned-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>\n---\n MAINTAINERS | 3 +\n examples/Makefile | 1 +\n examples/ptpclient/Makefile | 59 +++++\n examples/ptpclient/ptpclient.c | 525 +++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 588 insertions(+)\n create mode 100644 examples/ptpclient/Makefile\n create mode 100644 examples/ptpclient/ptpclient.c", "diff": "diff --git a/MAINTAINERS b/MAINTAINERS\nindex 080a8e8..a80ce96 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -514,3 +514,6 @@ F: examples/tep_termination/\n F: examples/vmdq/\n F: examples/vmdq_dcb/\n F: doc/guides/sample_app_ug/vmdq_dcb_forwarding.rst\n+\n+M: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>\n+F: examples/ptpclient\n\\ No newline at end of file\ndiff --git a/examples/Makefile b/examples/Makefile\nindex b4eddbd..4672534 100644\n--- a/examples/Makefile\n+++ b/examples/Makefile\n@@ -74,5 +74,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_XEN_DOM0) += vhost_xen\n DIRS-y += vmdq\n DIRS-y += vmdq_dcb\n DIRS-$(CONFIG_RTE_LIBRTE_POWER) += vm_power_manager\n+DIRS-$(CONFIG_RTE_LIBRTE_IEEE1588) += ptpclient\n \n include $(RTE_SDK)/mk/rte.extsubdir.mk\ndiff --git a/examples/ptpclient/Makefile b/examples/ptpclient/Makefile\nnew file mode 100644\nindex 0000000..503339f\n--- /dev/null\n+++ b/examples/ptpclient/Makefile\n@@ -0,0 +1,59 @@\n+# BSD LICENSE\n+#\n+# Copyright(c) 2010-2015 Intel Corporation. All rights reserved.\n+# All rights reserved.\n+#\n+# Redistribution and use in source and binary forms, with or without\n+# modification, are permitted provided that the following conditions\n+# are met:\n+#\n+# * Redistributions of source code must retain the above copyright\n+# notice, this list of conditions and the following disclaimer.\n+# * Redistributions in binary form must reproduce the above copyright\n+# notice, this list of conditions and the following disclaimer in\n+# the documentation and/or other materials provided with the\n+# distribution.\n+# * Neither the name of Intel Corporation nor the names of its\n+# contributors may be used to endorse or promote products derived\n+# from this software without specific prior written permission.\n+#\n+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+\n+ifeq ($(RTE_SDK),)\n+$(error \"Please define RTE_SDK environment variable\")\n+endif\n+\n+# Default target, can be overriddegitn by command line or environment\n+RTE_TARGET ?= x86_64-native-linuxapp-gcc\n+\n+include $(RTE_SDK)/mk/rte.vars.mk\n+\n+# binary name\n+APP = ptpclient\n+\n+# all source are stored in SRCS-y\n+SRCS-y := ptpclient.c\n+#SRCS-$(CONFIG_RTE_LIBRTE_IEEE1588) := ptpclient.c\n+\n+\n+CFLAGS += $(WERROR_FLAGS)\n+\n+# workaround for a gcc bug with noreturn attribute\n+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603\n+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)\n+CFLAGS_main.o += -Wno-return-type\n+endif\n+\n+EXTRA_CFLAGS += -O3\n+\n+include $(RTE_SDK)/mk/rte.extapp.mk\ndiff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c\nnew file mode 100644\nindex 0000000..1fe8e6d\n--- /dev/null\n+++ b/examples/ptpclient/ptpclient.c\n@@ -0,0 +1,525 @@\n+/*-\n+ * BSD LICENSE\n+ *\n+ * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without\n+ * modification, are permitted provided that the following conditions\n+ * are met:\n+ *\n+ * * Redistributions of source code must retain the above copyright\n+ * notice, this list of conditions and the following disclaimer.\n+ * * Redistributions in binary form must reproduce the above copyright\n+ * notice, this list of conditions and the following disclaimer in\n+ * the documentation and/or other materials provided with the\n+ * distribution.\n+ * * Neither the name of Intel Corporation nor the names of its\n+ * contributors may be used to endorse or promote products derived\n+ * from this software without specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <stdint.h>\n+#include <inttypes.h>\n+#include <rte_eal.h>\n+#include <rte_ethdev.h>\n+#include <rte_cycles.h>\n+#include <rte_lcore.h>\n+#include <rte_mbuf.h>\n+#include <rte_ip.h>\n+\n+#define RX_RING_SIZE 128\n+#define TX_RING_SIZE 512\n+\n+#define NUM_MBUFS 8191\n+#define MBUF_CACHE_SIZE 250\n+\n+/* Values for the PTP messageType field */\n+#define SYNC 0x0\n+#define DELAY_REQ 0x1\n+#define PDELAY_REQ 0x2\n+#define PDELAY_RESP 0x3\n+#define FOLLOW_UP 0x8\n+#define DELAY_RESP 0x9\n+#define PDELAY_RESP_FOLLOW_UP 0xA\n+#define ANNOUNCE 0xB\n+#define SIGNALING 0xC\n+#define MANAGEMENT 0xD\n+\n+#define NSEC_PER_SEC 1000000000L\n+#define PTP_PROTOCOL 0x88F7\n+\n+struct rte_mempool *mbuf_pool;\n+\n+static const struct rte_eth_conf port_conf_default = {\n+\t.rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN }\n+};\n+\n+static const struct ether_addr ether_multicast = {\n+\t\t.addr_bytes = {0x01, 0x1b, 0x19, 0x0, 0x0, 0x0}\n+};\n+\n+struct ptpv2_msg {\n+\tuint8_t msg_id;\n+\tuint8_t version; /* PTP V2 only */\n+\tuint8_t unused[34];\n+};\n+\n+struct tstamp {\n+\tuint16_t seconds_msb;\n+\tuint32_t seconds_lsb;\n+\tuint32_t nanoseconds;\n+} __attribute__((packed));\n+\n+struct clock_identity {\n+\tuint8_t id[8];\n+};\n+\n+struct port_identity {\n+\tstruct clock_identity clock_identity;\n+\tuint16_t port_number;\n+} __attribute__((packed));\n+\n+struct ptp_header {\n+\tuint8_t msgtype;\n+\tuint8_t ver;\n+\tuint16_t message_length;\n+\tuint8_t domain_number;\n+\tuint8_t reserved1;\n+\tuint8_t flag_field[2];\n+\tint64_t correction;\n+\tuint32_t reserved2;\n+\tstruct port_identity source_port_identity;\n+\tuint16_t sequenceId;\n+\tuint8_t control;\n+\tint8_t log_message_interval;\n+} __attribute__((packed));\n+\n+struct sync_msg {\n+\tstruct ptp_header hdr;\n+\tstruct tstamp origin_timestamp;\n+} __attribute__((packed));\n+\n+struct follow_up_msg {\n+\tstruct ptp_header hdr;\n+\tstruct tstamp precise_origin_timestamp;\n+\tuint8_t suffix[0];\n+} __attribute__((packed));\n+\n+struct delay_req_msg {\n+\tstruct ptp_header hdr;\n+\tstruct tstamp origin_timestamp;\n+} __attribute__((packed));\n+\n+struct delay_resp_msg {\n+\tstruct ptp_header hdr;\n+\tstruct tstamp receive_timestamp;\n+\tstruct port_identity requesting_port_identity;\n+\tuint8_t suffix[0];\n+} __attribute__((packed));\n+\n+struct ptp_message {\n+\tunion {\n+\t\tstruct ptp_header header;\n+\t\tstruct sync_msg sync;\n+\t\tstruct delay_req_msg delay_req;\n+\t\tstruct follow_up_msg follow_up;\n+\t\tstruct delay_resp_msg delay_resp;\n+\t} __attribute__((packed));\n+};\n+\n+struct ptpv2_data_slave_ordinary {\n+\tstruct timespec timestamp;\n+\tstruct timespec timestamp1;\n+\tstruct timespec timestamp2;\n+\tstruct timespec timestamp3;\n+\tstruct timespec timestamp4;\n+\tint64_t delta;\n+\tuint8_t portid;\n+\tuint16_t seqID_SYNC;\n+\tuint16_t seqID_FOLLOWUP;\n+\tstruct rte_mbuf *m;\n+};\n+\n+void parse_ptp_frames(uint8_t portid, struct rte_mbuf *m);\n+void print_clock_info(struct ptpv2_data_slave_ordinary *ptp_data);\n+void parse_sync(struct ptpv2_data_slave_ordinary *ptp_data);\n+void parse_fup(struct ptpv2_data_slave_ordinary *ptp_data);\n+void parse_drsp(struct ptpv2_data_slave_ordinary *ptp_data);\n+\n+static inline uint64_t timespec64_to_ns(const struct timespec *ts)\n+{\n+\treturn ((uint64_t) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;\n+}\n+\n+/*\n+ * Initializes a given port using global settings and with the RX buffers\n+ * coming from the mbuf_pool passed as a parameter.\n+ */\n+static inline int\n+port_init(uint8_t port, struct rte_mempool *mbuf_pool)\n+{\n+\tstruct rte_eth_dev_info dev_info;\n+\tstruct rte_eth_conf port_conf = port_conf_default;\n+\tconst uint16_t rx_rings = 1;\n+\tconst uint16_t tx_rings = 1;\n+\tint retval;\n+\tuint16_t q;\n+\n+\n+\tif (port >= rte_eth_dev_count())\n+\t\treturn -1;\n+\n+\t/* Configure the Ethernet device. */\n+\tretval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);\n+\tif (retval != 0)\n+\t\treturn retval;\n+\n+\t/* Allocate and set up 1 RX queue per Ethernet port. */\n+\tfor (q = 0; q < rx_rings; q++) {\n+\t\tretval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE,\n+\t\t\t\trte_eth_dev_socket_id(port), NULL, mbuf_pool);\n+\t\tif (retval < 0)\n+\t\t\treturn retval;\n+\t}\n+\n+\t/* Allocate and set up 1 TX queue per Ethernet port. */\n+\tfor (q = 0; q < tx_rings; q++) {\n+\t\t/* Setup txq_flags */\n+\t\tstruct rte_eth_txconf *txconf;\n+\t\trte_eth_dev_info_get(q, &dev_info);\n+\t\ttxconf = &dev_info.default_txconf;\n+\t\ttxconf->txq_flags = 0;\n+\n+\t\tretval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE,\n+\t\t\t\trte_eth_dev_socket_id(port), txconf);\n+\t\tif (retval < 0)\n+\t\t\treturn retval;\n+\t}\n+\n+\t/* Start the Ethernet port. */\n+\tretval = rte_eth_dev_start(port);\n+\tif (retval < 0)\n+\t\treturn retval;\n+\n+\t/* Enable timesync timestamping for the Ethernet device */\n+\trte_eth_timesync_enable(port);\n+\n+\t/* Enable RX in promiscuous mode for the Ethernet device. */\n+\trte_eth_promiscuous_enable(port);\n+\n+\treturn 0;\n+}\n+\n+void\n+print_clock_info(struct ptpv2_data_slave_ordinary *ptp_data)\n+{\n+\tprintf(\"\\nT2 - Slave Clock. %lds %ldns\", (ptp_data->timestamp2.tv_sec),\n+\t\t\t(ptp_data->timestamp2.tv_nsec));\n+\tprintf(\"\\nT1 - Master Clock. %lds %ldns \",\n+\t\t\tptp_data->timestamp1.tv_sec,\n+\t\t\t(ptp_data->timestamp1.tv_nsec));\n+\tprintf(\"\\nT3 - Slave Clock. %lds %ldns\", ptp_data->timestamp3.tv_sec,\n+\t\t\t(ptp_data->timestamp3.tv_nsec));\n+\tprintf(\"\\nT4 - Master Clock. %lds %ldns \",\n+\t\tptp_data->timestamp4.tv_sec, (ptp_data->timestamp4.tv_nsec));\n+\tprintf(\"\\nDelta between master and slave clocks:%\"PRId64\"ns\\n\",\n+\t\t\tptp_data->delta);\n+\trte_eth_timesync_gettime(ptp_data->portid, &ptp_data->timestamp);\n+\tprintf(\"Gettime:%llds %ldns\",\n+\t\t(long long)ptp_data->timestamp.tv_sec,\n+\t\tptp_data->timestamp.tv_nsec);\n+\ttime_t tt = ptp_data->timestamp.tv_sec;\n+\tprintf(\"\\nConverted Current PTP Time: %.24s %.9ld ns \\n\", ctime(&tt), ptp_data->timestamp.tv_nsec);\n+\tprintf(\"[Ctrl+C to quit]\\n\");\n+\n+\t/* Clear screen and put cursor in column 1, row 1 */\n+\tprintf(\"\\033[2J\\033[1;1H\");\n+}\n+\n+static int64_t\n+delta_eval(struct ptpv2_data_slave_ordinary *ptp_data)\n+{\n+\tint64_t delta;\n+\tuint64_t t1 = 0;\n+\tuint64_t t2 = 0;\n+\tuint64_t t3 = 0;\n+\tuint64_t t4 = 0;\n+\n+\tt1 = timespec64_to_ns(&ptp_data->timestamp1);\n+\tt2 = timespec64_to_ns(&ptp_data->timestamp2);\n+\tt3 = timespec64_to_ns(&ptp_data->timestamp3);\n+\tt4 = timespec64_to_ns(&ptp_data->timestamp4);\n+\t/* Due to optimalisation */\n+\tdelta = (t2-t1)-(t4-t3);\n+\tdelta = delta/2;\n+\tdelta = -delta;\n+\n+\treturn delta;\n+}\n+\n+/*\n+ * Parse PTP SYNC message\n+ */\n+void\n+parse_sync(struct ptpv2_data_slave_ordinary *ptp_data)\n+{\n+\tstruct ptp_header *ptp_hdr;\n+\n+\tptp_hdr = (struct ptp_header *)(rte_pktmbuf_mtod(ptp_data->m, char *)\n+\t\t\t+ sizeof(struct ether_hdr));\n+\tptp_data->seqID_SYNC = rte_be_to_cpu_16(ptp_hdr->sequenceId);\n+\trte_eth_timesync_read_rx_timestamp(ptp_data->portid,\n+\t\t\t&ptp_data->timestamp2, 0);\n+}\n+/*\n+ * Parse PTP FOLLOWUP message & Send DELAY_REQ to master clock.\n+ */\n+void\n+parse_fup(struct ptpv2_data_slave_ordinary *ptp_data)\n+{\n+\tstruct ether_hdr *eth_hdr;\n+\tstruct ptp_header *ptp_hdr;\n+\tstruct clock_identity *client_clkid;\n+\tstruct ptp_message *ptp_msg;\n+\tstruct rte_mbuf *created_pkt;\n+\tstruct ether_addr eth_multicast = ether_multicast;\n+\tsize_t pkt_size;\n+\tint wait_us;\n+\tstruct rte_mbuf *m = ptp_data->m;\n+\n+\teth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);\n+\tptp_hdr = (struct ptp_header *)(rte_pktmbuf_mtod(m, char *)\n+\t\t\t+ sizeof(struct ether_hdr));\n+\tptp_data->seqID_FOLLOWUP = rte_be_to_cpu_16(ptp_hdr->sequenceId);\n+\tptp_msg = (struct ptp_message *)\n+\t\t\t(rte_pktmbuf_mtod(m, char *) + sizeof(struct ether_hdr));\n+\tptp_data->timestamp1.tv_nsec =\n+\t\t\tntohl(ptp_msg->follow_up.precise_origin_timestamp.nanoseconds);\n+\tptp_data->timestamp1.tv_sec =\n+\t\t((uint64_t)ntohl\n+\t\t\t\t(ptp_msg->follow_up.precise_origin_timestamp.seconds_lsb)) |\n+\t\t(((uint64_t)ntohs\n+\t\t\t\t(ptp_msg->follow_up.precise_origin_timestamp.seconds_msb))\n+\t\t\t\t<< 32);\n+\n+\tif (ptp_data->seqID_FOLLOWUP == ptp_data->seqID_SYNC) {\n+\n+\t\tcreated_pkt = rte_pktmbuf_alloc(mbuf_pool);\n+\t\tpkt_size = sizeof(struct ether_hdr) + sizeof(struct ptp_message);\n+\t\tcreated_pkt->data_len = pkt_size;\n+\t\tcreated_pkt->pkt_len = pkt_size;\n+\t\teth_hdr = rte_pktmbuf_mtod(created_pkt, struct ether_hdr *);\n+\t\trte_eth_macaddr_get(ptp_data->portid, ð_hdr->s_addr);\n+\n+\t\t/* Set multicast adress 01-1B-19-00-00-00 */\n+\t\tether_addr_copy(ð_multicast, ð_hdr->d_addr);\n+\n+\t\teth_hdr->ether_type = htons(PTP_PROTOCOL);\n+\t\tptp_msg = (struct ptp_message *)(rte_pktmbuf_mtod(created_pkt, char *) +\n+\t\t\t\t\t\t\t\t\t\tsizeof(struct ether_hdr));\n+\n+\t\tptp_msg->delay_req.hdr.sequenceId = ptp_data->seqID_SYNC;\n+\t\tptp_msg->delay_req.hdr.msgtype = DELAY_REQ;\n+\t\tptp_msg->delay_req.hdr.ver = 2;\n+\t\tptp_msg->delay_req.hdr.control = 1;\n+\t\tptp_msg->delay_req.hdr.log_message_interval = 127;\n+\n+\t\t/* Set up clock id */\n+\t\tclient_clkid = &ptp_msg->delay_req.hdr.source_port_identity.clock_identity;\n+\n+\t\tclient_clkid->id[0] = eth_hdr->s_addr.addr_bytes[0];\n+\t\tclient_clkid->id[1] = eth_hdr->s_addr.addr_bytes[1];\n+\t\tclient_clkid->id[2] = eth_hdr->s_addr.addr_bytes[2];\n+\t\tclient_clkid->id[3] = 0xFF;\n+\t\tclient_clkid->id[4] = 0xFE;\n+\t\tclient_clkid->id[5] = eth_hdr->s_addr.addr_bytes[3];\n+\t\tclient_clkid->id[6] = eth_hdr->s_addr.addr_bytes[4];\n+\t\tclient_clkid->id[7] = eth_hdr->s_addr.addr_bytes[5];\n+\n+\t\t/* Enable Flag for Hardware Timestamping */\n+\t\tcreated_pkt->ol_flags |= PKT_TX_IEEE1588_TMST;\n+\n+\t\t/* We read value from NIC to prevent latching with old value */\n+\t\trte_eth_timesync_read_tx_timestamp(ptp_data->portid, &ptp_data->timestamp3);\n+\n+\t\t/* the packet is being transmitted */\n+\t\trte_eth_tx_burst(ptp_data->portid, 0, &created_pkt, 1);\n+\n+\t\twait_us = 0;\n+\t\tptp_data->timestamp3.tv_nsec = 0;\n+\t\tptp_data->timestamp3.tv_sec = 0;\n+\n+\t\t/* we must wait at least 1us to read TX Timestamp */\n+\t\twhile ((rte_eth_timesync_read_tx_timestamp(ptp_data->portid,\n+\t\t\t\t&ptp_data->timestamp3) < 0) && (wait_us < 1000)) {\n+\t\t\trte_delay_us(1);\n+\t\t\twait_us++;\n+\t\t}\n+\t} else {\n+\t\treturn;\n+\t}\n+}\n+\n+/*\n+ * Parse DELAY_RESP message\n+ */\n+void\n+parse_drsp(struct ptpv2_data_slave_ordinary *ptp_data)\n+{\n+\tstruct rte_mbuf *m = ptp_data->m;\n+\tstruct ptp_message *ptp_msg;\n+\n+\tptp_msg = (struct ptp_message *) (rte_pktmbuf_mtod(m, char *) +\n+\t\t\t\t\t\t\t\t\tsizeof(struct ether_hdr));\n+\tptp_data->timestamp4.tv_nsec =\n+\t\t\tntohl(ptp_msg->delay_resp.receive_timestamp.nanoseconds);\n+\tptp_data->timestamp4.tv_sec =\n+\t\t((uint64_t)ntohl\n+\t\t\t\t(ptp_msg->delay_resp.receive_timestamp.seconds_lsb)) |\n+\t\t(((uint64_t)ntohs\n+\t\t\t\t(ptp_msg->delay_resp.receive_timestamp.seconds_msb)) << 32);\n+\n+\t/* Evaluate delta for adjustment */\n+\tptp_data->delta = delta_eval(ptp_data);\n+\trte_eth_timesync_adjust(ptp_data->portid, ptp_data->delta);\n+\tprint_clock_info(ptp_data);\n+}\n+\n+/* This function processes PTP packets, implementing\n+ * slave PTP IEEE1588 L2 functionality\n+ */\n+void\n+parse_ptp_frames(uint8_t portid, struct rte_mbuf *m) {\n+\tstruct ptp_header *ptp_hdr;\n+\tstruct ether_hdr *eth_hdr;\n+\tstatic struct ptpv2_data_slave_ordinary ptp_data;\n+\tuint16_t eth_type;\n+\n+\teth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);\n+\teth_type = rte_be_to_cpu_16(eth_hdr->ether_type);\n+\n+\tif (eth_type == PTP_PROTOCOL) {\n+\n+\t\tptp_data.m = m;\n+\t\tptp_data.portid = portid;\n+\t\tptp_hdr = (struct ptp_header *)(rte_pktmbuf_mtod(m, char *)\n+\t\t\t\t\t+ sizeof(struct ether_hdr));\n+\n+\t\tswitch (ptp_hdr->msgtype) {\n+\t\tcase SYNC:\n+\t\t\tparse_sync(&ptp_data);\n+\t\t\tbreak;\n+\t\tcase FOLLOW_UP:\n+\t\t\tparse_fup(&ptp_data);\n+\t\t\tbreak;\n+\t\tcase DELAY_RESP:\n+\t\t\tparse_drsp(&ptp_data);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+}\n+\n+/*\n+ * The lcore main. This is the main thread that does the work, reading from\n+ * an input port and writing to an output port.\n+ */\n+static __attribute__((noreturn)) void\n+lcore_main(void)\n+{\n+\tconst uint8_t nb_ports = rte_eth_dev_count();\n+\tuint8_t portid;\n+\tunsigned nb_rx;\n+\tstruct rte_mbuf *m;\n+\tunsigned ret;\n+\n+\t/*\n+\t * Check that the port is on the same NUMA node as the polling thread\n+\t * for best performance.\n+\t */\n+\tprintf(\"\\nCore %u Waiting for SYNC packets. [Ctrl+C to quit]\\n\",\n+\t\t\trte_lcore_id());\n+\n+\t/* Run until the application is quit or killed. */\n+\n+\twhile (1) {\n+\t\t/*\n+\t\t * Read packet from RX queues\n+\t\t */\n+\t\tfor (portid = 0; portid < nb_ports; portid++) {\n+\n+\t\t\tnb_rx = rte_eth_rx_burst(portid, 0, &m, 1);\n+\n+\t\t\tif (likely(nb_rx == 0))\n+\t\t\t\t\tcontinue;\n+\n+\t\t\tif ((m->ol_flags & PKT_RX_IEEE1588_PTP)) {\n+\t\t\t\tparse_ptp_frames(portid, m);\n+\t\t\t}\n+\n+\t\t\tret = 0;\n+\t\t\tdo {\n+\t\t\t\trte_pktmbuf_free(m);\n+\t\t\t} while (++ret < nb_rx);\n+\t\t}\n+\t}\n+}\n+\n+/*\n+ * The main function, which does initialization and calls the per-lcore\n+ * functions.\n+ */\n+int\n+main(int argc, char *argv[])\n+{\n+\n+\tunsigned nb_ports;\n+\tuint8_t portid;\n+\n+\t/* Initialize the Environment Abstraction Layer (EAL). */\n+\tint ret = rte_eal_init(argc, argv);\n+\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"Error with EAL initialization\\n\");\n+\n+\targc -= ret;\n+\targv += ret;\n+\n+\t/* Check that there is an even number of ports to send/receive on. */\n+\tnb_ports = rte_eth_dev_count();\n+\n+\t/* Creates a new mempool in memory to hold the mbufs. */\n+\tmbuf_pool = rte_pktmbuf_pool_create(\"MBUF_POOL\", NUM_MBUFS * nb_ports,\n+\t\tMBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());\n+\n+\tif (mbuf_pool == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"Cannot create mbuf pool\\n\");\n+\n+\t/* Initialize all ports. */\n+\tfor (portid = 0; portid < nb_ports; portid++)\n+\t\tif (port_init(portid, mbuf_pool) != 0)\n+\t\t\trte_exit(EXIT_FAILURE, \"Cannot init port %\"PRIu8 \"\\n\",\n+\t\t\t\t\tportid);\n+\n+\tif (rte_lcore_count() > 1)\n+\t\tprintf(\"\\nWARNING: Too many lcores enabled. Only 1 used.\\n\");\n+\n+\t/* Call lcore_main on the master core only. */\n+\tlcore_main();\n+\n+\treturn 0;\n+}\n", "prefixes": [ "dpdk-dev", "3/3" ] }{ "id": 7375, "url": "