FD.io VPP  v21.10.1-2-g0a485f517
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/api_types.hpp>
19 #include <vom/route_api_types.hpp>
20 #include <vom/route_cmds.hpp>
21 
22 namespace VOM {
23 namespace route {
24 namespace ip_route_cmds {
25 
27  table_id_t id,
28  const prefix_t& prefix,
29  const path_list_t& pl)
30  : srpc_cmd(item)
31  , m_id(id)
32  , m_prefix(prefix)
33  , m_pl(pl)
34 {
35 }
36 
37 bool
39 {
40  return ((m_prefix == other.m_prefix) && (m_id == other.m_id) &&
41  (m_pl == other.m_pl));
42 }
43 
44 rc_t
46 {
47  msg_t req(con.ctx(), m_pl.size(), std::ref(*this));
48 
49  auto& payload = req.get_request().get_payload();
50 
51  payload.route.table_id = m_id;
52  payload.is_add = 1;
53  payload.is_multipath = 1;
54 
55  payload.route.table_id = m_id;
56  payload.route.prefix = to_api(m_prefix);
57 
58  uint32_t ii = 0;
59  for (auto& p : m_pl)
60  to_api(p, payload.route.paths[ii++]);
61 
62  VAPI_CALL(req.execute());
63 
64  return (wait());
65 }
66 
69 {
70  std::ostringstream s;
71  s << "ip-route-create: " << m_hw_item.to_string() << " table-id:" << m_id
72  << " prefix:" << m_prefix.to_string() << " paths:";
73  for (auto p : m_pl)
74  s << p.to_string() << " ";
75 
76  return (s.str());
77 }
78 
80  table_id_t id,
81  const prefix_t& prefix)
82  : rpc_cmd(item)
83  , m_id(id)
84  , m_prefix(prefix)
85 {
86 }
87 
88 bool
90 {
91  return ((m_prefix == other.m_prefix) && (m_id == other.m_id));
92 }
93 
94 rc_t
96 {
97  msg_t req(con.ctx(), 0, std::ref(*this));
98 
99  auto& payload = req.get_request().get_payload();
100  payload.is_add = 0;
101  payload.is_multipath = 0;
102 
103  payload.route.table_id = m_id;
104  payload.route.n_paths = 0;
105  payload.route.table_id = m_id;
106  payload.route.prefix = to_api(m_prefix);
107 
108  VAPI_CALL(req.execute());
109 
110  wait();
112 
113  return rc_t::OK;
114 }
115 
118 {
119  std::ostringstream s;
120  s << "ip-route-delete: " << m_hw_item.to_string() << " id:" << m_id
121  << " prefix:" << m_prefix.to_string();
122 
123  return (s.str());
124 }
125 
127  : m_id(id)
128  , m_proto(proto)
129 {
130 }
131 
132 bool
133 dump_cmd::operator==(const dump_cmd& other) const
134 {
135  return (true);
136 }
137 
138 rc_t
140 {
141  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
142 
143  auto& payload = m_dump->get_request().get_payload();
144 
145  payload.table.table_id = m_id;
146  payload.table.is_ip6 = m_proto.is_ipv6();
147 
148  VAPI_CALL(m_dump->execute());
149 
150  wait();
151 
152  return rc_t::OK;
153 }
154 
157 {
158  return ("ip-route-v4-dump");
159 }
160 
161 } // namespace ip_route_cmds
162 } // namespace route
163 } // namespace vom
164 
165 /*
166  * fd.io coding-style-patch-verification: OFF
167  *
168  * Local Variables:
169  * eval: (c-set-style "mozilla")
170  * End:
171  */
VOM::route::ip_route_cmds::delete_cmd
A cmd class that deletes a route.
Definition: route_cmds.hpp:67
VOM::route::prefix_t
A prefix defintion.
Definition: prefix.hpp:131
VOM::HW::item< handle_t >
VOM::dump_cmd< vapi::Ip_route_dump >::msg_t
vapi::Ip_route_dump msg_t
Definition: dump_cmd.hpp:46
VOM::rpc_cmd< HW::item< handle_t >, vapi::Ip_route_add_del >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
VOM::HW::item::set
void set(const rc_t &rc)
Set the HW return code - should only be called from the family of Command objects.
Definition: hw.hpp:125
VOM::route::ip_route_cmds::delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:95
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::route::ip_route_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:156
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::route::path_list_t
std::set< path > path_list_t
A path-list is a set of paths.
Definition: route.hpp:231
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
route_cmds.hpp
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::rpc_cmd< HW::item< handle_t >, vapi::Ip_route_add_del >::m_hw_item
HW::item< handle_t > & m_hw_item
A reference to an object's HW::item that the command will update.
Definition: rpc_cmd.hpp:134
VOM::dump_cmd< vapi::Ip_route_dump >::m_dump
std::unique_ptr< vapi::Ip_route_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::route::ip_route_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:139
route_api_types.hpp
VOM::route::prefix_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:214
VOM::route::ip_route_cmds::update_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:45
VOM::route::ip_route_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:133
VOM::route::ip_route_cmds::update_cmd
A command class that creates or updates the route.
Definition: route_cmds.hpp:32
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::dump_cmd< vapi::Ip_route_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
VOM::route::ip_route_cmds::delete_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:117
VOM::route::ip_route_cmds::update_cmd::operator==
bool operator==(const update_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:38
VOM::route::ip_route_cmds::update_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:68
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::l3_proto_t::is_ipv6
bool is_ipv6() const
Definition: prefix.cpp:35
VOM::to_api
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
id
u8 id[64]
Definition: dhcp.api:160
VOM::rpc_cmd< HW::item< handle_t >, vapi::Ip_route_add_del >::msg_t
vapi::Ip_route_add_del msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::l3_proto_t
An L3 protocol can be used to construct a prefix that is used to match packets are part of a route.
Definition: prefix.hpp:52
VOM::route::ip_route_cmds::dump_cmd
A cmd class that Dumps ip fib routes.
Definition: route_cmds.hpp:98
VOM::srpc_cmd
Definition: srpc_cmd.hpp:24
VOM::route::ip_route_cmds::update_cmd::update_cmd
update_cmd(HW::item< handle_t > &item, table_id_t id, const prefix_t &prefix, const path_list_t &pl)
Constructor.
Definition: route_cmds.cpp:26
item
cJSON * item
Definition: cJSON.h:222
VOM::dump_cmd< vapi::Ip_route_dump >::dump_cmd
dump_cmd()
Default Constructor.
Definition: dump_cmd.hpp:55
VOM::route::ip_route_cmds::delete_cmd::operator==
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:89
VOM::route::table_id_t
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:121
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
VOM::route::ip_route_cmds::delete_cmd::delete_cmd
delete_cmd(HW::item< handle_t > &item, table_id_t id, const prefix_t &prefix)
Constructor.
Definition: route_cmds.cpp:79
api_types.hpp
prefix
vl_api_prefix_t prefix
Definition: ip.api:175
string
const char *const string
Definition: cJSON.h:172