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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vom/api_types.hpp>
17 #include <vom/route.hpp>
18 #include <vom/route_api_types.hpp>
22 const route::itf_flags_t&
23 from_api(vapi_enum_mfib_itf_flags val)
25 if (route::itf_flags_t::ACCEPT == val)
26 return route::itf_flags_t::ACCEPT;
28 return route::itf_flags_t::FORWARD;
31 vapi_enum_mfib_itf_flags
32 to_api(const route::itf_flags_t& in)
34 vapi_enum_mfib_itf_flags out = MFIB_API_ITF_FLAG_NONE;
36 if (route::itf_flags_t::ACCEPT & in)
37 out = static_cast<vapi_enum_mfib_itf_flags>(out | MFIB_API_ITF_FLAG_ACCEPT);
38 if (route::itf_flags_t::FORWARD & in)
40 static_cast<vapi_enum_mfib_itf_flags>(out | MFIB_API_ITF_FLAG_FORWARD);
46 to_api(const route::path& p, vapi_type_fib_path& payload)
48 payload.flags = FIB_API_PATH_FLAG_NONE;
49 payload.proto = to_api(p.nh_proto());
50 payload.sw_if_index = ~0;
52 if (route::path::flags_t::DVR & p.flags()) {
53 payload.type = FIB_API_PATH_TYPE_DVR;
54 } else if (route::path::special_t::STANDARD == p.type()) {
55 to_api(p.nh(), payload.nh.address);
58 payload.table_id = p.rd()->table_id();
61 payload.sw_if_index = p.itf()->handle().value();
63 } else if (route::path::special_t::DROP == p.type()) {
64 payload.type = FIB_API_PATH_TYPE_DROP;
65 } else if (route::path::special_t::UNREACH == p.type()) {
66 payload.type = FIB_API_PATH_TYPE_ICMP_UNREACH;
67 } else if (route::path::special_t::PROHIBIT == p.type()) {
68 payload.type = FIB_API_PATH_TYPE_ICMP_PROHIBIT;
69 } else if (route::path::special_t::LOCAL == p.type()) {
70 payload.type = FIB_API_PATH_TYPE_LOCAL;
73 payload.weight = p.weight();
74 payload.preference = p.preference();
79 from_api(const vapi_type_fib_path& p)
82 case FIB_API_PATH_TYPE_DVR: {
83 std::shared_ptr<interface> itf = interface::find(p.sw_if_index);
85 throw invalid_decode("fib-path deocde no interface:" +
86 std::to_string(p.sw_if_index));
88 return (route::path(*itf, from_api(p.proto), route::path::flags_t::DVR,
89 p.weight, p.preference));
91 case FIB_API_PATH_TYPE_NORMAL: {
92 boost::asio::ip::address address = from_api(p.nh.address, p.proto);
93 std::shared_ptr<interface> itf = interface::find(p.sw_if_index);
95 return (route::path(address, *itf, p.weight, p.preference));
97 std::shared_ptr<route_domain> rd = route_domain::find(p.table_id);
100 throw invalid_decode("fib-path deocde no route-domain:" +
101 std::to_string(p.table_id));
103 return (route::path(*rd, address, p.weight, p.preference));
106 case FIB_API_PATH_TYPE_LOCAL:
107 return (route::path(route::path::special_t::LOCAL));
108 case FIB_API_PATH_TYPE_DROP:
109 return (route::path(route::path::special_t::DROP));
110 case FIB_API_PATH_TYPE_ICMP_UNREACH:
111 return (route::path(route::path::special_t::PROHIBIT));
112 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
113 return (route::path(route::path::special_t::UNREACH));
115 case FIB_API_PATH_TYPE_UDP_ENCAP:
116 case FIB_API_PATH_TYPE_BIER_IMP:
117 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
118 case FIB_API_PATH_TYPE_INTERFACE_RX:
119 case FIB_API_PATH_TYPE_CLASSIFY:
123 return (route::path(route::path::special_t::DROP));
128 * fd.io coding-style-patch-verification: ON
131 * eval: (c-set-style "mozilla")