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.hpp"
18 DEFINE_VAPI_MSG_IDS_DHCP_API_JSON;
21 dhcp_config::bind_cmd::bind_cmd(HW::item<bool>& item,
23 const std::string& hostname,
24 const l2_address_t& client_id)
27 , m_hostname(hostname)
28 , m_client_id(client_id)
33 dhcp_config::bind_cmd::operator==(const bind_cmd& other) const
35 return ((m_itf == other.m_itf) && (m_hostname == other.m_hostname));
39 dhcp_config::bind_cmd::issue(connection& con)
41 msg_t req(con.ctx(), std::ref(*this));
43 auto& payload = req.get_request().get_payload();
44 payload.sw_if_index = m_itf.value();
46 payload.pid = getpid();
47 payload.want_dhcp_event = 1;
49 memcpy(payload.hostname, m_hostname.c_str(),
50 std::min(sizeof(payload.hostname), m_hostname.length()));
52 memset(payload.client_id, 0, sizeof(payload.client_id));
53 payload.client_id[0] = 1;
54 std::copy_n(begin(m_client_id.bytes),
55 std::min(sizeof(payload.client_id), m_client_id.bytes.size()),
56 payload.client_id + 1);
58 VAPI_CALL(req.execute());
60 m_hw_item.set(wait());
66 dhcp_config::bind_cmd::to_string() const
69 s << "Dhcp-config-bind: " << m_hw_item.to_string()
70 << " itf:" << m_itf.to_string() << " hostname:" << m_hostname;
75 dhcp_config::unbind_cmd::unbind_cmd(HW::item<bool>& item,
77 const std::string& hostname)
80 , m_hostname(hostname)
85 dhcp_config::unbind_cmd::operator==(const unbind_cmd& other) const
87 return ((m_itf == other.m_itf) && (m_hostname == other.m_hostname));
91 dhcp_config::unbind_cmd::issue(connection& con)
93 msg_t req(con.ctx(), std::ref(*this));
95 auto& payload = req.get_request().get_payload();
96 payload.sw_if_index = m_itf.value();
98 payload.pid = getpid();
99 payload.want_dhcp_event = 0;
101 memcpy(payload.hostname, m_hostname.c_str(),
102 std::min(sizeof(payload.hostname), m_hostname.length()));
104 VAPI_CALL(req.execute());
107 m_hw_item.set(rc_t::NOOP);
113 dhcp_config::unbind_cmd::to_string() const
115 std::ostringstream s;
116 s << "Dhcp-config-unbind: " << m_hw_item.to_string()
117 << " itf:" << m_itf.to_string() << " hostname:" << m_hostname;
122 dhcp_config::events_cmd::events_cmd(event_listener& el)
123 : event_cmd(el.status())
129 dhcp_config::events_cmd::operator==(const events_cmd& other) const
135 dhcp_config::events_cmd::issue(connection& con)
138 * Set the call back to handle DHCP complete envets.
140 m_reg.reset(new reg_t(con.ctx(), std::ref(*this)));
143 * return in-progress so the command stays in the pending list.
145 return (rc_t::INPROGRESS);
149 dhcp_config::events_cmd::retire(connection& con)
154 dhcp_config::events_cmd::notify()
156 m_listener.handle_dhcp_event(this);
160 dhcp_config::events_cmd::to_string() const
162 return ("dhcp-events");
167 * fd.io coding-style-patch-verification: ON
170 * eval: (c-set-style "mozilla")