2 * Copyright (c) 2009, 2010 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include "openflow/openflow.h"
25 #include "ofp-print.h"
34 main(int argc OVS_UNUSED, char *argv[])
36 struct ofp_match expected_match;
39 int n = 0, errors = 0;
41 set_program_name(argv[0]);
46 pcap = fdopen(3, "rb");
48 ovs_fatal(errno, "failed to open fd 3 for reading");
51 retval = pcap_read_header(pcap);
53 ovs_fatal(retval > 0 ? retval : 0, "reading pcap header failed");
56 while (fread(&expected_match, sizeof expected_match, 1, flows)) {
57 struct ofpbuf *packet;
58 struct ofp_match extracted_match;
63 retval = pcap_read(pcap, &packet);
65 ovs_fatal(0, "unexpected end of file reading pcap file");
67 ovs_fatal(retval, "error reading pcap file");
70 flow_extract(packet, 1, &flow);
71 flow_to_match(&flow, 0, &extracted_match);
73 if (memcmp(&expected_match, &extracted_match, sizeof expected_match)) {
74 char *exp_s = ofp_match_to_string(&expected_match, 2);
75 char *got_s = ofp_match_to_string(&extracted_match, 2);
77 printf("mismatch on packet #%d (1-based).\n", n);
79 ofp_print_packet(stdout, packet->data, packet->size, packet->size);
80 printf("Expected flow:\n%s\n", exp_s);
81 printf("Actually extracted flow:\n%s\n", got_s);
87 ofpbuf_delete(packet);
89 printf("checked %d packets, %d errors\n", n, errors);