23 const int NameChangeTransaction::READY_ST;
24 const int NameChangeTransaction::SELECTING_FWD_SERVER_ST;
25 const int NameChangeTransaction::SELECTING_REV_SERVER_ST;
26 const int NameChangeTransaction::PROCESS_TRANS_OK_ST;
27 const int NameChangeTransaction::PROCESS_TRANS_FAILED_ST;
29 const int NameChangeTransaction::NCT_DERIVED_STATE_MIN;
32 const int NameChangeTransaction::SELECT_SERVER_EVT;
33 const int NameChangeTransaction::SERVER_SELECTED_EVT;
34 const int NameChangeTransaction::SERVER_IO_ERROR_EVT;
35 const int NameChangeTransaction::NO_MORE_SERVERS_EVT;
36 const int NameChangeTransaction::IO_COMPLETED_EVT;
37 const int NameChangeTransaction::UPDATE_OK_EVT;
38 const int NameChangeTransaction::UPDATE_FAILED_EVT;
40 const int NameChangeTransaction::NCT_DERIVED_EVENT_MIN;
42 const unsigned int NameChangeTransaction::MAX_UPDATE_TRIES_PER_SERVER;
44 NameChangeTransaction::
50 : io_service_(io_service), ncr_(ncr), forward_domain_(forward_domain),
51 reverse_domain_(reverse_domain), dns_client_(), dns_update_request_(),
52 dns_update_status_(
DNSClient::OTHER), dns_update_response_(),
53 forward_change_completed_(false), reverse_change_completed_(false),
54 current_server_list_(), current_server_(), next_server_pos_(0),
55 update_attempts_(0), cfg_mgr_(cfg_mgr), tsig_key_() {
64 "NameChangeRequest cannot be null");
67 if (ncr_->isForwardChange() && !(forward_domain_)) {
69 "Forward change must have a forward domain");
72 if (ncr_->isReverseChange() && !(reverse_domain_)) {
74 "Reverse change must have a reverse domain");
79 "Configuration manager cannot be null");
106 .arg(current_server_->toText())
114 std::ostringstream stream;
117 stream <<
"SUCCESS, rcode: ";
121 stream <<
" update response is NULL";
128 stream <<
"IO_STOPPED";
131 stream <<
"INVALID_RESPONSE";
143 return (stream.str());
148 std::ostringstream stream;
150 ?
"Completed, " :
"Failed, ")
153 if (ncr_->isForwardChange()) {
155 ?
" completed, " :
" failed, ");
158 if (ncr_->isReverseChange()) {
160 ?
" completed, " :
" failed, ");
163 stream <<
" request: " << ncr_->toText();
164 return (stream.str());
177 dns_client_->doUpdate(*io_service_, current_server_->getIpAddress(),
178 current_server_->getPort(), *dns_update_request_,
179 d2_params->getDnsServerTimeout(), tsig_key_);
186 .arg(current_server_->toText());
187 }
catch (
const std::exception& ex) {
276 dns_update_request_ = request;
281 update_attempts_ = 0;
282 dns_update_request_.reset();
287 dns_update_status_ = status;
292 dns_update_response_ = response;
297 dns_update_response_.reset();
302 forward_change_completed_ = value;
307 reverse_change_completed_ = value;
312 update_attempts_ = value;
319 "prepNewRequest - domain cannot be null");
327 request->setId(QidGenerator::getInstance().generateQid());
332 }
catch (
const std::exception& ex) {
342 "addLeaseAddressRdata - RRset cannot cannot be null");
353 rrset->addRdata(rdata);
354 }
catch (
const std::exception& ex) {
364 "addDhcidRdata - RRset cannot cannot be null");
368 const std::vector<uint8_t>& ncr_dhcid = ncr_->getDhcid().getBytes();
371 DHCID(buffer, ncr_dhcid.size()));
372 rrset->addRdata(rdata);
373 }
catch (
const std::exception& ex) {
384 "addPtrRdata - RRset cannot cannot be null");
389 PTR(
getNcr()->getFqdn()));
390 rrset->addRdata(rdata);
391 }
catch (
const std::exception& ex) {
404 return (ncr_->getDhcid());
409 return (ncr_->getRequestId());
414 return (ncr_->getStatus());
419 return (forward_domain_);
424 return (reverse_domain_);
431 "initServerSelection called with an empty domain");
437 tsig_key_ = tsig_key_info->getTSIGKey();
442 current_server_list_ = domain->getServers();
443 next_server_pos_ = 0;
444 current_server_.reset();
449 if ((current_server_list_) &&
450 (next_server_pos_ < current_server_list_->size())) {
451 current_server_ = (*current_server_list_)[next_server_pos_];
453 dns_update_response_.reset();
459 dns_client_.reset(
new DNSClient(dns_update_response_ ,
this,
470 return (dns_client_);
475 return (current_server_);
480 return (ncr_->setStatus(status));
485 return (dns_update_request_);
490 return (dns_update_status_);
495 return (dns_update_response_);
500 return (forward_change_completed_);
505 return (reverse_change_completed_);
510 return (update_attempts_);
virtual D2UpdateMessagePtr prepNewRequest(DdnsDomainPtr domain)
Creates a new DNS update request based on the given domain.
static const int NOP_EVT
Signifies that no event has occurred.
The Name class encapsulates DNS names.
boost::shared_ptr< TSIGKeyInfo > TSIGKeyInfoPtr
Defines a pointer for TSIGKeyInfo instances.
This file defines the class NameChangeTransaction.
const isc::log::MessageID DHCP_DDNS_STARTING_TRANSACTION
virtual void sendUpdate(const std::string &comment="")
Send the update request to the current server.
boost::shared_ptr< D2Params > D2ParamsPtr
Defines a pointer for D2Params instances.
The D2UpdateMessage encapsulates a DNS Update message.
size_t getUpdateAttempts() const
Fetches the update attempt count for the current update.
static const int PROCESS_TRANS_OK_ST
State which processes successful transaction conclusion.
Thrown if the transaction encounters a general error.
static const unsigned int MAX_UPDATE_TRIES_PER_SERVER
Maximum times to attempt a single update on a given server.
The DNSClient class handles communication with the DNS server.
void defineEvent(unsigned int value, const std::string &label)
Adds an event value and associated label to the set of events.
boost::shared_ptr< DNSClient > DNSClientPtr
boost::shared_ptr< DdnsDomain > DdnsDomainPtr
Defines a pointer for DdnsDomain instances.
virtual void onModelFailure(const std::string &explanation)
Handler for fatal model execution errors.
boost::shared_ptr< D2UpdateMessage > D2UpdateMessagePtr
Pointer to the DNS Update Message.
const isc::log::MessageID DHCP_DDNS_UPDATE_REQUEST_SENT
void setNcrStatus(const dhcp_ddns::NameChangeStatus &status)
Sets the status of the transaction's NameChangeRequest.
static const RRClass & IN()
boost::shared_ptr< const Rdata > ConstRdataPtr
bool getForwardChangeCompleted() const
Returns whether the forward change has completed or not.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
static const int SELECTING_FWD_SERVER_ST
State in which forward DNS server selection is done.
std::string transactionOutcomeString() const
Returns a string version of transaction outcome.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
void startTransaction()
Begins execution of the transaction.
static const int SERVER_IO_ERROR_EVT
Issued when an update fails due to an IO error.
const dhcp_ddns::NameChangeRequestPtr & getNcr() const
Fetches the NameChangeRequest for this transaction.
unsigned int getCurrState() const
Fetches the model's current state.
static const int IO_COMPLETED_EVT
Issued when a DNS update packet exchange has completed.
virtual void verifyStates()
Validates the contents of the set of states.
virtual void runModel(unsigned int event)
Processes events through the state model.
bool getReverseChangeCompleted() const
Returns whether the reverse change has completed or not.
const isc::log::MessageID DHCP_DDNS_TRANS_SEND_ERROR
Other, unclassified error.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void setForwardChangeCompleted(const bool value)
Sets the forward change completion flag to the given value.
void addDhcidRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease client's DHCID to the given RRset.
std::string getRequestId() const
Fetches the request id that identifies this transaction.
isc::log::Logger d2_to_dns_logger("d2-to-dns")
static const int SERVER_SELECTED_EVT
Issued when a server has been selected.
void retryTransition(const int fail_to_state)
Determines the state and next event based on update attempts.
static const RRType & A()
const D2UpdateMessagePtr & getDnsUpdateRequest() const
Fetches the current DNS update request packet.
Status
A status code of the DNSClient.
std::string getEventLabel(const int event) const
Fetches the label associated with an event value.
NameChangeStatus
Defines the runtime processing status values for requests.
boost::shared_ptr< D2CfgMgr > D2CfgMgrPtr
Defines a shared pointer to D2CfgMgr.
DNSClient::Status getDnsUpdateStatus() const
Fetches the most recent DNS update status.
virtual void defineStates()
Adds states defined by NameChangeTransaction to the state set.
const isc::log::MessageID DHCP_DDNS_STATE_MODEL_UNEXPECTED_ERROR
void setReverseChangeCompleted(const bool value)
Sets the reverse change completion flag to the given value.
Response received and is ok.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static const int SELECTING_REV_SERVER_ST
State in which reverse DNS server selection is done.
void startModel(const int start_state)
Begins execution of the model.
void setDnsUpdateStatus(const DNSClient::Status &status)
Sets the update status to the given status value.
DdnsDomainPtr & getForwardDomain()
Fetches the forward DdnsDomain.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void addPtrRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease FQDN to the given RRset.
virtual void defineStates()
Populates the set of states.
const D2UpdateMessagePtr & getDnsUpdateResponse() const
Fetches the most recent DNS update response packet.
static const int NO_MORE_SERVERS_EVT
Issued when there are no more servers from which to select.
virtual void operator()(DNSClient::Status status)
Serves as the DNSClient IO completion event handler.
void transition(unsigned int state, unsigned int event)
Sets up the model to transition into given state with a given event.
Response received but invalid.
void setUpdateAttempts(const size_t value)
Sets the update attempt count to the given value.
const DNSClientPtr & getDNSClient() const
Fetches the DNSClient instance.
static const int PROCESS_TRANS_FAILED_ST
State which processes an unsuccessful transaction conclusion.
const DnsServerInfoPtr & getCurrentServer() const
Fetches the currently selected server.
std::string responseString() const
Returns a string version of the current response status and rcode.
The RRType class encapsulates DNS resource record types.
static const int SELECT_SERVER_EVT
Issued when a server needs to be selected.
void clearDnsUpdateRequest()
Destroys the current update request packet and resets update attempts count.
Container class for handling the DHCID value within a NameChangeRequest.
static const int READY_ST
State from which a transaction is started.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
void setDnsUpdateRequest(D2UpdateMessagePtr &request)
Sets the update request packet to the given packet.
virtual void defineEvents()
Adds events defined by NameChangeTransaction to the event set.
const StatePtr getStateInternal(unsigned int value)
Fetches the state referred to by value.
static const int UPDATE_OK_EVT
Issued when the attempted update successfully completed.
const dns::RRType & getAddressRRType() const
Returns the DHCP data type for the lease address.
const isc::log::MessageID DHCP_DDNS_UPDATE_RESPONSE_RECEIVED
void clearDnsUpdateResponse()
Destroys the current update response packet.
dhcp_ddns::NameChangeStatus getNcrStatus() const
Fetches the NameChangeRequest status of the transaction.
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
DdnsDomainPtr & getReverseDomain()
Fetches the reverse DdnsDomain.
const int DBGLVL_TRACE_DETAIL
Trace detailed operations.
const EventPtr & getEvent(unsigned int value)
Fetches the event referred to by value.
unsigned int getNextEvent() const
Fetches the model's next event.
static const int UPDATE_FAILED_EVT
Issued when the attempted update fails to complete.
virtual void verifyEvents()
Validates the contents of the set of events.
void addLeaseAddressRdata(dns::RRsetPtr &rrset)
Adds an RData for the lease address to the given RRset.
static const RRType & AAAA()
const TransactionKey & getTransactionKey() const
Fetches the unique key that identifies this transaction.
virtual void verifyEvents()
Validates the contents of the set of events.
void initServerSelection(const DdnsDomainPtr &domain)
Initializes server selection from the given DDNS domain.
virtual ~NameChangeTransaction()
Destructor.
void setDnsUpdateResponse(D2UpdateMessagePtr &response)
Sets the update response packet to the given packet.
boost::shared_ptr< DnsServerInfo > DnsServerInfoPtr
Defines a pointer for DnsServerInfo instances.
virtual void defineEvents()
Populates the set of events.
void postNextEvent(unsigned int event)
Sets the next event to the given event value.
bool selectNextServer()
Selects the next server in the current server list.
virtual void verifyStates()
Validates the contents of the set of states.