24    : query_(query), htype_(
HTYPE_ETHER), thread_(this_thread::get_id()) {
 
   29    if (!client_id && (!hwaddr || hwaddr->hwaddr_.empty())) {
 
   31                  "null client-id and hwaddr in ClientHandler");
 
   35        client_id_ = client_id->getClientId();
 
   37    if (hwaddr && !hwaddr->hwaddr_.empty()) {
 
   38        htype_ = hwaddr->htype_;
 
   39        hwaddr_ = hwaddr->hwaddr_;
 
   43mutex ClientHandler::mutex_;
 
   45ClientHandler::ClientByIdContainer ClientHandler::clients_client_id_;
 
   47ClientHandler::ClientByHWAddrContainer ClientHandler::clients_hwaddr_;
 
   49ClientHandler::ClientPtr
 
   50ClientHandler::lookup(
const ClientIdPtr& client_id) {
 
   56    auto it = clients_client_id_.find(client_id->getClientId());
 
   57    if (it == clients_client_id_.end()) {
 
   63ClientHandler::ClientPtr
 
   64ClientHandler::lookup(
const HWAddrPtr& hwaddr) {
 
   69    if (hwaddr->hwaddr_.empty()) {
 
   73    auto key = boost::make_tuple(hwaddr->htype_, hwaddr->hwaddr_);
 
   74    auto it = clients_hwaddr_.find(key);
 
   75    if (it == clients_hwaddr_.end()) {
 
   82ClientHandler::addById(
const ClientPtr& client) {
 
   89    clients_client_id_.insert(client);
 
   93ClientHandler::addByHWAddr(
const ClientPtr& client) {
 
   97                  "null client in ClientHandler::addByHWAddr");
 
  101    clients_hwaddr_.insert(client);
 
  112    clients_client_id_.erase(client_id->getClientId());
 
  116ClientHandler::del(
const HWAddrPtr& hwaddr) {
 
  121    if (hwaddr->hwaddr_.empty()) {
 
  125    auto key = boost::make_tuple(hwaddr->htype_, hwaddr->hwaddr_);
 
  127    auto it = clients_hwaddr_.find(key);
 
  128    if (it == clients_hwaddr_.end()) {
 
  132    clients_hwaddr_.erase(it);
 
  136    : client_(), locked_client_id_(), locked_hwaddr_() {
 
 
  140    bool unlocked = 
false;
 
  141    lock_guard<mutex> lk(mutex_);
 
  142    if (locked_client_id_) {
 
  146    if (locked_hwaddr_) {
 
  150    if (!unlocked || !client_ || !client_->cont_) {
 
 
  169    if (locked_client_id_) {
 
  171                  "already handling client-id in ClientHandler::tryLock");
 
  173    if (locked_hwaddr_) {
 
  175                  "already handling hwaddr in ClientHandler::tryLock");
 
  182        client_id.reset(
new ClientId(opt_client_id->getData()));
 
  185    if (hwaddr && hwaddr->hwaddr_.empty()) {
 
  188    if (!client_id && !hwaddr) {
 
  197    client_.reset(
new Client(query, client_id, hwaddr));
 
  200        lock_guard<mutex> lk(mutex_);
 
  205            holder_id = lookup(client_id);
 
  207                locked_client_id_ = client_id;
 
  210                next_query_id = holder_id->next_query_;
 
  211                holder_id->next_query_ = query;
 
  212                holder_id->cont_ = cont;
 
  221            holder_hw = lookup(hwaddr);
 
  223                locked_hwaddr_ = hwaddr;
 
  227                next_query_hw = holder_hw->next_query_;
 
  228                holder_hw->next_query_ = query;
 
  229                holder_hw->cont_ = cont;
 
  241                    .arg(next_query_id->getHWAddrLabel())
 
  242                    .arg(next_query_id->toText())
 
  243                    .arg(this_thread::get_id())
 
  244                    .arg(holder_id->query_->getHWAddrLabel())
 
  245                    .arg(holder_id->query_->toText())
 
  246                    .arg(holder_id->thread_);
 
  248                                                     static_cast<int64_t
>(1));
 
  254                .arg(query->getHWAddrLabel())
 
  255                .arg(query->toText())
 
  256                .arg(this_thread::get_id())
 
  257                .arg(holder_id->query_->getHWAddrLabel())
 
  258                .arg(holder_id->query_->toText())
 
  259                .arg(holder_id->thread_);
 
  261                                                 static_cast<int64_t
>(1));
 
  270                    .arg(next_query_hw->getHWAddrLabel())
 
  271                    .arg(next_query_hw->toText())
 
  272                    .arg(this_thread::get_id())
 
  273                    .arg(holder_hw->query_->getHWAddrLabel())
 
  274                    .arg(holder_hw->query_->toText())
 
  275                    .arg(holder_hw->thread_);
 
  277                                                     static_cast<int64_t
>(1));
 
  283                .arg(query->getHWAddrLabel())
 
  284                .arg(query->toText())
 
  285                .arg(this_thread::get_id())
 
  286                .arg(holder_hw->query_->getHWAddrLabel())
 
  287                .arg(holder_hw->query_->toText())
 
  288                .arg(holder_hw->thread_);
 
  290                                                 static_cast<int64_t
>(1));
 
 
  297ClientHandler::lockById() {
 
  299    if (!locked_client_id_) {
 
  307ClientHandler::lockByHWAddr() {
 
  309    if (!locked_hwaddr_) {
 
  311                  "nothing to lock in ClientHandler::lockByHWAddr");
 
  314    addByHWAddr(client_);
 
  318ClientHandler::unLockById() {
 
  320    if (!locked_client_id_) {
 
  322                  "nothing to unlock in ClientHandler::unLockById");
 
  325    del(locked_client_id_);
 
  326    locked_client_id_.reset();
 
  330ClientHandler::unLockByHWAddr() {
 
  332    if (!locked_hwaddr_) {
 
  334                  "nothing to unlock in ClientHandler::unLockByHWAddr");
 
  338    locked_hwaddr_.reset();
 
 
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
virtual ~ClientHandler()
Destructor.
bool tryLock(Pkt4Ptr query, ContinuationPtr cont=ContinuationPtr())
Tries to acquires a client.
ClientHandler()
Public interface.
Holds Client identifier or client IPv4 address.
static StatsMgr & instance()
Statistics Manager accessor method.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
ThreadPool< std::function< void()> > & getThreadPool()
Get the dhcp thread pool.
bool getMode() const
Get the multi-threading mode.
Contains declarations for loggers used by the DHCPv4 server component.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const isc::log::MessageID DHCP4_PACKET_DROP_0011
@ DHO_DHCP_CLIENT_IDENTIFIER
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
const isc::log::MessageID DHCP4_PACKET_QUEUE_FULL
isc::log::Logger bad_packet4_logger(DHCP4_BAD_PACKET_LOGGER_NAME)
Logger for rejected packets.
const int DBG_DHCP4_BASIC
Debug level used to trace basic operations within the code.
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
boost::shared_ptr< Continuation > ContinuationPtr
Define the type of shared pointers to continuations.
isc::log::Logger dhcp4_logger(DHCP4_APP_LOGGER_NAME)
Base logger for DHCPv4 server.
const isc::log::MessageID DHCP4_PACKET_DROP_0012
@ HTYPE_ETHER
Ethernet 10Mbps.
boost::shared_ptr< Option > OptionPtr
const int DBGLVL_PKT_HANDLING
This debug level is reserved for logging the details of packet handling, such as dropping the packet ...
Defines the logger used by the top-level component of kea-lfc.
bool addFront(const WorkItemPtr &item)
add a work item to the thread pool at front