+ ofpbuf_init(&bands, 64);
+ for (;;) {
+ struct ofputil_meter_config mc;
+ int retval;
+
+ retval = ofputil_decode_meter_config(&b, &mc, &bands);
+ if (retval) {
+ if (retval != EOF) {
+ ofp_print_error(s, retval);
+ }
+ break;
+ }
+ ds_put_char(s, '\n');
+ ofp_print_meter_config(s, &mc);
+ }
+ ofpbuf_uninit(&bands);
+}
+
+static void
+ofp_print_meter_stats_reply(struct ds *s, const struct ofp_header *oh)
+{
+ struct ofpbuf bands;
+ struct ofpbuf b;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ ofpbuf_init(&bands, 64);
+ for (;;) {
+ struct ofputil_meter_stats ms;
+ int retval;
+
+ retval = ofputil_decode_meter_stats(&b, &ms, &bands);
+ if (retval) {
+ if (retval != EOF) {
+ ofp_print_error(s, retval);
+ }
+ break;
+ }
+ ds_put_char(s, '\n');
+ ofp_print_meter_stats(s, &ms);
+ }
+ ofpbuf_uninit(&bands);
+}
+
+static void
+ofp_print_error(struct ds *string, enum ofperr error)
+{
+ if (string->length) {
+ ds_put_char(string, ' ');
+ }
+ ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
+}
+
+static void
+ofp_print_hello(struct ds *string, const struct ofp_header *oh)
+{
+ uint32_t allowed_versions;
+ bool ok;
+
+ ok = ofputil_decode_hello(oh, &allowed_versions);
+
+ ds_put_cstr(string, "\n version bitmap: ");
+ ofputil_format_version_bitmap(string, allowed_versions);
+
+ if (!ok) {
+ ds_put_cstr(string, "\n unknown data in hello:\n");
+ ds_put_hex_dump(string, oh, ntohs(oh->length), 0, true);
+ }
+}
+
+static void
+ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
+{
+ size_t len = ntohs(oh->length);
+ struct ofpbuf payload;
+ enum ofperr error;
+ char *s;
+
+ error = ofperr_decode_msg(oh, &payload);
+ if (!error) {
+ ds_put_cstr(string, "***decode error***");
+ ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
+ return;
+ }
+
+ ds_put_format(string, " %s\n", ofperr_get_name(error));
+
+ if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
+ ds_put_printable(string, ofpbuf_data(&payload), ofpbuf_size(&payload));
+ } else {
+ s = ofp_to_string(ofpbuf_data(&payload), ofpbuf_size(&payload), 1);
+ ds_put_cstr(string, s);
+ free(s);
+ }
+ ofpbuf_uninit(&payload);
+}
+
+static void
+ofp_print_port_status(struct ds *string, const struct ofp_header *oh)
+{
+ struct ofputil_port_status ps;
+ enum ofperr error;
+
+ error = ofputil_decode_port_status(oh, &ps);
+ if (error) {
+ ofp_print_error(string, error);
+ return;
+ }
+
+ if (ps.reason == OFPPR_ADD) {
+ ds_put_format(string, " ADD:");
+ } else if (ps.reason == OFPPR_DELETE) {
+ ds_put_format(string, " DEL:");
+ } else if (ps.reason == OFPPR_MODIFY) {
+ ds_put_format(string, " MOD:");
+ }
+
+ ofp_print_phy_port(string, &ps.desc);
+}
+
+static void
+ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh)
+{
+ const struct ofp_desc_stats *ods = ofpmsg_body(oh);
+
+ ds_put_char(string, '\n');
+ ds_put_format(string, "Manufacturer: %.*s\n",
+ (int) sizeof ods->mfr_desc, ods->mfr_desc);
+ ds_put_format(string, "Hardware: %.*s\n",
+ (int) sizeof ods->hw_desc, ods->hw_desc);
+ ds_put_format(string, "Software: %.*s\n",
+ (int) sizeof ods->sw_desc, ods->sw_desc);
+ ds_put_format(string, "Serial Num: %.*s\n",
+ (int) sizeof ods->serial_num, ods->serial_num);
+ ds_put_format(string, "DP Description: %.*s\n",
+ (int) sizeof ods->dp_desc, ods->dp_desc);
+}
+
+static void
+ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh)
+{
+ struct ofputil_flow_stats_request fsr;
+ enum ofperr error;
+
+ error = ofputil_decode_flow_stats_request(&fsr, oh);
+ if (error) {
+ ofp_print_error(string, error);
+ return;
+ }
+
+ if (fsr.table_id != 0xff) {
+ ds_put_format(string, " table=%"PRIu8, fsr.table_id);
+ }
+
+ if (fsr.out_port != OFPP_ANY) {
+ ds_put_cstr(string, " out_port=");
+ ofputil_format_port(fsr.out_port, string);
+ }
+
+ ds_put_char(string, ' ');
+ match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY);
+}
+
+void
+ofp_print_flow_stats(struct ds *string, struct ofputil_flow_stats *fs)
+{
+ ds_put_format(string, " cookie=0x%"PRIx64", duration=",
+ ntohll(fs->cookie));
+
+ ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
+ ds_put_format(string, ", table=%"PRIu8", ", fs->table_id);
+ ds_put_format(string, "n_packets=%"PRIu64", ", fs->packet_count);
+ ds_put_format(string, "n_bytes=%"PRIu64", ", fs->byte_count);
+ if (fs->idle_timeout != OFP_FLOW_PERMANENT) {
+ ds_put_format(string, "idle_timeout=%"PRIu16", ", fs->idle_timeout);
+ }
+ if (fs->hard_timeout != OFP_FLOW_PERMANENT) {
+ ds_put_format(string, "hard_timeout=%"PRIu16", ", fs->hard_timeout);
+ }
+ if (fs->flags) {
+ ofp_print_flow_flags(string, fs->flags);
+ }
+ if (fs->idle_age >= 0) {
+ ds_put_format(string, "idle_age=%d, ", fs->idle_age);
+ }
+ if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) {
+ ds_put_format(string, "hard_age=%d, ", fs->hard_age);
+ }
+
+ match_format(&fs->match, string, fs->priority);
+ if (string->string[string->length - 1] != ' ') {
+ ds_put_char(string, ' ');
+ }
+
+ ds_put_cstr(string, "actions=");
+ ofpacts_format(fs->ofpacts, fs->ofpacts_len, string);
+}
+
+static void
+ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh)
+{
+ struct ofpbuf ofpacts;
+ struct ofpbuf b;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ ofpbuf_init(&ofpacts, 64);
+ for (;;) {
+ struct ofputil_flow_stats fs;
+ int retval;
+
+ retval = ofputil_decode_flow_stats_reply(&fs, &b, true, &ofpacts);
+ if (retval) {
+ if (retval != EOF) {
+ ds_put_cstr(string, " ***parse error***");
+ }
+ break;
+ }
+ ds_put_char(string, '\n');
+ ofp_print_flow_stats(string, &fs);
+ }
+ ofpbuf_uninit(&ofpacts);
+}
+
+static void
+ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
+{
+ struct ofputil_aggregate_stats as;
+ enum ofperr error;
+
+ error = ofputil_decode_aggregate_stats_reply(&as, oh);
+ if (error) {
+ ofp_print_error(string, error);
+ return;
+ }
+
+ ds_put_format(string, " packet_count=%"PRIu64, as.packet_count);
+ ds_put_format(string, " byte_count=%"PRIu64, as.byte_count);
+ ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
+}
+
+static void
+print_port_stat(struct ds *string, const char *leader, uint64_t stat, int more)
+{
+ ds_put_cstr(string, leader);
+ if (stat != UINT64_MAX) {
+ ds_put_format(string, "%"PRIu64, stat);
+ } else {
+ ds_put_char(string, '?');
+ }
+ if (more) {
+ ds_put_cstr(string, ", ");
+ } else {
+ ds_put_cstr(string, "\n");
+ }
+}
+
+static void
+ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
+{
+ ofp_port_t ofp10_port;
+ enum ofperr error;
+
+ error = ofputil_decode_port_stats_request(oh, &ofp10_port);
+ if (error) {
+ ofp_print_error(string, error);
+ return;
+ }
+
+ ds_put_cstr(string, " port_no=");
+ ofputil_format_port(ofp10_port, string);
+}
+
+static void
+ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
+ int verbosity)
+{
+ struct ofpbuf b;
+
+ ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh));
+ if (verbosity < 1) {
+ return;
+ }
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ for (;;) {
+ struct ofputil_port_stats ps;
+ int retval;
+
+ retval = ofputil_decode_port_stats(&ps, &b);
+ if (retval) {
+ if (retval != EOF) {
+ ds_put_cstr(string, " ***parse error***");
+ }
+ return;
+ }
+
+ ds_put_cstr(string, " port ");
+ if (ofp_to_u16(ps.port_no) < 10) {
+ ds_put_char(string, ' ');
+ }
+ ofputil_format_port(ps.port_no, string);
+
+ ds_put_cstr(string, ": rx ");
+ print_port_stat(string, "pkts=", ps.stats.rx_packets, 1);
+ print_port_stat(string, "bytes=", ps.stats.rx_bytes, 1);
+ print_port_stat(string, "drop=", ps.stats.rx_dropped, 1);
+ print_port_stat(string, "errs=", ps.stats.rx_errors, 1);
+ print_port_stat(string, "frame=", ps.stats.rx_frame_errors, 1);
+ print_port_stat(string, "over=", ps.stats.rx_over_errors, 1);
+ print_port_stat(string, "crc=", ps.stats.rx_crc_errors, 0);
+
+ ds_put_cstr(string, " tx ");
+ print_port_stat(string, "pkts=", ps.stats.tx_packets, 1);
+ print_port_stat(string, "bytes=", ps.stats.tx_bytes, 1);
+ print_port_stat(string, "drop=", ps.stats.tx_dropped, 1);
+ print_port_stat(string, "errs=", ps.stats.tx_errors, 1);
+ print_port_stat(string, "coll=", ps.stats.collisions, 0);
+
+ if (ps.duration_sec != UINT32_MAX) {
+ ds_put_cstr(string, " duration=");
+ ofp_print_duration(string, ps.duration_sec, ps.duration_nsec);
+ ds_put_char(string, '\n');
+ }
+ }
+}
+
+static void
+ofp_print_one_ofpst_table_reply(struct ds *string, enum ofp_version ofp_version,
+ const char *name, struct ofp12_table_stats *ts)
+{
+ char name_[OFP_MAX_TABLE_NAME_LEN + 1];
+
+ /* ofp13_table_stats is different */
+ if (ofp_version > OFP12_VERSION) {
+ return;
+ }
+
+ ovs_strlcpy(name_, name, sizeof name_);
+
+ ds_put_format(string, " %d: %-8s: ", ts->table_id, name_);
+ ds_put_format(string, "wild=0x%05"PRIx64", ", ntohll(ts->wildcards));
+ ds_put_format(string, "max=%6"PRIu32", ", ntohl(ts->max_entries));
+ ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count));
+ ds_put_cstr(string, " ");
+ ds_put_format(string, "lookup=%"PRIu64", ", ntohll(ts->lookup_count));
+ ds_put_format(string, "matched=%"PRIu64"\n", ntohll(ts->matched_count));
+
+ if (ofp_version < OFP11_VERSION) {
+ return;
+ }
+
+ ds_put_cstr(string, " ");
+ ds_put_format(string, "match=0x%08"PRIx64", ", ntohll(ts->match));
+ ds_put_format(string, "instructions=0x%08"PRIx32", ",
+ ntohl(ts->instructions));
+ ds_put_format(string, "config=0x%08"PRIx32"\n", ntohl(ts->config));
+ ds_put_cstr(string, " ");
+ ds_put_format(string, "write_actions=0x%08"PRIx32", ",
+ ntohl(ts->write_actions));
+ ds_put_format(string, "apply_actions=0x%08"PRIx32"\n",
+ ntohl(ts->apply_actions));
+
+ if (ofp_version < OFP12_VERSION) {
+ return;
+ }
+
+ ds_put_cstr(string, " ");
+ ds_put_format(string, "write_setfields=0x%016"PRIx64"\n",
+ ntohll(ts->write_setfields));
+ ds_put_cstr(string, " ");
+ ds_put_format(string, "apply_setfields=0x%016"PRIx64"\n",
+ ntohll(ts->apply_setfields));
+ ds_put_cstr(string, " ");
+ ds_put_format(string, "metadata_match=0x%016"PRIx64"\n",
+ ntohll(ts->metadata_match));
+ ds_put_cstr(string, " ");
+ ds_put_format(string, "metadata_write=0x%016"PRIx64"\n",
+ ntohll(ts->metadata_write));
+}
+
+static void
+ofp_print_ofpst_table_reply13(struct ds *string, const struct ofp_header *oh,
+ int verbosity)
+{
+ struct ofp13_table_stats *ts;
+ struct ofpbuf b;
+ size_t n;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ ofpraw_pull_assert(&b);
+
+ n = ofpbuf_size(&b) / sizeof *ts;
+ ds_put_format(string, " %"PRIuSIZE" tables\n", n);
+ if (verbosity < 1) {
+ return;
+ }
+
+ for (;;) {
+ ts = ofpbuf_try_pull(&b, sizeof *ts);
+ if (!ts) {
+ return;
+ }
+ ds_put_format(string,
+ " %d: active=%"PRIu32", lookup=%"PRIu64 \
+ ", matched=%"PRIu64"\n",
+ ts->table_id, ntohl(ts->active_count),
+ ntohll(ts->lookup_count), ntohll(ts->matched_count));
+ }
+}
+
+static void
+ofp_print_ofpst_table_reply12(struct ds *string, const struct ofp_header *oh,
+ int verbosity)
+{
+ struct ofp12_table_stats *ts;
+ struct ofpbuf b;
+ size_t n;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ ofpraw_pull_assert(&b);
+
+ n = ofpbuf_size(&b) / sizeof *ts;
+ ds_put_format(string, " %"PRIuSIZE" tables\n", n);
+ if (verbosity < 1) {
+ return;
+ }
+
+ for (;;) {
+ ts = ofpbuf_try_pull(&b, sizeof *ts);
+ if (!ts) {
+ return;
+ }
+
+ ofp_print_one_ofpst_table_reply(string, OFP12_VERSION, ts->name, ts);
+ }
+}
+
+static void
+ofp_print_ofpst_table_reply11(struct ds *string, const struct ofp_header *oh,
+ int verbosity)
+{
+ struct ofp11_table_stats *ts;
+ struct ofpbuf b;
+ size_t n;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ ofpraw_pull_assert(&b);
+
+ n = ofpbuf_size(&b) / sizeof *ts;
+ ds_put_format(string, " %"PRIuSIZE" tables\n", n);
+ if (verbosity < 1) {
+ return;
+ }
+
+ for (;;) {
+ struct ofp12_table_stats ts12;
+
+ ts = ofpbuf_try_pull(&b, sizeof *ts);
+ if (!ts) {
+ return;
+ }
+
+ ts12.table_id = ts->table_id;
+ ts12.wildcards = htonll(ntohl(ts->wildcards));
+ ts12.max_entries = ts->max_entries;
+ ts12.active_count = ts->active_count;
+ ts12.lookup_count = ts->lookup_count;
+ ts12.matched_count = ts->matched_count;
+ ts12.match = htonll(ntohl(ts->match));
+ ts12.instructions = ts->instructions;
+ ts12.config = ts->config;
+ ts12.write_actions = ts->write_actions;
+ ts12.apply_actions = ts->apply_actions;
+ ofp_print_one_ofpst_table_reply(string, OFP11_VERSION, ts->name, &ts12);
+ }
+}
+
+static void
+ofp_print_ofpst_table_reply10(struct ds *string, const struct ofp_header *oh,
+ int verbosity)
+{
+ struct ofp10_table_stats *ts;
+ struct ofpbuf b;
+ size_t n;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ ofpraw_pull_assert(&b);
+
+ n = ofpbuf_size(&b) / sizeof *ts;
+ ds_put_format(string, " %"PRIuSIZE" tables\n", n);
+ if (verbosity < 1) {
+ return;
+ }
+
+ for (;;) {
+ struct ofp12_table_stats ts12;
+
+ ts = ofpbuf_try_pull(&b, sizeof *ts);
+ if (!ts) {
+ return;
+ }
+
+ ts12.table_id = ts->table_id;
+ ts12.wildcards = htonll(ntohl(ts->wildcards));
+ ts12.max_entries = ts->max_entries;
+ ts12.active_count = ts->active_count;
+ ts12.lookup_count = get_32aligned_be64(&ts->lookup_count);
+ ts12.matched_count = get_32aligned_be64(&ts->matched_count);
+ ofp_print_one_ofpst_table_reply(string, OFP10_VERSION, ts->name, &ts12);
+ }
+}
+
+static void
+ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh,
+ int verbosity)
+{
+ switch ((enum ofp_version)oh->version) {
+ case OFP14_VERSION:
+ case OFP13_VERSION:
+ ofp_print_ofpst_table_reply13(string, oh, verbosity);
+ break;
+
+ case OFP12_VERSION:
+ ofp_print_ofpst_table_reply12(string, oh, verbosity);
+ break;
+
+ case OFP11_VERSION:
+ ofp_print_ofpst_table_reply11(string, oh, verbosity);
+ break;
+
+ case OFP10_VERSION:
+ ofp_print_ofpst_table_reply10(string, oh, verbosity);
+ break;
+
+ default:
+ OVS_NOT_REACHED();
+ }
+}
+
+static void
+ofp_print_queue_name(struct ds *string, uint32_t queue_id)
+{
+ if (queue_id == OFPQ_ALL) {
+ ds_put_cstr(string, "ALL");
+ } else {
+ ds_put_format(string, "%"PRIu32, queue_id);
+ }
+}
+
+static void
+ofp_print_ofpst_queue_request(struct ds *string, const struct ofp_header *oh)
+{
+ struct ofputil_queue_stats_request oqsr;
+ enum ofperr error;
+
+ error = ofputil_decode_queue_stats_request(oh, &oqsr);
+ if (error) {
+ ds_put_format(string, "***decode error: %s***\n", ofperr_get_name(error));
+ return;
+ }
+
+ ds_put_cstr(string, "port=");
+ ofputil_format_port(oqsr.port_no, string);
+
+ ds_put_cstr(string, " queue=");
+ ofp_print_queue_name(string, oqsr.queue_id);
+}
+
+static void
+ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh,
+ int verbosity)
+{
+ struct ofpbuf b;
+
+ ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh));
+ if (verbosity < 1) {
+ return;
+ }
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ for (;;) {
+ struct ofputil_queue_stats qs;
+ int retval;
+
+ retval = ofputil_decode_queue_stats(&qs, &b);
+ if (retval) {
+ if (retval != EOF) {
+ ds_put_cstr(string, " ***parse error***");
+ }
+ return;
+ }
+
+ ds_put_cstr(string, " port ");
+ ofputil_format_port(qs.port_no, string);
+ ds_put_cstr(string, " queue ");
+ ofp_print_queue_name(string, qs.queue_id);
+ ds_put_cstr(string, ": ");
+
+ print_port_stat(string, "bytes=", qs.tx_bytes, 1);
+ print_port_stat(string, "pkts=", qs.tx_packets, 1);
+ print_port_stat(string, "errors=", qs.tx_errors, 1);
+
+ ds_put_cstr(string, "duration=");
+ if (qs.duration_sec != UINT32_MAX) {
+ ofp_print_duration(string, qs.duration_sec, qs.duration_nsec);
+ } else {
+ ds_put_char(string, '?');
+ }
+ ds_put_char(string, '\n');
+ }
+}
+
+static void
+ofp_print_ofpst_port_desc_reply(struct ds *string,
+ const struct ofp_header *oh)
+{
+ struct ofpbuf b;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ ofpraw_pull_assert(&b);
+ ds_put_char(string, '\n');
+ ofp_print_phy_ports(string, oh->version, &b);