jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Milamber <milam...@apache.org>
Subject Re: svn commit: r1511681 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java xdocs/usermanual/component_reference.xml
Date Thu, 08 Aug 2013 13:15:29 GMT

Le 08/08/2013 12:17, sebb a ecrit :
> On 8 August 2013 12:30, Milamber <milamber@apache.org> wrote:
>> Le 08/08/2013 10:39, sebb@apache.org a ecrit :
>>
>>> Author: sebb
>>> Date: Thu Aug  8 10:39:14 2013
>>> New Revision: 1511681
>>>
>>> URL: http://svn.apache.org/r1511681
>>> Log:
>>> Support device in addition to source IP address
>>> Support choice of IPv4 or IPv6; report error if selected interface is not
>>> found
>>> Bugzilla Id: 54874
>>>
>>> Modified:
>>>
>>> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
>>>       jmeter/trunk/xdocs/usermanual/component_reference.xml
>>>
>>> Modified:
>>> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
>>> URL:
>>> http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java?rev=1511681&r1=1511680&r2=1511681&view=diff
>>>
>>> ==============================================================================
>>> ---
>>> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
>>> (original)
>>> +++
>>> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
>>> Thu Aug  8 10:39:14 2013
>>> @@ -21,13 +21,14 @@ package org.apache.jmeter.protocol.http.
>>>    import java.io.BufferedInputStream;
>>>    import java.io.IOException;
>>>    import java.io.InputStream;
>>> +import java.net.Inet4Address;
>>> +import java.net.Inet6Address;
>>>    import java.net.InetAddress;
>>>    import java.net.InterfaceAddress;
>>>    import java.net.NetworkInterface;
>>>    import java.net.SocketException;
>>>    import java.net.URL;
>>>    import java.net.UnknownHostException;
>>> -import java.util.List;
>>>      import org.apache.jmeter.config.Arguments;
>>>    import org.apache.jmeter.protocol.http.control.AuthManager;
>>> @@ -144,7 +145,9 @@ public abstract class HTTPAbstractImpl i
>>>         * The prefix used to distiguish a device name from a host name.
>>>         * Host names cannot start with "/".
>>>         */
>>> -    private static final String DEVICE_PREFIX = "/dev/";
>>> +    private static final String DEVICE_PREFIX = "/";
>>
>>
>> This changes introduce an regression, /dev/eth0 don't works now.
>>
> Yes, that was deliberate. I changed the docs accordingly.
>
> You need to use /eth0.

/eth0 don't works, but /ipv4/eth0 works.

Seems very complicated to find the good syntax (without read the docs or 
with "IP source address" label only)

Why not use a regexp pattern to check IPv4 and IPv6 address? without a 
ipvX prefix ?

And why not considering if the ipSource (as is) isn't a IP address 
(4/6), and not is in the interface's list on host, then it's a hostname, 
else return an error.
Therefore it's not necessary to have special prefix to fill the field.




>
> I thought it was awkard to use /dev/ipv6/eth0, so I collapsed the prefix to "/".
>
>>
>>> +    private static final String IPV4 = "ipv4/";
>>> +    private static final String IPV6 = "ipv6/";
>>>          /**
>>>         * Gets the IP source address (IP spoofing) if one has been
>>> provided.
>>> @@ -157,19 +160,32 @@ public abstract class HTTPAbstractImpl i
>>>            final String ipSource = getIpSource();
>>>            if (ipSource.length() > 0) {
>>>                if (ipSource.startsWith(DEVICE_PREFIX)) {
>>> -                final String device =
>>> ipSource.substring(DEVICE_PREFIX.length());
>>> -                NetworkInterface net =
>>> NetworkInterface.getByName(device);
>>> +                String interfaceName =
>>> ipSource.substring(DEVICE_PREFIX.length());
>>
>>
>> If the the ipSource is "/dev/eth0", the interfaceName become "dev/eth0" and
>> generate this error:
>>
>> java.net.UnknownHostException: Cannot find interface dev/wlan0
>>      at
>> org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl.getIpSourceAddress(HTTPAbstractImpl.java:184)
>>      at
>> org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.setupRequest(HTTPHC4Impl.java:671)
>>      at
>> org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:269)
>>      at
>> org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
>>      at
>> org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1080)
>>      at
>> org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1069)
>>      at
>> org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:429)
>>      at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257)
>>      at java.lang.Thread.run(Thread.java:679)
>>
>>
>>
>>
>>> +                final Class<? extends InetAddress> ipClass;
>>> +                if (interfaceName.startsWith(IPV4)) {
>>> +                    interfaceName =
>>> interfaceName.substring(IPV4.length());
>>> +                    ipClass = Inet4Address.class;
>>> +                } else if (interfaceName.startsWith(IPV6)) {
>>> +                    interfaceName =
>>> interfaceName.substring(IPV6.length());
>>> +                    ipClass = Inet6Address.class;
>>> +                } else {
>>> +                    ipClass = InetAddress.class;
>>> +                }
>>> +                NetworkInterface net =
>>> NetworkInterface.getByName(interfaceName);
>>>                    if (net != null) {
>>> -                    List<InterfaceAddress> netAds =
>>> net.getInterfaceAddresses();
>>> -                    if (netAds.size() > 0) {
>>> -                        return netAds.get(0).getAddress();
>>> +                    for (InterfaceAddress ia :
>>> net.getInterfaceAddresses()) {
>>> +                        final InetAddress inetAddr = ia.getAddress();
>>> +                        if (ipClass.isInstance(inetAddr)) {
>>> +                            return inetAddr;
>>> +                        }
>>>                        }
>>> +                    throw new UnknownHostException("Interface " +
>>> interfaceName + " does not have address of type " +
>>> ipClass.getSimpleName());
>>>                    }
>>> -                return null;
>>> +                throw new UnknownHostException("Cannot find interface " +
>>> interfaceName);
>>>                }
>>>                return InetAddress.getByName(ipSource);
>>>            }
>>> -        return null;
>>> +        return null; // did not want to spoof the IP address
>>>        }
>>>          /**
>>>
>>> Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
>>> URL:
>>> http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1511681&r1=1511680&r2=1511681&view=diff
>>>
>>> ==============================================================================
>>> --- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
>>> +++ jmeter/trunk/xdocs/usermanual/component_reference.xml Thu Aug  8
>>> 10:39:14 2013
>>> @@ -323,9 +323,11 @@ and send HTTP/HTTPS requests for all ima
>>>            [Only for HTTP Request HTTPClient]
>>>            Override the default local IP address for this sample.
>>>            The JMeter host must have multiple IP addresses (i.e. IP aliases
>>> or network interfaces).
>>> -        The value can be a host name, IP address, or a network interface
>>> device such as "eth0" or "le0".
>>> -        In order to distinguish these from host names, the interface name
>>> must be entered with the prefix "/dev/",
>>> -        for example "/dev/eth0" or "/dev/le0".
>>> +        The value can be a host name, IP address, or a network interface
>>> device such as "eth0" or "lo0".
>>> +        In order to distinguish these from host names, the interface name
>>> must be entered with the prefix "/",
>>> +        for example "/eth0" or "/lo0". This will pick the first available
>>> address for that interface which
>>> +        this may be either IPV4 or IPV6. To select a specific IP protocol
>>> version, prefix the interface name
>>> +        with "/ipv4/" or "/ipv6/", for example "/ipv4/eth0" or
>>> "/ipv6/eth0"
>>>            If the property <b>httpclient.localaddress</b> is defined,
that
>>> is used for all HttpClient requests.
>>>            </property>
>>>    </properties>
>>>
>>>
>>>


Mime
View raw message