LCOV - code coverage report
Current view: top level - ofproto - ofproto-provider.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 10 10 100.0 %
Date: 2016-09-14 01:02:56 Functions: 19 19 100.0 %
Branches: 9 10 90.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :            :  * you may not use this file except in compliance with the License.
       6                 :            :  * You may obtain a copy of the License at:
       7                 :            :  *
       8                 :            :  *     http://www.apache.org/licenses/LICENSE-2.0
       9                 :            :  *
      10                 :            :  * Unless required by applicable law or agreed to in writing, software
      11                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :            :  * See the License for the specific language governing permissions and
      14                 :            :  * limitations under the License.
      15                 :            :  */
      16                 :            : 
      17                 :            : #ifndef OFPROTO_OFPROTO_PROVIDER_H
      18                 :            : #define OFPROTO_OFPROTO_PROVIDER_H 1
      19                 :            : 
      20                 :            : /* Definitions for use within ofproto.
      21                 :            :  *
      22                 :            :  *
      23                 :            :  * Thread-safety
      24                 :            :  * =============
      25                 :            :  *
      26                 :            :  * Lots of ofproto data structures are only accessed from a single thread.
      27                 :            :  * Those data structures are generally not thread-safe.
      28                 :            :  *
      29                 :            :  * The ofproto-dpif ofproto implementation accesses the flow table from
      30                 :            :  * multiple threads, including modifying the flow table from multiple threads
      31                 :            :  * via the "learn" action, so the flow table and various structures that index
      32                 :            :  * it have been made thread-safe.  Refer to comments on individual data
      33                 :            :  * structures for details.
      34                 :            :  */
      35                 :            : 
      36                 :            : #include "cfm.h"
      37                 :            : #include "classifier.h"
      38                 :            : #include "guarded-list.h"
      39                 :            : #include "heap.h"
      40                 :            : #include "hindex.h"
      41                 :            : #include "object-collection.h"
      42                 :            : #include "ofproto/ofproto.h"
      43                 :            : #include "openvswitch/list.h"
      44                 :            : #include "openvswitch/ofp-actions.h"
      45                 :            : #include "openvswitch/ofp-util.h"
      46                 :            : #include "openvswitch/ofp-errors.h"
      47                 :            : #include "ovs-atomic.h"
      48                 :            : #include "ovs-rcu.h"
      49                 :            : #include "ovs-thread.h"
      50                 :            : #include "openvswitch/shash.h"
      51                 :            : #include "simap.h"
      52                 :            : #include "timeval.h"
      53                 :            : #include "versions.h"
      54                 :            : 
      55                 :            : struct match;
      56                 :            : struct ofputil_flow_mod;
      57                 :            : struct bfd_cfg;
      58                 :            : struct meter;
      59                 :            : struct ofoperation;
      60                 :            : 
      61                 :            : extern struct ovs_mutex ofproto_mutex;
      62                 :            : 
      63                 :            : /* An OpenFlow switch.
      64                 :            :  *
      65                 :            :  * With few exceptions, ofproto implementations may look at these fields but
      66                 :            :  * should not modify them. */
      67                 :            : struct ofproto {
      68                 :            :     struct hmap_node hmap_node; /* In global 'all_ofprotos' hmap. */
      69                 :            :     const struct ofproto_class *ofproto_class;
      70                 :            :     char *type;                 /* Datapath type. */
      71                 :            :     char *name;                 /* Datapath name. */
      72                 :            : 
      73                 :            :     /* Settings. */
      74                 :            :     uint64_t fallback_dpid;     /* Datapath ID if no better choice found. */
      75                 :            :     uint64_t datapath_id;       /* Datapath ID. */
      76                 :            :     bool forward_bpdu;          /* Option to allow forwarding of BPDU frames
      77                 :            :                                  * when NORMAL action is invoked. */
      78                 :            :     char *mfr_desc;             /* Manufacturer (NULL for default). */
      79                 :            :     char *hw_desc;              /* Hardware (NULL for default). */
      80                 :            :     char *sw_desc;              /* Software version (NULL for default). */
      81                 :            :     char *serial_desc;          /* Serial number (NULL for default). */
      82                 :            :     char *dp_desc;              /* Datapath description (NULL for default). */
      83                 :            :     enum ofputil_frag_handling frag_handling;
      84                 :            : 
      85                 :            :     /* Datapath. */
      86                 :            :     struct hmap ports;          /* Contains "struct ofport"s. */
      87                 :            :     struct shash port_by_name;
      88                 :            :     struct simap ofp_requests;  /* OpenFlow port number requests. */
      89                 :            :     uint16_t alloc_port_no;     /* Last allocated OpenFlow port number. */
      90                 :            :     uint16_t max_ports;         /* Max possible OpenFlow port num, plus one. */
      91                 :            :     struct hmap ofport_usage;   /* Map ofport to last used time. */
      92                 :            :     uint64_t change_seq;        /* Change sequence for netdev status. */
      93                 :            : 
      94                 :            :     /* Flow tables. */
      95                 :            :     long long int eviction_group_timer; /* For rate limited reheapification. */
      96                 :            :     struct oftable *tables;
      97                 :            :     int n_tables;
      98                 :            :     ovs_version_t tables_version;  /* Controls which rules are visible to
      99                 :            :                                     * table lookups. */
     100                 :            : 
     101                 :            :     /* Rules indexed on their cookie values, in all flow tables. */
     102                 :            :     struct hindex cookies OVS_GUARDED_BY(ofproto_mutex);
     103                 :            :     struct hmap learned_cookies OVS_GUARDED_BY(ofproto_mutex);
     104                 :            : 
     105                 :            :     /* List of expirable flows, in all flow tables. */
     106                 :            :     struct ovs_list expirable OVS_GUARDED_BY(ofproto_mutex);
     107                 :            : 
     108                 :            :     /* Meter table.
     109                 :            :      * OpenFlow meters start at 1.  To avoid confusion we leave the first
     110                 :            :      * pointer in the array un-used, and index directly with the OpenFlow
     111                 :            :      * meter_id. */
     112                 :            :     struct ofputil_meter_features meter_features;
     113                 :            :     struct meter **meters; /* 'meter_features.max_meter' + 1 pointers. */
     114                 :            : 
     115                 :            :     /* OpenFlow connections. */
     116                 :            :     struct connmgr *connmgr;
     117                 :            : 
     118                 :            :     int min_mtu;                    /* Current MTU of non-internal ports. */
     119                 :            : 
     120                 :            :     /* Groups. */
     121                 :            :     struct cmap groups;               /* Contains "struct ofgroup"s. */
     122                 :            :     uint32_t n_groups[4] OVS_GUARDED; /* # of existing groups of each type. */
     123                 :            :     struct ofputil_group_features ogf;
     124                 :            : };
     125                 :            : 
     126                 :            : void ofproto_init_tables(struct ofproto *, int n_tables);
     127                 :            : void ofproto_init_max_ports(struct ofproto *, uint16_t max_ports);
     128                 :            : 
     129                 :            : struct ofproto *ofproto_lookup(const char *name);
     130                 :            : struct ofport *ofproto_get_port(const struct ofproto *, ofp_port_t ofp_port);
     131                 :            : 
     132                 :            : /* An OpenFlow port within a "struct ofproto".
     133                 :            :  *
     134                 :            :  * The port's name is netdev_get_name(port->netdev).
     135                 :            :  *
     136                 :            :  * With few exceptions, ofproto implementations may look at these fields but
     137                 :            :  * should not modify them. */
     138                 :            : struct ofport {
     139                 :            :     struct hmap_node hmap_node; /* In struct ofproto's "ports" hmap. */
     140                 :            :     struct ofproto *ofproto;    /* The ofproto that contains this port. */
     141                 :            :     struct netdev *netdev;
     142                 :            :     struct ofputil_phy_port pp;
     143                 :            :     ofp_port_t ofp_port;        /* OpenFlow port number. */
     144                 :            :     uint64_t change_seq;
     145                 :            :     long long int created;      /* Time created, in msec. */
     146                 :            :     int mtu;
     147                 :            : };
     148                 :            : 
     149                 :            : void ofproto_port_set_state(struct ofport *, enum ofputil_port_state);
     150                 :            : 
     151                 :            : /* OpenFlow table flags:
     152                 :            :  *
     153                 :            :  *   - "Hidden" tables are not included in OpenFlow operations that operate on
     154                 :            :  *     "all tables".  For example, a request for flow stats on all tables will
     155                 :            :  *     omit flows in hidden tables, table stats requests will omit the table
     156                 :            :  *     entirely, and the switch features reply will not count the hidden table.
     157                 :            :  *
     158                 :            :  *     However, operations that specifically name the particular table still
     159                 :            :  *     operate on it.  For example, flow_mods and flow stats requests on a
     160                 :            :  *     hidden table work.
     161                 :            :  *
     162                 :            :  *     To avoid gaps in table IDs (which have unclear validity in OpenFlow),
     163                 :            :  *     hidden tables must be the highest-numbered tables that a provider
     164                 :            :  *     implements.
     165                 :            :  *
     166                 :            :  *   - "Read-only" tables can't be changed through OpenFlow operations.  (At
     167                 :            :  *     the moment all flow table operations go effectively through OpenFlow, so
     168                 :            :  *     this means that read-only tables can't be changed at all after the
     169                 :            :  *     read-only flag is set.)
     170                 :            :  *
     171                 :            :  * The generic ofproto layer never sets these flags.  An ofproto provider can
     172                 :            :  * set them if it is appropriate.
     173                 :            :  */
     174                 :            : enum oftable_flags {
     175                 :            :     OFTABLE_HIDDEN = 1 << 0,   /* Hide from most OpenFlow operations. */
     176                 :            :     OFTABLE_READONLY = 1 << 1  /* Don't allow OpenFlow controller to change
     177                 :            :                                   this table. */
     178                 :            : };
     179                 :            : 
     180                 :            : /* A flow table within a "struct ofproto".
     181                 :            :  *
     182                 :            :  *
     183                 :            :  * Thread-safety
     184                 :            :  * =============
     185                 :            :  *
     186                 :            :  * Adding or removing rules requires holding ofproto_mutex.
     187                 :            :  *
     188                 :            :  * Rules in 'cls' are RCU protected.  For extended access to a rule, try
     189                 :            :  * incrementing its ref_count with ofproto_rule_try_ref(), or
     190                 :            :  * ofproto_rule_ref(), if the rule is still known to be in 'cls'.  A rule
     191                 :            :  * will be freed using ovsrcu_postpone() once its 'ref_count' reaches zero.
     192                 :            :  *
     193                 :            :  * Modifying a rule requires the rule's own mutex.
     194                 :            :  *
     195                 :            :  * Freeing a rule requires ofproto_mutex.  After removing the rule from the
     196                 :            :  * classifier, release a ref_count from the rule ('cls''s reference to the
     197                 :            :  * rule).
     198                 :            :  *
     199                 :            :  * Refer to the thread-safety notes on struct rule for more information.*/
     200                 :            : struct oftable {
     201                 :            :     enum oftable_flags flags;
     202                 :            :     struct classifier cls;      /* Contains "struct rule"s. */
     203                 :            :     char *name;                 /* Table name exposed via OpenFlow, or NULL. */
     204                 :            : 
     205                 :            :     /* Maximum number of flows or UINT_MAX if there is no limit besides any
     206                 :            :      * limit imposed by resource limitations. */
     207                 :            :     unsigned int max_flows;
     208                 :            :     /* Current number of flows, not counting temporary duplicates nor deferred
     209                 :            :      * deletions. */
     210                 :            :     unsigned int n_flows;
     211                 :            : 
     212                 :            :     /* These members determine the handling of an attempt to add a flow that
     213                 :            :      * would cause the table to have more than 'max_flows' flows.
     214                 :            :      *
     215                 :            :      * If 'eviction_fields' is NULL, overflows will be rejected with an error.
     216                 :            :      *
     217                 :            :      * If 'eviction_fields' is nonnull (regardless of whether n_eviction_fields
     218                 :            :      * is nonzero), an overflow will cause a flow to be removed.  The flow to
     219                 :            :      * be removed is chosen to give fairness among groups distinguished by
     220                 :            :      * different values for the subfields within 'groups'. */
     221                 :            :     struct mf_subfield *eviction_fields;
     222                 :            :     size_t n_eviction_fields;
     223                 :            : 
     224                 :            :     /* Eviction groups.
     225                 :            :      *
     226                 :            :      * When a flow is added that would cause the table to have more than
     227                 :            :      * 'max_flows' flows, and 'eviction_fields' is nonnull, these groups are
     228                 :            :      * used to decide which rule to evict: the rule is chosen from the eviction
     229                 :            :      * group that contains the greatest number of rules.*/
     230                 :            :     uint32_t eviction_group_id_basis;
     231                 :            :     struct hmap eviction_groups_by_id;
     232                 :            :     struct heap eviction_groups_by_size;
     233                 :            : 
     234                 :            :     /* Flow table miss handling configuration. */
     235                 :            :     ATOMIC(enum ofputil_table_miss) miss_config;
     236                 :            : 
     237                 :            :     /* Eviction is enabled if either the client (vswitchd) enables it or an
     238                 :            :      * OpenFlow controller enables it; thus, a nonzero value indicates that
     239                 :            :      * eviction is enabled.  */
     240                 :            : #define EVICTION_CLIENT  (1 << 0)  /* Set to 1 if client enables eviction. */
     241                 :            : #define EVICTION_OPENFLOW (1 << 1) /* Set to 1 if OpenFlow enables eviction. */
     242                 :            :     unsigned int eviction;
     243                 :            : 
     244                 :            :     /* If zero, vacancy events are disabled.  If nonzero, this is the type of
     245                 :            :        vacancy event that is enabled: either OFPTR_VACANCY_DOWN or
     246                 :            :        OFPTR_VACANCY_UP.  Only one type of vacancy event can be enabled at a
     247                 :            :        time. */
     248                 :            :     enum ofp14_table_reason vacancy_event;
     249                 :            : 
     250                 :            :     /* Non-zero values for vacancy_up and vacancy_down indicates that vacancy
     251                 :            :      * is enabled by table-mod, else these values are set to zero when
     252                 :            :      * vacancy is disabled */
     253                 :            :     uint8_t vacancy_down; /* Vacancy threshold when space decreases (%). */
     254                 :            :     uint8_t vacancy_up;   /* Vacancy threshold when space increases (%). */
     255                 :            : 
     256                 :            :     atomic_ulong n_matched;
     257                 :            :     atomic_ulong n_missed;
     258                 :            : };
     259                 :            : 
     260                 :            : /* Assigns TABLE to each oftable, in turn, in OFPROTO.
     261                 :            :  *
     262                 :            :  * All parameters are evaluated multiple times. */
     263                 :            : #define OFPROTO_FOR_EACH_TABLE(TABLE, OFPROTO)              \
     264                 :            :     for ((TABLE) = (OFPROTO)->tables;                       \
     265                 :            :          (TABLE) < &(OFPROTO)->tables[(OFPROTO)->n_tables]; \
     266                 :            :          (TABLE)++)
     267                 :            : 
     268                 :            : /* An OpenFlow flow within a "struct ofproto".
     269                 :            :  *
     270                 :            :  * With few exceptions, ofproto implementations may look at these fields but
     271                 :            :  * should not modify them.
     272                 :            :  *
     273                 :            :  *
     274                 :            :  * Thread-safety
     275                 :            :  * =============
     276                 :            :  *
     277                 :            :  * Except near the beginning or ending of its lifespan, rule 'rule' belongs to
     278                 :            :  * the classifier rule->ofproto->tables[rule->table_id].cls.  The text below
     279                 :            :  * calls this classifier 'cls'.
     280                 :            :  *
     281                 :            :  * Motivation
     282                 :            :  * ----------
     283                 :            :  *
     284                 :            :  * The thread safety rules described here for "struct rule" are motivated by
     285                 :            :  * two goals:
     286                 :            :  *
     287                 :            :  *    - Prevent threads that read members of "struct rule" from reading bad
     288                 :            :  *      data due to changes by some thread concurrently modifying those
     289                 :            :  *      members.
     290                 :            :  *
     291                 :            :  *    - Prevent two threads making changes to members of a given "struct rule"
     292                 :            :  *      from interfering with each other.
     293                 :            :  *
     294                 :            :  *
     295                 :            :  * Rules
     296                 :            :  * -----
     297                 :            :  *
     298                 :            :  * A rule 'rule' may be accessed without a risk of being freed by a thread
     299                 :            :  * until the thread quiesces (i.e., rules are RCU protected and destructed
     300                 :            :  * using ovsrcu_postpone()).  Code that needs to hold onto a rule for a
     301                 :            :  * while should increment 'rule->ref_count' either with ofproto_rule_ref()
     302                 :            :  * (if 'ofproto_mutex' is held), or with ofproto_rule_try_ref() (when some
     303                 :            :  * other thread might remove the rule from 'cls').  ofproto_rule_try_ref()
     304                 :            :  * will fail if the rule has already been scheduled for destruction.
     305                 :            :  *
     306                 :            :  * 'rule->ref_count' protects 'rule' from being freed.  It doesn't protect the
     307                 :            :  * rule from being deleted from 'cls' (that's 'ofproto_mutex') and it doesn't
     308                 :            :  * protect members of 'rule' from modification (that's 'rule->mutex').
     309                 :            :  *
     310                 :            :  * 'rule->mutex' protects the members of 'rule' from modification.  It doesn't
     311                 :            :  * protect the rule from being deleted from 'cls' (that's 'ofproto_mutex') and
     312                 :            :  * it doesn't prevent the rule from being freed (that's 'rule->ref_count').
     313                 :            :  *
     314                 :            :  * Regarding thread safety, the members of a rule fall into the following
     315                 :            :  * categories:
     316                 :            :  *
     317                 :            :  *    - Immutable.  These members are marked 'const'.
     318                 :            :  *
     319                 :            :  *    - Members that may be safely read or written only by code holding
     320                 :            :  *      ofproto_mutex.  These are marked OVS_GUARDED_BY(ofproto_mutex).
     321                 :            :  *
     322                 :            :  *    - Members that may be safely read only by code holding ofproto_mutex or
     323                 :            :  *      'rule->mutex', and safely written only by coding holding ofproto_mutex
     324                 :            :  *      AND 'rule->mutex'.  These are marked OVS_GUARDED.
     325                 :            :  */
     326                 :            : struct rule {
     327                 :            :     /* Where this rule resides in an OpenFlow switch.
     328                 :            :      *
     329                 :            :      * These are immutable once the rule is constructed, hence 'const'. */
     330                 :            :     struct ofproto *const ofproto; /* The ofproto that contains this rule. */
     331                 :            :     const struct cls_rule cr;      /* In owning ofproto's classifier. */
     332                 :            :     const uint8_t table_id;        /* Index in ofproto's 'tables' array. */
     333                 :            :     bool removed;                  /* Rule has been removed from the ofproto
     334                 :            :                                     * data structures. */
     335                 :            : 
     336                 :            :     /* Protects members marked OVS_GUARDED.
     337                 :            :      * Readers only need to hold this mutex.
     338                 :            :      * Writers must hold both this mutex AND ofproto_mutex.
     339                 :            :      * By implication writers can read *without* taking this mutex while they
     340                 :            :      * hold ofproto_mutex. */
     341                 :            :     struct ovs_mutex mutex OVS_ACQ_AFTER(ofproto_mutex);
     342                 :            : 
     343                 :            :     /* Number of references.
     344                 :            :      * The classifier owns one reference.
     345                 :            :      * Any thread trying to keep a rule from being freed should hold its own
     346                 :            :      * reference. */
     347                 :            :     struct ovs_refcount ref_count;
     348                 :            : 
     349                 :            :     /* A "flow cookie" is the OpenFlow name for a 64-bit value associated with
     350                 :            :      * a flow.. */
     351                 :            :     ovs_be64 flow_cookie OVS_GUARDED;
     352                 :            :     struct hindex_node cookie_node OVS_GUARDED_BY(ofproto_mutex);
     353                 :            : 
     354                 :            :     enum ofputil_flow_mod_flags flags OVS_GUARDED;
     355                 :            : 
     356                 :            :     /* Timeouts. */
     357                 :            :     uint16_t hard_timeout OVS_GUARDED; /* In seconds from ->modified. */
     358                 :            :     uint16_t idle_timeout OVS_GUARDED; /* In seconds from ->used. */
     359                 :            : 
     360                 :            :     /* Eviction precedence. */
     361                 :            :     const uint16_t importance;
     362                 :            : 
     363                 :            :     /* Removal reason for sending flow removed message.
     364                 :            :      * Used only if 'flags' has OFPUTIL_FF_SEND_FLOW_REM set and if the
     365                 :            :      * value is not OVS_OFPRR_NONE. */
     366                 :            :     uint8_t removed_reason;
     367                 :            : 
     368                 :            :     /* Eviction groups (see comment on struct eviction_group for explanation) .
     369                 :            :      *
     370                 :            :      * 'eviction_group' is this rule's eviction group, or NULL if it is not in
     371                 :            :      * any eviction group.  When 'eviction_group' is nonnull, 'evg_node' is in
     372                 :            :      * the ->eviction_group->rules hmap. */
     373                 :            :     struct eviction_group *eviction_group OVS_GUARDED_BY(ofproto_mutex);
     374                 :            :     struct heap_node evg_node OVS_GUARDED_BY(ofproto_mutex);
     375                 :            : 
     376                 :            :     /* OpenFlow actions.  See struct rule_actions for more thread-safety
     377                 :            :      * notes. */
     378                 :            :     const struct rule_actions * const actions;
     379                 :            : 
     380                 :            :     /* In owning meter's 'rules' list.  An empty list if there is no meter. */
     381                 :            :     struct ovs_list meter_list_node OVS_GUARDED_BY(ofproto_mutex);
     382                 :            : 
     383                 :            :     /* Flow monitors (e.g. for NXST_FLOW_MONITOR, related to struct ofmonitor).
     384                 :            :      *
     385                 :            :      * 'add_seqno' is the sequence number when this rule was created.
     386                 :            :      * 'modify_seqno' is the sequence number when this rule was last modified.
     387                 :            :      * See 'monitor_seqno' in connmgr.c for more information. */
     388                 :            :     enum nx_flow_monitor_flags monitor_flags OVS_GUARDED_BY(ofproto_mutex);
     389                 :            :     uint64_t add_seqno OVS_GUARDED_BY(ofproto_mutex);
     390                 :            :     uint64_t modify_seqno OVS_GUARDED_BY(ofproto_mutex);
     391                 :            : 
     392                 :            :     /* Optimisation for flow expiry.  In ofproto's 'expirable' list if this
     393                 :            :      * rule is expirable, otherwise empty. */
     394                 :            :     struct ovs_list expirable OVS_GUARDED_BY(ofproto_mutex);
     395                 :            : 
     396                 :            :     /* Times.  Last so that they are more likely close to the stats managed
     397                 :            :      * by the provider. */
     398                 :            :     long long int created OVS_GUARDED; /* Creation time. */
     399                 :            : 
     400                 :            :     /* Must hold 'mutex' for both read/write, 'ofproto_mutex' not needed. */
     401                 :            :     long long int modified OVS_GUARDED; /* Time of last modification. */
     402                 :            : };
     403                 :            : 
     404                 :            : void ofproto_rule_ref(struct rule *);
     405                 :            : bool ofproto_rule_try_ref(struct rule *);
     406                 :            : void ofproto_rule_unref(struct rule *);
     407                 :            : 
     408                 :            : static inline const struct rule_actions * rule_get_actions(const struct rule *);
     409                 :            : static inline bool rule_is_table_miss(const struct rule *);
     410                 :            : static inline bool rule_is_hidden(const struct rule *);
     411                 :            : 
     412                 :            : /* A set of actions within a "struct rule".
     413                 :            :  *
     414                 :            :  *
     415                 :            :  * Thread-safety
     416                 :            :  * =============
     417                 :            :  *
     418                 :            :  * A struct rule_actions may be accessed without a risk of being freed by
     419                 :            :  * code that holds 'rule->mutex' (where 'rule' is the rule for which
     420                 :            :  * 'rule->actions == actions') or during the RCU active period.
     421                 :            :  *
     422                 :            :  * All members are immutable: they do not change during the rule's
     423                 :            :  * lifetime. */
     424                 :            : struct rule_actions {
     425                 :            :     /* Flags.
     426                 :            :      *
     427                 :            :      * 'has_meter' is true if 'ofpacts' contains an OFPACT_METER action.
     428                 :            :      *
     429                 :            :      * 'has_learn_with_delete' is true if 'ofpacts' contains an OFPACT_LEARN
     430                 :            :      * action whose flags include NX_LEARN_F_DELETE_LEARNED. */
     431                 :            :     bool has_meter;
     432                 :            :     bool has_learn_with_delete;
     433                 :            :     bool has_groups;
     434                 :            : 
     435                 :            :     /* Actions. */
     436                 :            :     uint32_t ofpacts_len;         /* Size of 'ofpacts', in bytes. */
     437                 :            :     struct ofpact ofpacts[];      /* Sequence of "struct ofpacts". */
     438                 :            : };
     439                 :            : BUILD_ASSERT_DECL(offsetof(struct rule_actions, ofpacts) % OFPACT_ALIGNTO == 0);
     440                 :            : 
     441                 :            : const struct rule_actions *rule_actions_create(const struct ofpact *, size_t);
     442                 :            : void rule_actions_destroy(const struct rule_actions *);
     443                 :            : bool ofproto_rule_has_out_port(const struct rule *, ofp_port_t port)
     444                 :            :     OVS_REQUIRES(ofproto_mutex);
     445                 :            : 
     446                 :            : #define DECL_OFPROTO_COLLECTION(TYPE, NAME)                             \
     447                 :            :     DECL_OBJECT_COLLECTION(TYPE, NAME)                                  \
     448                 :            : static inline void NAME##_collection_ref(struct NAME##_collection *coll)   \
     449                 :            : {                                                                       \
     450                 :            :     for (size_t i = 0; i < coll->collection.n; i++) {                   \
     451                 :            :         ofproto_##NAME##_ref((TYPE)coll->collection.objs[i]);           \
     452                 :            :     }                                                                   \
     453                 :            : }                                                                       \
     454                 :            :                                                                         \
     455                 :            : static inline void NAME##_collection_unref(struct NAME##_collection *coll) \
     456                 :            : {                                                                       \
     457                 :            :     for (size_t i = 0; i < coll->collection.n; i++) {                   \
     458                 :            :         ofproto_##NAME##_unref((TYPE)coll->collection.objs[i]);         \
     459                 :            :     }                                                                   \
     460                 :            : }
     461                 :            : 
     462 [ +  + ][ +  + ]:    6763334 : DECL_OFPROTO_COLLECTION (struct rule *, rule)
     463                 :            : 
     464                 :            : #define RULE_COLLECTION_FOR_EACH(RULE, RULES)                           \
     465                 :            :     for (size_t i__ = 0;                                                \
     466                 :            :          i__ < rule_collection_n(RULES)                                 \
     467                 :            :              ? (RULE = rule_collection_rules(RULES)[i__]) != NULL : false; \
     468                 :            :          i__++)
     469                 :            : 
     470                 :            : /* Pairwise iteration through two rule collections that must be of the same
     471                 :            :  * size. */
     472                 :            : #define RULE_COLLECTIONS_FOR_EACH(RULE1, RULE2, RULES1, RULES2)        \
     473                 :            :     for (size_t i__ = 0;                                               \
     474                 :            :          i__ < rule_collection_n(RULES1)                               \
     475                 :            :              ? ((RULE1 = rule_collection_rules(RULES1)[i__]),          \
     476                 :            :                 (RULE2 = rule_collection_rules(RULES2)[i__]) != NULL)  \
     477                 :            :              : false;                                                  \
     478                 :            :          i__++)
     479                 :            : 
     480                 :            : /* Limits the number of flows allowed in the datapath. Only affects the
     481                 :            :  * ofproto-dpif implementation. */
     482                 :            : extern unsigned ofproto_flow_limit;
     483                 :            : 
     484                 :            : /* Maximum idle time (in ms) for flows to be cached in the datapath.
     485                 :            :  * Revalidators may expire flows more quickly than the configured value based
     486                 :            :  * on system load and other factors. This variable is subject to change. */
     487                 :            : extern unsigned ofproto_max_idle;
     488                 :            : 
     489                 :            : /* Number of upcall handler and revalidator threads. Only affects the
     490                 :            :  * ofproto-dpif implementation. */
     491                 :            : extern size_t n_handlers, n_revalidators;
     492                 :            : 
     493                 :            : /* Cpu mask for pmd threads. */
     494                 :            : extern char *pmd_cpu_mask;
     495                 :            : 
     496                 :            : static inline struct rule *rule_from_cls_rule(const struct cls_rule *);
     497                 :            : 
     498                 :            : void ofproto_rule_expire(struct rule *rule, uint8_t reason)
     499                 :            :     OVS_REQUIRES(ofproto_mutex);
     500                 :            : void ofproto_rule_delete(struct ofproto *, struct rule *)
     501                 :            :     OVS_EXCLUDED(ofproto_mutex);
     502                 :            : void ofproto_rule_reduce_timeouts(struct rule *rule, uint16_t idle_timeout,
     503                 :            :                                   uint16_t hard_timeout)
     504                 :            :     OVS_EXCLUDED(ofproto_mutex);
     505                 :            : 
     506                 :            : /* A group within a "struct ofproto", RCU-protected.
     507                 :            :  *
     508                 :            :  * With few exceptions, ofproto implementations may look at these fields but
     509                 :            :  * should not modify them. */
     510                 :            : struct ofgroup {
     511                 :            :     struct cmap_node cmap_node; /* In ofproto's "groups" cmap. */
     512                 :            : 
     513                 :            :     /* Group versioning. */
     514                 :            :     struct versions versions;
     515                 :            : 
     516                 :            :     /* Number of references.
     517                 :            :      *
     518                 :            :      * This is needed to keep track of references to the group in the xlate
     519                 :            :      * module.
     520                 :            :      *
     521                 :            :      * If the main thread removes the group from an ofproto, we need to
     522                 :            :      * guarantee that the group remains accessible to users of
     523                 :            :      * xlate_group_actions and the xlate_cache, as the xlate_cache will not be
     524                 :            :      * cleaned up until the corresponding datapath flows are revalidated. */
     525                 :            :     struct ovs_refcount ref_count;
     526                 :            : 
     527                 :            :     /* No lock is needed to protect the fields below since they are not
     528                 :            :      * modified after construction. */
     529                 :            :     struct ofproto * const ofproto;  /* The ofproto that contains this group. */
     530                 :            :     const uint32_t group_id;
     531                 :            :     const enum ofp11_group_type type; /* One of OFPGT_*. */
     532                 :            :     bool being_deleted;               /* Group removal has begun. */
     533                 :            : 
     534                 :            :     const long long int created;      /* Creation time. */
     535                 :            :     const long long int modified;     /* Time of last modification. */
     536                 :            : 
     537                 :            :     const struct ovs_list buckets;    /* Contains "struct ofputil_bucket"s. */
     538                 :            :     const uint32_t n_buckets;
     539                 :            : 
     540                 :            :     const struct ofputil_group_props props;
     541                 :            : 
     542                 :            :     struct rule_collection rules OVS_GUARDED;   /* Referring rules. */
     543                 :            : };
     544                 :            : 
     545                 :            : struct ofgroup *ofproto_group_lookup(const struct ofproto *ofproto,
     546                 :            :                                      uint32_t group_id, ovs_version_t version,
     547                 :            :                                      bool take_ref);
     548                 :            : 
     549                 :            : void ofproto_group_ref(struct ofgroup *);
     550                 :            : bool ofproto_group_try_ref(struct ofgroup *);
     551                 :            : void ofproto_group_unref(struct ofgroup *);
     552                 :            : 
     553                 :            : void ofproto_group_delete_all(struct ofproto *)
     554                 :            :     OVS_EXCLUDED(ofproto_mutex);
     555                 :            : 
     556                 :       6900 : DECL_OFPROTO_COLLECTION (struct ofgroup *, group)
     557                 :            : 
     558                 :            : #define GROUP_COLLECTION_FOR_EACH(GROUP, GROUPS)                        \
     559                 :            :     for (size_t i__ = 0;                                                \
     560                 :            :          i__ < group_collection_n(GROUPS)                               \
     561                 :            :              ? (GROUP = group_collection_groups(GROUPS)[i__]) != NULL: false; \
     562                 :            :          i__++)
     563                 :            : 
     564                 :            : /* Pairwise iteration through two group collections that must be of the same
     565                 :            :  * size. */
     566                 :            : #define GROUP_COLLECTIONS_FOR_EACH(GROUP1, GROUP2, GROUPS1, GROUPS2)    \
     567                 :            :     for (size_t i__ = 0;                                                \
     568                 :            :          i__ < group_collection_n(GROUPS1)                              \
     569                 :            :              ? ((GROUP1 = group_collection_groups(GROUPS1)[i__]),       \
     570                 :            :                 (GROUP2 = group_collection_groups(GROUPS2)[i__]) != NULL) \
     571                 :            :              : false;                                                   \
     572                 :            :          i__++)
     573                 :            : 
     574                 :            : /* ofproto class structure, to be defined by each ofproto implementation.
     575                 :            :  *
     576                 :            :  *
     577                 :            :  * Data Structures
     578                 :            :  * ===============
     579                 :            :  *
     580                 :            :  * These functions work primarily with four different kinds of data
     581                 :            :  * structures:
     582                 :            :  *
     583                 :            :  *   - "struct ofproto", which represents an OpenFlow switch.
     584                 :            :  *
     585                 :            :  *   - "struct ofport", which represents a port within an ofproto.
     586                 :            :  *
     587                 :            :  *   - "struct rule", which represents an OpenFlow flow within an ofproto.
     588                 :            :  *
     589                 :            :  *   - "struct ofgroup", which represents an OpenFlow 1.1+ group within an
     590                 :            :  *     ofproto.
     591                 :            :  *
     592                 :            :  * Each of these data structures contains all of the implementation-independent
     593                 :            :  * generic state for the respective concept, called the "base" state.  None of
     594                 :            :  * them contains any extra space for ofproto implementations to use.  Instead,
     595                 :            :  * each implementation is expected to declare its own data structure that
     596                 :            :  * contains an instance of the generic data structure plus additional
     597                 :            :  * implementation-specific members, called the "derived" state.  The
     598                 :            :  * implementation can use casts or (preferably) the CONTAINER_OF macro to
     599                 :            :  * obtain access to derived state given only a pointer to the embedded generic
     600                 :            :  * data structure.
     601                 :            :  *
     602                 :            :  *
     603                 :            :  * Life Cycle
     604                 :            :  * ==========
     605                 :            :  *
     606                 :            :  * Four stylized functions accompany each of these data structures:
     607                 :            :  *
     608                 :            :  *            "alloc"       "construct"       "destruct"       "dealloc"
     609                 :            :  *            ------------  ----------------  ---------------  --------------
     610                 :            :  *   ofproto  ->alloc       ->construct       ->destruct       ->dealloc
     611                 :            :  *   ofport   ->port_alloc  ->port_construct  ->port_destruct  ->port_dealloc
     612                 :            :  *   rule     ->rule_alloc  ->rule_construct  ->rule_destruct  ->rule_dealloc
     613                 :            :  *   group    ->group_alloc ->group_construct ->group_destruct ->group_dealloc
     614                 :            :  *
     615                 :            :  * "ofproto", "ofport", and "group" have this exact life cycle.  The "rule"
     616                 :            :  * data structure also follow this life cycle with some additional elaborations
     617                 :            :  * described under "Rule Life Cycle" below.
     618                 :            :  *
     619                 :            :  * Any instance of a given data structure goes through the following life
     620                 :            :  * cycle:
     621                 :            :  *
     622                 :            :  *   1. The client calls the "alloc" function to obtain raw memory.  If "alloc"
     623                 :            :  *      fails, skip all the other steps.
     624                 :            :  *
     625                 :            :  *   2. The client initializes all of the data structure's base state.  If this
     626                 :            :  *      fails, skip to step 7.
     627                 :            :  *
     628                 :            :  *   3. The client calls the "construct" function.  The implementation
     629                 :            :  *      initializes derived state.  It may refer to the already-initialized
     630                 :            :  *      base state.  If "construct" fails, skip to step 6.
     631                 :            :  *
     632                 :            :  *   4. The data structure is now initialized and in use.
     633                 :            :  *
     634                 :            :  *   5. When the data structure is no longer needed, the client calls the
     635                 :            :  *      "destruct" function.  The implementation uninitializes derived state.
     636                 :            :  *      The base state has not been uninitialized yet, so the implementation
     637                 :            :  *      may still refer to it.
     638                 :            :  *
     639                 :            :  *   6. The client uninitializes all of the data structure's base state.
     640                 :            :  *
     641                 :            :  *   7. The client calls the "dealloc" to free the raw memory.  The
     642                 :            :  *      implementation must not refer to base or derived state in the data
     643                 :            :  *      structure, because it has already been uninitialized.
     644                 :            :  *
     645                 :            :  * Each "alloc" function allocates and returns a new instance of the respective
     646                 :            :  * data structure.  The "alloc" function is not given any information about the
     647                 :            :  * use of the new data structure, so it cannot perform much initialization.
     648                 :            :  * Its purpose is just to ensure that the new data structure has enough room
     649                 :            :  * for base and derived state.  It may return a null pointer if memory is not
     650                 :            :  * available, in which case none of the other functions is called.
     651                 :            :  *
     652                 :            :  * Each "construct" function initializes derived state in its respective data
     653                 :            :  * structure.  When "construct" is called, all of the base state has already
     654                 :            :  * been initialized, so the "construct" function may refer to it.  The
     655                 :            :  * "construct" function is allowed to fail, in which case the client calls the
     656                 :            :  * "dealloc" function (but not the "destruct" function).
     657                 :            :  *
     658                 :            :  * Each "destruct" function uninitializes and frees derived state in its
     659                 :            :  * respective data structure.  When "destruct" is called, the base state has
     660                 :            :  * not yet been uninitialized, so the "destruct" function may refer to it.  The
     661                 :            :  * "destruct" function is not allowed to fail.
     662                 :            :  *
     663                 :            :  * Each "dealloc" function frees raw memory that was allocated by the
     664                 :            :  * "alloc" function.  The memory's base and derived members might not have ever
     665                 :            :  * been initialized (but if "construct" returned successfully, then it has been
     666                 :            :  * "destruct"ed already).  The "dealloc" function is not allowed to fail.
     667                 :            :  *
     668                 :            :  *
     669                 :            :  * Conventions
     670                 :            :  * ===========
     671                 :            :  *
     672                 :            :  * Most of these functions return 0 if they are successful or a positive error
     673                 :            :  * code on failure.  Depending on the function, valid error codes are either
     674                 :            :  * errno values or OFPERR_* OpenFlow error codes.
     675                 :            :  *
     676                 :            :  * Most of these functions are expected to execute synchronously, that is, to
     677                 :            :  * block as necessary to obtain a result.  Thus, these functions may return
     678                 :            :  * EAGAIN (or EWOULDBLOCK or EINPROGRESS) only where the function descriptions
     679                 :            :  * explicitly say those errors are a possibility.  We may relax this
     680                 :            :  * requirement in the future if and when we encounter performance problems. */
     681                 :            : struct ofproto_class {
     682                 :            : /* ## ----------------- ## */
     683                 :            : /* ## Factory Functions ## */
     684                 :            : /* ## ----------------- ## */
     685                 :            : 
     686                 :            :     /* Initializes provider.  The caller may pass in 'iface_hints',
     687                 :            :      * which contains an shash of "struct iface_hint" elements indexed
     688                 :            :      * by the interface's name.  The provider may use these hints to
     689                 :            :      * describe the startup configuration in order to reinitialize its
     690                 :            :      * state.  The caller owns the provided data, so a provider must
     691                 :            :      * make copies of anything required.  An ofproto provider must
     692                 :            :      * remove any existing state that is not described by the hint, and
     693                 :            :      * may choose to remove it all. */
     694                 :            :     void (*init)(const struct shash *iface_hints);
     695                 :            : 
     696                 :            :     /* Enumerates the types of all supported ofproto types into 'types'.  The
     697                 :            :      * caller has already initialized 'types'.  The implementation should add
     698                 :            :      * its own types to 'types' but not remove any existing ones, because other
     699                 :            :      * ofproto classes might already have added names to it. */
     700                 :            :     void (*enumerate_types)(struct sset *types);
     701                 :            : 
     702                 :            :     /* Enumerates the names of all existing datapath of the specified 'type'
     703                 :            :      * into 'names' 'all_dps'.  The caller has already initialized 'names' as
     704                 :            :      * an empty sset.
     705                 :            :      *
     706                 :            :      * 'type' is one of the types enumerated by ->enumerate_types().
     707                 :            :      *
     708                 :            :      * Returns 0 if successful, otherwise a positive errno value.
     709                 :            :      */
     710                 :            :     int (*enumerate_names)(const char *type, struct sset *names);
     711                 :            : 
     712                 :            :     /* Deletes the datapath with the specified 'type' and 'name'.  The caller
     713                 :            :      * should have closed any open ofproto with this 'type' and 'name'; this
     714                 :            :      * function is allowed to fail if that is not the case.
     715                 :            :      *
     716                 :            :      * 'type' is one of the types enumerated by ->enumerate_types().
     717                 :            :      * 'name' is one of the names enumerated by ->enumerate_names() for 'type'.
     718                 :            :      *
     719                 :            :      * Returns 0 if successful, otherwise a positive errno value.
     720                 :            :      */
     721                 :            :     int (*del)(const char *type, const char *name);
     722                 :            : 
     723                 :            :     /* Returns the type to pass to netdev_open() when a datapath of type
     724                 :            :      * 'datapath_type' has a port of type 'port_type', for a few special
     725                 :            :      * cases when a netdev type differs from a port type.  For example,
     726                 :            :      * when using the userspace datapath, a port of type "internal"
     727                 :            :      * needs to be opened as "tap".
     728                 :            :      *
     729                 :            :      * Returns either 'type' itself or a string literal, which must not
     730                 :            :      * be freed. */
     731                 :            :     const char *(*port_open_type)(const char *datapath_type,
     732                 :            :                                   const char *port_type);
     733                 :            : 
     734                 :            : /* ## ------------------------ ## */
     735                 :            : /* ## Top-Level type Functions ## */
     736                 :            : /* ## ------------------------ ## */
     737                 :            : 
     738                 :            :     /* Performs any periodic activity required on ofprotos of type
     739                 :            :      * 'type'.
     740                 :            :      *
     741                 :            :      * An ofproto provider may implement it or not, depending on whether
     742                 :            :      * it needs type-level maintenance.
     743                 :            :      *
     744                 :            :      * Returns 0 if successful, otherwise a positive errno value. */
     745                 :            :     int (*type_run)(const char *type);
     746                 :            : 
     747                 :            :     /* Causes the poll loop to wake up when a type 'type''s 'run'
     748                 :            :      * function needs to be called, e.g. by calling the timer or fd
     749                 :            :      * waiting functions in poll-loop.h.
     750                 :            :      *
     751                 :            :      * An ofproto provider may implement it or not, depending on whether
     752                 :            :      * it needs type-level maintenance. */
     753                 :            :     void (*type_wait)(const char *type);
     754                 :            : 
     755                 :            : /* ## --------------------------- ## */
     756                 :            : /* ## Top-Level ofproto Functions ## */
     757                 :            : /* ## --------------------------- ## */
     758                 :            : 
     759                 :            :     /* Life-cycle functions for an "ofproto" (see "Life Cycle" above).
     760                 :            :      *
     761                 :            :      *
     762                 :            :      * Construction
     763                 :            :      * ============
     764                 :            :      *
     765                 :            :      * ->construct() should not modify any base members of the ofproto.  The
     766                 :            :      * client will initialize the ofproto's 'ports' and 'tables' members after
     767                 :            :      * construction is complete.
     768                 :            :      *
     769                 :            :      * When ->construct() is called, the client does not yet know how many flow
     770                 :            :      * tables the datapath supports, so ofproto->n_tables will be 0 and
     771                 :            :      * ofproto->tables will be NULL.  ->construct() should call
     772                 :            :      * ofproto_init_tables() to allocate and initialize ofproto->n_tables and
     773                 :            :      * ofproto->tables.  Each flow table will be initially empty, so
     774                 :            :      * ->construct() should delete flows from the underlying datapath, if
     775                 :            :      * necessary, rather than populating the tables.
     776                 :            :      *
     777                 :            :      * If the ofproto knows the maximum port number that the datapath can have,
     778                 :            :      * then it can call ofproto_init_max_ports().  If it does so, then the
     779                 :            :      * client will ensure that the actions it allows to be used through
     780                 :            :      * OpenFlow do not refer to ports above that maximum number.
     781                 :            :      *
     782                 :            :      * Only one ofproto instance needs to be supported for any given datapath.
     783                 :            :      * If a datapath is already open as part of one "ofproto", then another
     784                 :            :      * attempt to "construct" the same datapath as part of another ofproto is
     785                 :            :      * allowed to fail with an error.
     786                 :            :      *
     787                 :            :      * ->construct() returns 0 if successful, otherwise a positive errno
     788                 :            :      * value.
     789                 :            :      *
     790                 :            :      *
     791                 :            :      * Destruction
     792                 :            :      * ===========
     793                 :            :      *
     794                 :            :      * ->destruct() must also destroy all remaining rules in the ofproto's
     795                 :            :      * tables, by passing each remaining rule to ofproto_rule_delete(), then
     796                 :            :      * destroy all remaining groups by calling ofproto_group_delete_all().
     797                 :            :      *
     798                 :            :      * The client will destroy the flow tables themselves after ->destruct()
     799                 :            :      * returns.
     800                 :            :      */
     801                 :            :     struct ofproto *(*alloc)(void);
     802                 :            :     int (*construct)(struct ofproto *ofproto);
     803                 :            :     void (*destruct)(struct ofproto *ofproto);
     804                 :            :     void (*dealloc)(struct ofproto *ofproto);
     805                 :            : 
     806                 :            :     /* Performs any periodic activity required by 'ofproto'.  It should:
     807                 :            :      *
     808                 :            :      *   - Call connmgr_send_packet_in() for each received packet that missed
     809                 :            :      *     in the OpenFlow flow table or that had a OFPP_CONTROLLER output
     810                 :            :      *     action.
     811                 :            :      *
     812                 :            :      *   - Call ofproto_rule_expire() for each OpenFlow flow that has reached
     813                 :            :      *     its hard_timeout or idle_timeout, to expire the flow.
     814                 :            :      *
     815                 :            :      * Returns 0 if successful, otherwise a positive errno value. */
     816                 :            :     int (*run)(struct ofproto *ofproto);
     817                 :            : 
     818                 :            :     /* Causes the poll loop to wake up when 'ofproto''s 'run' function needs to
     819                 :            :      * be called, e.g. by calling the timer or fd waiting functions in
     820                 :            :      * poll-loop.h.  */
     821                 :            :     void (*wait)(struct ofproto *ofproto);
     822                 :            : 
     823                 :            :     /* Adds some memory usage statistics for the implementation of 'ofproto'
     824                 :            :      * into 'usage', for use with memory_report().
     825                 :            :      *
     826                 :            :      * This function is optional. */
     827                 :            :     void (*get_memory_usage)(const struct ofproto *ofproto,
     828                 :            :                              struct simap *usage);
     829                 :            : 
     830                 :            :     /* Adds some memory usage statistics for the implementation of 'type'
     831                 :            :      * into 'usage', for use with memory_report().
     832                 :            :      *
     833                 :            :      * This function is optional. */
     834                 :            :     void (*type_get_memory_usage)(const char *type, struct simap *usage);
     835                 :            : 
     836                 :            :     /* Every "struct rule" in 'ofproto' is about to be deleted, one by one.
     837                 :            :      * This function may prepare for that, for example by clearing state in
     838                 :            :      * advance.  It should *not* actually delete any "struct rule"s from
     839                 :            :      * 'ofproto', only prepare for it.
     840                 :            :      *
     841                 :            :      * This function is optional; it's really just for optimization in case
     842                 :            :      * it's cheaper to delete all the flows from your hardware in a single pass
     843                 :            :      * than to do it one by one. */
     844                 :            :     void (*flush)(struct ofproto *ofproto);
     845                 :            : 
     846                 :            :     /* Helper for the OpenFlow OFPT_TABLE_FEATURES request.
     847                 :            :      *
     848                 :            :      * The 'features' array contains 'ofproto->n_tables' elements.  Each
     849                 :            :      * element is initialized as:
     850                 :            :      *
     851                 :            :      *   - 'table_id' to the array index.
     852                 :            :      *
     853                 :            :      *   - 'name' to "table#" where # is the table ID.
     854                 :            :      *
     855                 :            :      *   - 'metadata_match' and 'metadata_write' to OVS_BE64_MAX.
     856                 :            :      *
     857                 :            :      *   - 'config' to the table miss configuration.
     858                 :            :      *
     859                 :            :      *   - 'max_entries' to 1,000,000.
     860                 :            :      *
     861                 :            :      *   - Both 'nonmiss' and 'miss' to:
     862                 :            :      *
     863                 :            :      *     * 'next' to all 1-bits for all later tables.
     864                 :            :      *
     865                 :            :      *     * 'instructions' to all instructions.
     866                 :            :      *
     867                 :            :      *     * 'write' and 'apply' both to:
     868                 :            :      *
     869                 :            :      *       - 'ofpacts': All actions.
     870                 :            :      *
     871                 :            :      *       - 'set_fields': All fields.
     872                 :            :      *
     873                 :            :      *   - 'match', 'mask', and 'wildcard' to all fields.
     874                 :            :      *
     875                 :            :      * If 'stats' is nonnull, it also contains 'ofproto->n_tables' elements.
     876                 :            :      * Each element is initialized as:
     877                 :            :      *
     878                 :            :      *   - 'table_id' to the array index.
     879                 :            :      *
     880                 :            :      *   - 'active_count' to the 'n_flows' of struct ofproto for the table.
     881                 :            :      *
     882                 :            :      *   - 'lookup_count' and 'matched_count' to 0.
     883                 :            :      *
     884                 :            :      * The implementation should update any members in each element for which
     885                 :            :      * it has better values:
     886                 :            :      *
     887                 :            :      *   - Any member of 'features' to better describe the implementation's
     888                 :            :      *     capabilities.
     889                 :            :      *
     890                 :            :      *   - 'lookup_count' to the number of packets looked up in this flow table
     891                 :            :      *     so far.
     892                 :            :      *
     893                 :            :      *   - 'matched_count' to the number of packets looked up in this flow
     894                 :            :      *     table so far that matched one of the flow entries.
     895                 :            :      */
     896                 :            :     void (*query_tables)(struct ofproto *ofproto,
     897                 :            :                          struct ofputil_table_features *features,
     898                 :            :                          struct ofputil_table_stats *stats);
     899                 :            : 
     900                 :            :     /* Sets the current tables version the provider should use for classifier
     901                 :            :      * lookups.  This must be called with a new version number after each set
     902                 :            :      * of flow table changes has been completed, so that datapath revalidation
     903                 :            :      * can be triggered. */
     904                 :            :     void (*set_tables_version)(struct ofproto *ofproto, ovs_version_t version);
     905                 :            : 
     906                 :            : /* ## ---------------- ## */
     907                 :            : /* ## ofport Functions ## */
     908                 :            : /* ## ---------------- ## */
     909                 :            : 
     910                 :            :     /* Life-cycle functions for a "struct ofport" (see "Life Cycle" above).
     911                 :            :      *
     912                 :            :      * ->port_construct() should not modify any base members of the ofport.
     913                 :            :      * An ofproto implementation should use the 'ofp_port' member of
     914                 :            :      * "struct ofport" as the OpenFlow port number.
     915                 :            :      *
     916                 :            :      * ofports are managed by the base ofproto code.  The ofproto
     917                 :            :      * implementation should only create and destroy them in response to calls
     918                 :            :      * to these functions.  The base ofproto code will create and destroy
     919                 :            :      * ofports in the following situations:
     920                 :            :      *
     921                 :            :      *   - Just after the ->construct() function is called, the base ofproto
     922                 :            :      *     iterates over all of the implementation's ports, using
     923                 :            :      *     ->port_dump_start() and related functions, and constructs an ofport
     924                 :            :      *     for each dumped port.
     925                 :            :      *
     926                 :            :      *   - If ->port_poll() reports that a specific port has changed, then the
     927                 :            :      *     base ofproto will query that port with ->port_query_by_name() and
     928                 :            :      *     construct or destruct ofports as necessary to reflect the updated
     929                 :            :      *     set of ports.
     930                 :            :      *
     931                 :            :      *   - If ->port_poll() returns ENOBUFS to report an unspecified port set
     932                 :            :      *     change, then the base ofproto will iterate over all of the
     933                 :            :      *     implementation's ports, in the same way as at ofproto
     934                 :            :      *     initialization, and construct and destruct ofports to reflect all of
     935                 :            :      *     the changes.
     936                 :            :      *
     937                 :            :      *   - On graceful shutdown, the base ofproto code will destruct all
     938                 :            :      *     the ports.
     939                 :            :      *
     940                 :            :      * ->port_construct() returns 0 if successful, otherwise a positive errno
     941                 :            :      * value.
     942                 :            :      *
     943                 :            :      *
     944                 :            :      * ->port_destruct()
     945                 :            :      * =================
     946                 :            :      *
     947                 :            :      * ->port_destruct() takes a 'del' parameter.  If the provider implements
     948                 :            :      * the datapath itself (e.g. dpif-netdev, it can ignore 'del'.  On the
     949                 :            :      * other hand, if the provider is an interface to an external datapath
     950                 :            :      * (e.g. to a kernel module that implement the datapath) then 'del' should
     951                 :            :      * influence destruction behavior in the following way:
     952                 :            :      *
     953                 :            :      *   - If 'del' is true, it should remove the port from the underlying
     954                 :            :      *     implementation.  This is the common case.
     955                 :            :      *
     956                 :            :      *   - If 'del' is false, it should leave the port in the underlying
     957                 :            :      *     implementation.  This is used when Open vSwitch is performing a
     958                 :            :      *     graceful shutdown and ensures that, across Open vSwitch restarts,
     959                 :            :      *     the underlying ports are not removed and recreated.  That makes an
     960                 :            :      *     important difference for, e.g., "internal" ports that have
     961                 :            :      *     configured IP addresses; without this distinction, the IP address
     962                 :            :      *     and other configured state for the port is lost.
     963                 :            :      */
     964                 :            :     struct ofport *(*port_alloc)(void);
     965                 :            :     int (*port_construct)(struct ofport *ofport);
     966                 :            :     void (*port_destruct)(struct ofport *ofport, bool del);
     967                 :            :     void (*port_dealloc)(struct ofport *ofport);
     968                 :            : 
     969                 :            :     /* Called after 'ofport->netdev' is replaced by a new netdev object.  If
     970                 :            :      * the ofproto implementation uses the ofport's netdev internally, then it
     971                 :            :      * should switch to using the new one.  The old one has been closed.
     972                 :            :      *
     973                 :            :      * An ofproto implementation that doesn't need to do anything in this
     974                 :            :      * function may use a null pointer. */
     975                 :            :     void (*port_modified)(struct ofport *ofport);
     976                 :            : 
     977                 :            :     /* Called after an OpenFlow request changes a port's configuration.
     978                 :            :      * 'ofport->pp.config' contains the new configuration.  'old_config'
     979                 :            :      * contains the previous configuration.
     980                 :            :      *
     981                 :            :      * The caller implements OFPUTIL_PC_PORT_DOWN using netdev functions to
     982                 :            :      * turn NETDEV_UP on and off, so this function doesn't have to do anything
     983                 :            :      * for that bit (and it won't be called if that is the only bit that
     984                 :            :      * changes). */
     985                 :            :     void (*port_reconfigured)(struct ofport *ofport,
     986                 :            :                               enum ofputil_port_config old_config);
     987                 :            : 
     988                 :            :     /* Looks up a port named 'devname' in 'ofproto'.  On success, returns 0 and
     989                 :            :      * initializes '*port' appropriately. Otherwise, returns a positive errno
     990                 :            :      * value.
     991                 :            :      *
     992                 :            :      * The caller owns the data in 'port' and must free it with
     993                 :            :      * ofproto_port_destroy() when it is no longer needed. */
     994                 :            :     int (*port_query_by_name)(const struct ofproto *ofproto,
     995                 :            :                               const char *devname, struct ofproto_port *port);
     996                 :            : 
     997                 :            :     /* Attempts to add 'netdev' as a port on 'ofproto'.  Returns 0 if
     998                 :            :      * successful, otherwise a positive errno value.  The caller should
     999                 :            :      * inform the implementation of the OpenFlow port through the
    1000                 :            :      * ->port_construct() method.
    1001                 :            :      *
    1002                 :            :      * It doesn't matter whether the new port will be returned by a later call
    1003                 :            :      * to ->port_poll(); the implementation may do whatever is more
    1004                 :            :      * convenient. */
    1005                 :            :     int (*port_add)(struct ofproto *ofproto, struct netdev *netdev);
    1006                 :            : 
    1007                 :            :     /* Deletes port number 'ofp_port' from the datapath for 'ofproto'.  Returns
    1008                 :            :      * 0 if successful, otherwise a positive errno value.
    1009                 :            :      *
    1010                 :            :      * It doesn't matter whether the new port will be returned by a later call
    1011                 :            :      * to ->port_poll(); the implementation may do whatever is more
    1012                 :            :      * convenient. */
    1013                 :            :     int (*port_del)(struct ofproto *ofproto, ofp_port_t ofp_port);
    1014                 :            : 
    1015                 :            :     /* Refreshes datapath configuration of 'port'.
    1016                 :            :      * Returns 0 if successful, otherwise a positive errno value. */
    1017                 :            :     int (*port_set_config)(const struct ofport *port, const struct smap *cfg);
    1018                 :            : 
    1019                 :            :     /* Get port stats */
    1020                 :            :     int (*port_get_stats)(const struct ofport *port,
    1021                 :            :                           struct netdev_stats *stats);
    1022                 :            : 
    1023                 :            :     /* Port iteration functions.
    1024                 :            :      *
    1025                 :            :      * The client might not be entirely in control of the ports within an
    1026                 :            :      * ofproto.  Some hardware implementations, for example, might have a fixed
    1027                 :            :      * set of ports in a datapath.  For this reason, the client needs a way to
    1028                 :            :      * iterate through all the ports that are actually in a datapath.  These
    1029                 :            :      * functions provide that functionality.
    1030                 :            :      *
    1031                 :            :      * The 'state' pointer provides the implementation a place to
    1032                 :            :      * keep track of its position.  Its format is opaque to the caller.
    1033                 :            :      *
    1034                 :            :      * The ofproto provider retains ownership of the data that it stores into
    1035                 :            :      * ->port_dump_next()'s 'port' argument.  The data must remain valid until
    1036                 :            :      * at least the next call to ->port_dump_next() or ->port_dump_done() for
    1037                 :            :      * 'state'.  The caller will not modify or free it.
    1038                 :            :      *
    1039                 :            :      * Details
    1040                 :            :      * =======
    1041                 :            :      *
    1042                 :            :      * ->port_dump_start() attempts to begin dumping the ports in 'ofproto'.
    1043                 :            :      * On success, it should return 0 and initialize '*statep' with any data
    1044                 :            :      * needed for iteration.  On failure, returns a positive errno value, and
    1045                 :            :      * the client will not call ->port_dump_next() or ->port_dump_done().
    1046                 :            :      *
    1047                 :            :      * ->port_dump_next() attempts to retrieve another port from 'ofproto' for
    1048                 :            :      * 'state'.  If there is another port, it should store the port's
    1049                 :            :      * information into 'port' and return 0.  It should return EOF if all ports
    1050                 :            :      * have already been iterated.  Otherwise, on error, it should return a
    1051                 :            :      * positive errno value.  This function will not be called again once it
    1052                 :            :      * returns nonzero once for a given iteration (but the 'port_dump_done'
    1053                 :            :      * function will be called afterward).
    1054                 :            :      *
    1055                 :            :      * ->port_dump_done() allows the implementation to release resources used
    1056                 :            :      * for iteration.  The caller might decide to stop iteration in the middle
    1057                 :            :      * by calling this function before ->port_dump_next() returns nonzero.
    1058                 :            :      *
    1059                 :            :      * Usage Example
    1060                 :            :      * =============
    1061                 :            :      *
    1062                 :            :      * int error;
    1063                 :            :      * void *state;
    1064                 :            :      *
    1065                 :            :      * error = ofproto->ofproto_class->port_dump_start(ofproto, &state);
    1066                 :            :      * if (!error) {
    1067                 :            :      *     for (;;) {
    1068                 :            :      *         struct ofproto_port port;
    1069                 :            :      *
    1070                 :            :      *         error = ofproto->ofproto_class->port_dump_next(
    1071                 :            :      *                     ofproto, state, &port);
    1072                 :            :      *         if (error) {
    1073                 :            :      *             break;
    1074                 :            :      *         }
    1075                 :            :      *         // Do something with 'port' here (without modifying or freeing
    1076                 :            :      *         // any of its data).
    1077                 :            :      *     }
    1078                 :            :      *     ofproto->ofproto_class->port_dump_done(ofproto, state);
    1079                 :            :      * }
    1080                 :            :      * // 'error' is now EOF (success) or a positive errno value (failure).
    1081                 :            :      */
    1082                 :            :     int (*port_dump_start)(const struct ofproto *ofproto, void **statep);
    1083                 :            :     int (*port_dump_next)(const struct ofproto *ofproto, void *state,
    1084                 :            :                           struct ofproto_port *port);
    1085                 :            :     int (*port_dump_done)(const struct ofproto *ofproto, void *state);
    1086                 :            : 
    1087                 :            :     /* Polls for changes in the set of ports in 'ofproto'.  If the set of ports
    1088                 :            :      * in 'ofproto' has changed, then this function should do one of the
    1089                 :            :      * following:
    1090                 :            :      *
    1091                 :            :      * - Preferably: store the name of the device that was added to or deleted
    1092                 :            :      *   from 'ofproto' in '*devnamep' and return 0.  The caller is responsible
    1093                 :            :      *   for freeing '*devnamep' (with free()) when it no longer needs it.
    1094                 :            :      *
    1095                 :            :      * - Alternatively: return ENOBUFS, without indicating the device that was
    1096                 :            :      *   added or deleted.
    1097                 :            :      *
    1098                 :            :      * Occasional 'false positives', in which the function returns 0 while
    1099                 :            :      * indicating a device that was not actually added or deleted or returns
    1100                 :            :      * ENOBUFS without any change, are acceptable.
    1101                 :            :      *
    1102                 :            :      * The purpose of 'port_poll' is to let 'ofproto' know about changes made
    1103                 :            :      * externally to the 'ofproto' object, e.g. by a system administrator via
    1104                 :            :      * ovs-dpctl.  Therefore, it's OK, and even preferable, for port_poll() to
    1105                 :            :      * not report changes made through calls to 'port_add' or 'port_del' on the
    1106                 :            :      * same 'ofproto' object.  (But it's OK for it to report them too, just
    1107                 :            :      * slightly less efficient.)
    1108                 :            :      *
    1109                 :            :      * If the set of ports in 'ofproto' has not changed, returns EAGAIN.  May
    1110                 :            :      * also return other positive errno values to indicate that something has
    1111                 :            :      * gone wrong.
    1112                 :            :      *
    1113                 :            :      * If the set of ports in a datapath is fixed, or if the only way that the
    1114                 :            :      * set of ports in a datapath can change is through ->port_add() and
    1115                 :            :      * ->port_del(), then this function may be a null pointer.
    1116                 :            :      */
    1117                 :            :     int (*port_poll)(const struct ofproto *ofproto, char **devnamep);
    1118                 :            : 
    1119                 :            :     /* Arranges for the poll loop to wake up when ->port_poll() will return a
    1120                 :            :      * value other than EAGAIN.
    1121                 :            :      *
    1122                 :            :      * If the set of ports in a datapath is fixed, or if the only way that the
    1123                 :            :      * set of ports in a datapath can change is through ->port_add() and
    1124                 :            :      * ->port_del(), or if the poll loop will always wake up anyway when
    1125                 :            :      * ->port_poll() will return a value other than EAGAIN, then this function
    1126                 :            :      * may be a null pointer.
    1127                 :            :      */
    1128                 :            :     void (*port_poll_wait)(const struct ofproto *ofproto);
    1129                 :            : 
    1130                 :            :     /* Checks the status of LACP negotiation for 'port'.  Returns 1 if LACP
    1131                 :            :      * partner information for 'port' is up-to-date, 0 if LACP partner
    1132                 :            :      * information is not current (generally indicating a connectivity
    1133                 :            :      * problem), or -1 if LACP is not enabled on 'port'.
    1134                 :            :      *
    1135                 :            :      * This function may be a null pointer if the ofproto implementation does
    1136                 :            :      * not support LACP.
    1137                 :            :      */
    1138                 :            :     int (*port_is_lacp_current)(const struct ofport *port);
    1139                 :            : 
    1140                 :            :     /* Get LACP port stats. Returns -1 if LACP is not enabled on 'port'.
    1141                 :            :      *
    1142                 :            :      * This function may be a null pointer if the ofproto implementation does
    1143                 :            :      * not support LACP.
    1144                 :            :      */
    1145                 :            :     int (*port_get_lacp_stats)(const struct ofport *port,
    1146                 :            :                                struct lacp_slave_stats *stats);
    1147                 :            : 
    1148                 :            : /* ## ----------------------- ## */
    1149                 :            : /* ## OpenFlow Rule Functions ## */
    1150                 :            : /* ## ----------------------- ## */
    1151                 :            : 
    1152                 :            :     /* Chooses an appropriate table for 'match' within 'ofproto'.  On
    1153                 :            :      * success, stores the table ID into '*table_idp' and returns 0.  On
    1154                 :            :      * failure, returns an OpenFlow error code.
    1155                 :            :      *
    1156                 :            :      * The choice of table should be a function of 'match' and 'ofproto''s
    1157                 :            :      * datapath capabilities.  It should not depend on the flows already in
    1158                 :            :      * 'ofproto''s flow tables.  Failure implies that an OpenFlow rule with
    1159                 :            :      * 'match' as its matching condition can never be inserted into 'ofproto',
    1160                 :            :      * even starting from an empty flow table.
    1161                 :            :      *
    1162                 :            :      * If multiple tables are candidates for inserting the flow, the function
    1163                 :            :      * should choose one arbitrarily (but deterministically).
    1164                 :            :      *
    1165                 :            :      * If this function is NULL then table 0 is always chosen. */
    1166                 :            :     enum ofperr (*rule_choose_table)(const struct ofproto *ofproto,
    1167                 :            :                                      const struct match *match,
    1168                 :            :                                      uint8_t *table_idp);
    1169                 :            : 
    1170                 :            :     /* Life-cycle functions for a "struct rule".
    1171                 :            :      *
    1172                 :            :      *
    1173                 :            :      * Rule Life Cycle
    1174                 :            :      * ===============
    1175                 :            :      *
    1176                 :            :      * The life cycle of a struct rule is an elaboration of the basic life
    1177                 :            :      * cycle described above under "Life Cycle".
    1178                 :            :      *
    1179                 :            :      * After a rule is successfully constructed, it is then inserted.  If
    1180                 :            :      * insertion is successful, then before it is later destructed, it is
    1181                 :            :      * deleted.
    1182                 :            :      *
    1183                 :            :      * You can think of a rule as having the following extra steps inserted
    1184                 :            :      * between "Life Cycle" steps 4 and 5:
    1185                 :            :      *
    1186                 :            :      *   4.1. The client inserts the rule into the flow table, making it
    1187                 :            :      *        visible in flow table lookups.
    1188                 :            :      *
    1189                 :            :      *   4.2. The client calls "rule_insert" to insert the flow.  The
    1190                 :            :      *        implementation attempts to install the flow in the underlying
    1191                 :            :      *        hardware and returns an error code indicate success or failure.
    1192                 :            :      *        On failure, go to step 5.
    1193                 :            :      *
    1194                 :            :      *   4.3. The rule is now installed in the flow table.  Eventually it will
    1195                 :            :      *        be deleted.
    1196                 :            :      *
    1197                 :            :      *   4.4. The client removes the rule from the flow table.  It is no longer
    1198                 :            :      *        visible in flow table lookups.
    1199                 :            :      *
    1200                 :            :      *   4.5. The client calls "rule_delete".  The implementation uninstalls
    1201                 :            :      *        the flow from the underlying hardware.  Deletion is not allowed
    1202                 :            :      *        to fail.
    1203                 :            :      *
    1204                 :            :      *
    1205                 :            :      * Construction
    1206                 :            :      * ============
    1207                 :            :      *
    1208                 :            :      * When ->rule_construct() is called, 'rule' is a new rule that is not yet
    1209                 :            :      * inserted into a flow table.  ->rule_construct() should initialize enough
    1210                 :            :      * of the rule's derived state for 'rule' to be suitable for inserting into
    1211                 :            :      * a flow table.  ->rule_construct() should not modify any base members of
    1212                 :            :      * struct rule.
    1213                 :            :      *
    1214                 :            :      * If ->rule_construct() fails (as indicated by returning a nonzero
    1215                 :            :      * OpenFlow error code), the ofproto base code will uninitialize and
    1216                 :            :      * deallocate 'rule'.  See "Rule Life Cycle" above for more details.
    1217                 :            :      *
    1218                 :            :      * ->rule_construct() must also:
    1219                 :            :      *
    1220                 :            :      *   - Validate that the datapath supports the matching rule in 'rule->cr'
    1221                 :            :      *     datapath.  For example, if the rule's table does not support
    1222                 :            :      *     registers, then it is an error if 'rule->cr' does not wildcard all
    1223                 :            :      *     registers.
    1224                 :            :      *
    1225                 :            :      *   - Validate that the datapath can correctly implement 'rule->ofpacts'.
    1226                 :            :      *
    1227                 :            :      * After a successful construction the rest of the rule life cycle calls
    1228                 :            :      * may not fail, so ->rule_construct() must also make sure that the rule
    1229                 :            :      * can be inserted in to the datapath.
    1230                 :            :      *
    1231                 :            :      *
    1232                 :            :      * Insertion
    1233                 :            :      * =========
    1234                 :            :      *
    1235                 :            :      * Following successful construction, the ofproto base case inserts 'rule'
    1236                 :            :      * into its flow table, then it calls ->rule_insert().  ->rule_insert()
    1237                 :            :      * must add the new rule to the datapath flow table and return only after
    1238                 :            :      * this is complete.  The 'new_rule' may be a duplicate of an 'old_rule'.
    1239                 :            :      * In this case the 'old_rule' is non-null, and the implementation should
    1240                 :            :      * forward rule statistics counts from the 'old_rule' to the 'new_rule' if
    1241                 :            :      * 'forward_counts' is 'true', 'used' timestamp is always forwarded.  This
    1242                 :            :      * may not fail.
    1243                 :            :      *
    1244                 :            :      *
    1245                 :            :      * Deletion
    1246                 :            :      * ========
    1247                 :            :      *
    1248                 :            :      * The ofproto base code removes 'rule' from its flow table before it calls
    1249                 :            :      * ->rule_delete() (if non-null).  ->rule_delete() must remove 'rule' from
    1250                 :            :      * the datapath flow table and return only after this has completed
    1251                 :            :      * successfully.
    1252                 :            :      *
    1253                 :            :      * Rule deletion must not fail.
    1254                 :            :      *
    1255                 :            :      *
    1256                 :            :      * Destruction
    1257                 :            :      * ===========
    1258                 :            :      *
    1259                 :            :      * ->rule_destruct() must uninitialize derived state.
    1260                 :            :      *
    1261                 :            :      * Rule destruction must not fail. */
    1262                 :            :     struct rule *(*rule_alloc)(void);
    1263                 :            :     enum ofperr (*rule_construct)(struct rule *rule)
    1264                 :            :         /* OVS_REQUIRES(ofproto_mutex) */;
    1265                 :            :     void (*rule_insert)(struct rule *rule, struct rule *old_rule,
    1266                 :            :                         bool forward_counts)
    1267                 :            :         /* OVS_REQUIRES(ofproto_mutex) */;
    1268                 :            :     void (*rule_delete)(struct rule *rule) /* OVS_REQUIRES(ofproto_mutex) */;
    1269                 :            :     void (*rule_destruct)(struct rule *rule);
    1270                 :            :     void (*rule_dealloc)(struct rule *rule);
    1271                 :            : 
    1272                 :            :     /* Obtains statistics for 'rule', storing the number of packets that have
    1273                 :            :      * matched it in '*packet_count' and the number of bytes in those packets
    1274                 :            :      * in '*byte_count'.  UINT64_MAX indicates that the packet count or byte
    1275                 :            :      * count is unknown. */
    1276                 :            :     void (*rule_get_stats)(struct rule *rule, uint64_t *packet_count,
    1277                 :            :                            uint64_t *byte_count, long long int *used)
    1278                 :            :         /* OVS_EXCLUDED(ofproto_mutex) */;
    1279                 :            : 
    1280                 :            :     /* Changes the OpenFlow IP fragment handling policy to 'frag_handling',
    1281                 :            :      * which takes one of the following values, with the corresponding
    1282                 :            :      * meanings:
    1283                 :            :      *
    1284                 :            :      *  - OFPUTIL_FRAG_NORMAL: The switch should treat IP fragments the same
    1285                 :            :      *    way as other packets, omitting TCP and UDP port numbers (always
    1286                 :            :      *    setting them to 0).
    1287                 :            :      *
    1288                 :            :      *  - OFPUTIL_FRAG_DROP: The switch should drop all IP fragments without
    1289                 :            :      *    passing them through the flow table.
    1290                 :            :      *
    1291                 :            :      *  - OFPUTIL_FRAG_REASM: The switch should reassemble IP fragments before
    1292                 :            :      *    passing packets through the flow table.
    1293                 :            :      *
    1294                 :            :      *  - OFPUTIL_FRAG_NX_MATCH (a Nicira extension): Similar to
    1295                 :            :      *    OFPUTIL_FRAG_NORMAL, except that TCP and UDP port numbers should be
    1296                 :            :      *    included in fragments with offset 0.
    1297                 :            :      *
    1298                 :            :      * Implementations are not required to support every mode.
    1299                 :            :      * OFPUTIL_FRAG_NORMAL is the default mode when an ofproto is created.
    1300                 :            :      *
    1301                 :            :      * At the time of the call to ->set_frag_handling(), the current mode is
    1302                 :            :      * available in 'ofproto->frag_handling'.  ->set_frag_handling() returns
    1303                 :            :      * true if the requested mode was set, false if it is not supported.
    1304                 :            :      *
    1305                 :            :      * Upon successful return, the caller changes 'ofproto->frag_handling' to
    1306                 :            :      * reflect the new mode.
    1307                 :            :      */
    1308                 :            :     bool (*set_frag_handling)(struct ofproto *ofproto,
    1309                 :            :                               enum ofputil_frag_handling frag_handling);
    1310                 :            : 
    1311                 :            :     /* Implements the OpenFlow OFPT_PACKET_OUT command.  The datapath should
    1312                 :            :      * execute the 'ofpacts_len' bytes of "struct ofpacts" in 'ofpacts'.
    1313                 :            :      *
    1314                 :            :      * The caller retains ownership of 'packet' and of 'ofpacts', so
    1315                 :            :      * ->packet_out() should not modify or free them.
    1316                 :            :      *
    1317                 :            :      * This function must validate that it can correctly implement 'ofpacts'.
    1318                 :            :      * If not, then it should return an OpenFlow error code.
    1319                 :            :      *
    1320                 :            :      * 'flow' reflects the flow information for 'packet'.  All of the
    1321                 :            :      * information in 'flow' is extracted from 'packet', except for
    1322                 :            :      * flow->in_port (see below).  flow->tunnel and its register values are
    1323                 :            :      * zeroed.
    1324                 :            :      *
    1325                 :            :      * flow->in_port comes from the OpenFlow OFPT_PACKET_OUT message.  The
    1326                 :            :      * implementation should reject invalid flow->in_port values by returning
    1327                 :            :      * OFPERR_OFPBRC_BAD_PORT.  (If the implementation called
    1328                 :            :      * ofproto_init_max_ports(), then the client will reject these ports
    1329                 :            :      * itself.)  For consistency, the implementation should consider valid for
    1330                 :            :      * flow->in_port any value that could possibly be seen in a packet that it
    1331                 :            :      * passes to connmgr_send_packet_in().  Ideally, even an implementation
    1332                 :            :      * that never generates packet-ins (e.g. due to hardware limitations)
    1333                 :            :      * should still allow flow->in_port values for every possible physical port
    1334                 :            :      * and OFPP_LOCAL.  The only virtual ports (those above OFPP_MAX) that the
    1335                 :            :      * caller will ever pass in as flow->in_port, other than OFPP_LOCAL, are
    1336                 :            :      * OFPP_NONE and OFPP_CONTROLLER.  The implementation should allow both of
    1337                 :            :      * these, treating each of them as packets generated by the controller as
    1338                 :            :      * opposed to packets originating from some switch port.
    1339                 :            :      *
    1340                 :            :      * (Ordinarily the only effect of flow->in_port is on output actions that
    1341                 :            :      * involve the input port, such as actions that output to OFPP_IN_PORT,
    1342                 :            :      * OFPP_FLOOD, or OFPP_ALL.  flow->in_port can also affect Nicira extension
    1343                 :            :      * "resubmit" actions.)
    1344                 :            :      *
    1345                 :            :      * 'packet' is not matched against the OpenFlow flow table, so its
    1346                 :            :      * statistics should not be included in OpenFlow flow statistics.
    1347                 :            :      *
    1348                 :            :      * Returns 0 if successful, otherwise an OpenFlow error code. */
    1349                 :            :     enum ofperr (*packet_out)(struct ofproto *ofproto, struct dp_packet *packet,
    1350                 :            :                               const struct flow *flow,
    1351                 :            :                               const struct ofpact *ofpacts,
    1352                 :            :                               size_t ofpacts_len);
    1353                 :            : 
    1354                 :            :     enum ofperr (*nxt_resume)(struct ofproto *ofproto,
    1355                 :            :                               const struct ofputil_packet_in_private *);
    1356                 :            : 
    1357                 :            : /* ## ------------------------- ## */
    1358                 :            : /* ## OFPP_NORMAL configuration ## */
    1359                 :            : /* ## ------------------------- ## */
    1360                 :            : 
    1361                 :            :     /* Configures NetFlow on 'ofproto' according to the options in
    1362                 :            :      * 'netflow_options', or turns off NetFlow if 'netflow_options' is NULL.
    1363                 :            :      *
    1364                 :            :      * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
    1365                 :            :      * NetFlow, as does a null pointer. */
    1366                 :            :     int (*set_netflow)(struct ofproto *ofproto,
    1367                 :            :                        const struct netflow_options *netflow_options);
    1368                 :            : 
    1369                 :            :     void (*get_netflow_ids)(const struct ofproto *ofproto,
    1370                 :            :                             uint8_t *engine_type, uint8_t *engine_id);
    1371                 :            : 
    1372                 :            :     /* Configures sFlow on 'ofproto' according to the options in
    1373                 :            :      * 'sflow_options', or turns off sFlow if 'sflow_options' is NULL.
    1374                 :            :      *
    1375                 :            :      * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
    1376                 :            :      * sFlow, as does a null pointer. */
    1377                 :            :     int (*set_sflow)(struct ofproto *ofproto,
    1378                 :            :                      const struct ofproto_sflow_options *sflow_options);
    1379                 :            : 
    1380                 :            :     /* Configures IPFIX on 'ofproto' according to the options in
    1381                 :            :      * 'bridge_exporter_options' and the 'flow_exporters_options'
    1382                 :            :      * array, or turns off IPFIX if 'bridge_exporter_options' and
    1383                 :            :      * 'flow_exporters_options' is NULL.
    1384                 :            :      *
    1385                 :            :      * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
    1386                 :            :      * IPFIX, as does a null pointer. */
    1387                 :            :     int (*set_ipfix)(
    1388                 :            :         struct ofproto *ofproto,
    1389                 :            :         const struct ofproto_ipfix_bridge_exporter_options
    1390                 :            :             *bridge_exporter_options,
    1391                 :            :         const struct ofproto_ipfix_flow_exporter_options
    1392                 :            :             *flow_exporters_options, size_t n_flow_exporters_options);
    1393                 :            : 
    1394                 :            :     /* Gets IPFIX stats on 'ofproto' according to the exporter of birdge
    1395                 :            :      * IPFIX or flow-based IPFIX.
    1396                 :            :      *
    1397                 :            :      * OFPERR_NXST_NOT_CONFIGURED as a return value indicates that bridge
    1398                 :            :      * IPFIX or flow-based IPFIX is not configured. */
    1399                 :            :     int (*get_ipfix_stats)(
    1400                 :            :         const struct ofproto *ofproto,
    1401                 :            :         bool bridge_ipfix, struct ovs_list *replies
    1402                 :            :         );
    1403                 :            : 
    1404                 :            :     /* Configures connectivity fault management on 'ofport'.
    1405                 :            :      *
    1406                 :            :      * If 'cfm_settings' is nonnull, configures CFM according to its members.
    1407                 :            :      *
    1408                 :            :      * If 'cfm_settings' is null, removes any connectivity fault management
    1409                 :            :      * configuration from 'ofport'.
    1410                 :            :      *
    1411                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1412                 :            :      * support CFM, as does a null pointer. */
    1413                 :            :     int (*set_cfm)(struct ofport *ofport, const struct cfm_settings *s);
    1414                 :            : 
    1415                 :            :     /* Checks the status change of CFM on 'ofport'.  Returns true if
    1416                 :            :      * there is status change since last call or if CFM is not specified. */
    1417                 :            :     bool (*cfm_status_changed)(struct ofport *ofport);
    1418                 :            : 
    1419                 :            :     /* Populates 'smap' with the status of CFM on 'ofport'.  Returns 0 on
    1420                 :            :      * success, or a positive errno.  EOPNOTSUPP as a return value indicates
    1421                 :            :      * that this ofproto_class does not support CFM, as does a null pointer.
    1422                 :            :      *
    1423                 :            :      * The caller must provide and own '*status', and it must free the array
    1424                 :            :      * returned in 'status->rmps'.  '*status' is indeterminate if the return
    1425                 :            :      * value is non-zero. */
    1426                 :            :     int (*get_cfm_status)(const struct ofport *ofport,
    1427                 :            :                           struct cfm_status *status);
    1428                 :            : 
    1429                 :            :     /* Configures LLDP on 'ofport'.
    1430                 :            :      *
    1431                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1432                 :            :      * support LLDP, as does a null pointer. */
    1433                 :            :     int (*set_lldp)(struct ofport *ofport, const struct smap *cfg);
    1434                 :            : 
    1435                 :            :     /* Checks the status of LLDP configured on 'ofport'.  Returns true if the
    1436                 :            :      * port's LLDP status was successfully stored into '*status'.  Returns
    1437                 :            :      * false if the port did not have LLDP configured, in which case '*status'
    1438                 :            :      * is indeterminate.
    1439                 :            :      *
    1440                 :            :      * The caller must provide and own '*status'.  '*status' is indeterminate
    1441                 :            :      * if the return value is non-zero. */
    1442                 :            :     bool (*get_lldp_status)(const struct ofport *ofport,
    1443                 :            :                             struct lldp_status *status);
    1444                 :            : 
    1445                 :            :     /* Configures Auto Attach.
    1446                 :            :      *
    1447                 :            :      * If 's' is nonnull, configures Auto Attach according to its members.
    1448                 :            :      *
    1449                 :            :      * If 's' is null, removes any Auto Attach configuration.
    1450                 :            :      */
    1451                 :            :     int (*set_aa)(struct ofproto *ofproto,
    1452                 :            :                   const struct aa_settings *s);
    1453                 :            : 
    1454                 :            :     /* If 's' is nonnull, this function registers a mapping associated with
    1455                 :            :      * client data pointer 'aux' in 'ofproto'.  If 'aux' is already registered
    1456                 :            :      * then this function updates its configuration to 's'.  Otherwise, this
    1457                 :            :      * function registers a new mapping.
    1458                 :            :      *
    1459                 :            :      * An implementation that does not support mapping at all may set
    1460                 :            :      * it to NULL or return EOPNOTSUPP.  An implementation that supports
    1461                 :            :      * only a subset of the functionality should implement what it can
    1462                 :            :      * and return 0.
    1463                 :            :      */
    1464                 :            :     int (*aa_mapping_set)(struct ofproto *ofproto, void *aux,
    1465                 :            :                           const struct aa_mapping_settings *s);
    1466                 :            : 
    1467                 :            :     /* If 's' is nonnull, this function unregisters a mapping associated with
    1468                 :            :      * client data pointer 'aux' in 'ofproto'.  If 'aux' is already registered
    1469                 :            :      * then this function updates its configuration to 's'.  Otherwise, this
    1470                 :            :      * function unregisters a new mapping.
    1471                 :            :      *
    1472                 :            :      * An implementation that does not support mapping at all may set
    1473                 :            :      * it to NULL or return EOPNOTSUPP.  An implementation that supports
    1474                 :            :      * only a subset of the functionality should implement what it can
    1475                 :            :      * and return 0.
    1476                 :            :      */
    1477                 :            :     int (*aa_mapping_unset)(struct ofproto *ofproto, void *aux);
    1478                 :            : 
    1479                 :            :     /*
    1480                 :            :      * Returns the a list of AutoAttach VLAN operations.  When Auto Attach is
    1481                 :            :      * enabled, the VLAN associated with an I-SID/VLAN mapping is first
    1482                 :            :      * negotiated with an Auto Attach Server.  Once an I-SID VLAN mapping
    1483                 :            :      * becomes active, the corresponding VLAN needs to be communicated to the
    1484                 :            :      * bridge in order to add the VLAN to the trunk port linking the Auto
    1485                 :            :      * Attach Client (in this case openvswitch) and the Auto Attach Server.
    1486                 :            :      *
    1487                 :            :      * The list entries are of type "struct bridge_aa_vlan".  Each entry
    1488                 :            :      * specifies the operation (add or remove), the interface on which to
    1489                 :            :      * execute the operation and the VLAN.
    1490                 :            :      */
    1491                 :            :     int (*aa_vlan_get_queued)(struct ofproto *ofproto, struct ovs_list *list);
    1492                 :            : 
    1493                 :            :     /*
    1494                 :            :      * Returns the current number of entries in the list of VLAN operations
    1495                 :            :      * in the Auto Attach Client (see previous function description
    1496                 :            :      * aa_vlan_get_queued).  Returns 0 if Auto Attach is disabled.
    1497                 :            :      */
    1498                 :            :     unsigned int (*aa_vlan_get_queue_size)(struct ofproto *ofproto);
    1499                 :            : 
    1500                 :            :     /* Configures BFD on 'ofport'.
    1501                 :            :      *
    1502                 :            :      * If 'cfg' is NULL, or 'cfg' does not contain the key value pair
    1503                 :            :      * "enable=true", removes BFD from 'ofport'.  Otherwise, configures BFD
    1504                 :            :      * according to 'cfg'.
    1505                 :            :      *
    1506                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1507                 :            :      * support BFD, as does a null pointer. */
    1508                 :            :     int (*set_bfd)(struct ofport *ofport, const struct smap *cfg);
    1509                 :            : 
    1510                 :            :     /* Checks the status change of BFD on 'ofport'.  Returns true if there
    1511                 :            :      * is status change since last call or if BFD is not specified. */
    1512                 :            :     bool (*bfd_status_changed)(struct ofport *ofport);
    1513                 :            : 
    1514                 :            :     /* Populates 'smap' with the status of BFD on 'ofport'.  Returns 0 on
    1515                 :            :      * success, or a positive errno.  EOPNOTSUPP as a return value indicates
    1516                 :            :      * that this ofproto_class does not support BFD, as does a null pointer. */
    1517                 :            :     int (*get_bfd_status)(struct ofport *ofport, struct smap *smap);
    1518                 :            : 
    1519                 :            :     /* Configures spanning tree protocol (STP) on 'ofproto' using the
    1520                 :            :      * settings defined in 's'.
    1521                 :            :      *
    1522                 :            :      * If 's' is nonnull, configures STP according to its members.
    1523                 :            :      *
    1524                 :            :      * If 's' is null, removes any STP configuration from 'ofproto'.
    1525                 :            :      *
    1526                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1527                 :            :      * support STP, as does a null pointer. */
    1528                 :            :     int (*set_stp)(struct ofproto *ofproto,
    1529                 :            :                    const struct ofproto_stp_settings *s);
    1530                 :            : 
    1531                 :            :     /* Retrieves state of spanning tree protocol (STP) on 'ofproto'.
    1532                 :            :      *
    1533                 :            :      * Stores STP state for 'ofproto' in 's'.  If the 'enabled' member
    1534                 :            :      * is false, the other member values are not meaningful.
    1535                 :            :      *
    1536                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1537                 :            :      * support STP, as does a null pointer. */
    1538                 :            :     int (*get_stp_status)(struct ofproto *ofproto,
    1539                 :            :                           struct ofproto_stp_status *s);
    1540                 :            : 
    1541                 :            :     /* Configures spanning tree protocol (STP) on 'ofport' using the
    1542                 :            :      * settings defined in 's'.
    1543                 :            :      *
    1544                 :            :      * If 's' is nonnull, configures STP according to its members.  The
    1545                 :            :      * caller is responsible for assigning STP port numbers (using the
    1546                 :            :      * 'port_num' member in the range of 1 through 255, inclusive) and
    1547                 :            :      * ensuring there are no duplicates.
    1548                 :            :      *
    1549                 :            :      * If 's' is null, removes any STP configuration from 'ofport'.
    1550                 :            :      *
    1551                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1552                 :            :      * support STP, as does a null pointer. */
    1553                 :            :     int (*set_stp_port)(struct ofport *ofport,
    1554                 :            :                         const struct ofproto_port_stp_settings *s);
    1555                 :            : 
    1556                 :            :     /* Retrieves spanning tree protocol (STP) port status of 'ofport'.
    1557                 :            :      *
    1558                 :            :      * Stores STP state for 'ofport' in 's'.  If the 'enabled' member is
    1559                 :            :      * false, the other member values are not meaningful.
    1560                 :            :      *
    1561                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1562                 :            :      * support STP, as does a null pointer. */
    1563                 :            :     int (*get_stp_port_status)(struct ofport *ofport,
    1564                 :            :                                struct ofproto_port_stp_status *s);
    1565                 :            : 
    1566                 :            :     /* Retrieves spanning tree protocol (STP) port statistics of 'ofport'.
    1567                 :            :      *
    1568                 :            :      * Stores STP state for 'ofport' in 's'.  If the 'enabled' member is
    1569                 :            :      * false, the other member values are not meaningful.
    1570                 :            :      *
    1571                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1572                 :            :      * support STP, as does a null pointer. */
    1573                 :            :     int (*get_stp_port_stats)(struct ofport *ofport,
    1574                 :            :                               struct ofproto_port_stp_stats *s);
    1575                 :            : 
    1576                 :            :     /* Configures Rapid Spanning Tree Protocol (RSTP) on 'ofproto' using the
    1577                 :            :      * settings defined in 's'.
    1578                 :            :      *
    1579                 :            :      * If 's' is nonnull, configures RSTP according to its members.
    1580                 :            :      *
    1581                 :            :      * If 's' is null, removes any RSTP configuration from 'ofproto'.
    1582                 :            :      *
    1583                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1584                 :            :      * support RSTP, as does a null pointer. */
    1585                 :            :     void (*set_rstp)(struct ofproto *ofproto,
    1586                 :            :                     const struct ofproto_rstp_settings *s);
    1587                 :            : 
    1588                 :            :     /* Retrieves state of Rapid Spanning Tree Protocol (RSTP) on 'ofproto'.
    1589                 :            :      *
    1590                 :            :      * Stores RSTP state for 'ofproto' in 's'.  If the 'enabled' member
    1591                 :            :      * is false, the other member values are not meaningful.
    1592                 :            :      *
    1593                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1594                 :            :      * support RSTP, as does a null pointer. */
    1595                 :            :     void (*get_rstp_status)(struct ofproto *ofproto,
    1596                 :            :                            struct ofproto_rstp_status *s);
    1597                 :            : 
    1598                 :            :     /* Configures Rapid Spanning Tree Protocol (RSTP) on 'ofport' using the
    1599                 :            :      * settings defined in 's'.
    1600                 :            :      *
    1601                 :            :      * If 's' is nonnull, configures RSTP according to its members.  The
    1602                 :            :      * caller is responsible for assigning RSTP port numbers (using the
    1603                 :            :      * 'port_num' member in the range of 1 through 255, inclusive) and
    1604                 :            :      * ensuring there are no duplicates.
    1605                 :            :      *
    1606                 :            :      * If 's' is null, removes any RSTP configuration from 'ofport'.
    1607                 :            :      *
    1608                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1609                 :            :      * support STP, as does a null pointer. */
    1610                 :            :     void (*set_rstp_port)(struct ofport *ofport,
    1611                 :            :                          const struct ofproto_port_rstp_settings *s);
    1612                 :            : 
    1613                 :            :     /* Retrieves Rapid Spanning Tree Protocol (RSTP) port status of 'ofport'.
    1614                 :            :      *
    1615                 :            :      * Stores RSTP state for 'ofport' in 's'.  If the 'enabled' member is
    1616                 :            :      * false, the other member values are not meaningful.
    1617                 :            :      *
    1618                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1619                 :            :      * support RSTP, as does a null pointer. */
    1620                 :            :     void (*get_rstp_port_status)(struct ofport *ofport,
    1621                 :            :                                 struct ofproto_port_rstp_status *s);
    1622                 :            : 
    1623                 :            :     /* Registers meta-data associated with the 'n_qdscp' Qualities of Service
    1624                 :            :      * 'queues' attached to 'ofport'.  This data is not intended to be
    1625                 :            :      * sufficient to implement QoS.  Instead, providers may use this
    1626                 :            :      * information to implement features which require knowledge of what queues
    1627                 :            :      * exist on a port, and some basic information about them.
    1628                 :            :      *
    1629                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1630                 :            :      * support QoS, as does a null pointer. */
    1631                 :            :     int (*set_queues)(struct ofport *ofport,
    1632                 :            :                       const struct ofproto_port_queue *queues, size_t n_qdscp);
    1633                 :            : 
    1634                 :            :     /* If 's' is nonnull, this function registers a "bundle" associated with
    1635                 :            :      * client data pointer 'aux' in 'ofproto'.  A bundle is the same concept as
    1636                 :            :      * a Port in OVSDB, that is, it consists of one or more "slave" devices
    1637                 :            :      * (Interfaces, in OVSDB) along with VLAN and LACP configuration and, if
    1638                 :            :      * there is more than one slave, a bonding configuration.  If 'aux' is
    1639                 :            :      * already registered then this function updates its configuration to 's'.
    1640                 :            :      * Otherwise, this function registers a new bundle.
    1641                 :            :      *
    1642                 :            :      * If 's' is NULL, this function unregisters the bundle registered on
    1643                 :            :      * 'ofproto' associated with client data pointer 'aux'.  If no such bundle
    1644                 :            :      * has been registered, this has no effect.
    1645                 :            :      *
    1646                 :            :      * This function affects only the behavior of the NXAST_AUTOPATH action and
    1647                 :            :      * output to the OFPP_NORMAL port.  An implementation that does not support
    1648                 :            :      * it at all may set it to NULL or return EOPNOTSUPP.  An implementation
    1649                 :            :      * that supports only a subset of the functionality should implement what
    1650                 :            :      * it can and return 0. */
    1651                 :            :     int (*bundle_set)(struct ofproto *ofproto, void *aux,
    1652                 :            :                       const struct ofproto_bundle_settings *s);
    1653                 :            : 
    1654                 :            :     /* If 'port' is part of any bundle, removes it from that bundle.  If the
    1655                 :            :      * bundle now has no ports, deletes the bundle.  If the bundle now has only
    1656                 :            :      * one port, deconfigures the bundle's bonding configuration. */
    1657                 :            :     void (*bundle_remove)(struct ofport *ofport);
    1658                 :            : 
    1659                 :            :     /* If 's' is nonnull, this function registers a mirror associated with
    1660                 :            :      * client data pointer 'aux' in 'ofproto'.  A mirror is the same concept as
    1661                 :            :      * a Mirror in OVSDB.  If 'aux' is already registered then this function
    1662                 :            :      * updates its configuration to 's'.  Otherwise, this function registers a
    1663                 :            :      * new mirror.
    1664                 :            :      *
    1665                 :            :      * If 's' is NULL, this function unregisters the mirror registered on
    1666                 :            :      * 'ofproto' associated with client data pointer 'aux'.  If no such mirror
    1667                 :            :      * has been registered, this has no effect.
    1668                 :            :      *
    1669                 :            :      * An implementation that does not support mirroring at all may set
    1670                 :            :      * it to NULL or return EOPNOTSUPP.  An implementation that supports
    1671                 :            :      * only a subset of the functionality should implement what it can
    1672                 :            :      * and return 0. */
    1673                 :            :     int (*mirror_set)(struct ofproto *ofproto, void *aux,
    1674                 :            :                       const struct ofproto_mirror_settings *s);
    1675                 :            : 
    1676                 :            :     /* Retrieves statistics from mirror associated with client data
    1677                 :            :      * pointer 'aux' in 'ofproto'.  Stores packet and byte counts in
    1678                 :            :      * 'packets' and 'bytes', respectively.  If a particular counter is
    1679                 :            :      * not supported, the appropriate argument is set to UINT64_MAX.
    1680                 :            :      *
    1681                 :            :      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
    1682                 :            :      * support retrieving mirror statistics. */
    1683                 :            :     int (*mirror_get_stats)(struct ofproto *ofproto, void *aux,
    1684                 :            :                             uint64_t *packets, uint64_t *bytes);
    1685                 :            : 
    1686                 :            :     /* Configures the VLANs whose bits are set to 1 in 'flood_vlans' as VLANs
    1687                 :            :      * on which all packets are flooded, instead of using MAC learning.  If
    1688                 :            :      * 'flood_vlans' is NULL, then MAC learning applies to all VLANs.
    1689                 :            :      *
    1690                 :            :      * This function affects only the behavior of the OFPP_NORMAL action.  An
    1691                 :            :      * implementation that does not support it may set it to NULL or return
    1692                 :            :      * EOPNOTSUPP. */
    1693                 :            :     int (*set_flood_vlans)(struct ofproto *ofproto,
    1694                 :            :                            unsigned long *flood_vlans);
    1695                 :            : 
    1696                 :            :     /* Returns true if 'aux' is a registered bundle that is currently in use as
    1697                 :            :      * the output for a mirror. */
    1698                 :            :     bool (*is_mirror_output_bundle)(const struct ofproto *ofproto, void *aux);
    1699                 :            : 
    1700                 :            :     /* When the configuration option of forward_bpdu changes, this function
    1701                 :            :      * will be invoked. */
    1702                 :            :     void (*forward_bpdu_changed)(struct ofproto *ofproto);
    1703                 :            : 
    1704                 :            :     /* Sets the MAC aging timeout for the OFPP_NORMAL action to 'idle_time', in
    1705                 :            :      * seconds, and the maximum number of MAC table entries to
    1706                 :            :      * 'max_entries'.
    1707                 :            :      *
    1708                 :            :      * An implementation that doesn't support configuring these features may
    1709                 :            :      * set this function to NULL or implement it as a no-op. */
    1710                 :            :     void (*set_mac_table_config)(struct ofproto *ofproto,
    1711                 :            :                                  unsigned int idle_time, size_t max_entries);
    1712                 :            : 
    1713                 :            :     /* Configures multicast snooping on 'ofport' using the settings
    1714                 :            :      * defined in 's'.
    1715                 :            :      *
    1716                 :            :      * If 's' is nonnull, this function updates multicast snooping
    1717                 :            :      * configuration to 's' in 'ofproto'.
    1718                 :            :      *
    1719                 :            :      * If 's' is NULL, this function disables multicast snooping
    1720                 :            :      * on 'ofproto'.
    1721                 :            :      *
    1722                 :            :      * An implementation that does not support multicast snooping may set
    1723                 :            :      * it to NULL or return EOPNOTSUPP. */
    1724                 :            :     int (*set_mcast_snooping)(struct ofproto *ofproto,
    1725                 :            :                               const struct ofproto_mcast_snooping_settings *s);
    1726                 :            : 
    1727                 :            :     /* Configures multicast snooping port's flood setting on 'ofproto'.
    1728                 :            :      *
    1729                 :            :      * If 's' is nonnull, this function updates multicast snooping
    1730                 :            :      * configuration to 's' in 'ofproto'.
    1731                 :            :      *
    1732                 :            :      * If 's' is NULL, this function doesn't change anything.
    1733                 :            :      *
    1734                 :            :      * An implementation that does not support multicast snooping may set
    1735                 :            :      * it to NULL or return EOPNOTSUPP. */
    1736                 :            :     int (*set_mcast_snooping_port)(struct ofproto *ofproto_, void *aux,
    1737                 :            :                           const struct ofproto_mcast_snooping_port_settings *s);
    1738                 :            : 
    1739                 :            : /* ## ------------------------ ## */
    1740                 :            : /* ## OpenFlow meter functions ## */
    1741                 :            : /* ## ------------------------ ## */
    1742                 :            : 
    1743                 :            :     /* These functions should be NULL if an implementation does not support
    1744                 :            :      * them.  They must be all null or all non-null.. */
    1745                 :            : 
    1746                 :            :     /* Initializes 'features' to describe the metering features supported by
    1747                 :            :      * 'ofproto'. */
    1748                 :            :     void (*meter_get_features)(const struct ofproto *ofproto,
    1749                 :            :                                struct ofputil_meter_features *features);
    1750                 :            : 
    1751                 :            :     /* If '*id' is UINT32_MAX, adds a new meter with the given 'config'.  On
    1752                 :            :      * success the function must store a provider meter ID other than
    1753                 :            :      * UINT32_MAX in '*id'.  All further references to the meter will be made
    1754                 :            :      * with the returned provider meter id rather than the OpenFlow meter id.
    1755                 :            :      * The caller does not try to interpret the provider meter id, giving the
    1756                 :            :      * implementation the freedom to either use the OpenFlow meter_id value
    1757                 :            :      * provided in the meter configuration, or any other value suitable for the
    1758                 :            :      * implementation.
    1759                 :            :      *
    1760                 :            :      * If '*id' is a value other than UINT32_MAX, modifies the existing meter
    1761                 :            :      * with that meter provider ID to have configuration 'config', while
    1762                 :            :      * leaving '*id' unchanged.  On failure, the existing meter configuration
    1763                 :            :      * is left intact. */
    1764                 :            :     enum ofperr (*meter_set)(struct ofproto *ofproto, ofproto_meter_id *id,
    1765                 :            :                              const struct ofputil_meter_config *config);
    1766                 :            : 
    1767                 :            :     /* Gets the meter and meter band packet and byte counts for maximum of
    1768                 :            :      * 'stats->n_bands' bands for the meter with provider ID 'id' within
    1769                 :            :      * 'ofproto'.  The caller fills in the other stats values.  The band stats
    1770                 :            :      * are copied to memory at 'stats->bands' provided by the caller.  The
    1771                 :            :      * number of returned band stats is returned in 'stats->n_bands'. */
    1772                 :            :     enum ofperr (*meter_get)(const struct ofproto *ofproto,
    1773                 :            :                              ofproto_meter_id id,
    1774                 :            :                              struct ofputil_meter_stats *stats);
    1775                 :            : 
    1776                 :            :     /* Deletes a meter, making the 'ofproto_meter_id' invalid for any
    1777                 :            :      * further calls. */
    1778                 :            :     void (*meter_del)(struct ofproto *, ofproto_meter_id);
    1779                 :            : 
    1780                 :            : 
    1781                 :            : /* ## -------------------- ## */
    1782                 :            : /* ## OpenFlow 1.1+ groups ## */
    1783                 :            : /* ## -------------------- ## */
    1784                 :            : 
    1785                 :            :     struct ofgroup *(*group_alloc)(void);
    1786                 :            :     enum ofperr (*group_construct)(struct ofgroup *);
    1787                 :            :     void (*group_destruct)(struct ofgroup *);
    1788                 :            :     void (*group_dealloc)(struct ofgroup *);
    1789                 :            : 
    1790                 :            :     void (*group_modify)(struct ofgroup *);
    1791                 :            : 
    1792                 :            :     enum ofperr (*group_get_stats)(const struct ofgroup *,
    1793                 :            :                                    struct ofputil_group_stats *);
    1794                 :            : 
    1795                 :            : /* ## --------------------- ## */
    1796                 :            : /* ## Datapath information  ## */
    1797                 :            : /* ## --------------------- ## */
    1798                 :            :     /* Retrieve the version string of the datapath. The version
    1799                 :            :      * string can be NULL if it can not be determined.
    1800                 :            :      *
    1801                 :            :      * The version retuned is read only. The caller should not
    1802                 :            :      * free it.
    1803                 :            :      *
    1804                 :            :      * This function should be NULL if an implementation does not support it.
    1805                 :            :      */
    1806                 :            :     const char *(*get_datapath_version)(const struct ofproto *);
    1807                 :            : };
    1808                 :            : 
    1809                 :            : extern const struct ofproto_class ofproto_dpif_class;
    1810                 :            : 
    1811                 :            : int ofproto_class_register(const struct ofproto_class *);
    1812                 :            : int ofproto_class_unregister(const struct ofproto_class *);
    1813                 :            : 
    1814                 :            : /* Criteria that flow_mod and other operations use for selecting rules on
    1815                 :            :  * which to operate. */
    1816                 :            : struct rule_criteria {
    1817                 :            :     /* An OpenFlow table or 255 for all tables. */
    1818                 :            :     uint8_t table_id;
    1819                 :            : 
    1820                 :            :     /* OpenFlow matching criteria.  Interpreted different in "loose" way by
    1821                 :            :      * collect_rules_loose() and "strict" way by collect_rules_strict(), as
    1822                 :            :      * defined in the OpenFlow spec. */
    1823                 :            :     struct cls_rule cr;
    1824                 :            :     ovs_version_t version;
    1825                 :            : 
    1826                 :            :     /* Matching criteria for the OpenFlow cookie.  Consider a bit B in a rule's
    1827                 :            :      * cookie and the corresponding bits C in 'cookie' and M in 'cookie_mask'.
    1828                 :            :      * The rule will not be selected if M is 1 and B != C.  */
    1829                 :            :     ovs_be64 cookie;
    1830                 :            :     ovs_be64 cookie_mask;
    1831                 :            : 
    1832                 :            :     /* Selection based on actions within a rule:
    1833                 :            :      *
    1834                 :            :      * If out_port != OFPP_ANY, selects only rules that output to out_port.
    1835                 :            :      * If out_group != OFPG_ALL, select only rules that output to out_group. */
    1836                 :            :     ofp_port_t out_port;
    1837                 :            :     uint32_t out_group;
    1838                 :            : 
    1839                 :            :     /* If true, collects only rules that are modifiable. */
    1840                 :            :     bool include_hidden;
    1841                 :            :     bool include_readonly;
    1842                 :            : };
    1843                 :            : 
    1844                 :            : /* flow_mod with execution context. */
    1845                 :            : struct ofproto_flow_mod {
    1846                 :            :     /* Allocated by 'init' phase, may be freed after 'start' phase, as these
    1847                 :            :      * are not needed for 'revert' nor 'finish'. */
    1848                 :            :     struct rule *temp_rule;
    1849                 :            :     struct rule_criteria criteria;
    1850                 :            :     struct cls_conjunction *conjs;
    1851                 :            :     size_t n_conjs;
    1852                 :            : 
    1853                 :            :     /* Replicate needed fields from ofputil_flow_mod to not need it after the
    1854                 :            :      * flow has been created. */
    1855                 :            :     uint16_t command;
    1856                 :            :     bool modify_cookie;
    1857                 :            :     /* Fields derived from ofputil_flow_mod. */
    1858                 :            :     bool modify_may_add_flow;
    1859                 :            :     enum nx_flow_update_event event;
    1860                 :            : 
    1861                 :            :     /* These are only used during commit execution.
    1862                 :            :      * ofproto_flow_mod_uninit() does NOT clean these up. */
    1863                 :            :     ovs_version_t version;              /* Version in which changes take
    1864                 :            :                                          * effect. */
    1865                 :            :     struct rule_collection old_rules;   /* Affected rules. */
    1866                 :            :     struct rule_collection new_rules;   /* Replacement rules. */
    1867                 :            : };
    1868                 :            : 
    1869                 :            : void ofproto_flow_mod_uninit(struct ofproto_flow_mod *);
    1870                 :            : 
    1871                 :            : /* port_mod with execution context. */
    1872                 :            : struct ofproto_port_mod {
    1873                 :            :     struct ofputil_port_mod pm;
    1874                 :            :     struct ofport *port;                /* Affected port. */
    1875                 :            : };
    1876                 :            : 
    1877                 :            : /* flow_mod with execution context. */
    1878                 :            : struct ofproto_group_mod {
    1879                 :            :     struct ofputil_group_mod gm;
    1880                 :            : 
    1881                 :            :     ovs_version_t version;              /* Version in which changes take
    1882                 :            :                                          * effect. */
    1883                 :            :     struct ofgroup *new_group;          /* New group. */
    1884                 :            :     struct group_collection old_groups; /* Affected groups. */
    1885                 :            : };
    1886                 :            : 
    1887                 :            : enum ofperr ofproto_flow_mod(struct ofproto *, const struct ofputil_flow_mod *)
    1888                 :            :     OVS_EXCLUDED(ofproto_mutex);
    1889                 :            : void ofproto_add_flow(struct ofproto *, const struct match *, int priority,
    1890                 :            :                       const struct ofpact *ofpacts, size_t ofpacts_len)
    1891                 :            :     OVS_EXCLUDED(ofproto_mutex);
    1892                 :            : void ofproto_delete_flow(struct ofproto *, const struct match *, int priority)
    1893                 :            :     OVS_EXCLUDED(ofproto_mutex);
    1894                 :            : void ofproto_flush_flows(struct ofproto *);
    1895                 :            : 
    1896                 :            : enum ofperr ofproto_check_ofpacts(struct ofproto *,
    1897                 :            :                                   const struct ofpact ofpacts[],
    1898                 :            :                                   size_t ofpacts_len);
    1899                 :            : 
    1900                 :            : static inline const struct rule_actions *
    1901                 :    1501663 : rule_get_actions(const struct rule *rule)
    1902                 :            : {
    1903                 :    1501663 :     return rule->actions;
    1904                 :            : }
    1905                 :            : 
    1906                 :            : /* Returns true if 'rule' is an OpenFlow 1.3 "table-miss" rule, false
    1907                 :            :  * otherwise.
    1908                 :            :  *
    1909                 :            :  * ("Table-miss" rules are special because a packet_in generated through one
    1910                 :            :  * uses OFPR_NO_MATCH as its reason, whereas packet_ins generated by any other
    1911                 :            :  * rule use OFPR_ACTION.) */
    1912                 :            : static inline bool
    1913                 :        680 : rule_is_table_miss(const struct rule *rule)
    1914                 :            : {
    1915 [ +  + ][ +  - ]:        680 :     return rule->cr.priority == 0 && cls_rule_is_catchall(&rule->cr);
    1916                 :            : }
    1917                 :            : 
    1918                 :            : /* Returns true if 'rule' should be hidden from the controller.
    1919                 :            :  *
    1920                 :            :  * Rules with priority higher than UINT16_MAX are set up by ofproto itself
    1921                 :            :  * (e.g. by in-band control) and are intentionally hidden from the
    1922                 :            :  * controller. */
    1923                 :            : static inline bool
    1924                 :      90014 : rule_is_hidden(const struct rule *rule)
    1925                 :            : {
    1926                 :      90014 :     return rule->cr.priority > UINT16_MAX;
    1927                 :            : }
    1928                 :            : 
    1929                 :            : static inline struct rule *
    1930                 :    1338967 : rule_from_cls_rule(const struct cls_rule *cls_rule)
    1931                 :            : {
    1932         [ +  + ]:    1338967 :     return cls_rule ? CONTAINER_OF(cls_rule, struct rule, cr) : NULL;
    1933                 :            : }
    1934                 :            : 
    1935                 :            : #endif /* ofproto/ofproto-provider.h */

Generated by: LCOV version 1.12