use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSimplifierTest method testVisitIpWildcardSetIpSpace_whitelistOne.
@Test
public void testVisitIpWildcardSetIpSpace_whitelistOne() {
IpWildcard ipWildcard = new IpWildcard("1.2.3.4");
assertThat(IpSpaceSimplifier.simplify(IpWildcardSetIpSpace.builder().including(ipWildcard).build()), equalTo(ipWildcard));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSimplifierTest method testVisitIpWildcardSetIpSpace.
@Test
public void testVisitIpWildcardSetIpSpace() {
assertThat(IpSpaceSimplifier.simplify(IpWildcardSetIpSpace.builder().build()), equalTo(EmptyIpSpace.INSTANCE));
assertThat(IpSpaceSimplifier.simplify(IpWildcardSetIpSpace.builder().excluding(new IpWildcard("1.2.3.0/24")).build()), equalTo(EmptyIpSpace.INSTANCE));
assertThat(IpSpaceSimplifier.simplify(IpWildcardSetIpSpace.builder().including(IpWildcard.ANY).build()), equalTo(UniverseIpSpace.INSTANCE));
assertThat(IpSpaceSimplifier.simplify(IpWildcardSetIpSpace.builder().including(IpWildcard.ANY).excluding(IpWildcard.ANY).build()), equalTo(EmptyIpSpace.INSTANCE));
// whitelisted wildcards that are covered by a blacklisted wildcard are removed
IpWildcardSetIpSpace ipSpace = IpWildcardSetIpSpace.builder().including(new IpWildcard("1.2.1.0/24"), new IpWildcard("2.2.2.2")).excluding(new IpWildcard("1.2.0.0/16")).build();
IpWildcard simplifiedIpSpace = new IpWildcard("2.2.2.2");
assertThat(IpSpaceSimplifier.simplify(ipSpace), equalTo(simplifiedIpSpace));
// blacklisted wildcards that don't overlap whitelisted wildcards are removed
ipSpace = IpWildcardSetIpSpace.builder().including(new IpWildcard("2.2.2.2")).excluding(new IpWildcard("1.0.0.0/8")).build();
assertThat(IpSpaceSimplifier.simplify(ipSpace), equalTo(simplifiedIpSpace));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSpecializerTest method testSpecializePrefix.
@Test
public void testSpecializePrefix() {
Prefix prefix = Prefix.parse("1.1.1.0/24");
assertThat(trivialSpecializer.visitPrefix(prefix), equalTo(prefix));
assertThat(whitelistAnySpecializer.visitPrefix(prefix), equalTo(prefix));
assertThat(blacklistAnySpecializer.visitPrefix(prefix), equalTo(EmptyIpSpace.INSTANCE));
/*
* All headerspace Ips are matched by the IpSpace, so it specializes to the universe.
*/
IpSpaceSpecializer specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(new IpWildcard("1.1.1.4/30")), ImmutableSortedSet.of());
assertThat(specializer.visitPrefix(prefix), equalTo(UniverseIpSpace.INSTANCE));
specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(new IpWildcard("1.0.0.0/8")), ImmutableSortedSet.of(new IpWildcard("1.1.0.0/16")));
assertThat(specializer.visitPrefix(prefix), equalTo(EmptyIpSpace.INSTANCE));
specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(new IpWildcard("1.0.0.0/8")), ImmutableSortedSet.of(new IpWildcard("1.1.1.1/32")));
assertThat(specializer.visitPrefix(prefix), equalTo(prefix));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSpecializerTest method testSpecializeIpWildcard_subsetOfWhitelisted_intersectBlacklist.
@Test
public void testSpecializeIpWildcard_subsetOfWhitelisted_intersectBlacklist() {
IpWildcard ip = new IpWildcard("1.2.3.0/24");
IpSpaceSpecializer specializer = new IpSpaceSpecializer(ImmutableSet.of(new IpWildcard("1.2.0.0/16")), ImmutableSet.of(new IpWildcard("1.2.3.4")));
assertThat(specializer.specialize(ip), equalTo(ip));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class NodJobTest method testNotNattedSat.
/**
* Test that traffic originating from 3.0.0.1 that is expected NOT to be NATed returns SAT when we
* constrain to only allow NOT-NATed results.
*/
@Test
public void testNotNattedSat() {
HeaderSpace headerSpace = new HeaderSpace();
headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.1")));
NodJob nodJob = getNodJob(headerSpace, false);
Context z3Context = new Context();
Status status = nodJob.computeNodSat(System.currentTimeMillis(), z3Context);
assertThat(status, equalTo(Status.SATISFIABLE));
}
Aggregations