ofproto: Make OFPFC_ADD internally modify a rule instead of swapping.
[sliver-openvswitch.git] / ofproto / ofproto-provider.h
index ef4d588..43273ec 100644 (file)
@@ -65,8 +65,8 @@ struct ofproto {
     struct shash port_by_name;
     unsigned long *ofp_port_ids;/* Bitmap of used OpenFlow port numbers. */
     struct simap ofp_requests;  /* OpenFlow port number requests. */
-    ofp_port_t alloc_port_no;   /* Last allocated OpenFlow port number. */
-    ofp_port_t max_ports;       /* Max possible OpenFlow port num, plus one. */
+    uint16_t alloc_port_no;     /* Last allocated OpenFlow port number. */
+    uint16_t max_ports;         /* Max possible OpenFlow port num, plus one. */
 
     /* Flow tables. */
     struct oftable *tables;
@@ -114,7 +114,7 @@ struct ofproto {
 };
 
 void ofproto_init_tables(struct ofproto *, int n_tables);
-void ofproto_init_max_ports(struct ofproto *, ofp_port_t max_ports);
+void ofproto_init_max_ports(struct ofproto *, uint16_t max_ports);
 
 struct ofproto *ofproto_lookup(const char *name);
 struct ofport *ofproto_get_port(const struct ofproto *, ofp_port_t ofp_port);
@@ -281,11 +281,13 @@ void ofproto_rule_expire(struct rule *rule, uint8_t reason)
     OVS_RELEASES(rule->evict);
 void ofproto_rule_destroy(struct ofproto *, struct classifier *cls,
                           struct rule *) OVS_REQ_WRLOCK(cls->rwlock);
+void ofproto_rule_reduce_timeouts(struct rule *rule, uint16_t idle_timeout,
+                                  uint16_t hard_timeout)
+    OVS_EXCLUDED(rule->ofproto->expirable_mutex, rule->timeout_mutex);
 
 bool ofproto_rule_has_out_port(const struct rule *, ofp_port_t out_port);
 
 void ofoperation_complete(struct ofoperation *, enum ofperr);
-struct rule *ofoperation_get_victim(struct ofoperation *);
 
 bool ofoperation_has_out_port(const struct ofoperation *, ofp_port_t out_port);
 
@@ -887,7 +889,7 @@ struct ofproto_class {
      * An ofproto implementation reports the success or failure of an
      * asynchronous operation on a rule using the rule's 'pending' member,
      * which points to a opaque "struct ofoperation" that represents the
-     * ongoing opreation.  When the operation completes, the ofproto
+     * ongoing operation.  When the operation completes, the ofproto
      * implementation calls ofoperation_complete(), passing the ofoperation and
      * an error indication.
      *
@@ -904,22 +906,22 @@ struct ofproto_class {
      * The ofproto base code updates the flow table optimistically, assuming
      * that the operation will probably succeed:
      *
-     *   - ofproto adds or replaces the rule in the flow table before calling
+     *   - ofproto adds the rule in the flow table before calling
      *     ->rule_construct().
      *
-     *   - ofproto updates the rule's actions before calling
-     *     ->rule_modify_actions().
+     *   - ofproto updates the rule's actions and other properties before
+     *     calling ->rule_modify_actions().
      *
      *   - ofproto removes the rule before calling ->rule_destruct().
      *
      * With one exception, when an asynchronous operation completes with an
      * error, ofoperation_complete() backs out the already applied changes:
      *
-     *   - If adding or replacing a rule in the flow table fails, ofproto
-     *     removes the new rule or restores the original rule.
+     *   - If adding a rule in the flow table fails, ofproto removes the new
+     *     rule.
      *
-     *   - If modifying a rule's actions fails, ofproto restores the original
-     *     actions.
+     *   - If modifying a rule fails, ofproto restores the original actions
+     *     (and other properties).
      *
      *   - Removing a rule is not allowed to fail.  It must always succeed.
      *
@@ -935,17 +937,9 @@ struct ofproto_class {
      * Construction
      * ============
      *
-     * When ->rule_construct() is called, the caller has already inserted
-     * 'rule' into 'rule->ofproto''s flow table numbered 'rule->table_id'.
-     * There are two cases:
-     *
-     *   - 'rule' is a new rule in its flow table.  In this case,
-     *     ofoperation_get_victim(rule) returns NULL.
-     *
-     *   - 'rule' is replacing an existing rule in its flow table that had the
-     *     same matching criteria and priority.  In this case,
-     *     ofoperation_get_victim(rule) returns the rule being replaced (the
-     *     "victim" rule).
+     * When ->rule_construct() is called, 'rule' is a new rule in its flow
+     * table.  The caller has already inserted 'rule' into 'rule->ofproto''s
+     * flow table numbered 'rule->table_id'.
      *
      * ->rule_construct() should set the following in motion:
      *
@@ -956,16 +950,10 @@ struct ofproto_class {
      *
      *   - Validate that the datapath can correctly implement 'rule->ofpacts'.
      *
-     *   - If the rule is valid, update the datapath flow table, adding the new
-     *     rule or replacing the existing one.
-     *
-     *   - If 'rule' is replacing an existing rule, uninitialize any derived
-     *     state for the victim rule, as in step 5 in the "Life Cycle"
-     *     described above.
+     *   - If the rule is valid, add the new rule to the datapath flow table.
      *
      * (On failure, the ofproto code will roll back the insertion from the flow
-     * table, either removing 'rule' or replacing it by the victim rule if
-     * there is one.)
+     * table by removing 'rule'.)
      *
      * ->rule_construct() must act in one of the following ways:
      *
@@ -1041,6 +1029,10 @@ struct ofproto_class {
      *
      *   - Update the datapath flow table with the new actions.
      *
+     *   - Only if 'reset_counters' is true, reset any packet or byte counters
+     *     associated with the rule to zero, so that rule_get_stats() will not
+     *     longer count those packets or bytes.
+     *
      * If the operation synchronously completes, ->rule_modify_actions() may
      * call ofoperation_complete() before it returns.  Otherwise, ->run()
      * should call ofoperation_complete() later, after the operation does
@@ -1051,7 +1043,7 @@ struct ofproto_class {
      *
      * ->rule_modify_actions() should not modify any base members of struct
      * rule. */
-    void (*rule_modify_actions)(struct rule *rule);
+    void (*rule_modify_actions)(struct rule *rule, bool reset_counters);
 
     /* Changes the OpenFlow IP fragment handling policy to 'frag_handling',
      * which takes one of the following values, with the corresponding