FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
route_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/route.hpp>
17 #include <vom/route_api_types.hpp>
18 
19 namespace VOM {
20 
21 void
22 to_vpp(const route::path& p, vapi_payload_ip_add_del_route& payload)
23 {
24  payload.is_drop = 0;
25  payload.is_unreach = 0;
26  payload.is_prohibit = 0;
27  payload.is_local = 0;
28  payload.is_classify = 0;
29  payload.is_resolve_host = 0;
30  payload.is_resolve_attached = 0;
31 
32  if (route::path::flags_t::DVR & p.flags()) {
33  payload.is_dvr = 1;
34  }
35 
37  uint8_t path_v6;
38  to_bytes(p.nh(), &path_v6, payload.next_hop_address);
39  payload.next_hop_sw_if_index = 0xffffffff;
40 
41  if (p.rd()) {
42  payload.next_hop_table_id = p.rd()->table_id();
43  }
44  if (p.itf()) {
45  payload.next_hop_sw_if_index = p.itf()->handle().value();
46  }
47  } else if (route::path::special_t::DROP == p.type()) {
48  payload.is_drop = 1;
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()) {
54  payload.is_local = 1;
55  }
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;
60 }
61 
62 void
63 to_vpp(const route::path& p, vapi_payload_ip_mroute_add_del& payload)
64 {
65  payload.next_hop_afi = p.nh_proto();
66 
68  uint8_t path_v6;
69  to_bytes(p.nh(), &path_v6, payload.nh_address);
70 
71  if (p.itf()) {
72  payload.next_hop_sw_if_index = p.itf()->handle().value();
73  }
74 
75  payload.next_hop_afi = p.nh_proto();
76  } else if (route::path::special_t::LOCAL == p.type()) {
77  payload.is_local = 1;
78  }
79 }
80 
82 from_vpp(const vapi_type_fib_path& p, const nh_proto_t& nhp)
83 {
84  if (p.is_local) {
86  } else if (p.is_drop) {
88  } else if (p.is_unreach) {
90  } else if (p.is_prohibit) {
92  } else {
94  from_bytes(nh_proto_t::IPV6 == nhp, p.next_hop);
95  std::shared_ptr<interface> itf = interface::find(p.sw_if_index);
96  if (itf) {
97  if (p.is_dvr) {
98  return route::path(*itf, nhp, route::path::flags_t::DVR, p.weight,
99  p.preference);
100  } else {
101  return route::path(address, *itf, p.weight, p.preference);
102  }
103  } else {
104  std::shared_ptr<route_domain> rd = route_domain::find(p.table_id);
105  if (rd) {
106  return route::path(*rd, address, p.weight, p.preference);
107  }
108  }
109  }
110 
111  VOM_LOG(log_level_t::ERROR) << "cannot decode: ";
112 
114 }
115 };
116 
117 /*
118  * fd.io coding-style-patch-verification: ON
119  *
120  * Local Variables:
121  * eval: (c-set-style "mozilla")
122  * End:
123  */
typedef address
Definition: ip_types.api:30
static std::shared_ptr< route_domain > find(const key_t &temp)
Find the instnace of the route domain in the OM.
static const special_t STANDARD
A standard path type.
Definition: route.hpp:45
#define VOM_LOG(lvl)
Definition: logger.hpp:181
static std::shared_ptr< interface > find(const handle_t &h)
The the singular instance of the interface in the DB by handle.
Definition: interface.cpp:531
static const nh_proto_t IPV6
Definition: prefix.hpp:35
void to_vpp(const route::path &p, vapi_payload_ip_add_del_route &payload)
std::shared_ptr< route_domain > rd() const
Definition: route.cpp:240
A path for IP or MPLS routes.
Definition: route.hpp:32
route::path from_vpp(const vapi_type_fib_path &p, const nh_proto_t &nhp)
const boost::asio::ip::address & nh() const
Definition: route.cpp:234
static const special_t LOCAL
A local/for-us/recieve.
Definition: route.hpp:50
static const special_t DROP
drop path
Definition: route.hpp:55
Types belonging to Routing.
Definition: prefix.hpp:31
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
Definition: prefix.cpp:218
static const special_t UNREACH
a path will return ICMP unreachables
Definition: route.hpp:60
special_t type() const
Getters.
Definition: route.cpp:216
uint8_t preference() const
Definition: route.cpp:258
static const special_t PROHIBIT
a path will return ICMP prohibit
Definition: route.hpp:65
static const flags_t DVR
A path that resolves via a DVR next-hop.
Definition: route.hpp:88
uint8_t weight() const
Definition: route.cpp:252
boost::asio::ip::address from_bytes(uint8_t is_ip6, const uint8_t *bytes)
Convert a VPP byte stinrg into a boost addresss.
Definition: prefix.cpp:193
nh_proto_t nh_proto() const
Definition: route.cpp:222
static const log_level_t ERROR
Definition: logger.hpp:29
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
std::shared_ptr< interface > itf() const
Definition: route.cpp:246
flags_t flags() const
Definition: route.cpp:228