Skip to content
Merged
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
105 changes: 105 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Config file for automatic testing at travis-ci.org

sudo: required

dist: trusty

language: c

# My very smart trick to force inclusion of the veth kernel module
# (even though we do not use docker at all her)
services:
- docker

env:
global:
- PYP_ADD="/usr/local/lib/python2.7/dist-packages:/usr/local/lib/python2.7/site-packages"
matrix:
- TEST_SCENARIO=switch
- TEST_SCENARIO=of

# There is probably some redundant stuff in this list. If you find one, remove
# it
addons:
apt:
packages:
- libjudy-dev
- libgmp-dev
- libpcap-dev
- libboost-dev
- libboost-test-dev
- libboost-program-options-dev
- libboost-system-dev
- libboost-filesystem-dev
- libboost-thread-dev
- libboost-test-dev
- libevent-dev
- automake
- libtool
- flex
- bison
- pkg-config
- g++
- libssl-dev
- doxygen
- git
- libedit-dev
- libevent-dev
- libfreetype6-dev
- libpng-dev
- libyaml-0-2
- libbz2-dev
- libnl-route-3-dev
- openssl
- pkg-config
- python-dev
- python-matplotlib
- python-numpy
- python-pip
- python-scipy
- python-setuptools
- python-yaml

# need to replace github ssh references with https
before_install:
- git submodule update --init --recursive
- sudo apt-get install ethtool
- sudo pip install --upgrade pip
- sudo pip install --upgrade thrift
- sudo pip install ctypesgen
- sudo pip install crc16

# install bmv2 before p4c-bmv2 to get nanomsg
install:
- wget https://s3-us-west-2.amazonaws.com/p4lang/thrift_bin.tar.gz
- tar -xzvf thrift_bin.tar.gz -C $HOME/
- export PATH=$PATH:$HOME/thrift/bin/
- export LDFLAGS="$LDFLAGS -L$HOME/thrift/lib"
- export CPPFLAGS="$CPPFLAGS -I$HOME/thrift/include"
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/thrift/lib
- mkdir install_tmp && cd install_tmp/
- sudo apt-get remove python-scapy
- git clone https://github.com/p4lang/scapy-vxlan.git && cd scapy-vxlan && sudo python setup.py install && cd ..
- cd .. && sudo rm -rf install_tmp/
- bash CI/travis/install-ptf.sh
- bash CI/travis/install-bmv2.sh
- bash CI/travis/install-p4c-bmv2.sh
- bash CI/travis/install-p4ofagent.sh
- export CPPFLAGS="$CPPFLAGS -I$HOME/p4ofagent/include"
- export LDFLAGS="$LDFLAGS -L$HOME/p4ofagent/lib"
- git clone https://github.com/floodlight/oftest.git oftest_tmp
- export PYTHONPATH=$PYP_ADD:$PYTHONPATH
- sudo ldconfig
- ./autogen.sh

before_script:
- cp CI/travis/veth_setup.sh tools/
- cd tools; sudo ./veth_setup.sh; sudo ./veth_disable_ipv6.sh; cd ..

script:
- if [ "$TEST_SCENARIO" = "switch" ] ; then ./configure --with-bmv2 --with-switchsai; fi
- if [ "$TEST_SCENARIO" = "of" ] ; then ./configure --with-bmv2 --with-of; fi
- make -j2
- if [ "$TEST_SCENARIO" = "switch" ] ; then ./CI/travis/run_switch_tests.sh; fi
- if [ "$TEST_SCENARIO" = "of" ] ; then ./CI/travis/run_of_tests.sh; fi

12 changes: 12 additions & 0 deletions CI/travis/install-bmv2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e
git clone https://github.com/p4lang/behavioral-model.git bmv2_tmp
cd bmv2_tmp
bash travis/install-nanomsg.sh
sudo ldconfig
bash travis/install-nnpy.sh
./autogen.sh
./configure 'CXXFLAGS=-O0' --with-pdfixed
make -j2 && sudo make install
cd ..
rm -rf bmv2_tmp
8 changes: 8 additions & 0 deletions CI/travis/install-p4c-bmv2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e
git clone https://github.com/p4lang/p4c-bm.git p4c-bmv2
cd p4c-bmv2
git submodule update --init --recursive
sudo pip install -r requirements.txt
sudo python setup.py install
cd ..
17 changes: 17 additions & 0 deletions CI/travis/install-p4ofagent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e
git clone https://github.com/p4lang/p4ofagent.git p4ofagent_tmp
cd p4ofagent_tmp
git submodule update --init
cd submodules/indigo/
find -name ".gitmodules" -type f -exec sed -i 's/git@github.com:/https:\/\/github.com\//' {} \;
git submodule update --init
cd submodules/bigcode/
find -name ".gitmodules" -type f -exec sed -i 's/git@github.com:/https:\/\/github.com\//' {} \;
cd ../../../../
./autogen.sh
./configure --prefix=$HOME/p4ofagent
make p4ofagent CPPFLAGS="-D_BMV2_ -I$HOME/bmv2/include"
make install
cd ..
rm -rf p4ofagent_tmp
6 changes: 6 additions & 0 deletions CI/travis/install-ptf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e
git clone https://github.com/p4lang/ptf.git
cd ptf
sudo python setup.py install
cd ..
5 changes: 5 additions & 0 deletions CI/travis/run_of_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sudo ./bmv2/run_bm.sh &>/dev/null &
sleep 10
sudo ./bmv2/run_drivers.sh &>/dev/null &
sleep 10
sudo ./bmv2/run_of_tests.sh --oft-path oftest_tmp/oft
17 changes: 17 additions & 0 deletions CI/travis/run_switch_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sudo ./bmv2/run_bm.sh &>/dev/null &
sleep 10
sudo ./bmv2/run_drivers.sh &>/dev/null &
sleep 10
sudo ./bmv2/run_tests.sh --test-dir tests/ptf-tests/api-tests
sudo killall bmswitchp4_drivers lt-bmswitchp4_drivers simple_switch lt-simple_switch; echo 0
sudo ./bmv2/run_bm.sh &>/dev/null &
sleep 10
sudo ./bmv2/run_drivers.sh &>/dev/null &
sleep 10
sudo ./bmv2/run_tests.sh --test-dir tests/ptf-tests/sai-tests
sudo killall bmswitchp4_drivers lt-bmswitchp4_drivers simple_switch lt-simple_switch; echo 0
sudo ./bmv2/run_bm.sh &>/dev/null &
sleep 10
sudo ./bmv2/run_drivers.sh &>/dev/null &
sleep 10
sudo ./bmv2/run_tests.sh
38 changes: 38 additions & 0 deletions CI/travis/veth_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
noOfVeths=18
if [ $# -eq 1 ]; then
noOfVeths=$1
fi
echo "No of Veths is $noOfVeths"
idx=0
let "vethpairs=$noOfVeths/2"
while [ $idx -lt $vethpairs ]
do
#1 2 3 4 5 6 7 125
intf0="veth$(($idx*2))"
intf1="veth$(($idx*2+1))"
idx=$((idx + 1))
if ! ip link show $intf0 &> /dev/null; then
ip link add name $intf0 type veth peer name $intf1
ip link set dev $intf0 up
ip link set dev $intf1 up
TOE_OPTIONS="rx tx sg tso ufo gso gro rxvlan txvlan"
for TOE_OPTION in $TOE_OPTIONS; do
/sbin/ethtool --offload $intf0 "$TOE_OPTION" off
/sbin/ethtool --offload $intf1 "$TOE_OPTION" off
done
fi
done
idx=125
intf0="veth$(($idx*2))"
intf1="veth$(($idx*2+1))"
if ! ip link show $intf0 &> /dev/null; then
ip link add name $intf0 type veth peer name $intf1
ip link set dev $intf0 up
ip link set dev $intf1 up
TOE_OPTIONS="rx tx sg tso ufo gso gro rxvlan txvlan"
for TOE_OPTION in $TOE_OPTIONS; do
/sbin/ethtool --offload $intf0 "$TOE_OPTION" off
/sbin/ethtool --offload $intf1 "$TOE_OPTION" off
done
fi
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
# P4FLAGS = -I .

SUBDIRS = p4src switchapi switchsai switchlink
8 changes: 8 additions & 0 deletions bmv2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This scripts are generated by configure
run_bm.sh
run_drivers.sh
run_tests.sh

gen-py.tar.lz
p4_pd
switch.json
39 changes: 39 additions & 0 deletions bmv2/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4

AM_CPPFLAGS += -DBMV2
AM_CPPFLAGS += -I$(top_builddir)/p4-build
AM_CPPFLAGS += -isystem$(includedir)

lib_LTLIBRARIES = libbmswitchp4.la
libbmswitchp4_la_CPPFLAGS = $(AM_CPPFLAGS)
libbmswitchp4_la_LIBADD =
if WITH_SWITCHLINK
libbmswitchp4_la_LIBADD += @top_builddir@/switchlink/libswitchlink.la
endif
if WITH_SWITCHSAI
libbmswitchp4_la_LIBADD += @top_builddir@/switchsai/libbmswitchsai.la
endif
if WITH_SWITCHAPI
libbmswitchp4_la_LIBADD += @top_builddir@/switchapi/libbmswitchapi.la
endif
if WITH_OF
libbmswitchp4_la_LIBADD += @top_builddir@/p4-build/bmv2/libof.la
endif
libbmswitchp4_la_LIBADD += \
@top_builddir@/p4-build/bmv2/libpd.la \
@top_builddir@/p4-build/bmv2/libpdthrift.la \
-lbmpdfixed -lbmpdfixedthrift $(THRIFT_LIB)
libbmswitchp4_la_SOURCES = \
bmv2_init.c

bin_PROGRAMS = bmswitchp4_drivers
bmswitchp4_drivers_CPPFLAGS = $(AM_CPPFLAGS)
bmswitchp4_drivers_LDADD = \
libbmswitchp4.la
if WITH_OF
bmswitchp4_drivers_LDADD += \
-lp4ofagent @top_builddir@/p4-build/bmv2/libof.la \
-lbmpdfixed -lpthread -lm
endif
bmswitchp4_drivers_SOURCES = \
main.c
105 changes: 105 additions & 0 deletions bmv2/bmv2_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
Copyright 2013-present Barefoot Networks, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include <getopt.h>
#include <assert.h>

#include <bmpd/switch/pd/pd.h>
#include <bm/pdfixed/pd_static.h>
#include <bm/pdfixed/thrift-src/pdfixed_rpc_server.h>
#include <bmpd/switch/thrift-src/pd_rpc_server.h>

char *pd_server_str = NULL;
char *of_controller_str = NULL;
int of_ipv6 = 0;

/**
* The maximum number of ports to support:
* @fixme should be runtime parameter
*/
#define PORT_COUNT 256
#define PD_SERVER_DEFAULT_PORT 9090

/**
* Check an operation and return if there's an error.
*/
#define CHECK(op) \
do { \
int _rv; \
if ((_rv = (op)) < 0) { \
fprintf(stderr, "%s: ERROR %d at %s:%d", \
#op, _rv, __FILE__, __LINE__); \
return _rv; \
} \
} while (0)

#ifdef SWITCHLINK_ENABLE
extern int switchlink_init(void);
#endif /* SWITCHLINK_ENABLE */

#ifdef SWITCHAPI_ENABLE
extern int switch_api_init(int device, unsigned int num_ports);
extern int start_switch_api_rpc_server(void);
extern int start_switch_api_packet_driver(void);
#endif /* SWITCHAPI_ENABLE */

#ifdef SWITCHSAI_ENABLE
#define SWITCH_SAI_THRIFT_RPC_SERVER_PORT "9092"
extern int start_p4_sai_thrift_rpc_server(char * port);
#endif /* SWITCHSAI_ENABLE */

#ifdef OPENFLOW_ENABLE
extern void p4ofagent_init(bool ipv6, char *ip_ctl);
#endif

int
bmv2_model_init() {
int rv=0;
/* Start up the PD RPC server */
void *pd_server_cookie;
start_bfn_pd_rpc_server(&pd_server_cookie);
add_to_rpc_server(pd_server_cookie);

p4_pd_init();
p4_pd_dc_init();
p4_pd_dc_assign_device(0, "ipc:///tmp/bmv2-0-notifications.ipc", 10001);

/* Start up the API RPC server */
#ifdef SWITCHAPI_ENABLE
CHECK(switch_api_init(0, 256));
CHECK(start_switch_api_rpc_server());
CHECK(start_switch_api_packet_driver());
#endif /* SWITCHAPI_DISABLE */

#ifdef SWITCHSAI_ENABLE
CHECK(start_p4_sai_thrift_rpc_server(SWITCH_SAI_THRIFT_RPC_SERVER_PORT));
#endif /*SWITCHSAI_ENABLE */

#ifdef SWITCHLINK_ENABLE
CHECK(switchlink_init());
#endif /* SWITCHLINK_ENABLE */

#ifdef OPENFLOW_ENABLE
p4ofagent_init(of_ipv6, of_controller_str);
#endif

return rv;
}
Empty file added bmv2/dummy.p4
Empty file.
Loading