Search in sources :

Example 21 with IpWildcard

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));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Test(org.junit.Test)

Example 22 with 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));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) IpWildcardSetIpSpace(org.batfish.datamodel.IpWildcardSetIpSpace) Test(org.junit.Test)

Example 23 with IpWildcard

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));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Prefix(org.batfish.datamodel.Prefix) Test(org.junit.Test)

Example 24 with IpWildcard

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));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Test(org.junit.Test)

Example 25 with IpWildcard

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));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) HeaderSpace(org.batfish.datamodel.HeaderSpace) Test(org.junit.Test)

Aggregations

IpWildcard (org.batfish.datamodel.IpWildcard)63 Test (org.junit.Test)38 Ip (org.batfish.datamodel.Ip)18 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)17 SubRange (org.batfish.datamodel.SubRange)16 HeaderSpace (org.batfish.datamodel.HeaderSpace)12 Prefix (org.batfish.datamodel.Prefix)9 LinkedList (java.util.LinkedList)8 Configuration (org.batfish.datamodel.Configuration)8 Context (com.microsoft.z3.Context)7 Interface (org.batfish.datamodel.Interface)7 IpAccessList (org.batfish.datamodel.IpAccessList)6 IpProtocol (org.batfish.datamodel.IpProtocol)6 BoolExpr (com.microsoft.z3.BoolExpr)5 TreeSet (java.util.TreeSet)5 BatfishException (org.batfish.common.BatfishException)5 RouteFilterList (org.batfish.datamodel.RouteFilterList)5 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 Status (com.microsoft.z3.Status)4 Map (java.util.Map)4