Search in sources :

Example 31 with InetAddress

use of java.net.InetAddress in project platformlayer by platformlayer.

the class OpenstackComputeMachine method getNetworkPoint.

@Override
public NetworkPoint getNetworkPoint() throws OpsException {
    if (networkPoint == null) {
        // TODO: Check private networks
        OpenstackCloudHelpers helpers = new OpenstackCloudHelpers();
        List<InetAddress> addresses = Lists.newArrayList();
        // We assume that private networks can still reach the public internet, so these work for everyone
        List<Ip> publicIps = helpers.findPublicIps(cloud, server);
        for (Ip ip : publicIps) {
            // if (Objects.equal("6", ip.getVersion())) {
            // continue;
            // }
            String addr = ip.getAddr();
            if (!Strings.isNullOrEmpty(addr)) {
                addresses.add(InetAddresses.forString(addr));
            }
        }
        if (addresses.size() != 1) {
            throw new OpsException("Found multiple addresses: " + Joiner.on(",").join(addresses));
        }
        networkPoint = NetworkPoint.forAddress(addresses.get(0));
    }
    return networkPoint;
}
Also used : OpsException(org.platformlayer.ops.OpsException) Ip(org.openstack.model.compute.Addresses.Network.Ip) InetAddress(java.net.InetAddress)

Example 32 with InetAddress

use of java.net.InetAddress in project platformlayer by platformlayer.

the class DiskImageController method waitForAddress.

private Machine waitForAddress(final Machine machine) throws OpsException {
    try {
        final NetworkPoint myNetworkPoint = NetworkPoint.forMe();
        List<InetAddress> addresses = machine.getNetworkPoint().findAddresses(myNetworkPoint);
        if (!addresses.isEmpty()) {
            return machine;
        }
        return TimeoutPoll.poll(TimeSpan.FIVE_MINUTES, TimeSpan.TEN_SECONDS, new PollFunction<Machine>() {

            @Override
            public Machine call() throws Exception {
                Machine refreshed = cloud.refreshMachine(machine);
                List<InetAddress> addresses = refreshed.getNetworkPoint().findAddresses(myNetworkPoint);
                if (!addresses.isEmpty()) {
                    return refreshed;
                }
                return null;
            }
        });
    } catch (ExecutionException e) {
        throw new OpsException("Error while waiting for address", e);
    } catch (TimeoutException e) {
        throw new OpsException("Timeout while waiting for address", e);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) List(java.util.List) ProcessExecutionException(org.platformlayer.ops.process.ProcessExecutionException) ExecutionException(java.util.concurrent.ExecutionException) InetAddress(java.net.InetAddress) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint) Machine(org.platformlayer.ops.Machine) TimeoutException(java.util.concurrent.TimeoutException) ProcessExecutionException(org.platformlayer.ops.process.ProcessExecutionException) OpsException(org.platformlayer.ops.OpsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 33 with InetAddress

use of java.net.InetAddress in project platformlayer by platformlayer.

the class DnsResolverServiceController method findAddresses.

@Override
public List<InetAddress> findAddresses(NetworkPoint from) throws OpsException {
    Machine machine = instances.getMachine(model);
    if (machine == null) {
        return Collections.emptyList();
    }
    List<InetAddress> addresses = machine.getNetworkPoint().findAddresses(from);
    return addresses;
}
Also used : InetAddress(java.net.InetAddress) Machine(org.platformlayer.ops.Machine)

Example 34 with InetAddress

use of java.net.InetAddress in project platform_frameworks_base by android.

the class Vpn method makeLinkProperties.

private LinkProperties makeLinkProperties() {
    boolean allowIPv4 = mConfig.allowIPv4;
    boolean allowIPv6 = mConfig.allowIPv6;
    LinkProperties lp = new LinkProperties();
    lp.setInterfaceName(mInterface);
    if (mConfig.addresses != null) {
        for (LinkAddress address : mConfig.addresses) {
            lp.addLinkAddress(address);
            allowIPv4 |= address.getAddress() instanceof Inet4Address;
            allowIPv6 |= address.getAddress() instanceof Inet6Address;
        }
    }
    if (mConfig.routes != null) {
        for (RouteInfo route : mConfig.routes) {
            lp.addRoute(route);
            InetAddress address = route.getDestination().getAddress();
            allowIPv4 |= address instanceof Inet4Address;
            allowIPv6 |= address instanceof Inet6Address;
        }
    }
    if (mConfig.dnsServers != null) {
        for (String dnsServer : mConfig.dnsServers) {
            InetAddress address = InetAddress.parseNumericAddress(dnsServer);
            lp.addDnsServer(address);
            allowIPv4 |= address instanceof Inet4Address;
            allowIPv6 |= address instanceof Inet6Address;
        }
    }
    if (!allowIPv4) {
        lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), RTN_UNREACHABLE));
    }
    if (!allowIPv6) {
        lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_UNREACHABLE));
    }
    // Concatenate search domains into a string.
    StringBuilder buffer = new StringBuilder();
    if (mConfig.searchDomains != null) {
        for (String domain : mConfig.searchDomains) {
            buffer.append(domain).append(' ');
        }
    }
    lp.setDomains(buffer.toString().trim());
    return lp;
}
Also used : LinkAddress(android.net.LinkAddress) IpPrefix(android.net.IpPrefix) Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 35 with InetAddress

use of java.net.InetAddress in project platform_frameworks_base by android.

the class NetworkDiagnostics method prepareExplicitSourceIcmpMeasurements.

private void prepareExplicitSourceIcmpMeasurements(InetAddress target) {
    for (LinkAddress l : mLinkProperties.getLinkAddresses()) {
        InetAddress source = l.getAddress();
        if (source instanceof Inet6Address && l.isGlobalPreferred()) {
            Pair<InetAddress, InetAddress> srcTarget = new Pair<>(source, target);
            if (!mExplicitSourceIcmpChecks.containsKey(srcTarget)) {
                Measurement measurement = new Measurement();
                measurement.thread = new Thread(new IcmpCheck(source, target, measurement));
                mExplicitSourceIcmpChecks.put(srcTarget, measurement);
            }
        }
    }
}
Also used : LinkAddress(android.net.LinkAddress) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress) Pair(android.util.Pair)

Aggregations

InetAddress (java.net.InetAddress)2214 UnknownHostException (java.net.UnknownHostException)422 IOException (java.io.IOException)294 Test (org.junit.Test)289 InetSocketAddress (java.net.InetSocketAddress)250 NetworkInterface (java.net.NetworkInterface)191 ArrayList (java.util.ArrayList)173 SocketException (java.net.SocketException)153 HashMap (java.util.HashMap)104 Inet6Address (java.net.Inet6Address)103 Inet4Address (java.net.Inet4Address)96 Socket (java.net.Socket)78 DatagramPacket (java.net.DatagramPacket)73 LinkAddress (android.net.LinkAddress)70 Token (org.apache.cassandra.dht.Token)67 DatagramSocket (java.net.DatagramSocket)65 Map (java.util.Map)59 RouteInfo (android.net.RouteInfo)56 LinkProperties (android.net.LinkProperties)52 ServerSocket (java.net.ServerSocket)52