Search in sources :

Example 36 with IpWildcard

use of org.batfish.datamodel.IpWildcard in project batfish by batfish.

the class FwFromDestinationPrefixListExcept method applyTo.

@Override
public void applyTo(IpAccessListLine line, JuniperConfiguration jc, Warnings w, Configuration c) {
    PrefixList pl = jc.getPrefixLists().get(_name);
    if (pl != null) {
        pl.getReferers().put(this, "firewall from destination-prefix-list");
        if (pl.getIpv6()) {
            return;
        }
        RouteFilterList destinationPrefixList = c.getRouteFilterLists().get(_name);
        List<IpWildcard> wildcards = destinationPrefixList.getMatchingIps();
        line.setNotDstIps(Iterables.concat(line.getNotDstIps(), wildcards));
    } else {
        w.redFlag("Reference to undefined source prefix-list: \"" + _name + "\"");
    }
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) RouteFilterList(org.batfish.datamodel.RouteFilterList)

Example 37 with IpWildcard

use of org.batfish.datamodel.IpWildcard in project batfish by batfish.

the class IpSpaceBooleanExprTransformerTest method testVisitIp.

@Test
public void testVisitIp() {
    Ip ip = new Ip("1.2.3.4");
    BooleanExpr matchSrcExpr = ip.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(matchSrcExpr, equalTo(HeaderSpaceMatchExpr.matchSrcIp(ImmutableSet.of(new IpWildcard(ip)))));
    BooleanExpr matchDstExpr = ip.accept(DST_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(matchDstExpr, equalTo(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(ip)))));
    BooleanExpr matchSrcOrDstExpr = ip.accept(SRC_OR_DST_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(matchSrcOrDstExpr, equalTo(HeaderSpaceMatchExpr.matchSrcOrDstIp(ImmutableSet.of(new IpWildcard(ip)))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Ip(org.batfish.datamodel.Ip) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 38 with IpWildcard

use of org.batfish.datamodel.IpWildcard in project batfish by batfish.

the class IpSpaceBooleanExprTransformerTest method testVisitIpWildcardSetIpSpace.

@Test
public void testVisitIpWildcardSetIpSpace() {
    IpWildcard includeWildcard = new IpWildcard("1.1.1.1");
    IpWildcard excludeWildcard = new IpWildcard("2.2.2.2");
    IpWildcardSetIpSpace ipSpace = IpWildcardSetIpSpace.builder().including(includeWildcard).excluding(excludeWildcard).build();
    BooleanExpr expr = ipSpace.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    BooleanExpr includeExpr = includeWildcard.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    BooleanExpr excludeExpr = excludeWildcard.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(expr, equalTo(new AndExpr(ImmutableList.of(new NotExpr(excludeExpr), includeExpr))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) AndExpr(org.batfish.z3.expr.AndExpr) IpWildcardSetIpSpace(org.batfish.datamodel.IpWildcardSetIpSpace) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 39 with IpWildcard

use of org.batfish.datamodel.IpWildcard in project batfish by batfish.

the class DefaultTransitionGeneratorTest method testVisitPreOut.

@Test
public void testVisitPreOut() {
    SynthesizerInput input = MockSynthesizerInput.builder().setIpsByHostname(ImmutableMap.of(NODE1, ImmutableSet.of(IP1, IP2), NODE2, ImmutableSet.of(IP3, IP4))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PreOut.State.INSTANCE)));
    // PostInNotMine
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP1), new IpWildcard(IP2)))), ImmutableSet.of(new PostIn(NODE1)), new PreOut(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP3), new IpWildcard(IP4)))), ImmutableSet.of(new PostIn(NODE2)), new PreOut(NODE2))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) PostIn(org.batfish.z3.state.PostIn) PreOut(org.batfish.z3.state.PreOut) MockSynthesizerInput(org.batfish.z3.MockSynthesizerInput) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NotExpr(org.batfish.z3.expr.NotExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 40 with IpWildcard

use of org.batfish.datamodel.IpWildcard in project batfish by batfish.

the class DefaultTransitionGeneratorTest method testVisitNodeAccept.

@Test
public void testVisitNodeAccept() {
    SynthesizerInput input = MockSynthesizerInput.builder().setEnabledNodes(ImmutableSet.of(NODE1, NODE2)).setIpsByHostname(ImmutableMap.of(NODE1, ImmutableSet.of(IP1, IP2), NODE2, ImmutableSet.of(IP3, IP4))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeAccept.State.INSTANCE)));
    // PostInForMe
    assertThat(rules, hasItem(new BasicRuleStatement(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP1), new IpWildcard(IP2))), ImmutableSet.of(new PostIn(NODE1)), new NodeAccept(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP3), new IpWildcard(IP4))), ImmutableSet.of(new PostIn(NODE2)), new NodeAccept(NODE2))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) PostIn(org.batfish.z3.state.PostIn) MockSynthesizerInput(org.batfish.z3.MockSynthesizerInput) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NodeAccept(org.batfish.z3.state.NodeAccept) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) 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