|
@@ -34,7 +34,7 @@ namespace {
|
|
|
|
|
|
TEST(Subnet4Test, constructor) {
|
|
|
EXPECT_NO_THROW(Subnet4 subnet1(IOAddress("192.0.2.2"), 16,
|
|
|
- 1, 2, 3));
|
|
|
+ 1, 2, 3, 10));
|
|
|
|
|
|
EXPECT_THROW(Subnet4 subnet2(IOAddress("192.0.2.0"), 33, 1, 2, 3),
|
|
|
BadValue); // invalid prefix length
|
|
@@ -42,7 +42,33 @@ TEST(Subnet4Test, constructor) {
|
|
|
BadValue); // IPv6 addresses are not allowed in Subnet4
|
|
|
}
|
|
|
|
|
|
-TEST(Subnet4Test, in_range) {
|
|
|
+// Checks that the subnet id can be either autogenerated or set to an
|
|
|
+// arbitrary value through the constructor.
|
|
|
+TEST(Subnet4Test, subnetID) {
|
|
|
+ // Create subnet and don't specify id, so as it is autogenerated.
|
|
|
+ Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 24, 1000, 2000,
|
|
|
+ 3000));
|
|
|
+ SubnetID id0 = subnet->getID();
|
|
|
+
|
|
|
+ // Create another subnet and let id be autogenerated.
|
|
|
+ subnet.reset(new Subnet4(IOAddress("192.0.3.0"), 24, 1000, 2000,
|
|
|
+ 3000));
|
|
|
+ SubnetID id1 = subnet->getID();
|
|
|
+
|
|
|
+ // The autogenerated ids must not be equal.
|
|
|
+ EXPECT_NE(id0, id1);
|
|
|
+
|
|
|
+ // Create third subnet but this time select an arbitrary id. The id
|
|
|
+ // we use us the one of second subnet. That way we ensure that the
|
|
|
+ // subnet id we provide via constructor is used and it is not
|
|
|
+ // autogenerated - if it was autogenerated we would get id other
|
|
|
+ // than id1 because id1 has already been used.
|
|
|
+ subnet.reset(new Subnet4(IOAddress("192.0.4.0"), 24, 1000, 2000,
|
|
|
+ 3000, id1));
|
|
|
+ EXPECT_EQ(id1, subnet->getID());
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Subnet4Test, inRange) {
|
|
|
Subnet4 subnet(IOAddress("192.0.2.1"), 24, 1000, 2000, 3000);
|
|
|
|
|
|
EXPECT_EQ(1000, subnet.getT1());
|
|
@@ -362,7 +388,33 @@ TEST(Subnet6Test, constructor) {
|
|
|
BadValue); // IPv4 addresses are not allowed in Subnet6
|
|
|
}
|
|
|
|
|
|
-TEST(Subnet6Test, in_range) {
|
|
|
+// Checks that the subnet id can be either autogenerated or set to an
|
|
|
+// arbitrary value through the constructor.
|
|
|
+TEST(Subnet6Test, subnetID) {
|
|
|
+ // Create subnet and don't specify id, so as it is autogenerated.
|
|
|
+ Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8:1::"), 64, 1000, 2000,
|
|
|
+ 3000, 4000));
|
|
|
+ SubnetID id0 = subnet->getID();
|
|
|
+
|
|
|
+ // Create another subnet and let id be autogenerated.
|
|
|
+ subnet.reset(new Subnet6(IOAddress("2001:db8:2::"), 64, 1000, 2000,
|
|
|
+ 3000, 4000));
|
|
|
+ SubnetID id1 = subnet->getID();
|
|
|
+
|
|
|
+ // The autogenerated ids must not be equal.
|
|
|
+ EXPECT_NE(id0, id1);
|
|
|
+
|
|
|
+ // Create third subnet but this time select an arbitrary id. The id
|
|
|
+ // we use us the one of second subnet. That way we ensure that the
|
|
|
+ // subnet id we provide via constructor is used and it is not
|
|
|
+ // autogenerated - if it was autogenerated we would get id other
|
|
|
+ // than id1 because id1 has already been used.
|
|
|
+ subnet.reset(new Subnet6(IOAddress("2001:db8:3::"), 64, 1000, 2000,
|
|
|
+ 3000, 4000, id1));
|
|
|
+ EXPECT_EQ(id1, subnet->getID());
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Subnet6Test, inRange) {
|
|
|
Subnet6 subnet(IOAddress("2001:db8:1::"), 64, 1000, 2000, 3000, 4000);
|
|
|
|
|
|
EXPECT_EQ(1000, subnet.getT1());
|