Merge "Add varargs methods to build DhcpServingParams" am: 80f3ddca8a
am: c461d4dd01
Change-Id: Ide92e32de40c267b83fd54032d75c599a068d6f2
This commit is contained in:
@@ -28,6 +28,8 @@ import android.net.IpPrefix;
|
|||||||
import android.net.LinkAddress;
|
import android.net.LinkAddress;
|
||||||
import android.net.NetworkUtils;
|
import android.net.NetworkUtils;
|
||||||
|
|
||||||
|
import com.google.android.collect.Sets;
|
||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -154,6 +156,25 @@ public class DhcpServingParams {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default routers to be advertised to DHCP clients.
|
||||||
|
*
|
||||||
|
* <p>Each router must be inside the served prefix. This may be an empty list of routers,
|
||||||
|
* but it must always be set explicitly before building the {@link DhcpServingParams}.
|
||||||
|
*/
|
||||||
|
public Builder setDefaultRouters(@NonNull Inet4Address... defaultRouters) {
|
||||||
|
return setDefaultRouters(Sets.newArraySet(defaultRouters));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to build the parameters with no default router.
|
||||||
|
*
|
||||||
|
* <p>Equivalent to calling {@link #setDefaultRouters(Inet4Address...)} with no address.
|
||||||
|
*/
|
||||||
|
public Builder withNoDefaultRouter() {
|
||||||
|
return setDefaultRouters();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the DNS servers to be advertised to DHCP clients.
|
* Set the DNS servers to be advertised to DHCP clients.
|
||||||
*
|
*
|
||||||
@@ -165,6 +186,25 @@ public class DhcpServingParams {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the DNS servers to be advertised to DHCP clients.
|
||||||
|
*
|
||||||
|
* <p>This may be an empty list of servers, but it must always be set explicitly before
|
||||||
|
* building the {@link DhcpServingParams}.
|
||||||
|
*/
|
||||||
|
public Builder setDnsServers(@NonNull Inet4Address... dnsServers) {
|
||||||
|
return setDnsServers(Sets.newArraySet(dnsServers));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to build the parameters with no DNS server.
|
||||||
|
*
|
||||||
|
* <p>Equivalent to calling {@link #setDnsServers(Inet4Address...)} with no address.
|
||||||
|
*/
|
||||||
|
public Builder withNoDnsServer() {
|
||||||
|
return setDnsServers();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set excluded addresses that the DHCP server is not allowed to assign to clients.
|
* Set excluded addresses that the DHCP server is not allowed to assign to clients.
|
||||||
*
|
*
|
||||||
@@ -176,6 +216,16 @@ public class DhcpServingParams {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set excluded addresses that the DHCP server is not allowed to assign to clients.
|
||||||
|
*
|
||||||
|
* <p>This parameter is optional. DNS servers and default routers are always excluded
|
||||||
|
* and do not need to be set here.
|
||||||
|
*/
|
||||||
|
public Builder setExcludedAddrs(@NonNull Inet4Address... excludedAddrs) {
|
||||||
|
return setExcludedAddrs(Sets.newArraySet(excludedAddrs));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the lease time for leases assigned by the DHCP server.
|
* Set the lease time for leases assigned by the DHCP server.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import org.junit.runner.RunWith;
|
|||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -150,14 +149,14 @@ public class DhcpServingParamsTest {
|
|||||||
|
|
||||||
@Test(expected = InvalidParameterException.class)
|
@Test(expected = InvalidParameterException.class)
|
||||||
public void testBuild_PrefixTooSmall() throws InvalidParameterException {
|
public void testBuild_PrefixTooSmall() throws InvalidParameterException {
|
||||||
mBuilder.setDefaultRouters(Collections.singleton(parseAddr("192.168.0.254")))
|
mBuilder.setDefaultRouters(parseAddr("192.168.0.254"))
|
||||||
.setServerAddr(new LinkAddress(TEST_SERVER_ADDR, 31))
|
.setServerAddr(new LinkAddress(TEST_SERVER_ADDR, 31))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = InvalidParameterException.class)
|
@Test(expected = InvalidParameterException.class)
|
||||||
public void testBuild_RouterNotInPrefix() throws InvalidParameterException {
|
public void testBuild_RouterNotInPrefix() throws InvalidParameterException {
|
||||||
mBuilder.setDefaultRouters(Collections.singleton(parseAddr("192.168.254.254"))).build();
|
mBuilder.setDefaultRouters(parseAddr("192.168.254.254")).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> void assertContains(@NonNull Set<T> set, @NonNull Set<T> subset) {
|
private static <T> void assertContains(@NonNull Set<T> set, @NonNull Set<T> subset) {
|
||||||
|
|||||||
Reference in New Issue
Block a user