Initial commit
This commit is contained in:
commit
e5a14cb6d6
|
@ -0,0 +1,5 @@
|
||||||
|
.docker_build
|
||||||
|
*.sif
|
||||||
|
*.tar.gz
|
||||||
|
overlay/
|
||||||
|
shared/
|
|
@ -0,0 +1,172 @@
|
||||||
|
FROM debian:11
|
||||||
|
|
||||||
|
ARG MAX_THREADS=1
|
||||||
|
ADD scripts/p4iab_docker_entry.sh /usr/bin/p4iab_docker_entry.sh
|
||||||
|
|
||||||
|
RUN set -ex; \
|
||||||
|
export DEBIAN_FRONTEND=noninteractive; \
|
||||||
|
apt-get update; \
|
||||||
|
apt-get upgrade -y; \
|
||||||
|
apt-get install -y \
|
||||||
|
# Build Tools
|
||||||
|
automake \
|
||||||
|
bison \
|
||||||
|
cmake \
|
||||||
|
flex \
|
||||||
|
git \
|
||||||
|
gcc \
|
||||||
|
g++ \
|
||||||
|
libtool \
|
||||||
|
make \
|
||||||
|
pkg-config \
|
||||||
|
valgrind \
|
||||||
|
# P4 Dependencies
|
||||||
|
python3 \
|
||||||
|
python3-cffi \
|
||||||
|
python3-crcmod \
|
||||||
|
python3-dev \
|
||||||
|
python3-ipaddr \
|
||||||
|
python3-pip \
|
||||||
|
python3-psutil \
|
||||||
|
python3-scapy \
|
||||||
|
python3-thrift \
|
||||||
|
python3-virtualenv \
|
||||||
|
python3-wheel \
|
||||||
|
python3-protobuf \
|
||||||
|
python3-grpcio \
|
||||||
|
libboost-filesystem-dev \
|
||||||
|
libboost-graph-dev \
|
||||||
|
libboost-iostreams-dev \
|
||||||
|
libboost-program-options-dev \
|
||||||
|
libboost-system-dev \
|
||||||
|
libboost-test-dev \
|
||||||
|
libboost-thread-dev \
|
||||||
|
libboost-dev \
|
||||||
|
libgc-dev \
|
||||||
|
libgmp-dev \
|
||||||
|
libbpf-dev \
|
||||||
|
libevent-dev \
|
||||||
|
libffi-dev \
|
||||||
|
libgflags-dev \
|
||||||
|
libpcap-dev \
|
||||||
|
libnanomsg-dev \
|
||||||
|
libssl-dev \
|
||||||
|
libreadline-dev \
|
||||||
|
libthrift-dev \
|
||||||
|
thrift-compiler \
|
||||||
|
libprotobuf-dev \
|
||||||
|
protobuf-compiler \
|
||||||
|
protobuf-compiler-grpc \
|
||||||
|
libprotoc-dev \
|
||||||
|
libgrpc-dev \
|
||||||
|
libgrpc++-dev \
|
||||||
|
# Mininet Dependencies
|
||||||
|
python3-pep8 \
|
||||||
|
python3-pexpect \
|
||||||
|
python3-tk \
|
||||||
|
pyflakes3 \
|
||||||
|
pylint \
|
||||||
|
cgroupfs-mount \
|
||||||
|
cgroup-tools \
|
||||||
|
psmisc \
|
||||||
|
ethtool \
|
||||||
|
help2man \
|
||||||
|
iperf \
|
||||||
|
iproute2 \
|
||||||
|
socat \
|
||||||
|
ssh \
|
||||||
|
telnet \
|
||||||
|
tshark \
|
||||||
|
# User utilities
|
||||||
|
sudo \
|
||||||
|
htop \
|
||||||
|
less \
|
||||||
|
man \
|
||||||
|
net-tools \
|
||||||
|
tcpdump \
|
||||||
|
termshark \
|
||||||
|
tmux \
|
||||||
|
vim \
|
||||||
|
emacs-nox; \
|
||||||
|
pip3 install pypcap; \
|
||||||
|
ln -sf /usr/local/lib/python3.9/dist-packages \
|
||||||
|
/usr/lib/python3.9/site-packages; \
|
||||||
|
apt-get clean; \
|
||||||
|
# Setup user account
|
||||||
|
useradd -m -G sudo -s /bin/bash p4; \
|
||||||
|
echo "p4:p4" | chpasswd; \
|
||||||
|
mkdir -p /home/p4/shared; \
|
||||||
|
chmod +x /usr/bin/p4iab_docker_entry.sh; \
|
||||||
|
# Install P4 - PI
|
||||||
|
mkdir -p /opt/build; \
|
||||||
|
git clone --depth=1 --recurse-submodules --shallow-submodules -b v0.1.0 \
|
||||||
|
https://github.com/p4lang/PI.git /opt/build/PI; \
|
||||||
|
cd /opt/build/PI; \
|
||||||
|
./autogen.sh; \
|
||||||
|
./configure \
|
||||||
|
--prefix=/usr \
|
||||||
|
--with-proto \
|
||||||
|
--with-internal-rpc \
|
||||||
|
--with-cli; \
|
||||||
|
make -j$MAX_THREADS; \
|
||||||
|
make install; \
|
||||||
|
ldconfig; \
|
||||||
|
# Install P4 - Behavioral Model
|
||||||
|
mkdir -p /opt/build; \
|
||||||
|
git clone --depth=1 --recurse-submodules --shallow-submodules -b 1.15.0 \
|
||||||
|
https://github.com/p4lang/behavioral-model.git \
|
||||||
|
/opt/build/behavioral-model; \
|
||||||
|
cd /opt/build/behavioral-model; \
|
||||||
|
./autogen.sh; \
|
||||||
|
./configure \
|
||||||
|
--prefix=/usr \
|
||||||
|
--with-nanomsg \
|
||||||
|
--with-pi \
|
||||||
|
--with-thrift; \
|
||||||
|
make -j$MAX_THREADS; \
|
||||||
|
make install; \
|
||||||
|
ldconfig; \
|
||||||
|
cd targets/simple_switch_grpc; \
|
||||||
|
./autogen.sh; \
|
||||||
|
./configure \
|
||||||
|
--prefix=/usr \
|
||||||
|
--with-thrift; \
|
||||||
|
make -j$MAX_THREADS; \
|
||||||
|
make install; \
|
||||||
|
ldconfig; \
|
||||||
|
# Install P4 - p4c
|
||||||
|
mkdir -p /opt/build; \
|
||||||
|
git clone --depth=1 --recurse-submodules --shallow-submodules -b v1.2.3.9 \
|
||||||
|
https://github.com/p4lang/p4c.git /opt/build/p4c; \
|
||||||
|
cd /opt/build/p4c; \
|
||||||
|
mkdir build; \
|
||||||
|
cd build; \
|
||||||
|
cmake \
|
||||||
|
-DCMAKE_INSTALL_PREFIX=/usr \
|
||||||
|
-DENABLE_GTESTS=OFF \
|
||||||
|
..; \
|
||||||
|
make -j$MAX_THREADS; \
|
||||||
|
make install; \
|
||||||
|
ldconfig; \
|
||||||
|
# Install P4 - mininet
|
||||||
|
mkdir -p /opt/build; \
|
||||||
|
git clone --depth=1 --recurse-submodules --shallow-submodules -b 2.3.1b4 \
|
||||||
|
https://github.com/mininet/mininet.git /opt/build/mininet; \
|
||||||
|
cd /opt/build/mininet; \
|
||||||
|
PYTHON=python3 make install; \
|
||||||
|
# Install P4 - P4 runtime shell
|
||||||
|
mkdir -p /opt/build; \
|
||||||
|
git clone --depth=1 --recurse-submodules --shallow-submodules -b v0.0.3 \
|
||||||
|
https://github.com/p4lang/p4runtime-shell.git \
|
||||||
|
/opt/build/p4runtime-shell; \
|
||||||
|
cd /opt/build/p4runtime-shell; \
|
||||||
|
pip3 install .; \
|
||||||
|
# Install P4 - ptf
|
||||||
|
pip3 install ptf; \
|
||||||
|
# Setup P4 tutorials
|
||||||
|
sudo -u p4 git clone --depth=1 --recurse-submodules --shallow-submodules \
|
||||||
|
https://github.com/p4lang/tutorials.git /home/p4/tutorials; \
|
||||||
|
# Cleanup
|
||||||
|
rm -rf /opt/build; \
|
||||||
|
unlink /usr/lib/python3.9/site-packages;
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
# Change this to podman if you are on RHEL8+
|
||||||
|
DOCKER ?= docker
|
||||||
|
SINGULARITY ?= singularity
|
||||||
|
SHARED_DIR ?= ./shared
|
||||||
|
OVERLAY_DIR ?= ./overlay
|
||||||
|
MAX_THREADS ?= 16
|
||||||
|
|
||||||
|
UID := $(shell id -u)
|
||||||
|
GID := $(shell id -g)
|
||||||
|
|
||||||
|
.DEFAULT_GOAL := .docker_build
|
||||||
|
|
||||||
|
.docker_build: Dockerfile scripts/*
|
||||||
|
"$(DOCKER)" build --build-arg "MAX_THREADS=$(MAX_THREADS)" -t p4iab .
|
||||||
|
touch "$@"
|
||||||
|
|
||||||
|
p4iab.tar.gz: .docker_build
|
||||||
|
"$(DOCKER)" save p4iab:latest | gzip > "$@"
|
||||||
|
|
||||||
|
p4iab.sif: p4iab.def p4iab.tar.gz
|
||||||
|
sudo "$(SINGULARITY)" build "$@" "$<"
|
||||||
|
sudo chown $(UID):$(GID) "$@"
|
||||||
|
|
||||||
|
run: .docker_build
|
||||||
|
mkdir -p "$(SHARED_DIR)"
|
||||||
|
"$(DOCKER)" run --rm -it --privileged -v "$(SHARED_DIR):/home/p4/shared" -e TERM -u p4 --entrypoint p4iab_docker_entry.sh p4iab:latest
|
||||||
|
|
||||||
|
sc-run: p4iab.sif
|
||||||
|
mkdir -p "$(SHARED_DIR)" "$(OVERLAY_DIR)"
|
||||||
|
sudo singularity run --allow-setuid --overlay "$(OVERLAY_DIR)" -B "$(SHARED_DIR):/home/p4/shared" "$<"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
"$(DOCKER)" container prune
|
||||||
|
"$(DOCKER)" image prune -a
|
||||||
|
rm -f .docker_build p4iab.tar.gz p4iab.sif
|
||||||
|
|
||||||
|
clean-data:
|
||||||
|
sudo rm -rf $(OVERLAY_DIR) $(SHARED_DIR)
|
||||||
|
|
||||||
|
.PHONY: sc-run run clean clean-data
|
|
@ -0,0 +1,89 @@
|
||||||
|
P4-in-a-Bottle
|
||||||
|
==============
|
||||||
|
|
||||||
|
Ready to use P4 tutorial container.
|
||||||
|
|
||||||
|
|
||||||
|
What is This?
|
||||||
|
-------------
|
||||||
|
|
||||||
|
P4-in-a-Bottle is a simple container workspace intended to replace the
|
||||||
|
[P4 Guide](https://github.com/jafingerhut/p4-guide) Ubuntu VMs. As of
|
||||||
|
2023-05-17, It contains all the tools provided in its Ubuntu 23.04 VM.
|
||||||
|
|
||||||
|
|
||||||
|
Why?
|
||||||
|
----
|
||||||
|
|
||||||
|
The provided image in the P4 Guide is specific to VirtualBox, its not the
|
||||||
|
easiest thing in the world to get it working with libvirt/QEMU/KVM. I thought
|
||||||
|
I might as well take it a step further ane make it NOT a VM at all. Having
|
||||||
|
this container also has a few other advantages:
|
||||||
|
|
||||||
|
1. It has less overhead than the original VM image.
|
||||||
|
2. It can run with a variety of setups: Docker, Podman, K8S, OpenShift, etc...
|
||||||
|
3. It can be used as a basis for other P4 runtime testing suites.
|
||||||
|
4. It's much smaller than a VM image.
|
||||||
|
5. When converted into a singularity container, it can be launched as a single
|
||||||
|
binary executable.
|
||||||
|
|
||||||
|
How to Use
|
||||||
|
----------
|
||||||
|
|
||||||
|
There are two ways of launching P4-in-a-Bottle:
|
||||||
|
|
||||||
|
### Singularity
|
||||||
|
|
||||||
|
Singularity is a container runtime by Sylabs developed specificly for software
|
||||||
|
that require low-level access to hardware (i.e. NVIDIA drivers, network
|
||||||
|
devices). This is great for P4-in-a-Bottle, since Mininet requires access to
|
||||||
|
networking kernel components to work.
|
||||||
|
|
||||||
|
Unfortunately, Singularity only works natively on Linux, so if you're on Mac or
|
||||||
|
Windows (without WSL), you're out-of-luck here and should proceed to the docker
|
||||||
|
instructions below.
|
||||||
|
|
||||||
|
To use P4-in-a-Bottle with Singularity:
|
||||||
|
1. Install singularity from [GitHub](https://github.com/sylabs/singularity/releases).
|
||||||
|
2. Download a pre-built image `p4iab.sif` and place it in the same directory
|
||||||
|
as this README. If you skip this step YOU WILL BUILD BOTH THE DOCKER
|
||||||
|
CONTAINER AND THE SINGULARITY CONTAINER FROM SOURCE. (Trust me, you do NOT
|
||||||
|
want to build this yourself).
|
||||||
|
3. Run `make sc-run`. A shared directory `shared/` will be created to allow
|
||||||
|
you to move files between the container and your system.
|
||||||
|
|
||||||
|
### Docker
|
||||||
|
|
||||||
|
If you are stuck with docker, don't panic! The instructions are longer but
|
||||||
|
everything should still work.
|
||||||
|
1. Install docker on your system. This should be pretty self-explanatory.
|
||||||
|
2. Download a pre-built image `p4iab.tar.gz` and place it in the same directory
|
||||||
|
as this README. Then run `docker load -i p4iab.tar.gz && touch .docker_build`.
|
||||||
|
If you skip this step YOU WILL BUILD THE DOCKER CONTAINER FROM SOURCE. Do
|
||||||
|
so only if you know what you are doing.
|
||||||
|
3. Run `make run`. A shared directory `shared/` will be created to allow
|
||||||
|
you to move files between the container and your system.
|
||||||
|
|
||||||
|
|
||||||
|
Building from Source
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
To those who are building from source, note that this WILL take a significant
|
||||||
|
amount of time and space to build. If possible, use a pre-built image instead.
|
||||||
|
|
||||||
|
Build commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Building a docker image for local use
|
||||||
|
$ make .docker_build
|
||||||
|
|
||||||
|
# Building a docker image that can be imported on other machines
|
||||||
|
$ make p4iab.tar.gz
|
||||||
|
|
||||||
|
# Building a singularity image (This depends on the docker image)
|
||||||
|
$ make p4iab.sif
|
||||||
|
|
||||||
|
# Cleanup any cached artifacts
|
||||||
|
$ make clean
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
BootStrap: docker-archive
|
||||||
|
From: p4iab.tar.gz
|
||||||
|
|
||||||
|
%files
|
||||||
|
scripts/p4iab_singularity_entry.sh /usr/bin/p4iab_singularity_entry.sh
|
||||||
|
|
||||||
|
%post
|
||||||
|
chmod +x /usr/bin/p4iab_singularity_entry.sh
|
||||||
|
|
||||||
|
%runscript
|
||||||
|
/usr/bin/p4iab_singularity_entry.sh
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
cd ~
|
||||||
|
echo "Welcome to P4-in-a-Bottle!"
|
||||||
|
exec /bin/bash "$@"
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
cd ~p4
|
||||||
|
echo "Welcome to P4-in-a-Bottle!"
|
||||||
|
exec sudo -su p4
|
Loading…
Reference in New Issue