X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utilities%2Fovs-ofctl.c;h=e1f365b133a17e24737fa42b328b29a07a8cc58c;hb=eeba8e4fd3b9ae3c69fbf3ae9ef28a55184ac12a;hp=e7997c61e82b95639851baa67e424fbc785e071b;hpb=0199c526f17c7dbed579436f716a1feae22e192a;p=openvswitch diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index e7997c61..e1f365b1 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -84,15 +85,15 @@ parse_options(int argc, char *argv[]) VLOG_OPTION_ENUMS }; static struct option long_options[] = { - {"timeout", required_argument, 0, 't'}, - {"strict", no_argument, 0, OPT_STRICT}, - {"flow-format", required_argument, 0, 'F'}, - {"more", no_argument, 0, 'm'}, - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, + {"timeout", required_argument, NULL, 't'}, + {"strict", no_argument, NULL, OPT_STRICT}, + {"flow-format", required_argument, NULL, 'F'}, + {"more", no_argument, NULL, 'm'}, + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'V'}, VLOG_LONG_OPTIONS, - STREAM_SSL_LONG_OPTIONS - {0, 0, 0, 0}, + STREAM_SSL_LONG_OPTIONS, + {NULL, 0, NULL, 0}, }; char *short_options = long_options_to_short_options(long_options); @@ -198,17 +199,8 @@ static void run(int retval, const char *message, ...) if (retval) { va_list args; - fprintf(stderr, "%s: ", program_name); va_start(args, message); - vfprintf(stderr, message, args); - va_end(args); - if (retval == EOF) { - fputs(": unexpected end of file\n", stderr); - } else { - fprintf(stderr, ": %s\n", strerror(retval)); - } - - exit(EXIT_FAILURE); + ovs_fatal_valist(retval, message, args); } } @@ -523,8 +515,6 @@ negotiate_highest_flow_format(struct vconn *vconn, if (try_set_flow_format(vconn, NXFF_NXM)) { flow_format = NXFF_NXM; - } else if (try_set_flow_format(vconn, NXFF_TUN_ID_FROM_COOKIE)) { - flow_format = NXFF_TUN_ID_FROM_COOKIE; } else { flow_format = NXFF_OPENFLOW10; } @@ -552,7 +542,7 @@ do_dump_flows__(int argc, char *argv[], bool aggregate) parse_ofp_flow_stats_request_str(&fsr, aggregate, argc > 2 ? argv[2] : ""); open_vconn(argv[1], &vconn); - min_flow_format = ofputil_min_flow_format(&fsr.match, false, 0); + min_flow_format = ofputil_min_flow_format(&fsr.match); flow_format = negotiate_highest_flow_format(vconn, min_flow_format); request = ofputil_encode_flow_stats_request(&fsr, flow_format); dump_stats_transaction(argv[1], request); @@ -633,56 +623,67 @@ check_final_format_for_flow_mod(enum nx_flow_format flow_format) } static void -do_flow_mod__(int argc OVS_UNUSED, char *argv[], uint16_t command) +do_flow_mod_file__(int argc OVS_UNUSED, char *argv[], uint16_t command) { enum nx_flow_format flow_format; struct list requests; struct vconn *vconn; + FILE *file; + + file = !strcmp(argv[2], "-") ? stdin : fopen(argv[2], "r"); + if (file == NULL) { + ovs_fatal(errno, "%s: open", argv[2]); + } list_init(&requests); flow_format = set_initial_format_for_flow_mod(&requests); - parse_ofp_flow_mod_str(&requests, &flow_format, argc > 2 ? argv[2] : "", - command); - check_final_format_for_flow_mod(flow_format); - open_vconn(argv[1], &vconn); - transact_multiple_noreply(vconn, &requests); + while (parse_ofp_flow_mod_file(&requests, &flow_format, file, command)) { + check_final_format_for_flow_mod(flow_format); + transact_multiple_noreply(vconn, &requests); + } vconn_close(vconn); -} -static void -do_add_flow(int argc, char *argv[]) -{ - do_flow_mod__(argc, argv, OFPFC_ADD); + if (file != stdin) { + fclose(file); + } } static void -do_add_flows(int argc OVS_UNUSED, char *argv[]) +do_flow_mod__(int argc, char *argv[], uint16_t command) { enum nx_flow_format flow_format; struct list requests; struct vconn *vconn; - FILE *file; - file = !strcmp(argv[2], "-") ? stdin : fopen(argv[2], "r"); - if (file == NULL) { - ovs_fatal(errno, "%s: open", argv[2]); + if (argc > 2 && !strcmp(argv[2], "-")) { + do_flow_mod_file__(argc, argv, command); + return; } list_init(&requests); flow_format = set_initial_format_for_flow_mod(&requests); + parse_ofp_flow_mod_str(&requests, &flow_format, argc > 2 ? argv[2] : "", + command); + check_final_format_for_flow_mod(flow_format); + open_vconn(argv[1], &vconn); - while (parse_ofp_add_flow_file(&requests, &flow_format, file)) { - check_final_format_for_flow_mod(flow_format); - transact_multiple_noreply(vconn, &requests); - } + transact_multiple_noreply(vconn, &requests); vconn_close(vconn); +} - if (file != stdin) { - fclose(file); - } +static void +do_add_flow(int argc, char *argv[]) +{ + do_flow_mod__(argc, argv, OFPFC_ADD); +} + +static void +do_add_flows(int argc, char *argv[]) +{ + do_flow_mod_file__(argc, argv, OFPFC_ADD); } static void @@ -824,9 +825,9 @@ do_ping(int argc, char *argv[]) OFPT_ECHO_REQUEST, &request); random_bytes(rq_hdr + 1, payload); - gettimeofday(&start, NULL); + xgettimeofday(&start); run(vconn_transact(vconn, ofpbuf_clone(request), &reply), "transact"); - gettimeofday(&end, NULL); + xgettimeofday(&end); rpy_hdr = reply->data; if (reply->size != request->size @@ -871,7 +872,7 @@ do_benchmark(int argc OVS_UNUSED, char *argv[]) count, message_size, count * message_size); open_vconn(argv[1], &vconn); - gettimeofday(&start, NULL); + xgettimeofday(&start); for (i = 0; i < count; i++) { struct ofpbuf *request, *reply; struct ofp_header *rq_hdr; @@ -881,7 +882,7 @@ do_benchmark(int argc OVS_UNUSED, char *argv[]) run(vconn_transact(vconn, request, &reply), "transact"); ofpbuf_delete(reply); } - gettimeofday(&end, NULL); + xgettimeofday(&end); vconn_close(vconn); duration = ((1000*(double)(end.tv_sec - start.tv_sec)) @@ -1053,7 +1054,7 @@ read_flows_from_file(const char *filename, struct classifier *cls, int index) version->n_actions = actions.size / sizeof *version->actions; version->actions = ofpbuf_steal_data(&actions); - min_ff = ofputil_min_flow_format(&fm.cr, true, fm.cookie); + min_ff = ofputil_min_flow_format(&fm.cr); min_flow_format = MAX(min_flow_format, min_ff); check_final_format_for_flow_mod(min_flow_format); @@ -1119,8 +1120,7 @@ read_flows_from_switch(struct vconn *vconn, enum nx_flow_format flow_format, struct ofputil_flow_stats fs; int retval; - retval = ofputil_decode_flow_stats_reply(&fs, reply, - flow_format); + retval = ofputil_decode_flow_stats_reply(&fs, reply); if (retval) { if (retval != EOF) { ovs_fatal(0, "parse error in reply"); @@ -1139,8 +1139,6 @@ read_flows_from_switch(struct vconn *vconn, enum nx_flow_format flow_format, fte_insert(cls, &fs.rule, version, index); } - - osr = ofpbuf_at(reply, 0, sizeof *osr); } else { VLOG_DBG("received reply with xid %08"PRIx32" " "!= expected %08"PRIx32, recv_xid, send_xid); @@ -1339,7 +1337,7 @@ do_parse_flows(int argc OVS_UNUSED, char *argv[]) } list_init(&packets); - while (parse_ofp_add_flow_file(&packets, &flow_format, file)) { + while (parse_ofp_flow_mod_file(&packets, &flow_format, file, OFPFC_ADD)) { print_packet_list(&packets); } fclose(file);