You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2017/07/05 19:27:15 UTC

[1/3] mesos git commit: Moved `net::IPNetwork` to `net::IP:Network`.

Repository: mesos
Updated Branches:
  refs/heads/master 013f7e21a -> 9b69c0931


Moved `net::IPNetwork` to `net::IP:Network`.

Review: https://reviews.apache.org/r/59688/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/36b97ed7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/36b97ed7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/36b97ed7

Branch: refs/heads/master
Commit: 36b97ed73dce0b43ef8639d90132c2752669dc25
Parents: 013f7e2
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Wed Jul 5 11:34:12 2017 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Jul 5 11:34:12 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/ip.hpp | 209 +++++++++++++++++--------------
 3rdparty/stout/tests/ip_tests.cpp   | 107 +++++++++-------
 2 files changed, 175 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/36b97ed7/3rdparty/stout/include/stout/ip.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/ip.hpp b/3rdparty/stout/include/stout/ip.hpp
index ee48bef..16576ec 100644
--- a/3rdparty/stout/include/stout/ip.hpp
+++ b/3rdparty/stout/include/stout/ip.hpp
@@ -68,7 +68,6 @@
 #include <stout/windows.hpp>
 #endif // __WINDOWS__
 
-
 namespace net {
 
 // Represents an IP.
@@ -200,6 +199,109 @@ public:
     }
   }
 
+  // Represents an IP network. We store the IP address and the IP
+  // netmask which defines the subnet.
+  class Network
+  {
+  public:
+    // Returns the IPv4 network for loopback (i.e., 127.0.0.1/8).
+    //
+    // TODO(asridharan): We need to move this functionality to an
+    // `net::inet::IP::Network` class in the future.
+    static Network LOOPBACK_V4();
+
+    // Returns the IPv6 network for loopback (i.e. ::1/128)
+    //
+    // TODO(asridharan): We need to move this functionality to an
+    // `net::inet6::IP::Network` class in the future.
+    static Network LOOPBACK_V6();
+
+    // Creates an IP network from the given string that has the
+    // IP address in canonical format with subnet prefix.
+    // For example:
+    //   10.0.0.1/8
+    //   192.168.1.100/24
+    //   fe80::3/64
+    static Try<Network> parse(
+        const std::string& value,
+        int family = AF_UNSPEC);
+
+    // Creates an IP network from the given IP address and netmask.
+    // Returns error if the netmask is not valid (e.g., not contiguous).
+    static Try<Network> create(const IP& address, const IP& netmask);
+
+    // Creates an IP network from an IP address and a subnet prefix.
+    // Returns error if the prefix is not valid.
+    static Try<Network> create(const IP& address, int prefix);
+
+    // Returns the first available IP network of a given link device.
+    // The link device is specified using its name (e.g., eth0). Returns
+    // error if the link device is not found. Returns none if the link
+    // device is found, but does not have an IP network.
+    // TODO(jieyu): It is uncommon, but likely that a link device has
+    // multiple IP networks. In that case, consider returning the
+    // primary IP network instead of the first one.
+    static Result<Network> fromLinkDevice(const std::string& name, int family);
+
+    // Need to add a copy constructor due to the presence of
+    // `unique_ptr`.
+    Network(const Network& network)
+      :address_(new IP(network.address())),
+      netmask_(new IP(network.netmask())) {};
+
+    IP address() const { return *address_; }
+
+    IP netmask() const { return *netmask_; }
+
+    // Returns the prefix of the subnet defined by the IP netmask.
+    int prefix() const
+    {
+      switch (netmask_->family()) {
+        case AF_INET: {
+          return bits::countSetBits(netmask_->in()->s_addr);
+        }
+        case AF_INET6: {
+          struct in6_addr in6 = netmask_->in6().get();
+
+          int prefix = std::accumulate(
+              std::begin(in6.s6_addr),
+              std::end(in6.s6_addr),
+              0,
+              [](int acc, uint8_t c) {
+                return acc + bits::countSetBits(c);
+              });
+
+          return prefix;
+        }
+        default:
+          UNREACHABLE();
+      }
+    }
+
+    bool operator==(const Network& that) const
+    {
+      return *(address_) == *(that.address_) &&
+        *(netmask_) == *(that.netmask_);
+    }
+
+    bool operator!=(const Network& that) const
+    {
+      return !(*this == that);
+    }
+
+  private:
+    Network(const IP& _address, const IP& _netmask)
+      : address_(new IP(_address)), netmask_(new IP(_netmask)) {}
+
+    // NOTE: The reason we need to store `std::unique_ptr` and not
+    // `net::IP` here is that since this class has a nested definition
+    // within `net::IP` `net::IP` is an incomplete type at this point.
+    // We therefore cannot store an object and can only store pointers
+    // for this incomplete type.
+    std::unique_ptr<IP> address_;
+    std::unique_ptr<IP> netmask_;
+  };
+
 private:
   // NOTE: We need to clear the union when creating an IP because the
   // equality check uses memcmp.
@@ -334,90 +436,7 @@ inline std::ostream& operator<<(std::ostream& stream, const IP& ip)
 }
 
 
-// Represents an IP network. We store the IP address and the IP
-// netmask which defines the subnet.
-class IPNetwork
-{
-public:
-  // Returns the IPv4 network for loopback (i.e., 127.0.0.1/8).
-  static IPNetwork LOOPBACK_V4();
-
-  // Returns the IPv6 network for loopback (i.e. ::1/128)
-  static IPNetwork LOOPBACK_V6();
-
-  // Creates an IP network from the given string that has the
-  // IP address in canonical format with subnet prefix.
-  // For example:
-  //   10.0.0.1/8
-  //   192.168.1.100/24
-  //   fe80::3/64
-  static Try<IPNetwork> parse(const std::string& value, int family = AF_UNSPEC);
-
-  // Creates an IP network from the given IP address and netmask.
-  // Returns error if the netmask is not valid (e.g., not contiguous).
-  static Try<IPNetwork> create(const IP& address, const IP& netmask);
-
-  // Creates an IP network from an IP address and a subnet prefix.
-  // Returns error if the prefix is not valid.
-  static Try<IPNetwork> create(const IP& address, int prefix);
-
-  // Returns the first available IP network of a given link device.
-  // The link device is specified using its name (e.g., eth0). Returns
-  // error if the link device is not found. Returns none if the link
-  // device is found, but does not have an IP network.
-  // TODO(jieyu): It is uncommon, but likely that a link device has
-  // multiple IP networks. In that case, consider returning the
-  // primary IP network instead of the first one.
-  static Result<IPNetwork> fromLinkDevice(const std::string& name, int family);
-
-  IP address() const { return address_; }
-
-  IP netmask() const { return netmask_; }
-
-  // Returns the prefix of the subnet defined by the IP netmask.
-  int prefix() const
-  {
-    switch (netmask_.family()) {
-      case AF_INET: {
-        return bits::countSetBits(netmask_.in().get().s_addr);
-      }
-      case AF_INET6: {
-        struct in6_addr in6 = netmask_.in6().get();
-
-        int prefix = std::accumulate(
-          std::begin(in6.s6_addr),
-          std::end(in6.s6_addr),
-          0,
-          [](int acc, uint8_t c) { return acc + bits::countSetBits(c); });
-
-        return prefix;
-      }
-      default: {
-        UNREACHABLE();
-      }
-    }
-  }
-
-  bool operator==(const IPNetwork& that) const
-  {
-    return address_ == that.address_ && netmask_ == that.netmask_;
-  }
-
-  bool operator!=(const IPNetwork& that) const
-  {
-    return !(*this == that);
-  }
-
-private:
-  IPNetwork(const IP& _address, const IP& _netmask)
-    : address_(_address), netmask_(_netmask) {}
-
-  IP address_;
-  IP netmask_;
-};
-
-
-inline Try<IPNetwork> IPNetwork::parse(const std::string& value, int family)
+inline Try<IP::Network> IP::Network::parse(const std::string& value, int family)
 {
   std::vector<std::string> tokens = strings::split(value, "/");
 
@@ -443,19 +462,21 @@ inline Try<IPNetwork> IPNetwork::parse(const std::string& value, int family)
 }
 
 
-inline IPNetwork IPNetwork::LOOPBACK_V4()
+inline IP::Network IP::Network::LOOPBACK_V4()
 {
   return parse("127.0.0.1/8", AF_INET).get();
 }
 
 
-inline IPNetwork IPNetwork::LOOPBACK_V6()
+inline IP::Network IP::Network::LOOPBACK_V6()
 {
   return parse("::1/128", AF_INET6).get();
 }
 
 
-inline Try<IPNetwork> IPNetwork::create(const IP& address, const IP& netmask)
+inline Try<IP::Network> IP::Network::create(
+    const IP& address,
+    const IP& netmask)
 {
   if (address.family() != netmask.family()) {
     return Error(
@@ -496,11 +517,11 @@ inline Try<IPNetwork> IPNetwork::create(const IP& address, const IP& netmask)
     }
   }
 
-  return IPNetwork(address, netmask);
+  return IP::Network(address, netmask);
 }
 
 
-inline Try<IPNetwork> IPNetwork::create(const IP& address, int prefix)
+inline Try<IP::Network> IP::Network::create(const IP& address, int prefix)
 {
   if (prefix < 0) {
     return Error("Subnet prefix is negative");
@@ -518,7 +539,7 @@ inline Try<IPNetwork> IPNetwork::create(const IP& address, int prefix)
         mask = 0xffffffff << (32 - prefix);
       }
 
-      return IPNetwork(address, IP(mask));
+      return IP::Network(address, IP(mask));
     }
     case AF_INET6: {
       if (prefix > 128) {
@@ -539,7 +560,7 @@ inline Try<IPNetwork> IPNetwork::create(const IP& address, int prefix)
         mask.s6_addr[i] = _mask;
       }
 
-      return IPNetwork(address, IP(mask));
+      return IP::Network(address, IP(mask));
     }
     default: {
       UNREACHABLE();
@@ -550,7 +571,9 @@ inline Try<IPNetwork> IPNetwork::create(const IP& address, int prefix)
 
 // Returns the string representation of the given IP network using the
 // canonical form with prefix. For example: "10.0.0.1/8".
-inline std::ostream& operator<<(std::ostream& stream, const IPNetwork& network)
+inline std::ostream& operator<<(
+    std::ostream& stream,
+    const IP::Network& network)
 {
   stream << network.address() << "/" << network.prefix();
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/36b97ed7/3rdparty/stout/tests/ip_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/ip_tests.cpp b/3rdparty/stout/tests/ip_tests.cpp
index 39ee059..709d92e 100644
--- a/3rdparty/stout/tests/ip_tests.cpp
+++ b/3rdparty/stout/tests/ip_tests.cpp
@@ -37,8 +37,8 @@ TEST(NetTest, LinkDevice)
   ASSERT_SOME(links);
 
   foreach (const string& link, links.get()) {
-    Result<net::IPNetwork> network =
-      net::IPNetwork::fromLinkDevice(link, AF_INET);
+    Result<net::IP::Network> network =
+      net::IP::Network::fromLinkDevice(link, AF_INET);
 
     EXPECT_FALSE(network.isError());
 
@@ -61,7 +61,7 @@ TEST(NetTest, LinkDevice)
     }
   }
 
-  EXPECT_ERROR(net::IPNetwork::fromLinkDevice("non-exist", AF_INET));
+  EXPECT_ERROR(net::IP::Network::fromLinkDevice("non-exist", AF_INET));
 }
 
 
@@ -92,48 +92,59 @@ TEST(NetTest, ConstructIPv6)
 
 TEST(NetTest, ConstructIPv4Network)
 {
-  EXPECT_SOME(net::IPNetwork::parse("10.135.0.1/8"));
-  EXPECT_SOME(net::IPNetwork::parse("192.168.1.1/16"));
-  EXPECT_SOME(net::IPNetwork::parse("172.39.13.123/31"));
+  EXPECT_SOME(net::IP::Network::parse("10.135.0.1/8"));
+  EXPECT_SOME(net::IP::Network::parse("192.168.1.1/16"));
+  EXPECT_SOME(net::IP::Network::parse("172.39.13.123/31"));
 
-  EXPECT_ERROR(net::IPNetwork::parse("123.1.1.2//23"));
-  EXPECT_ERROR(net::IPNetwork::parse("121.2.3.5/23/"));
-  EXPECT_ERROR(net::IPNetwork::parse("12.32.3.a/16"));
-  EXPECT_ERROR(net::IPNetwork::parse("hello moto/8"));
-  EXPECT_ERROR(net::IPNetwork::parse("::1/128", AF_INET));
+  EXPECT_ERROR(net::IP::Network::parse("123.1.1.2//23"));
+  EXPECT_ERROR(net::IP::Network::parse("121.2.3.5/23/"));
+  EXPECT_ERROR(net::IP::Network::parse("12.32.3.a/16"));
+  EXPECT_ERROR(net::IP::Network::parse("hello moto/8"));
+  EXPECT_ERROR(net::IP::Network::parse("::1/128", AF_INET));
 
-  EXPECT_SOME(net::IPNetwork::create(net::IP(0x12345678), net::IP(0xffff0000)));
-  EXPECT_SOME(net::IPNetwork::create(net::IP(0x12345678), net::IP(0xf0000000)));
-  EXPECT_SOME(net::IPNetwork::create(net::IP(0x12345678), net::IP(0xffffffff)));
-  EXPECT_SOME(net::IPNetwork::create(net::IP(0x12345678), net::IP(0)));
+  EXPECT_SOME(net::IP::Network::create(
+      net::IP(0x12345678),
+      net::IP(0xffff0000)));
 
-  EXPECT_ERROR(net::IPNetwork::create(net::IP(0x87654321), net::IP(0xff)));
-  EXPECT_ERROR(net::IPNetwork::create(net::IP(0x87654321), net::IP(0xff00ff)));
+  EXPECT_SOME(net::IP::Network::create(
+      net::IP(0x12345678),
+      net::IP(0xf0000000)));
 
-  Try<net::IPNetwork> n1 = net::IPNetwork::create(net::IP(0x12345678), 16);
-  Try<net::IPNetwork> n2 = net::IPNetwork::create(net::IP(0x12345678), 32);
-  Try<net::IPNetwork> n3 = net::IPNetwork::create(net::IP(0x12345678), 0);
+  EXPECT_SOME(net::IP::Network::create(
+      net::IP(0x12345678),
+      net::IP(0xffffffff)));
 
-  EXPECT_SOME_EQ(net::IPNetwork::parse("18.52.86.120/16", AF_INET).get(), n1);
-  EXPECT_SOME_EQ(net::IPNetwork::parse("18.52.86.120/32", AF_INET).get(), n2);
-  EXPECT_SOME_EQ(net::IPNetwork::parse("18.52.86.120/0", AF_INET).get(), n3);
+  EXPECT_SOME(net::IP::Network::create(net::IP(0x12345678), net::IP(0)));
 
-  EXPECT_ERROR(net::IPNetwork::create(net::IP(0x12345678), 123));
-  EXPECT_ERROR(net::IPNetwork::create(net::IP(0x12345678), -1));
+  EXPECT_ERROR(net::IP::Network::create(net::IP(0x87654321), net::IP(0xff)));
+  EXPECT_ERROR(net::IP::Network::create(
+      net::IP(0x87654321),
+      net::IP(0xff00ff)));
+
+  Try<net::IP::Network> n1 = net::IP::Network::create(net::IP(0x12345678), 16);
+  Try<net::IP::Network> n2 = net::IP::Network::create(net::IP(0x12345678), 32);
+  Try<net::IP::Network> n3 = net::IP::Network::create(net::IP(0x12345678), 0);
+
+  EXPECT_SOME_EQ(net::IP::Network::parse("18.52.86.120/16", AF_INET).get(), n1);
+  EXPECT_SOME_EQ(net::IP::Network::parse("18.52.86.120/32", AF_INET).get(), n2);
+  EXPECT_SOME_EQ(net::IP::Network::parse("18.52.86.120/0", AF_INET).get(), n3);
+
+  EXPECT_ERROR(net::IP::Network::create(net::IP(0x12345678), 123));
+  EXPECT_ERROR(net::IP::Network::create(net::IP(0x12345678), -1));
 
   uint32_t address = 0x01020304;
   uint32_t netmask = 0xff000000;
 
-  Try<net::IPNetwork> network =
-    net::IPNetwork::create(net::IP(address), net::IP(netmask));
+  Try<net::IP::Network> network =
+      net::IP::Network::create(net::IP(address), net::IP(netmask));
 
   ASSERT_SOME(network);
   EXPECT_EQ(net::IP(address), network.get().address());
   EXPECT_EQ(net::IP(netmask), network.get().netmask());
   EXPECT_EQ("1.2.3.4/8", stringify(network.get()));
 
-  Try<net::IPNetwork> network2 =
-      net::IPNetwork::parse(stringify(network.get()));
+  Try<net::IP::Network> network2 =
+      net::IP::Network::parse(stringify(network.get()));
 
   ASSERT_SOME(network2);
   EXPECT_EQ(network.get(), network2.get());
@@ -142,13 +153,13 @@ TEST(NetTest, ConstructIPv4Network)
 
 TEST(NetTest, ConstructIPv6Network)
 {
-  EXPECT_SOME(net::IPNetwork::parse("::/128"));
-  EXPECT_SOME(net::IPNetwork::parse("fe80::d/64"));
-  EXPECT_SOME(net::IPNetwork::parse(
+  EXPECT_SOME(net::IP::Network::parse("::/128"));
+  EXPECT_SOME(net::IP::Network::parse("fe80::d/64"));
+  EXPECT_SOME(net::IP::Network::parse(
       "2001:cdba:0000:0000:0000:0000:3257:9652/16"));
 
-  EXPECT_ERROR(net::IPNetwork::parse("10.135.0.1/8", AF_INET6));
-  EXPECT_ERROR(net::IPNetwork::parse("hello moto/8"));
+  EXPECT_ERROR(net::IP::Network::parse("10.135.0.1/8", AF_INET6));
+  EXPECT_ERROR(net::IP::Network::parse("hello moto/8"));
 
   net::IP loopback(::in6addr_loopback);
   ASSERT_EQ("::1", stringify(loopback));
@@ -160,30 +171,30 @@ TEST(NetTest, ConstructIPv6Network)
   ASSERT_SOME(netmask1);
   ASSERT_SOME(netmask2);
 
-  EXPECT_SOME(net::IPNetwork::create(address.get(), netmask1.get()));
-  EXPECT_ERROR(net::IPNetwork::create(address.get(), loopback));
+  EXPECT_SOME(net::IP::Network::create(address.get(), netmask1.get()));
+  EXPECT_ERROR(net::IP::Network::create(address.get(), loopback));
 
-  Try<net::IPNetwork> n1 = net::IPNetwork::create(loopback, 53);
-  Try<net::IPNetwork> n2 = net::IPNetwork::create(loopback, 128);
-  Try<net::IPNetwork> n3 = net::IPNetwork::create(loopback, 0);
+  Try<net::IP::Network> n1 = net::IP::Network::create(loopback, 53);
+  Try<net::IP::Network> n2 = net::IP::Network::create(loopback, 128);
+  Try<net::IP::Network> n3 = net::IP::Network::create(loopback, 0);
 
-  EXPECT_SOME_EQ(net::IPNetwork::parse("::1/53", AF_INET6).get(), n1);
-  EXPECT_SOME_EQ(net::IPNetwork::parse("::1/128", AF_INET6).get(), n2);
-  EXPECT_SOME_EQ(net::IPNetwork::parse("::1/0", AF_INET6).get(), n3);
+  EXPECT_SOME_EQ(net::IP::Network::parse("::1/53", AF_INET6).get(), n1);
+  EXPECT_SOME_EQ(net::IP::Network::parse("::1/128", AF_INET6).get(), n2);
+  EXPECT_SOME_EQ(net::IP::Network::parse("::1/0", AF_INET6).get(), n3);
 
-  EXPECT_ERROR(net::IPNetwork::create(loopback, -3));
-  EXPECT_ERROR(net::IPNetwork::create(loopback, 182));
+  EXPECT_ERROR(net::IP::Network::create(loopback, -3));
+  EXPECT_ERROR(net::IP::Network::create(loopback, 182));
 
-  Try<net::IPNetwork> network =
-    net::IPNetwork::create(address.get(), netmask1.get());
+  Try<net::IP::Network> network =
+    net::IP::Network::create(address.get(), netmask1.get());
 
   ASSERT_SOME(network);
   EXPECT_EQ(address.get(), network.get().address());
   EXPECT_EQ(netmask1.get(), network.get().netmask());
   EXPECT_EQ("2001:cdba::3257:9652/9", stringify(network.get()));
 
-  Try<net::IPNetwork> network2 =
-    net::IPNetwork::parse(stringify(network.get()));
+  Try<net::IP::Network> network2 =
+    net::IP::Network::parse(stringify(network.get()));
 
   ASSERT_SOME(network2);
   EXPECT_EQ(network.get(), network2.get());


[3/3] mesos git commit: Replaced use of `net::IPNetwork` by `net::IP::Network` in Mesos.

Posted by be...@apache.org.
Replaced use of `net::IPNetwork` by `net::IP::Network` in Mesos.

Review: https://reviews.apache.org/r/59739/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9b69c093
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9b69c093
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9b69c093

Branch: refs/heads/master
Commit: 9b69c09310cdb6d7cfca1284f60c3f1b422c77cc
Parents: ec1f15e
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Wed Jul 5 11:38:14 2017 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Jul 5 11:40:32 2017 -0700

----------------------------------------------------------------------
 .../mesos/isolators/network/cni/cni.cpp         |  4 +-
 .../cni/plugins/port_mapper/port_mapper.cpp     |  2 +-
 src/tests/containerizer/cni_isolator_tests.cpp  | 44 ++++++++++----------
 src/tests/utils.cpp                             | 16 +++----
 src/tests/utils.hpp                             |  2 +-
 5 files changed, 34 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9b69c093/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
index b386fbe..831bc7d 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
@@ -964,7 +964,7 @@ Future<Nothing> NetworkCniIsolatorProcess::_isolate(
     if (network.cniNetworkInfo.isSome() && network.cniNetworkInfo->has_ip4()) {
       // IP are always stored in CIDR notation so need to retrieve the
       // address without the subnet mask.
-      Try<net::IPNetwork> ip = net::IPNetwork::parse(
+      Try<net::IP::Network> ip = net::IP::Network::parse(
           network.cniNetworkInfo->ip4().ip(),
           AF_INET);
 
@@ -1375,7 +1375,7 @@ Future<ContainerStatus> NetworkCniIsolatorProcess::status(
 
     if (containerNetwork.cniNetworkInfo->has_ip4()) {
       // Remove prefix length from IP address.
-      Try<net::IPNetwork> ip = net::IPNetwork::parse(
+      Try<net::IP::Network> ip = net::IP::Network::parse(
           containerNetwork.cniNetworkInfo->ip4().ip(), AF_INET);
 
       if (ip.isError()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/9b69c093/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
index ce79562..43cf3e4 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
@@ -405,7 +405,7 @@ Try<string, PluginError> PortMapper::handleAddCommand()
 
   // The IP from `delegateResult->ip4().ip()` is in CIDR notation. We
   // need to strip out the netmask.
-  Try<net::IPNetwork> ip = net::IPNetwork::parse(
+  Try<net::IP::Network> ip = net::IP::Network::parse(
       delegateResult->ip4().ip(),
       AF_INET);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/9b69c093/src/tests/containerizer/cni_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/cni_isolator_tests.cpp b/src/tests/containerizer/cni_isolator_tests.cpp
index 17afdf4..96e3e9e 100644
--- a/src/tests/containerizer/cni_isolator_tests.cpp
+++ b/src/tests/containerizer/cni_isolator_tests.cpp
@@ -111,9 +111,9 @@ public:
     cniPluginDir = path::join(sandbox.get(), "plugins");
     cniConfigDir = path::join(sandbox.get(), "configs");
 
-    Try<net::IPNetwork> hostIPNetwork = getNonLoopbackIP();
+    Try<net::IP::Network> hostNetwork = getNonLoopbackIP();
 
-    ASSERT_SOME(hostIPNetwork);
+    ASSERT_SOME(hostNetwork);
 
     // Get the first external name server.
     Try<string> read = os::read("/etc/resolv.conf");
@@ -148,8 +148,8 @@ public:
         echo "  }"
         echo "}"
         )~",
-        hostIPNetwork->address(),
-        hostIPNetwork->prefix(),
+        hostNetwork->address(),
+        hostNetwork->prefix(),
         nameServer.get()).get());
 
     ASSERT_SOME(result);
@@ -992,8 +992,8 @@ TEST_F(CniIsolatorTest, ROOT_OverrideHostname)
 // the right settings in /etc/resolv.conf.
 TEST_F(CniIsolatorTest, ROOT_VerifyResolverConfig)
 {
-  Try<net::IPNetwork> hostIPNetwork = getNonLoopbackIP();
-  ASSERT_SOME(hostIPNetwork);
+  Try<net::IP::Network> hostNetwork = getNonLoopbackIP();
+  ASSERT_SOME(hostNetwork);
 
   Try<string> mockPlugin = strings::format(
       R"~(
@@ -1019,8 +1019,8 @@ TEST_F(CniIsolatorTest, ROOT_VerifyResolverConfig)
       echo '  }'
       echo '}'
       )~",
-      hostIPNetwork.get().address(),
-      hostIPNetwork.get().prefix());
+      hostNetwork.get().address(),
+      hostNetwork.get().prefix());
 
   ASSERT_SOME(mockPlugin);
 
@@ -1110,8 +1110,8 @@ TEST_F(CniIsolatorTest, ROOT_VerifyResolverConfig)
 // that glibc accepts by using it to ping a host.
 TEST_F(CniIsolatorTest, ROOT_INTERNET_VerifyResolverConfig)
 {
-  Try<net::IPNetwork> hostIPNetwork = getNonLoopbackIP();
-  ASSERT_SOME(hostIPNetwork);
+  Try<net::IP::Network> hostNetwork = getNonLoopbackIP();
+  ASSERT_SOME(hostNetwork);
 
   // Note: We set a dummy nameserver IP address followed by the
   // Google anycast address. We also set the resolver timeout
@@ -1141,8 +1141,8 @@ TEST_F(CniIsolatorTest, ROOT_INTERNET_VerifyResolverConfig)
       echo '  }'
       echo '}'
       )~",
-      hostIPNetwork.get().address(),
-      hostIPNetwork.get().prefix());
+      hostNetwork.get().address(),
+      hostNetwork.get().prefix());
 
   ASSERT_SOME(mockPlugin);
 
@@ -1441,24 +1441,24 @@ TEST_P(DefaultExecutorCniTest, ROOT_VerifyContainerIP)
   const v1::AgentID& agentId = offer.agent_id();
 
   // The command tests if the MESOS_CONTAINER_IP is the same as the
-  // `hostIPNetwork.address` which is what the mock CNI plugin would have
+  // `hostnetwork.address` which is what the mock CNI plugin would have
   // setup for the container.
   //
   // If the container is running on the host network we set the IP to
   // slave's PID, which is effectively the `LIBPROCESS_IP` that the
   // `DefaultExecutor` is going to see. If, however, the container is
   // running on a CNI network we choose the first non-loopback
-  // address as `hostIPNetwork` since the mock CNI plugin
+  // address as `hostNetwork` since the mock CNI plugin
   // would set the container's IP to this address.
-  Try<net::IPNetwork> hostIPNetwork = net::IPNetwork::create(
+  Try<net::IP::Network> hostNetwork = net::IP::Network::create(
       slave.get()->pid.address.ip,
       32);
 
   if (networkInfo.isSome()) {
-    hostIPNetwork = getNonLoopbackIP();
+    hostNetwork = getNonLoopbackIP();
   }
 
-  ASSERT_SOME(hostIPNetwork);
+  ASSERT_SOME(hostNetwork);
 
   string command = strings::format(
       R"~(
@@ -1468,8 +1468,8 @@ TEST_P(DefaultExecutorCniTest, ROOT_VerifyContainerIP)
       else
         exit 1
       fi)~",
-      stringify(hostIPNetwork->address()),
-      stringify(hostIPNetwork->address())).get();
+      stringify(hostNetwork->address()),
+      stringify(hostNetwork->address())).get();
 
   v1::TaskInfo taskInfo = v1::createTask(
       agentId,
@@ -1671,15 +1671,15 @@ TEST_F(CniIsolatorPortMapperTest, ROOT_INTERNET_CURL_PortMapper)
 
   // Try connecting to the nginx server on port 80 through a
   // non-loopback IP address on `hostPort`.
-  Try<net::IPNetwork> hostIPNetwork = getNonLoopbackIP();
-  ASSERT_SOME(hostIPNetwork);
+  Try<net::IP::Network> hostNetwork = getNonLoopbackIP();
+  ASSERT_SOME(hostNetwork);
 
   // `TASK_RUNNING` does not guarantee that the service is running.
   // Hence, we need to re-try the service multiple times.
   Duration waited = Duration::zero();
   do {
     Try<string> connect = os::shell(
-        "curl -I http://" + stringify(hostIPNetwork->address()) +
+        "curl -I http://" + stringify(hostNetwork->address()) +
         ":" + stringify(hostPort));
 
     if (connect.isSome()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/9b69c093/src/tests/utils.cpp
----------------------------------------------------------------------
diff --git a/src/tests/utils.cpp b/src/tests/utils.cpp
index 053976d..b2c9d68 100644
--- a/src/tests/utils.cpp
+++ b/src/tests/utils.cpp
@@ -192,7 +192,7 @@ string getWebUIDir()
 }
 
 
-Try<net::IPNetwork> getNonLoopbackIP()
+Try<net::IP::Network> getNonLoopbackIP()
 {
   Try<set<string>> links = net::links();
   if (links.isError()) {
@@ -202,18 +202,18 @@ Try<net::IPNetwork> getNonLoopbackIP()
   }
 
   foreach (const string& link, links.get()) {
-    Result<net::IPNetwork> hostIPNetwork =
-      net::IPNetwork::fromLinkDevice(link, AF_INET);
+    Result<net::IP::Network> hostNetwork =
+      net::IP::Network::fromLinkDevice(link, AF_INET);
 
-    if (hostIPNetwork.isError()) {
+    if (hostNetwork.isError()) {
       return Error(
           "Unable to find a non-loopback address: " +
-          hostIPNetwork.error());
+          hostNetwork.error());
     }
 
-    if (hostIPNetwork.isSome() &&
-        (hostIPNetwork.get() != net::IPNetwork::LOOPBACK_V4())) {
-      return hostIPNetwork.get();
+    if (hostNetwork.isSome() &&
+        (hostNetwork.get() != net::IP::Network::LOOPBACK_V4())) {
+      return hostNetwork.get();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/9b69c093/src/tests/utils.hpp
----------------------------------------------------------------------
diff --git a/src/tests/utils.hpp b/src/tests/utils.hpp
index a2ae43c..b2f22cd 100644
--- a/src/tests/utils.hpp
+++ b/src/tests/utils.hpp
@@ -83,7 +83,7 @@ std::string getWebUIDir();
 Try<uint16_t> getFreePort();
 
 // Get a non-loopback IP available on this host.
-Try<net::IPNetwork> getNonLoopbackIP();
+Try<net::IP::Network> getNonLoopbackIP();
 
 } // namespace tests {
 } // namespace internal {


[2/3] mesos git commit: Replaced use of `net::IPNetwork` by `net::IP::Network` in stout.

Posted by be...@apache.org.
Replaced use of `net::IPNetwork` by `net::IP::Network` in stout.

Review: https://reviews.apache.org/r/59739/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ec1f15e3
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ec1f15e3
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ec1f15e3

Branch: refs/heads/master
Commit: ec1f15e3acc07dbcfeadfe39fa0d252cbb46ba4e
Parents: 36b97ed
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Wed Jul 5 11:39:31 2017 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Jul 5 11:40:32 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/posix/ip.hpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ec1f15e3/3rdparty/stout/include/stout/posix/ip.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/posix/ip.hpp b/3rdparty/stout/include/stout/posix/ip.hpp
index 0d7e85a..3d654f4 100644
--- a/3rdparty/stout/include/stout/posix/ip.hpp
+++ b/3rdparty/stout/include/stout/posix/ip.hpp
@@ -27,7 +27,7 @@
 
 namespace net {
 
-inline Result<IPNetwork> IPNetwork::fromLinkDevice(
+inline Result<IP::Network> IP::Network::fromLinkDevice(
     const std::string& name,
     int family)
 {
@@ -56,7 +56,7 @@ inline Result<IPNetwork> IPNetwork::fromLinkDevice(
 
           freeifaddrs(ifaddr);
 
-          Try<IPNetwork> network = IPNetwork::create(address, netmask);
+          Try<IP::Network> network = IP::Network::create(address, netmask);
           if (network.isError()) {
             return Error(network.error());
           }
@@ -71,7 +71,7 @@ inline Result<IPNetwork> IPNetwork::fromLinkDevice(
         // default /32 prefix for IPv4 and /64 for IPv6 is used.
         int prefix = (family == AF_INET ? 32 : 64);
 
-        Try<IPNetwork> network = IPNetwork::create(address, prefix);
+        Try<IP::Network> network = IP::Network::create(address, prefix);
         if (network.isError()) {
           return Error(network.error());
         }