summaryrefslogtreecommitdiff
path: root/lib/learn.c
Commit message (Collapse)AuthorAgeFilesLines
* learn: Fix parsing immediate value for a field match.Ilya Maximets2022-11-241-11/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The value is right-justified after the string parsing with parse_int_string(), i.e. it is in BE byte order and aligned to the right side of the array. For example, the 0x10011 value in a 4-byte field will look like 0x00 0x01 0x00 0x11. However, value copy to the resulted ofpact is performed from the start of the memory. So, in case the destination size is smaller than the original field size, incorrect part of the value will be copied. In the 0x00 0x01 0x00 0x11 example above, if the copy is performed to a 3-byte field, the first 3 bytes will be copied, which are 0x00 0x01 0x00 instead of 0x01 0x00 0x11. This leads to a problem where NXM_NX_REG3[0..16]=0x10011 turns into NXM_NX_REG3[0..16]=0x100 after the parsing. Fix that by offsetting the starting position to the size difference in bytes similarly to how it is done in learn_parse_load_immediate(). While at it, changing &imm to imm.b in function calls that expect byte arrays as an argument. The old way is technically correct, but more error prone. The mf_write_subfield_value() call was also incorrect. However, the 'match' variable is actually not used for anything since checking removal in commit: dd43a558597b ("Do not perform validation in learn_parse();") So, just removing the call and the 'match' variable entirely instead of fixing it. Fixes: 21b2fa617126 ("ofp-parse: Allow match field names in actions and brackets in matches.") Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2022-November/052100.html Reported-by: Thomas Lee <newsforthomas@engineer.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* lib: added check to prevent int overflowToms Atteka2019-03-261-0/+5
| | | | | | | | | | | | | | If enough large input is given ofpact_finish will fail. Implemented ofpbuf_oversized function to check for oversized buffer. Checks were added for parse functions and error messages returned. Basic manual testing performed. Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com> Reported-by: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12972 Signed-off-by: Toms Atteka <cpp.code.lv@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovs-actions: New document describing OVS actions in detail.Ben Pfaff2019-01-101-2/+2
| | | | | Acked-by: Mark Michelson <mmichels@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ofp-flow: Reduce memory consumption for ofputil_flow_mod, using minimatch.Ben Pfaff2018-03-311-4/+8
| | | | | | | | | | | | | | | | | | | | | | | Until now, struct ofputil_flow_mod, which represents an OpenFlow flow table modification request, has incorporated a struct match, which made the overall ofputil_flow_mod about 2.5 kB. This is OK for a small number of flows, but absurdly inflates memory requirements when there are hundreds of thousands of flows. This commit fixes the problem by changing struct match to struct minimatch inside ofputil_flow_mod, which reduces its size to about 100 bytes plus the actual size of the flow match (usually a few dozen bytes). This affects memory usage of ovs-ofctl (when it adds a large number of flows) more than ovs-vswitchd. Reported-by: Michael Ben-Ami <mbenami@digitalocean.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Reviewed-by: Armando Migliaccio <armamig@gmail.com> Tested-by: Armando Migliaccio <armamig@gmail.com> Reviewed-by: Jan Scheurich <jan.scheurich@ericsson.com> Tested-by: Jan Scheurich <jan.scheurich@ericsson.com> Tested-by: Yifeng Sun <pkusunyifeng@gmail.com> Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
* ofp-util, ofp-parse: Break up into many separate modules.Ben Pfaff2018-02-131-1/+3
| | | | | | | | | | | | ofp-util had been far too large and monolithic for a long time. This commit breaks it up into units that make some logical sense. It also moves the pieces of ofp-parse that were specific to each unit into the relevant unit. Most of this commit is just moving code around. Signed-off-by: Ben Pfaff <blp@ovn.org> Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
* Support accepting and displaying table names in OVS tools.Ben Pfaff2018-02-011-7/+13
| | | | | | | | | | | | | | | | | | | | | | | | OpenFlow has little-known support for naming tables. Open vSwitch has supported table names for ages, but it has never used or displayed them outside of commands dedicated to table manipulation. This commit adds support for table names in ovs-ofctl. When a table has a name, it displays that name in flows and actions, so that, for example, the following: table=1, arp, actions=resubmit(,2) might become: table=ingress_acl, arp, actions=resubmit(,mac_learning) given appropriately named tables. For backward compatibility, only interactive ovs-ofctl commands by default display table names; to display them in scripts, use the new --names option. This feature was inspired by a talk that Kei Nohguchi presented at Open vSwitch 2017 Fall Conference. CC: Kei Nohguchi <kei@nohguchi.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Mark Michelson <mmichels@redhat.com> Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
* Eliminate most shadowing for local variable names.Ben Pfaff2017-08-021-4/+3
| | | | | | | | | | | | | | Shadowing is when a variable with a given name in an inner scope hides a different variable with the same name in a surrounding scope. This is generally undesirable because it can confuse programmers. This commit eliminates most of it. Found with -Wshadow=local in GCC 7. The repo is not really ready to enable this option by default because of a few cases that are harder to fix, and harmless, such as nested use of CMAP_FOR_EACH. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
* userspace: Add OXM field MFF_PACKET_TYPEJan Scheurich2017-06-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | | Allow packet type namespace OFPHTN_ETHERTYPE as alternative pre-requisite for matching L3 protocols (MPLS, IP, IPv6, ARP etc). Change the meta-flow definition of packet_type field to use the new custom format MFS_PACKET_TYPE representing "(NS,NS_TYPE)". Parsing routine for MFS_PACKET_TYPE added to meta-flow.c. Formatting routine for field packet_type extracted from match_format() and moved to flow.c to be used from meta-flow.c for formatting MFS_PACKET_TYPE. Updated the ovs-fields man page source meta-flow.xml with documentation for packet-type-aware bridges and added documentation for field packet_type. Added packet_type to the matching properties in tests/ofproto.at. If dl_type is unwildcarded due to later packet modification, make sure it is cleared again if the original packet_type was not PT_ETH. Signed-off-by: Jan Scheurich <jan.scheurich@ericsson.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Support accepting and displaying port names in OVS tools.Ben Pfaff2017-05-311-8/+14
| | | | | | | | | | | | | | Until now, most ovs-ofctl commands have not accepted names for ports, only numbers, and have not been able to display port names either. It's a lot easier for users if they can use and see meaningful names instead of arbitrary numbers. This commit adds that support. For backward compatibility, only interactive ovs-ofctl commands by default display port names; to display them in scripts, use the new --names option. Signed-off-by: Ben Pfaff <blp@ovn.org> Tested-by: Aaron Conole <aconole@redhat.com>
* learn: Fix memory leak in learn_parse_sepc()Yi-Hung Wei2017-04-241-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | In testcase "ofproto-dpif - fragment handling - actions", valgrind reports memeory leaks with the following call stack. xmalloc (util.c:112) xvasprintf (util.c:176) xasprintf (util.c:272) mf_parse_subfield__ (nx-match.c:1939) mf_parse_subfield (nx-match.c:1991) learn_parse_spec (learn.c:242) learn_parse__ (learn.c:436) learn_parse (learn.c:464) parse_LEARN (ofp-actions.c:4670) ofpact_parse (ofp-actions.c:8231) ofpacts_parse__ (ofp-actions.c:8278) ofpacts_parse (ofp-actions.c:8350) ofpacts_parse_copy (ofp-actions.c:8368) parse_ofp_str__ (ofp-parse.c:543) parse_ofp_str (ofp-parse.c:596) parse_ofp_flow_mod_str (ofp-parse.c:1024) ofctl_flow_mod (ovs-ofctl.c:1496) ovs_cmdl_run_command__ (command-line.c:115) main (ovs-ofctl.c:147) Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ofp-actions: Add limit to learn action.Daniele Di Proietto2017-03-161-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds a new feature to the learn actions: the possibility to limit the number of learned flows. To be compatible with users of the old learn action, a new structure is introduced as well as a new OpenFlow raw action number. There's a small corner case when we have to delete the ukey. This happens when: * The learned rule has expired (or has been deleted). * The ukey that learned the rule is still in the datapath. * No packets hit the datapath flow recently. In this case we cannot relearn the rule (because there are no new packets), and the actions might depend on the learn execution, so the only option is to delete the ukey. I don't think this has big performance implications since it's done only for ukey with no traffic. We could also slowpath it, but that will cause an action upcall and the correct datapath actions will be installed later by a revalidator. If we delete the ukey, the next upcall will be a miss upcall and that will immediatedly install the correct datapath flow. Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ofproto: Add ref counting for variable length mf_fields.Yi-Hung Wei2017-03-151-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | Currently, a controller may potentially trigger a segmentation fault if it accidentally removes a TLV mapping that is still used by an active flow. To resolve this issue, in this patch, we maintain reference counting for each dynamically allocated variable length mf_fields, so that vswitchd can use this information to properly remove a TLV mapping, and to return an error if the controller tries to remove a TLV mapping that is still used by any active flow. To keep track of the usage of tun_metadata for each flow, two 'uint64_t' bitmaps are introduce for the flow match and flow action respectively. We use 'uint64_t' as a bitmap since the 64 geneve TLV tunnel metadata are the only available variable length mf_fields for now. We shall adopt general bitmap when more variable length mf_fields are introduced. The bitmaps are configured during the flow decoding process, and vswitchd use these bitmaps to increase or decrease the ref counting when the flow is created or deleted. VMWare-BZ: #1768370 Fixes: 04f48a68c428 ("ofp-actions: Fix variable length meta-flow OXMs.") Suggested-by: Jarno Rajahalme <jarno@ovn.org> Suggested-by: Joe Stringer <joe@ovn.org> Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com> Signed-off-by: Joe Stringer <joe@ovn.org>
* lib: Check match and action prerequisities with 'match'.Jarno Rajahalme2017-03-081-7/+8
| | | | | | | | | | | | | | | Supply the match mask to prerequisities checking when available. This allows checking for zero-valued matches. Non-zero valued matches imply the presense of corresponding mask bits, but for zero valued matches we must explicitly check the mask, too. This is required now only for conntrack validity checking due to the conntrack state having and 'invalid' bit, but not 'valid' bit. One way to match an valid conntrack state is to match on the 'tracked' bit being one and 'invalid' bit being zero. The latter requires the corresponding mask bit be verified. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Joe Stringer <joe@ovn.org>
* ofp-parse: Allow match field names in actions and brackets in matches.Jarno Rajahalme2017-01-041-56/+89
| | | | | | | | | | | | | | | | | | | | | | | | Allow using match field names in addition to the canonical register names in actions (including 'load', 'move', 'push', 'pop', 'output', 'multipath', 'bundle_load', and 'learn'). Allow also leaving out the trailing '[]' to indicate full field. These changes allow simpler syntax similar to 'set_field' to be used also elsewhere. Correspondingly, allow the '[start..end]' syntax to be used in matches in addition to the more explicit 'value/mask' notation. For example, to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match could include: ... reg0[14..15]=2 ... instead of ... reg0=0x8000/0xc000 ... Note that only contiguous masks can be specified with the bracket notation. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* learn: Fix iteration over learning specs.Ben Pfaff2016-09-021-9/+4
| | | | | | | | | | | | | | | | struct ofpact_learn_spec is variable-length. The 'n_specs' member of struct ofpact_learn counted the number of specs, but the iteration loops over struct ofpact_learn_spec only iterated as far as the *minimum* length of 'n_specs' specs. This fixes the problem, which exhibited as consistent failures for test 431 (learning action - TCPv6 port learning), seemingly only on i386 since it shows up for my personal development machine but appears to not happen for anyone else. Fixes: dfe191d5faa6 ("ofp-actions: Waste less memory in learn actions.") Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Jarno Rajahalme <jarno@ovn.org>
* learn: Avoid nested zero-sized arrays to fix build with MSVC.Jarno Rajahalme2016-09-011-6/+10
| | | | | | | | | | | | Avoid using nested zero-sized arrays to allow compilation with MSVC. Also, make sure the immediate data is accessed only if it exists, and that the size is always calculated from struct learn_spec field 'n_bits'. Fixes: dfe191d5faa6 ("ofp-actions: Waste less memory in learn actions.") Reported-by: Alin Serdean <aserdean@cloudbasesolutions.com> Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* ofp-actions: Waste less memory in set field and load actions.Jarno Rajahalme2016-08-311-5/+4
| | | | | | | | | | | | | | | Change the value and mask to be added to the end of the set field action without any extra bytes, exept for the usual ofp-actions padding to 8 bytes. Together with some structure member packing this saves on average about to 256 bytes for each set field and load action (as set field internal representation is also used for load actions). On a specific production data set each flow entry uses on average about 4.2 load or set field actions. This means that with this patch an average of more than 1kb can be saved for each flow with such a flow table. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* ofp-actions: Waste less memory in learn actions.Jarno Rajahalme2016-08-311-32/+40
| | | | | | | | | | | Make the immediate data member 'src_imm' of a learn spec allocated at the end of the action for just the right size. This, together with some structure packing saves on average of ~128 bytes for each learn spec in each learn action. Typical learn actions have about 4 specs each, so this amounts to saving about 0.5kb for each learn action. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* ofp-util: remove flow mod's delete_reason.Jarno Rajahalme2016-07-291-1/+0
| | | | | | | We can use the rule's removed_reason instead. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* Move lib/ofp-actions.h to include/openvswitch directoryBen Warren2016-04-141-4/+4
| | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/ofp-util.h to include/openvswitch directoryBen Warren2016-04-141-1/+1
| | | | | | | | This commit also adds several #include directives in source files in order to make the 'ofp-util.h' move possible Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/meta-flow.h to include/openvswitch directoryBen Warren2016-04-141-1/+1
| | | | | | | | | This commit also moves some bitmap macros into public header files and adds some #include directives in soure files in order to make the 'meta-flow.h' move possible. Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/match.h to include/openvswitch directoryBen Warren2016-04-141-1/+1
| | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ofp-actions: Make ofpact_finish() harder to misuse.Ben Pfaff2016-04-131-1/+1
| | | | | | | | | | | | It's pretty easy to forget to update the pointer to an ofpact when finishing it. This commit forces the caller to pass a pointer-to-pointer instead, and uses that to automatically update the pointer. There still could be cases that retain other pointers into the ofpbuf, but I imagine that this is harder to misuse. Suggested-by: Joe Stringer <joe@ovn.org> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Joe Stringer <joe@ovn.org>
* Move lib/ofpbuf.h to include/openvswitch directoryBen Warren2016-03-301-1/+1
| | | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Acked-by: Ryan Moats <rmoats@us.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/dynamic-string.h to include/openvswitch directoryBen Warren2016-03-191-2/+2
| | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/ofp-errors.h to include/openvswitch directoryBen Warren2016-03-191-1/+1
| | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ofp-actions: Color output of flow actions for ovs-ofctl dump-flows.Quentin Monnet2016-03-181-18/+31
| | | | | | | | | Add color output for flow actions for ovs-ofctl dump-flows command utility, by inserting color markers in the functions responsible for printing those actions. Signed-off-by: Quentin Monnet <quentin.monnet@6wind.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ofp-actions: Rename ofpact_update_len() to ofpact_finish().Ben Pfaff2016-01-041-1/+1
| | | | | | | | It does more than just update the length now, so this is a more accurate name. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* ofp-actions: Make composing actions harder to screw up.Ben Pfaff2016-01-041-1/+0
| | | | | | | | | | | | | | Until now, composing a fixed-length action with ofpact_put_<NAME>() failed to append any padding required after the action. This commit changes that so that these calls now add padding. This meant that the function ofpact_pad(), which was until now required in various unintuitive places, is no longer required, and removes it. Variable-length actions still require calling ofpact_update_len() after composition. I don't see a way to avoid that. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* Merge "master" into "ovn".Ben Pfaff2015-06-131-19/+5
|\ | | | | | | | | | | | | | | | | This allows OVN to take advantage of the client scalability changes that have been committed to ovsdb-server on master recently. Conflicts: Makefile.am lib/learn.c
| * learn: Improve error reporting.Ben Pfaff2015-05-291-2/+2
| | | | | | | | | | | | | | | | parse_int_string() returns an error if the field overflows, not if there is a bad hex digit. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Jesse Gross <jesse@nicira.com>
| * util: Library routines for printing and scanning large hex integers.Jesse Gross2015-05-281-19/+4
| | | | | | | | | | | | | | | | | | | | Geneve options are variable length and up to 124 bytes long, which means that they can't be easily manipulated by the integer string functions like we do for other fields. This adds a few helper routines to make these operations easier. Signed-off-by: Jesse Gross <jesse@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
* | meta-flow: Add convenience members to union mf_subvalue.Ben Pfaff2015-03-311-4/+2
|/ | | | | | | | | This makes access to the least-significant bits more convenient. This commit simplifies a few existing cases; later commits will make more use of this feature. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Russell Bryant <rbryant@redhat.com>
* ofpbuf: Simplify ofpbuf API.Pravin B Shelar2015-03-031-3/+3
| | | | | | | | | | | | ofpbuf was complicated due to its wide usage across all layers of OVS, Now we have introduced independent dp_packet which can be used for datapath packet, we can simplify ofpbuf. Following patch removes DPDK mbuf and access API of ofpbuf members. Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* lib: Move compiler.h to <openvswitch/compiler.h>Thomas Graf2014-12-151-4/+4
| | | | | | | | | | The following macros are renamed to avoid conflicts with other headers: * WARN_UNUSED_RESULT to OVS_WARN_UNUSED_RESULT * PRINTF_FORMAT to OVS_PRINTF_FORMAT * NO_RETURN to OVS_NO_RETURN Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Acked-by: Ben Pfaff <blp@nicira.com>
* Add support for OpenFlow 1.4+ "importance" values.Rishi Bamba2014-11-101-0/+1
| | | | | | | | | | | | | | | This patch enables a user to set importance for a new rule via add-flow OF1.4+ in the OVS and display the same via dump-flows command OF1.4+. The changes are made in accordance with OpenFlow 1.4 specs to implement eviction on the basis of "importance". This patch also enhances the diff-flows & replace-flows CLI for addition of importance parameter in a rule. This doesn't actually implement eviction on the basis of importance, which will happen in a later patch. Signed-off-by: Rishi Bamba <rishi.bamba@tcs.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* meta-flow: Make it simpler to expand mf_values in the futureMadhu Challa2014-11-061-2/+4
| | | | | | | | Remove hard coded array index and make it dependent on the array size. Signed-off-by: Madhu Challa <challa@noironetworks.com> Co-authored-by: Ben Pfaff <blp@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* ofp-actions: Support experimenter OXMs in Nicira extensions.Ben Pfaff2014-10-081-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Some of the Nicira extension actions include fixed-size 32-bit members that designate NXM fields. These actions can't accommodate 64-bit experimenter OXMs, so we need to figure out some kind of solution. This commit does that, in different ways for different actions. For some actions, I did not think it was worthwhile to worry about experimenter OXM, so I just disabled use of them. This is what I did for bundle, learn, and multipath actions. Other actions could be gracefully reinterpreted to support experimenter OXM. This is true of reg_move, which use NXM headers only at the end of the action and such that using an experimenter OXM would make the action longer (which unambigously signals to older OVS that the action is an error, which is desired behavior since older OVS cannot interpret this action). The stack push and pop actions are also in this category. reg_load was the most frustrating case. In OpenFlow 1.5 we had already eliminated this action in favor of OF1.5+ set_field. In other OpenFlow versions, though, reg_load is more powerful than set_field because it can modify partial fields. This commit therefore adds a new variant of reg_load, called reg_load2, which is simply OF1.5+ set_field with a Nicira extension header on it. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
* ofp-actions: Support OF1.5 (draft) masked Set-Field, merge with reg_load.Ben Pfaff2014-10-081-14/+8
| | | | | | | | | | | | | | | OpenFlow 1.5 (draft) extends the OFPAT_SET_FIELD action originally introduced in OpenFlow 1.2 so that it can set not just entire fields but any subset of bits within a field as well. This commit adds support for that feature when OpenFlow 1.5 is used. With this feature, OFPAT_SET_FIELD becomes a superset of NXAST_REG_LOAD. Thus, this commit merges the implementations of the two actions into a single ofpact_set_field. ONF-JIRA: EXT-314 Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
* ofp-actions: Centralize all OpenFlow action code for maintainability.Ben Pfaff2014-08-111-212/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Until now, knowledge about OpenFlow has been somewhat scattered around the tree. Some of it is in ofp-actions, some of it is in ofp-util, some in separate files for individual actions, and most of the wire format declarations are in include/openflow. This commit centralizes all of that in ofp-actions. Encoding and decoding OpenFlow actions was previously broken up by OpenFlow version. This was OK with only OpenFlow 1.0 and 1.1, but each additional version added a new wrapper around the existing ones, which started to become hard to understand. This commit merges all of the processing for the different versions, to the extent that they are similar, making the version differences clearer. Previously, ofp-actions contained OpenFlow encoding and decoding, plus ofpact formatting, but OpenFlow parsing was separated into ofp-parse, which seems an odd division. This commit moves the parsing code into ofp-actions with the rest of the code. Before this commit, the four main bits of code associated with a particular ofpact--OpenFlow encoding and decoding, ofpact formatting and parsing--were all found far away from each other. This often made it hard to see what was going on for a particular ofpact, since you had to search around to many different pieces of code. This commit reorganizes so that all of the code for a given ofpact is in a single place. As a code refactoring, this commit has little visible behavioral change. The update to ofproto-dpif.at illustrates one minor bug fix as a side effect: a flow that was added with the action "dec_ttl" (a standard OpenFlow action) was previously formatted as "dec_ttl(0)" (using a Nicira extension to specifically direct packets bounced to the controller because of too-low TTL), but after this commit it is correctly formatted as "dec_ttl". The other visible effect is to drop support for the Nicira extension dec_ttl action in OpenFlow 1.1 and later in favor of the equivalent standard action. It seems unlikely that anyone was really using the Nicira extension in OF1.1 or later. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
* Implement learned flow deletion.Ben Pfaff2014-06-121-12/+14
| | | | | | | | | | | | | | | | | | | | When a flow with a "learn" action is deleted, one often wants the flows that it created (the "learned flows") to be deleted as well. This commit makes that possible. I am aware of a race condition that could lead to a learned flow not being properly deleted. Suppose thread A deletes a flow with a "learn" action. Meanwhile, thread B obtains the actions for this flow and translates and executes them. Thread B could obtain the actions for the flow before it is deleted, but execute them after the "learn" flow and its learned flows are deleted. The result is that the flow created by thread B persists despite its "learn" flow having been deleted. This race can and should be fixed, but I think that this commit is worth reviewing without it. VMware-BZ: #1254021 Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Thomas Graf <tgraf@suug.ch> Acked-by: Ethan Jackson <ethan@nicira.com>
* ofproto: Use OFPRR_GROUP_DELETESimon Horman2014-06-111-0/+1
| | | | | | | | | | | | | Use OFPRR_GROUP_DELETE as the reason for deleting flows due to the removal of a group that they use. This implementation adds an delete_reason member to struct ofputil_flow_mod as a convenient way to set the reason used by delete_flows__() when it is called indirectly from delete_group__(). Signed-off-by: Simon Horman <horms@verge.net.au> [blp@nicira.com initialized the new member in a few more places] Signed-off-by: Ben Pfaff <blp@nicira.com>
* ofp-actions: Store cookie in network byte order in struct ofpact_learn.Ben Pfaff2014-06-061-5/+5
| | | | | | | | | | Most other code in Open vSwitch that works with flow cookies keeps them in network byte order. Using network byte order in struct ofpact_learn, also, reduces the number of byte order conversions needed across the source tree. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Thomas Graf <tgraf@suug.ch>
* ovs-ofctl: Support "send_flow_rem" in "learn" actions.Ben Pfaff2014-06-061-2/+4
| | | | | | | | | This flag was overlooked when support for the "learn" action was added. (It was always supported in the OpenFlow code, just not in the ovs-ofctl interface.) Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Thomas Graf <tgraf@suug.ch>
* ofpbuf: Abstract 'l2' pointer and document usage conventions.Jarno Rajahalme2014-04-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | Rename 'l2' to 'frame' and add new ofpbuf_set_frame() and ofpbuf_l2(). ofpbuf_set_frame() alse resets all the layer offsets. ofpbuf_l2() returns NULL if the packet has no Ethernet header, as indicated either by unset l3 offset or NULL frame pointer. Callers of ofpbuf_l2() are supposed to check the return value, unless they can otherwise be sure that the packet has a valid Ethernet header. The recent commit 437d0d22 made some assumptions that were not valid regarding the use of the 'l2' pointer in rconn module and by compose_rarp(). This is now fixed as follows: rconn now relies on the fact that once OpenFlow messages are given to rconn for transport, the frame pointer is no longer needed to refer to the OpenFlow header; and compose_rarp() now sets the frame pointer and offsets as expected. In addition to storing network frames, ofpbufs are also used for handling OpenFlow messages and action lists. lib/ofpbuf.h now has a comment documenting the current usage conventions and invariants. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* ofpbuf: Introduce access api for base, data and size.Pravin Shelar2014-03-301-6/+6
| | | | | | | These functions will be used by later patches. Following patch does not change functionality. Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
* openvswitch/types.h: New macros OVS_BE16_MAX, OVS_BE32_MAX, OVS_BE64_MAX.Ben Pfaff2013-09-171-1/+1
| | | | | | These seem slightly nicer than e.g. htons(UINT16_MAX). Signed-off-by: Ben Pfaff <blp@nicira.com>
* ofp-util: Abstract flow_mod OFPFF_* flags.Ben Pfaff2013-08-271-2/+13
| | | | | | | | | | | | | | | | | | The OFPFF_* flags used in flow_mods are just confusing enough that it seems worthwhile to try to abstract them out. In particular: * OFPFF_EMERG was introduced in OF1.0, deleted in OF1.1, and then its bit was reused for a different purpose in OF1.2. * OFPFF_RESET_COUNTS was introduced in OF1.2 but the semantics that it specifies are implied by "add" commands in earlier versions, so proper translation requires the OpenFlow version number and flow_mod command. This commit does the abstraction. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* ofp-util: Add 'modify_cookie' to struct ofputil_flow_mod, to support OF1.1.Ben Pfaff2013-07-081-0/+1
| | | | Signed-off-by: Ben Pfaff <blp@nicira.com>