Search in sources :

Example 46 with IpWildcard

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

Example 47 with IpWildcard

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

Example 48 with IpWildcard

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

Example 49 with IpWildcard

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

Example 50 with IpWildcard

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));
}
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