" \"subnet6\": [\n"
" {\n"
" \"id\": 1,\n"
- " \"interface\": \"\",\n"
- " \"interface-id\": \"\",\n"
" \"option-data\": [\n"
" {\n"
+" \"always-send\": false,\n"
" \"code\": 38,\n"
" \"csv-format\": false,\n"
" \"data\": \"ABCDEF0105\",\n"
" \"subnet6\": [\n"
" {\n"
" \"id\": 1,\n"
- " \"interface\": \"\",\n"
- " \"interface-id\": \"\",\n"
" \"option-data\": [\n"
" {\n"
+" \"always-send\": false,\n"
" \"code\": 38,\n"
" \"csv-format\": false,\n"
" \"data\": \"0102030405060708090A\",\n"
" },\n"
" {\n"
" \"id\": 2,\n"
- " \"interface\": \"\",\n"
- " \"interface-id\": \"\",\n"
" \"option-data\": [\n"
" {\n"
+" \"always-send\": false,\n"
" \"code\": 15,\n"
" \"csv-format\": false,\n"
" \"data\": \"FFFEFDFCFB\",\n"
" \"pd-pools\": [\n"
" {\n"
" \"delegated-len\": 64,\n"
- " \"excluded-prefix\": \"::\",\n"
- " \"excluded-prefix-len\": 0,\n"
" \"option-data\": [\n"
" {\n"
+" \"always-send\": false,\n"
" \"code\": 38,\n"
" \"csv-format\": false,\n"
" \"data\": \"112233445566\",\n"
" },\n"
" {\n"
" \"delegated-len\": 64,\n"
- " \"excluded-prefix\": \"::\",\n"
- " \"excluded-prefix-len\": 0,\n"
" \"option-data\": [\n"
" {\n"
+" \"always-send\": false,\n"
" \"code\": 15,\n"
" \"csv-format\": false,\n"
" \"data\": \"AABBCCDDEE\",\n"
/// @brief A pointer to a Subnet6 object
typedef boost::shared_ptr<Subnet6> Subnet6Ptr;
- /// @brief A collection of Subnet6 objects
- typedef std::vector<Subnet6Ptr> Subnet6Collection;
+ /// @name Definition of the multi index container holding subnet information
+ ///
+ //@{
+
+ /// @brief Tag for the random access index.
+ struct SubnetRandomAccessIndexTag { };
+
+ /// @brief Tag for the index for searching by subnet identifier.
-struct SubnetIdIndexTag { };
++struct SubnetSubnetIdIndexTag { };
+
+ /// @brief Tag for the index for searching by subnet prefix.
+ struct SubnetPrefixIndexTag { };
+
+ /// @brief Multi index container holding subnets.
+ ///
+ /// This multi index container can hold pointers to @ref Subnet4 or
+ /// @ref Subnet6 objects representing subnets. It provides indexes for
+ /// subnet lookups using subnet properties such as: subnet identifier
+ /// or subnet prefix. It also provides a random access index which
+ /// allows for using the container like a vector.
+ ///
+ /// The random access index is used by the DHCP servers which perform
+ /// a full scan on subnets to find the one that matches some specific
+ /// criteria for subnet selection.
+ ///
+ /// The remaining indexes are used for searching for a specific subnet
+ /// as a result of receiving a command over the control API, e.g.
+ /// when 'subnet-get' command is received.
+ ///
+ /// @todo We should consider optimizing subnet selection by leveraging
+ /// the indexing capabilities of this container, e.g. searching for
+ /// a subnet by interface name, relay address etc.
+ ///
+ /// @tparam SubnetType Type of the subnet: @ref Subnet4 or @ref Subnet6.
+ template<typename SubnetType>
+ using SubnetCollection = boost::multi_index_container<
+ // Multi index container holds pointers to the subnets.
+ boost::shared_ptr<SubnetType>,
+ // The following holds all indexes.
+ boost::multi_index::indexed_by<
+ // First is the random access index allowing for accessing
+ // objects just like we'd do with a vector.
+ boost::multi_index::random_access<
+ boost::multi_index::tag<SubnetRandomAccessIndexTag>
+ >,
+ // Second index allows for searching using subnet identifier.
+ boost::multi_index::ordered_unique<
- boost::multi_index::tag<SubnetIdIndexTag>,
++ boost::multi_index::tag<SubnetSubnetIdIndexTag>,
+ boost::multi_index::const_mem_fun<Subnet, SubnetID, &Subnet::getID>
+ >,
+ // Third index allows for searching using an output from toText function.
+ boost::multi_index::ordered_unique<
+ boost::multi_index::tag<SubnetPrefixIndexTag>,
+ boost::multi_index::const_mem_fun<Subnet, std::string, &Subnet::toText>
+ >
+ >
+ >;
+
+ /// @brief A collection of @c Subnet4 objects
+ ///
+ /// This container provides a set of indexes which can be used to retrieve
+ /// subnets by various properties.
+ typedef SubnetCollection<Subnet4> Subnet4Collection;
+
+ /// @brief A collection of @c Subnet6 objects
+ ///
+ /// This container provides a set of indexes which can be used to retrieve
+ /// subnets by various properties.
+ typedef SubnetCollection<Subnet6> Subnet6Collection;
+
+ //@}
} // end of isc::dhcp namespace
} // end of isc namespace