]> git.proxmox.com Git - mirror_ovs.git/blame - tests/test-odp.c
dynamic-string: New function ds_get_test_line().
[mirror_ovs.git] / tests / test-odp.c
CommitLineData
3bffc610 1/*
e0edde6f 2 * Copyright (c) 2011 Nicira, Inc.
3bffc610
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
17#include <config.h>
18
19#include <stdio.h>
20
21#include "dynamic-string.h"
22#include "flow.h"
23#include "odp-util.h"
24#include "ofpbuf.h"
b0f7b9b5 25#include "vlog.h"
3bffc610
BP
26
27int
28main(void)
29{
30 struct ds in;
31
32 ds_init(&in);
b0f7b9b5 33 vlog_set_levels_from_string("odp_util:console:dbg");
06d7ae7d 34 while (!ds_get_test_line(&in, stdin)) {
b0f7b9b5 35 enum odp_key_fitness fitness;
3bffc610
BP
36 struct ofpbuf odp_key;
37 struct flow flow;
38 struct ds out;
39 int error;
3bffc610 40
df2c07f4 41 /* Convert string to OVS DP key. */
3bffc610 42 ofpbuf_init(&odp_key, 0);
b2a60db8 43 error = odp_flow_key_from_string(ds_cstr(&in), NULL, &odp_key);
3bffc610
BP
44 if (error) {
45 printf("odp_flow_key_from_string: error\n");
46 goto next;
47 }
48
49 /* Convert odp_key to flow. */
b0f7b9b5
BP
50 fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
51 switch (fitness) {
52 case ODP_FIT_PERFECT:
53 break;
54
55 case ODP_FIT_TOO_LITTLE:
56 printf("ODP_FIT_TOO_LITTLE: ");
57 break;
58
59 case ODP_FIT_TOO_MUCH:
60 printf("ODP_FIT_TOO_MUCH: ");
61 break;
62
63 case ODP_FIT_ERROR:
3bffc610
BP
64 printf("odp_flow_key_to_flow: error\n");
65 goto next;
66 }
67
68 /* Convert cls_rule back to odp_key. */
69 ofpbuf_uninit(&odp_key);
70 ofpbuf_init(&odp_key, 0);
71 odp_flow_key_from_flow(&odp_key, &flow);
72
73 /* Convert odp_key to string. */
74 ds_init(&out);
75 odp_flow_key_format(odp_key.data, odp_key.size, &out);
76 puts(ds_cstr(&out));
77 ds_destroy(&out);
78
79 next:
80 ofpbuf_uninit(&odp_key);
81 }
82 ds_destroy(&in);
83
84 return 0;
85}