Skip to content

Commit

Permalink
[network] fixes excessive testing of arping method during discovery (#…
Browse files Browse the repository at this point in the history
…4854)

fixes escessive testing of arping method during discovery

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
  • Loading branch information
J-N-K authored and jannegpriv committed Mar 3, 2019
1 parent 7fdcb91 commit 5b1034c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void setUp() throws UnknownHostException {
subject.setUseDhcpSniffing(false);
subject.setIOSDevice(true);
subject.setServicePorts(Collections.singleton(1010));
subject.setUseArpPing(true, "arping");
subject.setUseArpPing(true, "arping", ArpPingUtilEnum.IPUTILS_ARPING);
subject.setUseIcmpPing(true);

assertThat(subject.pingMethod, is(IpPingMethodEnum.WINDOWS_PING));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.math.BigDecimal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.network.internal.utils.NetworkUtils;
import org.openhab.binding.network.internal.utils.NetworkUtils.ArpPingUtilEnum;

/**
* Contains the binding configuration and default values. The field names represent the configuration names,
Expand All @@ -28,11 +30,15 @@ public class NetworkBindingConfiguration {
public Boolean allowDHCPlisten = true;
public BigDecimal cacheDeviceStateTimeInMS = BigDecimal.valueOf(2000);
public String arpPingToolPath = "arping";
public @NonNullByDefault({}) ArpPingUtilEnum arpPingUtilMethod;

public void update(NetworkBindingConfiguration newConfiguration) {
this.allowSystemPings = newConfiguration.allowSystemPings;
this.allowDHCPlisten = newConfiguration.allowDHCPlisten;
this.cacheDeviceStateTimeInMS = newConfiguration.cacheDeviceStateTimeInMS;
this.arpPingToolPath = newConfiguration.arpPingToolPath;

NetworkUtils networkUtils = new NetworkUtils();
this.arpPingUtilMethod = networkUtils.determineNativeARPpingMethod(arpPingToolPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.cache.ExpiringCache;
Expand Down Expand Up @@ -58,8 +57,8 @@ public class PresenceDetection implements IPRequestReceivedCallback {
private boolean useDHCPsniffing = false;
private String arpPingState = "Disabled";
private String ipPingState = "Disabled";
protected String arpPingUtilPath = "";
protected ArpPingUtilEnum arpPingMethod = ArpPingUtilEnum.UNKNOWN_TOOL;
private String arpPingUtilPath = "arping";
protected @Nullable IpPingMethodEnum pingMethod = null;
private boolean iosDevice;
private Set<Integer> tcpPorts = new HashSet<>();
Expand Down Expand Up @@ -112,7 +111,7 @@ public void setHostname(String hostname) {
InetAddress destinationAddress = InetAddress.getByName(hostname);
if (!destinationAddress.equals(cachedDestination)) {
logger.trace("host name resolved to other address, (re-)setup presence detection");
setUseArpPing(true, arpPingUtilPath, destinationAddress);
setUseArpPing(true, destinationAddress);
if (useDHCPsniffing) {
if (cachedDestination != null) {
disableDHCPListen(cachedDestination);
Expand Down Expand Up @@ -179,9 +178,8 @@ public void setUseIcmpPing(@Nullable Boolean useSystemPing) {
* @param enable Enable or disable ARP ping
* @param arpPingUtilPath c
*/
public void setUseArpPing(boolean enable, String arpPingUtilPath, @Nullable InetAddress destinationAddress) {
this.arpPingUtilPath = arpPingUtilPath;
if (!enable || StringUtils.isBlank(arpPingUtilPath)) {
private void setUseArpPing(boolean enable, @Nullable InetAddress destinationAddress) {
if (!enable || arpPingUtilPath.isEmpty()) {
arpPingState = "Disabled";
arpPingMethod = ArpPingUtilEnum.UNKNOWN_TOOL;
return;
Expand All @@ -190,7 +188,7 @@ public void setUseArpPing(boolean enable, String arpPingUtilPath, @Nullable Inet
arpPingMethod = ArpPingUtilEnum.UNKNOWN_TOOL;
return;
}
arpPingMethod = networkUtils.determineNativeARPpingMethod(arpPingUtilPath);

switch (arpPingMethod) {
case UNKNOWN_TOOL: {
arpPingState = "Unknown arping tool";
Expand All @@ -217,8 +215,10 @@ public void setUseArpPing(boolean enable, String arpPingUtilPath, @Nullable Inet
* @param enable Enable or disable ARP ping
* @param arpPingUtilPath enableDHCPListen(useDHCPsniffing);
*/
public void setUseArpPing(boolean enable, String arpPingUtilPath) {
setUseArpPing(enable, arpPingUtilPath, destination.getValue());
public void setUseArpPing(boolean enable, String arpPingUtilPath, ArpPingUtilEnum arpPingUtilMethod) {
setUseArpPing(enable, destination.getValue());
this.arpPingUtilPath = arpPingUtilPath;
this.arpPingMethod = arpPingUtilMethod;
}

public String getArpPingState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected void startScan() {
s.setTimeout(PING_TIMEOUT_IN_MS);
// Ping devices
s.setUseIcmpPing(true);
s.setUseArpPing(true, configuration.arpPingToolPath);
s.setUseArpPing(true, configuration.arpPingToolPath, configuration.arpPingUtilMethod);
// TCP devices
s.setServicePorts(tcpServicePorts);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void initialize(PresenceDetection presenceDetection) {
// Hand over binding configurations to the network service
presenceDetection.setUseDhcpSniffing(configuration.allowDHCPlisten);
presenceDetection.setUseIcmpPing(configuration.allowSystemPings);
presenceDetection.setUseArpPing(true, configuration.arpPingToolPath);
presenceDetection.setUseArpPing(true, configuration.arpPingToolPath, configuration.arpPingUtilMethod);
}

this.retries = handlerConfiguration.retry.intValue();
Expand Down

0 comments on commit 5b1034c

Please sign in to comment.