8185c0910d273c94b949e6f1f336c0f324181b58
[vpp.git] / extras / vom / vom / arp_proxy_config_cmds.cpp
1 /*
2  * Copyright (c) 2017 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/arp_proxy_config_cmds.hpp"
17 #include "vom/api_types.hpp"
18
19 namespace VOM {
20 namespace arp_proxy_config_cmds {
21
22 config_cmd::config_cmd(HW::item<bool>& item,
23                        const boost::asio::ip::address_v4& low,
24                        const boost::asio::ip::address_v4& high)
25   : rpc_cmd(item)
26   , m_low(low)
27   , m_high(high)
28 {
29 }
30
31 bool
32 config_cmd::operator==(const config_cmd& o) const
33 {
34   return ((m_low == o.m_low) && (m_high == o.m_high));
35 }
36
37 rc_t
38 config_cmd::issue(connection& con)
39 {
40   msg_t req(con.ctx(), std::ref(*this));
41
42   auto& payload = req.get_request().get_payload();
43   payload.is_add = 1;
44
45   to_api(m_low, payload.proxy.low);
46   to_api(m_high, payload.proxy.hi);
47
48   VAPI_CALL(req.execute());
49
50   wait();
51
52   return (rc_t::OK);
53 }
54
55 std::string
56 config_cmd::to_string() const
57 {
58   std::ostringstream s;
59   s << "ARP-proxy-config: " << m_hw_item.to_string()
60     << " low:" << m_low.to_string() << " high:" << m_high.to_string();
61
62   return (s.str());
63 }
64
65 unconfig_cmd::unconfig_cmd(HW::item<bool>& item,
66                            const boost::asio::ip::address_v4& low,
67                            const boost::asio::ip::address_v4& high)
68   : rpc_cmd(item)
69   , m_low(low)
70   , m_high(high)
71 {
72 }
73
74 bool
75 unconfig_cmd::operator==(const unconfig_cmd& o) const
76 {
77   return ((m_low == o.m_low) && (m_high == o.m_high));
78 }
79
80 rc_t
81 unconfig_cmd::issue(connection& con)
82 {
83   msg_t req(con.ctx(), std::ref(*this));
84
85   auto& payload = req.get_request().get_payload();
86   payload.is_add = 0;
87
88   to_api(m_low, payload.proxy.low);
89   to_api(m_high, payload.proxy.hi);
90
91   VAPI_CALL(req.execute());
92
93   wait();
94   m_hw_item.set(rc_t::NOOP);
95
96   return (rc_t::OK);
97 }
98
99 std::string
100 unconfig_cmd::to_string() const
101 {
102   std::ostringstream s;
103   s << "ARP-proxy-unconfig: " << m_hw_item.to_string()
104     << " low:" << m_low.to_string() << " high:" << m_high.to_string();
105
106   return (s.str());
107 }
108
109 bool
110 dump_cmd::operator==(const dump_cmd& other) const
111 {
112   return (true);
113 }
114
115 rc_t
116 dump_cmd::issue(connection& con)
117 {
118   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
119
120   VAPI_CALL(m_dump->execute());
121
122   wait();
123
124   return rc_t::OK;
125 }
126
127 std::string
128 dump_cmd::to_string() const
129 {
130   return ("ARP-proxy-dump");
131 }
132
133 }; // namesapce cmds
134 }; // namespace VOM
135
136 /*
137  * fd.io coding-style-patch-verification: ON
138  *
139  * Local Variables:
140  * eval: (c-set-style "mozilla")
141  * End:
142  */