+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, ' ');
+ }
+
+ 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, " %zu 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)