Example usage for com.google.common.net InetAddresses increment

List of usage examples for com.google.common.net InetAddresses increment

Introduction

In this page you can find the example usage for com.google.common.net InetAddresses increment.

Prototype

public static InetAddress increment(InetAddress address) 

Source Link

Document

Returns a new InetAddress that is one more than the passed in address.

Usage

From source file:com.gemini.geminimain.GeminiMain.java

private static void createSampleData() throws UnknownHostException {
    //setup the random generator and seeds
    Integer serverMin = 10000000, serverMax = 20000000;
    Integer networkMin = 30000000, networkMax = 40000000;
    Integer appMin = 50000000, appMax = 60000000;
    int numServers = 40, numNetworks = 5, numApps = 2;

    //for now use a clean all the tables before generating the data
    ds.getCollection(GeminiApplication.class).drop();
    ds.getCollection(GeminiNetwork.class).drop();
    ds.getCollection(GeminiServer.class).drop();

    //create the application repository object
    GeminiApplicationRepositoryMongoDBImpl appDB = new GeminiApplicationRepositoryMongoDBImpl(mongoClient,
            morphia, "Gemini");
    GeminiNetworkRepositoryMongoDBImpl netDB = new GeminiNetworkRepositoryMongoDBImpl(mongoClient, morphia,
            "Gemini");
    GeminiServerRepositoryMongoDBImpl srvDB = new GeminiServerRepositoryMongoDBImpl(mongoClient, morphia,
            "Gemini");

    //first the server objects
    Random sRand = new Random();
    for (int i = 0; i < numServers; i++) {
        String serverID = String.valueOf(sRand.nextInt((serverMax - serverMin) + 1) + serverMin);
        GeminiServer s = new GeminiServer();
        s.setName(serverID + "name");
        s.setDescription(serverID + " description");
        s.setAddress(InetAddresses//from   ww  w .j  a v a  2  s  . c  o m
                .forString(InetAddresses.fromInteger(Integer.parseInt(serverID)).getHostAddress()));
        s.setSubnetMask("255.255.255.0");
        s.setPort(443);
        s.setOs("Linux");
        s.setManufacturer(serverID + " manu");
        s.setBackupSize(Integer.parseInt(serverID) + 10);
        s.setLocation(serverID + " locker");
        s.setAdmin(serverID + " admin");
        s.setPassword(serverID + " password");
        srvDB.add(s);
        servers.add(s);
    }

    //next create network objects
    Random nRand = new Random();
    for (int i = 0; i < numNetworks; i++) {
        String networkID = String.valueOf(nRand.nextInt((networkMax - networkMin) + 1) + networkMin);
        GeminiNetwork n = new GeminiNetwork();
        n.setNetworkType("Class C");
        n.setStart(InetAddresses
                .forString(InetAddresses.fromInteger(Integer.parseInt(networkID)).getHostAddress()));
        n.setEnd(InetAddresses.increment(n.getStart()));

        //add 'numServer' divided by 'numNetwork' servers from the servers array to each network
        for (int start = i * (numServers / numNetworks), j = 0; j < (numServers / numNetworks)
                && (start + j) < numServers; j++) {
            n.addServer(servers.get(start + j));
        }
        netDB.add(n);
        networks.add(n);
    }

    //next create the application objects
    Random aRand = new Random();
    for (int i = 0; i < numApps; i++) {
        String appID = String.valueOf(aRand.nextInt((appMax - appMin) + 1) + appMin);
        GeminiApplication a = new GeminiApplication();
        //a.setId(appID.toString());
        a.setName(appID + " name");
        a.setDescription(appID + " description");
        a.setCustom(appID + " custom");
        a.setLocation(appID + " location");
        a.setBackupSize(500);

        //add 'numNetworks' divided by 'numApps' networks from the networks array to each applicaiton
        for (int start = i * (numNetworks / numApps), j = 0; j < (numNetworks / numApps)
                && (start + j) < numNetworks; j++) {
            a.addNetwork(networks.get(start + j));
        }

        //add 'numServers' divided by 'numApps' servers from the servers array to each applicaiton
        for (int start = i * (numServers / numApps), j = 0; j < (numServers / numApps)
                && (start + j) < numServers; j++) {
            a.addServer(servers.get(start + j));
        }

        //add to database
        applications.add(a);
        appDB.add(a);
    }
}

From source file:vcclient.ManageIaaS.java

private static String[] list_PublicIP_on_GW(EdgeGateway edgegw) throws UnknownHostException {
    // TODO Auto-generated method stub   
    LinkedList<String> PublicAddress = new LinkedList<>();

    for (GatewayInterfaceType gatewayInterfacetype : edgegw.getResource().getConfiguration()
            .getGatewayInterfaces().getGatewayInterface()) {
        if (gatewayInterfacetype.getInterfaceType().compareTo("uplink") == 0) {

            for (SubnetParticipationType subnetparticipation : gatewayInterfacetype.getSubnetParticipation()) {

                if (subnetparticipation.getIpRanges() == null)
                    System.out.println("no sub-allocated public IP for this interface");
                else {
                    for (IpRangeType subnetpartyperange : subnetparticipation.getIpRanges().getIpRange()) {
                        InetAddress startaddress = InetAddress.getByName(subnetpartyperange.getStartAddress());
                        InetAddress endaddress = InetAddress.getByName(subnetpartyperange.getEndAddress());

                        InetAddress cpt = InetAddress.getByName(subnetpartyperange.getStartAddress());
                        PublicAddress.add(startaddress.getHostName());
                        System.out.println(cpt.getHostAddress());

                        while (!cpt.equals(endaddress)) {
                            cpt = InetAddresses.increment(cpt);
                            PublicAddress.add(cpt.getHostAddress());
                            System.out.println(cpt.getHostAddress());
                        }/*w w  w . java  2s  .  c o  m*/
                    }
                }
            }
        }
    }

    String[] PubAddresstab = new String[PublicAddress.size()];
    PubAddresstab = PublicAddress.toArray(PubAddresstab);

    /*System.out.println("PubAddresstab[0]= ");
    System.out.println(PubAddresstab[0]);
    System.exit(0);*/

    return PubAddresstab;
}