++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);
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_);
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;
// 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) ) ) {
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);
}
};
}
+// TODO: Implement getPlainMac() test as soon as interface detection is implemented.
+
TEST_F(IfaceMgrTest, getIface) {
cout << "Interface checks. Please ignore socket binding errors." << endl;
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);
// 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);