Changing ofport number in Openvswith
It’s a totally obscure topic for people outside ovs, you are free to ignore.
When a port is added in openvswitch, it gets a special ID for the sake of openflow operations (those, which are happen in ovs-ofctl
). It’s called ofport
. You can see those in output of ovs-vsctl list Interfaces
(nothing confusing there, Interfaces and Ports are different things, even if you add port via ovs-vsctl add-port
, there is an associated Interface in the OVS database).
So, normally, you get those ids at random. OVS gives them numbers in sequence. Newer versions of OVS even allows you to use names in ovs-ofctl
instead of those numbers to ease the pain, but this is a half-measure, as those names are resolved dynamically and are not 100% stable.
The true, the proper way to keep sanity in openflow database is to manage those numbers manually. If you do so, you know for sure, that your port is ofport=X
, and all your openflow rules (f.e. in_port=X action=drop
) are, actually, related to your port, not to a random unlucky port which appeared later.
ofport and ofport_request
The main problem with ofport
, is that it’s a RO field. You can’t change it. But! You may request OVS to change it.
The subtlety here is that OVS may ignore your request for specific number if you are trying to do something silly, like assigning the same ofport to two different ports, or change ofport for local port (the bridge name) — you are not allowed to do this.
So, there is a second field, read-write, and it’s called ofport_request
. If OVS can honor your request, ofport
become the same value as ofport_request
. If it can’t, nope, you can’t.
You may wonder why such complexity instead of plain error from ovs-vsctl
, but the reason is that it’s fields in database, and OVS can’t reject your request to the database (f.e. if you change database in offline mode), but it can ignore values in additional field and keep database consistent with ‘reality’.
Tl;dr; How to change ofport for a port
Changing ofport to the number 9 for existing port (with name foo
):
ovs-vsctl set Interface foo ofport_request=9
Changing ofport at the moment of creation:
ovs-vsctl add-port mybr foobar -- set Interface foo ofport_request=9
P.S.
It took me a whole hour to google up existence and get the meaning of ofport_request
through experiments, therefore, I believe, this article may be helpful.