use of org.batfish.common.BatfishException in project batfish by batfish.
the class CiscoControlPlaneExtractor method toRoutePolicyPrefixSet.
private RoutePolicyPrefixSet toRoutePolicyPrefixSet(Rp_prefix_setContext ctx) {
if (ctx.name != null) {
// named
String name = ctx.name.getText();
int expressionLine = ctx.name.getStart().getLine();
return new RoutePolicyPrefixSetName(name, expressionLine);
} else {
// inline
PrefixSpace prefixSpace = new PrefixSpace();
Prefix6Space prefix6Space = new Prefix6Space();
boolean ipv6 = false;
for (Prefix_set_elemContext pctxt : ctx.elems) {
int lower;
int upper;
Prefix prefix = null;
Prefix6 prefix6 = null;
if (pctxt.prefix != null) {
prefix = Prefix.parse(pctxt.prefix.getText());
lower = prefix.getPrefixLength();
upper = Prefix.MAX_PREFIX_LENGTH;
} else if (pctxt.ipa != null) {
prefix = new Prefix(toIp(pctxt.ipa), Prefix.MAX_PREFIX_LENGTH);
lower = prefix.getPrefixLength();
upper = Prefix.MAX_PREFIX_LENGTH;
} else if (pctxt.ipv6a != null) {
prefix6 = new Prefix6(toIp6(pctxt.ipv6a), Prefix6.MAX_PREFIX_LENGTH);
lower = prefix6.getPrefixLength();
upper = Prefix6.MAX_PREFIX_LENGTH;
} else if (pctxt.ipv6_prefix != null) {
prefix6 = new Prefix6(pctxt.ipv6_prefix.getText());
lower = prefix6.getPrefixLength();
upper = Prefix6.MAX_PREFIX_LENGTH;
} else {
throw new BatfishException("Unhandled alternative");
}
if (pctxt.minpl != null) {
lower = toInteger(pctxt.minpl);
}
if (pctxt.maxpl != null) {
upper = toInteger(pctxt.maxpl);
}
if (pctxt.eqpl != null) {
lower = toInteger(pctxt.eqpl);
upper = lower;
}
if (prefix != null) {
prefixSpace.addPrefixRange(new PrefixRange(prefix, new SubRange(lower, upper)));
} else {
prefix6Space.addPrefix6Range(new Prefix6Range(prefix6, new SubRange(lower, upper)));
ipv6 = true;
}
}
if (ipv6) {
return new RoutePolicyInlinePrefix6Set(prefix6Space);
} else {
return new RoutePolicyInlinePrefixSet(prefixSpace);
}
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class CiscoControlPlaneExtractor method enterRo_area.
@Override
public void enterRo_area(Ro_areaContext ctx) {
long area;
if (ctx.area_int != null) {
area = toLong(ctx.area_int);
} else if (ctx.area_ip != null) {
area = toIp(ctx.area_ip).asLong();
} else {
throw new BatfishException("Missing area");
}
_currentOspfArea = area;
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class BatfishJobExecutor method executeJobs.
/**
* @param jobs jobs to be executed, of type {@link JobT}
* @param output data structure to which the result of the job will be applied, it should be of
* generic type {@link OutputT}
* @param answerElement {@link AnswerElement} containing the detail of the jobs executed
* @param haltOnProcessingError whether to halt on processing error
* @param description description of the jobs submitted to the executor
* @param <JobT> type of job executed in the executor
* @param <AnswerElementT> type of {@link AnswerElement} to which {@link BatfishJobResult} will be
* applied
* @param <JobResultT> type of {@link BatfishJobResult} which will contain the result of the job
* @param <OutputT> type of data structure to which job result will be applied
*/
private <JobT extends BatfishJob<JobResultT>, AnswerElementT extends AnswerElement, JobResultT extends BatfishJobResult<OutputT, AnswerElementT>, OutputT> void executeJobs(List<JobT> jobs, OutputT output, AnswerElementT answerElement, boolean haltOnProcessingError, String description) {
// Initializing executors
ExecutorService pool = createExecutorService();
ExecutorCompletionService<JobResultT> completionService = new ExecutorCompletionService<>(pool);
if (!_settings.getSequential() && _settings.getShuffleJobs()) {
Collections.shuffle(jobs);
}
for (JobT job : jobs) {
completionService.submit(job);
}
initializeJobsStats(jobs, description);
boolean processingError = false;
List<BatfishException> failureCauses = new ArrayList<>();
try {
for (int i = 0; i < jobs.size(); i++) {
JobResultT result = null;
try {
// getting the result of the job
result = completionService.take().get();
} catch (InterruptedException e) {
throw new BatfishException("Job didn't finish", e);
} catch (ExecutionException e) {
throw new BatfishException(String.format("Error executing job: %s", e.getCause().getMessage()), e);
}
markJobCompleted();
boolean jobResultError = handleJobResult(result, output, answerElement, failureCauses, haltOnProcessingError);
if (jobResultError) {
processingError = true;
}
}
} finally {
pool.shutdown();
}
if (processingError) {
handleProcessingError(jobs, failureCauses, haltOnProcessingError);
} else if (!_logger.isActive(BatfishLogger.LEVEL_INFO)) {
_logger.info("All jobs executed successfully\n");
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class BatfishJobExecutor method handleProcessingError.
<JobT> void handleProcessingError(List<JobT> jobs, List<BatfishException> failureCauses, boolean haltOnProcessingError) {
int numJobs = jobs.size();
int numFailed = failureCauses.size();
int numSucceeded = numJobs - numFailed;
_logger.infof("%d jobs succeeded; %d jobs failed\n", numSucceeded, numFailed);
if (haltOnProcessingError) {
BatfishException e = new BatfishException(JOB_FAILURE_MESSAGE);
failureCauses.forEach(e::addSuppressed);
throw e;
}
}
use of org.batfish.common.BatfishException 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);
}
Aggregations