Commit b038ebda authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[5305] Added names to shared networks.

parent 837a8b6a
......@@ -13,6 +13,7 @@
#include <dhcpsrv/subnet_id.h>
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>
#include <string>
namespace isc {
namespace dhcp {
......@@ -37,6 +38,29 @@ typedef boost::shared_ptr<SharedNetwork> SharedNetworkPtr;
/// Shared networks provide similar interface like subnets, thus they both
/// derive from the @ref Network class.
class SharedNetwork : public AssignableNetwork {
protected:
/// @brief Constructor.
///
/// Sets name of the shared network.
explicit SharedNetwork(const std::string& name)
: name_(name) {
}
public:
/// @brief Returns a name of the shared network.
std::string getName() const {
return (name_);
}
/// @brief Sets new name for the shared network.
///
/// @param name New name for the shared network.
void setName(const std::string& name) {
name_ = name;
}
protected:
/// @brief Adds a subnet to a shared network.
......@@ -221,6 +245,11 @@ protected:
return (*subnet_it);
}
protected:
/// @brief Holds a name of a shared network.
std::string name_;
};
/// @brief Shared network holding IPv4 subnets.
......@@ -230,6 +259,13 @@ class SharedNetwork4 : public SharedNetwork,
public boost::enable_shared_from_this<SharedNetwork4> {
public:
/// @brief Constructor.
///
/// Sets name of the shared network.
explicit SharedNetwork4(const std::string& name)
: SharedNetwork(name) {
}
/// @brief Returns shared pointer to this network.
///
/// This method is required by the parent @ref AssignableNetwork class.
......@@ -303,6 +339,13 @@ class SharedNetwork6 : public SharedNetwork,
public boost::enable_shared_from_this<SharedNetwork6> {
public:
/// @brief Constructor.
///
/// Sets name of the shared network.
explicit SharedNetwork6(const std::string& name)
: SharedNetwork(name) {
}
/// @brief Returns shared pointer to this network.
///
/// This method is required by the parent @ref AssignableNetwork class.
......
......@@ -20,13 +20,25 @@ using namespace isc::dhcp;
namespace {
// This test verifies that shared network can be given a name and that
// this name can be retrieved.
TEST(SharedNetwork4Test, getName) {
// Create shared network with an initial name "dog".
SharedNetwork4Ptr network(new SharedNetwork4("frog"));
EXPECT_EQ("frog", network->getName());
// Override the name.
network->setName("dog");
EXPECT_EQ("dog", network->getName());
}
// This test verifies that an IPv4 subnet can be added to a shared network.
// It also verifies that two subnets with the same ID can't be added to
// a shared network and that a single subnet can't be added to two different
// shared subnets.
TEST(SharedNetwork4Test, addSubnet4) {
// First, create a network.
SharedNetwork4Ptr network(new SharedNetwork4());
SharedNetwork4Ptr network(new SharedNetwork4("frog"));
// Try to add null pointer. It should throw.
Subnet4Ptr subnet;
......@@ -56,7 +68,7 @@ TEST(SharedNetwork4Test, addSubnet4) {
// Create another network and try to add a subnet to it. It should fail
// because the subnet is already associated with the first network.
SharedNetwork4Ptr network2(new SharedNetwork4());
SharedNetwork4Ptr network2(new SharedNetwork4("dog"));
ASSERT_THROW(network2->add(subnet), InvalidOperation);
}
......@@ -68,7 +80,7 @@ TEST(SharedNetwork4Test, delSubnet4) {
Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.0"), 24, 10, 20, 30,
SubnetID(2)));
SharedNetwork4Ptr network(new SharedNetwork4());
SharedNetwork4Ptr network(new SharedNetwork4("frog"));
ASSERT_NO_THROW(network->add(subnet1));
ASSERT_NO_THROW(network->add(subnet2));
......@@ -105,7 +117,7 @@ TEST(SharedNetwork4Test, delSubnet4) {
// This test verifies that it is possible to iterate over the subnets
// associated with a particular shared network.
TEST(SharedNetwork4Test, getNextSubnet) {
SharedNetwork4Ptr network(new SharedNetwork4());
SharedNetwork4Ptr network(new SharedNetwork4("frog"));
// Create three subnets.
Subnet4Ptr subnet1(new Subnet4(IOAddress("10.0.0.0"), 8, 10, 20, 30,
......@@ -169,13 +181,25 @@ TEST(SharedNetwork4Test, getNextSubnet) {
}
}
// This test verifies that shared network can be given a name and that
// this name can be retrieved.
TEST(SharedNetwork6Test, getName) {
// Create shared network with an initial name "dog".
SharedNetwork6Ptr network(new SharedNetwork6("frog"));
EXPECT_EQ("frog", network->getName());
// Override the name.
network->setName("dog");
EXPECT_EQ("dog", network->getName());
}
// This test verifies that an IPv6 subnet can be added to a shared network.
// It also verifies that two subnets with the same ID can't be added to
// a shared network and that a single subnet can't be added to two different
// shared subnets.
TEST(SharedNetwork6Test, addSubnet6) {
// First, create a network.
SharedNetwork6Ptr network(new SharedNetwork6());
SharedNetwork6Ptr network(new SharedNetwork6("frog"));
// Try to add null pointer. It should throw.
Subnet6Ptr subnet;
......@@ -205,7 +229,7 @@ TEST(SharedNetwork6Test, addSubnet6) {
// Create another network and try to add a subnet to it. It should fail
// because the subnet is already associated with the first network.
SharedNetwork6Ptr network2(new SharedNetwork6());
SharedNetwork6Ptr network2(new SharedNetwork6("dog"));
ASSERT_THROW(network2->add(subnet), InvalidOperation);
}
......@@ -217,7 +241,7 @@ TEST(SharedNetwork6Test, delSubnet6) {
Subnet6Ptr subnet2(new Subnet6(IOAddress("3000::"), 16, 10, 20, 30, 40,
SubnetID(2)));
SharedNetwork6Ptr network(new SharedNetwork6());
SharedNetwork6Ptr network(new SharedNetwork6("frog"));
ASSERT_NO_THROW(network->add(subnet1));
ASSERT_NO_THROW(network->add(subnet2));
......@@ -254,7 +278,7 @@ TEST(SharedNetwork6Test, delSubnet6) {
// This test verifies that it is possible to iterate over the subnets
// associated with a particular shared network.
TEST(SharedNetwork6Test, getNextSubnet) {
SharedNetwork6Ptr network(new SharedNetwork6());
SharedNetwork6Ptr network(new SharedNetwork6("frog"));
// Create three subnets.
Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 64, 10, 20, 30,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment