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