21 namespace dhcp_client_cmds {
25 const std::string& hostname,
27 bool set_broadcast_flag)
30 , m_hostname(hostname)
31 , m_client_id(client_id)
32 , m_set_broadcast_flag(set_broadcast_flag)
39 return ((m_itf == other.m_itf) && (m_hostname == other.m_hostname));
45 msg_t req(con.
ctx(), std::ref(*
this));
47 auto& payload = req.get_request().get_payload();
49 payload.client.sw_if_index = m_itf.
value();
50 payload.client.pid = getpid();
51 payload.client.want_dhcp_event = 1;
52 payload.client.set_broadcast_flag = m_set_broadcast_flag;
54 memset(payload.client.hostname, 0,
sizeof(payload.client.hostname));
55 memcpy(payload.client.hostname, m_hostname.c_str(),
56 std::min(
sizeof(payload.client.hostname), m_hostname.length()));
58 memset(payload.client.id, 0,
sizeof(payload.client.id));
59 payload.client.id[0] = 1;
60 std::copy_n(begin(m_client_id.
bytes),
61 std::min(
sizeof(payload.client.id), m_client_id.
bytes.size()),
62 payload.client.id + 1);
74 <<
" itf:" << m_itf.
to_string() <<
" hostname:" << m_hostname;
81 const std::string& hostname)
84 , m_hostname(hostname)
91 return ((m_itf == other.m_itf) && (m_hostname == other.m_hostname));
97 msg_t req(con.
ctx(), std::ref(*
this));
99 auto& payload = req.get_request().get_payload();
101 payload.client.sw_if_index = m_itf.
value();
102 payload.client.pid = getpid();
103 payload.client.want_dhcp_event = 0;
105 memcpy(payload.client.hostname, m_hostname.c_str(),
106 std::min(
sizeof(payload.client.hostname), m_hostname.length()));
119 std::ostringstream s;
121 <<
" itf:" << m_itf.
to_string() <<
" hostname:" << m_hostname;
165 for (
auto& msg : *
this) {
166 auto& payload = msg.get_payload();
171 payload.lease.mask_width);
172 std::shared_ptr<interface> itf =
interface::find(payload.lease.sw_if_index);
175 std::shared_ptr<dhcp_client::lease_t> ev =
176 std::make_shared<dhcp_client::lease_t>(
177 s, itf,
from_bytes(0, payload.lease.router_address), pfx,
178 reinterpret_cast<const char*
>(payload.lease.hostname),
185 << payload.lease.sw_if_index;
195 return (
"dhcp-events");
211 m_dump.reset(
new msg_t(con.
ctx(), std::ref(*
this)));
223 return (
"dhcp-client-dump");
static const rc_t NOOP
The HW write/update action was/has not been attempted.
void retire(connection &con)
Retire the command - unsubscribe.
std::string to_string() const
convert to string format for debug purposes
uint32_t value() const
get the value of the handle
static std::shared_ptr< interface > find(const handle_t &h)
The the singular instance of the interface in the DB by handle.
A functor class represents our desire to recieve interface events.
Error codes that VPP will return during a HW write.
void flush()
flush/free all the events thus far reeived.
A class that listens to DHCP Events.
std::string to_string() const
convert to string format for debug purposes
Type def of a L2 address as read from VPP.
rc_t wait()
Wait on the commands promise.
void notify()
called in the VAPI RX thread when data is available.
bool operator==(const bind_cmd &i) const
Comparison operator - only used for UT.
std::string to_string() const
convert to string format for debug purposes
std::string to_string() const
convert to string format for debug purposes
virtual void handle_dhcp_event(std::shared_ptr< lease_t > e)=0
listener's virtual function invoked when a DHCP event is available to read
A representation of the connection to VPP.
A base class for all RPC commands to VPP.
std::vector< uint8_t > bytes
Underlying bytes array - filled from least to most significant.
std::string to_string() const
convert to string format for debug purposes
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
bind_cmd(HW::item< bool > &item, const handle_t &itf, const std::string &hostname, const l2_address_t &client_id, bool set_braodcast_flag=false)
Constructor.
std::string to_string() const
convert to string format for debug purposes
static const log_level_t INFO
std::unique_ptr< vapi::Event_registration< vapi::Dhcp_compl_event > > m_reg
The VAPI event registration.
unbind_cmd(HW::item< bool > &item, const handle_t &itf, const std::string &hostname)
Constructor.
static const state_t & from_vpp(int i)
A type declaration of an interface handle in VPP.
struct mac_address_t_ mac_address_t
vapi::Event_registration< vapi::Dhcp_compl_event > reg_t
static const rc_t OK
The HW write was successfull.
boost::asio::ip::address from_bytes(uint8_t is_ip6, const uint8_t *bytes)
Convert a VPP byte stinrg into a boost addresss.
static const log_level_t ERROR
bool operator==(const events_cmd &i) const
Comparison operator - only used for UT.
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
bool operator==(const unbind_cmd &i) const
Comparison operator - only used for UT.
events_cmd(dhcp_client::event_listener &el)
Constructor.
The VPP Object Model (VOM) library.
rc_t issue(connection &con)
Issue the command to VPP/HW.
void set(const rc_t &rc)
Set the HW return code - should only be called from the family of Command objects.
rc_t issue(connection &con)
Issue the command to VPP/HW.
rc_t issue(connection &con)
Issue the command to VPP/HW - subscribe to DHCP events.
An Event command base class.
DEFINE_VAPI_MSG_IDS_DHCP_API_JSON
rc_t issue(connection &con)
Issue the command to VPP/HW.
A cmd class that Unbinds Dhcp Config from an interface.
HW::item< bool > & m_hw_item
A reference to an object's HW::item that the command will update.
A command class that binds the DHCP config to the interface.
A cmd class that Dumps all the DHCP clients.
HW::item< bool > & item()
return the HW item the command updates
vapi::Dhcp_client_config msg_t
convenient typedef