Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Open vSwitch without stale ports

December 1, 2017
Flavio Bruno Leitner

    Open vSwitch is growing every day and being used in large-scale deployments. Usually, that means there are few ports configured in the vswitch that will be always available, like physical Ethernet ports and several other ports providing networking connectivity to virtual machines or containers. Those other ports are software devices and very often they cannot be reused after a reboot or a system crash for example.

    This blog post will talk about how to make sure the vSwitch comes up clean after a system crash or bad shutdown. The idea is that once vSwitch is up, there is no need for another component (usually a remote controller) to iterate over a large number of stale ports and clean them up.

    How it works

    There is a new port's property called "transient" accepted in upstream and expected to be available in OVS 2.9. For backward compatibility reasons, the default is "false" if not configured, and there is no behavior change from the previous OVS versions.

    However, very often the management system is aware if the port is a software device or not. In case it is, the "transient" property can be set to "true". It doesn't do anything else than inform the Open vSwitch service initialization to remove that port from the database before the service is brought up.

    In the case of Fedora and RHEL distributions, there is a new systemd service responsible to do the cleanup. It's called "ovs-delete-transient-ports.service" and it runs once per boot, so it doesn't affect service restarts. This service executes "ovs-ctl" script passing "delete-transient-ports" to do the actual work.

    To get into deeper details, systemd does the services orchestration. The first service being brought up is "ovsdb-server". Then the "ovs-delete-transient-ports" service runs, which queries the database for ports with "transient=true" and delete them. Finally, "ovs-vswitchd" service is started completing the vswitch initialization.

    I have a script, listed below, simulating 1000 containers connected to Open vSwitch and then I will trigger a kernel panic to simulate a kernel crash, for example. After a reboot without the property set, we can see that all ports remain in the database but not in the system.

    Content of create_containers.sh:

    #!/bin/bash
    
    # create a bridge
    ovs-vsctl add-br br0
    
    for ns in $(seq 1 $1)
    do
        # add a new veth pair
        ip link add vethHOST${ns} type veth \
            peer name vethNS${ns}
    
        # add a new network namespace
        ip netns add ${ns}
    
        # add host port to the vswitch bridge
        ovs-vsctl add-port br0 vethHOST${ns}
    
        # moving veth peer to the namespace
        ip link set vethNS${ns} netns ${ns}
    
    done
    # ./create_containers.sh 1000
    # # Checking the total number of software devices:
    # ip link | grep vethHOST | wc -l
    1000
    # # Checking the total number of ports in br0:
    # ovs-vsctl show | grep 'Port "vethHOST' | wc -l
    1000

    It's time to trigger the system crash to simulate a failure:

    # echo b > /proc/sysrq-trigger

    This is a good time to grab a cup of your preferred beverage while the system isn't back.

    The system is back, let's verify if the software devices survived and if they are in the OVS bridge.

    # # Repeating the previous command checking the
    # # number of software devices:
    # ip link | grep vethHOST | wc -l
    0
    # # Repeating the previous command checking the
    # # the number of ports in br0:
    # ovs-vsctl show | grep 'Port "vethHOST' | wc -l
    1000

    The ports remained in the database, though the devices don't exist. Now, if the management system tries to add a fresh software device that has the same name as one of those 1000 stale ports, it will receive an error:

    # ovs-vsctl add-port ovsbr0 vethHOST114
    ovs-vsctl: cannot create a port named vethHOST114
    because a port named vethHOST114 already exists on
    bridge br0

    Solution

    Let's change the script to set "transient=true" for all those software devices and repeat the test.

    #!/bin/bash
    
    # create a bridge
    ovs-vsctl add-br br0
    
    for ns in $(seq 1 $1)
    do
        # add a new veth pair
        ip link add vethHOST${ns} type veth \
            peer name vethNS${ns}
    
        # add a new network namespace
        ip netns add ${ns}
    
        # add host port to the vswitch bridge
        ovs-vsctl add-port br0 vethHOST${ns} \
        -- set Port vethHOST${ns} other_config:transient=true
    
        # moving veth peer to the namespace
        ip link set vethNS${ns} netns ${ns}
    
    done

    This is the result, after the system crash:

    # # Repeating the previous command checking the
    # # number of software devices:
    # ip link | grep vethHOST | wc -l
    0
    # # Repeating the previous command checking the
    # # the number of ports in br0:
    # ovs-vsctl show | grep 'Port "vethHOST' | wc -l
    0

    There are no software devices and no ports on the br0 bridge.

    Conclusion

    Open vSwitch has a database to store configuration in a persistent way, but sometimes that's not desired, especially for software devices like vnets, vhost-users or veth pairs, which will not survive a crash.

    Upstream has merged the transient port boolean property to help clean up those type of ports before the service is available.

    Thanks!


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

    Last updated: November 30, 2017

    Recent Posts

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    • Best Practice Configuration and Tuning for Linux and Windows VMs

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.