X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=utilities%2Fovs-ofctl.c;h=e62e646912de9f543be4cdc4ebbb7617d7f05a6e;hb=7685b7a9e5b3f6db6832e52e111000ff36d3acb4;hp=5eb8cf4aee7be25860a16e54a6d48c1fe45edf78;hpb=34582733d9aad82bba60f4bf986b62d58412502a;p=sliver-openvswitch.git diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 5eb8cf4ae..e62e64691 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -36,6 +36,7 @@ #include "compiler.h" #include "dirs.h" #include "dynamic-string.h" +#include "fatal-signal.h" #include "nx-match.h" #include "odp-util.h" #include "ofp-actions.h" @@ -113,7 +114,7 @@ main(int argc, char *argv[]) { set_program_name(argv[0]); parse_options(argc, argv); - signal(SIGPIPE, SIG_IGN); + fatal_ignore_sigpipe(); run_command(argc - optind, argv + optind, get_all_commands()); return 0; } @@ -325,7 +326,8 @@ usage(void) " benchmark TARGET N COUNT bandwidth of COUNT N-byte echos\n" "SWITCH or TARGET is an active OpenFlow connection method.\n" "\nOther commands:\n" - " ofp-parse FILE print messages read from FILE\n", + " ofp-parse FILE print messages read from FILE\n" + " ofp-parse-pcap PCAP print OpenFlow read from PCAP\n", program_name, program_name); vconn_usage(true, false, false); daemon_usage(); @@ -1539,7 +1541,7 @@ ofctl_monitor(int argc, char *argv[]) case OFP13_VERSION: break; default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -1601,7 +1603,7 @@ ofctl_packet_out(int argc, char *argv[]) struct vconn *vconn; char *error; int i; - enum ofputil_protocol usable_protocols; /* TODO: Use in proto selection */ + enum ofputil_protocol usable_protocols; /* XXX: Use in proto selection */ ofpbuf_init(&ofpacts, 64); error = parse_ofpacts(argv[3], &ofpacts, &usable_protocols); @@ -1825,6 +1827,93 @@ ofctl_ofp_parse(int argc OVS_UNUSED, char *argv[]) } } +static bool +is_openflow_port(ovs_be16 port_, char *ports[]) +{ + uint16_t port = ntohs(port_); + if (ports[0]) { + int i; + + for (i = 0; ports[i]; i++) { + if (port == atoi(ports[i])) { + return true; + } + } + return false; + } else { + return port == OFP_PORT || port == OFP_OLD_PORT; + } +} + +static void +ofctl_ofp_parse_pcap(int argc OVS_UNUSED, char *argv[]) +{ + struct tcp_reader *reader; + FILE *file; + int error; + bool first; + + file = ovs_pcap_open(argv[1], "rb"); + if (!file) { + ovs_fatal(errno, "%s: open failed", argv[1]); + } + + reader = tcp_reader_open(); + first = true; + for (;;) { + struct ofpbuf *packet; + long long int when; + struct flow flow; + const struct pkt_metadata md = PKT_METADATA_INITIALIZER(ODPP_NONE); + + error = ovs_pcap_read(file, &packet, &when); + if (error) { + break; + } + flow_extract(packet, &md, &flow); + if (flow.dl_type == htons(ETH_TYPE_IP) + && flow.nw_proto == IPPROTO_TCP + && (is_openflow_port(flow.tp_src, argv + 2) || + is_openflow_port(flow.tp_dst, argv + 2))) { + struct ofpbuf *payload = tcp_reader_run(reader, &flow, packet); + if (payload) { + while (payload->size >= sizeof(struct ofp_header)) { + const struct ofp_header *oh; + int length; + + /* Align OpenFlow on 8-byte boundary for safe access. */ + ofpbuf_shift(payload, -((intptr_t) payload->data & 7)); + + oh = payload->data; + length = ntohs(oh->length); + if (payload->size < length) { + break; + } + + if (!first) { + putchar('\n'); + } + first = false; + + if (timestamp) { + char *s = xastrftime_msec("%H:%M:%S.### ", when, true); + fputs(s, stdout); + free(s); + } + + printf(IP_FMT".%"PRIu16" > "IP_FMT".%"PRIu16":\n", + IP_ARGS(flow.nw_src), ntohs(flow.tp_src), + IP_ARGS(flow.nw_dst), ntohs(flow.tp_dst)); + ofp_print(stdout, payload->data, length, verbosity + 1); + ofpbuf_pull(payload, length); + } + } + } + ofpbuf_delete(packet); + } + tcp_reader_close(reader); +} + static void ofctl_ping(int argc, char *argv[]) { @@ -2165,13 +2254,13 @@ fte_free_all(struct classifier *cls) struct cls_cursor cursor; struct fte *fte, *next; - ovs_rwlock_wrlock(&cls->rwlock); + fat_rwlock_wrlock(&cls->rwlock); cls_cursor_init(&cursor, cls, NULL); CLS_CURSOR_FOR_EACH_SAFE (fte, next, rule, &cursor) { classifier_remove(cls, &fte->rule); fte_free(fte); } - ovs_rwlock_unlock(&cls->rwlock); + fat_rwlock_unlock(&cls->rwlock); classifier_destroy(cls); } @@ -2190,9 +2279,9 @@ fte_insert(struct classifier *cls, const struct match *match, cls_rule_init(&fte->rule, match, priority); fte->versions[index] = version; - ovs_rwlock_wrlock(&cls->rwlock); + fat_rwlock_wrlock(&cls->rwlock); old = fte_from_cls_rule(classifier_replace(cls, &fte->rule)); - ovs_rwlock_unlock(&cls->rwlock); + fat_rwlock_unlock(&cls->rwlock); if (old) { fte_version_free(old->versions[index]); fte->versions[!index] = old->versions[!index]; @@ -2403,7 +2492,7 @@ ofctl_replace_flows(int argc OVS_UNUSED, char *argv[]) list_init(&requests); /* Delete flows that exist on the switch but not in the file. */ - ovs_rwlock_rdlock(&cls.rwlock); + fat_rwlock_rdlock(&cls.rwlock); cls_cursor_init(&cursor, &cls, NULL); CLS_CURSOR_FOR_EACH (fte, rule, &cursor) { struct fte_version *file_ver = fte->versions[FILE_IDX]; @@ -2427,7 +2516,7 @@ ofctl_replace_flows(int argc OVS_UNUSED, char *argv[]) fte_make_flow_mod(fte, FILE_IDX, OFPFC_ADD, protocol, &requests); } } - ovs_rwlock_unlock(&cls.rwlock); + fat_rwlock_unlock(&cls.rwlock); transact_multiple_noreply(vconn, &requests); vconn_close(vconn); @@ -2469,7 +2558,7 @@ ofctl_diff_flows(int argc OVS_UNUSED, char *argv[]) ds_init(&a_s); ds_init(&b_s); - ovs_rwlock_rdlock(&cls.rwlock); + fat_rwlock_rdlock(&cls.rwlock); cls_cursor_init(&cursor, &cls, NULL); CLS_CURSOR_FOR_EACH (fte, rule, &cursor) { struct fte_version *a = fte->versions[0]; @@ -2489,7 +2578,7 @@ ofctl_diff_flows(int argc OVS_UNUSED, char *argv[]) } } } - ovs_rwlock_unlock(&cls.rwlock); + fat_rwlock_unlock(&cls.rwlock); ds_destroy(&a_s); ds_destroy(&b_s); @@ -3112,7 +3201,7 @@ ofctl_parse_pcap(int argc OVS_UNUSED, char *argv[]) { FILE *pcap; - pcap = pcap_open(argv[1], "rb"); + pcap = ovs_pcap_open(argv[1], "rb"); if (!pcap) { ovs_fatal(errno, "%s: open failed", argv[1]); } @@ -3120,16 +3209,17 @@ ofctl_parse_pcap(int argc OVS_UNUSED, char *argv[]) for (;;) { struct ofpbuf *packet; struct flow flow; + const struct pkt_metadata md = PKT_METADATA_INITIALIZER(ODPP_NONE); int error; - error = pcap_read(pcap, &packet); + error = ovs_pcap_read(pcap, &packet, NULL); if (error == EOF) { break; } else if (error) { ovs_fatal(error, "%s: read failed", argv[1]); } - flow_extract(packet, 0, 0, NULL, NULL, &flow); + flow_extract(packet, &md, &flow); flow_print(stdout, &flow); putchar('\n'); ofpbuf_delete(packet); @@ -3365,11 +3455,13 @@ static const struct command all_commands[] = { { "mod-table", 3, 3, ofctl_mod_table }, { "get-frags", 1, 1, ofctl_get_frags }, { "set-frags", 2, 2, ofctl_set_frags }, - { "ofp-parse", 1, 1, ofctl_ofp_parse }, { "probe", 1, 1, ofctl_probe }, { "ping", 1, 2, ofctl_ping }, { "benchmark", 3, 3, ofctl_benchmark }, + { "ofp-parse", 1, 1, ofctl_ofp_parse }, + { "ofp-parse-pcap", 1, INT_MAX, ofctl_ofp_parse_pcap }, + { "add-group", 1, 2, ofctl_add_group }, { "add-groups", 1, 2, ofctl_add_groups }, { "mod-group", 1, 2, ofctl_mod_group },