Microservice: BPF Compiler Collection (BCC)¶
The following section describes how to integrate the BPF Compiler Collection (BCC) [https://github.com/iovisor/bcc] in a container. These instructions assume an existing ECI installation and familiarity with building Docker containers.
Important
BPF Compiler Collection features must be enabled in the ECI image before BPF Compiler Collection can be used. Creating an ECI image that contains the BPF Compiler Collection features can be accomplished by selecting the XDP & BPF
and Kernel source
feature options during image setup. See section Building ECI for more information.

Building: BCC Container¶
The following section is applicable to:

The following steps detail how to build a Docker image which contains the BPF Compiler Collection (BCC).
If not already completed, follow section Prepare the Build System for Microservices to prepare the build system.
Open a terminal on the build system and navigate to the extracted
Dockerfiles
directory. The contents of this directory should be as follows:$ ls application-containers bpf display-containers softplc-containers
Navigate to the
bpf
directory. The contents of this directory should be as follows:$ ls bpf-compiler-collection
Navigate to the
bpf-compiler-collection
directory. The contents of this directory should be as follows:$ ls Dockerfile entry_point.sh
Build the BPF Compiler Collection (BCC) container by performing the following command:
$ docker build -t bcc:v1.0 .
Note
The “.” at the end of the command is intentional.
Save the Docker image as a tar archive by performing the following command:
$ docker save -o bcc.tar bcc:v1.0
After the save has completed successfully, there will be a tarballed Docker image:
Docker Image archive name
Description of Docker Image
tcc.tar
Docker image which contains the BPF Compiler Collection (BCC).
Executing: BCC Container¶
The following section is applicable to:

Ensure that the Docker daemon is active. Run the following command to restart the Docker daemon.
Warning
All running Docker containers will also restart.
$ systemctl restart docker
The status of the Docker daemon can be verified with the following command:
$ systemctl status docker
Copy the Docker image created earlier to the target system.
Load the copied Docker image by performing the following command:
$ docker load < bcc.tar
Check which Docker images are present on the target system with the following command:
$ docker images
The BCC image that was loaded should be present in the list. Note the name and tag of the image for use in the following steps.
For example, on our system the output is as follows:
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE bcc v1.0 d5bbc885feb3 7 seconds ago 456MB
This container provides the BPF Compiler Collection (BCC). The kernel headers are required to build and load BPF programs into the kernel, which means the ECI image must have been built with kernel headers (
Kernel source
feature option enabled). Those headers must be patched and accessible from within the container, this is why/lib/modules/$(uname -r)/build
is mounted. If they are missing, container instantiation will fail and the following error message will appear:$ docker run -it --rm bcc:v1.0 Missing kernel headers in /lib/modules/host-build, please mount them when starting the container
The BCC examples are located under
/bcc/examples
. XDP examples in particular are located under/bcc/examples/networking/xdp/
. To run thexdp_drop_count.py
code from the container at startup in SKB mode on network interfaceeth0
, the container can be started as below:$ docker run -it --rm \ --name bcc:v1.0 \ --privileged \ -v /lib/modules/$(uname -r)/build:/lib/modules/host-build:ro \ bcc:v1.0 \ python3 bcc/examples/networking/xdp/xdp_drop_count.py -S eth0 Preparing kernel headers... done Printing drops per IP protocol-number, hit CTRL+C to stop 0: 1 pkt/s 0: 0 pkt/s 0: 0 pkt/s 58: 1 pkt/s 0: 0 pkt/s 17: 1 pkt/s 58: 1 pkt/s
The real advantage offered by BCC is the ability to develop, build and run BPF programs directly on the target from a Python script, thanks to this container. In this regard, the container can be started in interactive mode on the target to experiment with BPF. To do so, just omit the command when instantiating the container:
$ docker run -it --rm \ --name bcc \ --privileged \ --net=host \ -v /lib/modules/$(uname -r)/build:/lib/modules/host-build:ro \ bcc
From there a shell opens and gives the possibility to edit scripts and run them dynamically with Python.