Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This...

20
Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface Card (NIC). This is achieved by creating a program to match traffic entering the Network Flow Processor from the physical network port, and sending the traffic to its PCIe interface(i.e. the network device driver in the kernel of the host OS). Conversely traffic received at the PCIe interface is directed to the network interface. The program is constructed in two phases. The first phase constructs a minimal program which drops all traffic. The second phase modifies the program to actually implement the “wires” between the network and the host. Part 1: Packet Dropping The first step is to create a Programmer Studio project, a P4 program, and a P4 rules file to merely drop all traffic. 1. Open Programmer Studio by double clicking on the icon. 2. Create a new project by choosing File -> New Project: Note: We are selecting File -> New Project to create a project. Later in the process, we will use File -> New to create source code files, and add these to the project. © 2015 Netronome Systems, Inc. 1 [email protected]

Transcript of Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This...

Page 1: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

Introduction to a NIC Wire App in P4

This lab introduces the concepts of P4 by implementing a rudimentary Network Interface Card (NIC). This is achieved by creating a program to match traffic entering the Network Flow Processor from the physical network port, and sending the traffic to its PCIe interface(i.e. the network device driver in the kernel of the host OS). Conversely traffic received at the PCIe interface is directed to the network interface.

The program is constructed in two phases. The first phase constructs a minimal program which drops all traffic. The second phase modifies the program to actually implement the “wires” between the network and the host.

Part 1: Packet Dropping The first step is to create a Programmer Studio project, a P4 program, and a P4 rules file to merely drop all traffic.

1. Open Programmer Studio by double clicking on the icon.

2. Create a new project by choosing File -> New Project:

Note: We are selecting File -> New Project to create a project. Later in the process, we will use File -> New to create source code files, and add these to the project.

© 2015 Netronome Systems, Inc. 1 [email protected]

Page 2: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

3. Select chip variant “nfp­4xxx­b0”, set the project type to be P4 using the checkbox, and choose a suitable project name, for example “P4Lab”:

Note: Take care to select the P4 checkbox, as otherwise the project will not be using the P4 perspective.

4. Create a new file and set its type to be “P4 Source File”:

© 2015 Netronome Systems, Inc. 2 [email protected]

Page 3: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

5. Enter the following P4 program:

header_type eth_hdr fields dst : 48; src : 48; etype : 16; header eth_hdr eth; parser start return eth_parse; parser eth_parse extract(eth); return ingress; action drop_act() drop(); table in_tbl actions drop_act; control ingress apply(in_tbl);

This program parses the Ethernet II header (destination address, source address, and type), and proceeds to drop all packets that arrive.

© 2015 Netronome Systems, Inc. 3 [email protected]

Page 4: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

6. Save the program by pressing Ctrl­S, and choose a suitable file name, for example “p4lab”:

7. Add the P4 source file to the project using the build settings dialog:

© 2015 Netronome Systems, Inc. 4 [email protected]

Page 5: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

a. First insert the P4 source file into the project:

b. Then select the file as the main P4 source file, and click OK:

© 2015 Netronome Systems, Inc. 5 [email protected]

Page 6: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

8. Configure the project for debugging using hardware:

9. Build the project to verify that the program is correct:

(Introduce a mistake, for example delete a semicolon, and rebuild again, to observe how error messages are reported.)

© 2015 Netronome Systems, Inc. 6 [email protected]

Page 7: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

10. Create a P4 rules file:

11. We will now create a default rule and associate it with the drop action.

a. Click on the table name:

b. Type a rule name, click the checkbox to make it the default rule, and select an action from the drop down list:

© 2015 Netronome Systems, Inc. 7 [email protected]

Page 8: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

c. Now press Ctrl­S to save the file.

12. We will now add the rules file to the project.

a. Open the build settings dialog:

b. Insert the rules file into the project:

© 2015 Netronome Systems, Inc. 8 [email protected]

Page 9: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

c. Select the file as the main rules file.

d. Click OK.

13. We now specify hardware debugging options.

a. Select the hardware debugging options dialog:

© 2015 Netronome Systems, Inc. 9 [email protected]

Page 10: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

b. Specify the hardware debugging destination host name:

The default debug server and runtime server port numbers are acceptable. Enter “0” as the host device number (i.e. SmartNIC number).

14. Start debugging by pressing F12, or by using the menu:

© 2015 Netronome Systems, Inc. 10 [email protected]

Page 11: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

15. Select microengine 0 on island 32 in the thread view pane, and double click “Thread0”:

16. Select the “p4lab.p4” file in the dropdown to debug at the P4 level:

© 2015 Netronome Systems, Inc. 11 [email protected]

Page 12: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

17. Enable displaying instruction addresses to simplify adding breakpoints (they can only be added at lines where instruction addresses are displayed) by right clicking in the left margin and enabling the option:

18. Add a few code breakpoints. Click on the source code line, then either click on the toolbar button, or press F9.

© 2015 Netronome Systems, Inc. 12 [email protected]

Page 13: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

Breakpoints are indicated using red stop icons, as follows:

19. Run the program by pressing F5 or clicking on the toolbar icon:

Note: When prompted to rebuild (Yes or No), click on Yes.

© 2015 Netronome Systems, Inc. 13 [email protected]

Page 14: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

20. Log in to the traffic generation server:

Log in as user “root”, password “netronome”.

21. Inject a packet by entering:

tcpreplay ­i p4p1 udp.pcap

A breakpoint should now be hit. Continue execution by pressing F5 to observe the packet making its way through the P4 execution stages (parsing, matching, and actions).

© 2015 Netronome Systems, Inc. 14 [email protected]

Page 15: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

22. The packet and counters can be observed using the viewers to the left of the source code display:

Click Refresh to display updated packet information. The extracted packet headers are only displayed once the packet has been parsed. The standard packet metadata is always available.

Click Refresh to display updated counter values.

23. Stop debugging by pressing Ctrl­F12 or by clicking on the toolbar button:

© 2015 Netronome Systems, Inc. 15 [email protected]

Page 16: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

Part 2: Packet Wire The next step involves modifying the program and rules to forward traffic from the network to the host, and the host to the network, i.e. in effect implementing the functionality of a rudimentary Network Interface Card (NIC).

1. Update the P4 program (“p4lab.p4”) as follows.

a. Introduce an action to forward traffic to a specified port:

action fwd_act(prt) modify_field(standard_metadata.egress_spec, prt);

b. Amend the ingress table declaration to match the ingress port and invoke this action:

table in_tbl reads standard_metadata.ingress_port : exact; actions fwd_act; drop_act;

© 2015 Netronome Systems, Inc. 16 [email protected]

Page 17: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

The entire program should now appear as follows.

2. We will now update the rules to match the ingress port and invoke the forwarding action, to create a “wire” between the physical network interface on the NIC (“p0”) and the virtual interface on the host (“v0.0”), and another wire for the converse direction.

a. Rebuild the program (press F7) to ensure that the rules editor is aware of the newly added table field.

b. Open the rules editor.

© 2015 Netronome Systems, Inc. 17 [email protected]

Page 18: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

c. Add the network to host rule by clicking on the table name, and clicking Add:

Enter a rule name. Enter “p0” as the match value. Select “fwd_act” as the action and enter “v0.0” as the action parameter.

© 2015 Netronome Systems, Inc. 18 [email protected]

Page 19: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

c. Also add a host to network rule. Click on Add again, and enter a rule name. Enter “v0.0” as the match value. Select “fwd_act” as the action and enter “p0” as the action parameter.

d. Press Ctrl­S to save changes.

3. Run the P4 program and set breakpoints as before.

4. Open two SSH connections to the server. Recall that your server number (s1 to s10) corresponds to your workstation number (netws1 to netws10 respectively).

Use the one SSH session to observe packets being received by the NIC, using the tcpdump ­i vf0 command:

© 2015 Netronome Systems, Inc. 19 [email protected]

Page 20: Introduction to a NIC Wire App in P4 · 2019. 2. 27. · Introduction to a NIC Wire App in P4 This lab introduces the concepts of P4 by implementing a rudimentary Network Interface

Use the other SSH sessions to inject packets, using the tcpreplay ­i p4p1 udp.pcap command:

Congratulations, you have now developed the firmware of a Network Interface Card! Extending the firmware to perform more elaborate match/action processing is now a “simple matter of programming”. The behavior of the NIC can be customized further by specifying rules that augment the program.

THE INFORMATION IN THIS DOCUMENT IS AT THIS TIME NOT A CONTRIBUTION TO P4.ORG.

© 2015 Netronome Systems, Inc. 20 [email protected]