Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Magma.sln
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Magma.WinTun.TcpHost", "sam
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Magma.AF_XDP", "src\Magma.AF_XDP\Magma.AF_XDP.csproj", "{5922914B-D7E6-4A23-9A26-5589FD72727B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Magma.DPDK", "src\Magma.DPDK\Magma.DPDK.csproj", "{864623FD-5021-4147-984F-2F5128CE4CB3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -307,6 +309,18 @@ Global
{5922914B-D7E6-4A23-9A26-5589FD72727B}.Release|x64.Build.0 = Release|Any CPU
{5922914B-D7E6-4A23-9A26-5589FD72727B}.Release|x86.ActiveCfg = Release|Any CPU
{5922914B-D7E6-4A23-9A26-5589FD72727B}.Release|x86.Build.0 = Release|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Debug|x64.ActiveCfg = Debug|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Debug|x64.Build.0 = Debug|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Debug|x86.ActiveCfg = Debug|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Debug|x86.Build.0 = Debug|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Release|Any CPU.Build.0 = Release|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Release|x64.ActiveCfg = Release|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Release|x64.Build.0 = Release|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Release|x86.ActiveCfg = Release|Any CPU
{864623FD-5021-4147-984F-2F5128CE4CB3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -332,6 +346,7 @@ Global
{503140F9-24F6-41B5-89F2-BB0FB24CCB2E} = {34A1DC50-486C-4BB9-9929-1805CA0B0DD0}
{845A5A0B-E59B-46AF-BF95-4FC50D660967} = {23E375E0-8A4A-4D6A-8C96-9F2046CE9EB0}
{5922914B-D7E6-4A23-9A26-5589FD72727B} = {34A1DC50-486C-4BB9-9929-1805CA0B0DD0}
{864623FD-5021-4147-984F-2F5128CE4CB3} = {34A1DC50-486C-4BB9-9929-1805CA0B0DD0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {99D656D2-FC86-462A-BB4C-610D644ADC62}
Expand Down
63 changes: 63 additions & 0 deletions docker/Dockerfile.dpdk
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Dockerfile for building Magma with DPDK support
# Based on Ubuntu 24.04 with DPDK 23.11+

FROM ubuntu:24.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV DPDK_VERSION=23.11.2

# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
wget \
curl \
git \
python3 \
python3-pip \
python3-pyelftools \
meson \
ninja-build \
pkg-config \
libnuma-dev \
libpcap-dev \
linux-headers-generic \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Download and build DPDK
WORKDIR /tmp
RUN wget https://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz && \
tar xf dpdk-${DPDK_VERSION}.tar.xz && \
cd dpdk-${DPDK_VERSION} && \
meson setup build && \
cd build && \
ninja && \
ninja install && \
ldconfig && \
cd /tmp && \
rm -rf dpdk-${DPDK_VERSION} dpdk-${DPDK_VERSION}.tar.xz

# Install .NET SDK 10.0
RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh && \
chmod +x dotnet-install.sh && \
./dotnet-install.sh --channel 10.0 --install-dir /usr/share/dotnet && \
ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet && \
rm dotnet-install.sh

# Set up huge pages (2GB)
RUN mkdir -p /dev/hugepages && \
echo "vm.nr_hugepages = 1024" >> /etc/sysctl.conf

# Create working directory
WORKDIR /app

# Copy the source code
COPY . .

# Restore and build
RUN dotnet restore && \
dotnet build -c Release

# Set entrypoint
CMD ["/bin/bash"]
184 changes: 184 additions & 0 deletions docker/README.DPDK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# DPDK Docker Environment

This directory contains Docker configurations for building and running Magma with DPDK support.

## Prerequisites

- Docker 20.10+ with Compose plugin (v2)
- Linux host with huge pages configured (see below)
- DPDK-compatible network interface (optional, for actual packet processing)

## Huge Pages Setup (Host)

Before running the Docker container, configure huge pages on the host:

```bash
# Allocate 1024 huge pages (2GB total)
echo 1024 | sudo tee /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages

# Create huge pages mount point
sudo mkdir -p /dev/hugepages
sudo mount -t hugetlbfs nodev /dev/hugepages
```

To make this persistent across reboots, add to `/etc/sysctl.conf`:
```
vm.nr_hugepages = 1024
```

## Building the Image

### Using Docker

```bash
cd docker
docker build -f Dockerfile.dpdk -t magma-dpdk:latest ..
```

### Using Docker Compose

```bash
cd docker
docker-compose -f docker-compose.dpdk.yml build
```

## Running the Container

### Using Docker

```bash
docker run -it --privileged \
--cap-add=IPC_LOCK \
--cap-add=NET_ADMIN \
--network=host \
-v /dev/hugepages:/dev/hugepages \
magma-dpdk:latest
```

### Using Docker Compose

```bash
cd docker
docker-compose -f docker-compose.dpdk.yml up -d
docker-compose -f docker-compose.dpdk.yml exec magma-dpdk /bin/bash
```

## Verifying DPDK Installation

Inside the container, verify DPDK is installed:

```bash
# Check DPDK version
dpdk-devbind --version

# List available network devices
dpdk-devbind --status

# Check huge pages
cat /proc/meminfo | grep Huge
```

## Building Magma with DPDK

Inside the container:

```bash
# Build all projects including Magma.DPDK
dotnet build

# Build only DPDK project
dotnet build src/Magma.DPDK/Magma.DPDK.csproj

# Run tests (if available)
dotnet test
```

## Using DPDK with Magma

```bash
# Example: Initialize DPDK EAL (requires huge pages)
cd /app
dotnet run --project samples/YourDpdkSample

# For testing without hardware (no huge pages required)
dotnet run --project samples/YourDpdkSample -- --no-huge
```

## Binding Network Interfaces to DPDK

To use DPDK with actual network hardware, bind interfaces to DPDK-compatible drivers:

```bash
# Inside container

# Check current driver
dpdk-devbind --status

# Unbind from kernel driver and bind to DPDK driver
dpdk-devbind --bind=vfio-pci 0000:01:00.0

# Verify binding
dpdk-devbind --status
```

## Troubleshooting

### Permission Denied

If you get permission errors:
- Ensure the container runs with `--privileged` flag
- Check that `IPC_LOCK` and `NET_ADMIN` capabilities are granted

### Huge Pages Not Available

```bash
# Check huge pages inside container
cat /proc/meminfo | grep Huge

# If zero, check host configuration
# Exit container and run on host:
echo 1024 | sudo tee /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
```

### DPDK Initialization Fails

Try running with `--no-huge` option for testing:
```bash
dotnet run -- --no-huge --in-memory
```

### No Network Devices Found

- Ensure network devices are bound to DPDK driver (see "Binding Network Interfaces" above)
- Use `dpdk-devbind --status` to check device status
- Some devices may require specific DPDK drivers

## CI/CD Integration

For CI builds, use the Dockerfile to create a consistent build environment:

```yaml
# Example GitHub Actions workflow
jobs:
build:
runs-on: ubuntu-latest
container:
image: magma-dpdk:latest
steps:
- uses: actions/checkout@v3
- name: Build with DPDK
run: dotnet build
```

## Notes

- The container requires privileged mode for direct hardware access
- Host network mode is recommended for DPDK applications
- Huge pages must be configured on the host, not just in the container
- DPDK 23.11+ uses meson/ninja build system (not the old make-based system)

## Resources

- [DPDK Documentation](https://doc.dpdk.org/)
- [DPDK Container Guide](https://doc.dpdk.org/guides/howto/docker.html)
- [Huge Pages Documentation](https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt)
22 changes: 22 additions & 0 deletions docker/docker-compose.dpdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.8'

services:
magma-dpdk:
build:
context: ..
dockerfile: docker/Dockerfile.dpdk
image: magma-dpdk:latest
container_name: magma-dpdk
privileged: true # Required for DPDK to access hardware
volumes:
- /dev/hugepages:/dev/hugepages # Share huge pages with host
- ..:/app # Mount source code
devices:
- /dev/vfio/vfio # VFIO device for DPDK (if using VFIO driver)
cap_add:
- IPC_LOCK # Required for huge pages
- NET_ADMIN # Required for network configuration
network_mode: host # Use host network for direct hardware access
command: /bin/bash
tty: true
stdin_open: true
Loading