FD.io VPP  v18.10-34-gcce845e
Vector Packet Processing
route_cmds.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 <sstream>
17 
18 #include "vom/route_cmds.hpp"
19 
20 namespace VOM {
21 namespace route {
22 namespace ip_route_cmds {
23 
24 static void
25 to_vpp(const route::path& p, vapi_payload_ip_add_del_route& payload)
26 {
27  payload.is_drop = 0;
28  payload.is_unreach = 0;
29  payload.is_prohibit = 0;
30  payload.is_local = 0;
31  payload.is_classify = 0;
32  payload.is_multipath = 0;
33  payload.is_resolve_host = 0;
34  payload.is_resolve_attached = 0;
35 
36  if (route::path::flags_t::DVR & p.flags()) {
37  payload.is_dvr = 1;
38  }
39 
41  uint8_t path_v6;
42  to_bytes(p.nh(), &path_v6, payload.next_hop_address);
43 
44  if (p.rd()) {
45  payload.next_hop_table_id = p.rd()->table_id();
46  }
47  if (p.itf()) {
48  payload.next_hop_sw_if_index = p.itf()->handle().value();
49  }
50  } else if (route::path::special_t::DROP == p.type()) {
51  payload.is_drop = 1;
52  } else if (route::path::special_t::UNREACH == p.type()) {
53  payload.is_unreach = 1;
54  } else if (route::path::special_t::PROHIBIT == p.type()) {
55  payload.is_prohibit = 1;
56  } else if (route::path::special_t::LOCAL == p.type()) {
57  payload.is_local = 1;
58  }
59  payload.next_hop_weight = p.weight();
60  payload.next_hop_preference = p.preference();
61  payload.next_hop_via_label = 0;
62  payload.classify_table_index = 0;
63 }
64 
66  table_id_t id,
67  const prefix_t& prefix,
68  const path_list_t& paths)
69  : rpc_cmd(item)
70  , m_id(id)
71  , m_prefix(prefix)
72  , m_paths(paths)
73 {
74  // no multipath yet.
75  assert(paths.size() == 1);
76 }
77 
78 bool
80 {
81  return ((m_prefix == other.m_prefix) && (m_id == other.m_id));
82 }
83 
84 rc_t
86 {
87  msg_t req(con.ctx(), 0, std::ref(*this));
88 
89  auto& payload = req.get_request().get_payload();
90 
91  payload.table_id = m_id;
92  payload.is_add = 1;
93  payload.is_multipath = 0;
94 
95  m_prefix.to_vpp(&payload.is_ipv6, payload.dst_address,
96  &payload.dst_address_length);
97 
98  for (auto& p : m_paths)
99  to_vpp(p, payload);
100 
101  VAPI_CALL(req.execute());
102 
103  return (wait());
104 }
105 
106 std::string
108 {
109  std::ostringstream s;
110  s << "ip-route-create: " << m_hw_item.to_string() << " table-id:" << m_id
111  << " prefix:" << m_prefix.to_string() << " paths:" << m_paths;
112 
113  return (s.str());
114 }
115 
117  table_id_t id,
118  const prefix_t& prefix)
119  : rpc_cmd(item)
120  , m_id(id)
121  , m_prefix(prefix)
122 {
123 }
124 
125 bool
127 {
128  return ((m_prefix == other.m_prefix) && (m_id == other.m_id));
129 }
130 
131 rc_t
133 {
134  msg_t req(con.ctx(), 0, std::ref(*this));
135 
136  auto& payload = req.get_request().get_payload();
137  payload.table_id = m_id;
138  payload.is_add = 0;
139 
140  m_prefix.to_vpp(&payload.is_ipv6, payload.dst_address,
141  &payload.dst_address_length);
142 
143  VAPI_CALL(req.execute());
144 
145  wait();
147 
148  return rc_t::OK;
149 }
150 
151 std::string
153 {
154  std::ostringstream s;
155  s << "ip-route-delete: " << m_hw_item.to_string() << " id:" << m_id
156  << " prefix:" << m_prefix.to_string();
157 
158  return (s.str());
159 }
160 
162 {
163 }
164 
165 bool
167 {
168  return (true);
169 }
170 
171 rc_t
173 {
174  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
175 
176  VAPI_CALL(m_dump->execute());
177 
178  wait();
179 
180  return rc_t::OK;
181 }
182 
183 std::string
185 {
186  return ("ip-route-v4-dump");
187 }
188 
190 {
191 }
192 
193 bool
195 {
196  return (true);
197 }
198 
199 rc_t
201 {
202  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
203 
204  VAPI_CALL(m_dump->execute());
205 
206  wait();
207 
208  return rc_t::OK;
209 }
210 
211 std::string
213 {
214  return ("ip-route-v6-dump");
215 }
216 } // namespace ip_route_cmds
217 } // namespace route
218 } // namespace vom
219  /*
220  * fd.io coding-style-patch-verification: ON
221  *
222  * Local Variables:
223  * eval: (c-set-style "mozilla")
224  * End:
225  */
flags_t flags() const
Definition: route.cpp:198
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:82
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:99
static void to_vpp(const route::path &p, vapi_payload_ip_add_del_route &payload)
Definition: route_cmds.cpp:25
delete_cmd(HW::item< bool > &item, table_id_t id, const prefix_t &prefix)
Constructor.
Definition: route_cmds.cpp:116
A cmd class that Dumps ipv6 fib.
Definition: route_cmds.hpp:131
bool operator==(const update_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:79
static const special_t STANDARD
A standard path type.
Definition: route.hpp:45
A command class that creates or updates the route.
Definition: route_cmds.hpp:32
A path for IP or MPLS routes.
Definition: route.hpp:32
update_cmd(HW::item< bool > &item, table_id_t id, const prefix_t &prefix, const path_list_t &paths)
Constructor.
Definition: route_cmds.cpp:65
Error codes that VPP will return during a HW write.
Definition: types.hpp:84
std::shared_ptr< interface > itf() const
Definition: route.cpp:216
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:107
#define assert(x)
Definition: dlmalloc.c:30
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:80
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:126
static const special_t LOCAL
A local/for-us/recieve.
Definition: route.hpp:50
bool operator==(const dump_v4_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:166
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:152
static const special_t DROP
drop path
Definition: route.hpp:55
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:200
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
Definition: prefix.cpp:218
A representation of the connection to VPP.
Definition: connection.hpp:33
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:183
static const special_t UNREACH
a path will return ICMP unreachables
Definition: route.hpp:60
std::shared_ptr< route_domain > rd() const
Definition: route.cpp:210
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:132
bool operator==(const dump_v6_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:194
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:38
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
void to_vpp(uint8_t *is_ip6, uint8_t *addr, uint8_t *len) const
Convert the prefix into VPP API parameters.
Definition: prefix.cpp:251
static const special_t PROHIBIT
a path will return ICMP prohibit
Definition: route.hpp:65
std::set< path > path_list_t
A path-list is a set of paths.
Definition: route.hpp:210
static const flags_t DVR
A path that resolves via a DVR next-hop.
Definition: route.hpp:88
uint8_t preference() const
Definition: route.cpp:228
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:104
A cmd class that deletes a route.
Definition: route_cmds.hpp:67
const boost::asio::ip::address & nh() const
Definition: route.cpp:204
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
A cmd class that Dumps ipv4 fib.
Definition: route_cmds.hpp:98
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:85
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:212
void set(const rc_t &rc)
Set the HW return code - should only be called from the family of Command objects.
Definition: hw.hpp:124
typedef prefix
Definition: ip_types.api:40
special_t type() const
Getters.
Definition: route.cpp:186
uint8_t weight() const
Definition: route.cpp:222
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:172
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:184
A prefix defintion.
Definition: prefix.hpp:92
HW::item< bool > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:132
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:64
vapi::Ip_add_del_route msg_t
convenient typedef
Definition: rpc_cmd.hpp:44