Search in sources :

Example 1 with GNS3TopologyCombinedParser

use of org.batfish.grammar.topology.GNS3TopologyCombinedParser in project batfish by batfish.

the class Batfish method parseTopology.

public Topology parseTopology(Path topologyFilePath) {
    _logger.info("*** PARSING TOPOLOGY ***\n");
    _logger.resetTimer();
    String topologyFileText = CommonUtil.readFile(topologyFilePath);
    _logger.infof("Parsing: \"%s\" ...", topologyFilePath.toAbsolutePath());
    Topology topology = null;
    if (topologyFileText.equals("")) {
        throw new BatfishException("ERROR: empty topology\n");
    } else if (topologyFileText.startsWith("autostart")) {
        BatfishCombinedParser<?, ?> parser = null;
        TopologyExtractor extractor = null;
        parser = new GNS3TopologyCombinedParser(topologyFileText, _settings);
        extractor = new GNS3TopologyExtractor();
        ParserRuleContext tree = parse(parser);
        ParseTreeWalker walker = new ParseTreeWalker();
        walker.walk(extractor, tree);
        topology = extractor.getTopology();
    } else {
        try {
            topology = BatfishObjectMapper.mapper().readValue(topologyFileText, Topology.class);
        } catch (IOException e) {
            _logger.fatal("...ERROR\n");
            throw new BatfishException("Topology format error", e);
        }
    }
    _logger.printElapsedTime();
    return topology;
}
Also used : CleanBatfishException(org.batfish.common.CleanBatfishException) BatfishException(org.batfish.common.BatfishException) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) BatfishCombinedParser(org.batfish.grammar.BatfishCombinedParser) GNS3TopologyCombinedParser(org.batfish.grammar.topology.GNS3TopologyCombinedParser) TopologyExtractor(org.batfish.grammar.topology.TopologyExtractor) GNS3TopologyExtractor(org.batfish.grammar.topology.GNS3TopologyExtractor) Topology(org.batfish.datamodel.Topology) GNS3TopologyExtractor(org.batfish.grammar.topology.GNS3TopologyExtractor) IOException(java.io.IOException) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker)

Aggregations

IOException (java.io.IOException)1 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)1 BatfishException (org.batfish.common.BatfishException)1 CleanBatfishException (org.batfish.common.CleanBatfishException)1 Topology (org.batfish.datamodel.Topology)1 BatfishCombinedParser (org.batfish.grammar.BatfishCombinedParser)1 GNS3TopologyCombinedParser (org.batfish.grammar.topology.GNS3TopologyCombinedParser)1 GNS3TopologyExtractor (org.batfish.grammar.topology.GNS3TopologyExtractor)1 TopologyExtractor (org.batfish.grammar.topology.TopologyExtractor)1