- actions = a.actions;
- n_actions = a.n_actions;
- } else {
- actions = rule->odp_actions;
- n_actions = rule->n_odp_actions;
- }
-
- /* Execute the ODP actions. */
- flow_extract_stats(flow, packet, &stats);
- if (execute_odp_actions(ofproto, flow->in_port,
- actions, n_actions, packet)) {
- update_stats(ofproto, rule, &stats);
- rule->used = time_msec();
- netflow_flow_update_time(ofproto->netflow, &rule->nf_flow, rule->used);
- }
-}
-
-/* Inserts 'rule' into 'p''s flow table.
- *
- * If 'packet' is nonnull, takes ownership of 'packet', executes 'rule''s
- * actions on it and credits the statistics for sending the packet to 'rule'.
- * 'packet' must have at least sizeof(struct ofp_packet_in) bytes of
- * headroom. */
-static void
-rule_insert(struct ofproto *p, struct rule *rule, struct ofpbuf *packet,
- uint16_t in_port)
-{
- struct rule *displaced_rule;
-
- /* Insert the rule in the classifier. */
- displaced_rule = rule_from_cls_rule(classifier_insert(&p->cls, &rule->cr));
- if (!rule->cr.wc.wildcards) {
- rule_make_actions(p, rule, packet);
- }
-
- /* Send the packet and credit it to the rule. */
- if (packet) {
- struct flow flow;
- flow_extract(packet, 0, in_port, &flow);
- rule_execute(p, rule, packet, &flow);
- }
-
- /* Install the rule in the datapath only after sending the packet, to
- * avoid packet reordering. */
- if (rule->cr.wc.wildcards) {
- COVERAGE_INC(ofproto_add_wc_flow);
- p->need_revalidate = true;
- } else {
- rule_install(p, rule, displaced_rule);
- }
-
- /* Free the rule that was displaced, if any. */
- if (displaced_rule) {
- rule_destroy(p, displaced_rule);
- }
-}
-
-static struct rule *
-rule_create_subrule(struct ofproto *ofproto, struct rule *rule,
- const struct flow *flow)
-{
- struct rule *subrule = rule_create(ofproto, rule, NULL, 0,
- rule->idle_timeout, rule->hard_timeout,
- 0, false);
- COVERAGE_INC(ofproto_subrule_create);
- cls_rule_init_exact(flow, (rule->cr.priority <= UINT16_MAX ? UINT16_MAX
- : rule->cr.priority),
- &subrule->cr);
-
- if (classifier_insert(&ofproto->cls, &subrule->cr)) {
- /* Can't happen, */
- NOT_REACHED();
- }
-
- return subrule;
-}
-
-/* Remove 'rule' from 'ofproto' and free up the associated memory:
- *
- * - If 'rule' was installed in the datapath, uninstalls it and updates
- * 'rule''s statistics (or its super-rule's statistics, if it is a
- * subrule), via rule_uninstall().
- *
- * - Removes 'rule' from the classifier.
- *
- * - If 'rule' is a super-rule that has subrules, revalidates (and possibly
- * uninstalls and destroys) its subrules, via rule_destroy().
- */
-static void
-rule_remove(struct ofproto *ofproto, struct rule *rule)
-{
- if (rule->cr.wc.wildcards) {
- COVERAGE_INC(ofproto_del_wc_flow);
- ofproto->need_revalidate = true;
- } else {
- rule_uninstall(ofproto, rule);
- }
- classifier_remove(&ofproto->cls, &rule->cr);
- rule_destroy(ofproto, rule);
-}