From: Ben Pfaff Date: Mon, 23 Sep 2013 17:28:14 +0000 (-0700) Subject: ovs-ofctl: Add undocumented "parse-pcap" command, for testing. X-Git-Tag: sliver-openvswitch-2.0.90-1~8^2~15 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=14249c02baecf418ebf28dba6eb71dbdbf02d701;p=sliver-openvswitch.git ovs-ofctl: Add undocumented "parse-pcap" command, for testing. Signed-off-by: Ben Pfaff --- diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index c2cc1f6d4..1cd23e6a9 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -50,6 +50,7 @@ #include "openflow/nicira-ext.h" #include "openflow/openflow.h" #include "packets.h" +#include "pcap-file.h" #include "poll-loop.h" #include "random.h" #include "stream-ssl.h" @@ -3076,6 +3077,36 @@ ofctl_parse_ofp11_instructions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) ds_destroy(&in); } +/* "parse-pcap PCAP": read packets from PCAP and print their flows. */ +static void +ofctl_parse_pcap(int argc OVS_UNUSED, char *argv[]) +{ + FILE *pcap; + + pcap = pcap_open(argv[1], "rb"); + if (!pcap) { + ovs_fatal(errno, "%s: open failed", argv[1]); + } + + for (;;) { + struct ofpbuf *packet; + struct flow flow; + int error; + + error = pcap_read(pcap, &packet); + if (error == EOF) { + break; + } else if (error) { + ovs_fatal(error, "%s: read failed", argv[1]); + } + + flow_extract(packet, 0, 0, NULL, NULL, &flow); + flow_print(stdout, &flow); + putchar('\n'); + ofpbuf_delete(packet); + } +} + /* "check-vlan VLAN_TCI VLAN_TCI_MASK": converts the specified vlan_tci and * mask values to and from various formats and prints the results. */ static void @@ -3329,6 +3360,7 @@ static const struct command all_commands[] = { { "parse-ofp11-match", 0, 0, ofctl_parse_ofp11_match }, { "parse-ofp11-actions", 0, 0, ofctl_parse_ofp11_actions }, { "parse-ofp11-instructions", 0, 0, ofctl_parse_ofp11_instructions }, + { "parse-pcap", 1, 1, ofctl_parse_pcap }, { "check-vlan", 2, 2, ofctl_check_vlan }, { "print-error", 1, 1, ofctl_print_error }, { "encode-error-reply", 2, 2, ofctl_encode_error_reply },