8ab6005eddbf34267ecb3c0b7b6c2b62f927eb75
[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
18 namespace VOM {
19 namespace ip_punt_redirect_cmds {
20
21 config_cmd::config_cmd(HW::item<bool>& item,
22                        const handle_t& rx_itf,
23                        const handle_t& tx_itf,
24                        const boost::asio::ip::address& addr)
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
33 config_cmd::operator==(const config_cmd& o) const
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
40 config_cmd::issue(connection& con)
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
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.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();
102   m_hw_item.set(rc_t::NOOP);
103
104   return rc_t::OK;
105 }
106
107 std::string
108 unconfig_cmd::to_string() const
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  */