summaryrefslogtreecommitdiff
path: root/lib/learning-switch.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-07-15 16:20:37 -0700
committerBen Pfaff <blp@nicira.com>2010-07-16 12:04:11 -0700
commit52f4c6fa0d9170ccde68b71910be7fc825ba447d (patch)
tree9dc84d4d3af87cb5d436fa585dc7bf432cb8fdc1 /lib/learning-switch.c
parent5a003f6067d6a1f06841e5d1567b942af98b5fcc (diff)
downloadopenvswitch-52f4c6fa0d9170ccde68b71910be7fc825ba447d.tar.gz
learning-switch: Refactor wildcards calculation.
There's no need to calculate the wildcards to use for each flow, since it is a constant across every flow. In my opinion this also makes process_packet_in() a little easier to understand, since it deletes a few lines of code from a relatively complicated function.
Diffstat (limited to 'lib/learning-switch.c')
-rw-r--r--lib/learning-switch.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/learning-switch.c b/lib/learning-switch.c
index 413a70fd6..c837fd0f5 100644
--- a/lib/learning-switch.c
+++ b/lib/learning-switch.c
@@ -58,7 +58,7 @@ struct lswitch {
uint32_t capabilities;
time_t last_features_request;
struct mac_learning *ml; /* NULL to act as hub instead of switch. */
- bool exact_flows; /* Use exact-match flows? */
+ uint32_t wildcards; /* Wildcards to apply to flows. */
bool action_normal; /* Use OFPP_NORMAL? */
/* Number of outgoing queued packets on the rconn. */
@@ -120,7 +120,16 @@ lswitch_create(struct rconn *rconn, bool learn_macs,
sw->last_features_request = time_now() - 1;
sw->ml = learn_macs ? mac_learning_create() : NULL;
sw->action_normal = action_normal;
- sw->exact_flows = exact_flows;
+ if (exact_flows) {
+ /* Exact match. */
+ sw->wildcards = 0;
+ } else {
+ /* We cannot wildcard all fields.
+ * We need in_port to detect moves.
+ * We need both SA and DA to do learning. */
+ sw->wildcards = (OFPFW_DL_TYPE | OFPFW_NW_SRC_MASK | OFPFW_NW_DST_MASK
+ | OFPFW_NW_PROTO | OFPFW_TP_SRC | OFPFW_TP_DST);
+ }
sw->queued = rconn_packet_counter_create();
sw->next_query = LLONG_MIN;
sw->last_query = LLONG_MIN;
@@ -433,19 +442,6 @@ process_packet_in(struct lswitch *sw, struct rconn *rconn, void *opi_)
} else if (sw->max_idle >= 0 && (!sw->ml || out_port != OFPP_FLOOD)) {
struct ofpbuf *buffer;
struct ofp_flow_mod *ofm;
- uint32_t wildcards;
-
- /* Check if we need to wildcard the flows. */
- if (!sw->exact_flows) {
- /* We can not wildcard all fields.
- * We need in_port to detect moves.
- * We need both SA and DA to do learning. */
- wildcards = (OFPFW_DL_TYPE | OFPFW_NW_SRC_MASK | OFPFW_NW_DST_MASK
- | OFPFW_NW_PROTO | OFPFW_TP_SRC | OFPFW_TP_DST);
- } else {
- /* Exact match */
- wildcards = 0;
- }
/* Check if we need to use "NORMAL" action. */
if (sw->action_normal && out_port != OFPP_FLOOD) {
@@ -457,7 +453,7 @@ process_packet_in(struct lswitch *sw, struct rconn *rconn, void *opi_)
buffer = make_add_simple_flow(&flow, ntohl(opi->buffer_id),
out_port, sw->max_idle);
ofm = buffer->data;
- ofm->match.wildcards = htonl(wildcards);
+ ofm->match.wildcards = htonl(sw->wildcards);
queue_tx(sw, rconn, buffer);
/* If the switch didn't buffer the packet, we need to send a copy. */