Skip to content

Commit 09d8c74

Browse files
snifbhlguohan
authored andcommitted
Added P4 Behavioral Model (opencomputeproject#492)
* Added Behavioral Model * Updated readme adapter diagram * Update README.md * Update README.md Fixed links, rename sai_object to sai_adapter in readme * Update README.md * update namespace for SAI_arch * Update README.md * fixed logger for direct include of sai.h * Changed Behavioral_Model dir name to BM, minor fixes * added BM folder * Update README.md * removed external learn app * added teaming support module * renamed BM to lowercase bm * backup * . * Added behavioral-model as git submodule * Update README.md * Changed P4 target name to lower case * removed P4 test dir * fixed some makefiles * fixed target relocation * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * rename build_p4_target.sh * rename build_p4_target.sh
1 parent 133705c commit 09d8c74

File tree

193 files changed

+54044
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+54044
-0
lines changed

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
[submodule "test/saithrift/ctypesgen"]
55
path = test/saithrift/ctypesgen
66
url = https://github.com/davidjamesca/ctypesgen
7+
[submodule "behavioral-model"]
8+
path = bm/behavioral-model
9+
url = https://github.com/p4lang/behavioral-model.git
10+
[submodule "bm/behavioral-model"]
11+
path = bm/behavioral-model
12+
url = https://github.com/p4lang/behavioral-model.git

bm/.gitignore

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Compiled Object files
2+
*.slo
3+
*.lo
4+
*.o
5+
*.obj
6+
7+
# Precompiled Headers
8+
*.gch
9+
*.pch
10+
11+
# Compiled Dynamic libraries
12+
*.so
13+
*.dylib
14+
*.dll
15+
16+
# Fortran module files
17+
*.mod
18+
19+
# Compiled Static libraries
20+
*.lai
21+
*.la
22+
*.a
23+
*.lib
24+
25+
# Executables
26+
*.exe
27+
*.out
28+
*.app
29+
30+
# Python byet code
31+
*.pyc
32+
33+
build/*
34+
lib*
35+
36+
# Emacs
37+
*~
38+
39+
*.pcap
40+
41+
# Tags
42+
GPATH
43+
GRTAGS
44+
GSYMS
45+
GTAGS
46+
47+
tools/bm_runtime/
48+
49+
# Files generated by autotools
50+
.deps
51+
Makefile
52+
Makefile.in
53+
configure
54+
config.log
55+
config.h
56+
aclocal.m4
57+
autom4te.cache/
58+
compile
59+
config.h.in
60+
config.status
61+
depcomp
62+
install-sh
63+
missing
64+
stamp-h1
65+
targets/simple_router/simple_router
66+
test-driver
67+
.dirstamp
68+
tests/test_*
69+
!tests/test_*.cpp
70+
!tests/testdata/*.pcap
71+
*.log
72+
*.trs
73+
config.guess
74+
config.sub
75+
ltmain.sh
76+
m4/ltoptions.m4
77+
m4/ltsugar.m4
78+
m4/ltversion.m4
79+
m4/lt~obsolete.m4
80+
py-compile
81+
.libs
82+
83+
*.ts
84+
85+
# gcov
86+
*.gcno
87+
*.gcda
88+
*.gcov
89+
90+
# doxygen
91+
doxygen-out
92+
93+
# thrift
94+
gen-cpp
95+
gen-py
96+
97+
VERSION-build
98+
99+
# dist archives
100+
*.tar.gz

bm/.gitmodules

Whitespace-only changes.

bm/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SAI BEHAVIORAL MODEL
2+
This repository clearly defines widely accepted network switch behaviour.
3+
The switch behavioral model provides a commom framework for all network vendors and users.
4+
It meant to describe the standard ethernet switch features and flows.
5+
The model enables for both users and vendors to experiance the SAI switch model using SAI API over P4 soft switch.
6+
7+
## Repository Structure
8+
The repository consist of:
9+
10+
### [P4 soft-switch](p4-sai/)
11+
P4_14 source files to be complied by the p4c complier
12+
Can be independently configured via the CLI interface.
13+
### [SAI adapter](sai_adapter/)
14+
C source files implementation for the SAI API build for P4 soft switch model.
15+
SAI lib
16+
Tests frameworks: PTF, unittests.

bm/behavioral-model

Submodule behavioral-model added at 55b2b04

bm/build_p4_target.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# backup behavioral-model original configs
2+
mv -f behavioral-model/configure.ac configure_bak.ac
3+
mv -f behavioral-model/targets/Makefile.am Makefile_bak.am
4+
cp -f p4-sai/bm_config/configure.ac behavioral-model/configure.ac
5+
cp -f p4-sai/bm_config/Makefile.am behavioral-model/targets/Makefile.am
6+
7+
rm -rf behavioral-model/targets/p4-sai
8+
mv p4-sai behavioral-model/targets/.
9+
# make behavioral model, p4-sai target.
10+
11+
cd behavioral-model/
12+
./autogen.sh
13+
./configure
14+
make
15+
16+
# return original config files
17+
cd -
18+
mv -f Makefile_bak.am behavioral-model/targets/Makefile.am
19+
mv -f configure_bak.ac behavioral-model/configure.ac
20+
21+
# return compiled target
22+
mv behavioral-model/targets/p4-sai .
23+
24+
# edit relative paths
25+
# cp simple_switch simple_switch_bak
26+
sed -i 's/P4\/SAI\/bm\/behavioral-model\/targets\/p4-sai/p4-sai/g' simple_switch
27+
sed -i 's/\.\.\/\.\.\/src\/bm_runtime\/\.libs\/libbmruntime\.a/\.\.\/behavioral-model\/src\/bm_runtime\/\.libs\/libbmruntime\.a/g' simple_switch
28+
sed -i 's/\.\.\/\.\.\/thrift_src\/\.libs/\.\.\/behavioral-model\/thrift_src\/\.libs/g' simple_switch
29+
rm runtime_CLI
30+
ln -s ../behavioral-model/tools/runtime_CLI.py runtime_CLI

bm/p4-sai/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/build
2+
/simple_switch
3+
/*.pcap
4+
sswitch_runtime
5+
simple_switch_CLI
6+
log.txt
7+
tests/CLI_tests/run_one_test.py
8+
log*

bm/p4-sai/CPPLINT.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# in case the src dir is used as the build dir
2+
exclude_files=gen-cpp

bm/p4-sai/Makefile.am

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
SUBDIRS = .
2+
3+
simple_switch_thrift_py_files = \
4+
gen-py/sswitch_runtime/constants.py \
5+
gen-py/sswitch_runtime/__init__.py \
6+
gen-py/sswitch_runtime/SimpleSwitch.py \
7+
gen-py/sswitch_runtime/ttypes.py
8+
simple_switch_thrift_files = \
9+
gen-cpp/bm/simple_switch_constants.cpp \
10+
gen-cpp/bm/simple_switch_constants.h \
11+
gen-cpp/bm/SimpleSwitch.cpp \
12+
gen-cpp/bm/SimpleSwitch.h \
13+
gen-cpp/bm/simple_switch_types.cpp \
14+
gen-cpp/bm/simple_switch_types.h
15+
16+
BUILT_SOURCES = $(simple_switch_thrift_files) $(simple_switch_thrift_py_files)
17+
18+
sswitchpydir = $(pythondir)/sswitch_runtime
19+
nodist_sswitchpy_PYTHON = $(simple_switch_thrift_py_files)
20+
21+
python_PYTHON = sswitch_CLI.py
22+
23+
# See
24+
# http://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Installation-Directory-Variables.html
25+
edit = sed \
26+
-e 's|@pythondir[@]|$(pythondir)|g'
27+
28+
simple_switch_CLI: Makefile
29+
rm -f $@ $@.tmp
30+
$(edit) $(srcdir)/$@.in >$@.tmp
31+
chmod +x $@.tmp
32+
chmod a-w $@.tmp
33+
mv $@.tmp $@
34+
35+
simple_switch_CLI: simple_switch_CLI.in
36+
37+
EXTRA_DIST = \
38+
simple_switch_CLI.in \
39+
sswitch_CLI
40+
41+
bin_SCRIPTS = \
42+
simple_switch_CLI
43+
44+
AM_CPPFLAGS += \
45+
-I$(srcdir)/thrift/src/ \
46+
-I$(builddir)/gen-cpp
47+
48+
libsimpleswitch_la_LIBADD = \
49+
$(top_builddir)/src/bm_sim/libbmsim.la \
50+
$(top_builddir)/src/bf_lpm_trie/libbflpmtrie.la \
51+
$(top_builddir)/src/BMI/libbmi.la \
52+
$(top_builddir)/third_party/jsoncpp/libjson.la \
53+
-lboost_system $(THRIFT_LIB) -lboost_program_options
54+
55+
noinst_LTLIBRARIES = libsimpleswitch.la
56+
57+
libsimpleswitch_la_SOURCES = \
58+
simple_switch.cpp simple_switch.h primitives.cpp \
59+
thrift/src/SimpleSwitch_server.cpp
60+
61+
bin_PROGRAMS = simple_switch
62+
63+
simple_switch_LDADD = \
64+
$(top_builddir)/src/bm_runtime/libbmruntime.la \
65+
$(top_builddir)/thrift_src/libruntimestubs.la \
66+
libsimpleswitch.la \
67+
libsimpleswitch_thrift.la
68+
69+
simple_switch_SOURCES = main.cpp
70+
71+
lib_LTLIBRARIES = libsimpleswitch_thrift.la
72+
73+
nodist_libsimpleswitch_thrift_la_SOURCES = \
74+
$(simple_switch_thrift_files)
75+
76+
# See http://www.gnu.org/software/automake/manual/html_node/Multiple-Outputs.html
77+
78+
THRIFT_IDL = $(srcdir)/thrift/simple_switch.thrift
79+
80+
EXTRA_DIST += $(THRIFT_IDL)
81+
82+
# We copy the generated Python code to srcdir/ if we have permissions (i.e. not
83+
# for 'make distcheck'). This is to ensure we can run the CLI easily. Maybe I
84+
# will think of a better solution later.
85+
thrift_files.ts: $(THRIFT_IDL)
86+
@rm -f thrift_files.tmp
87+
@touch thrift_files.tmp
88+
@mkdir -p $(builddir)/gen-cpp/bm
89+
$(THRIFT) -out $(builddir)/gen-cpp/bm --gen cpp -r $(THRIFT_IDL)
90+
$(THRIFT) -o $(builddir) --gen py -r $(THRIFT_IDL)
91+
if mkdir $(srcdir)/sswitch_runtime.test 2>/dev/null; then \
92+
rm -rf $(srcdir)/sswitch_runtime/; \
93+
cp -r $(builddir)/gen-py/sswitch_runtime/ $(srcdir)/; \
94+
rm -rf $(srcdir)/sswitch_runtime.test; else :; \
95+
fi
96+
@mv -f thrift_files.tmp $@
97+
98+
$(BUILT_SOURCES): thrift_files.ts
99+
## Recover from the removal of $@
100+
@if test -f $@; then :; else \
101+
trap 'rm -rf thrift_files.lock thrift_files.ts' 1 2 13 15; \
102+
## mkdir is a portable test-and-set
103+
if mkdir thrift_files.lock 2>/dev/null; then \
104+
## This code is being executed by the first process.
105+
rm -f thrift_files.ts; \
106+
$(MAKE) $(AM_MAKEFLAGS) thrift_files.ts; \
107+
result=$$?; rm -rf thrift_files.lock; exit $$result; \
108+
else \
109+
## This code is being executed by the follower processes.
110+
## Wait until the first process is done.
111+
while test -d thrift_files.lock; do sleep 1; done; \
112+
## Succeed if and only if the first process succeeded.
113+
test -f thrift_files.ts; \
114+
fi; \
115+
fi
116+
117+
nodist_pkginclude_HEADERS = \
118+
gen-cpp/bm/simple_switch_constants.h \
119+
gen-cpp/bm/SimpleSwitch.h \
120+
gen-cpp/bm/simple_switch_types.h
121+
122+
123+
CLEANFILES = $(BUILT_SOURCES) \
124+
thrift_files.ts \
125+
gen-cpp/bm/SimpleSwitch_server.skeleton.cpp \
126+
$(bin_SCRIPTS)
127+
128+
# I used to do a rm on gen-cpp, but it was removing a .deps directory, instead I
129+
# am adding the skeleton file to CLEANFILES
130+
clean-local:
131+
rm -rf gen-py

bm/p4-sai/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# P4 SOFT SWITCH MODEL
2+
This repository contains P4 implementation of SAI behavioural model, forked from [p4lang/behavioural_model](https://github.com/p4lang/behavioral-model/).
3+
<a name="p4"></a>
4+
5+
The Model is meant to provide a conformal behavioural SAI(https://github.com/opencomputeproject/SAI) model.
6+
It implements SAI 1.0 on top of soft switch coded via P4.
7+
8+
## Compiling P4 Behavioural model
9+
For list of dependencies and build instructions:
10+
[p4lang/behavioural_model](https://github.com/p4lang/behavioral-model/).
11+
12+
### Compiling P4 target
13+
Due to current behavioral-model implemntation, targets can only be complied in the bm/behavioral-model/targets/ dir.
14+
First time/every target (cpp) change, use:
15+
`bm/build_target.sh`
16+
17+
### Create virtual interfaces
18+
To create the virtual interfaces and hosts. ```veth_setup.sh``` and remove them by ```veth_teardown.sh```
19+
20+
### Compiling P4 code
21+
If any editing to the P4 program was made, before running it you first need to transform the P4 code into a json representation which can be consumed by the software switch. This
22+
representation will tell bmv2 which tables to initialize, how to configure the
23+
parser, ... It is produced by the [p4c-bm](https://github.com/p4lang/p4c-bm)
24+
tool. Please take a look at the
25+
[README](https://github.com/p4lang/p4c-bm/blob/master/README.rst) for this repo
26+
to find out how to install it. Once this is done,
27+
use the script that is found inside the P4-SAI target directory as follows:
28+
29+
./compile_json.sh
30+
31+
### Running P4 program
32+
running the switch can be done with the following command: ```run_server.sh``` found in P4-SAI target directory.
33+
This script also implements some default configurations found in: p4src/DefaultConfig.txt

bm/p4-sai/bm_config/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SUBDIRS = $(MAYBE_SECONDARY_TARGETS) p4-sai

0 commit comments

Comments
 (0)