Sign inSign up

sergiogimenez/netmap-docker

By sergiogimenez

Updated about 4 years ago

Image
1

188

sergiogimenez/netmap-docker repository overview

Dockerfile

FROM ubuntu:20.04

RUN apt-get update && \
    apt-get install -y git gcc make wget kmod net-tools
  
RUN apt-get install linux-headers-$(uname -r) -y

RUN git clone https://github.com/luigirizzo/netmap
RUN cd netmap && \
    ./configure --no-drivers && \
    make && \
    make install

Preparing Environment

Installing netmap for veths

Clone the netmap repo:

git clone https://github.com/luigirizzo/netmap
cd netmap

Install kernel headers. Make sure is available:

> apt search linux-headers-$(uname -r)

Sorting... Done
Full Text Search... Done
linux-headers-5.13.0-48-generic/focal-updates 5.13.0-48.54~20.04.1 amd64
  Linux kernel headers for version 5.13.0 on 64 bit x86 SMP

Then , install:

sudo apt install linux-headers-$(uname -r)

veth.c driver sources are not there by default, so we need to download kernel sources:

wget https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/linux/5.13.0-48.54/linux_5.13.0.orig.tar.gz
tar -xvf linux_5.13.0.orig.tar.gz

Change 5.13.0-48.54 for the needed version.

Now, in the netmap directory, let's install netmap and veth modified drivers.

./configure --drivers=veth.c --kernel-sources=./linux-5.13

If everything went fine, we should see an output like this:

kernel directory            /lib/modules/5.13.0-48-generic/build
                            [/usr/src/linux-headers-5.13.0-48-generic]
kernel sources              /home/sergioi2cat/i2cat/netmap/linux-5.13
linux version               50d13  [5.13.19]
module file                 netmap.ko

subsystems                  null ptnetmap generic monitor pipe vale
apps                        dedup vale-ctl nmreplay tlem lb bridge pkt-gen
native drivers              veth.c

Contents of the drivers.mak file:
veth.c@conf := CONFIG_VETH
veth.c@src := cp -Rp /home/sergioi2cat/i2cat/netmap/linux-5.13/drivers/net/veth.c veth.c
veth.c@patch := patches/vanilla--veth.c--41400--99999

Now compile and install:

make
sudo make install
sudo depmod -a
sudo modprobe netmap

Now remove the default linux veth driver:

sudo rmmod veth

And add the veth.ko one we just compiled:

sudo insmod veth.ko

Make sure netmap.ko and veth.c are compiled and loaded for the kernel version of the baremetal. To confirm it, the lsmod | grep netmap command should explicitily show that netmap module is being used by veth driver:

❯ lsmod | grep netmap
netmap                212992  1 veth

How to run the containers

docker run --name  --rm -dit \
           --name txc \
           --privileged \
           --cap-add=ALL -d \
           -v /dev:/dev \
           -v /lib/modules:/lib/modules \
           netmap-docker:latest \
           bash

The containers need to access the kernel moduels of the host, that's why we need to mount /dev and /lib/modules lib. Probably --cap-add=ALL -d is overkill and need to look for capabilities that do not grant root access to everything.

Simple test: Two containers conected through a a veth pair

The receiver container: rxc.

docker run --name  --rm -dit \
           --name rxc \
           --privileged \
           --cap-add=ALL -d \
           -v /dev:/dev \
           -v /lib/modules:/lib/modules \
           netmap-docker:latest \
           bash

The sender container: txc.

docker run --name  --rm -dit \
           --name txc \
           --privileged \
           --cap-add=ALL -d \
           -v /dev:/dev \
           -v /lib/modules:/lib/modules \
           netmap-docker:latest \
           bash

Now, in the host machine clone the following repo:

git clone https://github.com/cslev/add_veth_to_docker.git

And run the connect_containers_veth.sh script. This will create a veth pair and attach every peer into the containers. To run it:

cd add_veth_to_docker
sudo ./connect_containers_veth.sh txc rxc tx_veth rx_veth

Now, in the rxc container, run pkt-gen in rx mode:

rxc❯ pkt-gen -i rx_veth -f rx

And run pkt-gen in tx mode in txc:

txc❯ pkt-gen -i tx_veth -f tx

Tag summary

Content type

Image

Digest

sha256:9e0458447

Size

226.3 MB

Last updated

about 4 years ago

docker pull sergiogimenez/netmap-docker