/// it is supported. On the other hand, client belonging to classes
/// "foobar" and "zyxxy" is not supported.
///
+ /// @todo: Currently the logic is simple: client is supported if it belongs
+ /// to any class mentioned in white_list_. We will eventually need a
+ /// way to specify more fancy logic (e.g. to meet all classes, not just
+ /// any)
+ ///
/// @param client_classes list of all classes the client belongs to
/// @return true if client can be supported, false otherwise
bool
/// @brief optional definition of a client class
///
/// If defined, only clients belonging to that class will be allowed to use
- /// this particular subnet. The default value for this is "", which means
- /// that any client is allowed, regardless of its class.
- ///
- /// @todo This is just a single class for now, but it will eventually be
- /// list of classes (only classes on the list are allowed, the rest is
- /// rejected) and we'll also have black-list (only classes on the list are
- /// rejected, the rest are allowed). Implementing this will require
- /// fancy parser logic, so it may be a while until we support this.
- /// This will lead to changing type of white_list_ to ClientClasses.
- /// Note that the interface will remain the same (allowClientClass()
- /// would still take a single ClientClass. It will just be possible
- /// to call it multiple times to allow multiple classes).
- ClientClass white_list_;
+ /// this particular subnet. The default value for this is an empty list,
+ /// which means that any client is allowed, regardless of its class.
+ ///
+ /// @todo This is just a single list of allowed classes. We'll also need
+ /// to add a black-list (only classes on the list are rejected, the rest
+ /// are allowed). Implementing this will require more fancy parser logic,
+ /// so it may be a while until we support this.
+ ClientClasses white_list_;
private:
}
// Tests whether Subnet4 object is able to store and process properly
-// information about allowed client classes.
+// information about allowed client class (a single class).
TEST(Subnet4Test, clientClasses) {
// Create the V4 subnet.
Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 8, 1, 2, 3));
EXPECT_TRUE(subnet->clientSupported(three_classes));
}
+// Tests whether Subnet4 object is able to store and process properly
+// information about allowed client classes (multiple classes allowed).
+TEST(Subnet4Test, clientClassesMultiple) {
+ // Create the V4 subnet.
+ Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 8, 1, 2, 3));
+
+ // This client does not belong to any class.
+ isc::dhcp::ClientClasses no_class;
+
+ // This client belongs to foo only.
+ isc::dhcp::ClientClasses foo_class;
+ foo_class.insert("foo");
+
+ // This client belongs to bar only. I like that client.
+ isc::dhcp::ClientClasses bar_class;
+ bar_class.insert("bar");
+
+ // No class restrictions defined, any client should be supported
+ EXPECT_TRUE(subnet->clientSupported(no_class));
+ EXPECT_TRUE(subnet->clientSupported(foo_class));
+ EXPECT_TRUE(subnet->clientSupported(bar_class));
+
+ // Let's allow clients belongning to "bar" or "foo" class.
+ subnet->allowClientClass("bar");
+ subnet->allowClientClass("foo");
+
+ // Class-less clients are to be rejected.
+ EXPECT_FALSE(subnet->clientSupported(no_class));
+
+ // Clients in foo class should be accepted.
+ EXPECT_TRUE(subnet->clientSupported(foo_class));
+
+ // Clients in bar class should be accepted as well.
+ EXPECT_TRUE(subnet->clientSupported(bar_class));
+}
+
TEST(Subnet4Test, addInvalidOption) {
// Create the V4 subnet.
Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 8, 1, 2, 3));
}
// Tests whether Subnet6 object is able to store and process properly
-// information about allowed client classes.
+// information about allowed client class (a single class).
TEST(Subnet6Test, clientClasses) {
// Create the V6 subnet.
Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));
EXPECT_TRUE(subnet->clientSupported(three_classes));
}
+// Tests whether Subnet6 object is able to store and process properly
+// information about allowed client class (multiple classes allowed).
+TEST(Subnet6Test, clientClassesMultiple) {
+ // Create the V6 subnet.
+ Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));
+
+ // This client does not belong to any class.
+ isc::dhcp::ClientClasses no_class;
+
+ // This client belongs to foo only.
+ isc::dhcp::ClientClasses foo_class;
+ foo_class.insert("foo");
+
+ // This client belongs to bar only. I like that client.
+ isc::dhcp::ClientClasses bar_class;
+ bar_class.insert("bar");
+
+ // No class restrictions defined, any client should be supported
+ EXPECT_TRUE(subnet->clientSupported(no_class));
+ EXPECT_TRUE(subnet->clientSupported(foo_class));
+ EXPECT_TRUE(subnet->clientSupported(bar_class));
+
+ // Let's allow only clients belongning to "foo" or "bar" class.
+ subnet->allowClientClass("foo");
+ subnet->allowClientClass("bar");
+
+ // Class-less clients are to be rejected.
+ EXPECT_FALSE(subnet->clientSupported(no_class));
+
+ // Clients in foo class should be accepted.
+ EXPECT_TRUE(subnet->clientSupported(foo_class));
+
+ // Clients in bar class should be accepted as well.
+ EXPECT_TRUE(subnet->clientSupported(bar_class));
+}
+
TEST(Subnet6Test, Subnet6_Pool6_checks) {
Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4));