How to use librte_pmd_pcap of dpdk in our own dpdk app for packet capturing? - network-programming

I am new to DPDK, I'm trying to write my own app, which would capture packets at wire rate. Can I use the default kernel space libpcap long with dpdk ring and lcore. Or can I use the librte_pmd_pcap which is part of dpdk package.
Librte_pmd_pcap internally uses kernel space libpcap.
And I don't know how to use librte_pmd_pcap in my own dpdk app.
Can someone help me in using the librte_pmd_pcap in our own dpdk app to capture tcp packets.
*I have tested the testpmd app that comes with the dpdk package, testpmd is working fine. I need your help in writing my own dpdk app. Thanks in advance.

I was able to include the rte_eth_pcap.c to the application code and access the api. And this allowed me to use the -vdev EAL option to my app.

If by "the librte_pmd_pcap" you're referring to this source file, it uses libpcap, which is a user-mode library; it's not part of the kernel. It uses kernel-mode mechanisms on the operating systems (plural) that it supports; it uses BPF on *BSD, OS X, and Solaris 11; it uses PF_PACKET sockets on Linux (unless you're on an ancient Linux, in which case it uses SOCK_PACKET sockets); etc..
You can use libpcap directly, which will use the same kernel mechanism that any other code using libpcap does, including the code I linked to.

Related

How to access Xilinx Axi DMA from Linux?

I'm a software developer but I'm a newbie to embedded software development.
I have a Zynq Ultrascale board that has an Axi DMA in its Hardware and I want to access this DMA from Linux.
I know I should use DMA-Engine to Access DMA in Linux and I found the following link which is the Xilinx DMA driver, but I can't add these files to my qt project without any errors and I received file(header file) not found errors.
drivers/dma/xilinx/xilinx_dma.c
I have a piece of scattered information about the DMA driver, Device tree, and DMA-Engine but I know nothing about how to utilize these to access hardware DMA.
I built a Petalinux project and add DMA-Engine and DMA Test client to its kernel.
I don't know adding DMAEngine to the Petalinux project is enough or I should have a driver as well.
I don't know adding hardware specification (by .xsa file and .bit file) to the Petalinux project is enough or I should add a device tree to my Linux for detecting DMA as well
I lookup a step-by-step tutorial on how to set up Linux and qt creator for accessing DMA,
or at least a clear roadmap to my target.
thank you in advance.
First of all, you are facing errors when adding xilinx_dma.c to the Qt project because this file is meant to be compiled as part of kernel or as a kernel module.
Adding DMA Engine to Petalinux is not enough to work with DMA from user space. DMA Engine only provides a standardized API to let different DMAs be integrated into kernel. You need to add a client driver as well. Xilinx, as far as I know, has provided a simple client driver called DMA Proxy Driver. It also includes some simple examples that show how you can access DMA from the user space. However, if your application needs high bandwidth, you probably need to consider other options.
There is also an open source client driver for Axi DMA which achieves higher bandwidths compared to Proxy DMA Driver. It's user space API also allows you to register a callback function to be called whenever a transaction is finished.
The third option is to implement the driver in the user space. This can be done by defining the DMA as a UIO device in the device tree and access its register map directly from the user space. In this case, you need to allocate some contiguous memory blocks in the kernel space to avoid complications with MMU, which cannot be dealt with from the user space.

Wireshark does not capture dpdk interface packets

I am trying to capture the data packets from dpdk interface.
Using pdump+testpmd, able to capture the data packets.
However, if Wireshark is used with testpmd, the above fails.
Any suggestions highly appreciated. Thanks
Working on Ubuntu v 18+, DPDK v 19+ Wireshark v 3+
The solution is to use the pdump application. As others mentioned, once your DPDK application takes ownership of the network card, the kernel will not see the packets, and tcpdump hooks will not be triggered.
The documentation explains how to i) compile dpdk with support for pdump and pcap ii) enable your primary process - your application - to give packet information to a secondary process - the pdump sample application.
You can then use the generated pcap with wireshark.
As soon as you bind the physical interface from kernel to a DPDK driver (igb_uio, uio_pci_generic, vfio-pci) it becomes removed from kernel netdev for both Physical Function and Virtual Function. These NIC ports are accessible via UIO driver, and application like DPDK which has the PMD can probe and init the devices (with some exceptions).
If you want to use the port with Wireshark, unfortunately you have to bind it back to the kernel. You can also just capture packets to a .pcap file using DPDK and analyse it with Wireshark offline - if that fits your needs.
[EDIT-1] There are 2 ways to capture packets on UIO DPDK bind
make use of rte_pdump_init API in the primary (desired) DPDK application and use DPDK example dpdk-pdump to capture packets for RX or TX for desired queues.
Unbind the device from UIO and bind it back to kernel driver for netdev interface. start the DPDK rte_eal_init with special argument --vdev=net_pcap0,iface=[kernel nic interface instance]
Note: In option 2, one can run Wireshark and capture the packets too. But will lose out on performance and DPDK specific functionality.

Parsing packets captured using wireshark for management frames identification using libpcap or similar library

I want to parse packets captured by wireshark offline using libpcap. I am capturing packets from a wireless network in monitor mode. I have read that "libpcap" can be used to capture and parse packets captured in the ethernet. Can it be used for wireless networks too? If yes, can anyone suggest me some tutorial? and if No, which library is suitable for it and how to use it?
libpcap, and its Windows port, WinPcap can be used to capture network traffic (in fact, they're what Wireshark uses to capture network traffic), as well as to read a capture file in pcap format (the default format for Wireshark's existing releases) and, in libpcap 1.1 and later, to read some capture files in pcap-ng format (the default format for the current development version of Wireshark; it should write out files that libpcap 1.1 and later can read).
They can handle a number of network types, including Ethernet and Wi-Fi.
They do not, however, support parsing any packet types; that's the job of the code that uses them, whether it's tcpdump/WinDump, Wireshark, or some other application. There's a library called WiFiPcap that is:
A C++ wrapper around libpcap that parses 802.11 frames, and the most common layer 3 (IPv4, IPv6, ARP) and layer 4 protocols (TCP, UDP, ICMP) contained within them. Also works without link-layer headers. Works in Linux and Windows.
(copied from its web page, but edited to fix the protocol layer numbers to match the OSI model).
I have not looked at it, but it might do what you want.
There might also be other libraries that could be used to parse the packets.

Writing data to I/O address

i have a device (cash drawer) and i would like to directly communicate with the device. I know that its on address f1. Also openbit is 01.
As i've understood so far, i'd need to send 1 to memory address f1 and the cash drawer should open. Though using asm, i get access violation. Then again i've read that windows does not let you communicate directly to device i/o addresses (need to use win). What would be the correct way to send the data to that address.
Note that i cannot use drivers, because i can't communicate with the driver inside my application.
Op. system is win7.
Thanks in advance!
There was a library called inpout32.dll that allowed direct port access you can find it here
http://logix4u.net/Inpout32.dll_Discussion/write_DELPHI_for_inpout32.dll.html
But i don't know if supports windows 7.
In addition to the excellent suggestions above, check out this delphi code for writing and reading I/O. We have used the GWIOPM to do what you are asking, but note that it will be ok for 32-bit versions of Windows up to W7 etc (as is the case for most 'free' drivers). For 64-bit Windows you need a signed kernel driver. For this there are few things available at the moment. We had to write our own.
Why can't you communicate with the driver from your application? It's the best way for ring 3 application to talk with hardware in a safe manner.
However, if you really insist using drivers, you can try going to ring 0 and do direct access. It's much harder than in previous Windows versions (XP and before) but it's possible. I haven't done it myself since I don't have Windows 7, but you can try asking in asm programming forum anywhere.

Writing Device Drivers for a Microcontroller(any)

I am very enthusiastic in writing device drivers for a microcontroller(like PIC, Atmel etc).
Since I am a newbie in this controller-coding-area I just want to know whether writing device drivers for controller is same as we write for linux( or any other OS) ?
Also can anyone suggest some online device driver building tutorial for the same ..?
Thanks,
If you are thinking about developing the device drivers to interface your device with a host computer (probably using USB), then most of the microcontrollers nowadays implement default classes that rely on native drivers.
A concrete example:
If you use a PIC18F4555, you can use the regular HID (human interface device) windows driver to communicate with your microcontroller (given you implemented it correctly). No need to develop any driver.
Writing a device driver for an MCU is a pretty far cry from writing it for a OS. Most MCUs won't have an OS running on them at all. You'll generally end up writing some low level Interrupt Service Routines (ISRs) and filling up buffers, that your application software will end up emptying. You don't have to fit into any device driver paradigm that an O/S has defined. You basically have to read the datasheet for the device you are wanting to interface with and read and write to its memory over whatever interface it might use (e.g. SPI, I2C, UART, etc.). Ultimately the device driver ought to provide intuitive function calls to the application software.
If you are using AVR MCU like atmega then you can use vusb (https://www.obdev.at/products/vusb/index.html) for those MCU that don't have any HID and handles the interrupts by connecting D+ and D- pins of the USB to digital I/O ports of the MCU.
The atmegaU2 packages have their own USB communication ports and HID.

Resources