uint16_t type,
const OptionBuffer& buf);
+ /// @brief Factory function to create instance of option.
+ ///
+ /// Factory method creates instance of specified option. The option
+ /// to be created has to have corresponding factory function
+ /// registered with \ref LibDHCP::OptionFactoryRegister.
+ /// This method creates empty \ref OptionBuffer object. Use this
+ /// factory function if it is not needed to pass custom buffer.
+ ///
+ /// @param u universe of the option (V4 or V6)
+ /// @param type option-type
+ /// @throw isc::InvalidOperation if there is no factory function
+ /// registered for specified option type.
+ /// @return instance of option.
+ static OptionPtr factory(Option::Universe u, uint16_t type) {
+ return factory(u, type, OptionBuffer());
+ }
+
/// @brief ctor, used for options constructed, usually during transmission
///
return(false);
}
-Pkt4*
-TestControl::createDiscoverPkt4() {
+boost::shared_ptr<Pkt4>
+TestControl::createDiscoverPkt4() const {
const uint32_t transid = static_cast<uint32_t>(random());
- Pkt4* pkt4 = new Pkt4(DHCPDISCOVER, transid);
+ boost::shared_ptr<Pkt4> pkt4(new Pkt4(DHCPDISCOVER, transid));
+ if (!pkt4) {
+ isc_throw(isc::Unexpected, "failed to create DISCOVER packet");
+ }
- OptionBuffer opt_request_list_buf();
- // createRequestListBuffer4(opt_request_list_buf);
- return NULL;
+ OptionPtr request_list_option =
+ Option::factory(Option::V4, DHO_DHCP_PARAMETER_REQUEST_LIST);
+ pkt4->addOption(request_list_option);
+ return pkt4;
}
OptionPtr
OptionBuffer buf_with_options(buf_array, buf_array + sizeof(buf_array));
Option* opt = new Option(u, type, buf);
- opt->setData(buf_with_options.begin(),
- buf_with_options.end());
+ opt->setData(buf_with_options.begin(), buf_with_options.end());
return OptionPtr(opt);
}
/// \return true if any of the exit conditions is fulfiled.
bool checkExitConditions() const;
- dhcp::Pkt4* createDiscoverPkt4();
+ boost::shared_ptr<dhcp::Pkt4> createDiscoverPkt4() const;
static dhcp::OptionPtr factoryRequestList4(dhcp::Option::Universe u,
uint16_t type,