• Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    C
  • Created about 9 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Consolidated switch repo (API, SAI and Nettlink)

Switch

NOTE: This switch repository is no longer under active development or maintenance. You are welcome to file issues against it, but the former maintainers are unlikely to respond. If you are looking for something similar to this project that is open source, works with the open source P4 tools p4c and behavioral-model simple_switch, and actively developed as of 2020, consider instead looking at ONF's P4 program fabric.p4 and co-developed ONOS control plane software. Relevant links are:

The switch repository contains the switch.p4 sample P4 program along with all the library repos to manipulate the switch using SAI, SwitchAPI and switchlink.

    +-----+   +-----+   +-----+   +-----+
    |App a|   |App j|   |App n|   |App z|
    |     |...|     |...|     |...|     |
    +-----+   +-----+   +-----+   +-----+
       |         |         |         |
       |         |    +----|         |
+------------+   |    |
| Switchlink |   |    |
|            |<-----------------------------+
+------------------+  |                     |
|     SAI          |  |                     |
|                  |  |                     |
+-----------------------+                   |
|      Switch API       |                   |
|                       |                   |
+-----------------------+---------+         |
|      Resource Mgmt. API         |         |
| (auto-gen. from switch.p4)      |         | Netlink events
+---------------------------------+         |
|        Soft Switch              |         |
|  (compiled from switch.p4)      |         |
+---------------------------------+         |
                                            |
                                            |
+----------------------------------------------------------------+
|                             Kernel                             |
|                                                                |
+----------------------------------------------------------------+

Directory Structure

p4src - P4 sources
switchsai - SAI library
switchapi - SwitchAPI
switchlink - Linux netlink listener
tests/ptf-tests - P4 dependent(PD), SAI and API tests
tests/of-tests - Openflow tests

Make sure you pull the p4-build submodule with git submodule update --init --recursive.

Running switch in bmv2 without p4factory

You can now run switch.p4 in bmv2 without cloning p4factory. In order to do this you first need to install [bmv2] (https://github.com/p4lang/behavioral-model) and its compiler [p4c-bmv2] (https://github.com/p4lang/p4c-bm) on your system. Note that when running ./configure for bmv2, you need to provide the --with-pdfixed option, as switch requires the PD library. Additionally, if you plan on running the tests for switch.p4, please make sure you install [PTF] (https://github.com/p4lang/ptf) with sudo python setup.py install.

Once this is done, you can follow this steps:

 ./autogen.sh
 ./configure --with-bmv2 --with-switchsai
 make

The --with-switchsai flag will make sure that the compiled drivers include switchapi and switchsai. If you just need switchapi, replace the flag will --with-switchapi. Replace the flag with --with-switchlink if you need switchlink as well. If you omit these flags, the drivers will only include the PD.

Note that you should be using a fresh clone for this, not the switch submodule that comes with p4factory.

Make sure to look at the output of configure to spot any missing dependency.

Once everything has compiled, you can run the tests for switch.p4 (assuming you have installed [PTF] (https://github.com/p4lang/ptf). Please make sure that you have all the necessary veth pairs setup (you can use [tools/veth_setup.sh] (tools/veth_setup.sh)).

First, start the software switch with:

   sudo ./bmv2/run_bm.sh

Then, start the drivers with:

   sudo ./bmv2/run_drivers.sh

You can now run all the tests:

sudo ./bmv2/run_tests.sh  # for the PD tests
sudo ./bmv2/run_tests.sh --test-dir tests/ptf-tests/api-tests  # for the switchapi tests
sudo ./bmv2/run_tests.sh --test-dir tests/ptf-tests/sai-tests  # for the switchsai tests

Running switch with an openflow agent

You can now use p4ofagent to control switch.p4 on bmv2. To do this, install p4ofagent with CPPFLAGS=-D_BMV2_, then configure switch with --with-bmv2 and --with-of options. You can run the tests with sudo ./bmv2/run_of_tests.sh, and you can also play with a mininet-based l2-learning example by first building the switch docker image, then running sudo ./openflow_l2.py --controller-ip <ip>, where <ip> is the ip address of a Ryu instance running the simple_switch_13 app.

Building switch docker image

In addition to the setps in "Running switch in bmv2 without p4factory", configure bmv2 and p4c-bm with --prefix pointing to the install directory and install. Also configure switch with --prefix pointing to the install directory and --with-switchlink.

You can build the base docker image with:

cd switch/docker/bmv2
make -f docker.mk base-docker-image

This will build the docker image "p4dockerswitch".

sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED         SIZE
p4dockerswitch      latest              8835deb7979e        2 days ago      1.482 GB
ubuntu              14.04               1e0c3dd64ccd        5 weeks ago     187.9 MB

Running switch ntf-tests

Switch NTF tests require NTF (Network Test Framework) and Docker image.

You can now use NTF to build the topology required using the docker image and write tests.

Below are some NTF tests and how to run:

L2: Simple L2 topology with two switches and two hosts. The topology is loop free (no spanning tree protocol).

sudo ntf --topology switch/tests/ntf-tests/topology/l2_topology.json
--config switch/tests/ntf-tests/topology/config.json --test-dir
switch/tests/ntf-tests/ --test L2

STP: L2 topology with four switches and two hosts. It runs MSTPD to form a loop free topology.

sudo ntf --topology switch/tests/ntf-tests/topology/stp_topology.json
--config switch/tests/ntf-tests/topology/config.json --test-dir
switch/tests/ntf-tests/ --test STP

L3 Static: Simple L3 topology with two switches and two hosts. The setup is statically configured.

sudo ntf --topology switch/tests/ntf-tests/topology/l3_static_topology.json
--config switch/tests/ntf-tests/topology/config.json --test-dir
switch/tests/ntf-tests/ --test L3Static

L3 OSPF: Simple L3 topology with two switches and two hosts. The setup runs OSPF (Quagga) to learn and advertise networks.

sudo ntf --topology switch/tests/ntf-tests/topology/l3_ospf_topology.json
--config switch/tests/ntf-tests/topology/config.json --test-dir
switch/tests/ntf-tests/ --test L3OSPF

L3 BGP: Simple L3 topology with two switches and two hosts. The setup runs EBGP (Quagga) to learn and advertise networks.

sudo ntf --topology switch/tests/ntf-tests/topology/l3_bgp_topology.json
--config switch/tests/ntf-tests/topology/config.json --test-dir
switch/tests/ntf-tests/ --test L3BGP

More Repositories

1

tutorials

P4 language tutorials
P4
1,332
star
2

p4c

P4_16 reference compiler
C++
671
star
3

behavioral-model

The reference P4 software switch
C++
536
star
4

p4-spec

TeX
175
star
5

p4factory

Compile P4 and run the P4 behavioral simulator
C
174
star
6

p4app-switchML

Switch ML Application
C++
167
star
7

PI

An implementation framework for a P4Runtime server
C++
165
star
8

p4runtime

Specification documents for the P4Runtime control-plane API
Rust
146
star
9

ptf

Packet Test Framework
Python
144
star
10

p4pi

P4 on Raspberry Pi for Networking Education
JavaScript
123
star
11

p4app

Python
112
star
12

p4-applications

P4 Applications WG repo
P4
107
star
13

p4runtime-shell

An interactive Python shell for P4Runtime
Python
76
star
14

p4-dpdk-target

P4 driver SW for P4 DPDK target.
C++
56
star
15

pna

Portable NIC Architecture
P4
54
star
16

tdi

Table-Driven Interface (TDI) for a P4-programmable backend device.
C++
39
star
17

papers

Repository for papers related to P4
C
38
star
18

ntf

Network Test Framework
Python
37
star
19

education

P4 for Education
36
star
20

scapy-vxlan

A scapy clone, with support for additional packet headers
Python
36
star
21

p4-hlir

Python
32
star
22

p4ofagent

Openflow agent on a P4 dataplane
C
27
star
23

p4c-bm

Generates the JSON configuration for the behavioral-model (bmv2), as well as the C/C++ PD code
Python
24
star
24

p4lang.github.io

Deprecated P4.org website
HTML
23
star
25

p4analyzer

A Language Server Protocol (LSP) compliant analyzer for the P4 language
Rust
19
star
26

p4c-behavioral

[deprecated] P4 compiler for the behavioral model
C
18
star
27

p4app-TCP-INT

C
18
star
28

p4-constraints

Constraints on P4 objects enforced at runtime
C++
14
star
29

p4-build

Infrastructure needed to generate, build and install the PD library for a given P4 program
C++
12
star
30

gsoc

P4.org's Participation in Google Summer of Code
9
star
31

third-party

Third-party dependencies for p4lang software
Dockerfile
8
star
32

project-ideas

Ideas for P4 Projects.
6
star
33

target-utils

C
4
star
34

target-syslibs

C
3
star
35

hackathons

P4
2
star
36

governance

1
star