Skip to content

Commit

Permalink
Searchfilters: class naming consistency, fix bazel build (batfish#2343)
Browse files Browse the repository at this point in the history
* Update class names
* Update methods names as well
  • Loading branch information
progwriter authored Sep 22, 2018
1 parent 80ece1d commit 9d72089
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 107 deletions.
8 changes: 4 additions & 4 deletions projects/allinone/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ junit_tests(
)

junit_tests(
name = "ReachFilterDifferentialTest",
name = "SearchFiltersDifferentialTest",
size = "small",
srcs = [
"src/test/java/org/batfish/question/reachfilter/ReachFilterDifferentialTest.java",
"src/test/java/org/batfish/question/searchfilters/SearchFiltersDifferentialTest.java",
],
deps = [
"//projects/batfish",
Expand All @@ -132,10 +132,10 @@ junit_tests(
)

junit_tests(
name = "ReachFilterTest",
name = "SearchFiltersTest",
size = "small",
srcs = [
"src/test/java/org/batfish/question/reachfilter/ReachFilterTest.java",
"src/test/java/org/batfish/question/searchfilters/SearchFiltersTest.java",
],
deps = [
"//projects/batfish",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.junit.rules.TemporaryFolder;

/** End-to-end tests of {@link SearchFiltersQuestion} in differential mode. */
public class SearchFilterDifferentialTest {
public class SearchFiltersDifferentialTest {
@Rule public TemporaryFolder _tmp = new TemporaryFolder();

private static final String HOSTNAME = "hostname";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import org.batfish.datamodel.table.TableAnswerElement;
import org.batfish.main.Batfish;
import org.batfish.main.BatfishTestUtils;
import org.batfish.question.SearchFilterParameters;
import org.batfish.question.SearchFiltersParameters;
import org.batfish.question.testfilters.TestFiltersAnswerer;
import org.batfish.specifier.ConstantIpSpaceSpecifier;
import org.batfish.specifier.NameRegexInterfaceLinkLocationSpecifier;
Expand All @@ -68,7 +68,7 @@
import org.junit.rules.TemporaryFolder;

/** End-to-end tests of {@link org.batfish.question.searchfilters}. */
public final class SearchFilterTest {
public final class SearchFiltersTest {
private static final String IFACE1 = "iface1";

private static final String IFACE2 = "iface2";
Expand Down Expand Up @@ -161,7 +161,7 @@ public final class SearchFilterTest {

private static Configuration _config;

private static SearchFilterParameters _allLocationsParams;
private static SearchFiltersParameters _allLocationsParams;

@BeforeClass
public static void setup() throws IOException {
Expand Down Expand Up @@ -192,7 +192,7 @@ public static void setup() throws IOException {
_batfish = BatfishTestUtils.getBatfish(configurationMap, _tmp);
_allLocationsParams =
new SearchFiltersQuestion()
.toReachFilterParameters()
.toSearchFiltersParameters()
.toBuilder()
.setStartLocationSpecifier(ALL_LOCATIONS)
.setGenerateExplanations(false)
Expand Down Expand Up @@ -246,50 +246,50 @@ public void testGetQueryAcls_matchLine2() {

@Test
public void testReachFilter_deny_ACCEPT_ALL() {
Optional<SearchFilterResult> result =
Optional<SearchFiltersResult> result =
_batfish.reachFilter(_config, toDenyAcl(ACCEPT_ALL_ACL), _allLocationsParams);
assertThat("Should not find permitted flow", !result.isPresent());
}

@Test
public void testReachFilter_deny_REJECT_ALL() {
Optional<SearchFilterResult> result =
Optional<SearchFiltersResult> result =
_batfish.reachFilter(_config, toDenyAcl(REJECT_ALL_ACL), _allLocationsParams);
assertThat("Should find permitted flow", result.isPresent());
}

@Test
public void testReachFilter_permit_ACCEPT_ALL() {
Optional<SearchFilterResult> result =
Optional<SearchFiltersResult> result =
_batfish.reachFilter(_config, ACCEPT_ALL_ACL, _allLocationsParams);
assertThat("Should find permitted flow", result.isPresent());
}

@Test
public void testReachFilter_permit_REJECT_ALL() {
Optional<SearchFilterResult> result =
Optional<SearchFiltersResult> result =
_batfish.reachFilter(_config, REJECT_ALL_ACL, _allLocationsParams);
assertThat(result, equalTo(Optional.empty()));
}

@Test
public void testReachFilter_permit() {
Optional<SearchFilterResult> result = _batfish.reachFilter(_config, ACL, _allLocationsParams);
Optional<SearchFiltersResult> result = _batfish.reachFilter(_config, ACL, _allLocationsParams);
assertThat("Should find permitted flow", result.isPresent());
assertThat(result.get().getExampleFlow(), hasDstIp(oneOf(IP0, IP3)));
}

@Test
public void testReachFilter_permit_headerSpace() {
SearchFilterParameters.Builder paramsBuilder =
SearchFiltersParameters.Builder paramsBuilder =
_allLocationsParams
.toBuilder()
.setDestinationIpSpaceSpecifier(new ConstantIpSpaceSpecifier(IP0.toIpSpace()))
.setSourceIpSpaceSpecifier(new ConstantIpSpaceSpecifier(UniverseIpSpace.INSTANCE))
.setHeaderSpace(HeaderSpace.builder().build());

SearchFilterParameters params = paramsBuilder.build();
Optional<SearchFilterResult> result = _batfish.reachFilter(_config, ACL, params);
SearchFiltersParameters params = paramsBuilder.build();
Optional<SearchFiltersResult> result = _batfish.reachFilter(_config, ACL, params);
assertThat("Should find result", result.isPresent());
assertThat(result.get().getExampleFlow(), hasDstIp(IP0));

Expand All @@ -301,15 +301,15 @@ public void testReachFilter_permit_headerSpace() {

@Test
public void testReachFilter_deny() {
Optional<SearchFilterResult> permitResult =
Optional<SearchFiltersResult> permitResult =
_batfish.reachFilter(_config, toDenyAcl(ACL), _allLocationsParams);
assertThat("Should find permitted flow", permitResult.isPresent());
assertThat(permitResult.get().getExampleFlow(), hasDstIp(not(oneOf(IP0, IP3))));
}

@Test
public void testReachFilter_matchLine() {
Optional<SearchFilterResult> permitResult =
Optional<SearchFiltersResult> permitResult =
_batfish.reachFilter(_config, toMatchLineAcl(0, ACL), _allLocationsParams);
assertThat("Should find permitted flow", permitResult.isPresent());
assertThat(permitResult.get().getExampleFlow(), hasDstIp(IP0));
Expand All @@ -329,7 +329,7 @@ public void testReachFilter_matchLine() {

@Test
public void testReachFilter_matchLine_blocked() {
Optional<SearchFilterResult> permitResult =
Optional<SearchFiltersResult> permitResult =
_batfish.reachFilter(_config, toMatchLineAcl(2, BLOCKED_LINE_ACL), _allLocationsParams);
assertThat("Should not find permitted flow", !permitResult.isPresent());
}
Expand Down Expand Up @@ -369,7 +369,7 @@ COL_FILTER_NAME, equalTo(BLOCKED_LINE_ACL.getName()), Schema.STRING)),

@Test
public void testMatchSrcInterface() {
Optional<SearchFilterResult> result =
Optional<SearchFiltersResult> result =
_batfish.reachFilter(_config, toMatchLineAcl(0, SRC_ACL), _allLocationsParams);
assertThat(
result.get().getExampleFlow(), allOf(hasIngressInterface(nullValue()), hasDstIp(IP0)));
Expand Down Expand Up @@ -402,7 +402,7 @@ public void testSane() {
rejecting().setMatchCondition(matchSrcInterface(IFACE2)).build(),
ACCEPT_ALL))
.build();
Optional<SearchFilterResult> flow =
Optional<SearchFiltersResult> flow =
_batfish.reachFilter(_config, denyAllSourcesAcl, _allLocationsParams);
assertThat(flow, equalTo(Optional.empty()));
}
Expand All @@ -419,22 +419,22 @@ public void testSane2() {
rejecting().setMatchCondition(matchSrcInterface(IFACE1)).build(),
ACCEPT_ALL))
.build();
Optional<SearchFilterResult> flow =
Optional<SearchFiltersResult> flow =
_batfish.reachFilter(_config, denyAllSourcesAcl, _allLocationsParams);
assertThat("Should find a result", flow.isPresent());
assertThat(flow.get().getExampleFlow(), hasIngressInterface(IFACE2));
}

@Test
public void testSourceInterfaceParameter() {
SearchFilterParameters params =
SearchFiltersParameters params =
_allLocationsParams
.toBuilder()
.setStartLocationSpecifier(new NameRegexInterfaceLinkLocationSpecifier(IFACE1))
.build();

// can match line 1 because IFACE1 is specified
Optional<SearchFilterResult> result =
Optional<SearchFiltersResult> result =
_batfish.reachFilter(_config, toMatchLineAcl(1, SRC_ACL), params);
assertThat(result.get().getExampleFlow(), allOf(hasIngressInterface(IFACE1), hasDstIp(IP1)));

Expand All @@ -446,28 +446,28 @@ public void testSourceInterfaceParameter() {
@Test
public void testReachFilter_ACCEPT_ALL_dstIpConstraint() {
Ip constraintIp = new Ip("21.21.21.21");
SearchFilterParameters params =
SearchFiltersParameters params =
_allLocationsParams
.toBuilder()
.setDestinationIpSpaceSpecifier(new ConstantIpSpaceSpecifier(constraintIp.toIpSpace()))
.setSourceIpSpaceSpecifier(new ConstantIpSpaceSpecifier(UniverseIpSpace.INSTANCE))
.setHeaderSpace(new HeaderSpace())
.build();
Optional<SearchFilterResult> result = _batfish.reachFilter(_config, ACCEPT_ALL_ACL, params);
Optional<SearchFiltersResult> result = _batfish.reachFilter(_config, ACCEPT_ALL_ACL, params);
assertThat(result.get().getExampleFlow(), hasDstIp(constraintIp));
}

@Test
public void testReachFilter_ACCEPT_ALL_srcIpConstraint() {
Ip constraintIp = new Ip("21.21.21.21");
SearchFilterParameters params =
SearchFiltersParameters params =
_allLocationsParams
.toBuilder()
.setDestinationIpSpaceSpecifier(new ConstantIpSpaceSpecifier(UniverseIpSpace.INSTANCE))
.setSourceIpSpaceSpecifier(new ConstantIpSpaceSpecifier(constraintIp.toIpSpace()))
.setHeaderSpace(new HeaderSpace())
.build();
Optional<SearchFilterResult> result = _batfish.reachFilter(_config, ACCEPT_ALL_ACL, params);
Optional<SearchFiltersResult> result = _batfish.reachFilter(_config, ACCEPT_ALL_ACL, params);
assertThat(result.get().getExampleFlow(), hasSrcIp(constraintIp));
}

Expand All @@ -476,14 +476,14 @@ public void testReachFilter_DENY_ALL_portConstraints() {
HeaderSpace hs = new HeaderSpace();
hs.setSrcPorts(Collections.singletonList(new SubRange(1111, 1111)));
hs.setDstPorts(Collections.singletonList(new SubRange(2222, 2222)));
SearchFilterParameters params =
SearchFiltersParameters params =
_allLocationsParams
.toBuilder()
.setDestinationIpSpaceSpecifier(new ConstantIpSpaceSpecifier(UniverseIpSpace.INSTANCE))
.setSourceIpSpaceSpecifier(new ConstantIpSpaceSpecifier(UniverseIpSpace.INSTANCE))
.setHeaderSpace(hs)
.build();
Optional<SearchFilterResult> result = _batfish.reachFilter(_config, ACCEPT_ALL_ACL, params);
Optional<SearchFiltersResult> result = _batfish.reachFilter(_config, ACCEPT_ALL_ACL, params);
assertThat(result.get().getExampleFlow(), allOf(hasSrcPort(1111), hasDstPort(2222)));
}

Expand All @@ -505,9 +505,9 @@ public void testReachFilterNodeSpecifierDefault() {

@Test
public void testGetExplanation() {
SearchFilterParameters params =
SearchFiltersParameters params =
_allLocationsParams.toBuilder().setGenerateExplanations(false).build();
Optional<SearchFilterResult> result = _batfish.reachFilter(_config, ACCEPT_ALL_ACL, params);
Optional<SearchFiltersResult> result = _batfish.reachFilter(_config, ACCEPT_ALL_ACL, params);
assertThat("Should get a result", result.isPresent());
assertThat(
"Should not get an explanation", !result.get().getHeaderSpaceDescription().isPresent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
import org.batfish.grammar.BgpTableFormat;
import org.batfish.grammar.GrammarSettings;
import org.batfish.question.ReachabilityParameters;
import org.batfish.question.SearchFilterParameters;
import org.batfish.question.searchfilters.DifferentialSearchFilterResult;
import org.batfish.question.searchfilters.SearchFilterResult;
import org.batfish.question.SearchFiltersParameters;
import org.batfish.question.searchfilters.DifferentialSearchFiltersResult;
import org.batfish.question.searchfilters.SearchFiltersResult;
import org.batfish.referencelibrary.ReferenceLibrary;
import org.batfish.role.NodeRoleDimension;
import org.batfish.role.NodeRolesData;
Expand All @@ -62,12 +62,12 @@ public interface IBatfish extends IPluginConsumer {

boolean debugFlagEnabled(String flag);

DifferentialSearchFilterResult differentialReachFilter(
DifferentialSearchFiltersResult differentialReachFilter(
Configuration baseConfig,
IpAccessList baseAcl,
Configuration deltaConfig,
IpAccessList deltaAcl,
SearchFilterParameters searchFilterParameters);
SearchFiltersParameters searchFiltersParameters);

ReferenceLibrary getReferenceLibraryData();

Expand Down Expand Up @@ -192,8 +192,8 @@ void registerAnswerer(
void registerExternalBgpAdvertisementPlugin(
ExternalBgpAdvertisementPlugin externalBgpAdvertisementPlugin);

Optional<SearchFilterResult> reachFilter(
Configuration node, IpAccessList acl, SearchFilterParameters parameters);
Optional<SearchFiltersResult> reachFilter(
Configuration node, IpAccessList acl, SearchFiltersParameters parameters);

AnswerElement smtBlackhole(HeaderQuestion q);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import org.batfish.specifier.SpecifierContext;

/** A set of parameters for ACL filter analysis that uses high-level specifiers. */
public final class SearchFilterParameters {
public final class SearchFiltersParameters {
private final @Nonnull IpSpaceSpecifier _destinationIpSpaceSpecifier;
private final boolean _generateExplanations;
private final @Nonnull HeaderSpace _headerSpace;
private final @Nonnull LocationSpecifier _startLocationSpecifier;
private final @Nonnull IpSpaceSpecifier _sourceIpSpaceSpecifier;

private SearchFilterParameters(
private SearchFiltersParameters(
@Nonnull IpSpaceSpecifier destinationIpSpaceSpecifier,
@Nonnull LocationSpecifier startLocationSpecifier,
@Nonnull IpSpaceSpecifier sourceIpSpaceSpecifier,
Expand Down Expand Up @@ -115,8 +115,8 @@ public Builder setSourceIpSpaceSpecifier(@Nonnull IpSpaceSpecifier sourceIpSpace
return this;
}

public SearchFilterParameters build() {
return new SearchFilterParameters(
public SearchFiltersParameters build() {
return new SearchFiltersParameters(
requireNonNull(_destinationIpSpaceSpecifier),
requireNonNull(_startLocationSpecifier),
requireNonNull(_sourceIpSpaceSpecifier),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
import javax.annotation.Nullable;

/** The result of a differential reachFilter question. */
public final class DifferentialSearchFilterResult {
private final @Nullable SearchFilterResult _decreasedResult;
private final @Nullable SearchFilterResult _increasedResult;
public final class DifferentialSearchFiltersResult {
private final @Nullable SearchFiltersResult _decreasedResult;
private final @Nullable SearchFiltersResult _increasedResult;

public DifferentialSearchFilterResult(
@Nullable SearchFilterResult increasedResult, @Nullable SearchFilterResult decreasedResult) {
public DifferentialSearchFiltersResult(
@Nullable SearchFiltersResult increasedResult,
@Nullable SearchFiltersResult decreasedResult) {
_decreasedResult = decreasedResult;
_increasedResult = increasedResult;
}

/** @return The result for the decreased space. */
public Optional<SearchFilterResult> getDecreasedResult() {
public Optional<SearchFiltersResult> getDecreasedResult() {
return Optional.ofNullable(_decreasedResult);
}

/** @return The result for the decreased space. */
public Optional<SearchFilterResult> getIncreasedResult() {
public Optional<SearchFiltersResult> getIncreasedResult() {
return Optional.ofNullable(_increasedResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* AclLineMatchExpr} and an example flow in the headerspace.
*/
@ParametersAreNonnullByDefault
public class SearchFilterResult {
public class SearchFiltersResult {
private final @Nullable AclLineMatchExpr _headerSpaceDescription;
private final Flow _exampleFlow;

public SearchFilterResult(Flow exampleFlow, @Nullable AclLineMatchExpr headerSpaceDescription) {
public SearchFiltersResult(Flow exampleFlow, @Nullable AclLineMatchExpr headerSpaceDescription) {
_headerSpaceDescription = headerSpaceDescription;
_exampleFlow = exampleFlow;
}
Expand Down
Loading

0 comments on commit 9d72089

Please sign in to comment.