DPDK framework is written in C with a purpose to be fast and be able to use HW optimization technics. But there are many languages that people use to write a software. And one of the most popular languages is Java.
So we had a project with a goal to develop a packet capturing Java library. To marry DPDK with JAVA we have chosen JNI.
We have chosen the following approach to create a library that could be linked to Java application.
- Build DPDK as a set of dynamic libraries.
You need to enable CONFIG_RTE_BUILD_SHARED_LIB in the configuration.
- Generate C headers using JNI.
- Build own dynamic library using DPDK build system.
You need to include rte.extshared.mk in the library Makefile
Communication between DPDK and JAVA
There are two directions of communication, i.e. from JAVA application to DPDK and the opposite.
Here you need to follow JNI guidelines with the following exceptions.
- Do not use DPDK native thread for communication with JAVA but create a dedicated thread using pthread. Otherwise, we observed a crash.
- Use JAVA static methods. It is not clear why, but we could not use the regular JAVA methods.