Commit 76072004 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[1283] Remove toText() calls where IOAddress should be used directly

parent df980e49
......@@ -265,7 +265,7 @@ protected:
Triplet<uint32_t> valid = getParam("valid-lifetime");
stringstream tmp;
tmp << addr.toText() << "/" << (int)len
tmp << addr << "/" << (int)len
<< " with params t1=" << t1 << ", t2=" << t2 << ", valid=" << valid;
LOG_INFO(dhcp4_logger, DHCP4_CONFIG_NEW_SUBNET).arg(tmp.str());
......
......@@ -456,7 +456,7 @@ TEST_F(Dhcpv4SrvTest, DiscoverHint) {
// lifetime is correct, that T1 and T2 are returned properly
checkAddressParams(offer, subnet_);
EXPECT_EQ(offer->getYiaddr().toText(), hint.toText());
EXPECT_EQ(offer->getYiaddr(), hint);
// Check identifiers
checkServerId(offer, srv->getServerID());
......@@ -495,7 +495,7 @@ TEST_F(Dhcpv4SrvTest, DiscoverNoClientId) {
// lifetime is correct, that T1 and T2 are returned properly
checkAddressParams(offer, subnet_);
EXPECT_EQ(offer->getYiaddr().toText(), hint.toText());
EXPECT_EQ(offer->getYiaddr(), hint);
// Check identifiers
checkServerId(offer, srv->getServerID());
......@@ -534,7 +534,7 @@ TEST_F(Dhcpv4SrvTest, DiscoverInvalidHint) {
// lifetime is correct, that T1 and T2 are returned properly
checkAddressParams(offer, subnet_);
EXPECT_NE(offer->getYiaddr().toText(), hint.toText());
EXPECT_NE(offer->getYiaddr(), hint);
// Check identifiers
checkServerId(offer, srv->getServerID());
......@@ -600,12 +600,12 @@ TEST_F(Dhcpv4SrvTest, ManyDiscovers) {
checkClientId(offer3, clientid3);
// Finally check that the addresses offered are different
EXPECT_NE(addr1.toText(), addr2.toText());
EXPECT_NE(addr2.toText(), addr3.toText());
EXPECT_NE(addr3.toText(), addr1.toText());
cout << "Offered address to client1=" << addr1.toText() << endl;
cout << "Offered address to client2=" << addr2.toText() << endl;
cout << "Offered address to client3=" << addr3.toText() << endl;
EXPECT_NE(addr1, addr2);
EXPECT_NE(addr2, addr3);
EXPECT_NE(addr3, addr1);
cout << "Offered address to client1=" << addr1 << endl;
cout << "Offered address to client2=" << addr2 << endl;
cout << "Offered address to client3=" << addr3 << endl;
}
// Checks whether echoing back client-id is controllable, i.e.
......@@ -665,7 +665,7 @@ TEST_F(Dhcpv4SrvTest, RequestBasic) {
// Check if we get response at all
checkResponse(ack, DHCPACK, 1234);
EXPECT_EQ(hint.toText(), ack->getYiaddr().toText());
EXPECT_EQ(hint, ack->getYiaddr());
// Check that address was returned from proper range, that its lease
// lifetime is correct, that T1 and T2 are returned properly
......@@ -744,9 +744,9 @@ TEST_F(Dhcpv4SrvTest, ManyRequests) {
IOAddress addr3 = ack3->getYiaddr();
// Check that every client received the address it requested
EXPECT_EQ(req_addr1.toText(), addr1.toText());
EXPECT_EQ(req_addr2.toText(), addr2.toText());
EXPECT_EQ(req_addr3.toText(), addr3.toText());
EXPECT_EQ(req_addr1, addr1);
EXPECT_EQ(req_addr2, addr2);
EXPECT_EQ(req_addr3, addr3);
// Check that the assigned address is indeed from the configured pool
checkAddressParams(ack1, subnet_);
......@@ -768,12 +768,12 @@ TEST_F(Dhcpv4SrvTest, ManyRequests) {
l = checkLease(ack3, clientid3, req3->getHWAddr(), addr3);
// Finally check that the addresses offered are different
EXPECT_NE(addr1.toText(), addr2.toText());
EXPECT_NE(addr2.toText(), addr3.toText());
EXPECT_NE(addr3.toText(), addr1.toText());
cout << "Offered address to client1=" << addr1.toText() << endl;
cout << "Offered address to client2=" << addr2.toText() << endl;
cout << "Offered address to client3=" << addr3.toText() << endl;
EXPECT_NE(addr1, addr2);
EXPECT_NE(addr2, addr3);
EXPECT_NE(addr3, addr1);
cout << "Offered address to client1=" << addr1 << endl;
cout << "Offered address to client2=" << addr2 << endl;
cout << "Offered address to client3=" << addr3 << endl;
}
// Checks whether echoing back client-id is controllable
......@@ -859,7 +859,7 @@ TEST_F(Dhcpv4SrvTest, RenewBasic) {
// Check if we get response at all
checkResponse(ack, DHCPACK, 1234);
EXPECT_EQ(addr.toText(), ack->getYiaddr().toText());
EXPECT_EQ(addr, ack->getYiaddr());
// Check that address was returned from proper range, that its lease
// lifetime is correct, that T1 and T2 are returned properly
......
......@@ -136,7 +136,7 @@ void Dhcpv4SrvTest::messageCheck(const Pkt4Ptr& q, const Pkt4Ptr& a) {
EXPECT_TRUE(a->getOption(DHO_DHCP_SERVER_IDENTIFIER));
// Check that something is offered
EXPECT_TRUE(a->getYiaddr().toText() != "0.0.0.0");
EXPECT_NE("0.0.0.0", a->getYiaddr().toText());
}
::testing::AssertionResult
......@@ -309,14 +309,14 @@ Lease4Ptr Dhcpv4SrvTest::checkLease(const Pkt4Ptr& rsp,
Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(expected_addr);
if (!lease) {
cout << "Lease for " << expected_addr.toText()
cout << "Lease for " << expected_addr
<< " not found in the database backend.";
return (Lease4Ptr());
}
EXPECT_EQ(rsp->getYiaddr().toText(), expected_addr.toText());
EXPECT_EQ(rsp->getYiaddr(), expected_addr);
EXPECT_EQ(expected_addr.toText(), lease->addr_.toText());
EXPECT_EQ(expected_addr, lease->addr_);
if (client_id) {
EXPECT_TRUE(*lease->client_id_ == *id);
}
......
......@@ -497,12 +497,12 @@ protected:
"parser error: interface (defined for locally reachable "
"subnets) and interface-id (defined for subnets reachable"
" via relays) cannot be defined at the same time for "
"subnet " << addr.toText() << "/" << (int)len);
"subnet " << addr << "/" << (int)len);
}
}
stringstream tmp;
tmp << addr.toText() << "/" << static_cast<int>(len)
tmp << addr << "/" << static_cast<int>(len)
<< " with params t1=" << t1 << ", t2=" << t2 << ", pref="
<< pref << ", valid=" << valid;
......
......@@ -1193,7 +1193,7 @@ Dhcpv6Srv::createRemovalNameChangeRequest(const Lease6Ptr& lease) {
if (!lease->duid_) {
isc_throw(isc::Unexpected, "DUID must be set when creating"
<< " NameChangeRequest for DNS records removal for "
<< lease->addr_.toText());
<< lease->addr_);
}
isc::dhcp_ddns::D2Dhcid dhcid(*lease->duid_, hostname_wire);
......
......@@ -783,8 +783,7 @@ TEST_F(Dhcp6ParserTest, pdPoolBasics) {
// verify that it was interpreted correctly by checking the last address
// value.
isc::asiolink::IOAddress prefixAddress("2001:db8:1::");
EXPECT_EQ(lastAddrInPrefix(prefixAddress, 64).toText(),
p6->getLastAddress().toText());
EXPECT_EQ(lastAddrInPrefix(prefixAddress, 64), p6->getLastAddress());
}
// Goal of this test is verify that a list of PD pools can be configured.
......@@ -917,8 +916,7 @@ TEST_F(Dhcp6ParserTest, subnetAndPrefixDelegated) {
// verify that it was interpreted correctly by checking the last address
// value.
isc::asiolink::IOAddress prefixAddress("2001:db8:1::");
EXPECT_EQ(lastAddrInPrefix(prefixAddress, 64).toText(),
p6->getLastAddress().toText());
EXPECT_EQ(lastAddrInPrefix(prefixAddress, 64), p6->getLastAddress());
}
......
......@@ -642,12 +642,12 @@ TEST_F(Dhcpv6SrvTest, ManySolicits) {
checkClientId(reply3, clientid3);
// Finally check that the addresses offered are different
EXPECT_NE(addr1->getAddress().toText(), addr2->getAddress().toText());
EXPECT_NE(addr2->getAddress().toText(), addr3->getAddress().toText());
EXPECT_NE(addr3->getAddress().toText(), addr1->getAddress().toText());
cout << "Offered address to client1=" << addr1->getAddress().toText() << endl;
cout << "Offered address to client2=" << addr2->getAddress().toText() << endl;
cout << "Offered address to client3=" << addr3->getAddress().toText() << endl;
EXPECT_NE(addr1->getAddress(), addr2->getAddress());
EXPECT_NE(addr2->getAddress(), addr3->getAddress());
EXPECT_NE(addr3->getAddress(), addr1->getAddress());
cout << "Offered address to client1=" << addr1->getAddress() << endl;
cout << "Offered address to client2=" << addr2->getAddress() << endl;
cout << "Offered address to client3=" << addr3->getAddress() << endl;
}
// This test verifies that incoming REQUEST can be handled properly, that a
......@@ -852,12 +852,12 @@ TEST_F(Dhcpv6SrvTest, ManyRequests) {
checkClientId(reply3, clientid3);
// Finally check that the addresses offered are different
EXPECT_NE(addr1->getAddress().toText(), addr2->getAddress().toText());
EXPECT_NE(addr2->getAddress().toText(), addr3->getAddress().toText());
EXPECT_NE(addr3->getAddress().toText(), addr1->getAddress().toText());
cout << "Assigned address to client1=" << addr1->getAddress().toText() << endl;
cout << "Assigned address to client2=" << addr2->getAddress().toText() << endl;
cout << "Assigned address to client3=" << addr3->getAddress().toText() << endl;
EXPECT_NE(addr1->getAddress(), addr2->getAddress());
EXPECT_NE(addr2->getAddress(), addr3->getAddress());
EXPECT_NE(addr3->getAddress(), addr1->getAddress());
cout << "Assigned address to client1=" << addr1->getAddress() << endl;
cout << "Assigned address to client2=" << addr2->getAddress() << endl;
cout << "Assigned address to client3=" << addr3->getAddress() << endl;
}
// This test verifies that incoming (positive) RENEW can be handled properly, that a
......
......@@ -80,12 +80,12 @@ Dhcpv6SrvTest::checkLease(const DuidPtr& duid, const OptionPtr& ia_na,
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
addr->getAddress());
if (!lease) {
std::cout << "Lease for " << addr->getAddress().toText()
std::cout << "Lease for " << addr->getAddress()
<< " not found in the database backend.";
return (Lease6Ptr());
}
EXPECT_EQ(addr->getAddress().toText(), lease->addr_.toText());
EXPECT_EQ(addr->getAddress(), lease->addr_);
EXPECT_TRUE(*lease->duid_ == *duid);
EXPECT_EQ(ia->getIAID(), lease->iaid_);
EXPECT_EQ(subnet_->getID(), lease->subnet_id_);
......@@ -101,12 +101,12 @@ Dhcpv6SrvTest::checkPdLease(const DuidPtr& duid, const OptionPtr& ia_pd,
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD,
prefix->getAddress());
if (!lease) {
std::cout << "PD lease for " << prefix->getAddress().toText()
std::cout << "PD lease for " << prefix->getAddress()
<< " not found in the database backend.";
return (Lease6Ptr());
}
EXPECT_EQ(prefix->getAddress().toText(), lease->addr_.toText());
EXPECT_EQ(prefix->getAddress(), lease->addr_);
EXPECT_TRUE(*lease->duid_ == *duid);
EXPECT_EQ(ia->getIAID(), lease->iaid_);
EXPECT_EQ(subnet_->getID(), lease->subnet_id_);
......
......@@ -64,12 +64,12 @@ IOEndpoint::operator!=(const IOEndpoint& other) const {
ostream&
operator<<(ostream& os, const IOEndpoint& endpoint) {
if (endpoint.getFamily() == AF_INET6) {
os << "[" << endpoint.getAddress().toText() << "]";
os << "[" << endpoint.getAddress() << "]";
} else {
// In practice this should be AF_INET, but it's not guaranteed by
// the interface. We'll use the result of textual address
// representation opaquely.
os << endpoint.getAddress().toText();
os << endpoint.getAddress();
}
os << ":" << boost::lexical_cast<string>(endpoint.getPort());
return (os);
......
......@@ -84,7 +84,7 @@ TEST(IOAddressTest, fromBytes) {
EXPECT_NO_THROW({
addr = IOAddress::fromBytes(AF_INET, v4);
});
EXPECT_EQ(addr.toText(), IOAddress("192.0.2.3").toText());
EXPECT_EQ(addr, IOAddress("192.0.2.3"));
}
TEST(IOAddressTest, toBytesV4) {
......
......@@ -190,7 +190,7 @@ void Iface::addUnicast(const isc::asiolink::IOAddress& addr) {
for (Iface::AddressCollection::const_iterator i = unicasts_.begin();
i != unicasts_.end(); ++i) {
if (*i == addr) {
isc_throw(BadValue, "Address " << addr.toText()
isc_throw(BadValue, "Address " << addr
<< " already defined on the " << name_ << " interface.");
}
}
......@@ -569,7 +569,7 @@ int IfaceMgr::openSocket(const std::string& ifname, const IOAddress& addr,
} else {
isc_throw(BadValue, "Failed to detect family of address: "
<< addr.toText());
<< addr);
}
}
......@@ -644,7 +644,7 @@ int IfaceMgr::openSocketFromAddress(const IOAddress& addr,
}
// If we got here it means that we did not find specified address
// on any available interface.
isc_throw(BadValue, "There is no such address " << addr.toText());
isc_throw(BadValue, "There is no such address " << addr);
}
int IfaceMgr::openSocketFromRemoteAddress(const IOAddress& remote_addr,
......@@ -751,7 +751,8 @@ int IfaceMgr::openSocket6(Iface& iface, const IOAddress& addr, uint16_t port) {
if (bind(sock, (struct sockaddr *)&addr6, sizeof(addr6)) < 0) {
close(sock);
isc_throw(SocketConfigError, "Failed to bind socket " << sock << " to " << addr.toText()
isc_throw(SocketConfigError, "Failed to bind socket " << sock
<< " to " << addr
<< "/port=" << port);
}
#ifdef IPV6_RECVPKTINFO
......
......@@ -37,7 +37,7 @@ Option6IAAddr::Option6IAAddr(uint16_t type, const isc::asiolink::IOAddress& addr
valid_(valid) {
setEncapsulatedSpace("dhcp6");
if (!addr.isV6()) {
isc_throw(isc::BadValue, addr_.toText() << " is not an IPv6 address");
isc_throw(isc::BadValue, addr_ << " is not an IPv6 address");
}
}
......@@ -57,8 +57,7 @@ void Option6IAAddr::pack(isc::util::OutputBuffer& buf) {
buf.writeUint16(len() - getHeaderLen());
if (!addr_.isV6()) {
isc_throw(isc::BadValue, addr_.toText()
<< " is not an IPv6 address");
isc_throw(isc::BadValue, addr_ << " is not an IPv6 address");
}
buf.writeData(&addr_.toBytes()[0], isc::asiolink::V6ADDRESS_LEN);
......@@ -93,7 +92,7 @@ std::string Option6IAAddr::toText(int indent /* =0 */) {
for (int i=0; i<indent; i++)
tmp << " ";
tmp << "type=" << type_ << "(IAADDR) addr=" << addr_.toText()
tmp << "type=" << type_ << "(IAADDR) addr=" << addr_
<< ", preferred-lft=" << preferred_ << ", valid-lft="
<< valid_ << endl;
......
......@@ -51,7 +51,7 @@ Option6IAPrefix::Option6IAPrefix(uint32_t type, OptionBuffer::const_iterator beg
void Option6IAPrefix::pack(isc::util::OutputBuffer& buf) {
if (!addr_.isV6()) {
isc_throw(isc::BadValue, addr_.toText() << " is not an IPv6 address");
isc_throw(isc::BadValue, addr_ << " is not an IPv6 address");
}
buf.writeUint16(type_);
......
......@@ -54,7 +54,7 @@ OptionCustom::addArrayDataField(const asiolink::IOAddress& address) {
if ((address.isV4() && definition_.getType() != OPT_IPV4_ADDRESS_TYPE) ||
(address.isV6() && definition_.getType() != OPT_IPV6_ADDRESS_TYPE)) {
isc_throw(BadDataTypeCast, "invalid address specified "
<< address.toText() << ". Expected a valid IPv"
<< address << ". Expected a valid IPv"
<< (definition_.getType() == OPT_IPV4_ADDRESS_TYPE ?
"4" : "6") << " address.");
}
......@@ -375,7 +375,7 @@ OptionCustom::dataFieldToText(const OptionDataType data_type,
break;
case OPT_IPV4_ADDRESS_TYPE:
case OPT_IPV6_ADDRESS_TYPE:
text << readAddress(index).toText();
text << readAddress(index);
break;
case OPT_FQDN_TYPE:
text << readFqdn(index);
......@@ -443,7 +443,7 @@ OptionCustom::writeAddress(const asiolink::IOAddress& address,
if ((address.isV4() && buffers_[index].size() != V4ADDRESS_LEN) ||
(address.isV6() && buffers_[index].size() != V6ADDRESS_LEN)) {
isc_throw(BadDataTypeCast, "invalid address specified "
<< address.toText() << ". Expected a valid IPv"
<< address << ". Expected a valid IPv"
<< (buffers_[index].size() == V4ADDRESS_LEN ? "4" : "6")
<< " address.");
}
......
......@@ -497,7 +497,7 @@ OptionDefinition::writeToBuffer(const std::string& value,
asiolink::IOAddress address(value);
if (!address.isV4() && !address.isV6()) {
isc_throw(BadDataTypeCast, "provided address "
<< address.toText()
<< address
<< " is not a valid IPv4 or IPv6 address.");
}
OptionDataTypeUtil::writeAddress(address, buf);
......
......@@ -278,8 +278,8 @@ void Pkt4::repack() {
std::string
Pkt4::toText() {
stringstream tmp;
tmp << "localAddr=" << local_addr_.toText() << ":" << local_port_
<< " remoteAddr=" << remote_addr_.toText()
tmp << "localAddr=" << local_addr_ << ":" << local_port_
<< " remoteAddr=" << remote_addr_
<< ":" << remote_port_ << ", msgtype=" << static_cast<int>(getType())
<< ", transid=0x" << hex << transid_ << dec << endl;
......
......@@ -453,8 +453,8 @@ Pkt6::unpackTCP() {
std::string
Pkt6::toText() {
stringstream tmp;
tmp << "localAddr=[" << local_addr_.toText() << "]:" << local_port_
<< " remoteAddr=[" << remote_addr_.toText()
tmp << "localAddr=[" << local_addr_ << "]:" << local_port_
<< " remoteAddr=[" << remote_addr_
<< "]:" << remote_port_ << endl;
tmp << "msgtype=" << static_cast<int>(msg_type_) << ", transid=0x" <<
hex << transid_ << dec << endl;
......
......@@ -29,7 +29,7 @@ PktFilter::openFallbackSocket(const isc::asiolink::IOAddress& addr,
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
isc_throw(SocketConfigError, "failed to create fallback socket for"
" address " << addr.toText() << ", port " << port
" address " << addr << ", port " << port
<< ", reason: " << strerror(errno));
}
// Bind the socket to a specified address and port.
......@@ -44,7 +44,7 @@ PktFilter::openFallbackSocket(const isc::asiolink::IOAddress& addr,
// Remember to close the socket if we failed to bind it.
close(sock);
isc_throw(SocketConfigError, "failed to bind fallback socket to"
" address " << addr.toText() << ", port " << port
" address " << addr << ", port " << port
<< ", reason: " << strerror(errno)
<< " - is another DHCP server running?");
}
......@@ -54,7 +54,7 @@ PktFilter::openFallbackSocket(const isc::asiolink::IOAddress& addr,
if (fcntl(sock, F_SETFL, O_NONBLOCK) != 0) {
close(sock);
isc_throw(SocketConfigError, "failed to set SO_NONBLOCK option on the"
" fallback socket, bound to " << addr.toText() << ", port "
" fallback socket, bound to " << addr << ", port "
<< port << ", reason: " << strerror(errno));
}
// Successfully created and bound a fallback socket. Return a descriptor.
......
......@@ -79,7 +79,8 @@ PktFilterInet::openSocket(const Iface& iface,
if (bind(sock, (struct sockaddr *)&addr4, sizeof(addr4)) < 0) {
close(sock);
isc_throw(SocketConfigError, "Failed to bind socket " << sock << " to " << addr.toText()
isc_throw(SocketConfigError, "Failed to bind socket " << sock
<< " to " << addr
<< "/port=" << port);
}
......
......@@ -346,10 +346,10 @@ TEST_F(IfaceMgrTest, dhcp6Sniffer) {
cout << " pkt = new Pkt6(" << pkt->data_len_ << ");" << endl;
cout << " pkt->remote_port_ = " << pkt-> remote_port_ << ";" << endl;
cout << " pkt->remote_addr_ = IOAddress(\""
<< pkt->remote_addr_.toText() << "\");" << endl;
<< pkt->remote_addr_ << "\");" << endl;
cout << " pkt->local_port_ = " << pkt-> local_port_ << ";" << endl;
cout << " pkt->local_addr_ = IOAddress(\""
<< pkt->local_addr_.toText() << "\");" << endl;
<< pkt->local_addr_ << "\");" << endl;
cout << " pkt->ifindex_ = " << pkt->ifindex_ << ";" << endl;
cout << " pkt->iface_ = \"" << pkt->iface_ << "\";" << endl;
......@@ -914,7 +914,7 @@ TEST_F(IfaceMgrTest, sendReceive6) {
EXPECT_EQ(0, memcmp(&sendPkt->data_[0], &rcvPkt->data_[0],
rcvPkt->data_.size()));
EXPECT_EQ(sendPkt->getRemoteAddr().toText(), rcvPkt->getRemoteAddr().toText());
EXPECT_EQ(sendPkt->getRemoteAddr(), rcvPkt->getRemoteAddr());
// since we opened 2 sockets on the same interface and none of them is multicast,
// none is preferred over the other for sending data, so we really should not
......
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