X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=utilities%2Fovs-ofctl.c;h=cd42b969c43ca21a55f21bcda88d73fc5707f8b0;hb=8812ec2cdde70b6fae5163c65c7706bed08190c7;hp=258115ec55fa54e5c0832762c1e43232cad83dde;hpb=e2b9ac44c82590c2a9a27bff79ae43899277f703;p=openvswitch diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 258115ec..cd42b969 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -1217,7 +1217,7 @@ ofctl_barrier(struct unixctl_conn *conn, int argc OVS_UNUSED, return; } - msg = ofputil_encode_barrier_request(); + msg = ofputil_encode_barrier_request(vconn_get_version(aux->vconn)); error = vconn_send_block(aux->vconn, msg); if (error) { ofpbuf_delete(msg); @@ -1440,8 +1440,8 @@ ofctl_probe(int argc OVS_UNUSED, char *argv[]) struct vconn *vconn; struct ofpbuf *reply; - request = make_echo_request(); open_vconn(argv[1], &vconn); + request = make_echo_request(vconn_get_version(vconn)); run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]); if (reply->size != sizeof(struct ofp_header)) { ovs_fatal(0, "reply does not match request"); @@ -1843,7 +1843,7 @@ read_flows_from_file(const char *filename, struct classifier *cls, int index) version->cookie = fm.new_cookie; version->idle_timeout = fm.idle_timeout; version->hard_timeout = fm.hard_timeout; - version->flags = fm.flags & (OFPFF_SEND_FLOW_REM | OFPFF_EMERG); + version->flags = fm.flags & (OFPFF_SEND_FLOW_REM | OFPFF10_EMERG); version->ofpacts = fm.ofpacts; version->ofpacts_len = fm.ofpacts_len; @@ -1868,8 +1868,8 @@ recv_flow_stats_reply(struct vconn *vconn, ovs_be32 send_xid, struct ofpbuf *reply = *replyp; for (;;) { - ovs_be16 flags; int retval; + bool more; /* Get a flow stats reply message, if we don't already have one. */ if (!reply) { @@ -1897,10 +1897,10 @@ recv_flow_stats_reply(struct vconn *vconn, ovs_be32 send_xid, return true; case EOF: - flags = ((const struct ofp_stats_msg *) reply->l2)->flags; + more = ofpmp_more(reply->l2); ofpbuf_delete(reply); reply = NULL; - if (!(flags & htons(OFPSF_REPLY_MORE))) { + if (!more) { *replyp = NULL; return false; } @@ -2182,28 +2182,45 @@ ofctl_parse_nxm__(bool oxm) /* Convert string to nx_match. */ ofpbuf_init(&nx_match, 0); - match_len = nx_match_from_string(ds_cstr(&in), &nx_match); + if (oxm) { + match_len = oxm_match_from_string(ds_cstr(&in), &nx_match); + } else { + match_len = nx_match_from_string(ds_cstr(&in), &nx_match); + } /* Convert nx_match to cls_rule. */ if (strict) { - error = nx_pull_match(&nx_match, match_len, 0, &rule, - &cookie, &cookie_mask); + if (oxm) { + error = oxm_pull_match(&nx_match, 0, &rule); + } else { + error = nx_pull_match(&nx_match, match_len, 0, &rule, + &cookie, &cookie_mask); + } } else { - error = nx_pull_match_loose(&nx_match, match_len, 0, &rule, - &cookie, &cookie_mask); + if (oxm) { + error = oxm_pull_match_loose(&nx_match, 0, &rule); + } else { + error = nx_pull_match_loose(&nx_match, match_len, 0, &rule, + &cookie, &cookie_mask); + } } + if (!error) { char *out; /* Convert cls_rule back to nx_match. */ ofpbuf_uninit(&nx_match); ofpbuf_init(&nx_match, 0); - match_len = nx_put_match(&nx_match, oxm, &rule, - cookie, cookie_mask); + if (oxm) { + match_len = oxm_put_match(&nx_match, &rule); + out = oxm_match_to_string(nx_match.data, match_len); + } else { + match_len = nx_put_match(&nx_match, &rule, + cookie, cookie_mask); + out = nx_match_to_string(nx_match.data, match_len); + } - /* Convert nx_match to string. */ - out = nx_match_to_string(nx_match.data, match_len); puts(out); free(out); } else { @@ -2317,20 +2334,50 @@ ofctl_parse_ofp10_actions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) /* "parse-ofp10-match": reads a series of ofp10_match specifications as hex * bytes from stdin, converts them to cls_rules, prints them as strings on * stdout, and then converts them back to hex bytes and prints any differences - * from the input. */ + * from the input. + * + * The input hex bytes may contain "x"s to represent "don't-cares", bytes whose + * values are ignored in the input and will be set to zero when OVS converts + * them back to hex bytes. ovs-ofctl actually sets "x"s to random bits when + * it does the conversion to hex, to ensure that in fact they are ignored. */ static void ofctl_parse_ofp10_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { + struct ds expout; struct ds in; ds_init(&in); + ds_init(&expout); while (!ds_get_preprocessed_line(&in, stdin)) { - struct ofpbuf match_in; + struct ofpbuf match_in, match_expout; struct ofp10_match match_out; struct ofp10_match match_normal; struct cls_rule rule; + char *p; + + /* Parse hex bytes to use for expected output. */ + ds_clear(&expout); + ds_put_cstr(&expout, ds_cstr(&in)); + for (p = ds_cstr(&expout); *p; p++) { + if (*p == 'x') { + *p = '0'; + } + } + ofpbuf_init(&match_expout, 0); + if (ofpbuf_put_hex(&match_expout, ds_cstr(&expout), NULL)[0] != '\0') { + ovs_fatal(0, "Trailing garbage in hex data"); + } + if (match_expout.size != sizeof(struct ofp10_match)) { + ovs_fatal(0, "Input is %zu bytes, expected %zu", + match_expout.size, sizeof(struct ofp10_match)); + } - /* Parse hex bytes. */ + /* Parse hex bytes for input. */ + for (p = ds_cstr(&in); *p; p++) { + if (*p == 'x') { + *p = "0123456789abcdef"[random_uint32() & 0xf]; + } + } ofpbuf_init(&match_in, 0); if (ofpbuf_put_hex(&match_in, ds_cstr(&in), NULL)[0] != '\0') { ovs_fatal(0, "Trailing garbage in hex data"); @@ -2347,7 +2394,7 @@ ofctl_parse_ofp10_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) /* Convert back to ofp10_match and print differences from input. */ ofputil_cls_rule_to_ofp10_match(&rule, &match_out); - print_differences("", match_in.data, match_in.size, + print_differences("", match_expout.data, match_expout.size, &match_out, sizeof match_out); /* Normalize, then convert and compare again. */ @@ -2358,8 +2405,10 @@ ofctl_parse_ofp10_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) putchar('\n'); ofpbuf_uninit(&match_in); + ofpbuf_uninit(&match_expout); } ds_destroy(&in); + ds_destroy(&expout); } /* "parse-ofp11-match": reads a series of ofp11_match specifications as hex @@ -2568,7 +2617,7 @@ ofctl_check_vlan(int argc OVS_UNUSED, char *argv[]) /* Convert to and from NXM. */ ofpbuf_init(&nxm, 0); - nxm_match_len = nx_put_match(&nxm, false, &rule, htonll(0), htonll(0)); + nxm_match_len = nx_put_match(&nxm, &rule, htonll(0), htonll(0)); nxm_s = nx_match_to_string(nxm.data, nxm_match_len); error = nx_pull_match(&nxm, nxm_match_len, 0, &nxm_rule, NULL, NULL); printf("NXM: %s -> ", nxm_s); @@ -2584,9 +2633,9 @@ ofctl_check_vlan(int argc OVS_UNUSED, char *argv[]) /* Convert to and from OXM. */ ofpbuf_init(&nxm, 0); - nxm_match_len = nx_put_match(&nxm, true, &rule, htonll(0), htonll(0)); - nxm_s = nx_match_to_string(nxm.data, nxm_match_len); - error = nx_pull_match(&nxm, nxm_match_len, 0, &nxm_rule, NULL, NULL); + nxm_match_len = oxm_put_match(&nxm, &rule); + nxm_s = oxm_match_to_string(nxm.data, nxm_match_len); + error = oxm_pull_match(&nxm, 0, &nxm_rule); printf("OXM: %s -> ", nxm_s); if (error) { printf("%s\n", ofperr_to_string(error)); @@ -2643,17 +2692,14 @@ ofctl_print_error(int argc OVS_UNUSED, char *argv[]) } for (version = 0; version <= UINT8_MAX; version++) { - const struct ofperr_domain *domain; - - domain = ofperr_domain_from_version(version); - if (!domain) { + const char *name = ofperr_domain_get_name(version); + if (!name) { continue; } - printf("%s: %d,%d\n", - ofperr_domain_get_name(domain), - ofperr_get_type(error, domain), - ofperr_get_code(error, domain)); + ofperr_domain_get_name(version), + ofperr_get_type(error, version), + ofperr_get_code(error, version)); } }