X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=lib%2Fofp-print.c;h=56111435328e228d72b5762327a80c91fbb5489a;hb=a2ad9ecdd0d4ac9a641e8cef1f3f4681fd77d6b1;hp=9446887620db39ecc1e66741993808a223063745;hpb=c6430da5be53d510e31e8add61a2f2575193f4b4;p=openvswitch diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 94468876..56111435 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -852,6 +852,19 @@ ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, fm.n_actions * sizeof *fm.actions); } +static void +ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec) +{ + ds_put_format(string, "%u", sec); + if (nsec > 0) { + ds_put_format(string, ".%09u", nsec); + while (string->string[string->length - 1] == '0') { + string->length--; + } + } + ds_put_char(string, 's'); +} + static void ofp_print_flow_removed(struct ds *string, const struct ofp_flow_removed *ofr, int verbosity) @@ -879,9 +892,10 @@ ofp_print_flow_removed(struct ds *string, const struct ofp_flow_removed *ofr, if (ofr->priority != htons(32768)) { ds_put_format(string, " pri:%"PRIu16, ntohs(ofr->priority)); } - ds_put_format(string, " secs%"PRIu32" nsecs%"PRIu32 - " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n", - ntohl(ofr->duration_sec), ntohl(ofr->duration_nsec), + ds_put_cstr(string, " duration"); + ofp_print_duration(string, + ntohl(ofr->duration_sec), ntohl(ofr->duration_nsec)); + ds_put_format(string, " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n", ntohs(ofr->idle_timeout), ntohll(ofr->packet_count), ntohll(ofr->byte_count)); } @@ -1088,18 +1102,28 @@ ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh) } static void -ofp_print_ofpst_flow_request(struct ds *string, const struct ofp_header *oh, - int verbosity) +ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh) { - const struct ofp_flow_stats_request *fsr = ofputil_stats_body(oh); + struct flow_stats_request fsr; + int error; - if (fsr->table_id == 0xff) { - ds_put_format(string, " table_id=any, "); - } else { - ds_put_format(string, " table_id=%"PRIu8", ", fsr->table_id); + error = ofputil_decode_flow_stats_request(&fsr, oh, NXFF_OPENFLOW10); + if (error) { + ofp_print_error(string, error); + return; + } + + if (fsr.table_id != 0xff) { + ds_put_format(string, " table_id=%"PRIu8, fsr.table_id); + } + + if (fsr.out_port != OFPP_NONE) { + ds_put_cstr(string, " out_port="); + ofp_print_port_name(string, fsr.out_port); } - ofp_print_match(string, &fsr->match, verbosity); + ds_put_char(string, ' '); + cls_rule_format(&fsr.match, string); } static void @@ -1144,12 +1168,11 @@ ofp_print_ofpst_flow_reply(struct ds *string, const struct ofp_header *oh, break; } - ds_put_format(string, " cookie=0x%"PRIx64", ", ntohll(fs->cookie)); - ds_put_format(string, "duration_sec=%"PRIu32"s, ", - ntohl(fs->duration_sec)); - ds_put_format(string, "duration_nsec=%"PRIu32"ns, ", - ntohl(fs->duration_nsec)); - ds_put_format(string, "table_id=%"PRIu8", ", fs->table_id); + ds_put_format(string, " cookie=0x%"PRIx64", duration=", + ntohll(fs->cookie)); + ofp_print_duration(string, ntohl(fs->duration_sec), + ntohl(fs->duration_nsec)); + ds_put_format(string, ", table_id=%"PRIu8", ", fs->table_id); ds_put_format(string, "priority=%"PRIu16", ", ntohs(fs->priority)); ds_put_format(string, "n_packets=%"PRIu64", ", ntohll(fs->packet_count)); @@ -1206,12 +1229,11 @@ ofp_print_nxst_flow_reply(struct ds *string, const struct ofp_header *oh) break; } - ds_put_format(string, " cookie=0x%"PRIx64", ", ntohll(fs->cookie)); - ds_put_format(string, "duration_sec=%"PRIu32"s, ", - ntohl(fs->duration_sec)); - ds_put_format(string, "duration_nsec=%"PRIu32"ns, ", - ntohl(fs->duration_nsec)); - ds_put_format(string, "table_id=%"PRIu8", ", fs->table_id); + ds_put_format(string, " cookie=0x%"PRIx64", duration=", + ntohll(fs->cookie)); + ofp_print_duration(string, ntohl(fs->duration_sec), + ntohl(fs->duration_nsec)); + ds_put_format(string, ", table_id=%"PRIu8", ", fs->table_id); ds_put_format(string, "priority=%"PRIu16", ", ntohs(fs->priority)); ds_put_format(string, "n_packets=%"PRIu64", ", ntohll(fs->packet_count)); @@ -1247,28 +1269,25 @@ ofp_print_nxst_flow_reply(struct ds *string, const struct ofp_header *oh) } static void -ofp_print_ofpst_aggregate_request(struct ds *string, - const struct ofp_header *oh, int verbosity) +ofp_print_ofp_aggregate_stats_reply ( + struct ds *string, const struct ofp_aggregate_stats_reply *asr) { - const struct ofp_aggregate_stats_request *asr = ofputil_stats_body(oh); - - if (asr->table_id == 0xff) { - ds_put_format(string, " table_id=any, "); - } else { - ds_put_format(string, " table_id=%"PRIu8", ", asr->table_id); - } - - ofp_print_match(string, &asr->match, verbosity); + ds_put_format(string, " packet_count=%"PRIu64, ntohll(asr->packet_count)); + ds_put_format(string, " byte_count=%"PRIu64, ntohll(asr->byte_count)); + ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count)); } static void ofp_print_ofpst_aggregate_reply(struct ds *string, const struct ofp_header *oh) { - const struct ofp_aggregate_stats_reply *asr = ofputil_stats_body(oh); + ofp_print_ofp_aggregate_stats_reply(string, ofputil_stats_body(oh)); +} - ds_put_format(string, " packet_count=%"PRIu64, ntohll(asr->packet_count)); - ds_put_format(string, " byte_count=%"PRIu64, ntohll(asr->byte_count)); - ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count)); +static void +ofp_print_nxst_aggregate_reply(struct ds *string, + const struct nx_aggregate_stats_reply *nasr) +{ + ofp_print_ofp_aggregate_stats_reply(string, &nasr->asr); } static void print_port_stat(struct ds *string, const char *leader, @@ -1443,6 +1462,18 @@ ofp_print_echo(struct ds *string, const struct ofp_header *oh, int verbosity) } } +static void +ofp_print_nxt_status_message(struct ds *string, const struct ofp_header *oh) +{ + struct ofpbuf b; + + ofpbuf_use_const(&b, oh, ntohs(oh->length)); + ofpbuf_pull(&b, sizeof *oh); + ds_put_char(string, '"'); + ds_put_printable(string, b.data, b.size); + ds_put_char(string, '"'); +} + static void ofp_print_nxt_tun_id_from_cookie(struct ds *string, const struct nxt_tun_id_cookie *ntic) @@ -1450,6 +1481,24 @@ ofp_print_nxt_tun_id_from_cookie(struct ds *string, ds_put_format(string, " set=%"PRIu8, ntic->set); } +static void +ofp_print_nxt_role_message(struct ds *string, + const struct nx_role_request *nrr) +{ + unsigned int role = ntohl(nrr->role); + + ds_put_cstr(string, " role="); + if (role == NX_ROLE_OTHER) { + ds_put_cstr(string, "other"); + } else if (role == NX_ROLE_MASTER) { + ds_put_cstr(string, "master"); + } else if (role == NX_ROLE_SLAVE) { + ds_put_cstr(string, "slave"); + } else { + ds_put_format(string, "%u", role); + } +} + static void ofp_print_nxt_set_flow_format(struct ds *string, const struct nxt_set_flow_format *nsff) @@ -1545,13 +1594,11 @@ ofp_to_string__(const struct ofp_header *oh, break; case OFPUTIL_OFPST_FLOW_REQUEST: - ofp_print_stats_request(string, oh); - ofp_print_ofpst_flow_request(string, oh, verbosity); - break; - + case OFPUTIL_NXST_FLOW_REQUEST: case OFPUTIL_OFPST_AGGREGATE_REQUEST: + case OFPUTIL_NXST_AGGREGATE_REQUEST: ofp_print_stats_request(string, oh); - ofp_print_ofpst_aggregate_request(string, oh, verbosity); + ofp_print_flow_stats_request(string, oh); break; case OFPUTIL_OFPST_TABLE_REQUEST: @@ -1600,7 +1647,7 @@ ofp_to_string__(const struct ofp_header *oh, case OFPUTIL_NXT_STATUS_REQUEST: case OFPUTIL_NXT_STATUS_REPLY: - /* XXX */ + ofp_print_nxt_status_message(string, oh); break; case OFPUTIL_NXT_TUN_ID_FROM_COOKIE: @@ -1609,7 +1656,7 @@ ofp_to_string__(const struct ofp_header *oh, case OFPUTIL_NXT_ROLE_REQUEST: case OFPUTIL_NXT_ROLE_REPLY: - /* XXX */ + ofp_print_nxt_role_message(string, msg); break; case OFPUTIL_NXT_SET_FLOW_FORMAT: @@ -1621,8 +1668,6 @@ ofp_to_string__(const struct ofp_header *oh, break; case OFPUTIL_NXT_FLOW_REMOVED: - case OFPUTIL_NXST_FLOW_REQUEST: - case OFPUTIL_NXST_AGGREGATE_REQUEST: /* XXX */ break; @@ -1631,7 +1676,8 @@ ofp_to_string__(const struct ofp_header *oh, break; case OFPUTIL_NXST_AGGREGATE_REPLY: - /* XXX */ + ofp_print_stats_reply(string, oh); + ofp_print_nxst_aggregate_reply(string, oh); break; } }