X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=utilities%2Fovs-ofctl.c;h=dd5f4ba1f99047bda6afae22a579502ed0a37602;hb=eb5ee596d9cb52885fdb65ab3b534f64f22bb149;hp=2343240bb87095a0681ac445ee75a3a8f6685e30;hpb=1a126c0c6803db4e6c16ddc0a3369a6ad197d238;p=openvswitch diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 2343240b..dd5f4ba1 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -1453,6 +1453,7 @@ ofctl_probe(int argc OVS_UNUSED, char *argv[]) static void ofctl_packet_out(int argc, char *argv[]) { + enum ofputil_protocol protocol; struct ofputil_packet_out po; struct ofpbuf ofpacts; struct vconn *vconn; @@ -1468,7 +1469,7 @@ ofctl_packet_out(int argc, char *argv[]) po.ofpacts = ofpacts.data; po.ofpacts_len = ofpacts.size; - open_vconn(argv[1], &vconn); + protocol = open_vconn(argv[1], &vconn); for (i = 4; i < argc; i++) { struct ofpbuf *packet, *opo; const char *error_msg; @@ -1480,7 +1481,7 @@ ofctl_packet_out(int argc, char *argv[]) po.packet = packet->data; po.packet_len = packet->size; - opo = ofputil_encode_packet_out(&po); + opo = ofputil_encode_packet_out(&po, protocol); transact_noreply(vconn, opo); ofpbuf_delete(packet); } @@ -2334,20 +2335,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"); @@ -2364,7 +2395,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. */ @@ -2375,8 +2406,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