BD ARP entry use common API types
[vpp.git] / extras / vom / vom / bridge_domain_arp_entry_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/bridge_domain_arp_entry_cmds.hpp"
17 #include "vom/api_types.hpp"
18
19 namespace VOM {
20 namespace bridge_domain_arp_entry_cmds {
21
22 create_cmd::create_cmd(HW::item<bool>& item,
23                        uint32_t bd,
24                        const mac_address_t& mac,
25                        const boost::asio::ip::address& ip_addr)
26   : rpc_cmd(item)
27   , m_bd(bd)
28   , m_mac(mac)
29   , m_ip_addr(ip_addr)
30 {
31 }
32
33 bool
34 create_cmd::operator==(const create_cmd& other) const
35 {
36   return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
37           (m_bd == other.m_bd));
38 }
39
40 rc_t
41 create_cmd::issue(connection& con)
42 {
43   msg_t req(con.ctx(), std::ref(*this));
44
45   auto& payload = req.get_request().get_payload();
46   payload.bd_id = m_bd;
47   payload.is_add = 1;
48   payload.mac = to_api(m_mac);
49   payload.ip = to_api(m_ip_addr);
50
51   VAPI_CALL(req.execute());
52
53   return (wait());
54 }
55
56 std::string
57 create_cmd::to_string() const
58 {
59   std::ostringstream s;
60   s << "bridge-domain-arp-entry-create: " << m_hw_item.to_string()
61     << " bd:" << m_bd << " mac:" << m_mac.to_string()
62     << " ip:" << m_ip_addr.to_string();
63
64   return (s.str());
65 }
66
67 delete_cmd::delete_cmd(HW::item<bool>& item,
68                        uint32_t bd,
69                        const mac_address_t& mac,
70                        const boost::asio::ip::address& ip_addr)
71   : rpc_cmd(item)
72   , m_bd(bd)
73   , m_mac(mac)
74   , m_ip_addr(ip_addr)
75 {
76 }
77
78 bool
79 delete_cmd::operator==(const delete_cmd& other) const
80 {
81   return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
82           (m_bd == other.m_bd));
83 }
84
85 rc_t
86 delete_cmd::issue(connection& con)
87 {
88   msg_t req(con.ctx(), std::ref(*this));
89
90   auto& payload = req.get_request().get_payload();
91   payload.bd_id = m_bd;
92   payload.is_add = 0;
93   payload.mac = to_api(m_mac);
94   payload.ip = to_api(m_ip_addr);
95
96   VAPI_CALL(req.execute());
97
98   wait();
99   m_hw_item.set(rc_t::NOOP);
100
101   return rc_t::OK;
102 }
103
104 std::string
105 delete_cmd::to_string() const
106 {
107   std::ostringstream s;
108   s << "bridge-domain-arp-entry-delete: " << m_hw_item.to_string()
109     << " bd:" << m_bd << " mac:" << m_mac.to_string()
110     << " ip:" << m_ip_addr.to_string();
111
112   return (s.str());
113 }
114
115 dump_cmd::dump_cmd(uint32_t bd_id)
116   : m_bd(bd_id)
117 {
118 }
119
120 dump_cmd::dump_cmd(const dump_cmd& d)
121   : m_bd(d.m_bd)
122 {
123 }
124
125 bool
126 dump_cmd::operator==(const dump_cmd& other) const
127 {
128   return (true);
129 }
130
131 rc_t
132 dump_cmd::issue(connection& con)
133 {
134   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
135
136   auto& payload = m_dump->get_request().get_payload();
137   payload.bd_id = m_bd;
138
139   VAPI_CALL(m_dump->execute());
140
141   wait();
142
143   return rc_t::OK;
144 }
145
146 std::string
147 dump_cmd::to_string() const
148 {
149   return ("bridge-domain-arp-entry-dump");
150 }
151
152 }; // namespace bridge_domain_arp_entry
153 }; // namespace VOM
154
155 /*
156  * fd.io coding-style-patch-verification: ON
157  *
158  * Local Variables:
159  * eval: (c-set-style "mozilla")
160  * End:
161  */