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/dhcp_config_cmds.hpp"
18 DEFINE_VAPI_MSG_IDS_DHCP_API_JSON;
21 namespace dhcp_config_cmds {
23 bind_cmd::bind_cmd(HW::item<bool>& item,
25 const std::string& hostname,
26 const l2_address_t& client_id)
29 , m_hostname(hostname)
30 , m_client_id(client_id)
35 bind_cmd::operator==(const bind_cmd& other) const
37 return ((m_itf == other.m_itf) && (m_hostname == other.m_hostname));
41 bind_cmd::issue(connection& con)
43 msg_t req(con.ctx(), std::ref(*this));
45 auto& payload = req.get_request().get_payload();
46 payload.sw_if_index = m_itf.value();
48 payload.pid = getpid();
49 payload.want_dhcp_event = 1;
51 memcpy(payload.hostname, m_hostname.c_str(),
52 std::min(sizeof(payload.hostname), m_hostname.length()));
54 memset(payload.client_id, 0, sizeof(payload.client_id));
55 payload.client_id[0] = 1;
56 std::copy_n(begin(m_client_id.bytes),
57 std::min(sizeof(payload.client_id), m_client_id.bytes.size()),
58 payload.client_id + 1);
60 VAPI_CALL(req.execute());
62 m_hw_item.set(wait());
68 bind_cmd::to_string() const
71 s << "Dhcp-config-bind: " << m_hw_item.to_string()
72 << " itf:" << m_itf.to_string() << " hostname:" << m_hostname;
77 unbind_cmd::unbind_cmd(HW::item<bool>& item,
79 const std::string& hostname)
82 , m_hostname(hostname)
87 unbind_cmd::operator==(const unbind_cmd& other) const
89 return ((m_itf == other.m_itf) && (m_hostname == other.m_hostname));
93 unbind_cmd::issue(connection& con)
95 msg_t req(con.ctx(), std::ref(*this));
97 auto& payload = req.get_request().get_payload();
98 payload.sw_if_index = m_itf.value();
100 payload.pid = getpid();
101 payload.want_dhcp_event = 0;
103 memcpy(payload.hostname, m_hostname.c_str(),
104 std::min(sizeof(payload.hostname), m_hostname.length()));
106 VAPI_CALL(req.execute());
109 m_hw_item.set(rc_t::NOOP);
115 unbind_cmd::to_string() const
117 std::ostringstream s;
118 s << "Dhcp-config-unbind: " << m_hw_item.to_string()
119 << " itf:" << m_itf.to_string() << " hostname:" << m_hostname;
124 events_cmd::events_cmd(dhcp_config::event_listener& el)
125 : event_cmd(el.status())
131 events_cmd::operator==(const events_cmd& other) const
137 events_cmd::issue(connection& con)
140 * Set the call back to handle DHCP complete envets.
142 m_reg.reset(new reg_t(con.ctx(), std::ref(*this)));
145 * return in-progress so the command stays in the pending list.
147 return (rc_t::INPROGRESS);
151 events_cmd::retire(connection& con)
158 m_listener.handle_dhcp_event(this);
162 events_cmd::to_string() const
164 return ("dhcp-events");
169 * fd.io coding-style-patch-verification: ON
172 * eval: (c-set-style "mozilla")