Add reminder comment to lib/learning-switch.c.
[sliver-openvswitch.git] / lib / learning-switch.c
1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2  * Junior University
3  *
4  * We are making the OpenFlow specification and associated documentation
5  * (Software) available for public use and benefit with the expectation
6  * that others will use, modify and enhance the Software and contribute
7  * those enhancements back to the community. However, since we would
8  * like to make the Software available for broadest use, with as few
9  * restrictions as possible permission is hereby granted, free of
10  * charge, to any person obtaining a copy of this Software to deal in
11  * the Software under the copyrights without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  *
29  * The name and trademarks of copyright holder(s) may NOT be used in
30  * advertising or publicity pertaining to the Software or any
31  * derivatives without specific, written prior permission.
32  */
33
34 #include <config.h>
35 #include "learning-switch.h"
36
37 #include <errno.h>
38 #include <inttypes.h>
39 #include <netinet/in.h>
40 #include <stdlib.h>
41 #include <time.h>
42
43 #include "flow.h"
44 #include "mac-learning.h"
45 #include "ofpbuf.h"
46 #include "ofp-print.h"
47 #include "openflow/openflow.h"
48 #include "poll-loop.h"
49 #include "queue.h"
50 #include "rconn.h"
51 #include "stp.h"
52 #include "timeval.h"
53 #include "vconn.h"
54 #include "xtoxll.h"
55
56 #define THIS_MODULE VLM_learning_switch
57 #include "vlog.h"
58
59 enum port_state {
60     P_DISABLED = 1 << 0,
61     P_LISTENING = 1 << 1,
62     P_LEARNING = 1 << 2,
63     P_FORWARDING = 1 << 3,
64     P_BLOCKING = 1 << 4
65 };
66
67 struct lswitch {
68     /* If nonnegative, the switch sets up flows that expire after the given
69      * number of seconds (or never expire, if the value is OFP_FLOW_PERMANENT).
70      * Otherwise, the switch processes every packet. */
71     int max_idle;
72
73     unsigned long long int datapath_id;
74     uint32_t capabilities;
75     time_t last_features_request;
76     struct mac_learning *ml;    /* NULL to act as hub instead of switch. */
77
78     /* Number of outgoing queued packets on the rconn. */
79     int n_queued;
80
81     /* Spanning tree protocol implementation.
82      *
83      * We implement STP states by, whenever a port's STP state changes,
84      * querying all the flows on the switch and then deleting any of them that
85      * are inappropriate for a port's STP state. */
86     long long int next_query;   /* Next time at which to query all flows. */
87     long long int last_query;   /* Last time we sent a query. */
88     long long int last_reply;   /* Last time we received a query reply. */
89     unsigned int port_states[STP_MAX_PORTS];
90     uint32_t query_xid;         /* XID used for query. */
91     int n_flows, n_no_recv, n_no_send;
92 };
93
94 /* The log messages here could actually be useful in debugging, so keep the
95  * rate limit relatively high. */
96 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300);
97
98 static void queue_tx(struct lswitch *, struct rconn *, struct ofpbuf *);
99 static void send_features_request(struct lswitch *, struct rconn *);
100 static void schedule_query(struct lswitch *, long long int delay);
101 static bool may_learn(const struct lswitch *, uint16_t port_no);
102 static bool may_recv(const struct lswitch *, uint16_t port_no,
103                      bool any_actions);
104 static bool may_send(const struct lswitch *, uint16_t port_no);
105
106 typedef void packet_handler_func(struct lswitch *, struct rconn *, void *);
107 static packet_handler_func process_switch_features;
108 static packet_handler_func process_packet_in;
109 static packet_handler_func process_echo_request;
110 static packet_handler_func process_port_status;
111 static packet_handler_func process_phy_port;
112 static packet_handler_func process_stats_reply;
113
114 /* Creates and returns a new learning switch.
115  *
116  * If 'learn_macs' is true, the new switch will learn the ports on which MAC
117  * addresses appear.  Otherwise, the new switch will flood all packets.
118  *
119  * If 'max_idle' is nonnegative, the new switch will set up flows that expire
120  * after the given number of seconds (or never expire, if 'max_idle' is
121  * OFP_FLOW_PERMANENT).  Otherwise, the new switch will process every packet.
122  *
123  * 'rconn' is used to send out an OpenFlow features request. */
124 struct lswitch *
125 lswitch_create(struct rconn *rconn, bool learn_macs, int max_idle)
126 {
127     struct lswitch *sw;
128     size_t i;
129
130     sw = xcalloc(1, sizeof *sw);
131     sw->max_idle = max_idle;
132     sw->datapath_id = 0;
133     sw->last_features_request = time_now() - 1;
134     sw->ml = learn_macs ? mac_learning_create() : NULL;
135     sw->next_query = LLONG_MIN;
136     sw->last_query = LLONG_MIN;
137     sw->last_reply = LLONG_MIN;
138     for (i = 0; i < STP_MAX_PORTS; i++) {
139         sw->port_states[i] = P_DISABLED;
140     }
141     send_features_request(sw, rconn);
142     return sw;
143 }
144
145 /* Destroys 'sw'. */
146 void
147 lswitch_destroy(struct lswitch *sw)
148 {
149     if (sw) {
150         mac_learning_destroy(sw->ml);
151         free(sw);
152     }
153 }
154
155 /* Takes care of necessary 'sw' activity, except for receiving packets (which
156  * the caller must do). */
157 void
158 lswitch_run(struct lswitch *sw, struct rconn *rconn)
159 {
160     long long int now = time_msec();
161
162     /* If we're waiting for more replies, keeping waiting for up to 10 s. */
163     if (sw->last_reply != LLONG_MIN) {
164         if (now - sw->last_reply > 10000) {
165             VLOG_ERR_RL(&rl, "%012llx: No more flow stat replies last 10 s",
166                         sw->datapath_id);
167             sw->last_reply = LLONG_MIN;
168             sw->last_query = LLONG_MIN;
169             schedule_query(sw, 0);
170         } else {
171             return;
172         }
173     }
174
175     /* If we're waiting for any reply at all, keep waiting for up to 10 s. */
176     if (sw->last_query != LLONG_MIN) {
177         if (now - sw->last_query > 10000) {
178             VLOG_ERR_RL(&rl, "%012llx: No flow stat replies in last 10 s",
179                         sw->datapath_id);
180             sw->last_query = LLONG_MIN;
181             schedule_query(sw, 0);
182         } else {
183             return;
184         }
185     }
186
187     /* If it's time to send another query, do so. */
188     if (sw->next_query != LLONG_MIN && now >= sw->next_query) {
189         sw->next_query = LLONG_MIN;
190         if (!rconn_is_connected(rconn)) {
191             schedule_query(sw, 1000);
192         } else {
193             struct ofp_stats_request *osr;
194             struct ofp_flow_stats_request *ofsr;
195             struct ofpbuf *b;
196             int error;
197
198             VLOG_DBG("%012llx: Sending flow stats request to implement STP",
199                      sw->datapath_id);
200
201             sw->last_query = now;
202             sw->query_xid = random_uint32();
203             sw->n_flows = 0;
204             sw->n_no_recv = 0;
205             sw->n_no_send = 0;
206             osr = make_openflow_xid(sizeof *osr + sizeof *ofsr,
207                                     OFPT_STATS_REQUEST, sw->query_xid, &b);
208             osr->type = htons(OFPST_FLOW);
209             osr->flags = htons(0);
210             ofsr = (struct ofp_flow_stats_request *) osr->body;
211             ofsr->match.wildcards = htonl(OFPFW_ALL);
212             ofsr->table_id = 0xff;
213
214             error = rconn_send(rconn, b, NULL);
215             if (error) {
216                 VLOG_WARN_RL(&rl, "%012llx: sending flow stats request "
217                              "failed: %s", sw->datapath_id, strerror(error));
218                 ofpbuf_delete(b);
219                 schedule_query(sw, 1000);
220             }
221         }
222     }
223 }
224
225 static void
226 wait_timeout(long long int started)
227 {
228     long long int now = time_msec();
229     long long int timeout = 10000 - (now - started);
230     if (timeout <= 0) {
231         poll_immediate_wake();
232     } else {
233         poll_timer_wait(timeout);
234     }
235 }
236
237 void
238 lswitch_wait(struct lswitch *sw)
239 {
240     if (sw->last_reply != LLONG_MIN) {
241         wait_timeout(sw->last_reply);
242     } else if (sw->last_query != LLONG_MIN) {
243         wait_timeout(sw->last_query);
244     }
245 }
246
247 /* Processes 'msg', which should be an OpenFlow received on 'rconn', according
248  * to the learning switch state in 'sw'.  The most likely result of processing
249  * is that flow-setup and packet-out OpenFlow messages will be sent out on
250  * 'rconn'.  */
251 void
252 lswitch_process_packet(struct lswitch *sw, struct rconn *rconn,
253                        const struct ofpbuf *msg)
254 {
255     struct processor {
256         uint8_t type;
257         size_t min_size;
258         packet_handler_func *handler;
259     };
260     static const struct processor processors[] = {
261         {
262             OFPT_ECHO_REQUEST,
263             sizeof(struct ofp_header),
264             process_echo_request
265         },
266         {
267             OFPT_FEATURES_REPLY,
268             sizeof(struct ofp_switch_features),
269             process_switch_features
270         },
271         {
272             OFPT_PACKET_IN,
273             offsetof(struct ofp_packet_in, data),
274             process_packet_in
275         },
276         {
277             OFPT_PORT_STATUS,
278             sizeof(struct ofp_port_status),
279             process_port_status
280         },
281         {
282             OFPT_STATS_REPLY,
283             offsetof(struct ofp_stats_reply, body),
284             process_stats_reply
285         },
286         {
287             OFPT_FLOW_EXPIRED,
288             sizeof(struct ofp_flow_expired),
289             NULL
290         },
291     };
292     const size_t n_processors = ARRAY_SIZE(processors);
293     const struct processor *p;
294     struct ofp_header *oh;
295
296     oh = msg->data;
297     if (sw->datapath_id == 0
298         && oh->type != OFPT_ECHO_REQUEST
299         && oh->type != OFPT_FEATURES_REPLY) {
300         send_features_request(sw, rconn);
301         return;
302     }
303
304     for (p = processors; p < &processors[n_processors]; p++) {
305         if (oh->type == p->type) {
306             if (msg->size < p->min_size) {
307                 VLOG_WARN_RL(&rl, "%012llx: %s: too short (%zu bytes) for "
308                              "type %"PRIu8" (min %zu)", sw->datapath_id,
309                              rconn_get_name(rconn), msg->size, oh->type,
310                              p->min_size);
311                 return;
312             }
313             if (p->handler) {
314                 (p->handler)(sw, rconn, msg->data);
315             }
316             return;
317         }
318     }
319     if (VLOG_IS_DBG_ENABLED()) {
320         char *p = ofp_to_string(msg->data, msg->size, 2);
321         VLOG_DBG_RL(&rl, "%012llx: OpenFlow packet ignored: %s",
322                     sw->datapath_id, p);
323         free(p);
324     }
325 }
326 \f
327 static void
328 send_features_request(struct lswitch *sw, struct rconn *rconn)
329 {
330     time_t now = time_now();
331     if (now >= sw->last_features_request + 1) {
332         struct ofpbuf *b;
333         struct ofp_switch_config *osc;
334
335         /* Send OFPT_FEATURES_REQUEST. */
336         make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &b);
337         queue_tx(sw, rconn, b);
338
339         /* Send OFPT_SET_CONFIG. */
340         osc = make_openflow(sizeof *osc, OFPT_SET_CONFIG, &b);
341         osc->flags = htons(OFPC_SEND_FLOW_EXP);
342         osc->miss_send_len = htons(OFP_DEFAULT_MISS_SEND_LEN);
343         queue_tx(sw, rconn, b);
344
345         sw->last_features_request = now;
346     }
347 }
348
349 static void
350 queue_tx(struct lswitch *sw, struct rconn *rconn, struct ofpbuf *b)
351 {
352     int retval = rconn_send_with_limit(rconn, b, &sw->n_queued, 10);
353     if (retval && retval != ENOTCONN) {
354         if (retval == EAGAIN) {
355             VLOG_WARN_RL(&rl, "%012llx: %s: tx queue overflow",
356                          sw->datapath_id, rconn_get_name(rconn));
357         } else {
358             VLOG_WARN_RL(&rl, "%012llx: %s: send: %s",
359                          sw->datapath_id, rconn_get_name(rconn),
360                          strerror(retval));
361         }
362     }
363 }
364
365 static void
366 schedule_query(struct lswitch *sw, long long int delay)
367 {
368     long long int now = time_msec();
369     if (sw->next_query == LLONG_MIN || sw->next_query > now + delay) {
370         sw->next_query = now + delay;
371     }
372 }
373
374 static void
375 process_switch_features(struct lswitch *sw, struct rconn *rconn, void *osf_)
376 {
377     struct ofp_switch_features *osf = osf_;
378     size_t n_ports = ((ntohs(osf->header.length)
379                        - offsetof(struct ofp_switch_features, ports))
380                       / sizeof *osf->ports);
381     size_t i;
382
383     sw->datapath_id = ntohll(osf->datapath_id);
384     sw->capabilities = ntohl(osf->capabilities);
385     for (i = 0; i < n_ports; i++) {
386         process_phy_port(sw, rconn, &osf->ports[i]);
387     }
388     if (sw->capabilities & OFPC_STP) {
389         schedule_query(sw, 1000);
390     }
391 }
392
393 static void
394 process_packet_in(struct lswitch *sw, struct rconn *rconn, void *opi_)
395 {
396     struct ofp_packet_in *opi = opi_;
397     uint16_t in_port = ntohs(opi->in_port);
398     uint16_t out_port = OFPP_FLOOD;
399
400     size_t pkt_ofs, pkt_len;
401     struct ofpbuf pkt;
402     struct flow flow;
403
404     /* Extract flow data from 'opi' into 'flow'. */
405     pkt_ofs = offsetof(struct ofp_packet_in, data);
406     pkt_len = ntohs(opi->header.length) - pkt_ofs;
407     pkt.data = opi->data;
408     pkt.size = pkt_len;
409     flow_extract(&pkt, in_port, &flow);
410
411     if (may_learn(sw, in_port) && sw->ml) {
412         if (mac_learning_learn(sw->ml, flow.dl_src, in_port)) {
413             VLOG_DBG_RL(&rl, "%012llx: learned that "ETH_ADDR_FMT" is on "
414                         "port %"PRIu16, sw->datapath_id,
415                         ETH_ADDR_ARGS(flow.dl_src), in_port);
416         }
417     }
418
419     if (!may_recv(sw, in_port, false)) {
420         /* STP prevents receiving anything on this port. */
421         goto drop_it;
422     }
423
424     if (sw->ml) {
425         uint16_t learned_port = mac_learning_lookup(sw->ml, flow.dl_dst);
426         if (may_send(sw, learned_port)) {
427             out_port = learned_port;
428         }
429     }
430
431     if (in_port == out_port) {
432         /* Don't send out packets on their input ports. */
433         goto drop_it;
434     } else if (sw->max_idle >= 0 && (!sw->ml || out_port != OFPP_FLOOD)) {
435         /* The output port is known, or we always flood everything, so add a
436          * new flow. */
437         queue_tx(sw, rconn, make_add_simple_flow(&flow, ntohl(opi->buffer_id),
438                                                  out_port, sw->max_idle));
439
440         /* If the switch didn't buffer the packet, we need to send a copy. */
441         if (ntohl(opi->buffer_id) == UINT32_MAX) {
442             queue_tx(sw, rconn,
443                      make_unbuffered_packet_out(&pkt, in_port, out_port));
444         }
445     } else {
446         /* We don't know that MAC, or we don't set up flows.  Send along the
447          * packet without setting up a flow. */
448         struct ofpbuf *b;
449         if (ntohl(opi->buffer_id) == UINT32_MAX) {
450             b = make_unbuffered_packet_out(&pkt, in_port, out_port);
451         } else {
452             b = make_buffered_packet_out(ntohl(opi->buffer_id),
453                                          in_port, out_port);
454         }
455         queue_tx(sw, rconn, b);
456     }
457     return;
458
459 drop_it:
460     if (sw->max_idle >= 0) {
461         /* Set up a flow to drop packets. */
462         queue_tx(sw, rconn, make_add_flow(&flow, ntohl(opi->buffer_id),
463                                           sw->max_idle, 0));
464     } else {
465         /* Just drop the packet, since we don't set up flows at all.
466          * XXX we should send a packet_out with no actions if buffer_id !=
467          * UINT32_MAX, to avoid clogging the kernel buffers. */
468     }
469     return;
470 }
471
472 static void
473 process_echo_request(struct lswitch *sw, struct rconn *rconn, void *rq_)
474 {
475     struct ofp_header *rq = rq_;
476     queue_tx(sw, rconn, make_echo_reply(rq));
477 }
478
479 static void
480 process_port_status(struct lswitch *sw, struct rconn *rconn, void *ops_)
481 {
482     struct ofp_port_status *ops = ops_;
483     process_phy_port(sw, rconn, &ops->desc);
484 }
485
486 static void
487 process_phy_port(struct lswitch *sw, struct rconn *rconn, void *opp_)
488 {
489     const struct ofp_phy_port *opp = opp_;
490     uint16_t port_no = ntohs(opp->port_no);
491     if (sw->capabilities & OFPC_STP && port_no < STP_MAX_PORTS) {
492         uint32_t config = ntohl(opp->config);
493         uint32_t state = ntohl(opp->state);
494         unsigned int *port_state = &sw->port_states[port_no];
495         unsigned int new_port_state;
496
497         if (!(config & (OFPPC_NO_STP | OFPPC_PORT_DOWN))
498             && !(state & OFPPS_LINK_DOWN))
499         {
500             switch (state & OFPPS_STP_MASK) {
501             case OFPPS_STP_LISTEN:
502                 new_port_state = P_LISTENING;
503                 break;
504             case OFPPS_STP_LEARN:
505                 new_port_state = P_LEARNING;
506                 break;
507             case OFPPS_STP_FORWARD:
508                 new_port_state = P_FORWARDING;
509                 break;
510             case OFPPS_STP_BLOCK:
511                 new_port_state = P_BLOCKING;
512                 break;
513             default:
514                 new_port_state = P_DISABLED;
515                 break;
516             }
517         } else {
518             new_port_state = P_FORWARDING;
519         }
520         if (*port_state != new_port_state) {
521             *port_state = new_port_state;
522             schedule_query(sw, 1000);
523         }
524     }
525 }
526
527 static unsigned int
528 get_port_state(const struct lswitch *sw, uint16_t port_no)
529 {
530     return (port_no >= STP_MAX_PORTS || !(sw->capabilities & OFPC_STP)
531             ? P_FORWARDING
532             : sw->port_states[port_no]);
533 }
534
535 static bool
536 may_learn(const struct lswitch *sw, uint16_t port_no)
537 {
538     return get_port_state(sw, port_no) & (P_LEARNING | P_FORWARDING);
539 }
540
541 static bool
542 may_recv(const struct lswitch *sw, uint16_t port_no, bool any_actions)
543 {
544     unsigned int state = get_port_state(sw, port_no);
545     return !(any_actions
546              ? state & (P_DISABLED | P_LISTENING | P_BLOCKING)
547              : state & (P_DISABLED | P_LISTENING | P_BLOCKING | P_LEARNING));
548 }
549
550 static bool
551 may_send(const struct lswitch *sw, uint16_t port_no)
552 {
553     return get_port_state(sw, port_no) & P_FORWARDING;
554 }
555
556 static void
557 process_flow_stats(struct lswitch *sw, struct rconn *rconn,
558                    const struct ofp_flow_stats *ofs)
559 {
560     const char *end = (char *) ofs + ntohs(ofs->length);
561     bool delete = false;
562
563     /* Decide to delete the flow if it matches on an STP-disabled physical
564      * port.  But don't delete it if the flow just drops all received packets,
565      * because that's a perfectly reasonable thing to do for disabled physical
566      * ports. */
567     if (!(ofs->match.wildcards & htonl(OFPFW_IN_PORT))) {
568         if (!may_recv(sw, ntohs(ofs->match.in_port),
569                       end > (char *) ofs->actions)) {
570             delete = true;
571             sw->n_no_recv++;
572         }
573     }
574
575     /* Decide to delete the flow if it forwards to an STP-disabled physical
576      * port. */
577     if (!delete) {
578         const struct ofp_action_header *a;
579         size_t len;
580
581         for (a = ofs->actions; (char *) a < end; a += len / 8) {
582             uint16_t type;
583
584             len = ntohs(a->len);
585             if (len > end - (char *) a) {
586                 VLOG_DBG_RL(&rl, "%012llx: action exceeds available space "
587                             "(%zu > %td)",
588                             sw->datapath_id, len, end - (char *) a);
589                 break;
590             } else if (len % 8) {
591                 VLOG_DBG_RL(&rl, "%012llx: action length (%zu) not multiple "
592                             "of 8 bytes", sw->datapath_id, len);
593                 break;
594             }
595
596             type = ntohs(a->type);
597             if (a->type == htons(OFPAT_OUTPUT)) {
598                 struct ofp_action_output *oao = (struct ofp_action_output *) a;
599                 if (!may_send(sw, ntohs(oao->port))) {
600                     delete = true;
601                     sw->n_no_send++;
602                     break;
603                 }
604             }
605         }
606     }
607
608     /* Delete the flow. */
609     if (delete) {
610         struct ofp_flow_mod *ofm;
611         struct ofpbuf *b;
612
613         ofm = make_openflow(offsetof(struct ofp_flow_mod, actions),
614                             OFPT_FLOW_MOD, &b);
615         ofm->match = ofs->match;
616         ofm->command = OFPFC_DELETE_STRICT;
617         rconn_send(rconn, b, NULL);
618     }
619 }
620
621 static void
622 process_stats_reply(struct lswitch *sw, struct rconn *rconn, void *osr_)
623 {
624     struct ofp_stats_reply *osr = osr_;
625     const uint8_t *body = osr->body;
626     const uint8_t *pos = body;
627     size_t body_len;
628
629     if (sw->last_query == LLONG_MIN
630         || osr->type != htons(OFPST_FLOW)
631         || osr->header.xid != sw->query_xid) {
632         return;
633     }
634     body_len = (ntohs(osr->header.length)
635                 - offsetof(struct ofp_stats_reply, body));
636     for (;;) {
637         const struct ofp_flow_stats *fs;
638         ptrdiff_t bytes_left = body + body_len - pos;
639         size_t length;
640
641         if (bytes_left < sizeof *fs) {
642             if (bytes_left != 0) {
643                 VLOG_WARN_RL(&rl, "%012llx: %td leftover bytes in flow "
644                              "stats reply", sw->datapath_id, bytes_left);
645             }
646             break;
647         }
648
649         fs = (const void *) pos;
650         length = ntohs(fs->length);
651         if (length < sizeof *fs) {
652             VLOG_WARN_RL(&rl, "%012llx: flow stats length %zu is shorter than "
653                          "min %zu", sw->datapath_id, length, sizeof *fs);
654             break;
655         } else if (length > bytes_left) {
656             VLOG_WARN_RL(&rl, "%012llx: flow stats length %zu but only %td "
657                          "bytes left", sw->datapath_id, length, bytes_left);
658             break;
659         } else if ((length - sizeof *fs) % sizeof fs->actions[0]) {
660             VLOG_WARN_RL(&rl, "%012llx: flow stats length %zu has %zu bytes "
661                          "left over in final action", sw->datapath_id, length,
662                          (length - sizeof *fs) % sizeof fs->actions[0]);
663             break;
664         }
665
666         sw->n_flows++;
667         process_flow_stats(sw, rconn, fs);
668
669         pos += length;
670      }
671     if (!(osr->flags & htons(OFPSF_REPLY_MORE))) {
672         VLOG_DBG("%012llx: Deleted %d of %d received flows to "
673                  "implement STP, %d because of no-recv, %d because of "
674                  "no-send", sw->datapath_id,
675                  sw->n_no_recv + sw->n_no_send, sw->n_flows,
676                  sw->n_no_recv, sw->n_no_send);
677         sw->last_query = LLONG_MIN;
678         sw->last_reply = LLONG_MIN;
679     } else {
680         sw->last_reply = time_msec();
681     }
682 }
683