Search in sources :

Example 6 with Topology

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

the class Batfish method computeTestrigTopology.

private Topology computeTestrigTopology(Path testRigPath, Map<String, Configuration> configurations) {
    Path topologyFilePath = testRigPath.resolve(TOPOLOGY_FILENAME);
    Topology topology;
    // Get generated facts from topology file
    if (Files.exists(topologyFilePath)) {
        topology = processTopologyFile(topologyFilePath);
        _logger.infof("Testrig:%s in container:%s has topology file", getTestrigName(), getContainerName());
    } else {
        // guess adjacencies based on interface subnetworks
        _logger.info("*** (GUESSING TOPOLOGY IN ABSENCE OF EXPLICIT FILE) ***\n");
        topology = CommonUtil.synthesizeTopology(configurations);
    }
    return topology;
}
Also used : Path(java.nio.file.Path) Topology(org.batfish.datamodel.Topology)

Example 7 with Topology

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

the class RouteReflectionTest method generateRoutesTwoReflectors.

private SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> generateRoutesTwoReflectors(boolean useSameClusterIds) {
    Ip as1PeeringIp = new Ip("10.12.11.1");
    Ip edge1EbgpIfaceIp = new Ip("10.12.11.2");
    Ip edge1IbgpIfaceIp = new Ip("10.1.12.1");
    Ip edge1LoopbackIp = new Ip("2.0.0.1");
    Ip rr1Edge1IfaceIp = new Ip("10.1.12.2");
    Ip rr1Rr2IfaceIp = new Ip("10.1.23.2");
    Ip rr1LoopbackIp = new Ip("2.0.0.2");
    Ip rr2IbgpIfaceIp = new Ip("10.1.23.3");
    Ip rr2LoopbackIp = new Ip("2.0.0.3");
    StaticRoute.Builder sb = StaticRoute.builder();
    Configuration edge1 = _cb.setHostname(EDGE1_NAME).build();
    Vrf vEdge1 = _vb.setOwner(edge1).build();
    _ib.setOwner(edge1).setVrf(vEdge1);
    _ib.setAddress(new InterfaceAddress(edge1EbgpIfaceIp, EDGE_PREFIX_LENGTH)).build();
    _ib.setAddress(new InterfaceAddress(edge1LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build();
    _ib.setAddress(new InterfaceAddress(edge1IbgpIfaceIp, EDGE_PREFIX_LENGTH)).build();
    vEdge1.setStaticRoutes(ImmutableSortedSet.of(sb.setNextHopIp(rr1Edge1IfaceIp).setNetwork(new Prefix(rr1LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build()));
    BgpProcess edge1Proc = _pb.setRouterId(edge1LoopbackIp).setVrf(vEdge1).build();
    RoutingPolicy edge1EbgpExportPolicy = _nullExportPolicyBuilder.setOwner(edge1).build();
    _nb.setOwner(edge1).setVrf(vEdge1).setBgpProcess(edge1Proc).setClusterId(edge1LoopbackIp.asLong()).setRemoteAs(1).setLocalIp(edge1EbgpIfaceIp).setPeerAddress(as1PeeringIp).setExportPolicy(edge1EbgpExportPolicy.getName()).build();
    RoutingPolicy edge1IbgpExportPolicy = _defaultExportPolicyBuilder.setOwner(edge1).build();
    _nb.setRemoteAs(2).setLocalIp(edge1LoopbackIp).setPeerAddress(rr1LoopbackIp).setExportPolicy(edge1IbgpExportPolicy.getName()).build();
    Configuration rr1 = _cb.setHostname(RR1_NAME).build();
    Vrf vRr1 = _vb.setOwner(rr1).build();
    _ib.setOwner(rr1).setVrf(vRr1);
    _ib.setAddress(new InterfaceAddress(rr1Edge1IfaceIp, EDGE_PREFIX_LENGTH)).build();
    _ib.setAddress(new InterfaceAddress(rr1LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build();
    _ib.setAddress(new InterfaceAddress(rr1Rr2IfaceIp, EDGE_PREFIX_LENGTH)).build();
    vRr1.setStaticRoutes(ImmutableSortedSet.of(sb.setNextHopIp(edge1IbgpIfaceIp).setNetwork(new Prefix(edge1LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build(), sb.setNextHopIp(rr2IbgpIfaceIp).setNetwork(new Prefix(rr2LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build()));
    BgpProcess rr1Proc = _pb.setRouterId(rr1LoopbackIp).setVrf(vRr1).build();
    RoutingPolicy rr1ExportPolicy = _defaultExportPolicyBuilder.setOwner(rr1).build();
    _nb.setOwner(rr1).setVrf(vRr1).setBgpProcess(rr1Proc).setClusterId(rr1LoopbackIp.asLong()).setRemoteAs(2).setLocalIp(rr1LoopbackIp).setExportPolicy(rr1ExportPolicy.getName()).setRouteReflectorClient(true).setPeerAddress(edge1LoopbackIp).build();
    _nb.setRouteReflectorClient(false).setPeerAddress(rr2LoopbackIp).build();
    Configuration rr2 = _cb.setHostname(RR2_NAME).build();
    Vrf vRr2 = _vb.setOwner(rr2).build();
    _ib.setOwner(rr2).setVrf(vRr2);
    _ib.setAddress(new InterfaceAddress(rr2LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build();
    _ib.setAddress(new InterfaceAddress(rr2IbgpIfaceIp, EDGE_PREFIX_LENGTH)).build();
    BgpProcess rr2Proc = _pb.setRouterId(rr2LoopbackIp).setVrf(vRr2).build();
    RoutingPolicy edge2IbgpExportPolicy = _defaultExportPolicyBuilder.setOwner(rr2).build();
    vRr2.setStaticRoutes(ImmutableSortedSet.of(sb.setNextHopIp(rr1Rr2IfaceIp).setNetwork(new Prefix(rr1LoopbackIp, Prefix.MAX_PREFIX_LENGTH)).build()));
    Ip rr2ClusterIdForRr1 = useSameClusterIds ? rr1LoopbackIp : rr2LoopbackIp;
    _nb.setOwner(rr2).setVrf(vRr2).setBgpProcess(rr2Proc).setClusterId(rr2ClusterIdForRr1.asLong()).setLocalIp(rr2LoopbackIp).setPeerAddress(rr1LoopbackIp).setRouteReflectorClient(true).setExportPolicy(edge2IbgpExportPolicy.getName()).build();
    SortedMap<String, Configuration> configurations = new ImmutableSortedMap.Builder<String, Configuration>(String::compareTo).put(edge1.getName(), edge1).put(rr1.getName(), rr1).put(rr2.getName(), rr2).build();
    BdpEngine engine = new BdpEngine(new MockBdpSettings(), new BatfishLogger(BatfishLogger.LEVELSTR_OUTPUT, false), (s, i) -> new AtomicInteger());
    Topology topology = CommonUtil.synthesizeTopology(configurations);
    BdpDataPlane dp = engine.computeDataPlane(false, configurations, topology, ImmutableSet.of(_ab.setAsPath(AsPath.ofSingletonAsSets(1)).setDstIp(edge1EbgpIfaceIp).setDstNode(edge1.getName()).setNetwork(AS1_PREFIX).setNextHopIp(as1PeeringIp).setOriginatorIp(as1PeeringIp).setSrcIp(as1PeeringIp).setSrcNode("as1Edge").build()), new BdpAnswerElement());
    return engine.getRoutes(dp);
}
Also used : StaticRoute(org.batfish.datamodel.StaticRoute) BdpAnswerElement(org.batfish.datamodel.answers.BdpAnswerElement) Configuration(org.batfish.datamodel.Configuration) BatfishLogger(org.batfish.common.BatfishLogger) BgpProcess(org.batfish.datamodel.BgpProcess) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) Ip(org.batfish.datamodel.Ip) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Vrf(org.batfish.datamodel.Vrf) AbstractRouteMatchers.hasPrefix(org.batfish.datamodel.matchers.AbstractRouteMatchers.hasPrefix) Prefix(org.batfish.datamodel.Prefix) Topology(org.batfish.datamodel.Topology) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 8 with Topology

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

the class BatfishTest method testCheckTopologyInvalidNode.

@Test
public void testCheckTopologyInvalidNode() {
    Map<String, Configuration> configs = new HashMap<>();
    configs.put("h1", BatfishTestUtils.createTestConfiguration("h1", ConfigurationFormat.HOST, "eth0"));
    SortedSet<Edge> edges = new TreeSet<>(Collections.singletonList(new Edge("h1", "eth0", "h2", "e0")));
    Topology topology = new Topology(edges);
    _thrown.expect(BatfishException.class);
    _thrown.expectMessage("Topology contains a non-existent node 'h2'");
    Batfish.checkTopology(configs, topology);
}
Also used : HostConfiguration(org.batfish.representation.host.HostConfiguration) Configuration(org.batfish.datamodel.Configuration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Topology(org.batfish.datamodel.Topology) Edge(org.batfish.datamodel.Edge) Test(org.junit.Test)

Example 9 with Topology

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

the class BatfishTest method testCheckTopologyInvalidInterface.

@Test
public void testCheckTopologyInvalidInterface() {
    Map<String, Configuration> configs = new HashMap<>();
    configs.put("h1", BatfishTestUtils.createTestConfiguration("h1", ConfigurationFormat.HOST, "eth0"));
    configs.put("h2", BatfishTestUtils.createTestConfiguration("h2", ConfigurationFormat.HOST, "e0"));
    SortedSet<Edge> edges = new TreeSet<>(Collections.singletonList(new Edge("h1", "eth1", "h2", "e0")));
    Topology topology = new Topology(edges);
    _thrown.expect(BatfishException.class);
    _thrown.expectMessage("Topology contains a non-existent interface 'eth1' on node 'h1'");
    Batfish.checkTopology(configs, topology);
}
Also used : HostConfiguration(org.batfish.representation.host.HostConfiguration) Configuration(org.batfish.datamodel.Configuration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Topology(org.batfish.datamodel.Topology) Edge(org.batfish.datamodel.Edge) Test(org.junit.Test)

Example 10 with Topology

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

the class BatfishTest method testCheckValidTopology.

@Test
public void testCheckValidTopology() {
    Map<String, Configuration> configs = new HashMap<>();
    configs.put("h1", BatfishTestUtils.createTestConfiguration("h1", ConfigurationFormat.HOST, "eth0"));
    configs.put("h2", BatfishTestUtils.createTestConfiguration("h2", ConfigurationFormat.HOST, "e0"));
    SortedSet<Edge> edges = new TreeSet<>(Collections.singletonList(new Edge("h1", "eth0", "h2", "e0")));
    Topology topology = new Topology(edges);
    // test that checkTopology does not throw
    Batfish.checkTopology(configs, topology);
}
Also used : HostConfiguration(org.batfish.representation.host.HostConfiguration) Configuration(org.batfish.datamodel.Configuration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Topology(org.batfish.datamodel.Topology) Edge(org.batfish.datamodel.Edge) Test(org.junit.Test)

Aggregations

Topology (org.batfish.datamodel.Topology)35 Configuration (org.batfish.datamodel.Configuration)27 Test (org.junit.Test)19 Edge (org.batfish.datamodel.Edge)17 Vrf (org.batfish.datamodel.Vrf)17 Interface (org.batfish.datamodel.Interface)13 Ip (org.batfish.datamodel.Ip)10 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)8 HashMap (java.util.HashMap)7 SynthesizerInputMatchers.hasArpTrueEdge (org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge)7 Set (java.util.Set)6 SortedSet (java.util.SortedSet)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 BatfishLogger (org.batfish.common.BatfishLogger)6 BdpAnswerElement (org.batfish.datamodel.answers.BdpAnswerElement)6 Map (java.util.Map)5 SortedMap (java.util.SortedMap)5 TreeSet (java.util.TreeSet)5 IpAccessList (org.batfish.datamodel.IpAccessList)5 NodeInterfacePair (org.batfish.datamodel.collections.NodeInterfacePair)5