X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ofproto%2Fofproto-dpif.c;h=5669cd18469fc192f9cf19fa39330d8ecee3b3a9;hb=1a7c0cd710e19db3ff85606dbfd5fdad964a1eea;hp=cb01516010ae5162c871291c50e89e3b87231db7;hpb=adcf00ba35a0ce9cf2f1a84bce44559eab1f83a1;p=sliver-openvswitch.git diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index cb0151601..5669cd184 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -362,6 +362,18 @@ ofproto_dpif_flow_mod(struct ofproto_dpif *ofproto, ofproto_flow_mod(&ofproto->up, fm); } +/* Resets the modified time for 'rule' or an equivalent rule. If 'rule' is not + * in the classifier, but an equivalent rule is, unref 'rule' and ref the new + * rule. Otherwise if 'rule' is no longer installed in the classifier, + * reinstall it. + * + * Returns the rule whose modified time has been reset. */ +struct rule_dpif * +ofproto_dpif_refresh_rule(struct rule_dpif *rule) +{ + return rule_dpif_cast(ofproto_refresh_rule(&rule->up)); +} + /* Appends 'pin' to the queue of "packet ins" to be sent to the controller. * Takes ownership of 'pin' and pin->packet. */ void @@ -951,10 +963,11 @@ check_recirc(struct dpif_backer *backer) flow.dp_hash = 1; ofpbuf_use_stack(&key, &keybuf, sizeof keybuf); - odp_flow_key_from_flow(&key, &flow, 0); + odp_flow_key_from_flow(&key, &flow, NULL, 0); error = dpif_flow_put(backer->dpif, DPIF_FP_CREATE | DPIF_FP_MODIFY, - key.data, key.size, NULL, 0, NULL, 0, NULL); + ofpbuf_data(&key), ofpbuf_size(&key), NULL, 0, NULL, + 0, NULL); if (error && error != EEXIST) { if (error != EINVAL) { VLOG_WARN("%s: Reciculation flow probe failed (%s)", @@ -963,7 +976,8 @@ check_recirc(struct dpif_backer *backer) goto done; } - error = dpif_flow_del(backer->dpif, key.data, key.size, NULL); + error = dpif_flow_del(backer->dpif, ofpbuf_data(&key), ofpbuf_size(&key), + NULL); if (error) { VLOG_WARN("%s: failed to delete recirculation feature probe flow", dpif_name(backer->dpif)); @@ -1082,7 +1096,7 @@ check_max_mpls_depth(struct dpif_backer *backer) flow_set_mpls_bos(&flow, n, 1); ofpbuf_use_stack(&key, &keybuf, sizeof keybuf); - odp_flow_key_from_flow(&key, &flow, 0); + odp_flow_key_from_flow(&key, &flow, NULL, 0); error = dpif_flow_put(backer->dpif, DPIF_FP_CREATE | DPIF_FP_MODIFY, ofpbuf_data(&key), ofpbuf_size(&key), NULL, 0, NULL, 0, NULL); @@ -3169,16 +3183,49 @@ rule_dpif_get_actions(const struct rule_dpif *rule) return rule_get_actions(&rule->up); } -static uint8_t -rule_dpif_lookup__ (struct ofproto_dpif *ofproto, const struct flow *flow, - struct flow_wildcards *wc, struct rule_dpif **rule) +/* Lookup 'flow' in table 0 of 'ofproto''s classifier. + * If 'wc' is non-null, sets the fields that were relevant as part of + * the lookup. Returns the table_id where a match or miss occurred. + * + * The return value will be zero unless there was a miss and + * OFPTC11_TABLE_MISS_CONTINUE is in effect for the sequence of tables + * where misses occur. + * + * The rule is returned in '*rule', which is valid at least until the next + * RCU quiescent period. If the '*rule' needs to stay around longer, + * a non-zero 'take_ref' must be passed in to cause a reference to be taken + * on it before this returns. */ +uint8_t +rule_dpif_lookup(struct ofproto_dpif *ofproto, struct flow *flow, + struct flow_wildcards *wc, struct rule_dpif **rule, + bool take_ref) { enum rule_dpif_lookup_verdict verdict; enum ofputil_port_config config = 0; - uint8_t table_id = TBL_INTERNAL; + uint8_t table_id; + + if (ofproto_dpif_get_enable_recirc(ofproto)) { + /* Always exactly match recirc_id since datapath supports + * recirculation. */ + if (wc) { + wc->masks.recirc_id = UINT32_MAX; + } + + /* Start looking up from internal table for post recirculation flows + * or packets. We can also simply send all, including normal flows + * or packets to the internal table. They will not match any post + * recirculation rules except the 'catch all' rule that resubmit + * them to table 0. + * + * As an optimization, we send normal flows and packets to table 0 + * directly, saving one table lookup. */ + table_id = flow->recirc_id ? TBL_INTERNAL : 0; + } else { + table_id = 0; + } verdict = rule_dpif_lookup_from_table(ofproto, flow, wc, true, - &table_id, rule); + &table_id, rule, take_ref); switch (verdict) { case RULE_DPIF_LOOKUP_VERDICT_MATCH: @@ -3207,30 +3254,17 @@ rule_dpif_lookup__ (struct ofproto_dpif *ofproto, const struct flow *flow, } choose_miss_rule(config, ofproto->miss_rule, - ofproto->no_packet_in_rule, rule); + ofproto->no_packet_in_rule, rule, take_ref); return table_id; } -/* Lookup 'flow' in table 0 of 'ofproto''s classifier. - * If 'wc' is non-null, sets the fields that were relevant as part of - * the lookup. Returns the table_id where a match or miss occurred. - * - * The return value will be zero unless there was a miss and - * O!-TC_TABLE_MISS_CONTINUE is in effect for the sequence of tables - * where misses occur. */ -uint8_t -rule_dpif_lookup(struct ofproto_dpif *ofproto, struct flow *flow, - struct flow_wildcards *wc, struct rule_dpif **rule) -{ - /* Set metadata to the value of recirc_id to speed up internal - * rule lookup. */ - flow->metadata = htonll(flow->recirc_id); - return rule_dpif_lookup__(ofproto, flow, wc, rule); -} - +/* The returned rule is valid at least until the next RCU quiescent period. + * If the '*rule' needs to stay around longer, a non-zero 'take_ref' must be + * passed in to cause a reference to be taken on it before this returns. */ static struct rule_dpif * rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, uint8_t table_id, - const struct flow *flow, struct flow_wildcards *wc) + const struct flow *flow, struct flow_wildcards *wc, + bool take_ref) { struct classifier *cls = &ofproto->up.tables[table_id].cls; const struct cls_rule *cls_rule; @@ -3264,7 +3298,9 @@ rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, uint8_t table_id, } rule = rule_dpif_cast(rule_from_cls_rule(cls_rule)); - rule_dpif_ref(rule); + if (take_ref) { + rule_dpif_ref(rule); + } fat_rwlock_unlock(&cls->rwlock); return rule; @@ -3291,6 +3327,7 @@ rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, uint8_t table_id, * - RULE_OFPTC_TABLE_MISS_CONTROLLER if no rule was found and either: * + 'honor_table_miss' is false * + a table miss configuration specified that the packet should be + * sent to the controller in this case. * * - RULE_DPIF_LOOKUP_VERDICT_DROP if no rule was found, 'honor_table_miss' * is true and a table miss configuration specified that the packet @@ -3298,13 +3335,19 @@ rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, uint8_t table_id, * * - RULE_DPIF_LOOKUP_VERDICT_DEFAULT if no rule was found, * 'honor_table_miss' is true and a table miss configuration has - * not been specified in this case. */ + * not been specified in this case. + * + * The rule is returned in '*rule', which is valid at least until the next + * RCU quiescent period. If the '*rule' needs to stay around longer, + * a non-zero 'take_ref' must be passed in to cause a reference to be taken + * on it before this returns. */ enum rule_dpif_lookup_verdict rule_dpif_lookup_from_table(struct ofproto_dpif *ofproto, const struct flow *flow, struct flow_wildcards *wc, bool honor_table_miss, - uint8_t *table_id, struct rule_dpif **rule) + uint8_t *table_id, struct rule_dpif **rule, + bool take_ref) { uint8_t next_id; @@ -3313,7 +3356,8 @@ rule_dpif_lookup_from_table(struct ofproto_dpif *ofproto, next_id++, next_id += (next_id == TBL_INTERNAL)) { *table_id = next_id; - *rule = rule_dpif_lookup_in_table(ofproto, *table_id, flow, wc); + *rule = rule_dpif_lookup_in_table(ofproto, *table_id, flow, wc, + take_ref); if (*rule) { return RULE_DPIF_LOOKUP_VERDICT_MATCH; } else if (!honor_table_miss) { @@ -3340,13 +3384,21 @@ rule_dpif_lookup_from_table(struct ofproto_dpif *ofproto, /* Given a port configuration (specified as zero if there's no port), chooses * which of 'miss_rule' and 'no_packet_in_rule' should be used in case of a - * flow table miss. */ + * flow table miss. + * + * The rule is returned in '*rule', which is valid at least until the next + * RCU quiescent period. If the '*rule' needs to stay around longer, + * a reference must be taken on it (rule_dpif_ref()). + */ void choose_miss_rule(enum ofputil_port_config config, struct rule_dpif *miss_rule, - struct rule_dpif *no_packet_in_rule, struct rule_dpif **rule) + struct rule_dpif *no_packet_in_rule, struct rule_dpif **rule, + bool take_ref) { *rule = config & OFPUTIL_PC_NO_PACKET_IN ? no_packet_in_rule : miss_rule; - rule_dpif_ref(*rule); + if (take_ref) { + rule_dpif_ref(*rule); + } } void @@ -3778,6 +3830,7 @@ ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED, struct trace_ctx { struct xlate_out xout; struct xlate_in xin; + const struct flow *key; struct flow flow; struct flow_wildcards wc; struct ds *result; @@ -3818,7 +3871,9 @@ trace_format_flow(struct ds *result, int level, const char *title, { ds_put_char_multiple(result, '\t', level); ds_put_format(result, "%s: ", title); - if (flow_equal(&trace->xin.flow, &trace->flow)) { + /* Do not report unchanged flows for resubmits. */ + if ((level > 0 && flow_equal(&trace->xin.flow, &trace->flow)) + || (level == 0 && flow_equal(&trace->xin.flow, trace->key))) { ds_put_cstr(result, "unchanged"); } else { flow_format(result, &trace->xin.flow); @@ -3863,7 +3918,7 @@ trace_format_megaflow(struct ds *result, int level, const char *title, ds_put_char_multiple(result, '\t', level); ds_put_format(result, "%s: ", title); flow_wildcards_or(&trace->wc, &trace->xout.wc, &trace->wc); - match_init(&match, &trace->flow, &trace->wc); + match_init(&match, trace->key, &trace->wc); match_format(&match, result, OFP_DEFAULT_PRIORITY); ds_put_char(result, '\n'); } @@ -4169,7 +4224,7 @@ ofproto_trace(struct ofproto_dpif *ofproto, struct flow *flow, if (ofpacts) { rule = NULL; } else { - rule_dpif_lookup(ofproto, flow, &trace.wc, &rule); + rule_dpif_lookup(ofproto, flow, &trace.wc, &rule, false); trace_format_rule(ds, 0, rule); if (rule == ofproto->miss_rule) { @@ -4185,7 +4240,8 @@ ofproto_trace(struct ofproto_dpif *ofproto, struct flow *flow, if (rule || ofpacts) { trace.result = ds; - trace.flow = *flow; + trace.key = flow; /* Original flow key, used for megaflow. */ + trace.flow = *flow; /* May be modified by actions. */ xlate_in_init(&trace.xin, ofproto, flow, rule, ntohs(flow->tcp_flags), packet); if (ofpacts) { @@ -4224,8 +4280,6 @@ ofproto_trace(struct ofproto_dpif *ofproto, struct flow *flow, xlate_out_uninit(&trace.xout); } - - rule_dpif_unref(rule); } /* Store the current ofprotos in 'ofproto_shash'. Returns a sorted list @@ -4778,8 +4832,8 @@ ofproto_dpif_add_internal_flow(struct ofproto_dpif *ofproto, fm.buffer_id = 0; fm.out_port = 0; fm.flags = OFPUTIL_FF_HIDDEN_FIELDS | OFPUTIL_FF_NO_READONLY; - fm.ofpacts = ofpacts->data; - fm.ofpacts_len = ofpacts->size; + fm.ofpacts = ofpbuf_data(ofpacts); + fm.ofpacts_len = ofpbuf_size(ofpacts); error = ofproto_flow_mod(&ofproto->up, &fm); if (error) { @@ -4790,9 +4844,8 @@ ofproto_dpif_add_internal_flow(struct ofproto_dpif *ofproto, } rule = rule_dpif_lookup_in_table(ofproto, TBL_INTERNAL, &match->flow, - &match->wc); + &match->wc, false); if (rule) { - rule_dpif_unref(rule); *rulep = &rule->up; } else { OVS_NOT_REACHED();