use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSpecializerTest method testSpecializeIp.
@Test
public void testSpecializeIp() {
Ip ip = new Ip("1.1.1.1");
assertThat(trivialSpecializer.visitIp(ip), equalTo(ip));
assertThat(whitelistAnySpecializer.visitIp(ip), equalTo(ip));
assertThat(blacklistAnySpecializer.visitIp(ip), equalTo(EmptyIpSpace.INSTANCE));
IpSpaceSpecializer specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(), ImmutableSortedSet.of(new IpWildcard("1.1.1.0/24")));
assertThat(specializer.visitIp(ip), equalTo(EmptyIpSpace.INSTANCE));
// blacklist takes priority
specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(new IpWildcard("1.1.1.0/24")), ImmutableSortedSet.of(new IpWildcard("1.1.1.0/30")));
assertThat(specializer.visitIp(ip), equalTo(EmptyIpSpace.INSTANCE));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSpecializerTest method testSpecializeIpWildcard.
@Test
public void testSpecializeIpWildcard() {
IpWildcard ip = new IpWildcard(new Ip(0x01010001L), new Ip(0x0000FF00L));
assertThat(trivialSpecializer.visitIpWildcard(ip), equalTo(ip));
assertThat(whitelistAnySpecializer.visitIpWildcard(ip), equalTo(ip));
assertThat(blacklistAnySpecializer.visitIpWildcard(ip), equalTo(EmptyIpSpace.INSTANCE));
assertThat(trivialSpecializer.visitIpWildcard(IpWildcard.ANY), equalTo(UniverseIpSpace.INSTANCE));
assertThat(whitelistAnySpecializer.visitIpWildcard(IpWildcard.ANY), equalTo(UniverseIpSpace.INSTANCE));
assertThat(blacklistAnySpecializer.visitIpWildcard(IpWildcard.ANY), equalTo(EmptyIpSpace.INSTANCE));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSpecializerTest method testSpecializeIpWildcard_subsetOfWhitelisted.
@Test
public void testSpecializeIpWildcard_subsetOfWhitelisted() {
IpWildcard ip = new IpWildcard("1.2.3.0/24");
IpSpaceSpecializer specializer = new IpSpaceSpecializer(ImmutableSet.of(new IpWildcard("1.2.0.0/16")), ImmutableSet.of());
assertThat(specializer.specialize(ip), equalTo(ip));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSpecializerTest method testSpecializeIpWildcardSetIpSpace.
@Test
public void testSpecializeIpWildcardSetIpSpace() {
IpWildcardSetIpSpace ipSpace = IpWildcardSetIpSpace.builder().including(new IpWildcard("1.1.1.0/24")).including(new IpWildcard("1.2.0.0/24")).excluding(new IpWildcard("1.1.1.4/30")).build();
assertThat(trivialSpecializer.visitIpWildcardSetIpSpace(ipSpace), equalTo(ipSpace));
assertThat(whitelistAnySpecializer.visitIpWildcardSetIpSpace(ipSpace), equalTo(ipSpace));
assertThat(blacklistAnySpecializer.visitIpWildcardSetIpSpace(ipSpace), equalTo(EmptyIpSpace.INSTANCE));
IpSpaceSpecializer specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(new IpWildcard("1.1.1.0/24")), ImmutableSortedSet.of());
assertThat(specializer.visitIpWildcardSetIpSpace(ipSpace), equalTo(IpWildcardSetIpSpace.builder().including(IpWildcard.ANY).excluding(new IpWildcard("1.1.1.4/30")).build()));
/*
* Entire headerspace is contained in ipSpace, to specialize to UniverseIpSpace
*/
specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(new IpWildcard("1.2.0.0/30")), ImmutableSortedSet.of());
assertThat(specializer.visitIpWildcardSetIpSpace(ipSpace), equalTo(UniverseIpSpace.INSTANCE));
/*
* ipSpace contains only a portion of the headerspace, but we can remove parts of ipSpace
* that are irrelevant.
*/
specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(new IpWildcard("1.2.0.0/16")), ImmutableSortedSet.of());
assertThat(specializer.visitIpWildcardSetIpSpace(ipSpace), equalTo(IpWildcardSetIpSpace.builder().including(new IpWildcard("1.2.0.0/24")).build()));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class NodJobTest method testNotNattedUnsat.
/**
* Test that traffic originating from 3.0.0.1 that is expected NOT to be NATed returns UNSAT when
* we constrain to only allow NATed results.
*/
@Test
public void testNotNattedUnsat() {
HeaderSpace headerSpace = new HeaderSpace();
headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.1")));
NodJob nodJob = getNodJob(headerSpace, true);
Context z3Context = new Context();
Status status = nodJob.computeNodSat(System.currentTimeMillis(), z3Context);
assertThat(status, equalTo(Status.UNSATISFIABLE));
}
Aggregations