FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
ip_punt_redirect_cmds.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 
17 #include <vom/api_types.hpp>
18 
19 namespace VOM {
20 namespace ip_punt_redirect_cmds {
21 
23  const handle_t rx_itf,
24  const handle_t tx_itf,
26  : rpc_cmd(item)
27  , m_rx_itf(rx_itf)
28  , m_tx_itf(tx_itf)
29  , m_addr(addr)
30 {
31 }
32 
33 bool
35 {
36  return ((m_rx_itf == o.m_rx_itf) && (m_tx_itf == o.m_tx_itf) &&
37  (m_addr == o.m_addr));
38 }
39 
40 rc_t
42 {
43  msg_t req(con.ctx(), std::ref(*this));
44 
45  auto& payload = req.get_request().get_payload();
46 
47  payload.is_add = 1;
48  payload.punt.rx_sw_if_index = m_rx_itf.value();
49  payload.punt.tx_sw_if_index = m_tx_itf.value();
50  to_api(m_addr, payload.punt.nh);
51 
52  VAPI_CALL(req.execute());
53 
54  return (wait());
55 }
56 
57 std::string
59 {
60  std::ostringstream s;
61  s << "IP-punt-redirect: " << m_hw_item.to_string()
62  << " rx-itf:" << m_rx_itf.to_string() << " tx-itf:" << m_tx_itf.to_string()
63  << " next-hop:" << m_addr;
64 
65  return (s.str());
66 }
67 
69  const handle_t rx_itf,
70  const handle_t tx_itf,
72  : rpc_cmd(item)
73  , m_rx_itf(rx_itf)
74  , m_tx_itf(tx_itf)
75  , m_addr(addr)
76 {
77 }
78 
79 bool
81 {
82  return ((m_rx_itf == o.m_rx_itf) && (m_tx_itf == o.m_tx_itf) &&
83  (m_addr == o.m_addr));
84 }
85 
86 rc_t
88 {
89  msg_t req(con.ctx(), std::ref(*this));
90 
91  auto& payload = req.get_request().get_payload();
92 
93  payload.is_add = 0;
94  payload.punt.rx_sw_if_index = m_rx_itf.value();
95  payload.punt.tx_sw_if_index = m_tx_itf.value();
96  to_api(m_addr, payload.punt.nh);
97 
98  VAPI_CALL(req.execute());
99 
100  wait();
102 
103  return rc_t::OK;
104 }
105 
106 std::string
108 {
109  std::ostringstream s;
110  s << "IP-punt-redirect-unconfig: " << m_hw_item.to_string()
111  << " rx-itf:" << m_rx_itf.to_string() << " tx-itf:" << m_tx_itf.to_string()
112  << " next-hop:" << m_addr.to_string();
113 
114  return (s.str());
115 }
116 
117 bool
118 dump_cmd::operator==(const dump_cmd& other) const
119 {
120  return (true);
121 }
122 
123 rc_t
125 {
126  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
127 
128  VAPI_CALL(m_dump->execute());
129 
130  wait();
131 
132  return rc_t::OK;
133 }
134 
135 std::string
137 {
138  return ("ip-punt-redirect-dump");
139 }
140 
141 }; // namespace ip_punt_redirect_cmds
142 }; // namespace VOM
143 
144 /*
145  * fd.io coding-style-patch-verification: ON
146  *
147  * Local Variables:
148  * eval: (c-set-style "mozilla")
149  * End:
150  */
config_cmd(HW::item< bool > &item, const handle_t rx_itf, const handle_t tx_itf, const boost::asio::ip::address &addr)
Constructor.
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
typedef address
Definition: ip_types.api:30
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
A command class that configures the IP punt_redirect.
bool operator==(const config_cmd &i) const
Comparison operator - only used for UT.
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
vhost_vring_addr_t addr
Definition: vhost_user.h:121
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.
rc_t issue(connection &con)
Issue the command to VPP/HW.
A cmd class that Unconfigs Ip punt redirect.
A representation of the connection to VPP.
Definition: connection.hpp:33
void to_api(const ip_address_t &a, vapi_type_address &v)
Definition: api_types.cpp:21
unconfig_cmd(HW::item< bool > &item, const handle_t rx_itf, const handle_t tx_itf, const boost::asio::ip::address &addr)
Constructor.
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::string to_string() const
convert to string format for debug purposes
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
std::string to_string() const
convert to string format for debug purposes
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
rc_t issue(connection &con)
Issue the command to VPP/HW.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
A cmd class that Dumps all the IP punt redirect.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
std::string to_string() const
convert to string format for debug purposes
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
bool operator==(const unconfig_cmd &i) const
Comparison operator - only used for UT.
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_punt_redirect msg_t
convenient typedef
Definition: rpc_cmd.hpp:46