25 dhcp_client::state_t::state_t(
int v,
const std::string& s)
26 : enum_base<dhcp_client::state_t>(v, s)
30 const dhcp_client::state_t&
42 std::weak_ptr<dhcp_client_cmds::events_cmd> dhcp_client::m_s_event_cmd;
43 dhcp_client::dhcp_client_listener dhcp_client::m_listener;
48 const std::string& hostname,
49 bool set_broadcast_flag,
51 : m_itf(itf.singular())
52 , m_hostname(hostname)
54 , m_set_broadcast_flag(set_broadcast_flag)
57 , m_event_cmd(get_event_cmd())
62 const std::string& hostname,
64 bool set_broadcast_flag,
67 , m_hostname(hostname)
68 , m_client_id(client_id)
69 , m_set_broadcast_flag(set_broadcast_flag)
72 , m_event_cmd(get_event_cmd())
78 , m_hostname(o.m_hostname)
79 , m_client_id(o.m_client_id)
80 , m_set_broadcast_flag(o.m_set_broadcast_flag)
83 , m_event_cmd(o.m_event_cmd)
92 m_db.release(m_itf->key(),
this);
98 return ((
key() == l.
key()) && (m_hostname == l.m_hostname) &&
99 (m_client_id == l.m_client_id));
105 return (m_itf->key());
125 dhcp_client::replay()
129 m_hostname, m_client_id));
136 std::ostringstream s;
137 s <<
"DHCP-client: " << m_itf->to_string() <<
" hostname:" << m_hostname
138 <<
" client_id:[" << m_client_id <<
"] " << m_binding.
to_string();
140 s <<
" " << m_lease->to_string();
155 m_hostname, m_client_id));
159 m_lease = desired.m_lease;
160 if (m_evl != desired.m_evl) {
161 m_evl = desired.m_evl;
165 const std::shared_ptr<dhcp_client::lease_t>
177 std::shared_ptr<dhcp_client>
180 return (m_db.find_or_add(temp.m_itf->key(), temp));
183 std::shared_ptr<dhcp_client>
186 return (m_db.find(k));
189 std::shared_ptr<dhcp_client>
192 return find_or_add(*
this);
202 std::shared_ptr<interface>
itf,
209 , router_address(router_address)
210 , host_prefix(host_prefix)
219 std::stringstream ss;
229 : m_status(
rc_t::NOOP)
246 dhcp_client::event_handler::handle_replay()
254 std::shared_ptr<dhcp_client_cmds::dump_cmd>
cmd =
255 std::make_shared<dhcp_client_cmds::dump_cmd>();
260 for (
auto& record : *cmd) {
261 auto& payload = record.get_payload();
263 std::shared_ptr<interface> itf =
268 <<
" itf:" << payload.client.sw_if_index;
275 payload.lease.mask_width);
276 std::string hostname =
277 reinterpret_cast<const char*
>(payload.lease.hostname);
279 dhcp_client dc(*itf, hostname, l2, payload.client.set_broadcast_flag);
280 dc.
lease(std::make_shared<dhcp_client::lease_t>(
281 s, itf,
from_bytes(0, payload.lease.router_address), pfx, hostname,
288 dhcp_client::event_handler::order()
const 299 std::shared_ptr<dhcp_client_cmds::events_cmd>
300 dhcp_client::get_event_cmd()
302 if (m_s_event_cmd.expired()) {
303 std::shared_ptr<dhcp_client_cmds::events_cmd>
c =
304 std::make_shared<dhcp_client_cmds::events_cmd>(m_listener);
314 return (m_s_event_cmd.lock());
318 dhcp_client::handle_dhcp_event(std::shared_ptr<lease_t> lease)
322 m_evl->handle_dhcp_event(m_lease);
326 dhcp_client::dhcp_client_listener::handle_dhcp_event(std::shared_ptr<lease_t> e)
331 std::shared_ptr<dhcp_client> client =
find(e->itf->key());
334 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.
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
const std::shared_ptr< lease_t > lease() const
return the current lease data
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
std::string to_string() const
String conversion.
static rc_t write()
Write/Execute all commands hitherto enqueued.
Error codes that VPP will return during a HW write.
const key_t & key() const
Return the object's key.
A representation of DHCP client on an interface.
A class that listens to DHCP Events.
dhcp_client(const interface &itf, const std::string &hostname, bool set_broadcast_flag=true, event_listener *ev=nullptr)
Construct a new object matching the desried state.
std::string to_string() const
convert to string format for debug purposes
bool operator==(const dhcp_client &d) const
Comparison operator - for UT.
Type def of a L2 address as read from VPP.
vhost_vring_state_t state
route::prefix_t host_prefix
std::string to_string() const
convert to string format for debug purposes
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
std::string to_string() const
convert to string format for debug purposes
std::string to_string() const
A representation of an interface in VPP.
std::shared_ptr< interface > itf
static const state_t & from_vpp(int i)
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.
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
Then L2/objects that bind to interfaces, BD, ACLS, etc.
HW::item< bool > & status()
Return the HW::item associated with this command.
The VPP Object Model (VOM) library.
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.
std::shared_ptr< dhcp_client > singular() const
Return the 'singular' of the DHCP client that matches this object.
const std::string & to_string() const
convert to string format for debug purposes
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.
event_listener()
Constructor.