X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fofp-print.c;h=d88a574cbb8eac69c42e25f340725082fcf8fd58;hb=406e37ecf554529e9380ef06863d85ccc94009d1;hp=26d11489fae7c333fcced08eaf97df02e0394d4e;hpb=e41a91300789b03398007ebdb6025ca9d94fec26;p=openvswitch diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 26d11489..d88a574c 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -30,6 +30,7 @@ #include "compiler.h" #include "dynamic-string.h" #include "flow.h" +#include "multipath.h" #include "nx-match.h" #include "ofp-util.h" #include "ofpbuf.h" @@ -184,6 +185,7 @@ static void ofp_print_port_name(struct ds *string, uint16_t port) ds_put_cstr(string, name); } + static void print_note(struct ds *string, const struct nx_action_note *nan) { @@ -200,15 +202,47 @@ print_note(struct ds *string, const struct nx_action_note *nan) } } +static int +nx_action_len(enum nx_action_subtype subtype) +{ + switch (subtype) { + case NXAST_SNAT__OBSOLETE: return -1; + case NXAST_RESUBMIT: return sizeof(struct nx_action_resubmit); + case NXAST_SET_TUNNEL: return sizeof(struct nx_action_set_tunnel); + case NXAST_DROP_SPOOFED_ARP: + return sizeof(struct nx_action_drop_spoofed_arp); + case NXAST_SET_QUEUE: return sizeof(struct nx_action_set_queue); + case NXAST_POP_QUEUE: return sizeof(struct nx_action_pop_queue); + case NXAST_REG_MOVE: return sizeof(struct nx_action_reg_move); + case NXAST_REG_LOAD: return sizeof(struct nx_action_reg_load); + case NXAST_NOTE: return -1; + case NXAST_SET_TUNNEL64: return sizeof(struct nx_action_set_tunnel64); + case NXAST_MULTIPATH: return sizeof(struct nx_action_multipath); + default: return -1; + } +} + static void ofp_print_nx_action(struct ds *string, const struct nx_action_header *nah) { uint16_t subtype = ntohs(nah->subtype); + int required_len = nx_action_len(subtype); + int len = ntohs(nah->len); + + if (required_len != -1 && required_len != len) { + ds_put_format(string, "***Nicira action %"PRIu16" wrong length: %d***", + subtype, len); + return; + } if (subtype <= TYPE_MAXIMUM(enum nx_action_subtype)) { + const struct nx_action_set_tunnel64 *nast64; const struct nx_action_set_tunnel *nast; const struct nx_action_set_queue *nasq; const struct nx_action_resubmit *nar; + const struct nx_action_reg_move *move; + const struct nx_action_reg_load *load; + const struct nx_action_multipath *nam; switch ((enum nx_action_subtype) subtype) { case NXAST_RESUBMIT: @@ -240,8 +274,24 @@ ofp_print_nx_action(struct ds *string, const struct nx_action_header *nah) return; case NXAST_REG_MOVE: + move = (const struct nx_action_reg_move *) nah; + nxm_format_reg_move(move, string); + return; + case NXAST_REG_LOAD: - /* XXX */ + load = (const struct nx_action_reg_load *) nah; + nxm_format_reg_load(load, string); + return; + + case NXAST_SET_TUNNEL64: + nast64 = (const struct nx_action_set_tunnel64 *) nah; + ds_put_format(string, "set_tunnel64:%#"PRIx64, + ntohll(nast64->tun_id)); + return; + + case NXAST_MULTIPATH: + nam = (const struct nx_action_multipath *) nah; + multipath_format(nam, string); return; case NXAST_SNAT__OBSOLETE: @@ -756,6 +806,7 @@ ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, enum ofputil_msg_code code, int verbosity) { struct flow_mod fm; + bool need_priority; int error; error = ofputil_decode_flow_mod(&fm, oh, NXFF_OPENFLOW10); @@ -788,16 +839,26 @@ ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, ds_put_char(s, ' '); if (verbosity >= 3 && code == OFPUTIL_OFPT_FLOW_MOD) { const struct ofp_flow_mod *ofm = (const struct ofp_flow_mod *) oh; - ofp_print_match(s, &ofm->match, verbosity); + + /* ofp_print_match() doesn't print priority. */ + need_priority = true; } else if (verbosity >= 3 && code == OFPUTIL_NXT_FLOW_MOD) { const struct nx_flow_mod *nfm = (const struct nx_flow_mod *) oh; const void *nxm = nfm + 1; - char *nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len)); + char *nxm_s; + + nxm_s = nx_match_to_string(nxm, ntohs(nfm->match_len)); ds_put_cstr(s, nxm_s); free(nxm_s); + + /* nx_match_to_string() doesn't print priority. */ + need_priority = true; } else { cls_rule_format(&fm.cr, s); + + /* cls_rule_format() does print priority. */ + need_priority = false; } if (ds_last(s) != ' ') { @@ -812,7 +873,7 @@ ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, if (fm.hard_timeout != OFP_FLOW_PERMANENT) { ds_put_format(s, "hard:%"PRIu16" ", fm.hard_timeout); } - if (fm.cr.priority != OFP_DEFAULT_PRIORITY && verbosity >= 3) { + if (fm.cr.priority != OFP_DEFAULT_PRIORITY && need_priority) { ds_put_format(s, "pri:%"PRIu16" ", fm.cr.priority); } if (fm.buffer_id != UINT32_MAX) { @@ -983,7 +1044,7 @@ ofp_print_error(struct ds *string, int error) if (string->length) { ds_put_char(string, ' '); } - ds_put_format(string, " ***decode error type:%d(%s) code:%d(%s)***", + ds_put_format(string, " ***decode error type:%d(%s) code:%d(%s)***\n", type, lookup_error_type(type), code, lookup_error_code(type, code)); } @@ -1187,6 +1248,8 @@ ofp_print_nxst_flow_reply(struct ds *string, const struct ofp_header *oh) int match_len; int error; + ds_put_char(string, '\n'); + fs = ofpbuf_try_pull(&b, sizeof *fs); if (!fs) { ds_put_format(string, " ***%td leftover bytes at end***", b.size); @@ -1212,7 +1275,6 @@ ofp_print_nxst_flow_reply(struct ds *string, const struct ofp_header *oh) 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)); ds_put_format(string, "n_bytes=%"PRIu64", ", ntohll(fs->byte_count)); @@ -1242,7 +1304,6 @@ ofp_print_nxst_flow_reply(struct ds *string, const struct ofp_header *oh) ds_put_char(string, ' '); ofp_print_actions(string, (const struct ofp_action_header *) actions, n_actions * sizeof *actions); - ds_put_char(string, '\n'); } } @@ -1667,14 +1728,17 @@ 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 < sizeof(struct ofp_header)) { - ds_put_cstr(&string, "OpenFlow packet too short:\n"); + 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 %zu bytes):\n", + len); } else if (oh->version != OFP_VERSION) { ds_put_format(&string, "Bad OpenFlow version %"PRIu8":\n", oh->version); } else if (ntohs(oh->length) > len) { ds_put_format(&string, - "(***truncated to %zu bytes from %"PRIu16"***)", + "(***truncated to %zu bytes from %"PRIu16"***)\n", len, ntohs(oh->length)); } else if (ntohs(oh->length) < len) { ds_put_format(&string,