5 #include <boost/filesystem.hpp>
12 #include "services/services_types.h"
16 using namespace boost::asio;
17 using boost::asio::ip::udp;
20 bool run_with_vrouter) :
22 run_with_vrouter_(run_with_vrouter), ip_fabric_interface_(NULL),
23 ip_fabric_interface_index_(-1), pkt_interface_index_(-1),
24 dhcp_server_socket_(io), dhcp_server_read_buf_(NULL),
25 gateway_delete_seqno_(0) {
32 boost::system::error_code ec;
37 DHCP_TRACE(Error,
"Error creating DHCP socket : " << ec);
65 boost::system::error_code ec;
68 DHCP_TRACE(Error,
"Error shutting down DHCP socket : " << ec);
72 DHCP_TRACE(Error,
"Error closing DHCP socket : " << ec);
88 boost::asio::placeholders::error,
89 boost::asio::placeholders::bytes_transferred));
97 DHCP_TRACE(Error,
"Error reading packet <" + error.message() +
">");
98 if (error == boost::system::errc::operation_canceled) {
114 boost::asio::io_context &io) {
160 if (vmi->
vn() == NULL || subnet.to_ulong() == 0) {
162 DHCP_TRACE(
Trace,
"DHCP Lease DB not created - config not present : " <<
163 vmi->
subnet().to_string());
172 vmi->
subnet().to_string() <<
" - IPAM not available");
177 std::vector<Ip4Address> reserve_list;
182 reserve_list.push_back(vn_ipam->
default_gw.to_v4());
183 reserve_list.push_back(vn_ipam->
dns_server.to_v4());
184 res += vn_ipam->
default_gw.to_v4().to_string() +
", ";
185 res += vn_ipam->
dns_server.to_v4().to_string();
189 vmi->
name() <<
" " << vmi->
subnet().to_string() <<
"/" <<
199 vmi->
subnet().to_string() <<
"/" <<
217 for (std::set<VmInterface *>::iterator it =
gw_vmi_list_.begin();
238 boost::filesystem::path dir(
agent()->params()->agent_base_dir() +
"/dhcp");
239 boost::system::error_code ec;
240 if (!boost::filesystem::exists(dir, ec)) {
241 boost::filesystem::create_directory(dir, ec);
245 DHCP_TRACE(Error,
"Cannot create DHCP Lease directory : " << dir);
263 std::set<std::string> filelist;
264 for (std::set<VmInterface *>::const_iterator it =
gw_vmi_list_.begin();
270 boost::system::error_code ec;
271 boost::filesystem::path dir(
agent()->params()->agent_base_dir() +
273 if (boost::filesystem::exists(dir, ec) &&
274 boost::filesystem::is_directory(dir, ec)) {
275 for (boost::filesystem::directory_iterator it(dir);
276 it != boost::filesystem::directory_iterator(); ++it) {
277 std::string filename = it->path().string();
278 if (boost::filesystem::is_regular_file(it->status()) &&
279 filelist.find(filename) == filelist.end()) {
281 remove(filename.c_str());
void SetBounded(bool bounded)
void DeleteLeaseDb(VmInterface *vmi)
void StartLeaseFileCleanupTimer()
ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
ProtoWorkQueue work_queue_
void SendMessage(PktModuleName mod, InterTaskMsg *msg)
void set_ip_fabric_interface_index(uint32_t ind)
uint8_t * dhcp_server_read_buf_
const boost::uuids::uuid & GetUuid() const
const uint32_t id() const
const VnIpam * GetIpam(const IpAddress &ip) const
boost::asio::io_context & io_
#define DHCP_TRACE(obj, arg)
DhcpLeaseDb * GetLeaseDb(Interface *intrface)
boost::asio::ip::address IpAddress
const Ip4Address & subnet() const
uint32_t gateway_delete_seqno_
InterfaceTable * interface_table() const
VnTable * vn_table() const
LeaseManagerMap lease_manager_
const MacAddress & mac() const
static std::string UuidToString(const boost::uuids::uuid &id)
void set_ip_fabric_interface_mac(const MacAddress &mac)
void Unregister(ListenerId listener)
void ReadHandler(const boost::system::error_code &error, std::size_t len)
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
DBTableBase::ListenerId iid_
Timer * lease_file_cleanup_timer_
bool LeaseFileCleanupExpiry(uint32_t seqno)
void SetSize(size_t size)
static TaskScheduler * GetInstance()
void CreateLeaseDb(VmInterface *vmi)
const std::string & fabric_interface_name() const
void ItfNotify(DBEntryBase *entry)
PktHandler * pkt_handler() const
void VnNotify(DBEntryBase *entry)
const VnEntry * vn() const
DhcpProto(Agent *agent, boost::asio::io_context &io, bool run_with_vrouter)
AgentParam * params() const
static const uint32_t kDhcpLeaseFileDeleteTimeout
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
boost::asio::ip::address_v4 Ip4Address
void SendDhcpIpc(uint8_t *dhcp, std::size_t len)
const Ip4Address & primary_ip_addr() const
uint32_t services_queue_limit()
std::pair< Interface *, DhcpLeaseDb * > LeaseManagerPair
VmInterface::VmiType vmi_type() const
DBTableBase::ListenerId vnid_
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
const uint8_t subnet_plen() const
std::string GetLeaseFileName(const VmInterface *vmi)
const std::string & name() const
void set_pkt_interface_index(uint32_t ind)
bool dhcp_relay_mode() const
static const uint32_t kDhcpMaxPacketSize
boost::asio::ip::udp::endpoint remote_endpoint_
void set_ip_fabric_interface(Interface *itf)
std::set< VmInterface * > gw_vmi_list_
boost::asio::ip::udp::socket dhcp_server_socket_
static bool DeleteTimer(Timer *Timer)