FD.io VPP  v19.01.3-6-g70449b9b9
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_api_types.hpp>
19 #include <vom/route_cmds.hpp>
20 
21 namespace VOM {
22 namespace route {
23 namespace ip_route_cmds {
24 
26  table_id_t id,
27  const prefix_t& prefix,
28  const path& path)
29  : rpc_cmd(item)
30  , m_id(id)
31  , m_prefix(prefix)
32  , m_path(path)
33 {
34 }
35 
36 bool
38 {
39  return ((m_prefix == other.m_prefix) && (m_id == other.m_id) &&
40  (m_path == other.m_path));
41 }
42 
43 rc_t
45 {
46  msg_t req(con.ctx(), 0, std::ref(*this));
47 
48  auto& payload = req.get_request().get_payload();
49 
50  payload.table_id = m_id;
51  payload.is_add = 1;
52  payload.is_multipath = 0;
53 
54  m_prefix.to_vpp(&payload.is_ipv6, payload.dst_address,
55  &payload.dst_address_length);
56  to_vpp(m_path, payload);
57 
58  VAPI_CALL(req.execute());
59 
60  return (wait());
61 }
62 
63 std::string
65 {
66  std::ostringstream s;
67  s << "ip-route-create: " << m_hw_item.to_string() << " table-id:" << m_id
68  << " prefix:" << m_prefix.to_string() << " paths:" << m_path.to_string();
69 
70  return (s.str());
71 }
72 
74  table_id_t id,
75  const prefix_t& prefix,
76  const path& path)
77  : rpc_cmd(item)
78  , m_id(id)
79  , m_prefix(prefix)
80  , m_path(path)
81 {
82 }
83 
84 bool
86 {
87  return ((m_prefix == other.m_prefix) && (m_id == other.m_id) &&
88  (m_path == other.m_path));
89 }
90 
91 rc_t
93 {
94  msg_t req(con.ctx(), 0, std::ref(*this));
95 
96  auto& payload = req.get_request().get_payload();
97  payload.table_id = m_id;
98  payload.is_add = 0;
99 
100  m_prefix.to_vpp(&payload.is_ipv6, payload.dst_address,
101  &payload.dst_address_length);
102  to_vpp(m_path, payload);
103 
104  VAPI_CALL(req.execute());
105 
106  wait();
108 
109  return rc_t::OK;
110 }
111 
112 std::string
114 {
115  std::ostringstream s;
116  s << "ip-route-delete: " << m_hw_item.to_string() << " id:" << m_id
117  << " prefix:" << m_prefix.to_string() << " paths:" << m_path.to_string();
118 
119  return (s.str());
120 }
121 
123 {
124 }
125 
126 bool
128 {
129  return (true);
130 }
131 
132 rc_t
134 {
135  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
136 
137  VAPI_CALL(m_dump->execute());
138 
139  wait();
140 
141  return rc_t::OK;
142 }
143 
144 std::string
146 {
147  return ("ip-route-v4-dump");
148 }
149 
151 {
152 }
153 
154 bool
156 {
157  return (true);
158 }
159 
160 rc_t
162 {
163  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
164 
165  VAPI_CALL(m_dump->execute());
166 
167  wait();
168 
169  return rc_t::OK;
170 }
171 
172 std::string
174 {
175  return ("ip-route-v6-dump");
176 }
177 } // namespace ip_route_cmds
178 } // namespace route
179 } // namespace vom
180  /*
181  * fd.io coding-style-patch-verification: ON
182  *
183  * Local Variables:
184  * eval: (c-set-style "mozilla")
185  * End:
186  */
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:104
A cmd class that Dumps ipv6 fib.
Definition: route_cmds.hpp:135
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:64
A command class that creates or updates the route.
Definition: route_cmds.hpp:32
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:183
void to_vpp(const route::path &p, vapi_payload_ip_add_del_route &payload)
A path for IP or MPLS routes.
Definition: route.hpp:32
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
std::string to_string() const
convert to string format for debug purposes
Definition: route.cpp:196
bool operator==(const dump_v6_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:155
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:161
A representation of the connection to VPP.
Definition: connection.hpp:33
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
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:145
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:113
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:92
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
delete_cmd(HW::item< bool > &item, table_id_t id, const prefix_t &prefix, const path &path)
Constructor.
Definition: route_cmds.cpp:73
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
update_cmd(HW::item< bool > &item, table_id_t id, const prefix_t &prefix, const path &path)
Constructor.
Definition: route_cmds.cpp:25
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:102
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:44
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
bool operator==(const dump_v4_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:127
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
typedef prefix
Definition: ip_types.api:35
std::string to_string() const
convert to string format for debug purposes
Definition: route_cmds.cpp:173
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: route_cmds.cpp:133
bool operator==(const update_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:37
A prefix defintion.
Definition: prefix.hpp:92
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: route_cmds.cpp:85
HW::item< bool > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:134
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vapi::Ip_add_del_route msg_t
convenient typedef
Definition: rpc_cmd.hpp:46