Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local ip address configurable #1291

Closed
asfimport opened this issue Jan 14, 2004 · 8 comments
Closed

local ip address configurable #1291

asfimport opened this issue Jan 14, 2004 · 8 comments

Comments

@asfimport
Copy link
Collaborator

Heinrich Soebke (Bug 26136):
Sometimes it would be useful, if the ip address of a http request is
configurable (out of set of ip-addresses which are known for this pc).
I didn't find a possibility to do this in JMeter so far.

Votes in Bugzilla: 1
OS: other

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
I don't understand - where would this be used?

@asfimport
Copy link
Collaborator Author

Heinrich Soebke (migrated from Bugzilla):
in cases where the client is identified in the server by its ip-address
(normally the identification is done by the session identifier). The actual
topic is creating GPRS load in a GSM network.

@asfimport
Copy link
Collaborator Author

Heinrich Soebke (migrated from Bugzilla):
in cases where the client is identified in the server by its ip-address
(normally the identification is done by the session identifier). The actual
topic is creating GPRS load in a GSM network.

@asfimport
Copy link
Collaborator Author

Eric Bloch (migrated from Bugzilla):
I would use this too. Having the ability to round-robin requests/sessions as
coming from different client IPs helps a lot when trying to simulate real
network performance for the lower level software (e.g. kernel networking
stacks). If all traffic comes from one IP address, that is not very real world.

-Eric

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
Not sure how this can be done - any suggestions?

Also, note that proxies will present the same IP address to the server even
though there may be many different IPs behind the proxy.

It is wrong to assuming that an IP address is unique to a host - let alone a
session, as there maye be many sessions/browsers running on a single host.

@asfimport
Copy link
Collaborator Author

Heinrich Soebke (migrated from Bugzilla):
Created attachment HttpRequest.java: sample

HttpRequest.java
import java.io.*;
import java.util.*;
import java.net.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;


public class HttpRequest
extends TestProcedure {

    public TpHttpRequest()
    throws Exception {
    }

    public TpHttpRequest( String system )
    throws Exception {
        super( system );
    }

    // description for testsuite (short)
    public String _shortDescription = "TpHttpRequest makes a http request "	+
    "";

    // description for testsuite (long)
    public String _detailedDescription = "The class TpHttpRequest makes a "		+
    "http request and checks the return code.";

    public ParamStr  _targetIpAddress = new ParamStr("destination ip address", "139.21.93.123");

    public ParamStr  _targetProtocol = new ParamStr("protocol which is used to connect to the target",
    new String[] { "http", "https" });

    public ParamStr _targetPort = new ParamStr( " portnumber of target ", "80");

    public ParamStr _targetPath = new ParamStr( " url path of target (without leading slash)", "index.html");

    public ParamStr _sourceIpAddress = new ParamStr("list of local ip addresses, separated by semicolon or comma", "10.0.0.2,10.0.0.3,10.0.0.4,10.0.0.5,10.0.0.6,10.0.0.7");
    InetAddress _sourceIpAddressResolved = null;

    private static String className = TpHttpRequest.class.getName();

    private Vector _validIpAddresses = null;

    /**
     * composes the url from the given parameters of the procedure.
     * @return complete url
     */
    private String getURL()  throws Exception {
        String result = this._targetProtocol.getSubstitutedStrValue() +
        "://" +
        this._targetIpAddress.getSubstitutedStrValue() +
        ":" +
        this._targetPort.getSubstitutedStrValue() +
        "/" +
        this._targetPath.getSubstitutedStrValue();
        return  result;
    }

    private int getTargetPort() throws Exception  {
        String sPort = _targetPort.getSubstitutedStrValue();
        int port = Integer.parseInt(sPort);
        return port;

    }

    private HostConfiguration getHostConfiguration(InetAddress pAddress) throws Exception {
        HostConfiguration hc = new HostConfiguration();
        hc.setHost(this._targetIpAddress.getSubstitutedStrValue(),
        getTargetPort(),
        this._targetProtocol.getSubstitutedStrValue());
        hc.setLocalAddress(pAddress);
        return hc;
    }

    private List getSourceAddresses() throws Exception {
        if (_validIpAddresses == null) {
            String addresses = _sourceIpAddress.getSubstitutedStrValue();
            Vector result = new Vector();
            StringTokenizer tokenizer = new StringTokenizer(addresses, ";, ");
            while (tokenizer.hasMoreElements()) {
                String address = tokenizer.nextToken();
                InetAddress ia = null;
                try {
                    ia = InetAddress.getByName(address);
                } catch (UnknownHostException e) {
                    System.out.println( className + ".getSourceAddresses: address not valid: <" + address + ">");
                }
                if (ia != null) {
                    result.add(ia);
                }
            }
            _validIpAddresses = result;
        }
        return _validIpAddresses;

    }

    public void runTp() throws Exception{
        HttpMethod hMethod = new GetMethod();

        HttpClient hClient = new HttpClient();

        List sourceAddress = getSourceAddresses();
        if (sourceAddress.size() == 0) {
            _testProcedureResult.failed( "no source addresses available" );
        }
        Iterator ads = sourceAddress.iterator();
        while (ads.hasNext()) {
            InetAddress ia = (InetAddress) ads.next();
            HostConfiguration hc =  getHostConfiguration(ia);
            int statusCode = -1;
            try {
                // We will retry up to 3 times.
                for (int attempt = 0; statusCode == -1 && attempt < 3; attempt++) {
                    try {
                        hMethod.recycle();
                        hMethod.setPath(this._targetPath.getValue());
                        // execute the method.
                        statusCode = hClient.executeMethod(hc, hMethod);
                        _testProcedureResult.passed( "TpHttp passed" );
                    } catch (HttpRecoverableException e) {
                        System.out.println( className + ".runTp: A recoverable exception occurred, retrying.  " + e.getMessage());
                    }
                }
            } catch (BindException e) {
                _testProcedureResult.failed( "TpHttp: Address not valid " + ia.toString());
            } catch (IOException e) {
                _testProcedureResult.failed( "TpHttp failed" );
            }
        }

    }
}

@asfimport
Copy link
Collaborator Author

Heinrich Soebke (migrated from Bugzilla):

Not sure how this can be done - any suggestions?
I'm no longer in that project, but I try to remember:
There was a solution based on the org.apache.commons.httpclient package.
We had to configure every ip-address which was used for a request on the local
machine, otherwise no request with that address was possible. This was possible
on Windows and on Linux.
We created for every source ip address http requests in a loop. The attached
code snippet may demonstrate it. Starting point is the method runTest.

Also, note that proxies will present the same IP address to the server even
though there may be many different IPs behind the proxy.
It is wrong to assuming that an IP address is unique to a host - let alone a
session, as there maye be many sessions/browsers running on a single host.
Yes, that's true, but in that special case we needed requests with different
source ip addresses.

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
I've added the code to the 2.1 branch.

It will be in the next release, and in the the nightly from 2-1.20060414

Sorry it has taken so long.

Note that it will only work with the Apache HttpClient sampler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant