You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2013/08/08 01:55:59 UTC

svn commit: r1511542 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java xdocs/changes.xml xdocs/usermanual/component_reference.xml

Author: sebb
Date: Wed Aug  7 23:55:58 2013
New Revision: 1511542

URL: http://svn.apache.org/r1511542
Log:
Support device in addition to source IP address
Bugzilla Id: 54874

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
    jmeter/trunk/xdocs/changes.xml
    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=1511542&r1=1511541&r2=1511542&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 Wed Aug  7 23:55:58 2013
@@ -22,8 +22,12 @@ import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 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;
@@ -137,14 +141,32 @@ 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/";
+
+    /**
      * Gets the IP source address (IP spoofing) if one has been provided.
      * 
-     * @return the IP source address to use (or null, if none provided)
+     * @return the IP source address to use (or null, if none provided or the device address could not be found)
      * @throws UnknownHostException
+     * @throws SocketException 
      */
-    protected InetAddress getIpSourceAddress() throws UnknownHostException {
+    protected InetAddress getIpSourceAddress() throws UnknownHostException, SocketException {
         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);
+                if (net != null) {
+                    List<InterfaceAddress> netAds = net.getInterfaceAddresses();
+                    if (netAds.size() > 0) {
+                        return netAds.get(0).getAddress();
+                    }
+                }
+                return null;
+            }
             return InetAddress.getByName(ipSource);
         }
         return null;

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1511542&r1=1511541&r2=1511542&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Wed Aug  7 23:55:58 2013
@@ -296,6 +296,7 @@ Previously the default was 1, which coul
 <li>HTTP Request: Small user interaction improvements in Row parameter Detail Box</li>
 <li><bugzilla>55255</bugzilla> - Allow Body in HTTP DELETE method to support API that use it (like ElasticSearch)</li>
 <li><bugzilla>53480</bugzilla> - Add Kerberos support to Http Sampler (HttpClient4)</li>
+<li><bugzilla>54874</bugzilla> - Support device in addition to source IP address</li>
 </ul>
 
 <h3>Other samplers</h3>

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1511542&r1=1511541&r2=1511542&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Wed Aug  7 23:55:58 2013
@@ -322,7 +322,10 @@ and send HTTP/HTTPS requests for all ima
         <property name="Source IP address:" required="No">
         [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 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".
         If the property <b>httpclient.localaddress</b> is defined, that is used for all HttpClient requests.
         </property>
 </properties>