]> git.proxmox.com Git - mirror_ovs.git/blame - tests/test-flows.c
tests/ovs-monitor-ipsec: Remove --no-wait -vreconnect:emer from ovs-vsctl.
[mirror_ovs.git] / tests / test-flows.c
CommitLineData
a14bc59f 1/*
eadd1644 2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 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 17#include <config.h>
3f636c7e 18#undef NDEBUG
064af421 19#include "flow.h"
3f636c7e 20#include <assert.h>
064af421
BP
21#include <errno.h>
22#include <stdlib.h>
23#include <string.h>
844dff32 24#include "classifier.h"
3f636c7e 25#include "openflow/openflow.h"
25d436fb
BW
26#include "openvswitch/ofp-print.h"
27#include "openvswitch/ofp-util.h"
28#include "openvswitch/ofpbuf.h"
29#include "openvswitch/vlog.h"
3f636c7e 30#include "ovstest.h"
cf62fa4c 31#include "dp-packet.h"
2c78a3e6 32#include "pcap-file.h"
3f636c7e 33#include "timeval.h"
064af421 34#include "util.h"
064af421 35
eadd1644
AZ
36static void
37test_flows_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
064af421 38{
eec25dc1 39 struct ofp10_match expected_match;
064af421
BP
40 FILE *flows, *pcap;
41 int retval;
42 int n = 0, errors = 0;
43
44 set_program_name(argv[0]);
064af421 45
e60367e2
GS
46 flows = fopen(argv[1], "rb");
47 if (!flows) {
48 ovs_fatal(errno, "failed to open %s", argv[1]);
49 }
50 pcap = fopen(argv[2], "rb");
064af421 51 if (!pcap) {
e60367e2 52 ovs_fatal(errno, "failed to open %s", argv[2]);
064af421
BP
53 }
54
50aa0364 55 retval = ovs_pcap_read_header(pcap);
064af421
BP
56 if (retval) {
57 ovs_fatal(retval > 0 ? retval : 0, "reading pcap header failed");
58 }
59
60 while (fread(&expected_match, sizeof expected_match, 1, flows)) {
cf62fa4c 61 struct dp_packet *packet;
eec25dc1 62 struct ofp10_match extracted_match;
81a76618 63 struct match match;
ae412e7d 64 struct flow flow;
064af421
BP
65 n++;
66
50aa0364 67 retval = ovs_pcap_read(pcap, &packet, NULL);
064af421
BP
68 if (retval == EOF) {
69 ovs_fatal(0, "unexpected end of file reading pcap file");
70 } else if (retval) {
71 ovs_fatal(retval, "error reading pcap file");
72 }
73
cf62fa4c 74 flow_extract(packet, &flow);
b5e7e61a
AZ
75 flow.in_port.ofp_port = u16_to_ofp(1);
76
94639963 77 match_wc_init(&match, &flow);
81a76618 78 ofputil_match_to_ofp10_match(&match, &extracted_match);
064af421
BP
79
80 if (memcmp(&expected_match, &extracted_match, sizeof expected_match)) {
eec25dc1
BP
81 char *exp_s = ofp10_match_to_string(&expected_match, 2);
82 char *got_s = ofp10_match_to_string(&extracted_match, 2);
064af421
BP
83 errors++;
84 printf("mismatch on packet #%d (1-based).\n", n);
85 printf("Packet:\n");
cf62fa4c
PS
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);
81a76618 88 match_print(&match);
064af421
BP
89 printf("Expected flow:\n%s\n", exp_s);
90 printf("Actually extracted flow:\n%s\n", got_s);
7257b535
BP
91 ovs_hex_dump(stdout, &expected_match, sizeof expected_match, 0, false);
92 ovs_hex_dump(stdout, &extracted_match, sizeof extracted_match, 0, false);
064af421
BP
93 printf("\n");
94 free(exp_s);
95 free(got_s);
96 }
97
cf62fa4c 98 dp_packet_delete(packet);
064af421
BP
99 }
100 printf("checked %d packets, %d errors\n", n, errors);
eadd1644 101 exit(errors != 0);
064af421
BP
102}
103
eadd1644 104OVSTEST_REGISTER("test-flows", test_flows_main);