Search in sources :

Example 1 with NxosRoutingTableCombinedParser

use of org.batfish.grammar.routing_table.nxos.NxosRoutingTableCombinedParser in project batfish by batfish.

the class ParseEnvironmentRoutingTableJob method call.

@Override
public ParseEnvironmentRoutingTableResult call() {
    long startTime = System.currentTimeMillis();
    long elapsedTime;
    String currentPath = _file.toAbsolutePath().toString();
    BatfishCombinedParser<?, ?> combinedParser = null;
    ParserRuleContext tree = null;
    RoutingTableExtractor extractor = null;
    _logger.infof("Processing: '%s'\n", currentPath);
    // String relativePathStr =
    // _settings.getActiveTestrigSettings().getEnvironmentSettings().getEnvPath()
    // .relativize(_file).toString();
    RoutingTableFormat format = RoutingTableFormatDetector.identifyRoutingTableFormat(_fileText);
    switch(format) {
        case EMPTY:
            _warnings.redFlag("Empty file: '" + currentPath + "'\n");
            elapsedTime = System.currentTimeMillis() - startTime;
            return new ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, _warnings, ParseStatus.EMPTY);
        case EOS:
            EosRoutingTableCombinedParser eosRoutingTableParser = new EosRoutingTableCombinedParser(_fileText, _settings);
            combinedParser = eosRoutingTableParser;
            extractor = new EosRoutingTableExtractor(_hostname, _fileText, eosRoutingTableParser, _warnings, _batfish);
            break;
        case IOS:
            IosRoutingTableCombinedParser iosRoutingTableParser = new IosRoutingTableCombinedParser(_fileText, _settings);
            combinedParser = iosRoutingTableParser;
            extractor = new IosRoutingTableExtractor(_hostname, _fileText, iosRoutingTableParser, _warnings, _batfish);
            break;
        case NXOS:
            NxosRoutingTableCombinedParser nxosRoutingTableParser = new NxosRoutingTableCombinedParser(_fileText, _settings);
            combinedParser = nxosRoutingTableParser;
            extractor = new NxosRoutingTableExtractor(_hostname, _fileText, nxosRoutingTableParser, _warnings, _batfish);
            break;
        case UNKNOWN:
        default:
            String unknownError = "Unknown routing-table format for file: '" + currentPath + "'\n";
            if (!_settings.ignoreUnknown()) {
                elapsedTime = System.currentTimeMillis() - startTime;
                return new ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, new BatfishException(unknownError));
            } else {
                _warnings.unimplemented(unknownError);
                elapsedTime = System.currentTimeMillis() - startTime;
                return new ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, _warnings, ParseStatus.UNKNOWN);
            }
    }
    try {
        _logger.info("\tParsing...");
        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 ParseEnvironmentRoutingTableResult(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 ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, new BatfishException(error, e));
    } finally {
        Batfish.logWarnings(_logger, _warnings);
    }
    RoutesByVrf routesByVrf = extractor.getRoutesByVrf();
    elapsedTime = System.currentTimeMillis() - startTime;
    return new ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, _hostname, routesByVrf, _warnings, _ptSentences);
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) BatfishException(org.batfish.common.BatfishException) ParserBatfishException(org.batfish.main.ParserBatfishException) IosRoutingTableCombinedParser(org.batfish.grammar.routing_table.ios.IosRoutingTableCombinedParser) IosRoutingTableExtractor(org.batfish.grammar.routing_table.ios.IosRoutingTableExtractor) NxosRoutingTableExtractor(org.batfish.grammar.routing_table.nxos.NxosRoutingTableExtractor) EosRoutingTableCombinedParser(org.batfish.grammar.routing_table.eos.EosRoutingTableCombinedParser) BatfishException(org.batfish.common.BatfishException) ParserBatfishException(org.batfish.main.ParserBatfishException) ParserBatfishException(org.batfish.main.ParserBatfishException) EosRoutingTableExtractor(org.batfish.grammar.routing_table.eos.EosRoutingTableExtractor) NxosRoutingTableCombinedParser(org.batfish.grammar.routing_table.nxos.NxosRoutingTableCombinedParser) EosRoutingTableExtractor(org.batfish.grammar.routing_table.eos.EosRoutingTableExtractor) NxosRoutingTableExtractor(org.batfish.grammar.routing_table.nxos.NxosRoutingTableExtractor) IosRoutingTableExtractor(org.batfish.grammar.routing_table.ios.IosRoutingTableExtractor) RoutingTableExtractor(org.batfish.grammar.RoutingTableExtractor) RoutesByVrf(org.batfish.datamodel.collections.RoutesByVrf) RoutingTableFormat(org.batfish.grammar.RoutingTableFormat)

Aggregations

ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 BatfishException (org.batfish.common.BatfishException)1 RoutesByVrf (org.batfish.datamodel.collections.RoutesByVrf)1 RoutingTableExtractor (org.batfish.grammar.RoutingTableExtractor)1 RoutingTableFormat (org.batfish.grammar.RoutingTableFormat)1 EosRoutingTableCombinedParser (org.batfish.grammar.routing_table.eos.EosRoutingTableCombinedParser)1 EosRoutingTableExtractor (org.batfish.grammar.routing_table.eos.EosRoutingTableExtractor)1 IosRoutingTableCombinedParser (org.batfish.grammar.routing_table.ios.IosRoutingTableCombinedParser)1 IosRoutingTableExtractor (org.batfish.grammar.routing_table.ios.IosRoutingTableExtractor)1 NxosRoutingTableCombinedParser (org.batfish.grammar.routing_table.nxos.NxosRoutingTableCombinedParser)1 NxosRoutingTableExtractor (org.batfish.grammar.routing_table.nxos.NxosRoutingTableExtractor)1 ParserBatfishException (org.batfish.main.ParserBatfishException)1