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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/gbp_endpoint_cmds.hpp"
17 #include "vom/api_types.hpp"
19 DEFINE_VAPI_MSG_IDS_GBP_API_JSON;
22 namespace gbp_endpoint_cmds {
24 static vapi_enum_gbp_endpoint_flags
25 to_api(const gbp_endpoint::flags_t& in)
27 vapi_enum_gbp_endpoint_flags out = GBP_API_ENDPOINT_FLAG_NONE;
29 if (in & gbp_endpoint::flags_t::REMOTE)
30 out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_REMOTE);
31 if (in & gbp_endpoint::flags_t::BOUNCE)
32 out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_BOUNCE);
33 if (in & gbp_endpoint::flags_t::LEARNT)
34 out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_LEARNT);
35 if (in & gbp_endpoint::flags_t::EXTERNAL)
36 out = (vapi_enum_gbp_endpoint_flags)(out | GBP_API_ENDPOINT_FLAG_EXTERNAL);
41 create_cmd::create_cmd(HW::item<handle_t>& item,
43 const std::vector<boost::asio::ip::address>& ip_addrs,
44 const mac_address_t& mac,
46 const gbp_endpoint::flags_t& flags)
49 , m_ip_addrs(ip_addrs)
57 create_cmd::operator==(const create_cmd& other) const
59 return ((m_itf == other.m_itf) && (m_ip_addrs == other.m_ip_addrs) &&
60 (m_mac == other.m_mac) && (m_sclass == other.m_sclass) &&
61 (m_flags == other.m_flags));
65 create_cmd::issue(connection& con)
67 msg_t req(con.ctx(), m_ip_addrs.size() * sizeof(vapi_type_address),
71 auto& payload = req.get_request().get_payload();
72 payload.endpoint.sw_if_index = m_itf.value();
73 payload.endpoint.sclass = m_sclass;
74 payload.endpoint.n_ips = m_ip_addrs.size();
75 payload.endpoint.flags = to_api(m_flags);
77 for (n = 0; n < payload.endpoint.n_ips; n++) {
78 VOM::to_api(m_ip_addrs[n], payload.endpoint.ips[n]);
80 to_api(m_mac, payload.endpoint.mac);
82 VAPI_CALL(req.execute());
88 create_cmd::operator()(vapi::Gbp_endpoint_add& reply)
90 int handle = reply.get_response().get_payload().handle;
91 int retval = reply.get_response().get_payload().retval;
93 VOM_LOG(log_level_t::DEBUG) << this->to_string() << " " << retval;
95 rc_t rc = rc_t::from_vpp_retval(retval);
96 handle_t hdl = handle_t::INVALID;
102 this->fulfill(HW::item<handle_t>(hdl, rc));
108 create_cmd::to_string() const
110 std::ostringstream s;
111 s << "gbp-endpoint-create: " << m_hw_item.to_string() << " itf:" << m_itf
113 for (auto ip : m_ip_addrs)
116 s << "] mac:" << m_mac << " slcass:" << m_sclass
117 << " flags:" << m_flags.to_string();
122 delete_cmd::delete_cmd(HW::item<handle_t>& item)
128 delete_cmd::operator==(const delete_cmd& other) const
130 return (m_hw_item == other.m_hw_item);
134 delete_cmd::issue(connection& con)
136 msg_t req(con.ctx(), std::ref(*this));
138 auto& payload = req.get_request().get_payload();
139 payload.handle = m_hw_item.data().value();
141 VAPI_CALL(req.execute());
147 delete_cmd::to_string() const
149 std::ostringstream s;
150 s << "gbp-endpoint-delete: " << m_hw_item.to_string();
160 dump_cmd::operator==(const dump_cmd& other) const
166 dump_cmd::issue(connection& con)
168 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
170 VAPI_CALL(m_dump->execute());
178 dump_cmd::to_string() const
180 return ("gbp-endpoint-dump");
183 }; // namespace gbp_endpoint_cmds
187 * fd.io coding-style-patch-verification: ON
190 * eval: (c-set-style "mozilla")