+ query_stats(ofconn->ofproto, rule, &packet_count, &byte_count);
+
+ act_len = sizeof *rule->actions * rule->n_actions;
+
+ start_len = (*replyp)->size;
+ append_nxstats_reply(sizeof *nfs + NXM_MAX_LEN + act_len, ofconn, replyp);
+ reply = *replyp;
+
+ nfs = ofpbuf_put_uninit(reply, sizeof *nfs);
+ nfs->table_id = 0;
+ nfs->pad = 0;
+ calc_flow_duration(rule->created, &nfs->duration_sec, &nfs->duration_nsec);
+ nfs->cookie = rule->flow_cookie;
+ nfs->priority = htons(rule->cr.priority);
+ nfs->idle_timeout = htons(rule->idle_timeout);
+ nfs->hard_timeout = htons(rule->hard_timeout);
+ nfs->match_len = htons(nx_put_match(reply, &rule->cr));
+ memset(nfs->pad2, 0, sizeof nfs->pad2);
+ nfs->packet_count = htonll(packet_count);
+ nfs->byte_count = htonll(byte_count);
+ if (rule->n_actions > 0) {
+ ofpbuf_put(reply, rule->actions, act_len);
+ }
+ nfs->length = htons(reply->size - start_len);
+}
+
+static int
+handle_nxst_flow(struct ofconn *ofconn, struct ofpbuf *b)
+{
+ struct nx_flow_stats_request *nfsr;
+ struct cls_rule target;
+ struct ofpbuf *reply;
+ int error;
+
+ /* Dissect the message. */
+ nfsr = ofpbuf_try_pull(b, sizeof *nfsr);
+ if (!nfsr) {
+ return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
+ }
+ error = nx_pull_match(b, ntohs(nfsr->match_len), 0, &target);
+ if (error) {
+ return error;
+ }
+
+ COVERAGE_INC(ofproto_flows_req);
+ reply = start_nxstats_reply(&nfsr->nsm, 1024);
+ if (is_valid_table(nfsr->table_id)) {
+ struct cls_cursor cursor;
+ struct rule *rule;
+
+ cls_cursor_init(&cursor, &ofconn->ofproto->cls, &target);
+ CLS_CURSOR_FOR_EACH (rule, cr, &cursor) {
+ put_nx_flow_stats(ofconn, rule, nfsr->out_port, &reply);
+ }
+ }
+ queue_tx(reply, ofconn, ofconn->reply_counter);
+
+ return 0;
+}
+
+static void
+flow_stats_ds(struct ofproto *ofproto, struct rule *rule, struct ds *results)
+{
+ struct ofp_match match;
+ uint64_t packet_count, byte_count;
+ size_t act_len = sizeof *rule->actions * rule->n_actions;
+
+ query_stats(ofproto, rule, &packet_count, &byte_count);
+ ofputil_cls_rule_to_match(&rule->cr, NXFF_OPENFLOW10, &match);