FD.io VPP  v20.05.1-6-gf53edbc3b
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: ON
186  *
187  * Local Variables:
188  * eval: (c-set-style "mozilla")
189  * End:
190  */
static const ip_dscp_t DSCP_AF21
Definition: prefix.hpp:97
static const ip_dscp_t DSCP_CS4
Definition: prefix.hpp:90
static std::shared_ptr< route_domain > find(const key_t &temp)
Find the instnace of the route domain in the OM.
static const ip_dscp_t DSCP_AF11
Definition: prefix.hpp:94
static const special_t STANDARD
A standard path type.
Definition: route.hpp:45
static const itf_flags_t ACCEPT
Path is accepting multicast traffic.
Definition: route.hpp:214
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
std::shared_ptr< route_domain > rd() const
Definition: route.cpp:232
A path for IP or MPLS routes.
Definition: route.hpp:32
static const ip_dscp_t DSCP_AF33
Definition: prefix.hpp:102
static const ip_dscp_t DSCP_AF12
Definition: prefix.hpp:95
const boost::asio::ip::address & nh() const
Definition: route.cpp:226
static const itf_flags_t FORWARD
A local/for-us/recieve.
Definition: route.hpp:219
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
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
static const ip_dscp_t DSCP_AF13
Definition: prefix.hpp:96
static const ip_dscp_t DSCP_CS2
Definition: prefix.hpp:88
static const ip_dscp_t DSCP_AF32
Definition: prefix.hpp:101
static const ip_dscp_t DSCP_CS5
Definition: prefix.hpp:91
static const special_t UNREACH
a path will return ICMP unreachables
Definition: route.hpp:60
static const ip_dscp_t DSCP_CS7
Definition: prefix.hpp:93
special_t type() const
Getters.
Definition: route.cpp:208
uint8_t preference() const
Definition: route.cpp:250
static const ip_dscp_t DSCP_CS6
Definition: prefix.hpp:92
static const ip_dscp_t DSCP_AF41
Definition: prefix.hpp:103
static const special_t PROHIBIT
a path will return ICMP prohibit
Definition: route.hpp:65
IP DSCP values.
Definition: prefix.hpp:81
static const ip_dscp_t DSCP_AF43
Definition: prefix.hpp:105
static const flags_t DVR
A path that resolves via a DVR next-hop.
Definition: route.hpp:88
static const ip_dscp_t DSCP_CS1
Definition: prefix.hpp:87
static const ip_dscp_t DSCP_AF22
Definition: prefix.hpp:98
static const ip_dscp_t DSCP_AF23
Definition: prefix.hpp:99
uint8_t weight() const
Definition: route.cpp:244
static const ip_dscp_t DSCP_EF
Definition: prefix.hpp:106
manual_print typedef address
Definition: ip_types.api:85
static const ip_dscp_t DSCP_AF42
Definition: prefix.hpp:104
nh_proto_t nh_proto() const
Definition: route.cpp:214
static const ip_dscp_t DSCP_AF31
Definition: prefix.hpp:100
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
static const ip_dscp_t DSCP_CS0
Definition: prefix.hpp:86
const neighbour::flags_t from_api(vapi_enum_ip_neighbor_flags f)
Definition: api_types.cpp:36
static const ip_dscp_t DSCP_CS3
Definition: prefix.hpp:89
std::shared_ptr< interface > itf() const
Definition: route.cpp:238
flags_t flags() const
Definition: route.cpp:220