Open vSwitch configuration by Python?

4.8k views Asked by At

How to configure Open vSwitch (OVS) by python ?

Usually, I use shell commands to configure an Open vSwitch without OpenFlow controller. For example,

ovs-vsctl --may-exist add-br br0
ovs-vsctl --may-exist add-br br1
ovs-vsctl set bridge br1 protocols=OpenFlow13
ovs-vsctl --may-exist add-port br0 patch-tun -- set interface patch-tun type=patch options:peer=patch-int
ovs-vsctl set port patch-tun vlan_mode=trunk
ovs-vsctl --may-exist add-port br1 patch-int -- set interface patch-int type=patch options:peer=patch-tun
ovs-vsctl set port patch-int vlan_mode=trunk
ovs-ofctl --protocols=OpenFlow13 add-flow br1 "table=0,priority=1,in_port=1,dl_dst=00:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,20)"
ovs-ofctl --protocols=OpenFlow13 add-flow br1 "table=0,priority=1,in_port=1,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,21)"
.....

But I feel a pain in such shell script in case that I have to do add-port, del-port, add-flow or del-flow dynamically according to the situation. (Though OpenFlow controller may be able to do it, I don't want to keep any controller running since my OVS works only for bridging and vxlan tunneling.)

OVS seems to have its own python library (https://github.com/openvswitch/ovs/tree/master/python), but I can not find the how-to doc. Or, is there any other python library which can configure OVS ?

1

There are 1 answers

1
WoodN3ry On

I believe this is an application for OVS - for make some tests, if you run ovs-test will call this implementation python/ovstest/X.py. But this work if you install: python setup.py install.