]> git.proxmox.com Git - mirror_ovs.git/blob - tests/test-flows.c
tests: Log commands being executed for async message control test.
[mirror_ovs.git] / tests / test-flows.c
1 /*
2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2017 Nicira, Inc.
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
17 #include <config.h>
18 #undef NDEBUG
19 #include "flow.h"
20 #include <assert.h>
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include "classifier.h"
25 #include "openflow/openflow.h"
26 #include "openvswitch/ofp-match.h"
27 #include "openvswitch/ofp-print.h"
28 #include "openvswitch/ofpbuf.h"
29 #include "openvswitch/vlog.h"
30 #include "ovstest.h"
31 #include "dp-packet.h"
32 #include "pcap-file.h"
33 #include "timeval.h"
34 #include "util.h"
35
36 static void
37 test_flows_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
38 {
39 struct ofp10_match expected_match;
40 FILE *flows;
41 struct pcap_file *pcap;
42 int retval;
43 int n = 0, errors = 0;
44
45 set_program_name(argv[0]);
46
47 flows = fopen(argv[1], "rb");
48 if (!flows) {
49 ovs_fatal(errno, "failed to open %s", argv[1]);
50 }
51 pcap = ovs_pcap_open(argv[2], "rb");
52 if (!pcap) {
53 ovs_fatal(errno, "failed to open %s", argv[2]);
54 }
55
56 while (fread(&expected_match, sizeof expected_match, 1, flows)) {
57 struct dp_packet *packet;
58 struct ofp10_match extracted_match;
59 struct match match;
60 struct flow flow;
61 n++;
62
63 retval = ovs_pcap_read(pcap, &packet, NULL);
64 if (retval == EOF) {
65 ovs_fatal(0, "unexpected end of file reading pcap file");
66 } else if (retval) {
67 ovs_fatal(retval, "error reading pcap file");
68 }
69
70 flow_extract(packet, &flow);
71 flow.in_port.ofp_port = u16_to_ofp(1);
72
73 match_wc_init(&match, &flow);
74 ofputil_match_to_ofp10_match(&match, &extracted_match);
75
76 if (memcmp(&expected_match, &extracted_match, sizeof expected_match)) {
77 char *exp_s = ofp10_match_to_string(&expected_match, NULL, 2);
78 char *got_s = ofp10_match_to_string(&extracted_match, NULL, 2);
79 errors++;
80 printf("mismatch on packet #%d (1-based).\n", n);
81 printf("Packet:\n");
82 ofp_print_packet(stdout, dp_packet_data(packet), dp_packet_size(packet), htonl(PT_ETH));
83 ovs_hex_dump(stdout, dp_packet_data(packet), dp_packet_size(packet), 0, true);
84 match_print(&match, NULL);
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);
89 printf("\n");
90 free(exp_s);
91 free(got_s);
92 }
93
94 dp_packet_delete(packet);
95 }
96 ovs_pcap_close(pcap);
97 printf("checked %d packets, %d errors\n", n, errors);
98 exit(errors != 0);
99 }
100
101 OVSTEST_REGISTER("test-flows", test_flows_main);