summaryrefslogtreecommitdiff
path: root/python/ovs/flow
Commit message (Collapse)AuthorAgeFilesLines
* odp: Add SRv6 tunnel actions.Nobuhiro MIKI2023-03-291-0/+8
| | | | | | | 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-211-2/+4
| | | | | | | 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-211-1/+1
| | | | | | | | | 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-212-6/+18
| | | | | | | | 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-214-27/+32
| | | | | | | | | | | | | 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-212-8/+24
| | | | | | | | | | | | | | | | | | | | 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-213-46/+102
| | | | | | | | | | | | | | | 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>
* 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-152-1/+262
| | | | | | | | | | | | | | | | | | | | 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-151-0/+783
| | | | | | | | | | | | | | | | | 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-153-0/+842
| | | | | | | | | | | | | | 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-151-0/+125
| | | | | | | | | | 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>
* python: Add list parser.Adrian Moreno2022-07-151-0/+121
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-152-0/+411
| | | | | | | | | | | | | | | | | | 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-153-0/+332
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>