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