use of org.batfish.datamodel.Configuration 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.Configuration 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.Configuration 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);
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class BatfishTest method testUnusableVrrpHandledCorrectly.
@Test
public void testUnusableVrrpHandledCorrectly() throws Exception {
String configurationText = String.join("\n", new String[] { "hostname host1", "!", "interface Vlan65", " vrrp 1 ip 1.2.3.4", "!" });
SortedMap<String, String> configMap = ImmutableSortedMap.of("host1", configurationText);
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(configMap).build(), _folder);
Map<String, Configuration> configs = batfish.loadConfigurations();
// Assert that the config parsed successfully
assertThat(configs, hasKey("host1"));
assertThat(configs.get("host1").getInterfaces(), hasKey("Vlan65"));
assertThat(configs.get("host1").getInterfaces().get("Vlan65").getVrrpGroups().keySet(), hasSize(1));
// Tests that computing IP owners with such a bad interface does not crash.
CommonUtil.computeIpOwners(configs, false);
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class ElasticsearchDomainTest method testSecurityGroupsAcl.
@Test
public void testSecurityGroupsAcl() throws IOException {
Map<String, Configuration> configurations = loadAwsConfigurations();
assertThat(configurations, hasKey("es-domain"));
assertThat(configurations.get("es-domain").getInterfaces().entrySet(), hasSize(2));
IpAccessListLine rejectSynOnly = IpAccessListLine.builder().setTcpFlags(ImmutableSet.of(TcpFlags.SYN_ONLY)).setAction(LineAction.REJECT).build();
IpAccessList expectedIncomingFilter = new IpAccessList("~SECURITY_GROUP_INGRESS_ACL~", Lists.newArrayList(IpAccessListLine.builder().setAction(LineAction.ACCEPT).setIpProtocols(Sets.newHashSet(IpProtocol.TCP)).setSrcIps(Sets.newHashSet(new IpWildcard("1.2.3.4/32"), new IpWildcard("10.193.16.105/32"))).setDstPorts(Sets.newHashSet(new SubRange(45, 50))).build(), rejectSynOnly, IpAccessListLine.builder().setAction(LineAction.ACCEPT).setSrcIps(Sets.newHashSet(new IpWildcard("0.0.0.0/0"))).build()));
IpAccessList expectedOutgoingFilter = new IpAccessList("~SECURITY_GROUP_EGRESS_ACL~", Lists.newArrayList(IpAccessListLine.builder().setAction(LineAction.ACCEPT).setDstIps(Sets.newHashSet(new IpWildcard("0.0.0.0/0"))).build(), rejectSynOnly, IpAccessListLine.builder().setAction(LineAction.ACCEPT).setIpProtocols(Sets.newHashSet(IpProtocol.TCP)).setDstIps(Sets.newHashSet(new IpWildcard("1.2.3.4/32"), new IpWildcard("10.193.16.105/32"))).setSrcPorts(Sets.newHashSet(new SubRange(45, 50))).build()));
for (Interface iface : configurations.get("es-domain").getInterfaces().values()) {
assertThat(iface.getIncomingFilter(), equalTo(expectedIncomingFilter));
assertThat(iface.getOutgoingFilter(), equalTo(expectedOutgoingFilter));
}
}
Aggregations