FD.io VPP  v18.10-32-g1161dda
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 
18 namespace VOM {
19 namespace ip_punt_redirect_cmds {
20 
22  const handle_t& rx_itf,
23  const handle_t& tx_itf,
25  : rpc_cmd(item)
26  , m_rx_itf(rx_itf)
27  , m_tx_itf(tx_itf)
28  , m_addr(addr)
29 {
30 }
31 
32 bool
34 {
35  return ((m_rx_itf == o.m_rx_itf) && (m_tx_itf == o.m_tx_itf) &&
36  (m_addr == o.m_addr));
37 }
38 
39 rc_t
41 {
42  msg_t req(con.ctx(), std::ref(*this));
43 
44  auto& payload = req.get_request().get_payload();
45 
46  payload.is_add = 1;
47  payload.rx_sw_if_index = m_rx_itf.value();
48  payload.tx_sw_if_index = m_tx_itf.value();
49 
50  to_bytes(m_addr, &payload.is_ip6, payload.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-config: " << 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.rx_sw_if_index = m_rx_itf.value();
95  payload.tx_sw_if_index = m_tx_itf.value();
96 
97  to_bytes(m_addr, &payload.is_ip6, payload.nh);
98 
99  VAPI_CALL(req.execute());
100 
101  wait();
103 
104  return rc_t::OK;
105 }
106 
107 std::string
109 {
110  std::ostringstream s;
111  s << "IP-punt-redirect-unconfig: " << m_hw_item.to_string()
112  << " rx-itf:" << m_rx_itf.to_string() << " tx-itf:" << m_tx_itf.to_string()
113  << " next-hop:" << m_addr.to_string();
114 
115  return (s.str());
116 }
117 
118 }; // namespace ip_punt_redirect_cmds
119 }; // namespace VOM
120 
121 /*
122  * fd.io coding-style-patch-verification: ON
123  *
124  * Local Variables:
125  * eval: (c-set-style "mozilla")
126  * End:
127  */
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:99
typedef address
Definition: ip_types.api:35
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
A command class that configures the IP punt_redirect.
unconfig_cmd(HW::item< bool > &item, const handle_t &rx_itf, const handle_t &tx_itf, const boost::asio::ip::address &addr)
Constructor.
Error codes that VPP will return during a HW write.
Definition: types.hpp:84
vhost_vring_addr_t addr
Definition: vhost_user.h:121
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:160
std::string to_string() const
convert to string format for debug purposes
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:80
rc_t issue(connection &con)
Issue the command to VPP/HW.
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
rc_t issue(connection &con)
Issue the command to VPP/HW.
A cmd class that Unconfigs Ip punt redirect.
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
bool operator==(const unconfig_cmd &i) const
Comparison operator - only used for UT.
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
A type declaration of an interface handle in VPP.
Definition: types.hpp:228
bool operator==(const config_cmd &i) const
Comparison operator - only used for UT.
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:104
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
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:124
std::string to_string() const
convert to string format for debug purposes
config_cmd(HW::item< bool > &item, const handle_t &rx_itf, const handle_t &tx_itf, const boost::asio::ip::address &addr)
Constructor.
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_punt_redirect msg_t
convenient typedef
Definition: rpc_cmd.hpp:44