VPP-1507: Added binary api to dump configured ip_punt_redirect
[vpp.git] / extras / vom / vom / ip_punt_redirect_cmds.cpp
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
16 #include "vom/ip_punt_redirect_cmds.hpp"
17 #include <vom/api_types.hpp>
18
19 namespace VOM {
20 namespace ip_punt_redirect_cmds {
21
22 config_cmd::config_cmd(HW::item<bool>& item,
23                        const handle_t& rx_itf,
24                        const handle_t& tx_itf,
25                        const boost::asio::ip::address& addr)
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
34 config_cmd::operator==(const config_cmd& o) const
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
41 config_cmd::issue(connection& con)
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   payload.punt.nh = to_api(m_addr);
51
52   VAPI_CALL(req.execute());
53
54   return (wait());
55 }
56
57 std::string
58 config_cmd::to_string() const
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
68 unconfig_cmd::unconfig_cmd(HW::item<bool>& item,
69                            const handle_t& rx_itf,
70                            const handle_t& tx_itf,
71                            const boost::asio::ip::address& addr)
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
80 unconfig_cmd::operator==(const unconfig_cmd& o) const
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
87 unconfig_cmd::issue(connection& con)
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   payload.punt.nh = to_api(m_addr);
97
98   VAPI_CALL(req.execute());
99
100   wait();
101   m_hw_item.set(rc_t::NOOP);
102
103   return rc_t::OK;
104 }
105
106 std::string
107 unconfig_cmd::to_string() const
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 }; // namespace ip_punt_redirect_cmds
118 }; // namespace VOM
119
120 /*
121  * fd.io coding-style-patch-verification: ON
122  *
123  * Local Variables:
124  * eval: (c-set-style "mozilla")
125  * End:
126  */