Simulation Using Multiple IP Addresses

PureLoad Logo
PureLoad 6.2
February 2020
https://www.pureload.com
support@pureload.com

Documentation Index

Introduction

If you test a server application that makes use of the client's IP addresses you have to be able to send requests using different source IP addresses. This can be done using one of:

On a modern Linux machine we recommend using the Any-IP support.

To be able to use different source IP addresses most network tasks (including the HTTP tasks) allow setting the local IP address. There is also a set of tasks, the IP Pool tasks, to manage a pool of IP-addresses per PureLoad worker to make sure that parallel threads do not use the same IP address at the same time.

This document gives an introduction on how to simulate multiple IP addesses and describes the IP Pool tasks.

Using Virtual IP Addresses

A virtual IP address is an IP address that is not connected to a specific computer or network interface card (NIC) on a computer. Data packets are sent/received from/to the virtual IP address, but all packets travel through real network interfaces.

Configuring IP addresses

How to configure virtual addresses is platform dependent and requires general knowledge on how your network is configured. If you want to create many virtual addresses in bulk and keep the addresses permanently, you need to consult your OS documentation.

Still, this section gives you an overview on how this is done for a few different Operation Systems.

Configuring Virtual IP Address in Windows 10

The procedure to configure virtual IP addresses under Windows 10 as follows. This can only be performed by a user with administrator privilege.  

  1. Open Control Panel -> Network and Sharing Center
  2. Select Change adapter settings
  3. Right-click on the network device where you wish to add an address and select Properties.
  4. Choose Internet Protocol (TCP / IP ) and click on the Properties button.
  5. The Internet Protocol TCP / IP Properties dialog is opened. Click on the Advanced button at the bottom of the dialog.  The Advanced TCP / IP settings dialog displays all the configured IP addresses in your system.
  6. Click Add button next to the displayed IP addresses to add an IP address with a corresponding sub-net mask.

You may have to re-start the system to ensure that the changes take effect.

Configuring Virtual IP Address in Linux

To configure virtual IP addresses in Linux, you use the ifconfig command with super user privilege.

For example if you network interface is eth0 and the primary IP address is 192.168.2.1 you use ifconfig as follows:

ifconfig eth0:1 192.168.2.2 netmask 255.255.255.0 up
ifconfig eth0:2 192.168.2.3 netmask 255.255.255.0 up

This adds two virtual interfaces with IP address 192.168.2.2 and 192.168.2.3.  The interface number must be unique for each interface (for example eth0:1, eth0:2 etc).

Any-IP support on Linux

Any-IP is the capability to receive packets and establish incoming connections on IP addresses not explicitly configured on the host. This allows the host to be configured to respond to any address in a specified range as if it were local, without actually needing to configure the address on an interface.

Using Any-IP also requires the socket option IP_TRANSPARENT to be set for all new sockets created.
IP_TRANSPARENT socket option is not supported by Java and requires a native library in order to work.
The IpSocketInitTask requires the native libpuresock.so library in order to set IP_TRANSPARENT.

Pre-built Library

A pre-built binary of libpuresock.so is included and will work on most x86_64 based Linux systems.
If the pre-built binary does not work, a manual compilation and installation is required (see below).

Manual Compilation and Installation

The native library is bundled with PureLoad in C source format in the PURELOAD-HOME/native/src/puresock directory:

Makefile        make build script
puresock.c    native library C source

Use 'make' build script to compile and install the native library:

%> make
 ...
%> make install
install libpuresock.so ../../../lib

For manual installation, copy libpuresock.so to <PURE-INSTALL-DIR>/lib.
The library should be installed on all servers used (i.e all load servers).

Configure Routing

Now we can configure a host to respond and send from any IP address using "ip route add local" command.
For example, to configure a host to respond to any address in 192.168.0/24 as a local address we can do:

ip route add local 192.168.0/24 dev lo

Example using IPv6 address 2001:1b70:4292:2B0:9:80::/96:

ip -6 route add local 2001:1b70:4292:2B0:9:80::/96 dev lo

Now we can set the source IP address to any address in the 192.168.0/24 and the host is reachable by any 192.168.0/24 address when received on any host interface.

In addition this requires that routing be set up as expected.
If the real IP address of the host in our example is 10.20.30.40 and is reachable through eth0 on the receiving side, a route must also be added there on the receving side:

ip route add 192.168.0/24 via 10.20.30.40 dev eth0

Similar for IPv6, with a real IP address of 2001:0db8:0:f101::1:

ip -6 route add 2001:1b70:4292:2B0:9:80::/96 via 2001:0db8:0:f101::1 dev eth0

PureLoad Usage

In PureLoad you now use IpSocketOptionsTask to set the IP_TRANSPARENT socket option to allow PureLoad to bind to a non-local IP address. The IP address to bind to is specified in the tasks (e.g.HttpInitTask). A good way to manage the IP addresses is to use the IP Pool Tasks (see below).

In addition if we will be generating many connections we typically want to use IpSocketOptionsTask to set SO_REUSEADDR socket option.

A typical scenario looks something like:

The Init sequence is here used to set socket options, Init the pool of IP addresses, get an IP address and init HTTP using the assigned IP address.
The first IpSocketInitTask is used to set the SO_REUSEADDR and IP_TRANSPARENT socket option. Next we use the IPPoolInitTask we initialize a pool of source IP addresses to be used: 192.168.0/24. I.e 254 IP addresses starting with 192.168.0.1 up to 192.168.0.254:

The PoolGetTask is used to get an IP address from the pool and assign to a variable (local-ip):

The assigned variable is then used by the HttpInitTask to specify the local (source) address to be used by all HTTP tasks:

After this we can execute any number of HTTP tasks in the "Execute HTTP" sequence.

Finally we must make sure to return the used IP address to the IP pool:

Make sure that the "CleanUp" sequence has Condition "Always" selected to make sure it's executed even if any previous tasks fails.
For more information about the IP pool tasks, see the section below.

IP Pool Tasks

IPPoolInitTask

The IPPoolInitTask is only executed once per load test session and creates the pool with addresses.

The pool can be initialized in two ways:

  1. A specified range of addresses
  2. By probing the specified interface(s)

An example where the pool is initiated from a range:

IPPoolInitTask

The range creates IP addresses 192.68.2.1 to 192.68.2.100, excluding all addresses ending with 0. The "Shuffle" option is used to ensure that the generated numbers are not stored in the pool ordered.

The range can be specified in several ways:

Another example, where the pool is generated by probing the interface (in this case the physical interfaces e100g0,  e100g1 and e100g3):

IPPoolInitTask

Here we exclude all addresses ending with ".1".

PoolGetTask

To get next available task from the IP pool, the PoolGetTask is used:

PoolGetTask

As Pool Name we specify the name of the IP pool created by IPPoolInitTask. We assign the retrieved IP address to the variable "ip". This variable can then be used in other task where we need to specify the local IP Address.

PoolReturnTask

When we do not need the IP Address retrieved by PoolGetTask, we must return it to the pool using PoolReturnTask:

PoolReturnTask



Copyright © 2020 PureLoad Software Group AB. All rights reserved.