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;
}
Aggregations