Tracing packets inside Open vSwitch

Open vSwitch is a software switch responsible for providing network connectivity to virtual machines or containers. Since it is programmable, it brings a challenge to understand what is going on in the network. Open vSwitch (OVS) is an OpenFlow virtual switch, so before talking about OVS itself, it is necessary to introduce OpenFlow a bit.

OpenFlow is an open standard protocol that allows separation of the packet forwarding (data plane) from the high level routing decisions (control plane). The control plane (also known as OF controller) is responsible to provide instructions to the data plane (vswitch) on how to process packets.

The fact that each packet can have its own fate brings a new challenge to understand what is going on in the network. This article will show how to know what is happening with packets inside the vswitch.

Packet Tracing

Let’s assume a common scenario where the OVS is running on a Linux hypervisor providing network to a few virtual machines. Those virtual machines have different purposes, so they have different network requirements. This should not be a problem for OVS because it allows the controller to add to the vswitch specific flow entries that matches on packet’s headers and then perform actions.

In this example the vswitch is programmed with these flow entries:

1  table=3,ip,tcp,tcp_dst=80,action=output:2
2  table=2,ip,tcp,tcp_dst=22,action=output:1
3  table=0,in_port=3,ip,nw_src=10.0.0.0/24,action=resubmit(,2)
4  table=0,in_port=3,ip,nw_src=192.168.1.0/24,action=resubmit(,3)

The line number #1 adds a rule in table 3 matching on TCP/IP packet with destination port 80 (HTTP). If a packet matches, the action is to output the packet on OpenFlow port 2 (VM’s device).

The line number#2 is similar but matches on destination port 22. If a packet matches, the action is to output the packet on OpenFlow port 1 (Another VM).

The next two lines matches on source IP addresses. If there is a match, the packet is submitted to table indicated as parameter to the resubmit() action.

The example has only 4 simple rules, but it is enough to break how ordinary switches usually work. Do you know what happens with packets coming from other subnets? Or what happens with packets to other destination ports? The challenge to answer those questions increases when the vswitch has hundred thousands rules or even more.

However, the battle is not lost. Fortunately, OVS provides a tracing tool to describe what would happen with a specific packet going through the data path. For example, let’s see if a packet from IP address 10.0.0.1 and destination port 22 would really go to OF port 1 (VM running sshd server).

 1. # ovs-appctl ofproto/trace ovsbr0 in_port=3,tcp,nw_src=10.0.0.2,tcp_dst=22
 2. Bridge: ovsbr0
 3. Flow: tcp,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,nw_src=10.0.0.2,nw_dst=0.0.0.0,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=0,tp_dst=22,tcp_flags=0

 4. Rule: table=0 cookie=0 ip,in_port=3,nw_src=10.0.0.0/24
 5. OpenFlow actions=resubmit(,2)

 6.        Resubmitted flow: tcp,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,nw_src=10.0.0.2,nw_dst=0.0.0.0,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=0,tp_dst=22,tcp_flags=0
 7.        Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 reg8=0x0 reg9=0x0 reg10=0x0 reg11=0x0 reg12=0x0 reg13=0x0 reg14=0x0 reg15=0x0
 8.        Resubmitted  odp: drop
 9.        Resubmitted megaflow: recirc_id=0,tcp,in_port=3,nw_src=10.0.0.0/24,nw_frag=no,tp_dst=22
10.        Rule: table=2 cookie=0 tcp,tp_dst=22
11.        OpenFlow actions=output:1

12. Final flow: unchanged
13. Megaflow: recirc_id=0,tcp,in_port=3,nw_src=10.0.0.0/24,nw_frag=no,tp_dst=22
14. Datapath actions: 2

 

The line number #1 is the trace command. The ovsbr0 is the bridge where the packet is going through. The next arguments describe the packet itself. For instance, the nw_src matches with the IP source address. All the packet fields are well documented in the ovs-ofctl(8) man-page.

The line number #3 shows the flow extracted from the packet described in the command line. Unspecified packet fields are zeroed. The next line shows the matching rule followed by the action taken. Since the rule says to resubmit to table 2, the trace tool indents a new block and shows the new flow extracted plus the registers that are not used in this example. The line #10 shows the matching rule followed by the final data path action to output to OF port #1. Looks like it is working.

In summary, it is possible to follow the flow entries and actions until the final decision is made. At the end, the trace tool shows the Megaflow which matches on all relevant fields followed by the data path actions.

What happens with the same packet but with another TCP destination port?

 1. # ovs-appctl ofproto/trace ovsbr0 in_port=3,tcp,nw_src=10.0.0.2,tcp_dst=80
 2. Bridge: ovsbr0
 3. Flow: tcp,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,nw_src=10.0.0.2,nw_dst=0.0.0.0,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=0,tp_dst=80,tcp_flags=0

 4. Rule: table=0 cookie=0 ip,in_port=3,nw_src=10.0.0.0/24
 5. OpenFlow actions=resubmit(,2)

 6.      Resubmitted flow: tcp,in_port=3,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:00,nw_src=10.0.0.2,nw_dst=0.0.0.0,nw_tos=0,nw_ecn=0,nw_ttl=0,tp_src=0,tp_dst=80,tcp_flags=0
 7.      Resubmitted regs: reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0 reg8=0x0 reg9=0x0 reg10=0x0 reg11=0x0 reg12=0x0 reg13=0x0 reg14=0x0 reg15=0x0
 8.      Resubmitted  odp: drop
 9.      Resubmitted megaflow: recirc_id=0,tcp,in_port=3,nw_src=10.0.0.0/24,nw_frag=no,tp_dst=0x40/0xffc0
10.      Rule: table=254 cookie=0 priority=0,reg0=0x2
11.      OpenFlow actions=drop

12. Final flow: unchanged
13. Megaflow: recirc_id=0,tcp,in_port=3,nw_src=10.0.0.0/24,nw_frag=no,tp_dst=0x40/0xffc0
14. Datapath actions: drop

 

Note on line number #4 that the packet matches with the rule because of the source IP address, so it is resubmitted to the table 2 as before. However, it doesn’t match any rule there. When the packet doesn’t match any rule in the flow tables, it is called a table miss. The vswitch table miss behavior can be configured and it depends on the OpenFlow version being used. In this example the default action was to drop the packet.

An alternative action for the table miss would be to send to a OF controller which presumably would have the required knowledge to know what to do next with the packet. Then the OF controller would update the vswitch with a new flow entries to handle the next packets.

The trace command provides other interesting options like accepting packets described in hex digits. Also that some actions might cause side effects. For further information please refer to the ovs-vswitchd(8) man-page.

Conclusion

The trace tool is really powerful and comes in handy to understand the pipeline processing inside the vswitch.

 


Join Red Hat Developers, a developer program for you to learn, share, and code faster – and get access to Red Hat software for your development.  The developer program and software are both free!

 

Take advantage of your Red Hat Developers membership and download RHEL today at no cost.

Leave a Reply