22 namespace dhcp_client_cmds {
32 , m_hostname(hostname)
33 , m_client_id(client_id)
34 , m_set_broadcast_flag(set_broadcast_flag)
42 return ((m_itf == other.m_itf) && (m_hostname == other.m_hostname));
48 msg_t req(con.
ctx(), std::ref(*
this));
50 auto& payload = req.get_request().get_payload();
52 payload.client.sw_if_index = m_itf.
value();
53 payload.client.pid = getpid();
54 payload.client.want_dhcp_event = 1;
55 payload.client.set_broadcast_flag = m_set_broadcast_flag;
56 payload.client.dscp =
to_api(m_dscp);
58 memset(payload.client.hostname, 0,
sizeof(payload.client.hostname));
59 memcpy(payload.client.hostname, m_hostname.c_str(),
60 std::min(
sizeof(payload.client.hostname), m_hostname.length()));
62 memset(payload.client.id, 0,
sizeof(payload.client.id));
63 payload.client.id[0] = 1;
64 std::copy_n(begin(m_client_id.
bytes),
65 std::min(
sizeof(payload.client.id), m_client_id.
bytes.size()),
66 payload.client.id + 1);
78 <<
" itf:" << m_itf.
to_string() <<
" hostname:" << m_hostname
79 <<
" client_id:[" << m_client_id <<
"] " 90 , m_hostname(hostname)
97 return ((m_itf == other.m_itf) && (m_hostname == other.m_hostname));
103 msg_t req(con.
ctx(), std::ref(*
this));
105 auto& payload = req.get_request().get_payload();
107 payload.client.sw_if_index = m_itf.
value();
108 payload.client.pid = getpid();
109 payload.client.want_dhcp_event = 0;
111 memcpy(payload.client.hostname, m_hostname.c_str(),
112 std::min(
sizeof(payload.client.hostname), m_hostname.length()));
125 std::ostringstream s;
127 <<
" itf:" << m_itf.
to_string() <<
" hostname:" << m_hostname;
171 for (
auto& msg : *
this) {
172 auto& payload = msg.get_payload();
177 (uint8_t*)&payload.lease.host_address.un,
178 payload.lease.mask_width);
179 std::shared_ptr<interface> itf =
interface::find(payload.lease.sw_if_index);
182 std::shared_ptr<dhcp_client::lease_t> ev =
183 std::make_shared<dhcp_client::lease_t>(
184 s, itf,
from_bytes(0, (uint8_t*)&payload.lease.router_address.un),
185 pfx,
reinterpret_cast<const char*
>(payload.lease.hostname),
192 << payload.lease.sw_if_index;
202 return (
"dhcp-events");
218 m_dump.reset(
new msg_t(con.
ctx(), std::ref(*
this)));
230 return (
"dhcp-client-dump");
static const rc_t NOOP
The HW write/update action was/has not been attempted.
std::string to_string() const
convert to string format for debug purposes
void retire(connection &con)
Retire the command - unsubscribe.
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.
bool operator==(const unbind_cmd &i) const
Comparison operator - only used for UT.
Error codes that VPP will return during a HW write.
std::string to_string() const
convert to string format for debug purposes
void flush()
flush/free all the events thus far reeived.
A class that listens to DHCP Events.
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Type def of a L2 address as read from VPP.
rc_t wait()
Wait on the commands promise.
std::string to_string() const
convert to string format for debug purposes
void notify()
called in the VAPI RX thread when data is available.
bind_cmd(HW::item< bool > &item, const handle_t &itf, const std::string &hostname, const l2_address_t &client_id, bool set_braodcast_flag, const ip_dscp_t &dscp)
Constructor.
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.
bool operator==(const events_cmd &i) const
Comparison operator - only used for UT.
A base class for all RPC commands to VPP.
std::vector< uint8_t > bytes
Underlying bytes array - filled from least to most significant.
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
static const log_level_t INFO
std::string to_string() const
convert to string format for debug purposes
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
std::string to_string() const
convert to string format for debug purposes
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.
const std::string & to_string() const
convert to string format for debug purposes
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
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
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.
std::string to_string() const
convert to string format for debug purposes
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.
bool operator==(const bind_cmd &i) const
Comparison operator - only used for UT.
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