subnet.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. // Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef SUBNET_H
  15. #define SUBNET_H
  16. #include <boost/shared_ptr.hpp>
  17. #include <boost/multi_index_container.hpp>
  18. #include <boost/multi_index/hashed_index.hpp>
  19. #include <boost/multi_index/sequenced_index.hpp>
  20. #include <boost/multi_index/mem_fun.hpp>
  21. #include <boost/multi_index/member.hpp>
  22. #include <asiolink/io_address.h>
  23. #include <dhcp/option.h>
  24. #include <dhcpsrv/key_from_key.h>
  25. #include <dhcpsrv/option_space_container.h>
  26. #include <dhcpsrv/pool.h>
  27. #include <dhcpsrv/triplet.h>
  28. #include <dhcpsrv/lease.h>
  29. namespace isc {
  30. namespace dhcp {
  31. /// @brief a base class for Subnet4 and Subnet6
  32. ///
  33. /// This class presents a common base for IPv4 and IPv6 subnets.
  34. /// In a physical sense, a subnet defines a single network link with all devices
  35. /// attached to it. In most cases all devices attached to a single link can
  36. /// share the same parameters. Therefore Subnet holds several values that are
  37. /// typically shared by all hosts: renew timer (T1), rebind timer (T2) and
  38. /// leased addresses lifetime (valid-lifetime). It also holds the set
  39. /// of DHCP option instances configured for the subnet. These options are
  40. /// included in DHCP messages being sent to clients which are connected
  41. /// to the particular subnet.
  42. ///
  43. /// @todo: Implement support for options here
  44. /// @brief Unique identifier for a subnet (both v4 and v6)
  45. typedef uint32_t SubnetID;
  46. class Subnet {
  47. public:
  48. /// @brief Option descriptor.
  49. ///
  50. /// Option descriptor holds information about option configured for
  51. /// a particular subnet. This information comprises the actual option
  52. /// instance and information whether this option is sent to DHCP client
  53. /// only on request (persistent = false) or always (persistent = true).
  54. struct OptionDescriptor {
  55. /// Option instance.
  56. OptionPtr option;
  57. /// Persistent flag, if true option is always sent to the client,
  58. /// if false option is sent to the client on request.
  59. bool persistent;
  60. /// @brief Constructor.
  61. ///
  62. /// @param opt option
  63. /// @param persist if true option is always sent.
  64. OptionDescriptor(const OptionPtr& opt, bool persist)
  65. : option(opt), persistent(persist) {};
  66. /// @brief Constructor
  67. ///
  68. /// @param persist if true option is always sent.
  69. OptionDescriptor(bool persist)
  70. : option(OptionPtr()), persistent(persist) {};
  71. };
  72. /// A pointer to option descriptor.
  73. typedef boost::shared_ptr<OptionDescriptor> OptionDescriptorPtr;
  74. /// @brief Multi index container for DHCP option descriptors.
  75. ///
  76. /// This container comprises three indexes to access option
  77. /// descriptors:
  78. /// - sequenced index: used to access elements in the order they
  79. /// have been added to the container,
  80. /// - option type index: used to search option descriptors containing
  81. /// options with specific option code (aka option type).
  82. /// - persistency flag index: used to search option descriptors with
  83. /// 'persistent' flag set to true.
  84. ///
  85. /// This container is the equivalent of three separate STL containers:
  86. /// - std::list of all options,
  87. /// - std::multimap of options with option code used as a multimap key,
  88. /// - std::multimap of option descriptors with option persistency flag
  89. /// used as a multimap key.
  90. /// The major advantage of this container over 3 separate STL containers
  91. /// is automatic synchronization of all indexes when elements are added,
  92. /// removed or modified in the container. With separate containers,
  93. /// the synchronization would have to be guaranteed by the Subnet class
  94. /// code. This would increase code complexity and presumably it would
  95. /// be much harder to add new search criteria (indexes).
  96. ///
  97. /// @todo we may want to search for options using option spaces when
  98. /// they are implemented.
  99. ///
  100. /// @see http://www.boost.org/doc/libs/1_51_0/libs/multi_index/doc/index.html
  101. typedef boost::multi_index_container<
  102. // Container comprises elements of OptionDescriptor type.
  103. OptionDescriptor,
  104. // Here we start enumerating various indexes.
  105. boost::multi_index::indexed_by<
  106. // Sequenced index allows accessing elements in the same way
  107. // as elements in std::list.
  108. // Sequenced is an index #0.
  109. boost::multi_index::sequenced<>,
  110. // Start definition of index #1.
  111. boost::multi_index::hashed_non_unique<
  112. // KeyFromKeyExtractor is the index key extractor that allows
  113. // accessing option type being held by the OptionPtr through
  114. // OptionDescriptor structure.
  115. KeyFromKeyExtractor<
  116. // Use option type as the index key. The type is held
  117. // in OptionPtr object so we have to call Option::getType
  118. // to retrieve this key for each element.
  119. boost::multi_index::const_mem_fun<
  120. Option,
  121. uint16_t,
  122. &Option::getType
  123. >,
  124. // Indicate that OptionPtr is a member of
  125. // OptionDescriptor structure.
  126. boost::multi_index::member<
  127. OptionDescriptor,
  128. OptionPtr,
  129. &OptionDescriptor::option
  130. >
  131. >
  132. >,
  133. // Start definition of index #2.
  134. // Use 'persistent' struct member as a key.
  135. boost::multi_index::hashed_non_unique<
  136. boost::multi_index::member<
  137. OptionDescriptor,
  138. bool,
  139. &OptionDescriptor::persistent
  140. >
  141. >
  142. >
  143. > OptionContainer;
  144. // Pointer to the OptionContainer object.
  145. typedef boost::shared_ptr<OptionContainer> OptionContainerPtr;
  146. /// Type of the index #1 - option type.
  147. typedef OptionContainer::nth_index<1>::type OptionContainerTypeIndex;
  148. /// Pair of iterators to represent the range of options having the
  149. /// same option type value. The first element in this pair represents
  150. /// the beginning of the range, the second element represents the end.
  151. typedef std::pair<OptionContainerTypeIndex::const_iterator,
  152. OptionContainerTypeIndex::const_iterator> OptionContainerTypeRange;
  153. /// Type of the index #2 - option persistency flag.
  154. typedef OptionContainer::nth_index<2>::type OptionContainerPersistIndex;
  155. /// @brief checks if specified address is in range
  156. bool inRange(const isc::asiolink::IOAddress& addr) const;
  157. /// @brief Add new option instance to the collection.
  158. ///
  159. /// @param option option instance.
  160. /// @param persistent if true, send an option regardless if client
  161. /// requested it or not.
  162. /// @param option_space name of the option space to add an option to.
  163. ///
  164. /// @throw isc::BadValue if invalid option provided.
  165. void addOption(const OptionPtr& option, bool persistent,
  166. const std::string& option_space);
  167. /// @brief Adds new vendor option instance to the collection.
  168. ///
  169. /// @param option option instance.
  170. /// @param persistent if true, send an option regardless if client
  171. /// requested it or not.
  172. /// @param vendor_id enterprise id of the vendor space to add an option to.
  173. void addVendorOption(const OptionPtr& option, bool persistent,
  174. uint32_t vendor_id);
  175. /// @brief Delete all options configured for the subnet.
  176. void delOptions();
  177. /// @brief Deletes all vendor options configured for the subnet.
  178. void delVendorOptions();
  179. /// @brief checks if the specified address is in pools
  180. ///
  181. /// Note the difference between inSubnet() and inPool(). For a given
  182. /// subnet (e.g. 2001::/64) there may be one or more pools defined
  183. /// that may or may not cover entire subnet, e.g. pool 2001::1-2001::10).
  184. /// inPool() returning true implies inSubnet(), but the reverse implication
  185. /// is not always true. For the given example, 2001::1234:abcd would return
  186. /// true for inSubnet(), but false for inPool() check.
  187. ///
  188. /// @param type type of pools to iterate over
  189. /// @param addr this address will be checked if it belongs to any pools in
  190. /// that subnet
  191. /// @return true if the address is in any of the pools
  192. bool inPool(Lease::Type type, const isc::asiolink::IOAddress& addr) const;
  193. /// @brief Return valid-lifetime for addresses in that prefix
  194. Triplet<uint32_t> getValid() const {
  195. return (valid_);
  196. }
  197. /// @brief Returns T1 (renew timer), expressed in seconds
  198. Triplet<uint32_t> getT1() const {
  199. return (t1_);
  200. }
  201. /// @brief Returns T2 (rebind timer), expressed in seconds
  202. Triplet<uint32_t> getT2() const {
  203. return (t2_);
  204. }
  205. /// @brief Return a collection of option descriptors.
  206. ///
  207. /// @param option_space name of the option space.
  208. ///
  209. /// @return pointer to collection of options configured for a subnet.
  210. OptionContainerPtr
  211. getOptionDescriptors(const std::string& option_space) const;
  212. /// @brief Return a collection of vendor option descriptors.
  213. ///
  214. /// @param vendor_id enterprise id of the option space.
  215. ///
  216. /// @return pointer to collection of options configured for a subnet.
  217. OptionContainerPtr
  218. getVendorOptionDescriptors(uint32_t vendor_id) const;
  219. /// @brief Return single option descriptor.
  220. ///
  221. /// @param option_space name of the option space.
  222. /// @param option_code code of the option to be returned.
  223. ///
  224. /// @return option descriptor found for the specified option space
  225. /// and option code.
  226. OptionDescriptor
  227. getOptionDescriptor(const std::string& option_space,
  228. const uint16_t option_code);
  229. /// @brief Return single vendor option descriptor.
  230. ///
  231. /// @param vendor_id enterprise id of the option space.
  232. /// @param option_code code of the option to be returned.
  233. ///
  234. /// @return option descriptor found for the specified option space
  235. /// and option code.
  236. OptionDescriptor
  237. getVendorOptionDescriptor(uint32_t vendor_id, uint16_t option_code);
  238. /// @brief returns the last address that was tried from this pool
  239. ///
  240. /// This method returns the last address that was attempted to be allocated
  241. /// from this subnet. This is used as helper information for the next
  242. /// iteration of the allocation algorithm.
  243. ///
  244. /// @todo: Define map<SubnetID, IOAddress> somewhere in the
  245. /// AllocEngine::IterativeAllocator and keep the data there
  246. ///
  247. /// @param type lease type to be returned
  248. /// @return address/prefix that was last tried from this pool
  249. isc::asiolink::IOAddress getLastAllocated(Lease::Type type) const;
  250. /// @brief sets the last address that was tried from this pool
  251. ///
  252. /// This method sets the last address that was attempted to be allocated
  253. /// from this subnet. This is used as helper information for the next
  254. /// iteration of the allocation algorithm.
  255. ///
  256. /// @todo: Define map<SubnetID, IOAddress> somewhere in the
  257. /// AllocEngine::IterativeAllocator and keep the data there
  258. /// @param addr address/prefix to that was tried last
  259. /// @param type lease type to be set
  260. void setLastAllocated(Lease::Type type,
  261. const isc::asiolink::IOAddress& addr);
  262. /// @brief Returns unique ID for that subnet
  263. /// @return unique ID for that subnet
  264. SubnetID getID() const { return (id_); }
  265. /// @brief Returns subnet parameters (prefix and prefix length)
  266. ///
  267. /// @return (prefix, prefix length) pair
  268. std::pair<isc::asiolink::IOAddress, uint8_t> get() const {
  269. return (std::make_pair(prefix_, prefix_len_));
  270. }
  271. /// @brief Adds a new pool.
  272. /// @param pool pool to be added
  273. void addPool(const PoolPtr& pool);
  274. /// @brief Deletes all pools of specified type
  275. ///
  276. /// This method is used for testing purposes only
  277. /// @param type type of pools to be deleted
  278. void delPools(Lease::Type type);
  279. /// @brief Returns a pool that specified address belongs to
  280. ///
  281. /// If there is no pool that the address belongs to (hint is invalid), other
  282. /// pool of specified type will be returned.
  283. ///
  284. /// With anypool set to true, this is means give me a pool, preferably
  285. /// the one that addr belongs to. With anypool set to false, it means
  286. /// give me a pool that addr belongs to (or NULL if here is no such pool)
  287. ///
  288. /// @param type pool type that the pool is looked for
  289. /// @param addr address that the returned pool should cover (optional)
  290. /// @param anypool other pool may be returned as well, not only the one
  291. /// that addr belongs to
  292. /// @return found pool (or NULL)
  293. const PoolPtr getPool(Lease::Type type, const isc::asiolink::IOAddress& addr,
  294. bool anypool = true) const;
  295. /// @brief Returns a pool without any address specified
  296. ///
  297. /// @param type pool type that the pool is looked for
  298. /// @return returns one of the pools defined
  299. PoolPtr getAnyPool(Lease::Type type) {
  300. return (getPool(type, default_pool()));
  301. }
  302. /// @brief Returns the default address that will be used for pool selection
  303. ///
  304. /// It must be implemented in derived classes (should return :: for Subnet6
  305. /// and 0.0.0.0 for Subnet4)
  306. virtual isc::asiolink::IOAddress default_pool() const = 0;
  307. /// @brief Returns all pools (const variant)
  308. ///
  309. /// The reference is only valid as long as the object that returned it.
  310. ///
  311. /// @param type lease type to be set
  312. /// @return a collection of all pools
  313. const PoolCollection& getPools(Lease::Type type) const;
  314. /// @brief Sets name of the network interface for directly attached networks
  315. ///
  316. /// @param iface_name name of the interface
  317. void setIface(const std::string& iface_name);
  318. /// @brief Network interface name used to reach subnet (or "" for remote
  319. /// subnets)
  320. /// @return network interface name for directly attached subnets or ""
  321. std::string getIface() const;
  322. /// @brief Returns textual representation of the subnet (e.g.
  323. /// "2001:db8::/64")
  324. ///
  325. /// @return textual representation
  326. virtual std::string toText() const;
  327. /// @brief Resets subnet-id counter to its initial value (1)
  328. ///
  329. /// This should be called during reconfiguration, before any new
  330. /// subnet objects are created. It will ensure that the subnet_id will
  331. /// be consistent between reconfigures.
  332. static void resetSubnetID() {
  333. static_id_ = 1;
  334. }
  335. protected:
  336. /// @brief Returns all pools (non-const variant)
  337. ///
  338. /// The reference is only valid as long as the object that returned it.
  339. ///
  340. /// @param type lease type to be set
  341. /// @return a collection of all pools
  342. PoolCollection& getPoolsWritable(Lease::Type type);
  343. /// @brief Protected constructor
  344. //
  345. /// By making the constructor protected, we make sure that noone will
  346. /// ever instantiate that class. Subnet4 and Subnet6 should be used instead.
  347. ///
  348. /// This constructor assigns a new subnet-id (see @ref generateNextID).
  349. /// This subnet-id has unique value that is strictly monotonously increasing
  350. /// for each subnet, until it is explicitly reset back to 1 during
  351. /// reconfiguration process.
  352. Subnet(const isc::asiolink::IOAddress& prefix, uint8_t len,
  353. const Triplet<uint32_t>& t1,
  354. const Triplet<uint32_t>& t2,
  355. const Triplet<uint32_t>& valid_lifetime);
  356. /// @brief virtual destructor
  357. ///
  358. /// A virtual destructor is needed because other classes
  359. /// derive from this class.
  360. virtual ~Subnet() { };
  361. /// @brief keeps the subnet-id value
  362. ///
  363. /// It is inreased every time a new Subnet object is created.
  364. /// It is reset (@ref resetSubnetId) every time reconfiguration occurs.
  365. ///
  366. /// Static value initialized in subnet.cc.
  367. static SubnetID static_id_;
  368. /// @brief returns the next unique Subnet-ID
  369. ///
  370. /// This method generates and returns the next unique subnet-id.
  371. /// It is a strictly monotonously increasing value (1,2,3,...) for
  372. /// each new Subnet object created. It can be explicitly reset
  373. /// back to 1 during reconfiguration (@ref resetSubnetID).
  374. ///
  375. /// @return the next unique Subnet-ID
  376. static SubnetID generateNextID() {
  377. return (static_id_++);
  378. }
  379. /// @brief Checks if used pool type is valid
  380. ///
  381. /// Allowed type for Subnet4 is Pool::TYPE_V4.
  382. /// Allowed types for Subnet6 are Pool::TYPE_{IA,TA,PD}.
  383. /// This method is implemented in derived classes.
  384. ///
  385. /// @param type type to be checked
  386. /// @throw BadValue if invalid value is used
  387. virtual void checkType(Lease::Type type) const = 0;
  388. /// @brief Check if option is valid and can be added to a subnet.
  389. ///
  390. /// @param option option to be validated.
  391. virtual void validateOption(const OptionPtr& option) const = 0;
  392. /// @brief subnet-id
  393. ///
  394. /// Subnet-id is a unique value that can be used to find or identify
  395. /// a Subnet4 or Subnet6.
  396. SubnetID id_;
  397. /// @brief collection of IPv4 or non-temporary IPv6 pools in that subnet
  398. PoolCollection pools_;
  399. /// @brief collection of IPv6 temporary address pools in that subnet
  400. PoolCollection pools_ta_;
  401. /// @brief collection of IPv6 prefix pools in that subnet
  402. PoolCollection pools_pd_;
  403. /// @brief a prefix of the subnet
  404. isc::asiolink::IOAddress prefix_;
  405. /// @brief a prefix length of the subnet
  406. uint8_t prefix_len_;
  407. /// @brief a tripet (min/default/max) holding allowed renew timer values
  408. Triplet<uint32_t> t1_;
  409. /// @brief a tripet (min/default/max) holding allowed rebind timer values
  410. Triplet<uint32_t> t2_;
  411. /// @brief a tripet (min/default/max) holding allowed valid lifetime values
  412. Triplet<uint32_t> valid_;
  413. /// @brief last allocated address
  414. ///
  415. /// This is the last allocated address that was previously allocated from
  416. /// this particular subnet. Some allocation algorithms (e.g. iterative) use
  417. /// that value, others do not. It should be noted that although the value
  418. /// is usually correct, there are cases when it is invalid, e.g. after
  419. /// removing a pool, restarting or changing allocation algorithms. For
  420. /// that purpose it should be only considered a help that should not be
  421. /// fully trusted.
  422. isc::asiolink::IOAddress last_allocated_ia_;
  423. /// @brief last allocated temporary address
  424. ///
  425. /// See @ref last_allocated_ia_ for details.
  426. isc::asiolink::IOAddress last_allocated_ta_;
  427. /// @brief last allocated IPv6 prefix
  428. ///
  429. /// See @ref last_allocated_ia_ for details.
  430. isc::asiolink::IOAddress last_allocated_pd_;
  431. /// @brief Name of the network interface (if connected directly)
  432. std::string iface_;
  433. private:
  434. /// A collection of option spaces grouping option descriptors.
  435. typedef OptionSpaceContainer<OptionContainer,
  436. OptionDescriptor, std::string> OptionSpaceCollection;
  437. /// A collection of vendor space option descriptors.
  438. typedef OptionSpaceContainer<OptionContainer,
  439. OptionDescriptor, uint32_t> VendorOptionSpaceCollection;
  440. /// Regular options are kept here
  441. OptionSpaceCollection option_spaces_;
  442. /// Vendor options are kept here
  443. VendorOptionSpaceCollection vendor_option_spaces_;
  444. };
  445. /// @brief A generic pointer to either Subnet4 or Subnet6 object
  446. typedef boost::shared_ptr<Subnet> SubnetPtr;
  447. /// @brief A configuration holder for IPv4 subnet.
  448. ///
  449. /// This class represents an IPv4 subnet.
  450. class Subnet4 : public Subnet {
  451. public:
  452. /// @brief Constructor with all parameters
  453. ///
  454. /// This constructor calls Subnet::Subnet, where subnet-id is generated.
  455. ///
  456. /// @param prefix Subnet4 prefix
  457. /// @param length prefix length
  458. /// @param t1 renewal timer (in seconds)
  459. /// @param t2 rebind timer (in seconds)
  460. /// @param valid_lifetime preferred lifetime of leases (in seconds)
  461. Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
  462. const Triplet<uint32_t>& t1,
  463. const Triplet<uint32_t>& t2,
  464. const Triplet<uint32_t>& valid_lifetime);
  465. /// @brief Sets siaddr for the Subnet4
  466. ///
  467. /// Will be used for siaddr field (the next server) that typically is used
  468. /// as TFTP server. If not specified, the default value of 0.0.0.0 is
  469. /// used.
  470. void setSiaddr(const isc::asiolink::IOAddress& siaddr);
  471. /// @brief Returns siaddr for this subnet
  472. ///
  473. /// @return siaddr value
  474. isc::asiolink::IOAddress getSiaddr() const;
  475. protected:
  476. /// @brief Check if option is valid and can be added to a subnet.
  477. ///
  478. /// @param option option to be validated.
  479. ///
  480. /// @throw isc::BadValue if provided option is invalid.
  481. virtual void validateOption(const OptionPtr& option) const;
  482. /// @brief Returns default address for pool selection
  483. /// @return ANY IPv4 address
  484. virtual isc::asiolink::IOAddress default_pool() const {
  485. return (isc::asiolink::IOAddress("0.0.0.0"));
  486. }
  487. /// @brief Checks if used pool type is valid
  488. ///
  489. /// Allowed type for Subnet4 is Pool::TYPE_V4.
  490. ///
  491. /// @param type type to be checked
  492. /// @throw BadValue if invalid value is used
  493. virtual void checkType(Lease::Type type) const;
  494. /// @brief siaddr value for this subnet
  495. isc::asiolink::IOAddress siaddr_;
  496. };
  497. /// @brief A pointer to a Subnet4 object
  498. typedef boost::shared_ptr<Subnet4> Subnet4Ptr;
  499. /// @brief A collection of Subnet6 objects
  500. typedef std::vector<Subnet4Ptr> Subnet4Collection;
  501. /// @brief A configuration holder for IPv6 subnet.
  502. ///
  503. /// This class represents an IPv6 subnet.
  504. class Subnet6 : public Subnet {
  505. public:
  506. /// @brief Constructor with all parameters
  507. ///
  508. /// This constructor calls Subnet::Subnet, where subnet-id is generated.
  509. ///
  510. /// @param prefix Subnet6 prefix
  511. /// @param length prefix length
  512. /// @param t1 renewal timer (in seconds)
  513. /// @param t2 rebind timer (in seconds)
  514. /// @param preferred_lifetime preferred lifetime of leases (in seconds)
  515. /// @param valid_lifetime preferred lifetime of leases (in seconds)
  516. Subnet6(const isc::asiolink::IOAddress& prefix, uint8_t length,
  517. const Triplet<uint32_t>& t1,
  518. const Triplet<uint32_t>& t2,
  519. const Triplet<uint32_t>& preferred_lifetime,
  520. const Triplet<uint32_t>& valid_lifetime);
  521. /// @brief Returns preverred lifetime (in seconds)
  522. ///
  523. /// @return a triplet with preferred lifetime
  524. Triplet<uint32_t> getPreferred() const {
  525. return (preferred_);
  526. }
  527. /// @brief sets interface-id option (if defined)
  528. ///
  529. /// @param ifaceid pointer to interface-id option
  530. void setInterfaceId(const OptionPtr& ifaceid) {
  531. interface_id_ = ifaceid;
  532. }
  533. /// @brief returns interface-id value (if specified)
  534. /// @return interface-id option (if defined)
  535. OptionPtr getInterfaceId() const {
  536. return interface_id_;
  537. }
  538. protected:
  539. /// @brief Check if option is valid and can be added to a subnet.
  540. ///
  541. /// @param option option to be validated.
  542. ///
  543. /// @throw isc::BadValue if provided option is invalid.
  544. virtual void validateOption(const OptionPtr& option) const;
  545. /// @brief Returns default address for pool selection
  546. /// @return ANY IPv6 address
  547. virtual isc::asiolink::IOAddress default_pool() const {
  548. return (isc::asiolink::IOAddress("::"));
  549. }
  550. /// @brief Checks if used pool type is valid
  551. ///
  552. /// allowed types for Subnet6 are Pool::TYPE_{IA,TA,PD}.
  553. ///
  554. /// @param type type to be checked
  555. /// @throw BadValue if invalid value is used
  556. virtual void checkType(Lease::Type type) const;
  557. /// @brief specifies optional interface-id
  558. OptionPtr interface_id_;
  559. /// @brief a triplet with preferred lifetime (in seconds)
  560. Triplet<uint32_t> preferred_;
  561. };
  562. /// @brief A pointer to a Subnet6 object
  563. typedef boost::shared_ptr<Subnet6> Subnet6Ptr;
  564. /// @brief A collection of Subnet6 objects
  565. typedef std::vector<Subnet6Ptr> Subnet6Collection;
  566. } // end of isc::dhcp namespace
  567. } // end of isc namespace
  568. #endif // SUBNET_T