26 dhcp_client::state_t::state_t(
int v,
const std::string& s)
27 : enum_base<dhcp_client::state_t>(v, s)
31 const dhcp_client::state_t&
43 std::weak_ptr<dhcp_client_cmds::events_cmd> dhcp_client::m_s_event_cmd;
44 dhcp_client::dhcp_client_listener dhcp_client::m_listener;
49 const std::string& hostname,
50 bool set_broadcast_flag,
53 : m_itf(itf.singular())
54 , m_hostname(hostname)
56 , m_set_broadcast_flag(set_broadcast_flag)
60 , m_event_cmd(get_event_cmd())
65 const std::string& hostname,
67 bool set_broadcast_flag,
71 , m_hostname(hostname)
72 , m_client_id(client_id)
73 , m_set_broadcast_flag(set_broadcast_flag)
77 , m_event_cmd(get_event_cmd())
83 , m_hostname(o.m_hostname)
84 , m_client_id(o.m_client_id)
85 , m_set_broadcast_flag(o.m_set_broadcast_flag)
89 , m_event_cmd(o.m_event_cmd)
98 m_db.release(m_itf->key(),
this);
104 return ((
key() == l.
key()) && (m_hostname == l.m_hostname) &&
105 (m_client_id == l.m_client_id && m_dscp == l.m_dscp));
111 return (m_itf->key());
131 dhcp_client::replay()
135 m_binding, m_itf->handle(), m_hostname, m_client_id,
false, m_dscp));
142 std::ostringstream s;
143 s <<
"DHCP-client: " << m_itf->to_string() <<
" hostname:" << m_hostname
144 <<
" client_id:[" << m_client_id <<
"] " 147 s <<
" " << m_lease->to_string();
162 m_binding, m_itf->handle(), m_hostname, m_client_id,
false, m_dscp));
166 m_lease = desired.m_lease;
167 if (m_evl != desired.m_evl) {
168 m_evl = desired.m_evl;
172 const std::shared_ptr<dhcp_client::lease_t>
184 std::shared_ptr<dhcp_client>
187 return (m_db.find_or_add(temp.m_itf->key(), temp));
190 std::shared_ptr<dhcp_client>
193 return (m_db.find(k));
196 std::shared_ptr<dhcp_client>
199 return find_or_add(*
this);
209 std::shared_ptr<interface>
itf,
216 , router_address(router_address)
217 , host_prefix(host_prefix)
226 std::stringstream ss;
236 : m_status(
rc_t::NOOP)
253 dhcp_client::event_handler::handle_replay()
261 std::shared_ptr<dhcp_client_cmds::dump_cmd>
cmd =
262 std::make_shared<dhcp_client_cmds::dump_cmd>();
267 for (
auto& record : *cmd) {
268 auto& payload = record.get_payload();
270 std::shared_ptr<interface> itf =
275 <<
" itf:" << payload.client.sw_if_index;
282 payload.lease.mask_width);
283 std::string hostname =
284 reinterpret_cast<const char*
>(payload.lease.hostname);
286 dhcp_client dc(*itf, hostname, l2, payload.client.set_broadcast_flag,
288 dc.
lease(std::make_shared<dhcp_client::lease_t>(
289 s, itf,
from_bytes(0, payload.lease.router_address), pfx, hostname,
296 dhcp_client::event_handler::order()
const 307 std::shared_ptr<dhcp_client_cmds::events_cmd>
308 dhcp_client::get_event_cmd()
310 if (m_s_event_cmd.expired()) {
311 std::shared_ptr<dhcp_client_cmds::events_cmd>
c =
312 std::make_shared<dhcp_client_cmds::events_cmd>(m_listener);
322 return (m_s_event_cmd.lock());
326 dhcp_client::handle_dhcp_event(std::shared_ptr<lease_t> lease)
330 m_evl->handle_dhcp_event(m_lease);
334 dhcp_client::dhcp_client_listener::handle_dhcp_event(std::shared_ptr<lease_t> e)
339 std::shared_ptr<dhcp_client> client =
find(e->itf->key());
342 client->handle_dhcp_event(e);
HW::item< bool > m_status
The HW::item associated with this command.
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
std::string to_string() const
convert to string format for debug purposes
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
static std::shared_ptr< interface > find(const handle_t &h)
The the singular instance of the interface in the DB by handle.
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
static const state_t REQUEST
static rc_t write()
Write/Execute all commands hitherto enqueued.
Error codes that VPP will return during a HW write.
A representation of DHCP client on an interface.
A class that listens to DHCP Events.
Type def of a L2 address as read from VPP.
std::string to_string() const
convert to string format for debug purposes
const key_t & key() const
Return the object's key.
vhost_vring_state_t state
route::prefix_t host_prefix
std::shared_ptr< dhcp_client > singular() const
Return the 'singular' of the DHCP client that matches this object.
std::string to_string() const
static const state_t BOUND
static const state_t DISCOVER
A Database to store the unique 'singular' instances of a single object type.
boost::asio::ip::address router_address
interface::key_t key_t
typedef for the DHCP client key type
A representation of an interface in VPP.
std::shared_ptr< interface > itf
static const state_t & from_vpp(int i)
const std::string & to_string() const
convert to string format for debug purposes
dhcp_client(const interface &itf, const std::string &hostname, bool set_broadcast_flag=true, const ip_dscp_t &dscp=ip_dscp_t::DSCP_CS0, event_listener *ev=nullptr)
Construct a new object matching the desried state.
static rc_t commit(const client_db::key_t &key, const OBJ &obj)
Make the State in VPP reflect the expressed desired state.
void event_handler(void *tls_async)
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
static void enqueue(cmd *f)
Enqueue A command for execution.
static void dump(std::ostream &os)
Dump all DHCP clients into the stream provided.
~dhcp_client()
Destructor.
std::string to_string() const
convert to string format for debug purposes
boost::asio::ip::address from_bytes(uint8_t is_ip6, const uint8_t *bytes)
Convert a VPP byte stinrg into a boost addresss.
bool operator==(const dhcp_client &d) const
Comparison operator - for UT.
static const log_level_t ERROR
Then L2/objects that bind to interfaces, BD, ACLS, etc.
std::string to_string() const
String conversion.
HW::item< bool > & status()
Return the HW::item associated with this command.
The VPP Object Model (VOM) library.
const neighbour::flags_t from_api(vapi_enum_ip_neighbor_flags f)
A representation of a method call to VPP.
static std::shared_ptr< dhcp_client > find(const key_t &k)
Find a DHCP client from its key.
Type def of a Ethernet address.
static bool register_listener(listener *listener)
Register a listener of events.
A cmd class that Unbinds Dhcp Config from an interface.
A command class that binds the DHCP config to the interface.
const std::shared_ptr< lease_t > lease() const
return the current lease data
event_listener()
Constructor.