6 #include "openflow/openflow.h"
18 main(int argc UNUSED, char *argv[])
20 struct ofp_match expected_match;
23 int n = 0, errors = 0;
25 set_program_name(argv[0]);
30 pcap = fdopen(3, "rb");
32 ovs_fatal(errno, "failed to open fd 3 for reading");
35 retval = pcap_read_header(pcap);
37 ovs_fatal(retval > 0 ? retval : 0, "reading pcap header failed");
40 while (fread(&expected_match, sizeof expected_match, 1, flows)) {
41 struct ofpbuf *packet;
42 struct ofp_match extracted_match;
47 retval = pcap_read(pcap, &packet);
49 ovs_fatal(0, "unexpected end of file reading pcap file");
51 ovs_fatal(retval, "error reading pcap file");
54 flow_extract(packet, 1, &flow);
55 flow_to_match(&flow, 0, &extracted_match);
57 if (memcmp(&expected_match, &extracted_match, sizeof expected_match)) {
58 char *exp_s = ofp_match_to_string(&expected_match, 2);
59 char *got_s = ofp_match_to_string(&extracted_match, 2);
61 printf("mismatch on packet #%d (1-based).\n", n);
63 ofp_print_packet(stdout, packet->data, packet->size, packet->size);
64 printf("Expected flow:\n%s\n", exp_s);
65 printf("Actually extracted flow:\n%s\n", got_s);
71 ofpbuf_delete(packet);
73 printf("checked %d packets, %d errors\n", n, errors);