diff --git a/ptf_nn/README.md b/ptf_nn/README.md index ff4cefd..97fb0a7 100644 --- a/ptf_nn/README.md +++ b/ptf_nn/README.md @@ -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_deps.py](check_deps.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 is done over TCP +using the nanomsg messaging library. ## Demo diff --git a/ptf_nn/check_deps.py b/ptf_nn/check_deps.py new file mode 100755 index 0000000..b679632 --- /dev/null +++ b/ptf_nn/check_deps.py @@ -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) diff --git a/ptf_nn/install_nnpy.sh b/ptf_nn/install_nnpy.sh new file mode 100755 index 0000000..77a7d63 --- /dev/null +++ b/ptf_nn/install_nnpy.sh @@ -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 .. diff --git a/ptf_nn/resources/ptf_nn.graphml b/ptf_nn/resources/ptf_nn.graphml new file mode 100644 index 0000000..83c2f12 --- /dev/null +++ b/ptf_nn/resources/ptf_nn.graphml @@ -0,0 +1,427 @@ + + + + + + + + + + + + + + + + + + + + + + + switch under test + + + + + + + + + + + + + + + + + + + + PTF host / host 0 + + + + + + + + + + Folder 1 + + + + + + + + + + + + + + + + eth1 +port 0 + + + + + + + + + + + + + + + + + eth2 +port 1 + + + + + + + + + + + + + + + + + eth3 +port 2 + + + + + + + + + + + + + + + + + eth0 +management + + + + + + + + + + + + + + + + + (1) +ptf --test-dir <TEST_DIR> --platform nn \ +--device-socket 0-{0-2}@tcp://localhost:PORT \ +--device-socket 1-{3}@tcp://REMOTE_IP:PORT + + + + + + + + + + + + + + + + + (2) +python ptf_nn_agent.py \ +--device-socket 0@tcp://localhost:PORT \ +-i 0-0@eth1 -i 0-1@eth2 -i 0-2@eth3 + + + + + + + + + + + + + + + + + + + + + + Remote host / host 1 + + + + + + + + + + Folder 2 + + + + + + + + + + + + + + + + eth1 +port 3 + + + + + + + + + + + + + + + + + (3) +python ptf_nn_agent.py \ +--device-socket 1@tcp://REMOTE_IP:PORT \ +-i 1-3@eth1 + + + + + + + + + + + + + + + + + eth0 +management +REMOTE_IP + + + + + + + + + + + + + + + + + + + + (3) starts an agent on the remote host. The agent binds to a TCP socket on the management interface and starts capturing traffic on host1:eth1 (port 3 of the switch). +(2) starts an agent on the local PTF host. The agent binds to a TCP socket locally and starts capturing traffic on host0:eth1 (port 0 of the switch), host0:eth2 (port 1) and host0:eth3 (port2 ). +(1) starts the PTF binary, using the nn (nanomsg) packet capturing platform. PTF connects to both TCP sockets (i.e. both agents). + As can be seens from the command line, PTF is told that the agent on host0 is in charge of switch ports 0 through 2 and that the agent on host1 is in charge of port 3. + PTF will then run all the tests included in the specified test directory. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TCP + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TCP + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ptf_nn/resources/ptf_nn.png b/ptf_nn/resources/ptf_nn.png index 85eb7cd..6f996b2 100644 Binary files a/ptf_nn/resources/ptf_nn.png and b/ptf_nn/resources/ptf_nn.png differ