BIND 10 trac878, updated. 21bac503aa78b1d0cbb6993edc083fbc508dad16 [878] Added test for joinMcast() and other improvements in IfaceMgr tests
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Aug 18 17:36:54 UTC 2011
The branch, trac878 has been updated
via 21bac503aa78b1d0cbb6993edc083fbc508dad16 (commit)
from ee826c177bef06f22cdbbf82044085972bfd8737 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 21bac503aa78b1d0cbb6993edc083fbc508dad16
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Thu Aug 18 19:36:31 2011 +0200
[878] Added test for joinMcast() and other improvements in IfaceMgr tests
-----------------------------------------------------------------------
Summary of changes:
src/bin/dhcp6/iface_mgr.cc | 13 +++----
src/bin/dhcp6/iface_mgr.h | 2 +-
src/bin/dhcp6/tests/iface_mgr_unittest.cc | 51 +++++++++++++++++++++++++----
3 files changed, 51 insertions(+), 15 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/dhcp6/iface_mgr.cc b/src/bin/dhcp6/iface_mgr.cc
index da50ba4..45cafe2 100644
--- a/src/bin/dhcp6/iface_mgr.cc
+++ b/src/bin/dhcp6/iface_mgr.cc
@@ -162,7 +162,7 @@ IfaceMgr::openSockets() {
++addr) {
sock = openSocket(iface->name_, *addr,
- DHCP6_SERVER_PORT, false);
+ DHCP6_SERVER_PORT);
if (sock<0) {
cout << "Failed to open unicast socket." << endl;
return (false);
@@ -171,7 +171,7 @@ IfaceMgr::openSockets() {
sock = openSocket(iface->name_,
IOAddress(ALL_DHCP_RELAY_AGENTS_AND_SERVERS),
- DHCP6_SERVER_PORT, true);
+ DHCP6_SERVER_PORT);
if (sock<0) {
cout << "Failed to open multicast socket." << endl;
close(sendsock_);
@@ -239,8 +239,7 @@ IfaceMgr::getIface(const std::string& ifname) {
int
IfaceMgr::openSocket(const std::string& ifname,
const IOAddress& addr,
- int port,
- bool mcast) {
+ int port) {
struct sockaddr_storage name;
int name_len;
struct sockaddr_in6 *addr6;
@@ -309,10 +308,10 @@ IfaceMgr::openSocket(const std::string& ifname,
// multicast stuff
- if (mcast /*addr.multicast()*/) {
+ if (addr.getAddress().to_v6().is_multicast()) {
// both mcast (ALL_DHCP_RELAY_AGENTS_AND_SERVERS and ALL_DHCP_SERVERS)
- // are link and site-scoped, so there is no sense to join those them
- // with global addressed.
+ // are link and site-scoped, so there is no sense to join those groups
+ // with global addresses.
if ( !joinMcast( sock, ifname,
string(ALL_DHCP_RELAY_AGENTS_AND_SERVERS) ) ) {
diff --git a/src/bin/dhcp6/iface_mgr.h b/src/bin/dhcp6/iface_mgr.h
index c251fdc..39061da 100644
--- a/src/bin/dhcp6/iface_mgr.h
+++ b/src/bin/dhcp6/iface_mgr.h
@@ -72,7 +72,7 @@ namespace isc {
int openSocket(const std::string& ifname,
const isc::asiolink::IOAddress& addr,
- int port, bool multicast);
+ int port);
// TODO: having 2 maps (ifindex->iface and ifname->iface would)
// probably be better for performance reasons
diff --git a/src/bin/dhcp6/tests/iface_mgr_unittest.cc b/src/bin/dhcp6/tests/iface_mgr_unittest.cc
index 0f7f431..483ac1d 100644
--- a/src/bin/dhcp6/tests/iface_mgr_unittest.cc
+++ b/src/bin/dhcp6/tests/iface_mgr_unittest.cc
@@ -39,8 +39,8 @@ public:
int openSocket(const std::string& ifname,
const isc::asiolink::IOAddress& addr,
- int port, bool multicast) {
- return IfaceMgr::openSocket(ifname, addr, port, multicast);
+ int port) {
+ return IfaceMgr::openSocket(ifname, addr, port);
}
};
@@ -70,6 +70,8 @@ TEST_F(IfaceMgrTest, ifaceClass) {
}
+// TODO: Implement getPlainMac() test as soon as interface detection is implemented.
+
TEST_F(IfaceMgrTest, getIface) {
cout << "Interface checks. Please ignore socket binding errors." << endl;
@@ -146,14 +148,49 @@ TEST_F(IfaceMgrTest, sockets) {
IOAddress loAddr("::1");
// bind multicast socket to port 10547
- int socket1 = ifacemgr->openSocket("lo", loAddr, 10547, true);
+ int socket1 = ifacemgr->openSocket("lo", loAddr, 10547);
EXPECT_GT(socket1, 0); // socket > 0
// bind unicast socket to port 10548
- int socket2 = ifacemgr->openSocket("lo", loAddr, 10548, false);
+ int socket2 = ifacemgr->openSocket("lo", loAddr, 10548);
+ EXPECT_GT(socket2, 0);
+
+ // expect success. This address/port is already bound, but
+ // we are using SO_REUSEADDR, so we can bind it twice
+ int socket3 = ifacemgr->openSocket("lo", loAddr, 10547);
+ EXPECT_GT(socket3, 0); // socket > 0
+
+ // we now have 3 sockets open at the same time. Looks good.
+
+ close(socket1);
+ close(socket2);
+ close(socket3);
+
+ delete ifacemgr;
+}
+
+TEST_F(IfaceMgrTest, socketsMcast) {
+ // testing socket operation in a portable way is tricky
+ // without interface detection implemented
+
+ NakedIfaceMgr * ifacemgr = new NakedIfaceMgr();
+
+ IOAddress loAddr("::1");
+ IOAddress mcastAddr("ff02::1:2");
+
+ // bind multicast socket to port 10547
+ int socket1 = ifacemgr->openSocket("lo", mcastAddr, 10547);
+ EXPECT_GT(socket1, 0); // socket > 0
+
+ // expect success. This address/port is already bound, but
+ // we are using SO_REUSEADDR, so we can bind it twice
+ int socket2 = ifacemgr->openSocket("lo", mcastAddr, 10547);
EXPECT_GT(socket2, 0);
- // good to check that both sockets can be opened at once
+ // there's no good way to test negative case here.
+ // we would need non-multicast interface. We will be able
+ // to iterate thru available interfaces and check if there
+ // are interfaces without multicast-capable flag.
close(socket1);
close(socket2);
@@ -173,8 +210,8 @@ TEST_F(IfaceMgrTest, sendReceive) {
// let's assume that every supported OS have lo interface
IOAddress loAddr("::1");
- int socket1 = ifacemgr->openSocket("lo", loAddr, 10547, true);
- int socket2 = ifacemgr->openSocket("lo", loAddr, 10546, false);
+ int socket1 = ifacemgr->openSocket("lo", loAddr, 10547);
+ int socket2 = ifacemgr->openSocket("lo", loAddr, 10546);
ifacemgr->setSendSock(socket2);
ifacemgr->setRecvSock(socket1);
More information about the bind10-changes
mailing list