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