tunnel: Common types for IP tunnels
[vpp.git] / src / vnet / tunnel / tunnel_types_api.c
1 /*
2  * tunnel_api.c - tunnel api
3  *
4  * Copyright (c) 2018 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <vnet/api_errno.h>
19 #include <vnet/tunnel/tunnel_types_api.h>
20
21 #include <vnet/tunnel/tunnel_types.api_enum.h>
22 #include <vnet/tunnel/tunnel_types.api_types.h>
23
24
25 STATIC_ASSERT (sizeof (vl_api_tunnel_encap_decap_flags_t) ==
26                sizeof (tunnel_encap_decap_flags_t),
27                "tunnel API and internal flags enum size differ");
28
29 int
30 tunnel_encap_decap_flags_decode (vl_api_tunnel_encap_decap_flags_t f,
31                                  tunnel_encap_decap_flags_t * o)
32 {
33   if (f & ~TUNNEL_FLAG_MASK)
34     /* unknown flags set */
35     return (VNET_API_ERROR_INVALID_VALUE_2);
36
37   *o = (tunnel_encap_decap_flags_t) f;
38   return (0);
39 }
40
41 vl_api_tunnel_encap_decap_flags_t
42 tunnel_encap_decap_flags_encode (tunnel_encap_decap_flags_t f)
43 {
44   return ((vl_api_tunnel_encap_decap_flags_t) f);
45 }
46
47 int
48 tunnel_mode_decode (vl_api_tunnel_mode_t in, tunnel_mode_t * out)
49 {
50   switch (in)
51     {
52 #define _(n, v)                                       \
53       case TUNNEL_API_MODE_##n:                       \
54         *out = TUNNEL_MODE_##n;                       \
55         return (0);
56       foreach_tunnel_mode
57 #undef _
58     }
59
60   return (VNET_API_ERROR_INVALID_VALUE_2);
61 }
62
63 vl_api_tunnel_mode_t
64 tunnel_mode_encode (tunnel_mode_t in)
65 {
66   vl_api_tunnel_mode_t out = TUNNEL_API_MODE_P2P;
67
68   switch (in)
69     {
70 #define _(n, v)                                       \
71       case TUNNEL_MODE_##n:                           \
72         out = TUNNEL_API_MODE_##n;                    \
73         break;
74       foreach_tunnel_mode
75 #undef _
76     }
77
78   return (out);
79 }
80
81 /*
82  * fd.io coding-style-patch-verification: ON
83  *
84  * Local Variables:
85  * eval: (c-set-style "gnu")
86  * End:
87  */