use of org.batfish.common.Warnings in project batfish by batfish.
the class Batfish method parseEnvironmentBgpTables.
private SortedMap<String, BgpAdvertisementsByVrf> parseEnvironmentBgpTables(SortedMap<Path, String> inputData, ParseEnvironmentBgpTablesAnswerElement answerElement) {
_logger.info("\n*** PARSING ENVIRONMENT BGP TABLES ***\n");
_logger.resetTimer();
SortedMap<String, BgpAdvertisementsByVrf> bgpTables = new TreeMap<>();
List<ParseEnvironmentBgpTableJob> jobs = new ArrayList<>();
SortedMap<String, Configuration> configurations = loadConfigurations();
for (Entry<Path, String> bgpFile : inputData.entrySet()) {
Path currentFile = bgpFile.getKey();
String fileText = bgpFile.getValue();
String hostname = currentFile.getFileName().toString();
String optionalSuffix = ".bgp";
if (hostname.endsWith(optionalSuffix)) {
hostname = hostname.substring(0, hostname.length() - optionalSuffix.length());
}
if (!configurations.containsKey(hostname)) {
continue;
}
Warnings warnings = buildWarnings(_settings);
ParseEnvironmentBgpTableJob job = new ParseEnvironmentBgpTableJob(_settings, fileText, hostname, currentFile, warnings, _bgpTablePlugins);
jobs.add(job);
}
BatfishJobExecutor.runJobsInExecutor(_settings, _logger, jobs, bgpTables, answerElement, _settings.getHaltOnParseError(), "Parse environment BGP tables");
_logger.printElapsedTime();
return bgpTables;
}
use of org.batfish.common.Warnings in project batfish by batfish.
the class ConvertConfigurationJob method call.
@Override
public ConvertConfigurationResult call() {
long startTime = System.currentTimeMillis();
long elapsedTime;
_logger.infof("Processing: \"%s\"", _name);
Map<String, Configuration> configurations = new HashMap<>();
Map<String, Warnings> warningsByHost = new HashMap<>();
ConvertConfigurationAnswerElement answerElement = new ConvertConfigurationAnswerElement();
try {
// We have only two options: AWS VPCs or router configs
if (VendorConfiguration.class.isInstance(_configObject)) {
Warnings warnings = Batfish.buildWarnings(_settings);
VendorConfiguration vendorConfiguration = ((VendorConfiguration) _configObject);
vendorConfiguration.setWarnings(warnings);
vendorConfiguration.setAnswerElement(answerElement);
Configuration configuration = vendorConfiguration.toVendorIndependentConfiguration();
if (configuration.getDefaultCrossZoneAction() == null) {
throw new BatfishException("Implementation error: missing default cross-zone action for host: '" + configuration.getHostname() + "'");
}
if (configuration.getDefaultInboundAction() == null) {
throw new BatfishException("Implementation error: missing default inbound action for host: '" + configuration.getHostname() + "'");
}
// get iptables if applicable
IptablesVendorConfiguration iptablesConfig = null;
VendorConfiguration ov = vendorConfiguration.getOverlayConfiguration();
if (ov != null) {
// apply overlay
HostConfiguration oh = (HostConfiguration) ov;
iptablesConfig = oh.getIptablesVendorConfig();
} else if (vendorConfiguration instanceof HostConfiguration) {
// TODO: To enable below, we need to reconcile overlay and non-overlay iptables semantics.
// HostConfiguration oh = (HostConfiguration)vendorConfiguration;
// iptablesConfig = oh.getIptablesVendorConfig();
}
if (iptablesConfig != null) {
iptablesConfig.addAsIpAccessLists(configuration, vendorConfiguration, warnings);
iptablesConfig.applyAsOverlay(configuration, warnings);
}
configurations.put(_name, configuration);
warningsByHost.put(_name, warnings);
} else {
configurations = ((AwsConfiguration) _configObject).toConfigurations(_settings, warningsByHost);
}
_logger.info(" ...OK\n");
} catch (Exception e) {
String error = "Conversion error for node with hostname '" + _name + "'";
elapsedTime = System.currentTimeMillis() - startTime;
return new ConvertConfigurationResult(elapsedTime, _logger.getHistory(), _name, new BatfishException(error, e));
} finally {
warningsByHost.forEach((hostname, warnings) -> Batfish.logWarnings(_logger, warnings));
;
}
elapsedTime = System.currentTimeMillis() - startTime;
return new ConvertConfigurationResult(elapsedTime, _logger.getHistory(), warningsByHost, _name, configurations, answerElement);
}
use of org.batfish.common.Warnings in project batfish by batfish.
the class Region method toConfigurationNodes.
public void toConfigurationNodes(AwsConfiguration awsConfiguration, Map<String, Configuration> configurationNodes) {
// updates the Ips which have been allocated already in subnets of all interfaces
updateAllocatedIps();
for (Vpc vpc : getVpcs().values()) {
Warnings warnings = Batfish.buildWarnings(awsConfiguration.getSettings());
Configuration cfgNode = vpc.toConfigurationNode(awsConfiguration, this, warnings);
configurationNodes.put(cfgNode.getName(), cfgNode);
awsConfiguration.getWarningsByHost().put(cfgNode.getName(), warnings);
}
for (ElasticsearchDomain elasticsearchDomain : getElasticSearchDomains().values()) {
Warnings warnings = Batfish.buildWarnings(awsConfiguration.getSettings());
Configuration cfgNode = elasticsearchDomain.toConfigurationNode(awsConfiguration, this, warnings);
cfgNode.setDeviceType(DeviceType.HOST);
configurationNodes.put(cfgNode.getName(), cfgNode);
awsConfiguration.getWarningsByHost().put(cfgNode.getName(), warnings);
}
for (InternetGateway igw : getInternetGateways().values()) {
Warnings warnings = Batfish.buildWarnings(awsConfiguration.getSettings());
Configuration cfgNode = igw.toConfigurationNode(awsConfiguration, this, warnings);
configurationNodes.put(cfgNode.getName(), cfgNode);
awsConfiguration.getWarningsByHost().put(cfgNode.getName(), warnings);
}
for (NatGateway ngw : getNatGateways().values()) {
Warnings warnings = Batfish.buildWarnings(awsConfiguration.getSettings());
warnings.redFlag("NAT functionality not yet implemented for " + ngw.getId());
Configuration cfgNode = ngw.toConfigurationNode(awsConfiguration, this, warnings);
configurationNodes.put(cfgNode.getName(), cfgNode);
awsConfiguration.getWarningsByHost().put(cfgNode.getName(), warnings);
}
for (VpnGateway vgw : getVpnGateways().values()) {
Warnings warnings = Batfish.buildWarnings(awsConfiguration.getSettings());
Configuration cfgNode = vgw.toConfigurationNode(awsConfiguration, this, warnings);
configurationNodes.put(cfgNode.getName(), cfgNode);
awsConfiguration.getWarningsByHost().put(cfgNode.getName(), warnings);
}
for (Instance instance : getInstances().values()) {
Warnings warnings = Batfish.buildWarnings(awsConfiguration.getSettings());
Configuration cfgNode = instance.toConfigurationNode(awsConfiguration, this, warnings);
cfgNode.setDeviceType(DeviceType.HOST);
configurationNodes.put(cfgNode.getName(), cfgNode);
awsConfiguration.getWarningsByHost().put(cfgNode.getName(), warnings);
}
for (RdsInstance rdsInstance : getRdsInstances().values()) {
Warnings warnings = Batfish.buildWarnings(awsConfiguration.getSettings());
Configuration cfgNode = rdsInstance.toConfigurationNode(awsConfiguration, this, warnings);
cfgNode.setDeviceType(DeviceType.HOST);
configurationNodes.put(cfgNode.getName(), cfgNode);
awsConfiguration.getWarningsByHost().put(cfgNode.getName(), warnings);
}
for (Subnet subnet : getSubnets().values()) {
Warnings warnings = Batfish.buildWarnings(awsConfiguration.getSettings());
Configuration cfgNode = subnet.toConfigurationNode(awsConfiguration, this, warnings);
configurationNodes.put(cfgNode.getName(), cfgNode);
awsConfiguration.getWarningsByHost().put(cfgNode.getName(), warnings);
}
for (VpnConnection vpnConnection : getVpnConnections().values()) {
Warnings warnings = Batfish.buildWarnings(awsConfiguration.getSettings());
vpnConnection.applyToVpnGateway(awsConfiguration, this, warnings);
awsConfiguration.getWarningsByHost().put(vpnConnection.getId(), warnings);
}
applySecurityGroupsAcls(configurationNodes);
// TODO: for now, set all interfaces to have the same bandwidth
for (Configuration cfgNode : configurationNodes.values()) {
for (Vrf vrf : cfgNode.getVrfs().values()) {
for (Interface iface : vrf.getInterfaces().values()) {
iface.setBandwidth(1E12d);
}
}
}
}
use of org.batfish.common.Warnings in project batfish by batfish.
the class RoutingPolicyTests method initializeFactory.
@Before
public void initializeFactory() {
NetworkFactory nf = new NetworkFactory();
_c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build();
_rpb = nf.routingPolicyBuilder().setOwner(_c);
_w = new Warnings();
_w.setRedFlagRecord(true);
}
use of org.batfish.common.Warnings in project batfish by batfish.
the class Batfish method mergeInitStepAnswer.
private void mergeInitStepAnswer(InitInfoAnswerElement initInfoAnswerElement, InitStepAnswerElement initStepAnswerElement, boolean summary, boolean verboseError) {
if (!summary) {
if (verboseError) {
SortedMap<String, List<BatfishStackTrace>> errors = initInfoAnswerElement.getErrors();
initStepAnswerElement.getErrors().forEach((hostname, initStepErrors) -> {
errors.computeIfAbsent(hostname, k -> new ArrayList<>()).add(initStepErrors);
});
}
SortedMap<String, Warnings> warnings = initInfoAnswerElement.getWarnings();
initStepAnswerElement.getWarnings().forEach((hostname, initStepWarnings) -> {
Warnings combined = warnings.computeIfAbsent(hostname, h -> buildWarnings(_settings));
combined.getPedanticWarnings().addAll(initStepWarnings.getPedanticWarnings());
combined.getRedFlagWarnings().addAll(initStepWarnings.getRedFlagWarnings());
combined.getUnimplementedWarnings().addAll(initStepWarnings.getUnimplementedWarnings());
});
}
}
Aggregations