Search in sources :

Example 66 with Configuration

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);
}
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 67 with Configuration

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);
}
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 68 with Configuration

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);
}
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 69 with Configuration

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);
}
Also used : HostConfiguration(org.batfish.representation.host.HostConfiguration) Configuration(org.batfish.datamodel.Configuration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 70 with Configuration

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));
    }
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Configuration(org.batfish.datamodel.Configuration) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) IpAccessList(org.batfish.datamodel.IpAccessList) SubRange(org.batfish.datamodel.SubRange) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Aggregations

Configuration (org.batfish.datamodel.Configuration)170 Test (org.junit.Test)69 Interface (org.batfish.datamodel.Interface)55 Ip (org.batfish.datamodel.Ip)49 Vrf (org.batfish.datamodel.Vrf)45 HashMap (java.util.HashMap)44 Topology (org.batfish.datamodel.Topology)38 VendorConfiguration (org.batfish.vendor.VendorConfiguration)35 Prefix (org.batfish.datamodel.Prefix)33 Edge (org.batfish.datamodel.Edge)32 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)30 Map (java.util.Map)29 Set (java.util.Set)29 TreeMap (java.util.TreeMap)29 BatfishException (org.batfish.common.BatfishException)28 IpAccessList (org.batfish.datamodel.IpAccessList)26 ArrayList (java.util.ArrayList)25 HashSet (java.util.HashSet)25 List (java.util.List)25 SortedSet (java.util.SortedSet)24