FD.io VPP  v21.06-3-gbb25fbf28
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 
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 
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 
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: OFF
146  *
147  * Local Variables:
148  * eval: (c-set-style "mozilla")
149  * End:
150  */
VOM::HW::item< bool >
VOM::dump_cmd< vapi::Ip_punt_redirect_dump >::msg_t
vapi::Ip_punt_redirect_dump msg_t
Definition: dump_cmd.hpp:46
VOM::rpc_cmd< HW::item< bool >, vapi::Ip_punt_redirect >::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::ip_punt_redirect_cmds::config_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: ip_punt_redirect_cmds.cpp:41
ip_punt_redirect_cmds.hpp
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
VOM::ip_punt_redirect_cmds::unconfig_cmd::unconfig_cmd
unconfig_cmd(HW::item< bool > &item, const handle_t rx_itf, const handle_t tx_itf, const boost::asio::ip::address &addr)
Constructor.
Definition: ip_punt_redirect_cmds.cpp:68
con
Connection con
Definition: vapi_cpp_test.cpp:56
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
VOM::rpc_cmd< HW::item< bool >, vapi::Ip_punt_redirect >::m_hw_item
HW::item< bool > & 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_punt_redirect_dump >::m_dump
std::unique_ptr< vapi::Ip_punt_redirect_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::ip_punt_redirect_cmds::config_cmd::operator==
bool operator==(const config_cmd &i) const
Comparison operator - only used for UT.
Definition: ip_punt_redirect_cmds.cpp:34
VOM::ip_punt_redirect_cmds::unconfig_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: ip_punt_redirect_cmds.cpp:87
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::ip_punt_redirect_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: ip_punt_redirect_cmds.cpp:136
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::ip_punt_redirect_cmds::unconfig_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: ip_punt_redirect_cmds.cpp:107
VOM::dump_cmd< vapi::Ip_punt_redirect_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::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
address
manual_print typedef address
Definition: ip_types.api:96
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::ip_punt_redirect_cmds::unconfig_cmd::operator==
bool operator==(const unconfig_cmd &i) const
Comparison operator - only used for UT.
Definition: ip_punt_redirect_cmds.cpp:80
VOM::ip_punt_redirect_cmds::unconfig_cmd
A cmd class that Unconfigs Ip punt redirect.
Definition: ip_punt_redirect_cmds.hpp:75
VOM::to_api
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
VOM::rpc_cmd< HW::item< bool >, vapi::Ip_punt_redirect >::msg_t
vapi::Ip_punt_redirect msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::ip_punt_redirect_cmds::config_cmd::config_cmd
config_cmd(HW::item< bool > &item, const handle_t rx_itf, const handle_t tx_itf, const boost::asio::ip::address &addr)
Constructor.
Definition: ip_punt_redirect_cmds.cpp:22
VOM::handle_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
VOM::ip_punt_redirect_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: ip_punt_redirect_cmds.cpp:118
VOM::ip_punt_redirect_cmds::config_cmd
A command class that configures the IP punt_redirect.
Definition: ip_punt_redirect_cmds.hpp:31
VOM::ip_punt_redirect_cmds::dump_cmd
A cmd class that Dumps all the IP punt redirect.
Definition: ip_punt_redirect_cmds.hpp:119
item
cJSON * item
Definition: cJSON.h:222
VOM::ip_punt_redirect_cmds::config_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: ip_punt_redirect_cmds.cpp:58
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::ip_punt_redirect_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: ip_punt_redirect_cmds.cpp:124
api_types.hpp
string
const char *const string
Definition: cJSON.h:172