+ 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);
+}
+
+static void
+ofp_print_stats_request(struct ds *string, const struct ofp_header *oh)
+{
+ uint16_t flags = ofpmp_flags(oh);
+
+ if (flags) {
+ ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags);
+ }
+}
+
+static void
+ofp_print_stats_reply(struct ds *string, const struct ofp_header *oh)
+{
+ uint16_t flags = ofpmp_flags(oh);
+
+ if (flags) {
+ ds_put_cstr(string, " flags=");
+ if (flags & OFPSF_REPLY_MORE) {
+ ds_put_cstr(string, "[more]");
+ flags &= ~OFPSF_REPLY_MORE;
+ }
+ if (flags) {
+ ds_put_format(string, "[***unknown flags 0x%04"PRIx16"***]",
+ flags);
+ }
+ }
+}
+
+static void
+ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity)
+{
+ size_t len = ntohs(oh->length);
+
+ ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh);
+ if (verbosity > 1) {
+ ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
+ }
+}
+
+static void
+ofp_print_role_generic(struct ds *string, enum ofp12_controller_role role,
+ uint64_t generation_id)
+{
+ ds_put_cstr(string, " role=");
+
+ switch (role) {
+ case OFPCR12_ROLE_NOCHANGE:
+ ds_put_cstr(string, "nochange");
+ break;
+ case OFPCR12_ROLE_EQUAL:
+ ds_put_cstr(string, "equal"); /* OF 1.2 wording */
+ break;
+ case OFPCR12_ROLE_MASTER:
+ ds_put_cstr(string, "master");
+ break;
+ case OFPCR12_ROLE_SLAVE:
+ ds_put_cstr(string, "slave");
+ break;
+ default:
+ OVS_NOT_REACHED();
+ }
+
+ if (generation_id != UINT64_MAX) {
+ ds_put_format(string, " generation_id=%"PRIu64, generation_id);
+ }
+}
+
+static void
+ofp_print_role_message(struct ds *string, const struct ofp_header *oh)
+{
+ struct ofputil_role_request rr;
+ enum ofperr error;
+
+ error = ofputil_decode_role_message(oh, &rr);
+ if (error) {
+ ofp_print_error(string, error);
+ return;
+ }
+
+ ofp_print_role_generic(string, rr.role, rr.have_generation_id ? rr.generation_id : UINT64_MAX);
+}
+
+static void
+ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh)
+{
+ struct ofputil_role_status rs;
+ enum ofperr error;
+
+ error = ofputil_decode_role_status(oh, &rs);
+ if (error) {
+ ofp_print_error(string, error);
+ return;
+ }
+
+ ofp_print_role_generic(string, rs.role, rs.generation_id);
+
+ ds_put_cstr(string, " reason=");
+
+ switch (rs.reason) {
+ case OFPCRR_MASTER_REQUEST:
+ ds_put_cstr(string, "master_request");
+ break;
+ case OFPCRR_CONFIG:
+ ds_put_cstr(string, "configuration_changed");
+ break;
+ case OFPCRR_EXPERIMENTER:
+ ds_put_cstr(string, "experimenter_data_changed");
+ break;
+ default:
+ OVS_NOT_REACHED();
+ }
+}
+
+static void
+ofp_print_nxt_flow_mod_table_id(struct ds *string,
+ const struct nx_flow_mod_table_id *nfmti)
+{
+ ds_put_format(string, " %s", nfmti->set ? "enable" : "disable");
+}
+
+static void
+ofp_print_nxt_set_flow_format(struct ds *string,
+ const struct nx_set_flow_format *nsff)
+{
+ uint32_t format = ntohl(nsff->format);
+
+ ds_put_cstr(string, " format=");
+ if (ofputil_nx_flow_format_is_valid(format)) {
+ ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
+ } else {
+ ds_put_format(string, "%"PRIu32, format);
+ }
+}
+
+static void
+ofp_print_nxt_set_packet_in_format(struct ds *string,
+ const struct nx_set_packet_in_format *nspf)
+{
+ uint32_t format = ntohl(nspf->format);
+
+ ds_put_cstr(string, " format=");
+ if (ofputil_packet_in_format_is_valid(format)) {
+ ds_put_cstr(string, ofputil_packet_in_format_to_string(format));
+ } else {
+ ds_put_format(string, "%"PRIu32, format);
+ }
+}
+
+/* Returns a string form of 'reason'. The return value is either a statically
+ * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
+ * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */
+#define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1)
+static const char *
+ofp_port_reason_to_string(enum ofp_port_reason reason,
+ char *reasonbuf, size_t bufsize)
+{
+ switch (reason) {
+ case OFPPR_ADD:
+ return "add";
+
+ case OFPPR_DELETE:
+ return "delete";
+
+ case OFPPR_MODIFY:
+ return "modify";
+
+ default:
+ snprintf(reasonbuf, bufsize, "%d", (int) reason);
+ return reasonbuf;
+ }
+}
+
+static void
+ofp_print_nxt_set_async_config(struct ds *string,
+ const struct nx_async_config *nac)
+{
+ int i;
+
+ for (i = 0; i < 2; i++) {
+ int j;
+
+ ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
+
+ ds_put_cstr(string, " PACKET_IN:");
+ for (j = 0; j < 32; j++) {
+ if (nac->packet_in_mask[i] & htonl(1u << j)) {
+ char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
+ const char *reason;
+
+ reason = ofputil_packet_in_reason_to_string(j, reasonbuf,
+ sizeof reasonbuf);
+ ds_put_format(string, " %s", reason);
+ }
+ }
+ if (!nac->packet_in_mask[i]) {
+ ds_put_cstr(string, " (off)");
+ }
+ ds_put_char(string, '\n');
+
+ ds_put_cstr(string, " PORT_STATUS:");
+ for (j = 0; j < 32; j++) {
+ if (nac->port_status_mask[i] & htonl(1u << j)) {
+ char reasonbuf[OFP_PORT_REASON_BUFSIZE];
+ const char *reason;
+
+ reason = ofp_port_reason_to_string(j, reasonbuf,
+ sizeof reasonbuf);
+ ds_put_format(string, " %s", reason);
+ }
+ }
+ if (!nac->port_status_mask[i]) {
+ ds_put_cstr(string, " (off)");
+ }
+ ds_put_char(string, '\n');
+
+ ds_put_cstr(string, " FLOW_REMOVED:");
+ for (j = 0; j < 32; j++) {
+ if (nac->flow_removed_mask[i] & htonl(1u << j)) {
+ char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
+ const char *reason;
+
+ reason = ofp_flow_removed_reason_to_string(j, reasonbuf,
+ sizeof reasonbuf);
+ ds_put_format(string, " %s", reason);
+ }
+ }
+ if (!nac->flow_removed_mask[i]) {
+ ds_put_cstr(string, " (off)");
+ }
+ ds_put_char(string, '\n');
+ }
+}
+
+static void
+ofp_print_nxt_set_controller_id(struct ds *string,
+ const struct nx_controller_id *nci)
+{
+ ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
+}
+
+static void
+ofp_print_nxt_flow_monitor_cancel(struct ds *string,
+ const struct ofp_header *oh)
+{
+ ds_put_format(string, " id=%"PRIu32,
+ ofputil_decode_flow_monitor_cancel(oh));
+}
+
+static const char *
+nx_flow_monitor_flags_to_name(uint32_t bit)
+{
+ enum nx_flow_monitor_flags fmf = bit;
+
+ switch (fmf) {
+ case NXFMF_INITIAL: return "initial";
+ case NXFMF_ADD: return "add";
+ case NXFMF_DELETE: return "delete";
+ case NXFMF_MODIFY: return "modify";
+ case NXFMF_ACTIONS: return "actions";
+ case NXFMF_OWN: return "own";
+ }
+
+ return NULL;
+}
+
+static void
+ofp_print_nxst_flow_monitor_request(struct ds *string,
+ const struct ofp_header *oh)
+{
+ struct ofpbuf b;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ for (;;) {
+ struct ofputil_flow_monitor_request request;
+ int retval;
+
+ retval = ofputil_decode_flow_monitor_request(&request, &b);
+ if (retval) {
+ if (retval != EOF) {
+ ofp_print_error(string, retval);
+ }
+ return;
+ }
+
+ ds_put_format(string, "\n id=%"PRIu32" flags=", request.id);
+ ofp_print_bit_names(string, request.flags,
+ nx_flow_monitor_flags_to_name, ',');
+
+ if (request.out_port != OFPP_NONE) {
+ ds_put_cstr(string, " out_port=");
+ ofputil_format_port(request.out_port, string);
+ }
+
+ if (request.table_id != 0xff) {
+ ds_put_format(string, " table=%"PRIu8, request.table_id);
+ }
+
+ ds_put_char(string, ' ');
+ match_format(&request.match, string, OFP_DEFAULT_PRIORITY);
+ ds_chomp(string, ' ');
+ }
+}
+
+static void
+ofp_print_nxst_flow_monitor_reply(struct ds *string,
+ const struct ofp_header *oh)
+{
+ uint64_t ofpacts_stub[1024 / 8];
+ struct ofpbuf ofpacts;
+ struct ofpbuf b;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
+ for (;;) {
+ char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
+ struct ofputil_flow_update update;
+ struct match match;
+ int retval;
+
+ update.match = &match;
+ retval = ofputil_decode_flow_update(&update, &b, &ofpacts);
+ if (retval) {
+ if (retval != EOF) {
+ ofp_print_error(string, retval);
+ }
+ ofpbuf_uninit(&ofpacts);
+ return;
+ }
+
+ ds_put_cstr(string, "\n event=");
+ switch (update.event) {
+ case NXFME_ADDED:
+ ds_put_cstr(string, "ADDED");
+ break;
+
+ case NXFME_DELETED:
+ ds_put_format(string, "DELETED reason=%s",
+ ofp_flow_removed_reason_to_string(update.reason,
+ reasonbuf,
+ sizeof reasonbuf));
+ break;
+
+ case NXFME_MODIFIED:
+ ds_put_cstr(string, "MODIFIED");
+ break;
+
+ case NXFME_ABBREV:
+ ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
+ continue;
+ }
+
+ ds_put_format(string, " table=%"PRIu8, update.table_id);
+ if (update.idle_timeout != OFP_FLOW_PERMANENT) {
+ ds_put_format(string, " idle_timeout=%"PRIu16,
+ update.idle_timeout);
+ }
+ if (update.hard_timeout != OFP_FLOW_PERMANENT) {
+ ds_put_format(string, " hard_timeout=%"PRIu16,
+ update.hard_timeout);
+ }
+ ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
+
+ ds_put_char(string, ' ');
+ match_format(update.match, string, OFP_DEFAULT_PRIORITY);
+
+ if (update.ofpacts_len) {
+ if (string->string[string->length - 1] != ' ') {
+ ds_put_char(string, ' ');
+ }
+ ds_put_cstr(string, "actions=");
+ ofpacts_format(update.ofpacts, update.ofpacts_len, string);
+ }
+ }
+}
+
+void
+ofp_print_version(const struct ofp_header *oh,
+ struct ds *string)
+{
+ switch (oh->version) {
+ case OFP10_VERSION:
+ break;
+ case OFP11_VERSION:
+ ds_put_cstr(string, " (OF1.1)");
+ break;
+ case OFP12_VERSION:
+ ds_put_cstr(string, " (OF1.2)");
+ break;
+ case OFP13_VERSION:
+ ds_put_cstr(string, " (OF1.3)");
+ break;
+ default:
+ ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
+ break;
+ }
+ ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
+}
+
+static void
+ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
+ struct ds *string)
+{
+ ds_put_cstr(string, ofpraw_get_name(raw));
+ ofp_print_version(oh, string);
+}
+
+static void
+ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
+ struct list *p_buckets)
+{
+ static const char *type_str[] = { "all", "select", "indirect",
+ "ff", "unknown" };
+ struct ofputil_bucket *bucket;
+
+ ds_put_format(s, "group_id=%"PRIu32",type=%s",
+ group_id, type_str[type > 4 ? 4 : type]);
+ if (!p_buckets) {
+ return;
+ }
+
+ LIST_FOR_EACH (bucket, list_node, p_buckets) {
+ ds_put_cstr(s, ",bucket=");
+
+ if (bucket->weight != 1) {
+ ds_put_format(s, "weight:%"PRIu16",", bucket->weight);
+ }
+ if (bucket->watch_port != OFPP_NONE) {
+ ds_put_format(s, "watch_port:%"PRIu32",", bucket->watch_port);
+ }
+ if (bucket->watch_group != OFPG11_ANY) {
+ ds_put_format(s, "watch_group:%"PRIu32",", bucket->watch_group);
+ }
+
+ ds_put_cstr(s, "actions=");
+ ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s);
+ }
+}
+
+static void
+ofp_print_group_desc(struct ds *s, const struct ofp_header *oh)
+{
+ struct ofpbuf b;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ for (;;) {
+ struct ofputil_group_desc gd;
+ int retval;
+
+ retval = ofputil_decode_group_desc_reply(&gd, &b, oh->version);
+ if (retval) {
+ if (retval != EOF) {
+ ds_put_cstr(s, " ***parse error***");
+ }
+ break;
+ }
+
+ ds_put_char(s, '\n');
+ ds_put_char(s, ' ');
+ ofp_print_group(s, gd.group_id, gd.type, &gd.buckets);
+ }
+}
+
+static void
+ofp_print_ofpst_group_request(struct ds *string, const struct ofp_header *oh)
+{
+ enum ofperr error;
+ uint32_t group_id;
+
+ error = ofputil_decode_group_stats_request(oh, &group_id);
+ if (error) {
+ ofp_print_error(string, error);
+ return;
+ }
+
+ ds_put_cstr(string, " group_id=");
+ ofputil_format_group(group_id, string);
+}
+
+static void
+ofp_print_group_stats(struct ds *s, const struct ofp_header *oh)
+{
+ struct ofpbuf b;
+ uint32_t bucket_i;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+
+ for (;;) {
+ struct ofputil_group_stats gs;
+ int retval;
+
+ retval = ofputil_decode_group_stats_reply(&b, &gs);
+ if (retval) {
+ if (retval != EOF) {
+ ds_put_cstr(s, " ***parse error***");
+ }
+ break;
+ }
+
+ ds_put_char(s, '\n');
+
+ ds_put_char(s, ' ');
+ ds_put_format(s, "group_id=%"PRIu32",", gs.group_id);
+
+ if (gs.duration_sec != UINT32_MAX) {
+ ds_put_cstr(s, "duration=");
+ ofp_print_duration(s, gs.duration_sec, gs.duration_nsec);
+ ds_put_char(s, ',');
+ }
+ ds_put_format(s, "ref_count=%"PRIu32",", gs.ref_count);
+ ds_put_format(s, "packet_count=%"PRIu64",", gs.packet_count);
+ ds_put_format(s, "byte_count=%"PRIu64"", gs.byte_count);
+
+ for (bucket_i = 0; bucket_i < gs.n_buckets; bucket_i++) {
+ if (gs.bucket_stats[bucket_i].packet_count != UINT64_MAX) {
+ ds_put_format(s, ",bucket%"PRIu32":", bucket_i);
+ ds_put_format(s, "packet_count=%"PRIu64",", gs.bucket_stats[bucket_i].packet_count);
+ ds_put_format(s, "byte_count=%"PRIu64"", gs.bucket_stats[bucket_i].byte_count);
+ }
+ }
+
+ free(gs.bucket_stats);
+ }
+}
+
+static void
+ofp_print_group_features(struct ds *string, const struct ofp_header *oh)
+{
+ struct ofputil_group_features features;
+
+ ofputil_decode_group_features_reply(oh, &features);
+
+ ds_put_format(string, "\n Group table:\n");
+ ds_put_format(string, " Types: 0x%"PRIx32"\n", features.types);
+ ds_put_format(string, " Capabilities: 0x%"PRIx32"\n",
+ features.capabilities);
+
+ if (features.types & (1u << OFPGT11_ALL)) {
+ ds_put_format(string, " All group :\n");
+ ds_put_format(string,
+ " max_groups = %#"PRIx32" actions=0x%08"PRIx32"\n",
+ features.max_groups[0], features.actions[0]);
+ }
+
+ if (features.types & (1u << OFPGT11_SELECT)) {
+ ds_put_format(string, " Select group :\n");
+ ds_put_format(string, " max_groups = %#"PRIx32" "
+ "actions=0x%08"PRIx32"\n",
+ features.max_groups[1], features.actions[1]);
+ }
+
+ if (features.types & (1u << OFPGT11_INDIRECT)) {
+ ds_put_format(string, " Indirect group :\n");
+ ds_put_format(string, " max_groups = %#"PRIx32" "
+ "actions=0x%08"PRIx32"\n",
+ features.max_groups[2], features.actions[2]);
+ }
+
+ if (features.types & (1u << OFPGT11_FF)) {
+ ds_put_format(string, " Fast Failover group :\n");
+ ds_put_format(string, " max_groups = %#"PRIx32" "
+ "actions=0x%08"PRIx32"\n",
+ features.max_groups[3], features.actions[3]);
+ }
+}
+
+static void
+ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
+{
+ struct ofputil_group_mod gm;
+ int error;
+
+ error = ofputil_decode_group_mod(oh, &gm);
+ if (error) {
+ ofp_print_error(s, error);
+ return;
+ }
+
+ ds_put_char(s, '\n');
+
+ ds_put_char(s, ' ');
+ switch (gm.command) {
+ case OFPGC11_ADD:
+ ds_put_cstr(s, "ADD");
+ break;
+
+ case OFPGC11_MODIFY:
+ ds_put_cstr(s, "MOD");
+ break;
+
+ case OFPGC11_DELETE:
+ ds_put_cstr(s, "DEL");
+ break;
+
+ default:
+ ds_put_format(s, "cmd:%"PRIu16"", gm.command);
+ }
+ ds_put_char(s, ' ');
+
+ ofp_print_group(s, gm.group_id, gm.type, &gm.buckets);
+}
+
+static const char *
+ofp13_action_to_string(uint32_t bit)
+{
+ switch (bit) {
+#define OFPAT13_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
+ case 1u << ENUM: return NAME;
+#include "ofp-util.def"
+ }
+ return NULL;
+}
+
+static void
+print_table_action_features(struct ds *s,
+ const struct ofputil_table_action_features *taf)
+{
+ ds_put_cstr(s, " actions: ");
+ ofp_print_bit_names(s, taf->actions, ofp13_action_to_string, ',');
+ ds_put_char(s, '\n');
+
+ ds_put_cstr(s, " supported on Set-Field: ");
+ if (taf->set_fields) {
+ int i;
+
+ for (i = 0; i < MFF_N_IDS; i++) {
+ uint64_t bit = UINT64_C(1) << i;
+
+ if (taf->set_fields & bit) {
+ ds_put_format(s, "%s,", mf_from_id(i)->name);
+ }
+ }
+ ds_chomp(s, ',');
+ } else {
+ ds_put_cstr(s, "none");
+ }
+ ds_put_char(s, '\n');
+}
+
+static bool
+table_action_features_equal(const struct ofputil_table_action_features *a,
+ const struct ofputil_table_action_features *b)
+{
+ return a->actions == b->actions && a->set_fields == b->set_fields;
+}
+
+static void
+print_table_instruction_features(
+ struct ds *s, const struct ofputil_table_instruction_features *tif)
+{
+ int start, end;
+
+ ds_put_cstr(s, " next tables: ");
+ for (start = bitmap_scan(tif->next, 1, 0, 255); start < 255;
+ start = bitmap_scan(tif->next, 1, end, 255)) {
+ end = bitmap_scan(tif->next, 0, start + 1, 255);
+ if (end == start + 1) {
+ ds_put_format(s, "%d,", start);
+ } else {
+ ds_put_format(s, "%d-%d,", start, end - 1);
+ }
+ }
+ ds_chomp(s, ',');
+ if (ds_last(s) == ' ') {
+ ds_put_cstr(s, "none");
+ }
+ ds_put_char(s, '\n');
+
+ ds_put_cstr(s, " instructions: ");
+ if (tif->instructions) {
+ int i;
+
+ for (i = 0; i < 32; i++) {
+ if (tif->instructions & (1u << i)) {
+ ds_put_format(s, "%s,", ovs_instruction_name_from_type(i));
+ }
+ }
+ ds_chomp(s, ',');
+ } else {
+ ds_put_cstr(s, "none");
+ }
+ ds_put_char(s, '\n');
+
+ if (table_action_features_equal(&tif->write, &tif->apply)) {
+ ds_put_cstr(s, " Write-Actions and Apply-Actions features:\n");
+ print_table_action_features(s, &tif->write);
+ } else {
+ ds_put_cstr(s, " Write-Actions features:\n");
+ print_table_action_features(s, &tif->write);
+ ds_put_cstr(s, " Apply-Actions features:\n");
+ print_table_action_features(s, &tif->apply);
+ }
+}
+
+static bool
+table_instruction_features_equal(
+ const struct ofputil_table_instruction_features *a,
+ const struct ofputil_table_instruction_features *b)
+{
+ return (bitmap_equal(a->next, b->next, 255)
+ && a->instructions == b->instructions
+ && table_action_features_equal(&a->write, &b->write)
+ && table_action_features_equal(&a->apply, &b->apply));
+}
+
+static void
+ofp_print_table_features(struct ds *s, const struct ofp_header *oh)
+{
+ struct ofpbuf b;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+
+ for (;;) {
+ struct ofputil_table_features tf;
+ int retval;
+ int i;
+
+ retval = ofputil_decode_table_features(&b, &tf, true);
+ if (retval) {
+ if (retval != EOF) {
+ ofp_print_error(s, retval);
+ }
+ return;
+ }
+
+ ds_put_format(s, "\n table %"PRIu8":\n", tf.table_id);
+ ds_put_format(s, " name=\"%s\"\n", tf.name);
+ ds_put_format(s, " metadata: match=%#"PRIx64" write=%#"PRIx64"\n",
+ ntohll(tf.metadata_match), ntohll(tf.metadata_write));
+
+ ds_put_cstr(s, " config=");
+ ofp_print_table_miss_config(s, tf.config);
+
+ ds_put_format(s, " max_entries=%"PRIu32"\n", tf.max_entries);
+
+ if (table_instruction_features_equal(&tf.nonmiss, &tf.miss)) {
+ ds_put_cstr(s, " instructions (table miss and others):\n");
+ print_table_instruction_features(s, &tf.nonmiss);
+ } else {
+ ds_put_cstr(s, " instructions (other than table miss):\n");
+ print_table_instruction_features(s, &tf.nonmiss);
+ ds_put_cstr(s, " instructions (table miss):\n");
+ print_table_instruction_features(s, &tf.miss);
+ }
+
+ ds_put_cstr(s, " matching:\n");
+ for (i = 0; i < MFF_N_IDS; i++) {
+ uint64_t bit = UINT64_C(1) << i;
+
+ if (tf.match & bit) {
+ const struct mf_field *f = mf_from_id(i);
+
+ ds_put_format(s, " %s: %s\n",
+ f->name,
+ (tf.mask ? "arbitrary mask"
+ : tf.wildcard ? "exact match or wildcard"
+ : "must exact match"));
+ }
+ }
+ }
+}
+
+static void
+ofp_to_string__(const struct ofp_header *oh, enum ofpraw raw,
+ struct ds *string, int verbosity)
+{
+ const void *msg = oh;
+
+ ofp_header_to_string__(oh, raw, string);
+ switch (ofptype_from_ofpraw(raw)) {
+
+ case OFPTYPE_GROUP_STATS_REQUEST:
+ ofp_print_stats_request(string, oh);
+ ofp_print_ofpst_group_request(string, oh);
+ break;
+
+ case OFPTYPE_GROUP_STATS_REPLY:
+ ofp_print_group_stats(string, oh);
+ break;
+
+ case OFPTYPE_GROUP_DESC_STATS_REQUEST:
+ ofp_print_stats_request(string, oh);
+ break;
+
+ case OFPTYPE_GROUP_DESC_STATS_REPLY:
+ ofp_print_group_desc(string, oh);
+ break;
+
+ case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
+ ofp_print_stats_request(string, oh);
+ break;
+
+ case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
+ ofp_print_group_features(string, oh);
+ break;
+
+ case OFPTYPE_GROUP_MOD:
+ ofp_print_group_mod(string, oh);
+ break;
+
+ case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
+ case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
+ ofp_print_table_features(string, oh);
+ break;
+
+ case OFPTYPE_HELLO:
+ ofp_print_hello(string, oh);
+ break;
+
+ case OFPTYPE_ERROR:
+ ofp_print_error_msg(string, oh);
+ break;
+
+ case OFPTYPE_ECHO_REQUEST:
+ case OFPTYPE_ECHO_REPLY:
+ ofp_print_echo(string, oh, verbosity);
+ break;
+
+ case OFPTYPE_FEATURES_REQUEST:
+ break;
+
+ case OFPTYPE_FEATURES_REPLY:
+ ofp_print_switch_features(string, oh);
+ break;
+
+ case OFPTYPE_GET_CONFIG_REQUEST:
+ break;
+
+ case OFPTYPE_GET_CONFIG_REPLY:
+ case OFPTYPE_SET_CONFIG:
+ ofp_print_switch_config(string, ofpmsg_body(oh));
+ break;
+
+ case OFPTYPE_PACKET_IN:
+ ofp_print_packet_in(string, oh, verbosity);
+ break;
+
+ case OFPTYPE_FLOW_REMOVED:
+ ofp_print_flow_removed(string, oh);
+ break;
+
+ case OFPTYPE_PORT_STATUS:
+ ofp_print_port_status(string, oh);
+ break;
+
+ case OFPTYPE_PACKET_OUT:
+ ofp_print_packet_out(string, oh, verbosity);
+ break;
+
+ case OFPTYPE_FLOW_MOD:
+ ofp_print_flow_mod(string, oh, verbosity);
+ break;
+
+ case OFPTYPE_PORT_MOD:
+ ofp_print_port_mod(string, oh);
+ break;
+
+ case OFPTYPE_TABLE_MOD:
+ ofp_print_table_mod(string, oh);
+ break;
+
+ case OFPTYPE_METER_MOD:
+ ofp_print_meter_mod(string, oh);
+ break;
+
+ case OFPTYPE_BARRIER_REQUEST:
+ case OFPTYPE_BARRIER_REPLY:
+ break;
+
+ case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
+ ofp_print_queue_get_config_request(string, oh);
+ break;
+
+ case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
+ ofp_print_queue_get_config_reply(string, oh);
+ break;
+
+ case OFPTYPE_ROLE_REQUEST:
+ case OFPTYPE_ROLE_REPLY:
+ ofp_print_role_message(string, oh);
+ break;
+ case OFPTYPE_ROLE_STATUS:
+ ofp_print_role_status_message(string, oh);
+ break;
+
+ case OFPTYPE_METER_STATS_REQUEST:
+ case OFPTYPE_METER_CONFIG_STATS_REQUEST:
+ ofp_print_stats_request(string, oh);
+ ofp_print_meter_stats_request(string, oh);
+ break;
+
+ case OFPTYPE_METER_STATS_REPLY:
+ ofp_print_stats_reply(string, oh);
+ ofp_print_meter_stats_reply(string, oh);
+ break;
+
+ case OFPTYPE_METER_CONFIG_STATS_REPLY:
+ ofp_print_stats_reply(string, oh);
+ ofp_print_meter_config_reply(string, oh);
+ break;
+
+ case OFPTYPE_METER_FEATURES_STATS_REPLY:
+ ofp_print_stats_reply(string, oh);
+ ofp_print_meter_features_reply(string, oh);
+ break;
+
+ case OFPTYPE_DESC_STATS_REQUEST:
+ case OFPTYPE_PORT_DESC_STATS_REQUEST:
+ case OFPTYPE_METER_FEATURES_STATS_REQUEST:
+ ofp_print_stats_request(string, oh);
+ break;
+
+ case OFPTYPE_FLOW_STATS_REQUEST:
+ case OFPTYPE_AGGREGATE_STATS_REQUEST:
+ ofp_print_stats_request(string, oh);
+ ofp_print_flow_stats_request(string, oh);
+ break;
+
+ case OFPTYPE_TABLE_STATS_REQUEST:
+ ofp_print_stats_request(string, oh);
+ break;
+
+ case OFPTYPE_PORT_STATS_REQUEST:
+ ofp_print_stats_request(string, oh);
+ ofp_print_ofpst_port_request(string, oh);
+ break;
+
+ case OFPTYPE_QUEUE_STATS_REQUEST:
+ ofp_print_stats_request(string, oh);
+ ofp_print_ofpst_queue_request(string, oh);
+ break;
+
+ case OFPTYPE_DESC_STATS_REPLY:
+ ofp_print_stats_reply(string, oh);
+ ofp_print_ofpst_desc_reply(string, oh);
+ break;
+
+ case OFPTYPE_FLOW_STATS_REPLY:
+ ofp_print_stats_reply(string, oh);
+ ofp_print_flow_stats_reply(string, oh);
+ break;
+
+ case OFPTYPE_QUEUE_STATS_REPLY:
+ ofp_print_stats_reply(string, oh);
+ ofp_print_ofpst_queue_reply(string, oh, verbosity);
+ break;
+
+ case OFPTYPE_PORT_STATS_REPLY:
+ ofp_print_stats_reply(string, oh);
+ ofp_print_ofpst_port_reply(string, oh, verbosity);
+ break;
+
+ case OFPTYPE_TABLE_STATS_REPLY:
+ ofp_print_stats_reply(string, oh);
+ ofp_print_ofpst_table_reply(string, oh, verbosity);
+ break;
+
+ case OFPTYPE_AGGREGATE_STATS_REPLY:
+ ofp_print_stats_reply(string, oh);
+ ofp_print_aggregate_stats_reply(string, oh);
+ break;
+
+ case OFPTYPE_PORT_DESC_STATS_REPLY:
+ ofp_print_stats_reply(string, oh);
+ ofp_print_ofpst_port_desc_reply(string, oh);
+ break;
+
+ case OFPTYPE_FLOW_MOD_TABLE_ID:
+ ofp_print_nxt_flow_mod_table_id(string, ofpmsg_body(oh));
+ break;
+
+ case OFPTYPE_SET_FLOW_FORMAT:
+ ofp_print_nxt_set_flow_format(string, ofpmsg_body(oh));
+ break;
+
+ case OFPTYPE_SET_PACKET_IN_FORMAT:
+ ofp_print_nxt_set_packet_in_format(string, ofpmsg_body(oh));
+ break;
+
+ case OFPTYPE_FLOW_AGE:
+ break;
+
+ case OFPTYPE_SET_CONTROLLER_ID:
+ ofp_print_nxt_set_controller_id(string, ofpmsg_body(oh));
+ break;
+
+ case OFPTYPE_GET_ASYNC_REPLY:
+ case OFPTYPE_SET_ASYNC_CONFIG:
+ ofp_print_nxt_set_async_config(string, ofpmsg_body(oh));
+ break;
+ case OFPTYPE_GET_ASYNC_REQUEST:
+ break;
+ case OFPTYPE_FLOW_MONITOR_CANCEL:
+ ofp_print_nxt_flow_monitor_cancel(string, msg);
+ break;
+
+ case OFPTYPE_FLOW_MONITOR_PAUSED:
+ case OFPTYPE_FLOW_MONITOR_RESUMED:
+ break;
+
+ case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
+ ofp_print_nxst_flow_monitor_request(string, msg);
+ break;
+
+ case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
+ ofp_print_nxst_flow_monitor_reply(string, msg);
+ break;
+ }
+}
+
+/* Composes and returns a string representing the OpenFlow packet of 'len'
+ * bytes at 'oh' at the given 'verbosity' level. 0 is a minimal amount of
+ * verbosity and higher numbers increase verbosity. The caller is responsible
+ * for freeing the string. */
+char *
+ofp_to_string(const void *oh_, size_t len, int verbosity)
+{
+ struct ds string = DS_EMPTY_INITIALIZER;
+ const struct ofp_header *oh = oh_;
+
+ if (!len) {
+ ds_put_cstr(&string, "OpenFlow message is empty\n");
+ } else if (len < sizeof(struct ofp_header)) {
+ ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n",
+ len);
+ } else if (ntohs(oh->length) > len) {
+ enum ofperr error;
+ enum ofpraw raw;
+
+ error = ofpraw_decode_partial(&raw, oh, len);
+ if (!error) {
+ ofp_header_to_string__(oh, raw, &string);
+ ds_put_char(&string, '\n');
+ }
+
+ ds_put_format(&string,
+ "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n",
+ len, ntohs(oh->length));
+ } else if (ntohs(oh->length) < len) {
+ ds_put_format(&string,
+ "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n",
+ ntohs(oh->length), len);
+ } else {
+ enum ofperr error;
+ enum ofpraw raw;
+
+ error = ofpraw_decode(&raw, oh);
+ if (!error) {
+ ofp_to_string__(oh, raw, &string, verbosity);
+ if (verbosity >= 5) {
+ if (ds_last(&string) != '\n') {
+ ds_put_char(&string, '\n');
+ }
+ ds_put_hex_dump(&string, oh, len, 0, true);
+ }
+ if (ds_last(&string) != '\n') {
+ ds_put_char(&string, '\n');
+ }
+ return ds_steal_cstr(&string);
+ }
+
+ ofp_print_error(&string, error);
+ }
+ ds_put_hex_dump(&string, oh, len, 0, true);
+ return ds_steal_cstr(&string);
+}
+\f
+static void
+print_and_free(FILE *stream, char *string)
+{
+ fputs(string, stream);
+ free(string);
+}
+
+/* Pretty-print the OpenFlow packet of 'len' bytes at 'oh' to 'stream' at the
+ * given 'verbosity' level. 0 is a minimal amount of verbosity and higher
+ * numbers increase verbosity. */
+void
+ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
+{
+ print_and_free(stream, ofp_to_string(oh, len, verbosity));
+}
+
+/* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
+ * 'data' to 'stream'. */