summaryrefslogtreecommitdiff
path: root/python
Commit message (Collapse)AuthorAgeFilesLines
* python-stream: Handle SSL error in do_handshake.Stefan Hoffmann2023-04-261-1/+2
| | | | | | | | | | | | | | | | | | | In some cases ovsdb server or relay gets restarted, ovsdb python clients may keep the local socket open. Instead of reconnecting a lot of failures will be logged. This can be reproduced with ssl connections to the server/relay and restarting it, so it has the same IP after restart. This patch catches the Exceptions at do_handshake to recreate the connection on the client side. Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: Stefan Hoffmann <stefan.hoffmann@cloudandheat.com> Signed-off-by: Luca Czesla <luca.czesla@mail.schwarz> Signed-off-by: Max Lamprecht <max.lamprecht@mail.schwarz> Co-authored-by: Luca Czesla <luca.czesla@mail.schwarz> Co-authored-by: Max Lamprecht <max.lamprecht@mail.schwarz> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* odp: Add SRv6 tunnel actions.Nobuhiro MIKI2023-03-292-0/+24
| | | | | | | This patch adds ODP actions for SRv6 and its tests. Signed-off-by: Nobuhiro MIKI <nmiki@yahoo-corp.jp> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Don't exit OFPFlow constructor.Adrian Moreno2022-12-211-3/+0
| | | | | | | | | | | Returning None in a constructor does not make sense and is just error prone. Removing what was a leftover from an attempt to handle a common error case of trying to parse what is commonly outputted by ovs-ofctl. This should be done by the caller anyway. Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Acked-by: Mike Pattrick <mkp@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Interpret free keys as output in clone.Adrian Moreno2022-12-212-2/+17
| | | | | | | clone-like actions can also output to ports by specifying the port name. Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Fix output=CONTROLLER action.Adrian Moreno2022-12-212-2/+10
| | | | | | | | | When CONTROLLER is used as free key, it means output=CONTROLLER which is handled by decode_controller. However, it must output the KV in the right format: "output": {"format": "CONTROLLER"}. Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Support case-insensitive OpenFlow actions.Adrian Moreno2022-12-213-6/+33
| | | | | | | | OpenFlow actions names can be capitalized so in order to support this, support case-insensitive KVDecoders and use it in Openflow actions. Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Return list of actions for odp action clone.Adrian Moreno2022-12-215-38/+59
| | | | | | | | | | | | | Sometimes we don't want to return the result of a nested key-value decoding as a dictionary but as a list of dictionaries. This happens when we parse actions where keys can be repeated. Refactor code that already takes that into account from ofp_act.py to kv.py and use it for datapath action "clone". Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Acked-by: Mike Pattrick <mkp@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Make key-value matching strict by default.Adrian Moreno2022-12-214-19/+61
| | | | | | | | | | | | | | | | | | | | Currently, if a key is not found in the decoder information, we use the default decoder which typically returns a string. This not only means we can go out of sync with the C code without noticing but it's also error prone as malformed flows could be parsed without warning. Make KeyValue parsing strict, raising an error if a decoder is not found for a key. This behaviour can be turned off globally by running 'KVDecoders.strict = False' but it's generally not recommended. Also, if a KVDecoder does need this default behavior, it can be explicitly configured specifying it's default decoder. Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Acked-by: Mike Pattrick <mkp@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add explicit decoders for all ofp actions.Adrian Moreno2022-12-214-49/+105
| | | | | | | | | | | | | | | We were silently relying on some ofp actions to be decoded by the default decoder which would yield decent string values. In order to be more safe and robust, add an explicit decoder for all missing actions. This patch also reworks the learn action decoding to make it more explicit and verify all the fields specified in the learn action are actually valid fields. Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Fix datapath flow decoders.Adrian Moreno2022-12-211-5/+22
| | | | | | | | | | | Fix the following erros in odp decoding: - Missing push_mpls action - Typos in collector_set_id, tp_src/tp_dst and csum - Missing two fields in vxlan match Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Acked-by: Mike Pattrick <mkp@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb-cs: Consider default conditions implicitly acked.Dumitru Ceara2022-12-131-2/+2
| | | | | | | | | | | | | | | | | When initializing a monitor table the default monitor condition is [True] which matches the behavior of the server (to send all rows of that table). There's no need to include this default condition in the initial monitor request so we can consider it implicitly acked by the server. This fixes the incorrect (one too large) expected condition sequence number reported by ovsdb_idl_set_condition() when application is trying to set a [True] condition for a new table. Reported-by: Numan Siddique <numans@ovn.org> Suggested-by: Ilya Maximets <i.maximets@ovn.org> Signed-off-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb-idl: Add the support to specify the uuid for row insert.Numan Siddique2022-11-301-8/+18
| | | | | | | | | | | | | | | | | | | | | | | | ovsdb-server allows the OVSDB clients to specify the uuid for the row inserts [1]. Both the C IDL client library and Python IDL are missing this feature. This patch adds this support. In C IDL, for each schema table, a new function is generated - <schema_table>insert_persistent_uuid(txn, uuid) which can be used the clients to persist the uuid. ovs-vsctl and other derivatives of ctl now supports the same in the generic 'create' command with the option "--id=<UUID>". In Python IDL, the uuid to persist can be specified in the Transaction.insert() function. [1] - a529e3cd1f("ovsdb-server: Allow OVSDB clients to specify the UUID for inserted rows.:) Acked-by: Adrian Moreno <amorenoz@redhat.com> Acked-by: Han Zhou <hzhou@ovn.org> Acked-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Numan Siddique <numans@ovn.org> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: idl: Fix idl.Row.__str__ method.Christopher Aubut2022-09-191-1/+2
| | | | | | | | | | | | | Fixes idl.Row's __str__ method to only print if the column exists on the object. The Row object passed to the 'updates' argument of Idl.notify only contains a subset of columns. Printing that argument causes an AttributeError. Fixes: 6a1c98461b46 ("Add a __str__ method to idl.Row") Submitted-at: https://github.com/openvswitch/ovs/pull/392 Acked-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Christopher Aubut <christopher@aubut.me> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python-c-ext: Use designated initializers for type and module.Ilya Maximets2022-08-301-45/+11
| | | | | | | | | | Python documentation suggests to do so "to avoid listing all the PyTypeObject fields that you don't care about and also to avoid caring about the fields' declaration order". And that does make sense. Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Do not send non-zero flag for a SSL socket.Miro Tomaska2022-08-121-1/+11
| | | | | | | | | | | | | | | pyOpenSSL was recently switched for the Python standard library ssl module in the cited commit. Python SSLsocket.send() does not allow non-zero optional flag and it will explicitly raise an exception for that. pyOpenSSL did nothing with this flag but kept it to be compatible with socket API: https://github.com/pyca/pyopenssl/blob/main/src/OpenSSL/SSL.py#L1844 Fixes: 68543dd523bd ("python: Replace pyOpenSSL with ssl.") Reported-at: https://bugzilla.redhat.com/2115035 Acked-By: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Miro Tomaska <mtomaska@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Fix E275 missing whitespace after keyword.Ilya Maximets2022-08-042-4/+4
| | | | | | | | | | | | | | | | | | | | With just released flake8 5.0 we're getting a bunch of E275 errors: utilities/bugtool/ovs-bugtool.in:959:23: E275 missing whitespace after keyword tests/test-ovsdb.py:623:11: E275 missing whitespace after keyword python/setup.py:105:8: E275 missing whitespace after keyword python/setup.py:106:8: E275 missing whitespace after keyword python/ovs/db/idl.py:145:15: E275 missing whitespace after keyword python/ovs/db/idl.py:167:15: E275 missing whitespace after keyword make[2]: *** [flake8-check] Error 1 This breaks CI on branches below 2.16. We don't see a problem right now on newer branches because we're installing extra dependencies that backtrack flake8 down to 4.1 or even 3.9. Acked-by: Mike Pattrick <mkp@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Use setuptools instead of distutils.Timothy Redaelli2022-08-041-5/+9
| | | | | | | | | | | | | | | On Python 3.12, distutils will be removed and it's currently (3.10+) deprecated (see PEP 632). Since the suggested and simplest replacement is setuptools, this commit replaces distutils to use setuptools instead. setuptools < 59.0 doesn't have setuptools.errors and so, in this case, distutils.errors is still used. Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Acked-by: Mike Pattrick <mkp@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add ability to pass extra libs and cflags for C extension.Ilya Maximets2022-07-291-6/+13
| | | | | | | | | | | | In order to correctly link with static libopenvswitch.a library, users should also provide required cflags and all the libraries libopenvswitch.a was actually built with and depends on. Otherwise, it's not possible to link correctly. Fixes: 671f93fe42d3 ("python: Allow building json C extension with static OVS library.") Acked-by: Frode Nordahl <frode.nordahl@canonical.com> Reviewed-by: David Marchand <david.marchand@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python-c-ext: Handle initialization failures.Ilya Maximets2022-07-291-1/+9
| | | | | | | | | | | | | PyModule_AddObject() may fail and it doesn't steal references in this case. The error condition should be handled to avoid possible memory leaks. And while it's not strictly specified if PyModule_Create may fail, most of the examples in python documentation include handling of a NULL case. Acked-by: Mike Pattrick <mkp@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python-c-ext: Fix a couple of build warnings.Timothy Redaelli2022-07-221-2/+2
| | | | | | | | | | | ovs/_json.c:67:20: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] ovs/_json.c:132:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare] Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python-c-ext: Remove Python 2 support.Timothy Redaelli2022-07-221-33/+1
| | | | | | | | | Since Python 2 is not supported anymore, remove Python 2 support from C extension too Fixes: 1ca0323e7c29 ("Require Python 3 and remove support for Python 2.") Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add unit tests for filtering engine.Adrian Moreno2022-07-152-0/+222
| | | | | | | | Add unit test for OFFilter class. Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add unit tests to datapath parsing.Adrian Moreno2022-07-152-0/+528
| | | | | | | | Add unit tests to datapath flow parsing. Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add unit tests for openflow parsing.Adrian Moreno2022-07-153-1/+667
| | | | | | | | Add unit tests for OFPFlow class and ip-port range decoder Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add unit tests for ListParser.Adrian Moreno2022-07-152-1/+68
| | | | | | | | Add unit tests for ListParser class. Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Introduce unit tests.Adrian Moreno2022-07-153-2/+86
| | | | | | | | Use pytest to run unit tests as part of the standard testsuite. Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add a json encoder to flow fields.Adrian Moreno2022-07-151-0/+14
| | | | | | | | The json encoder can be used to convert Flows to json. Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add flow filtering syntax.Adrian Moreno2022-07-154-2/+264
| | | | | | | | | | | | | | | | | | | | Based on pyparsing, create a very simple filtering syntax. It supports basic logic statements (and, &, or, ||, not, !), numerical operations (<, >), equality (=, !=), and masking (~=). The latter is only supported in certain fields (IntMask, EthMask, IPMask). Masking operation is semantically equivalent to "includes", therefore: ip_src ~= 192.168.1.1 means that ip_src field is either a host IP address equal to 192.168.1.1 or an IPMask that includes it (e.g: 192.168.1.1/24). Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add ovs datapath flow parsing.Adrian Moreno2022-07-152-0/+784
| | | | | | | | | | | | | | | | | A ODPFlow is a Flow with the following sections: ufid info (e.g: bytes, packets, dp, etc) match actions Only three datapath actions require special handling: gre: because it has double parenthesis geneve: because it supports many concatenated lists of options nat: we reuse the decoder used for openflow actions Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Introduce OpenFlow Flow parsing.Adrian Moreno2022-07-154-0/+844
| | | | | | | | | | | | | | Introduce OFPFlow class and all its decoders. Most of the decoders are generic (from decoders.py). Some have special syntax and need a specific implementation. Decoders for nat are moved to the common decoders.py because it's syntax is shared with other types of flows (e.g: dpif flows). Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add flow base class.Adrian Moreno2022-07-152-0/+126
| | | | | | | | | | It simplifies the implementation of different types of flows by creating the concept of Section (e.g: match, action) and automatic accessors for all the provided Sections Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* build-aux: Generate ofp field decoders.Adrian Moreno2022-07-152-1/+9
| | | | | | | | | Based on meta-field information extracted by extract_ofp_fields, autogenerate the right decoder to be used. Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* build-aux: Split extract-ofp-fields.Adrian Moreno2022-07-152-2/+426
| | | | | | | | | | | In order to be able to reuse the core extraction logic, split the command in two parts. The core extraction logic is moved to python/build while the command that writes the different files out of the extracted field info is kept in build-aux. Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add list parser.Adrian Moreno2022-07-152-0/+122
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some openflow or dpif flows encode their arguments in lists, eg: "some_action(arg1,arg2,arg3)". In order to decode this in a way that can be then stored and queried, add ListParser and ListDecoders classes that parse lists into KeyValue instances. The ListParser / ListDecoders mechanism is quite similar to KVParser and KVDecoders. Since the "key" of the different KeyValue objects is now ommited, it has to be provided by ListDecoders. For example, take the openflow action "resubmit" that can be written as: resubmit([port],[table][,ct]) Can be decoded by creating a ListDecoders instance such as: ListDecoders([ ("port", decode_default), ("table", decode_int), ("ct", decode_flag), ]) Naturally, the order of the decoders must be kept. Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add mask, ip and eth decoders.Adrian Moreno2022-07-153-1/+413
| | | | | | | | | | | | | | | | | | Add more decoders that can be used by KVParser. For IPv4 and IPv6 addresses, create a new class that wraps netaddr.IPAddress. For Ethernet addresses, create a new class that wraps netaddr.EUI. For Integers, create a new class that performs basic bitwise mask comparisons netaddr is added as a new shoft dependency: - extras_require in setup.py - Suggests in deb and rpm packages Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add generic Key-Value parser.Adrian Moreno2022-07-155-2/+338
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Most of ofproto and dpif flows are based on key-value pairs. These key-value pairs can be represented in several ways, eg: key:value, key=value, key(value). Add the following classes that allow parsing of key-value strings: * KeyValue: holds a key-value pair * KeyMetadata: holds some metadata associated with a KeyValue such as the original key and value strings and their position in the global string * KVParser: is able to parse a string and extract it's key-value pairs as KeyValue instances. Before creating the KeyValue instance it tries to decode the value via the KVDecoders * KVDecoders holds a number of decoders that KVParser can use to decode key-value pairs. It accepts a dictionary of keys and callables to allow users to specify what decoder (i.e: callable) to use for each key Also, flake8 seems to be incorrectly reporting an error (E203) in: "slice[index + offset : index + offset]" which is PEP8 compliant. So, ignore this error. Acked-by: Terry Wilson <twilson@redhat.com> Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Allow building json C extension with static OVS library.Frode Nordahl2022-07-151-1/+11
| | | | | | | | | | | | | | | Allow caller of setup.py to pass in libopenvswitch.a as an object for linking through the use of LDFLAGS environment variable when not building a shared openvswitch library. To accomplish this set the `enable_shared` environment variable to 'no'. Example: LDFLAGS=lib/libopenvswitch.a enable_shared=no setup.py install Signed-off-by: Frode Nordahl <frode.nordahl@canonical.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Add Python bindings TODO file.Dumitru Ceara2022-06-282-0/+36
| | | | | | | | | For now include the IDL related TODO items as discussed at: https://mail.openvswitch.org/pipermail/ovs-dev/2022-April/393516.html Signed-off-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: idl: Raise AttributeError from uuid_to_row.Terry Wilson2022-05-021-1/+6
| | | | | | | | | | | | | | | Prior to 4e3966e64, when calling _uuid_to_row, it would raise an AttributeError when trying to access base.ref_table.rows if the referenced table was not registered. When called from Row.__getattr__(), this would appropriately raise an AttributeError. After 4e3966e64, a KeyError would be raised, which is not expected from a getattr() or hasattr() call, which could break existing code. Fixes: 4e3966e64bed ("python: Politely handle misuse of table.condition.") Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Politely handle misuse of table.condition.Terry Wilson2022-04-271-35/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before 46d44cf3b, it was technically possible to assign a monitor condition directly to Idl.tables[table_name].condition. If done before the connection was established, it would successfully apply the condition (where cond_change() actually would fail). Although this wasn't meant to be supported, several OpenStack projects made use of this. After 46d44cf3b, .condition is no longer a list, but a ConditionState. Assigning a list to it breaks the Idl. The Neutron and ovsdbapp projects have patches in-flight to use Idl.cond_change() if ConditionState exists, as it now works before connection as well, but here could be other users that also start failing when upgrading to OVS 2.17. Instead of directly adding attributes to TableSchema, this adds the IdlTable/IdlColumn objects which hold Idl-specific data and adds a 'condition' property to TableSchema that maintains the old interface. Fixes: 46d44cf3be0d ("python: idl: Add monitor_cond_since support.") Signed-off-by: Terry Wilson <twilson@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Acked-By: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: idl: Set cond_changed to true if condition change requested.Wentao Jia2022-04-041-1/+1
| | | | | | | | | | | cond_changed set to true if _req_cond (requested condition change) is not none. This can avoid falling into an endless poll loop, because cond_changed is true will trigger immediate_wake(). Fixes: 46d44cf3be0d ("python: idl: Add monitor_cond_since support.") Signed-off-by: Wentao Jia <wentao.jia@easystack.cn> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: idl: Set cond_changed to false if last id is zero.Wentao Jia2022-04-041-0/+3
| | | | | | | | | | After reconnection, cond_changed will be set to true, poll will be called and never block causing cpu high load forever. Fixes: 46d44cf3be0d ("python: idl: Add monitor_cond_since support.") Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Wentao Jia <wentao.jia@easystack.cn> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* reconnect: Fix broken inactivity probe if there is no other reason to wake up.Ilya Maximets2022-02-241-11/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The purpose of reconnect_deadline__() function is twofold: 1. Its result is used to tell if the state has to be changed right now in reconnect_run(). 2. Its result also used to determine when the process need to wake up and call reconnect_run() for a next time, i.e. when the state may need to be changed next time. Since introduction of the 'receive-attempted' feature, the function returns LLONG_MAX if the deadline is in the future. That works for the first case, but doesn't for the second one, because we don't really know when we need to call reconnect_run(). This is the problem for applications where jsonrpc connection is the only source of wake ups, e.g. ovn-northd. When the network goes down silently, e.g. server looses IP address due to DHCP failure, ovn-northd will sleep in the poll loop indefinitely after being told that it doesn't need to call reconnect_run() (deadline == LLONG_MAX). Fixing that by actually returning the expected time if it is in the future, so we will know when to wake up. In order to keep the 'receive-attempted' feature, returning 'now + 1' in case where the time has already passed, but receive wasn't attempted. That will trigger a fast wake up, so the application will be able to attempt the receive even if there was no real events. In a correctly written application we should not fall into this case more than once in a row. '+ 1' ensures that we will not transition into a different state prematurely, i.e. before the receive is actually attempted. Fixes: 4241d652e465 ("jsonrpc: Avoid disconnecting prematurely due to long poll intervals.") Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: idl: Clear last_id on reconnect if condition changes in-flight.Dumitru Ceara2022-01-311-1/+17
| | | | | | | | | | | | | | | | | | | | When reconnecting, if there are condition changes already sent to the server but not yet acked, reset the db's 'last-id', esentially clearing the local cache after reconnect. This is needed because the client cannot easily differentiate between the following cases: a. either the server already processed the requested monitor condition change but the FSM was restarted before the client was notified. In this case the client should clear its local cache because it's out of sync with the monitor view on the server side. b. OR the server hasn't processed the requested monitor condition change yet. Fixes: 46d44cf3be0d ("python: idl: Add monitor_cond_since support.") Signed-off-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: idl: Resend requested but not acked conditions when reconnecting.Dumitru Ceara2022-01-311-2/+4
| | | | | | | | | | | | When reconnecting forget about in-flight monitor condition changes if the user requested a newer condition already. This matches the C implementation, in ovsdb_cs_db_sync_condition(). Fixes: 46d44cf3be0d ("python: idl: Add monitor_cond_since support.") Signed-off-by: Dumitru Ceara <dceara@redhat.com> Acked-By: Terry Wilson <twilson@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: idl: Add monitor_cond_since support.Terry Wilson2022-01-061-35/+210
| | | | | | | | | | Add support for monitor_cond_since / update3 to python-ovs to allow more efficient reconnections when connecting to clustered OVSDB servers. Signed-off-by: Terry Wilson <twilson@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb-data: Consolidate ovsdb atom and json strings.Ilya Maximets2021-11-301-4/+6
| | | | | | | | | | | | | | ovsdb_atom_string and json_string are basically the same data structure and ovsdb-server frequently needs to convert one to another. We can avoid that by using json_string from the beginning for all ovsdb strings. So, the conversion turns into simple json_clone(), i.e. increment of a reference counter. This change gives a moderate performance boost in some scenarios, improves the code clarity and may be useful for future development. Acked-by: Mike Pattrick <mkp@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: idl: Avoid pre-allocating column defaults.Terry Wilson2021-11-301-6/+33
| | | | | | | | | | | | | | | | | | | | | Many python implementations pre-allocate space for multiple objects in empty dicts and lists. Using a custom dict-like object that only generates these objects when they are accessed can save memory. On a fairly pathological case where the DB has 1000 networks each with 100 ports, with only 'name' fields set, this saves around 300MB of memory. One could argue that if values are not going to change from their defaults, then users should not be monitoring those columns, but it's also probably good to not waste memory even if user code is sub-optimal. Signed-off-by: Terry Wilson <twilson@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Flavio Fernandes <flavio@flaviof.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: db: Avoid allocation of an attr dict/row+column.Terry Wilson2021-11-091-0/+4
| | | | | | | | | | | | | | | | | Python objects normally have a dictionary named __dict__ allocated for handling dynamically assigned attributes. Depending on architecture and Python version, that empty dict may be between 64 and 280 bytes. Seeing as Atom and Datum objects do not need dynamic attribute support and there can be millions of rows in a database, avoiding this allocation with __slots__ can save 100s of MBs of memory per Idl process. Signed-off-by: Terry Wilson <twilson@redhat.com> Acked-by: Timothy Redaelli <tredaelli@redhat.com> Tested-by: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python: Replace pyOpenSSL with ssl.Timothy Redaelli2021-11-032-40/+57
| | | | | | | | | | | | | | | | | | | | | | | | Currently, pyOpenSSL is half-deprecated upstream and so it's removed on some distributions (for example on CentOS Stream 9, https://issues.redhat.com/browse/CS-336), but since OVS only supports Python 3 it's possible to replace pyOpenSSL with "import ssl" included in base Python 3. Stream recv and send had to be splitted as _recv and _send, since SSLError is a subclass of socket.error and so it was not possible to except for SSLWantReadError and SSLWantWriteError in recv and send of SSLStream. TCPstream._open cannot be used in SSLStream, since Python ssl module requires the SSL socket to be created before connecting it, so SSLStream._open needs to create the socket, create SSL socket and then connect the SSL socket. Reported-by: Timothy Redaelli <tredaelli@redhat.com> Reported-at: https://bugzilla.redhat.com/1988429 Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Acked-by: Terry Wilson <twilson@redhat.com> Tested-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>