Java Code Examples for com.google.common.net.InetAddresses#increment()

The following examples show how to use com.google.common.net.InetAddresses#increment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PooledDhcp6LeaseManager.java    From dhcp4j with Apache License 2.0 6 votes vote down vote up
/**
 * @return next available IP
 */
@Override protected InetAddress newIp(final Dhcp6RequestContext requestContext, final DuidOption.Duid clientId, final IaOption iaOption)
    throws Dhcp6Exception {
    // Client provided address hints
    final Iterable<InetAddress> requestedAddresses = getAddressesFromIa(iaOption);
    // TODO try to use hints in address allocation
    
    // Warning, this is highly inefficient
    InetAddress current = startingAddress;
    while (true) {
        if(current.equals(endingAddress)) {
            LOG.warn("IP pool exhausted");
            return null;
        }

        if(!getIaNaRegistry().containsIp(current) && !getIaTaRegistry().containsIp(current)) {
            return current;
        }

        current = InetAddresses.increment(current);
    }
}
 
Example 2
Source File: PooledDhcp6LeaseManager.java    From dhcp4j with Apache License 2.0 6 votes vote down vote up
/**
 * @return next available IP
 */
@Override protected InetAddress newIp(final Dhcp6RequestContext requestContext, final DuidOption.Duid clientId, final IaOption iaOption)
    throws Dhcp6Exception {
    // Client provided address hints
    final Iterable<InetAddress> requestedAddresses = getAddressesFromIa(iaOption);
    // TODO try to use hints in address allocation
    
    // Warning, this is highly inefficient
    InetAddress current = startingAddress;
    while (true) {
        if(current.equals(endingAddress)) {
            LOG.warn("IP pool exhausted");
            return null;
        }

        if(!getIaNaRegistry().containsIp(current) && !getIaTaRegistry().containsIp(current)) {
            return current;
        }

        current = InetAddresses.increment(current);
    }
}
 
Example 3
Source File: CidrAddressBlock.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<InetAddress> iterator() {
  return new AbstractSequentialIterator<InetAddress>(ip) {
    @Override
    protected InetAddress computeNext(InetAddress previous) {
      if (InetAddresses.isMaximum(previous)) {
        return null;
      }

      InetAddress next = InetAddresses.increment(previous);
      return contains(next) ? next : null;
    }
  };
}
 
Example 4
Source File: BmpMock.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static List<ChannelFuture> deployClients(final BmpMockDispatcher dispatcher,
                                                 final BmpMockArguments arguments) {
    final InetSocketAddress localAddress = arguments.getLocalAddress();
    InetAddress currentLocal = localAddress.getAddress();
    final int port = localAddress.getPort();
    final List<ChannelFuture> futureClients = new ArrayList<>();
    for (int i = 0; i < arguments.getRoutersCount(); i++) {
        for (final InetSocketAddress remoteAddress : arguments.getRemoteAddress()) {
            futureClients.add(dispatcher.createClient(new InetSocketAddress(currentLocal, port), remoteAddress));
        }
        currentLocal = InetAddresses.increment(currentLocal);
    }
    return futureClients;
}
 
Example 5
Source File: BmpMock.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static List<ChannelFuture> deployServers(final BmpMockDispatcher dispatcher,
                                                 final BmpMockArguments arguments) {
    final InetSocketAddress localAddress = arguments.getLocalAddress();
    InetAddress currentLocal = localAddress.getAddress();
    final int port = localAddress.getPort();
    final List<ChannelFuture> futureServers = new ArrayList<>();
    for (int i = 0; i < arguments.getRoutersCount(); i++) {
        futureServers.add(dispatcher.createServer(new InetSocketAddress(currentLocal, port)));
        currentLocal = InetAddresses.increment(currentLocal);
    }
    return futureServers;
}
 
Example 6
Source File: PCCsBuilder.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
void createPCCs(final Uint64 initialDBVersion, final Optional<TimerHandler> timerHandler) {
    InetAddress currentAddress = this.localAddress.getAddress();
    this.pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance()
            .getMessageHandlerRegistry());
    if (timerHandler.isPresent()) {
        timerHandler.get().setPCCDispatcher(this.pccDispatcher);
    }
    for (int i = 0; i < this.pccCount; i++) {
        final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(this.lsps, currentAddress,
            this.redelegationTimeout, this.stateTimeout, this.timer, timerHandler);
        createPCC(new InetSocketAddress(currentAddress, this.localAddress.getPort()), tunnelManager,
                initialDBVersion);
        currentAddress = InetAddresses.increment(currentAddress);
    }
}
 
Example 7
Source File: BGPTestTool.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
void start(final Arguments arguments) {
    final BGPDispatcher dispatcher = initializeActivator();

    final ArrayList<OptionalCapabilities> optCap = Lists.newArrayList(createMPCapability(Ipv4AddressFamily.class,
            UnicastSubsequentAddressFamily.class),
        createMPCapability(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class),
        createMPCapability(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class),
        createMPCapability(Ipv6AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class),
        createMPCapability(Ipv4AddressFamily.class, McastMplsLabeledVpnSubsequentAddressFamily.class),
        createMPCapability(Ipv6AddressFamily.class, McastMplsLabeledVpnSubsequentAddressFamily.class),
        createMPCapability(L2vpnAddressFamily.class, EvpnSubsequentAddressFamily.class),
        createMPCapability(Ipv4AddressFamily.class, RouteTargetConstrainSubsequentAddressFamily.class),
            createAs4BytesMPCapability(arguments.getAs()));
    if (arguments.getMultiPathSupport()) {
        optCap.add(createAddPathCapability());
    }
    final BgpParameters bgpParameters = createBgpParameters(optCap);

    final InetSocketAddress localAddress = arguments.getLocalAddresses();
    final int port = localAddress.getPort();
    InetAddress address = localAddress.getAddress();
    int numberOfSpeakers = arguments.getSpeakerCount();
    do {
        final BGPSessionListener sessionListener = new TestingListener(arguments.getNumberOfPrefixes(),
                arguments.getExtendedCommunities(),
            arguments.getMultiPathSupport());
        this.listeners.put(address.getHostAddress(), sessionListener);
        createPeer(dispatcher, arguments, new InetSocketAddress(address, port), sessionListener, bgpParameters);
        numberOfSpeakers--;
        address = InetAddresses.increment(address);
    } while (numberOfSpeakers > 0);
}