Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Tracing packets inside Open vSwitch

October 12, 2016
Flavio Bruno Leitner
Related topics:
Linux
Related products:
Red Hat Enterprise Linux

Share:

    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.

     

    Recent Posts

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue