use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpAccessListSpecializerTest method testSpecializeIpAccessListLine_singleDst.
@Test
public void testSpecializeIpAccessListLine_singleDst() {
IpAccessListLine ipAccessListLine = IpAccessListLine.builder().setDstIps(ImmutableSet.of(new IpWildcard("1.2.3.0/24"))).build();
assertThat(TRIVIAL_SPECIALIZER.specialize(ipAccessListLine), equalTo(Optional.of(ipAccessListLine)));
assertThat(BLACKLIST_ANY_DST_SPECIALIZER.specialize(ipAccessListLine), equalTo(Optional.empty()));
assertThat(WHITELIST_ANY_DST_SPECIALIZER.specialize(ipAccessListLine), equalTo(Optional.of(ipAccessListLine)));
assertThat(BLACKLIST_ANY_SRC_SPECIALIZER.specialize(ipAccessListLine), equalTo(Optional.empty()));
assertThat(WHITELIST_ANY_SRC_SPECIALIZER.specialize(ipAccessListLine), equalTo(Optional.of(ipAccessListLine)));
// specialize to a headerspace that whitelists part of the dstIp
IpAccessListSpecializer specializer = new IpAccessListSpecializer(IpAccessListLine.builder().setDstIps(ImmutableSet.of(new IpWildcard("1.2.3.4"))).build());
assertThat(specializer.specialize(ipAccessListLine), equalTo(Optional.of(ALWAYS_TRUE_LINE)));
// specialize to a headerspace that blacklists part of the dstIp
specializer = new IpAccessListSpecializer(IpAccessListLine.builder().setNotDstIps(ImmutableSet.of(new IpWildcard("1.2.3.4"))).build());
assertThat(specializer.specialize(ipAccessListLine), equalTo(Optional.of(ipAccessListLine)));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpAccessListSpecializerTest method testSpecializeIpAccessListLine_singleSrc.
@Test
public void testSpecializeIpAccessListLine_singleSrc() {
IpAccessListLine ipAccessListLine = IpAccessListLine.builder().setSrcIps(ImmutableSet.of(new IpWildcard("1.2.3.0/24"))).build();
assertThat(TRIVIAL_SPECIALIZER.specialize(ipAccessListLine), equalTo(Optional.of(ipAccessListLine)));
assertThat(BLACKLIST_ANY_DST_SPECIALIZER.specialize(ipAccessListLine), equalTo(Optional.empty()));
assertThat(WHITELIST_ANY_DST_SPECIALIZER.specialize(ipAccessListLine), equalTo(Optional.of(ipAccessListLine)));
assertThat(BLACKLIST_ANY_SRC_SPECIALIZER.specialize(ipAccessListLine), equalTo(Optional.empty()));
assertThat(WHITELIST_ANY_SRC_SPECIALIZER.specialize(ipAccessListLine), equalTo(Optional.of(ipAccessListLine)));
// specialize to a headerspace that whitelists part of the srcIp
IpAccessListSpecializer specializer = new IpAccessListSpecializer(IpAccessListLine.builder().setSrcIps(ImmutableSet.of(new IpWildcard("1.2.3.4"))).build());
assertThat(specializer.specialize(ipAccessListLine), equalTo(Optional.of(ALWAYS_TRUE_LINE)));
// specialize to a headerspace that blacklists part of the srcIp
specializer = new IpAccessListSpecializer(IpAccessListLine.builder().setNotSrcIps(ImmutableSet.of(new IpWildcard("1.2.3.4"))).build());
assertThat(specializer.specialize(ipAccessListLine), equalTo(Optional.of(ipAccessListLine)));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSimplifierTest method testVisitIpWildcard.
@Test
public void testVisitIpWildcard() {
assertThat(IpSpaceSimplifier.simplify(IpWildcard.ANY), equalTo(UniverseIpSpace.INSTANCE));
IpWildcard ipWildcard = new IpWildcard(new Ip("1.2.0.5"), new Ip(0xFFFF00FFL));
assertThat(IpSpaceSimplifier.simplify(ipWildcard), equalTo(ipWildcard));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSpecializerTest method testSpecializeAclIpSpace.
@Test
public void testSpecializeAclIpSpace() {
AclIpSpace ipSpace = AclIpSpace.builder().thenPermitting(Prefix.parse("0.0.1.0/24")).thenRejecting(Prefix.parse("0.0.1.4/30")).thenPermitting(Prefix.parse("0.0.1.6/31")).build();
assertThat(trivialSpecializer.visitAclIpSpace(ipSpace), equalTo(ipSpace));
assertThat(whitelistAnySpecializer.visitAclIpSpace(ipSpace), equalTo(ipSpace));
assertThat(blacklistAnySpecializer.visitAclIpSpace(ipSpace), equalTo(AclIpSpace.builder().thenPermitting(EmptyIpSpace.INSTANCE).thenRejecting(EmptyIpSpace.INSTANCE).thenPermitting(EmptyIpSpace.INSTANCE).build()));
// headerspace is contained in all lines
IpSpaceSpecializer specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(new IpWildcard("0.0.1.6/32")), ImmutableSortedSet.of());
assertThat(specializer.visitAclIpSpace(ipSpace), equalTo(AclIpSpace.builder().thenPermitting(UniverseIpSpace.INSTANCE).thenRejecting(UniverseIpSpace.INSTANCE).thenPermitting(UniverseIpSpace.INSTANCE).build()));
// headerspace is outside of all lines
specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(new IpWildcard("1.1.1.1/32")), ImmutableSortedSet.of());
assertThat(specializer.visitAclIpSpace(ipSpace), equalTo(AclIpSpace.builder().thenPermitting(EmptyIpSpace.INSTANCE).thenRejecting(EmptyIpSpace.INSTANCE).thenPermitting(EmptyIpSpace.INSTANCE).build()));
// not contained in any line, and intersects the first only
specializer = new IpSpaceSpecializer(ImmutableSortedSet.of(new IpWildcard(new Ip(0x00000100L), new Ip(0xFF0FFF00L))), ImmutableSortedSet.of());
assertThat(specializer.visitAclIpSpace(ipSpace), equalTo(AclIpSpace.builder().thenPermitting(Prefix.parse("0.0.1.0/24")).thenRejecting(EmptyIpSpace.INSTANCE).thenPermitting(EmptyIpSpace.INSTANCE).build()));
}
use of org.batfish.datamodel.IpWildcard in project batfish by batfish.
the class IpSpaceSpecializerTest method testSpecializeIpWildcard_supersetOfWhitelisted.
@Test
public void testSpecializeIpWildcard_supersetOfWhitelisted() {
IpWildcard ip = new IpWildcard("1.2.0.0/16");
IpSpaceSpecializer specializer = new IpSpaceSpecializer(ImmutableSet.of(new IpWildcard("1.2.3.0/24")), ImmutableSet.of());
assertThat(specializer.specialize(ip), equalTo(UniverseIpSpace.INSTANCE));
}
Aggregations