FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
api_types.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <vom/api_types.hpp>
17 
18 namespace VOM {
19 
20 vapi_enum_ip_neighbor_flags
22 {
23  vapi_enum_ip_neighbor_flags out = IP_API_NEIGHBOR_FLAG_NONE;
24 
26  out = static_cast<vapi_enum_ip_neighbor_flags>(out |
29  out = static_cast<vapi_enum_ip_neighbor_flags>(
31 
32  return (out);
33 }
34 
35 const neighbour::flags_t
36 from_api(vapi_enum_ip_neighbor_flags f)
37 {
39 
44 
45  return out;
46 }
47 
49  : reason(reason)
50 {}
51 
52 void
53 to_api(const boost::asio::ip::address_v4& a, vapi_type_ip4_address& v)
54 {
55  std::copy_n(std::begin(a.to_bytes()), a.to_bytes().size(), v);
56 }
57 void
58 to_api(const boost::asio::ip::address_v6& a, vapi_type_ip6_address& v)
59 {
60  std::copy_n(std::begin(a.to_bytes()), a.to_bytes().size(), v);
61 }
62 
63 void
64 to_api(const ip_address_t& a, vapi_type_address& v)
65 {
66  if (a.is_v4()) {
67  v.af = ADDRESS_IP4;
68  memcpy(v.un.ip4, a.to_v4().to_bytes().data(), 4);
69  } else {
70  v.af = ADDRESS_IP6;
71  memcpy(v.un.ip6, a.to_v6().to_bytes().data(), 16);
72  }
73 }
74 
75 void
77  vapi_union_address_union& u,
78  vapi_enum_address_family& af)
79 {
80  if (a.is_v4()) {
81  af = ADDRESS_IP4;
82  memcpy(u.ip4, a.to_v4().to_bytes().data(), 4);
83  } else {
84  af = ADDRESS_IP6;
85  memcpy(u.ip6, a.to_v6().to_bytes().data(), 16);
86  }
87 }
88 
89 void
90 to_api(const ip_address_t& a, vapi_union_address_union& u)
91 {
92  if (a.is_v4()) {
93  memcpy(u.ip4, a.to_v4().to_bytes().data(), 4);
94  } else {
95  memcpy(u.ip6, a.to_v6().to_bytes().data(), 16);
96  }
97 }
98 
99 boost::asio::ip::address_v6
100 from_api(const vapi_type_ip6_address& v)
101 {
102  std::array<uint8_t, 16> a;
103  std::copy(v, v + 16, std::begin(a));
104  boost::asio::ip::address_v6 v6(a);
105 
106  return v6;
107 }
108 
109 boost::asio::ip::address_v4
110 from_api(const vapi_type_ip4_address& v)
111 {
112  std::array<uint8_t, 4> a;
113  std::copy(v, v + 4, std::begin(a));
114  boost::asio::ip::address_v4 v4(a);
115 
116  return v4;
117 }
118 
120 from_api(const vapi_type_address& v)
121 {
123 
124  if (ADDRESS_IP6 == v.af) {
125  std::array<uint8_t, 16> a;
126  std::copy(v.un.ip6, v.un.ip6 + 16, std::begin(a));
127  boost::asio::ip::address_v6 v6(a);
128  addr = v6;
129  } else {
130  std::array<uint8_t, 4> a;
131  std::copy(v.un.ip6, v.un.ip6 + 4, std::begin(a));
132  boost::asio::ip::address_v4 v4(a);
133  addr = v4;
134  }
135 
136  return addr;
137 }
138 
140 from_api(const vapi_union_address_union& u, vapi_enum_fib_path_nh_proto proto)
141 {
143 
145  std::array<uint8_t, 16> a;
146  std::copy(u.ip6, u.ip6 + 16, std::begin(a));
147  boost::asio::ip::address_v6 v6(a);
148  addr = v6;
149  } else if (FIB_API_PATH_NH_PROTO_IP4 == proto) {
150  std::array<uint8_t, 4> a;
151  std::copy(u.ip6, u.ip6 + 4, std::begin(a));
152  boost::asio::ip::address_v4 v4(a);
153  addr = v4;
154  }
155 
156  return addr;
157 }
158 
160 from_api(const vapi_union_address_union& u, vapi_enum_address_family af)
161 {
163 
164  if (ADDRESS_IP6 == af) {
165  std::array<uint8_t, 16> a;
166  std::copy(u.ip6, u.ip6 + 16, std::begin(a));
167  boost::asio::ip::address_v6 v6(a);
168  addr = v6;
169  } else {
170  std::array<uint8_t, 4> a;
171  std::copy(u.ip6, u.ip6 + 4, std::begin(a));
172  boost::asio::ip::address_v4 v4(a);
173  addr = v4;
174  }
175 
176  return addr;
177 }
178 
179 void
180 to_api(const mac_address_t& a, vapi_type_mac_address& v)
181 {
182  std::copy(std::begin(a.bytes), std::end(a.bytes), v);
183 }
184 
186 from_api(const vapi_type_mac_address& v)
187 {
188  return mac_address_t(v);
189 }
190 
191 route::prefix_t
192 from_api(const vapi_type_prefix& v)
193 {
194  return route::prefix_t(from_api(v.address), v.len);
195 }
196 
197 vapi_type_prefix
199 {
200  vapi_type_prefix v;
201  to_api(p.address(), v.address);
202  v.len = p.mask_width();
203  return v;
204 }
205 
206 route::mprefix_t
207 from_api(const vapi_type_mprefix& v)
208 {
209  return route::mprefix_t(from_api(v.src_address, v.af),
210  from_api(v.grp_address, v.af),
211  v.grp_address_length);
212 }
213 
214 vapi_type_mprefix
216 {
217  vapi_enum_address_family af;
218  vapi_type_mprefix v;
219  to_api(p.grp_address(), v.grp_address, af);
220  to_api(p.src_address(), v.src_address, af);
221  v.grp_address_length = p.mask_width();
222  v.af = af;
223  return v;
224 }
225 
226 vapi_enum_fib_path_nh_proto
228 {
229  if (p == nh_proto_t::IPV4) {
231  } else if (p == nh_proto_t::IPV6) {
233  } else if (p == nh_proto_t::ETHERNET) {
235  } else if (p == nh_proto_t::MPLS) {
237  }
238 
240 }
241 
242 vapi_enum_address_family
244 {
245  if (p == l3_proto_t::IPV6) {
246  return ADDRESS_IP6;
247  }
248  return ADDRESS_IP4;
249 }
250 
251 const nh_proto_t&
252 from_api(vapi_enum_fib_path_nh_proto p)
253 {
254  switch (p) {
256  return nh_proto_t::IPV4;
258  return nh_proto_t::IPV6;
260  return nh_proto_t::ETHERNET;
262  return nh_proto_t::MPLS;
264  break;
265  }
266 
267  return nh_proto_t::IPV4;
268 }
269 
270 }; // VOM
271 
272 /*
273  * fd.io coding-style-patch-verification: OFF
274  *
275  * Local Variables:
276  * eval: (c-set-style "mozilla")
277  * End:
278  */
VOM::route::prefix_t
A prefix defintion.
Definition: prefix.hpp:131
ip_address
Definition: ip_types.h:79
VOM::route::prefix_t::mask_width
uint8_t mask_width() const
Get the network mask width.
Definition: prefix.cpp:186
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
f
vlib_frame_t * f
Definition: interface_output.c:1098
VOM::nh_proto_t::MPLS
const static nh_proto_t MPLS
Definition: prefix.hpp:36
IP_API_NEIGHBOR_FLAG_NONE
@ IP_API_NEIGHBOR_FLAG_NONE
Definition: ip_neighbor.api:37
mac_address_t
struct mac_address_t_ mac_address_t
VOM::route::mprefix_t::grp_address
const boost::asio::ip::address & grp_address() const
Get the address.
Definition: prefix.cpp:509
VOM::route::mprefix_t::mask_width
uint8_t mask_width() const
Get the network mask width.
Definition: prefix.cpp:521
FIB_API_PATH_NH_PROTO_BIER
@ FIB_API_PATH_NH_PROTO_BIER
Definition: fib_types.api:38
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
ADDRESS_IP6
@ ADDRESS_IP6
Definition: ip_types.api:23
VOM::route::mprefix_t
A prefix defintion.
Definition: prefix.hpp:252
VOM::neighbour::flags_t::STATIC
const static flags_t STATIC
Definition: neighbour.hpp:50
VOM::route::mprefix_t::src_address
const boost::asio::ip::address & src_address() const
Definition: prefix.cpp:515
VOM::route::prefix_t::address
const boost::asio::ip::address & address() const
Get the address.
Definition: prefix.cpp:180
FIB_API_PATH_NH_PROTO_IP4
@ FIB_API_PATH_NH_PROTO_IP4
Definition: fib_types.api:34
IP_API_NEIGHBOR_FLAG_STATIC
@ IP_API_NEIGHBOR_FLAG_STATIC
Definition: ip_neighbor.api:38
VOM::nh_proto_t::ETHERNET
const static nh_proto_t ETHERNET
Definition: prefix.hpp:37
end
f64 end
end of the time range
Definition: mactime.api:44
address
manual_print typedef address
Definition: ip_types.api:96
VOM::to_api
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
FIB_API_PATH_NH_PROTO_ETHERNET
@ FIB_API_PATH_NH_PROTO_ETHERNET
Definition: fib_types.api:37
VOM::l3_proto_t
An L3 protocol can be used to construct a prefix that is used to match packets are part of a route.
Definition: prefix.hpp:52
VOM::nh_proto_t::IPV6
const static nh_proto_t IPV6
Definition: prefix.hpp:35
VOM::ip_address_t
boost::asio::ip::address ip_address_t
Definition: api_types.hpp:32
af
vl_api_address_family_t af
Definition: ip.api:619
FIB_API_PATH_NH_PROTO_IP6
@ FIB_API_PATH_NH_PROTO_IP6
Definition: fib_types.api:35
VOM::mac_address_t
Type def of a Ethernet address.
Definition: types.hpp:295
VOM::nh_proto_t
Types belonging to Routing.
Definition: prefix.hpp:31
mac_address_t_
Definition: mac_address.h:21
a
a
Definition: bitmap.h:525
VOM::invalid_decode::invalid_decode
invalid_decode(const std::string reason)
Definition: api_types.cpp:48
VOM::nh_proto_t::IPV4
const static nh_proto_t IPV4
Definition: prefix.hpp:34
FIB_API_PATH_NH_PROTO_MPLS
@ FIB_API_PATH_NH_PROTO_MPLS
Definition: fib_types.api:36
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
VOM::neighbour::flags_t::NO_FIB_ENTRY
const static flags_t NO_FIB_ENTRY
Definition: neighbour.hpp:51
VOM::neighbour::flags_t
Definition: neighbour.hpp:30
ADDRESS_IP4
@ ADDRESS_IP4
Definition: ip_types.api:22
VOM::neighbour::flags_t::NONE
const static flags_t NONE
Definition: neighbour.hpp:49
VOM::from_api
const neighbour::flags_t from_api(vapi_enum_ip_neighbor_flags f)
Definition: api_types.cpp:36
api_types.hpp
IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY
@ IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY
Definition: ip_neighbor.api:39
VOM::l3_proto_t::IPV6
const static l3_proto_t IPV6
Definition: prefix.hpp:56
string
const char *const string
Definition: cJSON.h:172