Skip to content

Commit

Permalink
Use 0 as default PSA_PORT_RECIRCULATE value (#3360)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmateuszssak authored May 25, 2022
1 parent ea2f917 commit 2bffff8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 15 additions & 2 deletions backends/ebpf/psa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,21 +435,34 @@ $ python3 backends/ebpf/build_libbpf
You can compile a P4-16 PSA program for eBPF in a single step using:

```bash
make -f backends/ebpf/runtime/kernel.mk BPFOBJ=out.o ARGS="-DPSA_PORT_RECIRCULATE=<RECIRCULATE_PORT_IDX>" P4FILE=<P4-PROGRAM>.p4 P4C=p4c-ebpf psa
make -f backends/ebpf/runtime/kernel.mk BPFOBJ=out.o P4FILE=<P4-PROGRAM>.p4 P4C=p4c-ebpf psa
```

You can also perform compilation step by step:

```
$ p4c-ebpf --arch psa --target kernel -o out.c <program>.p4
$ clang -Ibackends/ebpf/runtime -Ibackends/ebpf/runtime/usr/include -O2 -g -c -emit-llvm -DBTF -DPSA_PORT_RECIRCULATE=<RECIRCULATE_PORT_IDX> -o out.bc out.c
$ clang -Ibackends/ebpf/runtime -Ibackends/ebpf/runtime/usr/include -O2 -g -c -emit-llvm -o out.bc out.c
$ llc -march=bpf -mcpu=generic -filetype=obj -o out.o out.bc
```

Note that you can use `-mcpu` flag to define the eBPF instruction set. Visit [this blog post](https://pchaigno.github.io/bpf/2021/10/20/ebpf-instruction-sets.html) to learn more about eBPF instruction sets.

The above steps generate `out.o` BPF object file that can be loaded to the kernel.

#### Optional flags

Supposing we want to use a packet recirculation we have to specify the `PSA_PORT_RECIRCULATE` port.
We can use `-DPSA_PORT_RECIRCULATE=<RECIRCULATE_PORT_IDX>` Clang flag via `kernel.mk`
```bash
make -f backends/ebpf/runtime/kernel.mk BPFOBJ=out.o ARGS="-DPSA_PORT_RECIRCULATE=<RECIRCULATE_PORT_IDX>" P4FILE=<P4-PROGRAM>.p4 P4C=p4c-ebpf psa
```
or directly:
`clang ... -DPSA_PORT_RECIRCULATE=<RECIRCULATE_PORT_IDX> ...`,
where `RECIRCULATE_PORT_IDX` is a number of a `psa_recirc` interface (this number can be obtained from `ip -n switch link`).

By default `PSA_PORT_RECIRCULATE` is set to 0.

### psabpf API and psabpf-ctl

We provide the `psabpf` C API and the `psabpf-ctl` CLI tool that can be used to manage eBPF programs generated by P4-eBPF compiler.
Expand Down
4 changes: 1 addition & 3 deletions backends/ebpf/psa/ebpfPsaGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ void PSAEbpfGenerator::emitPreamble(CodeBuilder *builder) const {
builder->newline();

builder->appendLine("#ifndef PSA_PORT_RECIRCULATE\n"
"#error \"PSA_PORT_RECIRCULATE not specified, "
"please use -DPSA_PORT_RECIRCULATE=n option to specify index of recirculation "
"interface (see the result of command 'ip link')\"\n"
"#define PSA_PORT_RECIRCULATE 0\n"
"#endif");
builder->appendLine("#define P4C_PSA_PORT_RECIRCULATE 0xfffffffa");
builder->newline();
Expand Down

0 comments on commit 2bffff8

Please sign in to comment.