]>
Commit | Line | Data |
---|---|---|
a14bc59f | 1 | /* |
e0edde6f | 2 | * Copyright (c) 2009, 2010, 2011 Nicira, Inc. |
a14bc59f BP |
3 | * |
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: | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
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. | |
15 | */ | |
16 | ||
064af421 BP |
17 | #include <config.h> |
18 | #include "flow.h" | |
19 | #include <errno.h> | |
20 | #include <stdlib.h> | |
21 | #include <string.h> | |
844dff32 | 22 | #include "classifier.h" |
064af421 BP |
23 | #include "openflow/openflow.h" |
24 | #include "timeval.h" | |
25 | #include "ofpbuf.h" | |
26 | #include "ofp-print.h" | |
844dff32 | 27 | #include "ofp-util.h" |
064af421 BP |
28 | #include "pcap.h" |
29 | #include "util.h" | |
30 | #include "vlog.h" | |
31 | ||
32 | #undef NDEBUG | |
33 | #include <assert.h> | |
34 | ||
35 | int | |
67a4917b | 36 | main(int argc OVS_UNUSED, char *argv[]) |
064af421 BP |
37 | { |
38 | struct ofp_match expected_match; | |
39 | FILE *flows, *pcap; | |
40 | int retval; | |
41 | int n = 0, errors = 0; | |
42 | ||
43 | set_program_name(argv[0]); | |
064af421 BP |
44 | |
45 | flows = stdin; | |
46 | pcap = fdopen(3, "rb"); | |
47 | if (!pcap) { | |
48 | ovs_fatal(errno, "failed to open fd 3 for reading"); | |
49 | } | |
50 | ||
51 | retval = pcap_read_header(pcap); | |
52 | if (retval) { | |
53 | ovs_fatal(retval > 0 ? retval : 0, "reading pcap header failed"); | |
54 | } | |
55 | ||
56 | while (fread(&expected_match, sizeof expected_match, 1, flows)) { | |
57 | struct ofpbuf *packet; | |
58 | struct ofp_match extracted_match; | |
844dff32 | 59 | struct cls_rule rule; |
ae412e7d | 60 | struct flow flow; |
064af421 BP |
61 | |
62 | n++; | |
63 | ||
64 | retval = pcap_read(pcap, &packet); | |
65 | if (retval == EOF) { | |
66 | ovs_fatal(0, "unexpected end of file reading pcap file"); | |
67 | } else if (retval) { | |
68 | ovs_fatal(retval, "error reading pcap file"); | |
69 | } | |
70 | ||
abff858b | 71 | flow_extract(packet, 0, 0, 1, &flow); |
844dff32 | 72 | cls_rule_init_exact(&flow, 0, &rule); |
b78f6b77 | 73 | ofputil_cls_rule_to_match(&rule, &extracted_match); |
064af421 BP |
74 | |
75 | if (memcmp(&expected_match, &extracted_match, sizeof expected_match)) { | |
76 | char *exp_s = ofp_match_to_string(&expected_match, 2); | |
77 | char *got_s = ofp_match_to_string(&extracted_match, 2); | |
78 | errors++; | |
79 | printf("mismatch on packet #%d (1-based).\n", n); | |
80 | printf("Packet:\n"); | |
c499c75d | 81 | ofp_print_packet(stdout, packet->data, packet->size); |
50f06e16 | 82 | ovs_hex_dump(stdout, packet->data, packet->size, 0, true); |
7257b535 | 83 | cls_rule_print(&rule); |
064af421 BP |
84 | printf("Expected flow:\n%s\n", exp_s); |
85 | printf("Actually extracted flow:\n%s\n", got_s); | |
7257b535 BP |
86 | ovs_hex_dump(stdout, &expected_match, sizeof expected_match, 0, false); |
87 | ovs_hex_dump(stdout, &extracted_match, sizeof extracted_match, 0, false); | |
064af421 BP |
88 | printf("\n"); |
89 | free(exp_s); | |
90 | free(got_s); | |
91 | } | |
92 | ||
93 | ofpbuf_delete(packet); | |
94 | } | |
95 | printf("checked %d packets, %d errors\n", n, errors); | |
96 | return errors != 0; | |
97 | } | |
98 |