aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrainbow_0206 <jiangwenjiang@huawei.com>2018-10-10 11:42:26 +0800
committerrainbow_0206 <jiangwenjiang@huawei.com>2018-10-16 17:00:52 +0800
commitebb5ad89104633abe176868167cc0009c2afe264 (patch)
tree5ffc10f778d85b40013cac3472cc8bf067df1b97
parentd622bf60c1894488276928f350c22e7a95008161 (diff)
Feat: support to log the mbuf to file
Change-Id: Id0ce0dd0764db78a2e12bdaee478405b9aba42e7 Signed-off-by: rainbow_0206 <jiangwenjiang@huawei.com>
-rw-r--r--stacks/lwip_stack/src/io_adpt/dpdk.c100
1 files changed, 95 insertions, 5 deletions
diff --git a/stacks/lwip_stack/src/io_adpt/dpdk.c b/stacks/lwip_stack/src/io_adpt/dpdk.c
index da2cfb6..d199513 100644
--- a/stacks/lwip_stack/src/io_adpt/dpdk.c
+++ b/stacks/lwip_stack/src/io_adpt/dpdk.c
@@ -191,6 +191,82 @@ NSTACK_STATIC struct rte_eth_conf port_conf_default_bond = {
};
/*****************************************************************************
+* Prototype : dpdk_mbuf_to_file
+* Description : write the packet data into a file
+* Input : uint16_t pkt_number
+* struct rte_mbuf **pkts
+* Output : None
+* Return Value :
+* Calls :
+* Called By :
+*
+*****************************************************************************/
+NSTACK_STATIC void
+dpdk_mbuf_to_file (uint16_t pkt_number, struct rte_mbuf **pkts)
+{
+ char line[100] = { 0 };
+ FILE *f = NULL;
+ struct rte_mbuf *p = NULL;
+ uint16_t len = 0, offset, i;
+ uint16_t pktlen = 0;
+ uint16_t start = 0;
+ uint16_t number = 0;
+ unsigned char *data = NULL;
+
+ f = fopen ("/var/log/nStack/packet.txt", "a+");
+ if (f == NULL)
+ {
+ NSHAL_LOGERR ("can not open the file:%s", "packet.txt");
+ return;
+ }
+
+ for (i = 0; i < pkt_number; i++)
+ {
+ pktlen = 0;
+ p = pkts[i];
+ while (p)
+ {
+ len = 0;
+ data = rte_pktmbuf_mtod (p, unsigned char *);
+ while (len < p->data_len)
+ {
+ start = pktlen % 16; /* start of the line */
+ if (start == 0)
+ {
+ number = SNPRINTF_S (line, sizeof (line), sizeof (line) - 1,
+ "%08X", len);
+ }
+
+ for (offset = 0;
+ ((offset + start) < 16) && ((len + offset) < p->data_len);
+ offset++)
+ {
+ number +=
+ SNPRINTF_S (line + number, sizeof (line),
+ sizeof (line) - 1, " %02X",
+ data[len + offset]);
+ }
+
+ fprintf (f, "%s", line);
+ if ((offset + start) == 16)
+ fprintf (f, "\n");
+
+ len += offset;
+ pktlen += offset;
+ (void) MEMSET_S (line, sizeof (line), 0, sizeof (line));
+ }
+
+ p = p->next;
+
+ }
+ fprintf (f, "\n");
+ }
+
+ fclose (f);
+ return;
+}
+
+/*****************************************************************************
* Prototype : hal_rte_eth_rx_burst
* Description : a copy of rte_eth_rx_burst, because this function invokes
a global(rte_eth_devices), which cannt be access by dlsym
@@ -207,13 +283,13 @@ NSTACK_STATIC struct rte_eth_conf port_conf_default_bond = {
*****************************************************************************/
NSTACK_STATIC inline uint16_t
hal_rte_eth_rx_burst (uint8_t port_id, uint16_t queue_id,
- struct rte_mbuf **rx_pkts, const uint16_t nb_pkts)
+ struct rte_mbuf ** rx_pkts, const uint16_t nb_pkts)
{
#ifdef RTE_ETHDEV_RXTX_CALLBACKS
struct rte_eth_rxtx_callback *cb;
#endif
int16_t nb_rx;
-
+ char *pst_capture_packet = NULL;
struct rte_eth_dev *dev = &rte_eth_devices[port_id];
if (NULL == dev->rx_pkt_burst)
@@ -250,6 +326,11 @@ hal_rte_eth_rx_burst (uint8_t port_id, uint16_t queue_id,
}
#endif
+ //pst_capture_packet = getenv ("NSTACK_CAPTURE_PACKET");
+ if (pst_capture_packet && strcmp (pst_capture_packet, "1") == 0)
+ {
+ dpdk_mbuf_to_file (nb_rx, rx_pkts);
+ }
return (uint16_t) nb_rx;
}
@@ -274,7 +355,8 @@ hal_rte_eth_tx_burst (uint8_t port_id, uint16_t queue_id,
#ifdef RTE_ETHDEV_RXTX_CALLBACKS
struct rte_eth_rxtx_callback *cb;
#endif
-
+ int16_t nb_tx = 0;
+ char *pst_capture_packet = NULL;
struct rte_eth_dev *dev = &rte_eth_devices[port_id];
if (NULL == dev->tx_pkt_burst)
@@ -309,8 +391,16 @@ hal_rte_eth_tx_burst (uint8_t port_id, uint16_t queue_id,
}
#endif
- return (*dev->tx_pkt_burst) (dev->data->tx_queues[queue_id], tx_pkts,
- nb_pkts);
+ nb_tx = (*dev->tx_pkt_burst) (dev->data->tx_queues[queue_id], tx_pkts,
+ nb_pkts);
+
+ //pst_capture_packet = getenv ("NSTACK_CAPTURE_PACKET");
+ if (pst_capture_packet && strcmp (pst_capture_packet, "1") == 0)
+ {
+ dpdk_mbuf_to_file (nb_tx, tx_pkts);
+ }
+
+ return nb_tx;
}
/*****************************************************************************