Connecting multiple switches

One of the many advantages of using a P4 switch is the capability of using custom protocols. However, the processing and communication with such protocols is only available between two or more switches P4.

The communication between switch P4 also enables the use of In-band Network Telemetry (INT) Dataplane Specification (https://p4.org/p4-spec/docs/INT_v2_1.pdfarrow-up-right) to collect metrics at the data plane.

This tutorial will show how to connect multiple switches P4 using P4Docker.

As in the first tutorial, add three nodes:

host1 and host2 using the same dnredson/net image and 1 port each

Host1
Host2

A switch node with the same configurations used in the first tutorial:

Name: sw1

P4 Code Name: code.json

API Port: 50001

Ports: 2

Entries: table_add MyIngress.ipv4_lpm ipv4_forward 10.0.1.2 => 00:00:00:00:01:02 1;table_add MyIngress.ipv4_lpm ipv4_forward 10.0.2.2 => 00:00:00:00:02:02 2

Sw1

Add a new node with the same configuration but change the name to sw2

sw2

In this scenario, both switches will use the same code and entries. The nodes in your project should look like this:

The next step is to create the edges. First, we will connect the host1 to the sw1-port1. Click on "Add Edge" and add the source information:

Source Parent: host1

Source Child: host1-p1

IP Address: 10.0.1.2/24

MAC Address: 00:00:00:00:01:02

Target parent: sw1

Target child: sw1-p1

IP Address: 10.0.1.1/24

MAC Address: 00:00:00:00:01:01

Uncheck the "Define bandwidth and delay"

Click on "Save changes" and the edge will be created

Click again on "Add edge", we will now connect the host2 to host2-p2:

Source Parent: host2

Source Child: host2-p1

IP Address: 10.0.2.2/24

MAC Address: 00:00:00:00:02:02

Target parent: sw2

Target child: sw2-p2

IP Address: 10.0.2.1/24

MAC Address: 00:00:00:00:02:01

Uncheck the "Define bandwidth and delay"

Click on Save changes. With that new connection, your canvas should look like the following:

Now, to create a connection between sw1 and sw2 we will create a new network 10.0.3.0/24, so each connection will be its own namespace. Click on "Add edge" and fill the form with the following information:

Source Parent: sw1

Source Child: sw1-p2

IP Address: 10.0.3.1/24

MAC Address: 00:00:00:00:03:01

Target parent: sw2

Target child: sw2-p1

IP Address: 10.0.3.2/24

MAC Address: 00:00:00:00:03:02

Uncheck the "Define bandwidth and delay"

Click on "Save Edge" and now our topology is complete:

Complete topology

To clearly understand the topology we will create, we will analyze the entries that were used on the switches:

table_add MyIngress.ipv4_lpm ipv4_forward 10.0.1.2 => 00:00:00:00:01:02 1

table_add MyIngress.ipv4_lpm ipv4_forward 10.0.2.2 => 00:00:00:00:02:02 2

With these entries, each switch will check the destination IP and send to the port 1 and MAC address 00:00:00:00:01:02 when the destiny is 10.0.1.2 (host1) and port 2 MAC 00:00:00:00:02:02 when the destiny is 10.0.2.2 (host2). Checking the image "complete topology" we can visualize that this is the path that connects the hosts:

Path from host1 to host2: host1-p1 > sw1-p1; sw1-p2 > sw2-p1; sw2-p2 > host2-p1

Path from host2 to host1: host2-p1 > sw2-p2; sw2-p1 > sw1-p2; sw1-p1 > host1-p1

If you want to add more switches or hosts, just adjust the entry accordingly. There is no limit of entries for each switch, just separate each entry with ";" no spaces.

The next step is to save the topology, and generate the cleaner code and the execution code.

Give a name to the project in the "Topology Name" field. We will use the name "tutorial2".

Click on "Save topology" and download the file. You can use this topology to adjust future versions.

Click on "Generate Code" and click on "Download", now we have the code to generate our topology.

Click on "Generate Cleaner Code" and click on "Download".

If you didn't execute the previous tutorial cleaner code, now we must execute it to clean all the previous tutorial components, since we will use the same names, thus, a possible conflict may occur.

Execute the cleaner code for the last tutorial giving execute permissions and running the code:

$ chmod +x cleanTutorial.sh

$ ./cleanTutoriial.sh

Once we guarantee the environment is clean, we can execute our new script without name conflicts.

Note: you can execute multiple scenarios since they don't share IP addresses or names.

Giver execution permission to the "tutorial2Config.sh" file and execute it:

$ chmod +x tutorial2Config.sh

$ ./tutorial2Config.sh

To check the connectivity between hosts, we can execute the ping command on host1 with destiny to host2 using the docker exec command:

$ docker exec -it host1 ping 10.0.2.2

This validates that the topology created is working properly.

Last updated