Learning DPDK : Java support

JNI-Java-Native-Interface

Overview

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.

Building blocks

We have chosen the following approach to create a library that could be linked to Java application.

  1. Build DPDK as a set of dynamic libraries.
    You need to enable CONFIG_RTE_BUILD_SHARED_LIB in the configuration.
  2. Generate C headers using JNI.
  3. 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.

  1. Do not use DPDK native thread for communication with JAVA but create a dedicated thread using pthread. Otherwise, we observed a crash.
  2. Use JAVA static methods. It is not clear why, but we could not use the regular JAVA methods.