Search in sources :

Example 11 with Warnings

use of org.batfish.common.Warnings in project batfish by batfish.

the class IptablesVendorConfiguration method applyAsOverlay.

public void applyAsOverlay(Configuration configuration, Warnings warnings) {
    IpAccessList prerouting = configuration.getIpAccessLists().remove("mangle::PREROUTING");
    IpAccessList postrouting = configuration.getIpAccessLists().remove("mangle::POSTROUTING");
    if (!configuration.getIpAccessLists().isEmpty()) {
        throw new BatfishException("Merging iptables rules for " + configuration.getName() + ": only mangle tables are supported");
    }
    if (prerouting != null) {
        for (Interface i : configuration.getInterfaces().values()) {
            String dbgName = configuration.getHostname() + ":" + i.getName();
            List<IpAccessListLine> newRules = prerouting.getLines().stream().filter(l -> {
                String iface = _lineInInterfaces.get(l);
                return iface == null || i.getName().equals(iface);
            }).collect(Collectors.toList());
            if (i.getIncomingFilter() != null) {
                throw new BatfishException(dbgName + " already has a filter," + " cannot combine with iptables rules!");
            }
            String aclName = "iptables_" + i.getName() + "_ingress";
            IpAccessList acl = new IpAccessList(aclName, newRules);
            if (configuration.getIpAccessLists().putIfAbsent(aclName, acl) != null) {
                throw new BatfishException(dbgName + " acl " + aclName + " already exists");
            }
            i.setIncomingFilter(acl);
        }
    }
    if (postrouting != null) {
        for (Interface i : configuration.getInterfaces().values()) {
            String dbgName = configuration.getHostname() + ":" + i.getName();
            List<IpAccessListLine> newRules = postrouting.getLines().stream().filter(l -> {
                String iface = _lineOutInterfaces.get(l);
                return iface == null || i.getName().equals(iface);
            }).collect(Collectors.toList());
            if (i.getOutgoingFilter() != null) {
                throw new BatfishException(dbgName + " already has a filter," + " cannot combine with iptables rules!");
            }
            String aclName = "iptables_" + i.getName() + "_egress";
            IpAccessList acl = new IpAccessList(aclName, newRules);
            if (configuration.getIpAccessLists().putIfAbsent(aclName, acl) != null) {
                throw new BatfishException(dbgName + " acl " + aclName + " already exists");
            }
            i.setOutgoingFilter(acl);
        }
    }
}
Also used : ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) Iterables(com.google.common.collect.Iterables) IdentityHashMap(java.util.IdentityHashMap) SortedSet(java.util.SortedSet) VendorConfiguration(org.batfish.vendor.VendorConfiguration) Set(java.util.Set) BatfishException(org.batfish.common.BatfishException) IpAccessList(org.batfish.datamodel.IpAccessList) Collectors(java.util.stream.Collectors) Interface(org.batfish.datamodel.Interface) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) Warnings(org.batfish.common.Warnings) Map(java.util.Map) Entry(java.util.Map.Entry) Configuration(org.batfish.datamodel.Configuration) LineAction(org.batfish.datamodel.LineAction) Collections(java.util.Collections) VendorConversionException(org.batfish.common.VendorConversionException) BatfishException(org.batfish.common.BatfishException) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) IpAccessList(org.batfish.datamodel.IpAccessList) Interface(org.batfish.datamodel.Interface)

Example 12 with Warnings

use of org.batfish.common.Warnings in project batfish by batfish.

the class WorkMgr method getParsingResults.

public JSONObject getParsingResults(String containerName, String testrigName) throws JsonProcessingException, JSONException {
    ParseVendorConfigurationAnswerElement pvcae = deserializeObject(getdirTestrig(containerName, testrigName).resolve(BfConsts.RELPATH_PARSE_ANSWER_PATH), ParseVendorConfigurationAnswerElement.class);
    JSONObject warnings = new JSONObject();
    SortedMap<String, Warnings> warningsMap = pvcae.getWarnings();
    ObjectWriter writer = BatfishObjectMapper.prettyWriter();
    for (String s : warningsMap.keySet()) {
        warnings.put(s, writer.writeValueAsString(warningsMap.get(s)));
    }
    return warnings;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ParseVendorConfigurationAnswerElement(org.batfish.datamodel.answers.ParseVendorConfigurationAnswerElement) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Warnings(org.batfish.common.Warnings)

Example 13 with Warnings

use of org.batfish.common.Warnings in project batfish by batfish.

the class HostInterfaceTest method setup.

@Before
public void setup() {
    _factory = new NetworkFactory();
    _c = _factory.configurationBuilder().setConfigurationFormat(ConfigurationFormat.HOST).setHostname("hostInterfaceTest").build();
    _w = new Warnings();
}
Also used : NetworkFactory(org.batfish.datamodel.NetworkFactory) Warnings(org.batfish.common.Warnings) Before(org.junit.Before)

Example 14 with Warnings

use of org.batfish.common.Warnings in project batfish by batfish.

the class HostInterfaceTest method testToInterface.

@Test
public void testToInterface() {
    String name = "eth0";
    HostInterface hi = new HostInterface(name);
    hi.setCanonicalName(name);
    Interface i = hi.toInterface(_c, new Warnings());
    /* Check defaults */
    assertThat(i, isProxyArp(equalTo(false)));
}
Also used : HostInterface(org.batfish.representation.host.HostInterface) Warnings(org.batfish.common.Warnings) HostInterface(org.batfish.representation.host.HostInterface) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Aggregations

Warnings (org.batfish.common.Warnings)14 Configuration (org.batfish.datamodel.Configuration)7 VendorConfiguration (org.batfish.vendor.VendorConfiguration)7 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 TreeMap (java.util.TreeMap)5 Interface (org.batfish.datamodel.Interface)5 IptablesVendorConfiguration (org.batfish.representation.iptables.IptablesVendorConfiguration)5 ImmutableList (com.google.common.collect.ImmutableList)4 Collections (java.util.Collections)4 Map (java.util.Map)4 BatfishException (org.batfish.common.BatfishException)4 AwsConfiguration (org.batfish.representation.aws.AwsConfiguration)4 HostConfiguration (org.batfish.representation.host.HostConfiguration)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableConfiguration (org.apache.commons.configuration2.ImmutableConfiguration)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Verify (com.google.common.base.Verify)2