ofproto: Change ofproto_add_flow(), ofproto_delete_flow() to take cls_rule.
[openvswitch] / lib / classifier.c
1 /*
2  * Copyright (c) 2009, 2010 Nicira Networks.
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 #include <config.h>
18 #include "classifier.h"
19 #include <assert.h>
20 #include <errno.h>
21 #include <netinet/in.h>
22 #include "dynamic-string.h"
23 #include "flow.h"
24 #include "hash.h"
25 #include "packets.h"
26
27 static struct cls_table *find_table(const struct classifier *,
28                                     const struct flow_wildcards *);
29 static struct cls_table *insert_table(struct classifier *,
30                                       const struct flow_wildcards *);
31
32 static struct cls_table *classifier_first_table(const struct classifier *);
33 static struct cls_table *classifier_next_table(const struct classifier *,
34                                                const struct cls_table *);
35 static void destroy_table(struct classifier *, struct cls_table *);
36
37 static bool should_include(const struct cls_table *, int include);
38
39 static struct cls_rule *find_match(const struct cls_table *,
40                                    const struct flow *);
41 static struct cls_rule *find_equal(struct cls_table *, const struct flow *,
42                                    uint32_t hash);
43 static struct cls_rule *insert_rule(struct cls_table *, struct cls_rule *);
44
45 static bool flow_equal_except(const struct flow *, const struct flow *,
46                                 const struct flow_wildcards *);
47 static void zero_wildcards(struct flow *, const struct flow_wildcards *);
48
49 /* Iterates RULE over HEAD and all of the cls_rules on HEAD->list. */
50 #define FOR_EACH_RULE_IN_LIST(RULE, HEAD)                               \
51     for ((RULE) = (HEAD); (RULE) != NULL; (RULE) = next_rule_in_list(RULE))
52 #define FOR_EACH_RULE_IN_LIST_SAFE(RULE, NEXT, HEAD)                    \
53     for ((RULE) = (HEAD);                                               \
54          (RULE) != NULL && ((NEXT) = next_rule_in_list(RULE), true);    \
55          (RULE) = (NEXT))
56
57 static struct cls_rule *next_rule_in_list(struct cls_rule *);
58
59 static struct cls_table *
60 cls_table_from_hmap_node(const struct hmap_node *node)
61 {
62     return node ? CONTAINER_OF(node, struct cls_table, hmap_node) : NULL;
63 }
64
65 static struct cls_rule *
66 cls_rule_from_hmap_node(const struct hmap_node *node)
67 {
68     return node ? CONTAINER_OF(node, struct cls_rule, hmap_node) : NULL;
69 }
70
71 /* Returns the cls_table within 'cls' that has no wildcards, or NULL if there
72  * is none.  */
73 struct cls_table *
74 classifier_exact_table(const struct classifier *cls)
75 {
76     struct flow_wildcards exact_wc;
77     flow_wildcards_init_exact(&exact_wc);
78     return find_table(cls, &exact_wc);
79 }
80
81 /* Returns the first rule in 'table', or a null pointer if 'table' is NULL. */
82 struct cls_rule *
83 cls_table_first_rule(const struct cls_table *table)
84 {
85     return table ? cls_rule_from_hmap_node(hmap_first(&table->rules)) : NULL;
86 }
87
88 /* Returns the next rule in 'table' following 'rule', or a null pointer if
89  * 'rule' is the last rule in 'table'. */
90 struct cls_rule *
91 cls_table_next_rule(const struct cls_table *table, const struct cls_rule *rule)
92 {
93     struct cls_rule *next
94         = CONTAINER_OF(rule->list.next, struct cls_rule, hmap_node);
95
96     return (next->priority < rule->priority
97             ? next
98             : cls_rule_from_hmap_node(hmap_next(&table->rules,
99                                                 &next->hmap_node)));
100 }
101
102 static void
103 cls_rule_init__(struct cls_rule *rule,
104                 const struct flow *flow, uint32_t wildcards)
105 {
106     rule->flow = *flow;
107     flow_wildcards_init(&rule->wc, wildcards);
108     cls_rule_zero_wildcarded_fields(rule);
109 }
110
111 /* Converts the flow in 'flow' into a cls_rule in 'rule', with the given
112  * 'wildcards' and 'priority'.*/
113 void
114 cls_rule_from_flow(const struct flow *flow, uint32_t wildcards,
115                    unsigned int priority, struct cls_rule *rule)
116 {
117     cls_rule_init__(rule, flow, wildcards);
118     rule->priority = priority;
119 }
120
121 /* Converts the ofp_match in 'match' (with format 'flow_format', one of NXFF_*)
122  * into a cls_rule in 'rule', with the given 'priority'.  'cookie' is used
123  * when 'flow_format' is NXFF_TUN_ID_FROM_COOKIE. */
124 void
125 cls_rule_from_match(const struct ofp_match *match, unsigned int priority,
126                     int flow_format, uint64_t cookie,
127                     struct cls_rule *rule)
128 {
129     uint32_t wildcards;
130     struct flow flow;
131
132     flow_from_match(match, flow_format, cookie, &flow, &wildcards);
133     cls_rule_init__(rule, &flow, wildcards);
134     rule->priority = rule->wc.wildcards ? priority : UINT16_MAX;
135 }
136
137 /* Initializes 'rule' as a "catch-all" rule that matches every packet, with
138  * priority 'priority'. */
139 void
140 cls_rule_init_catchall(struct cls_rule *rule, unsigned int priority)
141 {
142     memset(&rule->flow, 0, sizeof rule->flow);
143     flow_wildcards_init(&rule->wc, OVSFW_ALL);
144     rule->priority = priority;
145 }
146
147 /* For each bit or field wildcarded in 'rule', sets the corresponding bit or
148  * field in 'flow' to all-0-bits.  It is important to maintain this invariant
149  * in a clr_rule that might be inserted into a classifier.
150  *
151  * It is never necessary to call this function directly for a cls_rule that is
152  * initialized or modified only by cls_rule_*() functions.  It is useful to
153  * restore the invariant in a cls_rule whose 'wc' member is modified by hand.
154  */
155 void
156 cls_rule_zero_wildcarded_fields(struct cls_rule *rule)
157 {
158     zero_wildcards(&rule->flow, &rule->wc);
159 }
160
161 /* Converts 'rule' to a string and returns the string.  The caller must free
162  * the string (with free()). */
163 char *
164 cls_rule_to_string(const struct cls_rule *rule)
165 {
166     struct ds s = DS_EMPTY_INITIALIZER;
167     ds_put_format(&s, "wildcards=%x priority=%u ",
168                   rule->wc.wildcards, rule->priority);
169     flow_format(&s, &rule->flow);
170     return ds_cstr(&s);
171 }
172
173 /* Prints cls_rule 'rule', for debugging.
174  *
175  * (The output could be improved and expanded, but this was good enough to
176  * debug the classifier.) */
177 void
178 cls_rule_print(const struct cls_rule *rule)
179 {
180     printf("wildcards=%x priority=%u ", rule->wc.wildcards, rule->priority);
181     flow_print(stdout, &rule->flow);
182     putc('\n', stdout);
183 }
184 \f
185 /* Initializes 'cls' as a classifier that initially contains no classification
186  * rules. */
187 void
188 classifier_init(struct classifier *cls)
189 {
190     cls->n_rules = 0;
191     hmap_init(&cls->tables);
192 }
193
194 /* Destroys 'cls'.  Rules within 'cls', if any, are not freed; this is the
195  * caller's responsibility. */
196 void
197 classifier_destroy(struct classifier *cls)
198 {
199     if (cls) {
200         struct cls_table *table, *next_table;
201
202         HMAP_FOR_EACH_SAFE (table, next_table, hmap_node, &cls->tables) {
203             hmap_destroy(&table->rules);
204             hmap_remove(&cls->tables, &table->hmap_node);
205             free(table);
206         }
207         hmap_destroy(&cls->tables);
208     }
209 }
210
211 /* Returns true if 'cls' contains no classification rules, false otherwise. */
212 bool
213 classifier_is_empty(const struct classifier *cls)
214 {
215     return cls->n_rules == 0;
216 }
217
218 /* Returns the number of rules in 'classifier'. */
219 int
220 classifier_count(const struct classifier *cls)
221 {
222     return cls->n_rules;
223 }
224
225 /* Returns the number of rules in 'classifier' that have no wildcards. */
226 int
227 classifier_count_exact(const struct classifier *cls)
228 {
229     struct cls_table *exact_table = classifier_exact_table(cls);
230     return exact_table ? exact_table->n_table_rules : 0;
231 }
232
233 /* Inserts 'rule' into 'cls'.  Until 'rule' is removed from 'cls', the caller
234  * must not modify or free it.
235  *
236  * If 'cls' already contains an identical rule (including wildcards, values of
237  * fixed fields, and priority), replaces the old rule by 'rule' and returns the
238  * rule that was replaced.  The caller takes ownership of the returned rule and
239  * is thus responsible for freeing it, etc., as necessary.
240  *
241  * Returns NULL if 'cls' does not contain a rule with an identical key, after
242  * inserting the new rule.  In this case, no rules are displaced by the new
243  * rule, even rules that cannot have any effect because the new rule matches a
244  * superset of their flows and has higher priority. */
245 struct cls_rule *
246 classifier_insert(struct classifier *cls, struct cls_rule *rule)
247 {
248     struct cls_rule *old_rule;
249     struct cls_table *table;
250
251     table = find_table(cls, &rule->wc);
252     if (!table) {
253         table = insert_table(cls, &rule->wc);
254     }
255
256     old_rule = insert_rule(table, rule);
257     if (!old_rule) {
258         table->n_table_rules++;
259         cls->n_rules++;
260     }
261     return old_rule;
262 }
263
264 /* Removes 'rule' from 'cls'.  It is the caller's responsibility to free
265  * 'rule', if this is desirable. */
266 void
267 classifier_remove(struct classifier *cls, struct cls_rule *rule)
268 {
269     struct cls_rule *head;
270     struct cls_table *table;
271
272     table = find_table(cls, &rule->wc);
273     head = find_equal(table, &rule->flow, rule->hmap_node.hash);
274     if (head != rule) {
275         list_remove(&rule->list);
276     } else if (list_is_empty(&rule->list)) {
277         hmap_remove(&table->rules, &rule->hmap_node);
278     } else {
279         struct cls_rule *next = CONTAINER_OF(rule->list.next,
280                                              struct cls_rule, list);
281
282         list_remove(&rule->list);
283         hmap_replace(&table->rules, &rule->hmap_node, &next->hmap_node);
284     }
285
286     if (--table->n_table_rules == 0 && !table->n_refs) {
287         destroy_table(cls, table);
288     }
289
290     cls->n_rules--;
291 }
292
293 /* Finds and returns the highest-priority rule in 'cls' that matches 'flow'.
294  * Returns a null pointer if no rules in 'cls' match 'flow'.  If multiple rules
295  * of equal priority match 'flow', returns one arbitrarily.
296  *
297  * 'include' is a combination of CLS_INC_* values that specify tables to
298  * include in the search. */
299 struct cls_rule *
300 classifier_lookup(const struct classifier *cls, const struct flow *flow,
301                   int include)
302 {
303     struct cls_table *table;
304     struct cls_rule *best;
305
306     best = NULL;
307     HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
308         if (should_include(table, include)) {
309             struct cls_rule *rule = find_match(table, flow);
310             if (rule && (!best || rule->priority > best->priority)) {
311                 best = rule;
312             }
313         }
314     }
315     return best;
316 }
317
318 /* Finds and returns a rule in 'cls' with exactly the same priority and
319  * matching criteria as 'target'.  Returns a null pointer if 'cls' doesn't
320  * contain an exact match.
321  *
322  * Priority is ignored for exact-match rules (because OpenFlow 1.0 always
323  * treats exact-match rules as highest priority). */
324 struct cls_rule *
325 classifier_find_rule_exactly(const struct classifier *cls,
326                              const struct cls_rule *target)
327 {
328     struct cls_rule *head, *rule;
329     struct cls_table *table;
330
331     table = find_table(cls, &target->wc);
332     if (!table) {
333         return NULL;
334     }
335
336     head = find_equal(table, &target->flow, flow_hash(&target->flow, 0));
337     if (!target->wc.wildcards) {
338         return head;
339     }
340     FOR_EACH_RULE_IN_LIST (rule, head) {
341         if (target->priority >= rule->priority) {
342             return target->priority == rule->priority ? rule : NULL;
343         }
344     }
345     return NULL;
346 }
347
348 /* Checks if 'target' would overlap any other rule in 'cls'.  Two rules are
349  * considered to overlap if both rules have the same priority and a packet
350  * could match both. */
351 bool
352 classifier_rule_overlaps(const struct classifier *cls,
353                          const struct cls_rule *target)
354 {
355     struct cls_table *table;
356
357     HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
358         struct flow_wildcards wc;
359         struct cls_rule *head;
360
361         flow_wildcards_combine(&wc, &target->wc, &table->wc);
362         HMAP_FOR_EACH (head, hmap_node, &table->rules) {
363             struct cls_rule *rule;
364
365             FOR_EACH_RULE_IN_LIST (rule, head) {
366                 if (rule->priority == target->priority
367                     && flow_equal_except(&target->flow, &rule->flow, &wc)) {
368                     return true;
369                 }
370             }
371         }
372     }
373
374     return false;
375 }
376
377 /* Searches 'cls' for rules that exactly match 'target' or are more specific
378  * than 'target'.  That is, a given 'rule' matches 'target' if, for every
379  * field:
380  *
381  *   - 'target' and 'rule' specify the same (non-wildcarded) value for the
382  *     field, or
383  *
384  *   - 'target' wildcards the field,
385  *
386  * but not if:
387  *
388  *   - 'target' and 'rule' specify different values for the field, or
389  *
390  *   - 'target' specifies a value for the field but 'rule' wildcards it.
391  *
392  * Equivalently, the truth table for whether a field matches is:
393  *
394  *                                     rule
395  *
396  *                             wildcard    exact
397  *                            +---------+---------+
398  *                   t   wild |   yes   |   yes   |
399  *                   a   card |         |         |
400  *                   r        +---------+---------+
401  *                   g  exact |    no   |if values|
402  *                   e        |         |are equal|
403  *                   t        +---------+---------+
404  *
405  * This is the matching rule used by OpenFlow 1.0 non-strict OFPT_FLOW_MOD
406  * commands and by OpenFlow 1.0 aggregate and flow stats.
407  *
408  * Ignores target->priority.
409  *
410  * 'callback' is allowed to delete the rule that is passed as its argument, but
411  * it must not delete (or move) any other rules in 'cls' that have the same
412  * wildcards as the argument rule. */
413 void
414 classifier_for_each_match(const struct classifier *cls_,
415                           const struct cls_rule *target,
416                           int include, cls_cb_func *callback, void *aux)
417 {
418     struct classifier *cls = (struct classifier *) cls_;
419     struct cls_table *table, *next_table;
420
421     for (table = classifier_first_table(cls); table; table = next_table) {
422         if (should_include(table, include)
423             && !flow_wildcards_has_extra(&table->wc, &target->wc)) {
424             /* We have eliminated the "no" case in the truth table above.  Two
425              * of the three remaining cases are trivial.  We only need to check
426              * the fourth case, where both 'rule' and 'target' require an exact
427              * match. */
428             struct cls_rule *head, *next_head;
429
430             table->n_refs++;
431             HMAP_FOR_EACH_SAFE (head, next_head, hmap_node, &table->rules) {
432                 if (flow_equal_except(&head->flow, &target->flow,
433                                       &target->wc)) {
434                     struct cls_rule *rule, *next_rule;
435
436                     FOR_EACH_RULE_IN_LIST_SAFE (rule, next_rule, head) {
437                         callback(rule, aux);
438                     }
439                 }
440             }
441             next_table = classifier_next_table(cls, table);
442             if (!--table->n_refs && !table->n_table_rules) {
443                 destroy_table(cls, table);
444             }
445         } else {
446             next_table = classifier_next_table(cls, table);
447         }
448     }
449 }
450
451 /* 'callback' is allowed to delete the rule that is passed as its argument, but
452  * it must not delete (or move) any other rules in 'cls' that have the same
453  * wildcards as the argument rule.
454  *
455  * If 'include' is CLS_INC_EXACT then CLASSIFIER_FOR_EACH_EXACT_RULE is
456  * probably easier to use. */
457 void
458 classifier_for_each(const struct classifier *cls_, int include,
459                     cls_cb_func *callback, void *aux)
460 {
461     struct classifier *cls = (struct classifier *) cls_;
462     struct cls_table *table, *next_table;
463
464     for (table = classifier_first_table(cls); table; table = next_table) {
465         if (should_include(table, include)) {
466             struct cls_rule *head, *next_head;
467
468             table->n_refs++;
469             HMAP_FOR_EACH_SAFE (head, next_head, hmap_node, &table->rules) {
470                 struct cls_rule *rule, *next_rule;
471
472                 FOR_EACH_RULE_IN_LIST_SAFE (rule, next_rule, head) {
473                     callback(rule, aux);
474                 }
475             }
476             next_table = classifier_next_table(cls, table);
477             if (!--table->n_refs && !table->n_table_rules) {
478                 destroy_table(cls, table);
479             }
480         } else {
481             next_table = classifier_next_table(cls, table);
482         }
483     }
484 }
485 \f
486 static struct cls_table *
487 find_table(const struct classifier *cls, const struct flow_wildcards *wc)
488 {
489     struct cls_table *table;
490
491     HMAP_FOR_EACH_IN_BUCKET (table, hmap_node, flow_wildcards_hash(wc),
492                              &cls->tables) {
493         if (flow_wildcards_equal(wc, &table->wc)) {
494             return table;
495         }
496     }
497     return NULL;
498 }
499
500 static struct cls_table *
501 insert_table(struct classifier *cls, const struct flow_wildcards *wc)
502 {
503     struct cls_table *table;
504
505     table = xzalloc(sizeof *table);
506     hmap_init(&table->rules);
507     table->wc = *wc;
508     hmap_insert(&cls->tables, &table->hmap_node, flow_wildcards_hash(wc));
509
510     return table;
511 }
512
513 static struct cls_table *
514 classifier_first_table(const struct classifier *cls)
515 {
516     return cls_table_from_hmap_node(hmap_first(&cls->tables));
517 }
518
519 static struct cls_table *
520 classifier_next_table(const struct classifier *cls,
521                       const struct cls_table *table)
522 {
523     return cls_table_from_hmap_node(hmap_next(&cls->tables,
524                                               &table->hmap_node));
525 }
526
527 static void
528 destroy_table(struct classifier *cls, struct cls_table *table)
529 {
530     hmap_remove(&cls->tables, &table->hmap_node);
531     hmap_destroy(&table->rules);
532     free(table);
533 }
534
535 /* Returns true if 'table' should be included by an operation with the
536  * specified 'include' (a combination of CLS_INC_*). */
537 static bool
538 should_include(const struct cls_table *table, int include)
539 {
540     return include & (table->wc.wildcards ? CLS_INC_WILD : CLS_INC_EXACT);
541 }
542
543 static struct cls_rule *
544 find_match(const struct cls_table *table, const struct flow *flow)
545 {
546     struct cls_rule *rule;
547     struct flow f;
548
549     f = *flow;
550     zero_wildcards(&f, &table->wc);
551     HMAP_FOR_EACH_WITH_HASH (rule, hmap_node, flow_hash(&f, 0),
552                              &table->rules) {
553         if (flow_equal(&f, &rule->flow)) {
554             return rule;
555         }
556     }
557     return NULL;
558 }
559
560 static struct cls_rule *
561 find_equal(struct cls_table *table, const struct flow *flow, uint32_t hash)
562 {
563     struct cls_rule *head;
564
565     HMAP_FOR_EACH_WITH_HASH (head, hmap_node, hash, &table->rules) {
566         if (flow_equal(&head->flow, flow)) {
567             return head;
568         }
569     }
570     return NULL;
571 }
572
573 static struct cls_rule *
574 insert_rule(struct cls_table *table, struct cls_rule *new)
575 {
576     struct cls_rule *head;
577
578     new->hmap_node.hash = flow_hash(&new->flow, 0);
579
580     head = find_equal(table, &new->flow, new->hmap_node.hash);
581     if (!head) {
582         hmap_insert(&table->rules, &new->hmap_node, new->hmap_node.hash);
583         list_init(&new->list);
584         return NULL;
585     } else {
586         /* Scan the list for the insertion point that will keep the list in
587          * order of decreasing priority. */
588         struct cls_rule *rule;
589         FOR_EACH_RULE_IN_LIST (rule, head) {
590             if (new->priority >= rule->priority) {
591                 if (rule == head) {
592                     /* 'new' is the new highest-priority flow in the list. */
593                     hmap_replace(&table->rules,
594                                  &rule->hmap_node, &new->hmap_node);
595                 }
596
597                 if (new->priority == rule->priority) {
598                     list_replace(&new->list, &rule->list);
599                     return rule;
600                 } else {
601                     list_insert(&rule->list, &new->list);
602                     return NULL;
603                 }
604             }
605         }
606
607         /* Insert 'new' at the end of the list. */
608         list_push_back(&head->list, &new->list);
609         return NULL;
610     }
611 }
612
613 static struct cls_rule *
614 next_rule_in_list(struct cls_rule *rule)
615 {
616     struct cls_rule *next = OBJECT_CONTAINING(rule->list.next, next, list);
617     return next->priority < rule->priority ? next : NULL;
618 }
619
620 static bool
621 flow_equal_except(const struct flow *a, const struct flow *b,
622                   const struct flow_wildcards *wildcards)
623 {
624     const uint32_t wc = wildcards->wildcards;
625
626     BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 37);
627
628     return ((wc & NXFW_TUN_ID || a->tun_id == b->tun_id)
629             && !((a->nw_src ^ b->nw_src) & wildcards->nw_src_mask)
630             && !((a->nw_dst ^ b->nw_dst) & wildcards->nw_dst_mask)
631             && (wc & OFPFW_IN_PORT || a->in_port == b->in_port)
632             && (wc & OFPFW_DL_VLAN || a->dl_vlan == b->dl_vlan)
633             && (wc & OFPFW_DL_TYPE || a->dl_type == b->dl_type)
634             && (wc & OFPFW_TP_SRC || a->tp_src == b->tp_src)
635             && (wc & OFPFW_TP_DST || a->tp_dst == b->tp_dst)
636             && (wc & OFPFW_DL_SRC || eth_addr_equals(a->dl_src, b->dl_src))
637             && (wc & OFPFW_DL_DST || eth_addr_equals(a->dl_dst, b->dl_dst))
638             && (wc & OFPFW_NW_PROTO || a->nw_proto == b->nw_proto)
639             && (wc & OFPFW_DL_VLAN_PCP || a->dl_vlan_pcp == b->dl_vlan_pcp)
640             && (wc & OFPFW_NW_TOS || a->nw_tos == b->nw_tos));
641 }
642
643 static void
644 zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards)
645 {
646     const uint32_t wc = wildcards->wildcards;
647
648     BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 37);
649
650     if (wc & NXFW_TUN_ID) {
651         flow->tun_id = 0;
652     }
653     flow->nw_src &= wildcards->nw_src_mask;
654     flow->nw_dst &= wildcards->nw_dst_mask;
655     if (wc & OFPFW_IN_PORT) {
656         flow->in_port = 0;
657     }
658     if (wc & OFPFW_DL_VLAN) {
659         flow->dl_vlan = 0;
660     }
661     if (wc & OFPFW_DL_TYPE) {
662         flow->dl_type = 0;
663     }
664     if (wc & OFPFW_TP_SRC) {
665         flow->tp_src = 0;
666     }
667     if (wc & OFPFW_TP_DST) {
668         flow->tp_dst = 0;
669     }
670     if (wc & OFPFW_DL_SRC) {
671         memset(flow->dl_src, 0, sizeof flow->dl_src);
672     }
673     if (wc & OFPFW_DL_DST) {
674         memset(flow->dl_dst, 0, sizeof flow->dl_dst);
675     }
676     if (wc & OFPFW_NW_PROTO) {
677         flow->nw_proto = 0;
678     }
679     if (wc & OFPFW_DL_VLAN_PCP) {
680         flow->dl_vlan_pcp = 0;
681     }
682     if (wc & OFPFW_NW_TOS) {
683         flow->nw_tos = 0;
684     }
685 }