2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 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.
24 #include "classifier.h"
25 #include "openflow/openflow.h"
26 #include "openvswitch/ofp-print.h"
27 #include "openvswitch/ofp-util.h"
28 #include "openvswitch/ofpbuf.h"
29 #include "openvswitch/vlog.h"
31 #include "dp-packet.h"
32 #include "pcap-file.h"
37 test_flows_main(int argc OVS_UNUSED
, char *argv
[] OVS_UNUSED
)
39 struct ofp10_match expected_match
;
42 int n
= 0, errors
= 0;
44 set_program_name(argv
[0]);
46 flows
= fopen(argv
[1], "rb");
48 ovs_fatal(errno
, "failed to open %s", argv
[1]);
50 pcap
= fopen(argv
[2], "rb");
52 ovs_fatal(errno
, "failed to open %s", argv
[2]);
55 retval
= ovs_pcap_read_header(pcap
);
57 ovs_fatal(retval
> 0 ? retval
: 0, "reading pcap header failed");
60 while (fread(&expected_match
, sizeof expected_match
, 1, flows
)) {
61 struct dp_packet
*packet
;
62 struct ofp10_match extracted_match
;
67 retval
= ovs_pcap_read(pcap
, &packet
, NULL
);
69 ovs_fatal(0, "unexpected end of file reading pcap file");
71 ovs_fatal(retval
, "error reading pcap file");
74 flow_extract(packet
, &flow
);
75 flow
.in_port
.ofp_port
= u16_to_ofp(1);
77 match_wc_init(&match
, &flow
);
78 ofputil_match_to_ofp10_match(&match
, &extracted_match
);
80 if (memcmp(&expected_match
, &extracted_match
, sizeof expected_match
)) {
81 char *exp_s
= ofp10_match_to_string(&expected_match
, 2);
82 char *got_s
= ofp10_match_to_string(&extracted_match
, 2);
84 printf("mismatch on packet #%d (1-based).\n", n
);
86 ofp_print_packet(stdout
, dp_packet_data(packet
), dp_packet_size(packet
));
87 ovs_hex_dump(stdout
, dp_packet_data(packet
), dp_packet_size(packet
), 0, true);
89 printf("Expected flow:\n%s\n", exp_s
);
90 printf("Actually extracted flow:\n%s\n", got_s
);
91 ovs_hex_dump(stdout
, &expected_match
, sizeof expected_match
, 0, false);
92 ovs_hex_dump(stdout
, &extracted_match
, sizeof extracted_match
, 0, false);
98 dp_packet_delete(packet
);
100 printf("checked %d packets, %d errors\n", n
, errors
);
104 OVSTEST_REGISTER("test-flows", test_flows_main
);