Search in sources :

Example 21 with StaticRoute

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

the class BDDNetwork method computeInterfacePolicies.

/*
   * For each interface in the network, creates a canonical
   * representation of the import and export policies on this interface.
   */
private void computeInterfacePolicies() {
    for (Entry<String, Configuration> entry : _graph.getConfigurations().entrySet()) {
        String router = entry.getKey();
        // Skip if doesn't match the node regex
        Matcher m = _nodeSpecifier.getRegex().matcher(router);
        if (!m.matches()) {
            continue;
        }
        Configuration conf = entry.getValue();
        List<GraphEdge> edges = _graph.getEdgeMap().get(router);
        for (GraphEdge ge : edges) {
            // Import BGP policy
            RoutingPolicy importBgp = _graph.findImportRoutingPolicy(router, Protocol.BGP, ge);
            if (importBgp != null) {
                BDDRoute rec = computeBDD(_graph, conf, importBgp, true);
                _importBgpPolicies.put(ge, rec);
            }
            // Export BGP policy
            RoutingPolicy exportBgp = _graph.findExportRoutingPolicy(router, Protocol.BGP, ge);
            if (exportBgp != null) {
                BDDRoute rec = computeBDD(_graph, conf, exportBgp, true);
                _exportBgpPolicies.put(ge, rec);
            }
            IpAccessList in = ge.getStart().getIncomingFilter();
            IpAccessList out = ge.getStart().getOutgoingFilter();
            // Incoming ACL
            if (in != null) {
                BDDAcl x = BDDAcl.create(conf, in, true);
                _inAcls.put(ge, x);
            }
            // Outgoing ACL
            if (out != null) {
                BDDAcl x = BDDAcl.create(conf, out, true);
                _outAcls.put(ge, x);
            }
        }
    }
    for (Entry<String, List<GraphEdge>> entry : _graph.getEdgeMap().entrySet()) {
        String router = entry.getKey();
        // Skip if doesn't match the node regex
        Matcher m = _nodeSpecifier.getRegex().matcher(router);
        if (!m.matches()) {
            continue;
        }
        List<GraphEdge> edges = entry.getValue();
        Configuration conf = _graph.getConfigurations().get(router);
        for (GraphEdge ge : edges) {
            BDDRoute bgpIn = _importBgpPolicies.get(ge);
            BDDRoute bgpOut = _exportBgpPolicies.get(ge);
            BDDAcl aclIn = _inAcls.get(ge);
            BDDAcl aclOut = _outAcls.get(ge);
            Integer ospfCost = ge.getStart().getOspfCost();
            SortedSet<Pair<Prefix, Integer>> staticPrefixes = new TreeSet<>();
            SortedSet<StaticRoute> staticRoutes = conf.getDefaultVrf().getStaticRoutes();
            for (StaticRoute sr : staticRoutes) {
                Prefix pfx = sr.getNetwork();
                Integer adminCost = sr.getAdministrativeCost();
                Pair<Prefix, Integer> tup = new Pair<>(pfx, adminCost);
                staticPrefixes.add(tup);
            }
            InterfacePolicy ipol = new InterfacePolicy(aclIn, bgpIn, null, staticPrefixes);
            InterfacePolicy epol = new InterfacePolicy(aclOut, bgpOut, ospfCost, null);
            _importPolicyMap.put(ge, ipol);
            _exportPolicyMap.put(ge, epol);
        }
    }
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) Matcher(java.util.regex.Matcher) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Prefix(org.batfish.datamodel.Prefix) InterfacePolicy(org.batfish.symbolic.abstraction.InterfacePolicy) TreeSet(java.util.TreeSet) IpAccessList(org.batfish.datamodel.IpAccessList) List(java.util.List) IpAccessList(org.batfish.datamodel.IpAccessList) GraphEdge(org.batfish.symbolic.GraphEdge) Pair(org.batfish.common.Pair)

Example 22 with StaticRoute

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

the class AbstractRibTest method testGetRoutesIsNotAView.

/**
 * Test that routes obtained from getRoutes() do NOT reflect subsequent changes to the RIB
 */
@Test
public void testGetRoutesIsNotAView() {
    _rib.mergeRoute(_mostGeneralRoute);
    Set<StaticRoute> routes = _rib.getRoutes();
    StaticRoute r1 = new StaticRoute(Prefix.parse("1.1.1.1/32"), Ip.ZERO, null, 0, 0);
    _rib.mergeRoute(r1);
    assertThat(routes, not(containsInAnyOrder(r1)));
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Test(org.junit.Test)

Example 23 with StaticRoute

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

the class AbstractRibTest method testGetRoutesCannotBeModified.

/**
 * Test that routes obtained from getRoutes() cannot be modified
 */
@Test
public void testGetRoutesCannotBeModified() {
    _rib.mergeRoute(_mostGeneralRoute);
    Set<StaticRoute> routes = _rib.getRoutes();
    StaticRoute r1 = new StaticRoute(Prefix.parse("1.1.1.1/32"), Ip.ZERO, null, 0, 0);
    // Exception because ImmutableSet
    _expectedException.expect(UnsupportedOperationException.class);
    routes.add(r1);
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Test(org.junit.Test)

Example 24 with StaticRoute

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

the class AbstractRibTest method setupOverlappingRoutes.

/**
 * Inserts overlapping routes into the RIB and returns a (manually) ordered list of them
 */
private List<StaticRoute> setupOverlappingRoutes() {
    // Setup helper
    String[] testPrefixes = new String[] { "10.0.0.0/8", "10.0.0.0/9", "10.128.0.0/9", "10.1.1.1/32" };
    List<StaticRoute> routes = new ArrayList<>();
    // Test: merge the routes into the RIB
    for (String prefixStr : testPrefixes) {
        StaticRoute r = new StaticRoute(Prefix.parse(prefixStr), Ip.ZERO, null, 0, 0);
        _rib.mergeRoute(r);
        routes.add(r);
    }
    return routes;
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) ArrayList(java.util.ArrayList)

Example 25 with StaticRoute

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

the class AbstractRibTest method testLongestPrefixMatch.

/**
 * Ensure that longestPrefixMatch() returns correct routes when the RIB is non-empty
 */
@Test
public void testLongestPrefixMatch() {
    List<StaticRoute> routes = setupOverlappingRoutes();
    // Assertions
    Set<StaticRoute> match = _rib.longestPrefixMatch(new Ip("10.1.1.1"));
    assertThat(match, hasSize(1));
    assertThat(match, contains(routes.get(3)));
    match = _rib.longestPrefixMatch(new Ip("10.1.1.2"));
    assertThat(match, hasSize(1));
    assertThat(match, contains(routes.get(1)));
    match = _rib.longestPrefixMatch(new Ip("11.1.1.1"));
    assertThat(match, is(emptyIterableOf(StaticRoute.class)));
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) Ip(org.batfish.datamodel.Ip) Test(org.junit.Test)

Aggregations

StaticRoute (org.batfish.datamodel.StaticRoute)31 Configuration (org.batfish.datamodel.Configuration)17 Interface (org.batfish.datamodel.Interface)14 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)13 Ip (org.batfish.datamodel.Ip)12 Test (org.junit.Test)10 Prefix (org.batfish.datamodel.Prefix)9 ArrayList (java.util.ArrayList)4 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)4 List (java.util.List)3 TreeSet (java.util.TreeSet)3 BatfishException (org.batfish.common.BatfishException)3 IpAccessList (org.batfish.datamodel.IpAccessList)3 NetworkFactory (org.batfish.datamodel.NetworkFactory)3 Vrf (org.batfish.datamodel.Vrf)3 BoolExpr (com.microsoft.z3.BoolExpr)2 TreeMap (java.util.TreeMap)2 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)2 CommunityList (org.batfish.datamodel.CommunityList)2 Conjunction (org.batfish.datamodel.routing_policy.expr.Conjunction)2