Search in sources :

Example 1 with BgpTableFormat

use of org.batfish.grammar.BgpTableFormat in project batfish by batfish.

the class ParseEnvironmentBgpTableJob method call.

@Override
public ParseEnvironmentBgpTableResult call() {
    long startTime = System.currentTimeMillis();
    long elapsedTime;
    String currentPath = _file.toAbsolutePath().toString();
    ParserRuleContext tree = null;
    _logger.infof("Processing: '%s'\n", currentPath);
    // String relativePathStr =
    // _settings.getActiveTestrigSettings().getEnvironmentSettings().getEnvPath()
    // .relativize(_file).toString();
    BgpTablePlugin plugin = null;
    BgpTableFormat format = BgpTableFormatDetector.identifyBgpTableFormat(_fileText);
    switch(format) {
        case EMPTY:
            _warnings.redFlag("Empty file: '" + currentPath + "'\n");
            elapsedTime = System.currentTimeMillis() - startTime;
            return new ParseEnvironmentBgpTableResult(elapsedTime, _logger.getHistory(), _file, _warnings, ParseStatus.EMPTY);
        case UNKNOWN:
            String unknownError = "Unknown bgp-table format for file: '" + currentPath + "'\n";
            if (!_settings.ignoreUnknown()) {
                elapsedTime = System.currentTimeMillis() - startTime;
                return new ParseEnvironmentBgpTableResult(elapsedTime, _logger.getHistory(), _file, new BatfishException(unknownError));
            } else {
                _warnings.unimplemented(unknownError);
                elapsedTime = System.currentTimeMillis() - startTime;
                return new ParseEnvironmentBgpTableResult(elapsedTime, _logger.getHistory(), _file, _warnings, ParseStatus.UNKNOWN);
            }
        // $CASES-OMITTED$
        default:
            break;
    }
    plugin = _bgpTablePlugins.get(format);
    if (plugin == null) {
        String unsupportedError = "Unsupported bgp-table format: '" + format.bgpTableFormatName() + "' for file: '" + currentPath + "'\n";
        if (!_settings.ignoreUnsupported()) {
            elapsedTime = System.currentTimeMillis() - startTime;
            return new ParseEnvironmentBgpTableResult(elapsedTime, _logger.getHistory(), _file, new BatfishException(unsupportedError));
        } else {
            _warnings.unimplemented(unsupportedError);
            elapsedTime = System.currentTimeMillis() - startTime;
            return new ParseEnvironmentBgpTableResult(elapsedTime, _logger.getHistory(), _file, _warnings, ParseStatus.UNSUPPORTED);
        }
    }
    BgpTableExtractor extractor;
    try {
        _logger.info("\tParsing...");
        BatfishCombinedParser<?, ?> combinedParser = plugin.parser(_fileText, _settings);
        extractor = plugin.extractor(_hostname, _fileText, combinedParser, _warnings);
        tree = Batfish.parse(combinedParser, _logger, _settings);
        if (_settings.getPrintParseTree()) {
            _ptSentences = ParseTreePrettyPrinter.getParseTreeSentences(tree, combinedParser);
        }
        _logger.info("\tPost-processing...");
        extractor.processParseTree(tree);
        _logger.info("OK\n");
    } catch (ParserBatfishException e) {
        String error = "Error parsing configuration file: '" + currentPath + "'";
        elapsedTime = System.currentTimeMillis() - startTime;
        return new ParseEnvironmentBgpTableResult(elapsedTime, _logger.getHistory(), _file, new BatfishException(error, e));
    } catch (Exception e) {
        String error = "Error post-processing parse tree of configuration file: '" + currentPath + "'";
        elapsedTime = System.currentTimeMillis() - startTime;
        return new ParseEnvironmentBgpTableResult(elapsedTime, _logger.getHistory(), _file, new BatfishException(error, e));
    } finally {
        Batfish.logWarnings(_logger, _warnings);
    }
    BgpAdvertisementsByVrf bgpAdvertisementsByVrf = extractor.getBgpAdvertisementsByVrf();
    elapsedTime = System.currentTimeMillis() - startTime;
    return new ParseEnvironmentBgpTableResult(elapsedTime, _logger.getHistory(), _file, _hostname, bgpAdvertisementsByVrf, _warnings, _ptSentences);
}
Also used : ParserBatfishException(org.batfish.main.ParserBatfishException) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) BatfishException(org.batfish.common.BatfishException) ParserBatfishException(org.batfish.main.ParserBatfishException) BgpTableFormat(org.batfish.grammar.BgpTableFormat) BgpTablePlugin(org.batfish.common.plugin.BgpTablePlugin) BgpTableExtractor(org.batfish.grammar.BgpTableExtractor) BatfishException(org.batfish.common.BatfishException) ParserBatfishException(org.batfish.main.ParserBatfishException) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf)

Aggregations

ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 BatfishException (org.batfish.common.BatfishException)1 BgpTablePlugin (org.batfish.common.plugin.BgpTablePlugin)1 BgpAdvertisementsByVrf (org.batfish.datamodel.collections.BgpAdvertisementsByVrf)1 BgpTableExtractor (org.batfish.grammar.BgpTableExtractor)1 BgpTableFormat (org.batfish.grammar.BgpTableFormat)1 ParserBatfishException (org.batfish.main.ParserBatfishException)1