Giter VIP home page Giter VIP logo

ebpf-loadbalancer's Introduction

eBPF Load balancer

Linux eBPF load balancer to be attached into SO_REUSEPORT socket group.

This eBPF program allows load balance packets based on their src IP. All packets from the same src IP will land into the same collector.

Dependencies

This project uses autotools, gcc and clang to compile.

On Ubuntu:

$ sudo apt-get install autoconf libtool make automake gcc pkg-config

On Centos (tested on Centos 8):

$ sudo yum install autoconf libtool make automake pkgconf

eBPF Dependencies

To use eBPF loadbalancing Python3 is needed for eBPF compilation. Another requirement is libbpf (github.com/libbpf/libbpf) >= 0.4.0.

On Ubuntu:

$ sudo apt install linux-headers-$(uname -r) clang libbpf-dev linux-tools-$(uname -r)

On Centos (tested on Centos 8):

$ sudo yum install kernel-headers clang
$ sudo dnf --enablerepo=powertools install libbpf-devel
$ sudo dnf install bpftool

Install

To install src code:

$ ./bootstrap
$ ./configure       # See ./configure --help for options
$ make
$ make install      # Usually needs sudo permissions

Configure options

There are some custom ./configure options :

  • --with-pkgconfigdir=[/own_path/pkgconfig]: overwrite pkgconfig directory to install .pc file [default: ${PREFIX}/lib/pkgconfig]
  • --with-linux=[/own_path/linux/src]: linux source code necesary for eBPF compilation [default: /usr/src/linux]. (On Ubuntu use /usr/src/-generic version)

Usage

See main example. This example initializes an UDP socket bound to an address/port and attaches the eBPF load balancer to the socket.

There is a udp_publisher to test the collector.

Running

To test the loadbalancer, multiple instances should be launched. In this example, messages will be loadbalanced to 3 instances based on their src IP.

To run 3 collectors:

$ cd src
$ sudo bash -c 'ulimit -l unlimited; ./main 10.0.2.15 10001 0 3'   // first collector
$ sudo bash -c 'ulimit -l unlimited; ./main 10.0.2.15 10001 1 3'   // second collector
$ sudo bash -c 'ulimit -l unlimited; ./main 10.0.2.15 10001 2 3'   // third collector

To see the loadbalancer working, you should instance multiple publishers sending from different src ips, otherwise, all packets will be hashed to the same collector.

Publisher:

$ cd src
$ ./udp_publisher 10.0.2.15 10001 100

Debug

To show the maps:

(sudo may be needed)

$ bpftool map dump name tcp_balancing_t
$ bpftool map dump name udp_balancing_t

Contributors

This repository is based on reuseport, a loadbalancer used in pmacct.

ebpf-loadbalancer's People

Contributors

ahuangfeng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.