Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ptf nn agent update #26

Merged
merged 2 commits into from
Jul 20, 2016
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
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Config file for automatic testing at travis-ci.org

sudo: required

# workaround for a travis Python issue
# see https://github.com/travis-ci/travis-ci/issues/4948
language: generic

dist: trusty

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

addons:
apt:
packages:
- python-dev
- python-pip
- cmake
- libffi-dev

before_install:
- sudo apt-get install ethtool
- sudo pip install --upgrade pip
- sudo apt-get remove python-scapy
- git clone https://github.com/p4lang/scapy-vxlan.git && cd scapy-vxlan && sudo python setup.py install && cd ..
- bash CI/travis/install-nanomsg.sh
- sudo ldconfig
- bash CI/travis/install-nnpy.sh

install:
- sudo python setup.py install

before_script:
- cd ptf_nn/; sudo ./veth_setup.sh; cd ..

script:
- python CI/travis/check-nnpy.py
- ./CI/travis/run_tests.sh
17 changes: 17 additions & 0 deletions CI/travis/check-nnpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python

import nnpy
import sys

pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
pub.bind('inproc://foo')

sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
sub.connect('inproc://foo')
sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')

pub.send('hello, world')
recv = sub.recv()

if recv != 'hello, world':
sys.exit(1)
34 changes: 34 additions & 0 deletions CI/travis/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
force=0
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-f|--force)
force=1
;;
*)
# unknown option
;;
esac
shift # past argument or value
done

function quit {
if [ $force == 0 ]; then
echo "skipping installation, you can force installation with '-f'"
exit 0
fi
}

function check_lib {
ldconfig -p | grep $2 &> /dev/null
if [ $? == 0 ]; then
echo "$2 found"
quit
fi
ldconfig -p | grep $1 &> /dev/null
if [ $? == 0 ]; then
echo "a version of $1 was found, but not $2"
echo "you may experience issues when using a different version"
quit
fi
}
22 changes: 22 additions & 0 deletions CI/travis/install-nanomsg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $THIS_DIR/common.sh

# nanomsg is very confusing in how it manages SOVERSION vs VERSION, but this
# should be okay... (5.0.0 is the SOVERSION)
check_lib libnanomsg libnanomsg.so.5.0.0

set -e
wget https://github.com/nanomsg/nanomsg/archive/1.0.0.tar.gz -O nanomsg-1.0.0.tar.gz
tar -xzvf nanomsg-1.0.0.tar.gz
cd nanomsg-1.0.0
mkdir build
cd build
# I added -DCMAKE_INSTALL_PREFIX=/usr because on my Ubuntu 14.04 machine, the
# library is installed in /usr/local/lib/x86_64-linux-gnu/ by default, and for
# some reason ldconfig cannot find it
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
cmake --build .
sudo cmake --build . --target install
cd ..
9 changes: 9 additions & 0 deletions CI/travis/install-nnpy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e
git clone https://github.com/nanomsg/nnpy.git
# top of tree won't install
cd nnpy
git checkout c7e718a5173447c85182dc45f99e2abcf9cd4065
sudo pip install cffi
sudo pip install .
cd ..
23 changes: 23 additions & 0 deletions CI/travis/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

sudo python ptf_nn/ptf_nn_agent.py \
--device-socket 0@tcp://127.0.0.1:10001 -i 0-1@veth0 \
&>/dev/null &

sleep 5

sudo python ptf_nn/ptf_nn_agent.py \
--device-socket 1@tcp://127.0.0.1:10002 -i 1-1@veth3 \
&>/dev/null &

sleep 5

sudo python ptf_nn/ptf_nn_test_bridge.py -ifrom veth1 -ito veth2 \
&>/dev/null &

sleep 5

sudo ptf --test-dir ptf_nn/ptf_nn_test \
--device-socket 0-{0-64}@tcp://127.0.0.1:10001 \
--device-socket 1-{0-64}@tcp://127.0.0.1:10002 \
--platform nn
24 changes: 23 additions & 1 deletion ptf_nn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,33 @@ the host running PTF).

---

## Dependencies

We rely on [nanomsg](http://nanomsg.org/) (a messaging library) to forward
packets between the PTF agent and the PTF test runner. You will therefore need
to install the following:

- [nanomsg](https://github.com/nanomsg/nanomsg/releases): we recommend
installing the `1.0.0` production release.
- [nnpy](https://github.com/nanomsg/nnpy): these are the Python bindings for
nanomsg. You may use the provided (install-nnpy.sh)[install-nnpy.sh] script
to install nnpy. It will install a version of nnpy that we have tested.

We provide a [check-nnpy.py](check-nnpy.py) script that you can run to check
that nanomsg and nnpy are running properly.

## Overview

![PTF nanomsg overview](resources/ptf_nn.png)

---
In the above setup, we are able to capture and send packets on two different
machines (the PTF host and a remote host). Each agent acts as an intermediary
between a set of interfaces (connected to the switch) and the PTF
tester. Packets received on an interface (from the switch) will be tagged with
the port number and forwarded to the PTF tester. Packets received from the PTF
tester will be forwarded to the switch using the appropriate
interface. Communications between the PTF tester and each agent are done over
TCP using the nanomsg messaging library.

## Demo

Expand Down
1 change: 1 addition & 0 deletions ptf_nn/check-nnpy.py
1 change: 1 addition & 0 deletions ptf_nn/install-nnpy.py
Loading