This is the second version of the P4 software switch (aka behavioral model), nicknamed bmv2. It is meant to replace the original version, p4c-behavioral, in the long run, although we do not have feature equivalence yet. Unlike p4c-behavioral, this new version is static (i.e. we do not need to auto-generate new code and recompile every time a modification is done to the P4 program) and written in C++11. For information on why we decided to write a new version of the behavioral model, please look at the FAQ below.
This repository contains code for several variations of the behavioral
model, e.g. simple_switch
, simple_switch_grpc
, psa_switch
, etc.
See here for more details on the differences
between these.
On Ubuntu 14.04, the following packages are required:
You also need to install the following from source. Feel free to use the install scripts under travis/.
To use the CLI, you will need to install the nnpy Python package. Feel free to use travis/install-nnpy.sh
To make your life easier, we provide the install_deps.sh script, which will install all the dependencies needed on Ubuntu 14.04.
Our Travis regression tests now run on Ubuntu 14.04.
On MacOS you can use the tools/macos/bootstrap_mac.sh script to install all the above dependencies using homebrew. Note that in order to compile the code you need XCode 8 or later.
1. ./autogen.sh
2. ./configure
3. make
4. [sudo] make install # if you need to install bmv2
In addition, on Linux, you may have to run sudo ldconfig
after installing
bmv2, to refresh the shared library cache.
Debug logging is enabled by default. If you want to disable it for performance
reasons, you can pass --disable-logging-macros
to the configure
script.
In 'debug mode', you probably want to disable compiler optimization and enable symbols in the binary:
./configure 'CXXFLAGS=-O0 -g'
The new bmv2 debugger can be enabled by passing --enable-debugger
to
configure
.
To run the unit tests, simply do:
make check
If you get a nanomsg error when running the tests (make check), try running them as sudo
To run your own P4 programs in bmv2, you first need to compile the P4 code into a json representation which can be consumed by the software switch. This representation will tell bmv2 which tables to initialize, how to configure the parser, ...
There are currently 2 P4 compilers available for bmv2 on p4lang:
simple_switch
binary, while programs written for PSA can be executed with
the psa_switch
binary. See here for more details on
the differences between these.Assuming you have installed the p4c compiler, you can obtain the json file for a P4_16 v1model program as follows:
p4c --target bmv2 --arch v1model --std p4-16 <prog>.p4
This will create a <prog>.json
output file which can now be 'fed' to the bmv2
simple_switch
binary:
sudo ./simple_switch -i 0@<iface0> -i 1@<iface1> <prog>.json
In this example <iface0> and <iface1> are the interfaces which are bound to the switch (as ports 0 and 1).
The CLI code can be found at tools/runtime_CLI.py. It can be used like this:
./runtime_CLI.py --thrift-port 9090
The CLI connect to the Thrift RPC server running in each switch process. 9090 is the default value but of course if you are running several devices on your machine, you will need to provide a different port for each. One CLI instance can only connect to one switch device.
The CLI is realized using the Python's cmd module and supports auto-completion. If you inspect the code, you will see that the list of supported commands. This list includes:
- table_set_default <table name> <action name> <action parameters>
- table_add <table name> <action name> <match fields> => <action parameters> [priority]
- table_delete <table name> <entry handle>
The CLI include commands to program the multicast engine. Because we provide 2 different engines (SimplePre and SimplePreLAG), you have to specify which one your target is using when starting the CLI, using the --pre option. Accepted values are: None, SimplePre (default value) and SimplePreLAG. The l2_switch target uses the SimplePre engine, while the simple_switch target uses the SimplePreLAG engine.
You can take a look at the commands.txt file for l2_switch and simple_router to see how the CLI can be used.
To enable the debugger, make sure that you passed the --enable-debugger
flag
to configure
. You will also need to use the --debugger
command line flag
when starting the switch.
Use tools/p4dbg.py as follows when the switch is running to attach the debugger to the switch:
sudo ./p4dbg.py [--thrift-port <port>]
To enable event logging when starting your switch, use the --nanolog command line option. For example, to use the ipc address ipc:///tmp/bm-log.ipc:
sudo ./simple_switch -i 0@<iface0> -i 1@<iface1> --nanolog ipc:///tmp/bm-log.ipc <path to JSON file>
Use tools/nanomsg_client.py as follows when the switch is running:
sudo ./nanomsg_client.py [--thrift-port <port>]
The script will display events of significance (table hits / misses, parser transitions, ...) for each packet.
Some targets (simple_switch and simple_switch_grpc) let the user load shared
libraries dynamically at runtime. This is done by using the target-specific
command-line option --load-modules
, which takes as a parameter a
comma-separated list of shared objects. This functionality is currently only
available on systems where dlopen
is available. Make sure that the shared
objects are visible by the dynamic loader (e.g. by setting LD_LIBRARY_PATH
appropriately on Linux). You can control whether this feature is available by
using --enable-modules
/ --disable-modules
when configuring bmv2. By
default, this feature is enabled when dlopen
is available.
We will provide more information in a separate document. However you can test the Mininet integration right away using our simple_router target.
In a first terminal, type the following:
- cd mininet
- sudo python 1sw_demo.py --behavioral-exe ../targets/simple_router/simple_router --json ../targets/simple_router/simple_router.json
Then in a second terminal:
- cd targets/simple_router
- ./runtime_CLI < commands.txt
Now the switch is running and the tables have been populated. You can run pingall in Mininet or start a TCP flow with iperf between hosts h1 and h2.
When running a P4 program with simple_switch (instead of simple_router in
the above example), just provide the appropriate simple_switch
binary to
1sw_demo.py
with --behavioral-exe
.
You can take a look at the targets/ directory
first. We have also started
writing some doxygen documentation specifically targetted at programmers who
want to implement their own switch model using the bmv2 building blocks. You can
generate this documentation yourself (if you have doxygen installed) by running
doxygen Doxyfile
. The output can be found under the doxygen-out
directory. You can also browse this documentation
online.
At this time, we are aware of the following unsupported P4_14 features:
If you find more missing features or if you would like to request that a specific feature be added, please send us an email (p4-dev@lists.p4.org) or submit an issue with the appropriate label on Github. Do not hesitate to contribute code yourself!
Please submit an issue with the appropriate label on Github.
See CONTRIBUTING.md.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。