[dpdk-dev] [PATCH 3/3] example: PTP client slave minimal implementation
Daniel Mrzyglod
danielx.t.mrzyglod at intel.com
Fri Oct 2 17:20:08 CEST 2015
Add a sample application that acts as a PTP slave using the
DPDK ieee1588 functions.
Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod at intel.com>
---
MAINTAINERS | 3 +
examples/Makefile | 1 +
examples/ptpclient/Makefile | 59 +++++
examples/ptpclient/ptpclient.c | 525 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 588 insertions(+)
create mode 100644 examples/ptpclient/Makefile
create mode 100644 examples/ptpclient/ptpclient.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 080a8e8..a80ce96 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -514,3 +514,6 @@ F: examples/tep_termination/
F: examples/vmdq/
F: examples/vmdq_dcb/
F: doc/guides/sample_app_ug/vmdq_dcb_forwarding.rst
+
+M: Daniel Mrzyglod <danielx.t.mrzyglod at intel.com>
+F: examples/ptpclient
\ No newline at end of file
diff --git a/examples/Makefile b/examples/Makefile
index b4eddbd..4672534 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -74,5 +74,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_XEN_DOM0) += vhost_xen
DIRS-y += vmdq
DIRS-y += vmdq_dcb
DIRS-$(CONFIG_RTE_LIBRTE_POWER) += vm_power_manager
+DIRS-$(CONFIG_RTE_LIBRTE_IEEE1588) += ptpclient
include $(RTE_SDK)/mk/rte.extsubdir.mk
diff --git a/examples/ptpclient/Makefile b/examples/ptpclient/Makefile
new file mode 100644
index 0000000..503339f
--- /dev/null
+++ b/examples/ptpclient/Makefile
@@ -0,0 +1,59 @@
+# BSD LICENSE
+#
+# Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Intel Corporation nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriddegitn by command line or environment
+RTE_TARGET ?= x86_64-native-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = ptpclient
+
+# all source are stored in SRCS-y
+SRCS-y := ptpclient.c
+#SRCS-$(CONFIG_RTE_LIBRTE_IEEE1588) := ptpclient.c
+
+
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+EXTRA_CFLAGS += -O3
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c
new file mode 100644
index 0000000..1fe8e6d
--- /dev/null
+++ b/examples/ptpclient/ptpclient.c
@@ -0,0 +1,525 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <inttypes.h>
+#include <rte_eal.h>
+#include <rte_ethdev.h>
+#include <rte_cycles.h>
+#include <rte_lcore.h>
+#include <rte_mbuf.h>
+#include <rte_ip.h>
+
+#define RX_RING_SIZE 128
+#define TX_RING_SIZE 512
+
+#define NUM_MBUFS 8191
+#define MBUF_CACHE_SIZE 250
+
+/* Values for the PTP messageType field */
+#define SYNC 0x0
+#define DELAY_REQ 0x1
+#define PDELAY_REQ 0x2
+#define PDELAY_RESP 0x3
+#define FOLLOW_UP 0x8
+#define DELAY_RESP 0x9
+#define PDELAY_RESP_FOLLOW_UP 0xA
+#define ANNOUNCE 0xB
+#define SIGNALING 0xC
+#define MANAGEMENT 0xD
+
+#define NSEC_PER_SEC 1000000000L
+#define PTP_PROTOCOL 0x88F7
+
+struct rte_mempool *mbuf_pool;
+
+static const struct rte_eth_conf port_conf_default = {
+ .rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN }
+};
+
+static const struct ether_addr ether_multicast = {
+ .addr_bytes = {0x01, 0x1b, 0x19, 0x0, 0x0, 0x0}
+};
+
+struct ptpv2_msg {
+ uint8_t msg_id;
+ uint8_t version; /* PTP V2 only */
+ uint8_t unused[34];
+};
+
+struct tstamp {
+ uint16_t seconds_msb;
+ uint32_t seconds_lsb;
+ uint32_t nanoseconds;
+} __attribute__((packed));
+
+struct clock_identity {
+ uint8_t id[8];
+};
+
+struct port_identity {
+ struct clock_identity clock_identity;
+ uint16_t port_number;
+} __attribute__((packed));
+
+struct ptp_header {
+ uint8_t msgtype;
+ uint8_t ver;
+ uint16_t message_length;
+ uint8_t domain_number;
+ uint8_t reserved1;
+ uint8_t flag_field[2];
+ int64_t correction;
+ uint32_t reserved2;
+ struct port_identity source_port_identity;
+ uint16_t sequenceId;
+ uint8_t control;
+ int8_t log_message_interval;
+} __attribute__((packed));
+
+struct sync_msg {
+ struct ptp_header hdr;
+ struct tstamp origin_timestamp;
+} __attribute__((packed));
+
+struct follow_up_msg {
+ struct ptp_header hdr;
+ struct tstamp precise_origin_timestamp;
+ uint8_t suffix[0];
+} __attribute__((packed));
+
+struct delay_req_msg {
+ struct ptp_header hdr;
+ struct tstamp origin_timestamp;
+} __attribute__((packed));
+
+struct delay_resp_msg {
+ struct ptp_header hdr;
+ struct tstamp receive_timestamp;
+ struct port_identity requesting_port_identity;
+ uint8_t suffix[0];
+} __attribute__((packed));
+
+struct ptp_message {
+ union {
+ struct ptp_header header;
+ struct sync_msg sync;
+ struct delay_req_msg delay_req;
+ struct follow_up_msg follow_up;
+ struct delay_resp_msg delay_resp;
+ } __attribute__((packed));
+};
+
+struct ptpv2_data_slave_ordinary {
+ struct timespec timestamp;
+ struct timespec timestamp1;
+ struct timespec timestamp2;
+ struct timespec timestamp3;
+ struct timespec timestamp4;
+ int64_t delta;
+ uint8_t portid;
+ uint16_t seqID_SYNC;
+ uint16_t seqID_FOLLOWUP;
+ struct rte_mbuf *m;
+};
+
+void parse_ptp_frames(uint8_t portid, struct rte_mbuf *m);
+void print_clock_info(struct ptpv2_data_slave_ordinary *ptp_data);
+void parse_sync(struct ptpv2_data_slave_ordinary *ptp_data);
+void parse_fup(struct ptpv2_data_slave_ordinary *ptp_data);
+void parse_drsp(struct ptpv2_data_slave_ordinary *ptp_data);
+
+static inline uint64_t timespec64_to_ns(const struct timespec *ts)
+{
+ return ((uint64_t) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
+}
+
+/*
+ * Initializes a given port using global settings and with the RX buffers
+ * coming from the mbuf_pool passed as a parameter.
+ */
+static inline int
+port_init(uint8_t port, struct rte_mempool *mbuf_pool)
+{
+ struct rte_eth_dev_info dev_info;
+ struct rte_eth_conf port_conf = port_conf_default;
+ const uint16_t rx_rings = 1;
+ const uint16_t tx_rings = 1;
+ int retval;
+ uint16_t q;
+
+
+ if (port >= rte_eth_dev_count())
+ return -1;
+
+ /* Configure the Ethernet device. */
+ retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
+ if (retval != 0)
+ return retval;
+
+ /* Allocate and set up 1 RX queue per Ethernet port. */
+ for (q = 0; q < rx_rings; q++) {
+ retval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE,
+ rte_eth_dev_socket_id(port), NULL, mbuf_pool);
+ if (retval < 0)
+ return retval;
+ }
+
+ /* Allocate and set up 1 TX queue per Ethernet port. */
+ for (q = 0; q < tx_rings; q++) {
+ /* Setup txq_flags */
+ struct rte_eth_txconf *txconf;
+ rte_eth_dev_info_get(q, &dev_info);
+ txconf = &dev_info.default_txconf;
+ txconf->txq_flags = 0;
+
+ retval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE,
+ rte_eth_dev_socket_id(port), txconf);
+ if (retval < 0)
+ return retval;
+ }
+
+ /* Start the Ethernet port. */
+ retval = rte_eth_dev_start(port);
+ if (retval < 0)
+ return retval;
+
+ /* Enable timesync timestamping for the Ethernet device */
+ rte_eth_timesync_enable(port);
+
+ /* Enable RX in promiscuous mode for the Ethernet device. */
+ rte_eth_promiscuous_enable(port);
+
+ return 0;
+}
+
+void
+print_clock_info(struct ptpv2_data_slave_ordinary *ptp_data)
+{
+ printf("\nT2 - Slave Clock. %lds %ldns", (ptp_data->timestamp2.tv_sec),
+ (ptp_data->timestamp2.tv_nsec));
+ printf("\nT1 - Master Clock. %lds %ldns ",
+ ptp_data->timestamp1.tv_sec,
+ (ptp_data->timestamp1.tv_nsec));
+ printf("\nT3 - Slave Clock. %lds %ldns", ptp_data->timestamp3.tv_sec,
+ (ptp_data->timestamp3.tv_nsec));
+ printf("\nT4 - Master Clock. %lds %ldns ",
+ ptp_data->timestamp4.tv_sec, (ptp_data->timestamp4.tv_nsec));
+ printf("\nDelta between master and slave clocks:%"PRId64"ns\n",
+ ptp_data->delta);
+ rte_eth_timesync_gettime(ptp_data->portid, &ptp_data->timestamp);
+ printf("Gettime:%llds %ldns",
+ (long long)ptp_data->timestamp.tv_sec,
+ ptp_data->timestamp.tv_nsec);
+ time_t tt = ptp_data->timestamp.tv_sec;
+ printf("\nConverted Current PTP Time: %.24s %.9ld ns \n", ctime(&tt), ptp_data->timestamp.tv_nsec);
+ printf("[Ctrl+C to quit]\n");
+
+ /* Clear screen and put cursor in column 1, row 1 */
+ printf("\033[2J\033[1;1H");
+}
+
+static int64_t
+delta_eval(struct ptpv2_data_slave_ordinary *ptp_data)
+{
+ int64_t delta;
+ uint64_t t1 = 0;
+ uint64_t t2 = 0;
+ uint64_t t3 = 0;
+ uint64_t t4 = 0;
+
+ t1 = timespec64_to_ns(&ptp_data->timestamp1);
+ t2 = timespec64_to_ns(&ptp_data->timestamp2);
+ t3 = timespec64_to_ns(&ptp_data->timestamp3);
+ t4 = timespec64_to_ns(&ptp_data->timestamp4);
+ /* Due to optimalisation */
+ delta = (t2-t1)-(t4-t3);
+ delta = delta/2;
+ delta = -delta;
+
+ return delta;
+}
+
+/*
+ * Parse PTP SYNC message
+ */
+void
+parse_sync(struct ptpv2_data_slave_ordinary *ptp_data)
+{
+ struct ptp_header *ptp_hdr;
+
+ ptp_hdr = (struct ptp_header *)(rte_pktmbuf_mtod(ptp_data->m, char *)
+ + sizeof(struct ether_hdr));
+ ptp_data->seqID_SYNC = rte_be_to_cpu_16(ptp_hdr->sequenceId);
+ rte_eth_timesync_read_rx_timestamp(ptp_data->portid,
+ &ptp_data->timestamp2, 0);
+}
+/*
+ * Parse PTP FOLLOWUP message & Send DELAY_REQ to master clock.
+ */
+void
+parse_fup(struct ptpv2_data_slave_ordinary *ptp_data)
+{
+ struct ether_hdr *eth_hdr;
+ struct ptp_header *ptp_hdr;
+ struct clock_identity *client_clkid;
+ struct ptp_message *ptp_msg;
+ struct rte_mbuf *created_pkt;
+ struct ether_addr eth_multicast = ether_multicast;
+ size_t pkt_size;
+ int wait_us;
+ struct rte_mbuf *m = ptp_data->m;
+
+ eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
+ ptp_hdr = (struct ptp_header *)(rte_pktmbuf_mtod(m, char *)
+ + sizeof(struct ether_hdr));
+ ptp_data->seqID_FOLLOWUP = rte_be_to_cpu_16(ptp_hdr->sequenceId);
+ ptp_msg = (struct ptp_message *)
+ (rte_pktmbuf_mtod(m, char *) + sizeof(struct ether_hdr));
+ ptp_data->timestamp1.tv_nsec =
+ ntohl(ptp_msg->follow_up.precise_origin_timestamp.nanoseconds);
+ ptp_data->timestamp1.tv_sec =
+ ((uint64_t)ntohl
+ (ptp_msg->follow_up.precise_origin_timestamp.seconds_lsb)) |
+ (((uint64_t)ntohs
+ (ptp_msg->follow_up.precise_origin_timestamp.seconds_msb))
+ << 32);
+
+ if (ptp_data->seqID_FOLLOWUP == ptp_data->seqID_SYNC) {
+
+ created_pkt = rte_pktmbuf_alloc(mbuf_pool);
+ pkt_size = sizeof(struct ether_hdr) + sizeof(struct ptp_message);
+ created_pkt->data_len = pkt_size;
+ created_pkt->pkt_len = pkt_size;
+ eth_hdr = rte_pktmbuf_mtod(created_pkt, struct ether_hdr *);
+ rte_eth_macaddr_get(ptp_data->portid, ð_hdr->s_addr);
+
+ /* Set multicast adress 01-1B-19-00-00-00 */
+ ether_addr_copy(ð_multicast, ð_hdr->d_addr);
+
+ eth_hdr->ether_type = htons(PTP_PROTOCOL);
+ ptp_msg = (struct ptp_message *)(rte_pktmbuf_mtod(created_pkt, char *) +
+ sizeof(struct ether_hdr));
+
+ ptp_msg->delay_req.hdr.sequenceId = ptp_data->seqID_SYNC;
+ ptp_msg->delay_req.hdr.msgtype = DELAY_REQ;
+ ptp_msg->delay_req.hdr.ver = 2;
+ ptp_msg->delay_req.hdr.control = 1;
+ ptp_msg->delay_req.hdr.log_message_interval = 127;
+
+ /* Set up clock id */
+ client_clkid = &ptp_msg->delay_req.hdr.source_port_identity.clock_identity;
+
+ client_clkid->id[0] = eth_hdr->s_addr.addr_bytes[0];
+ client_clkid->id[1] = eth_hdr->s_addr.addr_bytes[1];
+ client_clkid->id[2] = eth_hdr->s_addr.addr_bytes[2];
+ client_clkid->id[3] = 0xFF;
+ client_clkid->id[4] = 0xFE;
+ client_clkid->id[5] = eth_hdr->s_addr.addr_bytes[3];
+ client_clkid->id[6] = eth_hdr->s_addr.addr_bytes[4];
+ client_clkid->id[7] = eth_hdr->s_addr.addr_bytes[5];
+
+ /* Enable Flag for Hardware Timestamping */
+ created_pkt->ol_flags |= PKT_TX_IEEE1588_TMST;
+
+ /* We read value from NIC to prevent latching with old value */
+ rte_eth_timesync_read_tx_timestamp(ptp_data->portid, &ptp_data->timestamp3);
+
+ /* the packet is being transmitted */
+ rte_eth_tx_burst(ptp_data->portid, 0, &created_pkt, 1);
+
+ wait_us = 0;
+ ptp_data->timestamp3.tv_nsec = 0;
+ ptp_data->timestamp3.tv_sec = 0;
+
+ /* we must wait at least 1us to read TX Timestamp */
+ while ((rte_eth_timesync_read_tx_timestamp(ptp_data->portid,
+ &ptp_data->timestamp3) < 0) && (wait_us < 1000)) {
+ rte_delay_us(1);
+ wait_us++;
+ }
+ } else {
+ return;
+ }
+}
+
+/*
+ * Parse DELAY_RESP message
+ */
+void
+parse_drsp(struct ptpv2_data_slave_ordinary *ptp_data)
+{
+ struct rte_mbuf *m = ptp_data->m;
+ struct ptp_message *ptp_msg;
+
+ ptp_msg = (struct ptp_message *) (rte_pktmbuf_mtod(m, char *) +
+ sizeof(struct ether_hdr));
+ ptp_data->timestamp4.tv_nsec =
+ ntohl(ptp_msg->delay_resp.receive_timestamp.nanoseconds);
+ ptp_data->timestamp4.tv_sec =
+ ((uint64_t)ntohl
+ (ptp_msg->delay_resp.receive_timestamp.seconds_lsb)) |
+ (((uint64_t)ntohs
+ (ptp_msg->delay_resp.receive_timestamp.seconds_msb)) << 32);
+
+ /* Evaluate delta for adjustment */
+ ptp_data->delta = delta_eval(ptp_data);
+ rte_eth_timesync_adjust(ptp_data->portid, ptp_data->delta);
+ print_clock_info(ptp_data);
+}
+
+/* This function processes PTP packets, implementing
+ * slave PTP IEEE1588 L2 functionality
+ */
+void
+parse_ptp_frames(uint8_t portid, struct rte_mbuf *m) {
+ struct ptp_header *ptp_hdr;
+ struct ether_hdr *eth_hdr;
+ static struct ptpv2_data_slave_ordinary ptp_data;
+ uint16_t eth_type;
+
+ eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
+ eth_type = rte_be_to_cpu_16(eth_hdr->ether_type);
+
+ if (eth_type == PTP_PROTOCOL) {
+
+ ptp_data.m = m;
+ ptp_data.portid = portid;
+ ptp_hdr = (struct ptp_header *)(rte_pktmbuf_mtod(m, char *)
+ + sizeof(struct ether_hdr));
+
+ switch (ptp_hdr->msgtype) {
+ case SYNC:
+ parse_sync(&ptp_data);
+ break;
+ case FOLLOW_UP:
+ parse_fup(&ptp_data);
+ break;
+ case DELAY_RESP:
+ parse_drsp(&ptp_data);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+/*
+ * The lcore main. This is the main thread that does the work, reading from
+ * an input port and writing to an output port.
+ */
+static __attribute__((noreturn)) void
+lcore_main(void)
+{
+ const uint8_t nb_ports = rte_eth_dev_count();
+ uint8_t portid;
+ unsigned nb_rx;
+ struct rte_mbuf *m;
+ unsigned ret;
+
+ /*
+ * Check that the port is on the same NUMA node as the polling thread
+ * for best performance.
+ */
+ printf("\nCore %u Waiting for SYNC packets. [Ctrl+C to quit]\n",
+ rte_lcore_id());
+
+ /* Run until the application is quit or killed. */
+
+ while (1) {
+ /*
+ * Read packet from RX queues
+ */
+ for (portid = 0; portid < nb_ports; portid++) {
+
+ nb_rx = rte_eth_rx_burst(portid, 0, &m, 1);
+
+ if (likely(nb_rx == 0))
+ continue;
+
+ if ((m->ol_flags & PKT_RX_IEEE1588_PTP)) {
+ parse_ptp_frames(portid, m);
+ }
+
+ ret = 0;
+ do {
+ rte_pktmbuf_free(m);
+ } while (++ret < nb_rx);
+ }
+ }
+}
+
+/*
+ * The main function, which does initialization and calls the per-lcore
+ * functions.
+ */
+int
+main(int argc, char *argv[])
+{
+
+ unsigned nb_ports;
+ uint8_t portid;
+
+ /* Initialize the Environment Abstraction Layer (EAL). */
+ int ret = rte_eal_init(argc, argv);
+
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
+
+ argc -= ret;
+ argv += ret;
+
+ /* Check that there is an even number of ports to send/receive on. */
+ nb_ports = rte_eth_dev_count();
+
+ /* Creates a new mempool in memory to hold the mbufs. */
+ mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS * nb_ports,
+ MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
+
+ if (mbuf_pool == NULL)
+ rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
+
+ /* Initialize all ports. */
+ for (portid = 0; portid < nb_ports; portid++)
+ if (port_init(portid, mbuf_pool) != 0)
+ rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n",
+ portid);
+
+ if (rte_lcore_count() > 1)
+ printf("\nWARNING: Too many lcores enabled. Only 1 used.\n");
+
+ /* Call lcore_main on the master core only. */
+ lcore_main();
+
+ return 0;
+}
--
2.1.0
More information about the dev
mailing list