package be.iminds.ilabt.jfed.connectivity_tester;

/**
 * User: twalcari
 * Date: 12/19/13
 * Time: 4:26 PM
 */
public class Ping4Test implements ConnectivityTest {
    private static final String DEFAULT_IPV4_ADDRESS = "flsmonitor.fed4fire.eu";

    private final String address;


    public Ping4Test() {
        this(DEFAULT_IPV4_ADDRESS);
    }

    public Ping4Test(String address) {
        this.address = address;
    }

    @Override
    public String getName() {
        return "Ping to IPv4-host '" + address + "'";
    }

    @Override
    public boolean isLoginRequired() {
        return false;
    }

    @Override
    public ConnectivityTestResult call() {
        if (PingUtils.isReachableByPing(address)) {
            return new ConnectivityTestResult(Status.SUCCEEDED, "Successfully connected to " + address);
        } else {

            return new ConnectivityTestResult(Status.FAILED, "Unable to reach " + address);
        }
    }
}
