![]() |
Kea
1.5.0
|
#include <subnet.h>
Inheritance diagram for isc::dhcp::Subnet:Public Member Functions | |
| void | addPool (const PoolPtr &pool) |
| Adds a new pool for the subnet. More... | |
| virtual isc::asiolink::IOAddress | default_pool () const =0 |
| Returns the default address that will be used for pool selection. More... | |
| void | delPools (Lease::Type type) |
| Deletes all pools of specified type. More... | |
| std::pair< isc::asiolink::IOAddress, uint8_t > | get () const |
| Returns subnet parameters (prefix and prefix length) More... | |
| PoolPtr | getAnyPool (Lease::Type type) |
| Returns a pool without any address specified. More... | |
| SubnetID | getID () const |
| Returns unique ID for that subnet. More... | |
| isc::asiolink::IOAddress | getLastAllocated (Lease::Type type) const |
| returns the last address that was tried from this subnet More... | |
| boost::posix_time::ptime | getLastAllocatedTime (const Lease::Type &lease_type) const |
Returns the timestamp when the setLastAllocated function was called. More... | |
| const PoolPtr | getPool (Lease::Type type, const isc::asiolink::IOAddress &addr, bool anypool=true) const |
| Returns a pool that specified address belongs to. More... | |
| const PoolPtr | getPool (Lease::Type type, const ClientClasses &client_classes, const isc::asiolink::IOAddress &addr) const |
| Returns a pool that specified address belongs to with classes. More... | |
| uint64_t | getPoolCapacity (Lease::Type type) const |
| Returns the number of possible leases for specified lease type. More... | |
| uint64_t | getPoolCapacity (Lease::Type type, const ClientClasses &client_classes) const |
| Returns the number of possible leases for specified lease type allowed for a client which belongs to classes. More... | |
| const PoolCollection & | getPools (Lease::Type type) const |
| Returns all pools (const variant) More... | |
| template<typename SharedNetworkPtrType > | |
| void | getSharedNetwork (SharedNetworkPtrType &shared_network) const |
| Retrieves pointer to a shared network associated with a subnet. More... | |
| std::string | getSharedNetworkName () const |
| Returns shared network name. More... | |
| bool | inPool (Lease::Type type, const isc::asiolink::IOAddress &addr) const |
| checks if the specified address is in pools More... | |
| bool | inPool (Lease::Type type, const isc::asiolink::IOAddress &addr, const ClientClasses &client_classes) const |
| checks if the specified address is in allowed pools More... | |
| bool | inRange (const isc::asiolink::IOAddress &addr) const |
| checks if specified address is in range More... | |
| void | setLastAllocated (Lease::Type type, const isc::asiolink::IOAddress &addr) |
| sets the last address that was tried from this subnet More... | |
| void | setSharedNetworkName (const std::string &shared_network_name) |
| Sets new shared network name. More... | |
| virtual std::string | toText () const |
| Returns textual representation of the subnet (e.g. More... | |
Public Member Functions inherited from isc::data::UserContext | |
| void | contextToElement (data::ElementPtr map) const |
| Merge unparse a user_context object. More... | |
| data::ConstElementPtr | getContext () const |
| Returns const pointer to the user context. More... | |
| void | setContext (const data::ConstElementPtr &ctx) |
| Sets user context. More... | |
Public Member Functions inherited from isc::data::CfgToElement | |
| virtual | ~CfgToElement () |
| Destructor. More... | |
Static Public Member Functions | |
| static void | resetSubnetID () |
| Resets subnet-id counter to its initial value (1) More... | |
Static Public Member Functions inherited from isc::data::UserContext | |
| static data::ElementPtr | toElement (data::ConstElementPtr map) |
| Copy extracting comments an Element map. More... | |
Protected Member Functions | |
| Subnet (const isc::asiolink::IOAddress &prefix, uint8_t len, const SubnetID id) | |
| Protected constructor. More... | |
| virtual | ~Subnet () |
| virtual destructor More... | |
| virtual void | checkType (Lease::Type type) const =0 |
| Checks if used pool type is valid. More... | |
| PoolCollection & | getPoolsWritable (Lease::Type type) |
| Returns all pools (non-const variant) More... | |
| bool | poolOverlaps (const Lease::Type &pool_type, const PoolPtr &pool) const |
| Checks if the specified pool overlaps with an existing pool. More... | |
| uint64_t | sumPoolCapacity (const PoolCollection &pools) const |
| Returns a sum of possible leases in all pools. More... | |
| uint64_t | sumPoolCapacity (const PoolCollection &pools, const ClientClasses &client_classes) const |
| Returns a sum of possible leases in all pools allowing classes. More... | |
| virtual data::ElementPtr | toElement () const |
| Unparse a subnet object. More... | |
Static Protected Member Functions | |
| static SubnetID | generateNextID () |
| returns the next unique Subnet-ID More... | |
| static std::pair< asiolink::IOAddress, uint8_t > | parsePrefixCommon (const std::string &prefix) |
| Converts subnet prefix to a pair of prefix/length pair. More... | |
Protected Attributes | |
| SubnetID | id_ |
| subnet-id More... | |
| std::string | iface_ |
| Name of the network interface (if connected directly) More... | |
| isc::asiolink::IOAddress | last_allocated_ia_ |
| last allocated address More... | |
| isc::asiolink::IOAddress | last_allocated_pd_ |
| last allocated IPv6 prefix More... | |
| isc::asiolink::IOAddress | last_allocated_ta_ |
| last allocated temporary address More... | |
| std::map< Lease::Type, boost::posix_time::ptime > | last_allocated_time_ |
| Timestamp indicating when a lease of a specified type has been last allocated from this subnet. More... | |
| PoolCollection | pools_ |
| collection of IPv4 or non-temporary IPv6 pools in that subnet More... | |
| PoolCollection | pools_pd_ |
| collection of IPv6 prefix pools in that subnet More... | |
| PoolCollection | pools_ta_ |
| collection of IPv6 temporary address pools in that subnet More... | |
| isc::asiolink::IOAddress | prefix_ |
| a prefix of the subnet More... | |
| uint8_t | prefix_len_ |
| a prefix length of the subnet More... | |
| WeakNetworkPtr | shared_network_ |
| Pointer to a shared network that subnet belongs to. More... | |
| std::string | shared_network_name_ |
| Shared network name. More... | |
Protected Attributes inherited from isc::data::UserContext | |
| data::ConstElementPtr | user_context_ |
| Pointer to the user context (may be NULL) More... | |
Static Protected Attributes | |
| static SubnetID | static_id_ = 1 |
| keeps the subnet-id value More... | |
Friends | |
| class | AssignableNetwork |
|
protected |
Protected constructor.
By making the constructor protected, we make sure that no one will ever instantiate that class. Subnet4 and Subnet6 should be used instead.
This constructor assigns a new subnet-id (see generateNextID). This subnet-id has unique value that is strictly monotonously increasing for each subnet, until it is explicitly reset back to 1 during reconfiguration process.
| prefix | subnet prefix |
| len | prefix length for the subnet |
| id | arbitrary subnet id, value of 0 triggers autogeneration of subnet id |
Definition at line 54 of file subnet.cc.
References isc_throw, isc::asiolink::IOAddress::isV4(), isc::asiolink::IOAddress::isV6(), last_allocated_time_, isc::dhcp::Lease::TYPE_NA, isc::dhcp::Lease::TYPE_PD, isc::dhcp::Lease::TYPE_TA, and isc::dhcp::Lease::TYPE_V4.
Here is the call graph for this function:
|
inlineprotectedvirtual |
| void isc::dhcp::Subnet::addPool | ( | const PoolPtr & | pool | ) |
Adds a new pool for the subnet.
This method checks that the address range represented by the pool matches the subnet prefix, if the pool type is different than IA_PD. The prefixes from the IA_PD pools don't need to match the prefix from the subnet from which they are handed out to the requesting router because the requesting router may use the delegated prefixes in different networks (using different subnets).
A DHCPv4 pool being added must not overlap with any existing DHCPv4 pool. A DHCPv6 pool being added must not overlap with any existing DHCPv6 pool.
Pools held within a subnet are sorted by first pool address/prefix from the lowest to the highest.
| pool | pool to be added |
| isc::BadValue | if the pool type is invalid, the pool is not an IA_PD pool and the address range of this pool does not match the subnet prefix, or the pool overlaps with an existing pool within the subnet. |
Definition at line 443 of file subnet.cc.
References checkType(), getPoolsWritable(), inRange(), isc_throw, poolOverlaps(), prefix_, prefix_len_, isc::dhcp::Lease::TYPE_NA, isc::dhcp::Lease::TYPE_PD, isc::dhcp::Lease::TYPE_TA, isc::dhcp::Lease::TYPE_V4, and isc::dhcp::Lease::typeToText().
Here is the call graph for this function:
|
protectedpure virtual |
Checks if used pool type is valid.
Allowed type for Subnet4 is Pool::TYPE_V4. Allowed types for Subnet6 are Pool::TYPE_{IA,TA,PD}. This method is implemented in derived classes.
| type | type to be checked |
| BadValue | if invalid value is used |
Referenced by addPool(), getLastAllocated(), getPool(), getPools(), getPoolsWritable(), and setLastAllocated().
|
pure virtual |
Returns the default address that will be used for pool selection.
It must be implemented in derived classes (should return :: for Subnet6 and 0.0.0.0 for Subnet4)
Referenced by getAnyPool().
| void isc::dhcp::Subnet::delPools | ( | Lease::Type | type | ) |
Deletes all pools of specified type.
This method is used for testing purposes only
| type | type of pools to be deleted |
Definition at line 498 of file subnet.cc.
References getPoolsWritable().
Here is the call graph for this function:
|
inlinestaticprotected |
returns the next unique Subnet-ID
This method generates and returns the next unique subnet-id. It is a strictly monotonously increasing value (1,2,3,...) for each new Subnet object created. It can be explicitly reset back to 1 during reconfiguration (resetSubnetID).
Definition at line 342 of file subnet.h.
References static_id_.
|
inline |
Returns subnet parameters (prefix and prefix length)
Definition at line 119 of file subnet.h.
References prefix_, and prefix_len_.
|
inline |
Returns a pool without any address specified.
| type | pool type that the pool is looked for |
Definition at line 189 of file subnet.h.
References default_pool(), and getPool().
Here is the call graph for this function:
|
inline |
Returns unique ID for that subnet.
Definition at line 114 of file subnet.h.
References id_.
Referenced by isc::dhcp::Subnet4::getNextSubnet(), isc::dhcp::Subnet6::getNextSubnet(), and toElement().
| isc::asiolink::IOAddress isc::dhcp::Subnet::getLastAllocated | ( | Lease::Type | type | ) | const |
returns the last address that was tried from this subnet
This method returns the last address that was attempted to be allocated from this subnet. This is used as helper information for the next iteration of the allocation algorithm.
| type | lease type to be returned |
Definition at line 83 of file subnet.cc.
References checkType(), isc_throw, last_allocated_ia_, last_allocated_pd_, last_allocated_ta_, isc::dhcp::Lease::TYPE_NA, isc::dhcp::Lease::TYPE_PD, isc::dhcp::Lease::TYPE_TA, and isc::dhcp::Lease::TYPE_V4.
Here is the call graph for this function:| boost::posix_time::ptime isc::dhcp::Subnet::getLastAllocatedTime | ( | const Lease::Type & | lease_type | ) | const |
Returns the timestamp when the setLastAllocated function was called.
| lease_type | Lease type for which last allocation timestamp should be returned. |
Definition at line 101 of file subnet.cc.
References last_allocated_time_.
| const PoolPtr isc::dhcp::Subnet::getPool | ( | Lease::Type | type, |
| const isc::asiolink::IOAddress & | addr, | ||
| bool | anypool = true |
||
| ) | const |
Returns a pool that specified address belongs to.
This method uses binary search to retrieve the pool. Thus, the number of comparisons performed by this method is logarithmic in the number of pools belonging to a subnet.
If there is no pool that the address belongs to (hint is invalid), other pool of specified type will be returned.
With anypool set to true, this is means give me a pool, preferably the one that addr belongs to. With anypool set to false, it means give me a pool that addr belongs to (or NULL if here is no such pool)
| type | pool type that the pool is looked for |
| addr | address that the returned pool should cover (optional) |
| anypool | other pool may be returned as well, not only the one that addr belongs to |
Definition at line 375 of file subnet.cc.
References checkType(), and getPools().
Referenced by getAnyPool().
Here is the call graph for this function:| const PoolPtr isc::dhcp::Subnet::getPool | ( | Lease::Type | type, |
| const ClientClasses & | client_classes, | ||
| const isc::asiolink::IOAddress & | addr | ||
| ) | const |
Returns a pool that specified address belongs to with classes.
Variant using only pools allowing given classes
| type | pool type that the pool is looked for |
| client_classes | client class list which must be allowed |
| addr | address that the returned pool should cover (optional) |
Definition at line 414 of file subnet.cc.
References checkType(), and getPools().
Here is the call graph for this function:| uint64_t isc::dhcp::Subnet::getPoolCapacity | ( | Lease::Type | type | ) | const |
Returns the number of possible leases for specified lease type.
| type | type of the lease |
Definition at line 146 of file subnet.cc.
References isc_throw, pools_, pools_pd_, pools_ta_, sumPoolCapacity(), isc::dhcp::Lease::TYPE_NA, isc::dhcp::Lease::TYPE_PD, isc::dhcp::Lease::TYPE_TA, and isc::dhcp::Lease::TYPE_V4.
Here is the call graph for this function:| uint64_t isc::dhcp::Subnet::getPoolCapacity | ( | Lease::Type | type, |
| const ClientClasses & | client_classes | ||
| ) | const |
Returns the number of possible leases for specified lease type allowed for a client which belongs to classes.
| type | type of the lease |
| client_classes | List of classes the client belongs to. |
Definition at line 162 of file subnet.cc.
References isc_throw, pools_, pools_pd_, pools_ta_, sumPoolCapacity(), isc::dhcp::Lease::TYPE_NA, isc::dhcp::Lease::TYPE_PD, isc::dhcp::Lease::TYPE_TA, and isc::dhcp::Lease::TYPE_V4.
Here is the call graph for this function:| const PoolCollection & isc::dhcp::Subnet::getPools | ( | Lease::Type | type | ) | const |
Returns all pools (const variant)
The reference is only valid as long as the object that returned it.
| type | lease type to be set |
Definition at line 339 of file subnet.cc.
References checkType(), isc_throw, pools_, pools_pd_, pools_ta_, isc::dhcp::Lease::TYPE_NA, isc::dhcp::Lease::TYPE_PD, isc::dhcp::Lease::TYPE_TA, and isc::dhcp::Lease::TYPE_V4.
Referenced by getPool(), inPool(), poolOverlaps(), isc::dhcp::Subnet4::toElement(), and isc::dhcp::Subnet6::toElement().
Here is the call graph for this function:
|
protected |
Returns all pools (non-const variant)
The reference is only valid as long as the object that returned it.
| type | lease type to be set |
Definition at line 357 of file subnet.cc.
References checkType(), isc_throw, pools_, pools_pd_, pools_ta_, isc::dhcp::Lease::TYPE_NA, isc::dhcp::Lease::TYPE_PD, isc::dhcp::Lease::TYPE_TA, and isc::dhcp::Lease::TYPE_V4.
Referenced by addPool(), and delPools().
Here is the call graph for this function:
|
inline |
Retrieves pointer to a shared network associated with a subnet.
By implementing it as a template function we overcome a need to include shared_network.h header file to specify return type explicitly. The header can't be included because it would cause circular dependency between subnet.h and shared_network.h.
This method uses an argument to hold a return value to allow the compiler to infer the return type without a need to call this function with an explicit return type as template argument.
| [out] | shared_network | Pointer to the shared network where returned value should be assigned. |
| Type | of the shared network, i.e. SharedNetwork4 or a SharedNetwork6. |
Definition at line 252 of file subnet.h.
References shared_network_.
Referenced by isc::dhcp::Subnet4::clientSupported(), isc::dhcp::Subnet6::clientSupported(), isc::dhcp::Subnet4::getNextSubnet(), and isc::dhcp::Subnet6::getNextSubnet().
|
inline |
Returns shared network name.
Definition at line 273 of file subnet.h.
References shared_network_name_.
| bool isc::dhcp::Subnet::inPool | ( | Lease::Type | type, |
| const isc::asiolink::IOAddress & | addr | ||
| ) | const |
checks if the specified address is in pools
Note the difference between inRange() and inPool() for addresses (i.e. not prefixes). For a given subnet (e.g. 2001::/64) there may be one or more pools defined that may or may not cover entire subnet, e.g. pool 2001::1-2001::10). inPool() returning true implies inRange(), but the reverse implication is not always true. For the given example, 2001::1234:abcd would return true for inRange(), but false for inPool() check.
| type | type of pools to iterate over |
| addr | this address will be checked if it belongs to any pools in that subnet |
Definition at line 503 of file subnet.cc.
References getPools(), inRange(), and isc::dhcp::Lease::TYPE_PD.
Here is the call graph for this function:| bool isc::dhcp::Subnet::inPool | ( | Lease::Type | type, |
| const isc::asiolink::IOAddress & | addr, | ||
| const ClientClasses & | client_classes | ||
| ) | const |
checks if the specified address is in allowed pools
This takes also into account client classes
| type | type of pools to iterate over |
| addr | this address will be checked if it belongs to any pools in that subnet |
| client_classes | client class list which must be allowed |
Definition at line 523 of file subnet.cc.
References getPools(), inRange(), and isc::dhcp::Lease::TYPE_PD.
Here is the call graph for this function:| bool isc::dhcp::Subnet::inRange | ( | const isc::asiolink::IOAddress & | addr | ) | const |
checks if specified address is in range
Definition at line 76 of file subnet.cc.
References isc::dhcp::firstAddrInPrefix(), isc::dhcp::lastAddrInPrefix(), prefix_, and prefix_len_.
Referenced by addPool(), and inPool().
Here is the call graph for this function:
|
staticprotected |
Converts subnet prefix to a pair of prefix/length pair.
IPv4 and IPv6 specific conversion functions should apply extra checks on the returned values, i.e. whether length is in range and the IP address has a valid type.
| prefix | Prefix to be parsed. |
| BadValue | if provided prefix is not valid. |
Definition at line 219 of file subnet.cc.
References isc_throw.
Referenced by isc::dhcp::Subnet4::parsePrefix(), and isc::dhcp::Subnet6::parsePrefix().
|
protected |
Checks if the specified pool overlaps with an existing pool.
| pool_type | Pool type. |
| pool | Pointer to a pool for which the method should check if it overlaps with any existing pool within this subnet. |
Definition at line 548 of file subnet.cc.
References getPools().
Referenced by addPool().
Here is the call graph for this function:
|
inlinestatic |
Resets subnet-id counter to its initial value (1)
This should be called during reconfiguration, before any new subnet objects are created. It will ensure that the subnet_id will be consistent between reconfigures.
Definition at line 231 of file subnet.h.
References static_id_.
| void isc::dhcp::Subnet::setLastAllocated | ( | Lease::Type | type, |
| const isc::asiolink::IOAddress & | addr | ||
| ) |
sets the last address that was tried from this subnet
This method sets the last address that was attempted to be allocated from this subnet. This is used as helper information for the next iteration of the allocation algorithm.
| addr | address/prefix to that was tried last |
| type | lease type to be set |
Definition at line 113 of file subnet.cc.
References checkType(), isc_throw, last_allocated_ia_, last_allocated_pd_, last_allocated_ta_, last_allocated_time_, isc::dhcp::Lease::TYPE_NA, isc::dhcp::Lease::TYPE_PD, isc::dhcp::Lease::TYPE_TA, and isc::dhcp::Lease::TYPE_V4.
Here is the call graph for this function:
|
inline |
Sets new shared network name.
In certain cases the subnet must be associated with the shared network but the shared network object is not available. In particular, subnets are returned from the configuration database with only names of the shared networks. The actual shared networks must be fetched from the database using a separate query. In order to not loose associations of subnets with shared networks, the configuration backends will use this method to store the shared network names. The servers will later use those names to associate subnets with shared network instances.
| shared_network_name | New shared network name. |
Definition at line 289 of file subnet.h.
References shared_network_name_.
|
protected |
Returns a sum of possible leases in all pools.
| pools | list of pools |
Definition at line 179 of file subnet.cc.
Referenced by getPoolCapacity().
|
protected |
|
protectedvirtual |
Unparse a subnet object.
Implements isc::data::CfgToElement.
Reimplemented in isc::dhcp::Subnet6, and isc::dhcp::Subnet4.
Definition at line 691 of file subnet.cc.
References isc::data::UserContext::contextToElement(), getID(), and toText().
Referenced by isc::dhcp::Subnet4::toElement(), and isc::dhcp::Subnet6::toElement().
Here is the call graph for this function:
|
virtual |
Returns textual representation of the subnet (e.g.
"2001:db8::/64")
Definition at line 139 of file subnet.cc.
References prefix_, and prefix_len_.
Referenced by isc::dhcp::Subnet6ConfigParser::initSubnet(), toElement(), and isc::dhcp::Subnet4::toElement().
|
friend |
|
protected |
|
protected |
|
protected |
last allocated address
This is the last allocated address that was previously allocated from this particular subnet. Some allocation algorithms (e.g. iterative) use that value, others do not. It should be noted that although the value is usually correct, there are cases when it is invalid, e.g. after removing a pool, restarting or changing allocation algorithms. For that purpose it should be only considered a help that should not be fully trusted.
Definition at line 428 of file subnet.h.
Referenced by getLastAllocated(), and setLastAllocated().
|
protected |
last allocated IPv6 prefix
See last_allocated_ia_ for details.
Definition at line 438 of file subnet.h.
Referenced by getLastAllocated(), and setLastAllocated().
|
protected |
last allocated temporary address
See last_allocated_ia_ for details.
Definition at line 433 of file subnet.h.
Referenced by getLastAllocated(), and setLastAllocated().
|
protected |
Timestamp indicating when a lease of a specified type has been last allocated from this subnet.
Definition at line 442 of file subnet.h.
Referenced by getLastAllocatedTime(), setLastAllocated(), and Subnet().
|
protected |
collection of IPv4 or non-temporary IPv6 pools in that subnet
Definition at line 405 of file subnet.h.
Referenced by getPoolCapacity(), getPools(), and getPoolsWritable().
|
protected |
collection of IPv6 prefix pools in that subnet
Definition at line 411 of file subnet.h.
Referenced by getPoolCapacity(), getPools(), and getPoolsWritable().
|
protected |
collection of IPv6 temporary address pools in that subnet
Definition at line 408 of file subnet.h.
Referenced by getPoolCapacity(), getPools(), and getPoolsWritable().
|
protected |
|
protected |
|
protected |
Pointer to a shared network that subnet belongs to.
Definition at line 448 of file subnet.h.
Referenced by getSharedNetwork().
|
protected |
Shared network name.
Definition at line 451 of file subnet.h.
Referenced by getSharedNetworkName(), and setSharedNetworkName().
|
staticprotected |
keeps the subnet-id value
It is incremented every time a new Subnet object is created. It is reset (resetSubnetID) every time reconfiguration occurs.
Static value initialized in subnet.cc.
Definition at line 323 of file subnet.h.
Referenced by generateNextID(), and resetSubnetID().