FD.io VPP  v19.08-27-gf4dcae4
Vector Packet Processing
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
67 std::string
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 
116 std::string
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 
155 std::string
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: ON
167  *
168  * Local Variables:
169  * eval: (c-set-style "mozilla")
170  * End:
171  */
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:121
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:133
bool operator==(const update_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:38
A command class that creates or updates the route.
Definition: route_cmds.hpp:32
A cmd class that Dumps ip fib routes.
Definition: route_cmds.hpp:98
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
vl_api_mprefix_t prefix
Definition: ip.api:456
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
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:139
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:68
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:89
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:117
bool is_ipv6() const
Definition: prefix.cpp:35
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
A representation of the connection to VPP.
Definition: connection.hpp:33
dump_cmd()
Default Constructor.
Definition: dump_cmd.hpp:55
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:214
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:95
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
std::set< path > path_list_t
A path-list is a set of paths.
Definition: route.hpp:231
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
A cmd class that deletes a route.
Definition: route_cmds.hpp:67
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
delete_cmd(HW::item< handle_t > &item, table_id_t id, const prefix_t &prefix)
Constructor.
Definition: route_cmds.cpp:79
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:45
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
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
std::unique_ptr< vapi::Ip_route_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:156
A prefix defintion.
Definition: prefix.hpp:131
HW::item< handle_t > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:134
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125
vapi::Ip_route_add_del msg_t
convenient typedef
Definition: rpc_cmd.hpp:46