2 * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
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 "classifier.h"
23 #include "openflow/openflow.h"
26 #include "ofp-print.h"
28 #include "pcap-file.h"
36 main(int argc OVS_UNUSED, char *argv[])
38 struct ofp10_match expected_match;
41 int n = 0, errors = 0;
43 set_program_name(argv[0]);
46 pcap = fdopen(3, "rb");
48 ovs_fatal(errno, "failed to open fd 3 for reading");
51 retval = ovs_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 ofp10_match extracted_match;
61 union flow_in_port in_port_;
64 retval = ovs_pcap_read(pcap, &packet, NULL);
66 ovs_fatal(0, "unexpected end of file reading pcap file");
68 ovs_fatal(retval, "error reading pcap file");
71 in_port_.ofp_port = u16_to_ofp(1);
72 flow_extract(packet, 0, 0, NULL, &in_port_, &flow);
73 match_wc_init(&match, &flow);
74 ofputil_match_to_ofp10_match(&match, &extracted_match);
76 if (memcmp(&expected_match, &extracted_match, sizeof expected_match)) {
77 char *exp_s = ofp10_match_to_string(&expected_match, 2);
78 char *got_s = ofp10_match_to_string(&extracted_match, 2);
80 printf("mismatch on packet #%d (1-based).\n", n);
82 ofp_print_packet(stdout, packet->data, packet->size);
83 ovs_hex_dump(stdout, packet->data, packet->size, 0, true);
85 printf("Expected flow:\n%s\n", exp_s);
86 printf("Actually extracted flow:\n%s\n", got_s);
87 ovs_hex_dump(stdout, &expected_match, sizeof expected_match, 0, false);
88 ovs_hex_dump(stdout, &extracted_match, sizeof extracted_match, 0, false);
94 ofpbuf_delete(packet);
96 printf("checked %d packets, %d errors\n", n, errors);