FD.io VPP  v21.06-3-gbb25fbf28
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/api_types.hpp>
17 #include <vom/route.hpp>
18 #include <vom/route_api_types.hpp>
19 
20 namespace VOM {
21 
22 const route::itf_flags_t&
23 from_api(vapi_enum_mfib_itf_flags val)
24 {
25  if (route::itf_flags_t::ACCEPT == val)
27  else
29 }
30 
31 vapi_enum_mfib_itf_flags
33 {
34  vapi_enum_mfib_itf_flags out = MFIB_API_ITF_FLAG_NONE;
35 
37  out = static_cast<vapi_enum_mfib_itf_flags>(out | MFIB_API_ITF_FLAG_ACCEPT);
39  out =
40  static_cast<vapi_enum_mfib_itf_flags>(out | MFIB_API_ITF_FLAG_FORWARD);
41 
42  return (out);
43 }
44 
45 void
46 to_api(const route::path& p, vapi_type_fib_path& payload)
47 {
48  payload.flags = FIB_API_PATH_FLAG_NONE;
49  payload.proto = to_api(p.nh_proto());
50  payload.sw_if_index = ~0;
51 
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);
56 
57  if (p.rd()) {
58  payload.table_id = p.rd()->table_id();
59  }
60  if (p.itf()) {
61  payload.sw_if_index = p.itf()->handle().value();
62  }
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;
71  }
72 
73  payload.weight = p.weight();
74  payload.preference = p.preference();
75  payload.n_labels = 0;
76 }
77 
79 from_api(const vapi_type_fib_path& p)
80 {
81  switch (p.type) {
82  case FIB_API_PATH_TYPE_DVR: {
83  std::shared_ptr<interface> itf = interface::find(p.sw_if_index);
84  if (!itf)
85  throw invalid_decode("fib-path deocde no interface:" +
86  std::to_string(p.sw_if_index));
87 
88  return (route::path(*itf, from_api(p.proto), route::path::flags_t::DVR,
89  p.weight, p.preference));
90  }
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);
94  if (itf) {
95  return (route::path(address, *itf, p.weight, p.preference));
96  } else {
97  std::shared_ptr<route_domain> rd = route_domain::find(p.table_id);
98 
99  if (!rd)
100  throw invalid_decode("fib-path deocde no route-domain:" +
101  std::to_string(p.table_id));
102 
103  return (route::path(*rd, address, p.weight, p.preference));
104  }
105  }
114 
120  // not done yet
121  break;
122  }
124 };
125 
126 vapi_enum_ip_dscp
127 to_api(const ip_dscp_t& d)
128 {
129  return static_cast<vapi_enum_ip_dscp>((int)d);
130 }
131 const ip_dscp_t&
132 from_api(vapi_enum_ip_dscp d)
133 {
134  switch (d) {
135  case IP_API_DSCP_CS0:
136  return ip_dscp_t::DSCP_CS0;
137  case IP_API_DSCP_CS1:
138  return ip_dscp_t::DSCP_CS1;
139  case IP_API_DSCP_CS2:
140  return ip_dscp_t::DSCP_CS2;
141  case IP_API_DSCP_CS3:
142  return ip_dscp_t::DSCP_CS3;
143  case IP_API_DSCP_CS4:
144  return ip_dscp_t::DSCP_CS4;
145  case IP_API_DSCP_CS5:
146  return ip_dscp_t::DSCP_CS5;
147  case IP_API_DSCP_CS6:
148  return ip_dscp_t::DSCP_CS6;
149  case IP_API_DSCP_CS7:
150  return ip_dscp_t::DSCP_CS7;
151  case IP_API_DSCP_EF:
152  return ip_dscp_t::DSCP_EF;
153  case IP_API_DSCP_AF11:
154  return ip_dscp_t::DSCP_AF11;
155  case IP_API_DSCP_AF12:
156  return ip_dscp_t::DSCP_AF12;
157  case IP_API_DSCP_AF13:
158  return ip_dscp_t::DSCP_AF13;
159  case IP_API_DSCP_AF21:
160  return ip_dscp_t::DSCP_AF21;
161  case IP_API_DSCP_AF22:
162  return ip_dscp_t::DSCP_AF22;
163  case IP_API_DSCP_AF23:
164  return ip_dscp_t::DSCP_AF23;
165  case IP_API_DSCP_AF31:
166  return ip_dscp_t::DSCP_AF31;
167  case IP_API_DSCP_AF32:
168  return ip_dscp_t::DSCP_AF32;
169  case IP_API_DSCP_AF33:
170  return ip_dscp_t::DSCP_AF33;
171  case IP_API_DSCP_AF41:
172  return ip_dscp_t::DSCP_AF41;
173  case IP_API_DSCP_AF42:
174  return ip_dscp_t::DSCP_AF42;
175  case IP_API_DSCP_AF43:
176  return ip_dscp_t::DSCP_AF43;
177  }
178 
179  return ip_dscp_t::DSCP_CS0;
180 }
181 
182 }; // namespace VOM
183 
184 /*
185  * fd.io coding-style-patch-verification: OFF
186  *
187  * Local Variables:
188  * eval: (c-set-style "mozilla")
189  * End:
190  */
VOM::ip_dscp_t::DSCP_CS2
const static ip_dscp_t DSCP_CS2
Definition: prefix.hpp:88
FIB_API_PATH_TYPE_DROP
@ FIB_API_PATH_TYPE_DROP
Definition: fib_types.api:78
MFIB_API_ITF_FLAG_FORWARD
@ MFIB_API_ITF_FLAG_FORWARD
Definition: mfib_types.api:34
IP_API_DSCP_AF32
@ IP_API_DSCP_AF32
Definition: ip_types.api:63
VOM::route::path::special_t::PROHIBIT
const static special_t PROHIBIT
a path will return ICMP prohibit
Definition: route.hpp:65
ip_dscp_t
enum ip_dscp_t_ ip_dscp_t
IP_API_DSCP_AF31
@ IP_API_DSCP_AF31
Definition: ip_types.api:62
IP_API_DSCP_CS5
@ IP_API_DSCP_CS5
Definition: ip_types.api:69
IP_API_DSCP_CS1
@ IP_API_DSCP_CS1
Definition: ip_types.api:53
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
IP_API_DSCP_AF21
@ IP_API_DSCP_AF21
Definition: ip_types.api:58
IP_API_DSCP_AF23
@ IP_API_DSCP_AF23
Definition: ip_types.api:60
VOM::ip_dscp_t::DSCP_CS4
const static ip_dscp_t DSCP_CS4
Definition: prefix.hpp:90
IP_API_DSCP_AF33
@ IP_API_DSCP_AF33
Definition: ip_types.api:64
MFIB_API_ITF_FLAG_NONE
@ MFIB_API_ITF_FLAG_NONE
Definition: mfib_types.api:31
IP_API_DSCP_AF43
@ IP_API_DSCP_AF43
Definition: ip_types.api:68
path
vl_api_fib_path_t path
Definition: mfib_types.api:44
VOM::route::path::nh
const boost::asio::ip::address & nh() const
Definition: route.cpp:226
VOM::route::path::rd
std::shared_ptr< route_domain > rd() const
Definition: route.cpp:232
VOM::ip_dscp_t::DSCP_AF33
const static ip_dscp_t DSCP_AF33
Definition: prefix.hpp:102
FIB_API_PATH_TYPE_CLASSIFY
@ FIB_API_PATH_TYPE_CLASSIFY
Definition: fib_types.api:95
VOM::route::itf_flags_t::FORWARD
const static itf_flags_t FORWARD
A local/for-us/recieve.
Definition: route.hpp:219
FIB_API_PATH_TYPE_ICMP_UNREACH
@ FIB_API_PATH_TYPE_ICMP_UNREACH
Definition: fib_types.api:84
IP_API_DSCP_CS4
@ IP_API_DSCP_CS4
Definition: ip_types.api:65
VOM::ip_dscp_t::DSCP_AF21
const static ip_dscp_t DSCP_AF21
Definition: prefix.hpp:97
VOM::ip_dscp_t::DSCP_AF12
const static ip_dscp_t DSCP_AF12
Definition: prefix.hpp:95
route_api_types.hpp
IP_API_DSCP_CS0
@ IP_API_DSCP_CS0
Definition: ip_types.api:52
VOM::ip_dscp_t::DSCP_AF43
const static ip_dscp_t DSCP_AF43
Definition: prefix.hpp:105
route.hpp
IP_API_DSCP_CS6
@ IP_API_DSCP_CS6
Definition: ip_types.api:71
IP_API_DSCP_AF22
@ IP_API_DSCP_AF22
Definition: ip_types.api:59
VOM::ip_dscp_t::DSCP_CS7
const static ip_dscp_t DSCP_CS7
Definition: prefix.hpp:93
IP_API_DSCP_CS7
@ IP_API_DSCP_CS7
Definition: ip_types.api:72
VOM::ip_dscp_t::DSCP_AF23
const static ip_dscp_t DSCP_AF23
Definition: prefix.hpp:99
IP_API_DSCP_AF41
@ IP_API_DSCP_AF41
Definition: ip_types.api:66
VOM::route::path::preference
uint8_t preference() const
Definition: route.cpp:250
IP_API_DSCP_CS3
@ IP_API_DSCP_CS3
Definition: ip_types.api:61
VOM::ip_dscp_t::DSCP_AF41
const static ip_dscp_t DSCP_AF41
Definition: prefix.hpp:103
FIB_API_PATH_FLAG_NONE
@ FIB_API_PATH_FLAG_NONE
Definition: fib_types.api:45
VOM::ip_dscp_t::DSCP_CS3
const static ip_dscp_t DSCP_CS3
Definition: prefix.hpp:89
VOM::ip_dscp_t::DSCP_EF
const static ip_dscp_t DSCP_EF
Definition: prefix.hpp:106
VOM::route::path::type
special_t type() const
Getters.
Definition: route.cpp:208
address
manual_print typedef address
Definition: ip_types.api:96
MFIB_API_ITF_FLAG_ACCEPT
@ MFIB_API_ITF_FLAG_ACCEPT
Definition: mfib_types.api:33
VOM::ip_dscp_t::DSCP_CS5
const static ip_dscp_t DSCP_CS5
Definition: prefix.hpp:91
VOM::ip_dscp_t::DSCP_AF22
const static ip_dscp_t DSCP_AF22
Definition: prefix.hpp:98
VOM::ip_dscp_t::DSCP_AF11
const static ip_dscp_t DSCP_AF11
Definition: prefix.hpp:94
VOM::route::path::flags_t::DVR
const static flags_t DVR
A path that resolves via a DVR next-hop.
Definition: route.hpp:88
VOM::route::path::special_t::STANDARD
const static special_t STANDARD
A standard path type.
Definition: route.hpp:45
IP_API_DSCP_CS2
@ IP_API_DSCP_CS2
Definition: ip_types.api:57
VOM::route::itf_flags_t::ACCEPT
const static itf_flags_t ACCEPT
Path is accepting multicast traffic.
Definition: route.hpp:214
VOM::route::path::weight
uint8_t weight() const
Definition: route.cpp:244
VOM::route::path::special_t::LOCAL
const static special_t LOCAL
A local/for-us/recieve.
Definition: route.hpp:50
VOM::to_api
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
VOM::route::path::special_t::DROP
const static special_t DROP
drop path
Definition: route.hpp:55
FIB_API_PATH_TYPE_DVR
@ FIB_API_PATH_TYPE_DVR
Definition: fib_types.api:91
VOM::ip_dscp_t::DSCP_AF32
const static ip_dscp_t DSCP_AF32
Definition: prefix.hpp:101
FIB_API_PATH_TYPE_INTERFACE_RX
@ FIB_API_PATH_TYPE_INTERFACE_RX
Definition: fib_types.api:93
IP_API_DSCP_AF42
@ IP_API_DSCP_AF42
Definition: ip_types.api:67
IP_API_DSCP_AF13
@ IP_API_DSCP_AF13
Definition: ip_types.api:56
FIB_API_PATH_TYPE_UDP_ENCAP
@ FIB_API_PATH_TYPE_UDP_ENCAP
Definition: fib_types.api:80
VOM::ip_dscp_t
IP DSCP values.
Definition: prefix.hpp:81
FIB_API_PATH_TYPE_BIER_IMP
@ FIB_API_PATH_TYPE_BIER_IMP
Definition: fib_types.api:82
VOM::route::itf_flags_t
Definition: route.hpp:207
VOM::route::path::special_t::UNREACH
const static special_t UNREACH
a path will return ICMP unreachables
Definition: route.hpp:60
VOM::route::path::nh_proto
nh_proto_t nh_proto() const
Definition: route.cpp:214
IP_API_DSCP_EF
@ IP_API_DSCP_EF
Definition: ip_types.api:70
FIB_API_PATH_TYPE_NORMAL
@ FIB_API_PATH_TYPE_NORMAL
Definition: fib_types.api:74
VOM::ip_dscp_t::DSCP_CS0
const static ip_dscp_t DSCP_CS0
Definition: prefix.hpp:86
FIB_API_PATH_TYPE_ICMP_PROHIBIT
@ FIB_API_PATH_TYPE_ICMP_PROHIBIT
Definition: fib_types.api:86
FIB_API_PATH_TYPE_LOCAL
@ FIB_API_PATH_TYPE_LOCAL
Definition: fib_types.api:76
VOM::ip_dscp_t::DSCP_AF42
const static ip_dscp_t DSCP_AF42
Definition: prefix.hpp:104
VOM::route::path
A path for IP or MPLS routes.
Definition: route.hpp:32
IP_API_DSCP_AF12
@ IP_API_DSCP_AF12
Definition: ip_types.api:55
IP_API_DSCP_AF11
@ IP_API_DSCP_AF11
Definition: ip_types.api:54
VOM::route::path::itf
std::shared_ptr< interface > itf() const
Definition: route.cpp:238
VOM::ip_dscp_t::DSCP_CS6
const static ip_dscp_t DSCP_CS6
Definition: prefix.hpp:92
VOM::invalid_decode
Definition: api_types.hpp:26
VOM::route::path::flags
flags_t flags() const
Definition: route.cpp:220
VOM::ip_dscp_t::DSCP_CS1
const static ip_dscp_t DSCP_CS1
Definition: prefix.hpp:87
VOM::ip_dscp_t::DSCP_AF31
const static ip_dscp_t DSCP_AF31
Definition: prefix.hpp:100
VOM::from_api
const neighbour::flags_t from_api(vapi_enum_ip_neighbor_flags f)
Definition: api_types.cpp:36
api_types.hpp
FIB_API_PATH_TYPE_SOURCE_LOOKUP
@ FIB_API_PATH_TYPE_SOURCE_LOOKUP
Definition: fib_types.api:88
VOM::ip_dscp_t::DSCP_AF13
const static ip_dscp_t DSCP_AF13
Definition: prefix.hpp:96
VOM::route_domain::find
static std::shared_ptr< route_domain > find(const key_t &temp)
Find the instnace of the route domain in the OM.
Definition: route_domain.cpp:124
VOM::interface::find
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:538