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/route.hpp>
17 #include <vom/route_api_types.hpp>
22 to_vpp(const route::path& p, vapi_payload_ip_add_del_route& payload)
25 payload.is_unreach = 0;
26 payload.is_prohibit = 0;
28 payload.is_classify = 0;
29 payload.is_resolve_host = 0;
30 payload.is_resolve_attached = 0;
32 if (route::path::flags_t::DVR & p.flags()) {
36 if (route::path::special_t::STANDARD == p.type()) {
38 to_bytes(p.nh(), &path_v6, payload.next_hop_address);
39 payload.next_hop_sw_if_index = 0xffffffff;
42 payload.next_hop_table_id = p.rd()->table_id();
45 payload.next_hop_sw_if_index = p.itf()->handle().value();
47 } else if (route::path::special_t::DROP == p.type()) {
49 } else if (route::path::special_t::UNREACH == p.type()) {
50 payload.is_unreach = 1;
51 } else if (route::path::special_t::PROHIBIT == p.type()) {
52 payload.is_prohibit = 1;
53 } else if (route::path::special_t::LOCAL == p.type()) {
56 payload.next_hop_weight = p.weight();
57 payload.next_hop_preference = p.preference();
58 payload.next_hop_via_label = 0x100000;
59 payload.classify_table_index = 0;
63 to_vpp(const route::path& p, vapi_payload_ip_mroute_add_del& payload)
65 payload.next_hop_afi = p.nh_proto();
67 if (route::path::special_t::STANDARD == p.type()) {
69 to_bytes(p.nh(), &path_v6, payload.nh_address);
72 payload.next_hop_sw_if_index = p.itf()->handle().value();
75 payload.next_hop_afi = p.nh_proto();
76 } else if (route::path::special_t::LOCAL == p.type()) {
82 from_vpp(const vapi_type_fib_path& p, const nh_proto_t& nhp)
85 return route::path(route::path::special_t::LOCAL);
86 } else if (p.is_drop) {
87 return route::path(route::path::special_t::DROP);
88 } else if (p.is_unreach) {
89 return route::path(route::path::special_t::UNREACH);
90 } else if (p.is_prohibit) {
91 return route::path(route::path::special_t::PROHIBIT);
93 boost::asio::ip::address address =
94 from_bytes(nh_proto_t::IPV6 == nhp, p.next_hop);
95 std::shared_ptr<interface> itf = interface::find(p.sw_if_index);
98 return route::path(*itf, nhp, route::path::flags_t::DVR, p.weight,
101 return route::path(address, *itf, p.weight, p.preference);
104 std::shared_ptr<route_domain> rd = route_domain::find(p.table_id);
106 return route::path(*rd, address, p.weight, p.preference);
111 VOM_LOG(log_level_t::ERROR) << "cannot decode: ";
113 return route::path(route::path::special_t::DROP);
118 * fd.io coding-style-patch-verification: ON
121 * eval: (c-set-style "mozilla")