Search in sources :

Example 61 with Configuration

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

the class FlatJuniperGrammarTest method testOspfMetric.

@Test
public void testOspfMetric() throws IOException {
    Configuration config = BatfishTestUtils.parseTextConfigs(_folder, "org/batfish/grammar/juniper/testconfigs/ospfmetric").get("ospfmetric");
    OspfAreaSummary summary = config.getDefaultVrf().getOspfProcess().getAreas().get(1L).getSummaries().get(Prefix.parse("10.0.0.0/16"));
    assertThat(summary, not(isAdvertised()));
    assertThat(summary, hasMetric(123L));
    // Defaults
    summary = config.getDefaultVrf().getOspfProcess().getAreas().get(2L).getSummaries().get(Prefix.parse("10.0.0.0/16"));
    assertThat(summary, isAdvertised());
    assertThat(summary, hasMetric(nullValue()));
    // Interface override
    assertThat(config, hasInterface("fe-1/0/1.0", hasOspfCost(equalTo(17))));
}
Also used : Configuration(org.batfish.datamodel.Configuration) OspfAreaSummary(org.batfish.datamodel.OspfAreaSummary) Test(org.junit.Test)

Example 62 with Configuration

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

the class FlatJuniperGrammarTest method testInterfaceMtu.

@Test
public void testInterfaceMtu() throws IOException {
    Configuration c = parseConfig("interfaceMtu");
    /* Properly configured interfaces should be present in respective areas. */
    assertThat(c.getInterfaces().keySet(), equalTo(Collections.singleton("xe-0/0/0:0.0")));
    assertThat(c, hasInterface("xe-0/0/0:0.0", hasMtu(9000)));
}
Also used : Configuration(org.batfish.datamodel.Configuration) Test(org.junit.Test)

Example 63 with Configuration

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

the class BatfishStorageTest method loadOldConfigurationsReturnsNull.

@Test
public void loadOldConfigurationsReturnsNull() {
    ConvertConfigurationAnswerElement oldConvertAnswer = new ConvertConfigurationAnswerElement();
    oldConvertAnswer.setVersion(INCOMPATIBLE_VERSION);
    assertThat("should not be compatible with current code", Version.isCompatibleVersion("current", "old test", oldConvertAnswer.getVersion()), equalTo(false));
    String trname = "sometr";
    Map<String, Configuration> configs = new HashMap<>();
    configs.put("node1", new Configuration("node1", ConfigurationFormat.CISCO_IOS));
    _storage.storeConfigurations(configs, oldConvertAnswer, trname);
    assertThat(_storage.loadConfigurations(trname), nullValue());
}
Also used : Configuration(org.batfish.datamodel.Configuration) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 64 with Configuration

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

the class BatfishStorageTest method roundTripConfigurationsSucceeds.

@Test
public void roundTripConfigurationsSucceeds() {
    Map<String, Configuration> configs = new HashMap<>();
    configs.put("node1", new Configuration("node1", ConfigurationFormat.CISCO_IOS));
    _storage.storeConfigurations(configs, new ConvertConfigurationAnswerElement(), "sometr");
    Map<String, Configuration> deserialized = _storage.loadConfigurations("sometr");
    assertThat(deserialized, not(nullValue()));
    assertThat(deserialized.keySet(), equalTo(Sets.newHashSet("node1")));
}
Also used : Configuration(org.batfish.datamodel.Configuration) HashMap(java.util.HashMap) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) Test(org.junit.Test)

Example 65 with Configuration

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

the class BatfishTest method testOverlayIptables.

@Test
public void testOverlayIptables() throws IOException {
    SortedMap<String, String> configurationsText = new TreeMap<>();
    String[] configurationNames = new String[] { "host1.cfg" };
    String testConfigsPrefix = "org/batfish/grammar/host/testrigs/router-iptables/configs/";
    SortedMap<String, String> hostsText = new TreeMap<>();
    String[] hostNames = new String[] { "host1.json" };
    String testHostsPrefix = "org/batfish/grammar/host/testrigs/router-iptables/hosts/";
    SortedMap<String, String> iptablesFilesText = new TreeMap<>();
    String[] iptablesNames = new String[] { "host1.iptables" };
    String testIptablesPrefix = "org/batfish/grammar/host/testrigs/router-iptables/iptables/";
    for (String configurationName : configurationNames) {
        String configurationText = CommonUtil.readResource(testConfigsPrefix + configurationName);
        configurationsText.put(configurationName, configurationText);
    }
    for (String hostName : hostNames) {
        String hostText = CommonUtil.readResource(testHostsPrefix + hostName);
        hostsText.put(hostName, hostText);
    }
    for (String iptablesName : iptablesNames) {
        String iptablesText = CommonUtil.readResource(testIptablesPrefix + iptablesName);
        iptablesFilesText.put(iptablesName, iptablesText);
    }
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(configurationsText).setHostsText(hostsText).setIptablesFilesText(iptablesFilesText).build(), _folder);
    Map<String, Configuration> configurations = batfish.loadConfigurations();
    assertThat(configurations.get("host1").getInterfaces().get("Ethernet0").getIncomingFilterName(), is(notNullValue()));
}
Also used : HostConfiguration(org.batfish.representation.host.HostConfiguration) Configuration(org.batfish.datamodel.Configuration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TreeMap(java.util.TreeMap) 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