public Set<Flow> computeCompositeNodOutput( List<CompositeNodJob> jobs, NodAnswerElement answerElement) { _logger.info("\n*** EXECUTING COMPOSITE NOD JOBS ***\n"); _logger.resetTimer(); Set<Flow> flows = new TreeSet<>(); BatfishJobExecutor.runJobsInExecutor( _settings, _logger, jobs, flows, answerElement, true, "Composite NOD"); _logger.printElapsedTime(); return flows; }
private SortedMap<String, RoutesByVrf> deserializeEnvironmentRoutingTables( Path serializeEnvironmentRoutingTablesPath) { _logger.info("\n*** DESERIALIZING ENVIRONMENT ROUTING TABLES ***\n"); _logger.resetTimer(); Map<Path, String> namesByPath = new TreeMap<>(); try (DirectoryStream<Path> serializedRoutingTables = Files.newDirectoryStream(serializeEnvironmentRoutingTablesPath)) { for (Path serializedRoutingTable : serializedRoutingTables) { String name = serializedRoutingTable.getFileName().toString(); namesByPath.put(serializedRoutingTable, name); } } catch (IOException e) { throw new BatfishException("Error reading serialized routing tables directory", e); } SortedMap<String, RoutesByVrf> routingTables = deserializeObjects(namesByPath, RoutesByVrf.class); _logger.printElapsedTime(); return routingTables; }
public Map<String, GenericConfigObject> deserializeVendorConfigurations( Path serializedVendorConfigPath) { _logger.info("\n*** DESERIALIZING VENDOR CONFIGURATION STRUCTURES ***\n"); _logger.resetTimer(); Map<Path, String> namesByPath = new TreeMap<>(); try (DirectoryStream<Path> serializedConfigs = Files.newDirectoryStream(serializedVendorConfigPath)) { for (Path serializedConfig : serializedConfigs) { String name = serializedConfig.getFileName().toString(); namesByPath.put(serializedConfig, name); } } catch (IOException e) { throw new BatfishException("Error reading vendor configs directory", e); } Map<String, GenericConfigObject> vendorConfigurations = deserializeObjects(namesByPath, GenericConfigObject.class); _logger.printElapsedTime(); return vendorConfigurations; }
private void serializeEnvironmentRoutingTables( SortedMap<String, RoutesByVrf> routingTables, Path outputPath) { if (routingTables == null) { throw new BatfishException("Exiting due to parsing error(s)"); } _logger.info("\n*** SERIALIZING ENVIRONMENT ROUTING TABLES ***\n"); _logger.resetTimer(); outputPath.toFile().mkdirs(); SortedMap<Path, RoutesByVrf> output = new TreeMap<>(); routingTables.forEach( (name, rt) -> { Path currentOutputPath = outputPath.resolve(name); output.put(currentOutputPath, rt); }); serializeObjects(output); _logger.printElapsedTime(); }
private SortedMap<String, BgpAdvertisementsByVrf> deserializeEnvironmentBgpTables( Path serializeEnvironmentBgpTablesPath) { _logger.info("\n*** DESERIALIZING ENVIRONMENT BGP TABLES ***\n"); _logger.resetTimer(); Map<Path, String> namesByPath = new TreeMap<>(); try (DirectoryStream<Path> serializedBgpTables = Files.newDirectoryStream(serializeEnvironmentBgpTablesPath)) { for (Path serializedBgpTable : serializedBgpTables) { String name = serializedBgpTable.getFileName().toString(); namesByPath.put(serializedBgpTable, name); } } catch (IOException e) { throw new BatfishException("Error reading serialized BGP tables directory", e); } SortedMap<String, BgpAdvertisementsByVrf> bgpTables = deserializeObjects(namesByPath, BgpAdvertisementsByVrf.class); _logger.printElapsedTime(); return bgpTables; }
private SortedMap<Path, String> readFiles(Path directory, String description) { _logger.infof("\n*** READING FILES: %s ***\n", description); _logger.resetTimer(); SortedMap<Path, String> fileData = new TreeMap<>(); List<Path> filePaths; try (Stream<Path> paths = CommonUtil.list(directory)) { filePaths = paths .filter(path -> !path.getFileName().toString().startsWith(".")) .sorted() .collect(Collectors.toList()); } AtomicInteger completed = newBatch("Reading files: " + description, filePaths.size()); for (Path file : filePaths) { _logger.debugf("Reading: \"%s\"\n", file); String fileTextRaw = CommonUtil.readFile(file.toAbsolutePath()); String fileText = fileTextRaw + ((fileTextRaw.length() != 0) ? "\n" : ""); fileData.put(file, fileText); completed.incrementAndGet(); } _logger.printElapsedTime(); return fileData; }
private void serializeEnvironmentBgpTables( SortedMap<String, BgpAdvertisementsByVrf> bgpTables, Path outputPath) { if (bgpTables == null) { throw new BatfishException("Exiting due to parsing error(s)"); } _logger.info("\n*** SERIALIZING ENVIRONMENT BGP TABLES ***\n"); _logger.resetTimer(); outputPath.toFile().mkdirs(); SortedMap<Path, BgpAdvertisementsByVrf> output = new TreeMap<>(); bgpTables.forEach( (name, rt) -> { Path currentOutputPath = outputPath.resolve(name); output.put(currentOutputPath, rt); }); serializeObjects(output); _logger.printElapsedTime(); }
private SortedMap<Path, String> readConfigurationFiles(Path testRigPath, String configsType) { _logger.infof("\n*** READING %s FILES ***\n", configsType); _logger.resetTimer(); SortedMap<Path, String> configurationData = new TreeMap<>(); Path configsPath = testRigPath.resolve(configsType); List<Path> configFilePaths = listAllFiles(configsPath); AtomicInteger completed = newBatch("Reading network configuration files", configFilePaths.size()); for (Path file : configFilePaths) { _logger.debugf("Reading: \"%s\"\n", file); String fileTextRaw = CommonUtil.readFile(file.toAbsolutePath()); String fileText = fileTextRaw + ((fileTextRaw.length() != 0) ? "\n" : ""); configurationData.put(file, fileText); completed.incrementAndGet(); } _logger.printElapsedTime(); return configurationData; }
private Map<String, Configuration> convertConfigurations( Map<String, GenericConfigObject> vendorConfigurations, ConvertConfigurationAnswerElement answerElement) { _logger.info("\n*** CONVERTING VENDOR CONFIGURATIONS TO INDEPENDENT FORMAT ***\n"); _logger.resetTimer(); Map<String, Configuration> configurations = new TreeMap<>(); List<ConvertConfigurationJob> jobs = new ArrayList<>(); for (Entry<String, GenericConfigObject> config : vendorConfigurations.entrySet()) { GenericConfigObject vc = config.getValue(); ConvertConfigurationJob job = new ConvertConfigurationJob(_settings, vc, config.getKey()); jobs.add(job); } BatfishJobExecutor.runJobsInExecutor( _settings, _logger, jobs, configurations, answerElement, _settings.getHaltOnConvertError(), "Convert configurations to vendor-independent format"); _logger.printElapsedTime(); return configurations; }
public Set<Flow> computeNodOutput(List<NodJob> jobs) { _logger.info("\n*** EXECUTING NOD JOBS ***\n"); _logger.resetTimer(); Set<Flow> flows = new TreeSet<>(); BatfishJobExecutor.runJobsInExecutor( _settings, _logger, jobs, flows, new NodAnswerElement(), true, "NOD"); _logger.printElapsedTime(); return flows; }
_settings.getHaltOnParseError(), "Parse environment BGP tables"); _logger.printElapsedTime(); return bgpTables;
private SortedMap<String, RoutesByVrf> parseEnvironmentRoutingTables( SortedMap<Path, String> inputData, ParseEnvironmentRoutingTablesAnswerElement answerElement) { _logger.info("\n*** PARSING ENVIRONMENT ROUTING TABLES ***\n"); _logger.resetTimer(); SortedMap<String, RoutesByVrf> routingTables = new TreeMap<>(); List<ParseEnvironmentRoutingTableJob> jobs = new ArrayList<>(); SortedMap<String, Configuration> configurations = loadConfigurations(); for (Entry<Path, String> routingFile : inputData.entrySet()) { Path currentFile = routingFile.getKey(); String fileText = routingFile.getValue(); String hostname = currentFile.getFileName().toString(); if (!configurations.containsKey(hostname)) { continue; } Warnings warnings = buildWarnings(_settings); ParseEnvironmentRoutingTableJob job = new ParseEnvironmentRoutingTableJob(_settings, fileText, currentFile, warnings, this); jobs.add(job); } BatfishJobExecutor.runJobsInExecutor( _settings, _logger, jobs, routingTables, answerElement, _settings.getHaltOnParseError(), "Parse environment routing tables"); _logger.printElapsedTime(); return routingTables; }
_settings.getFlatten() || _settings.getHaltOnParseError(), "Flatten configurations"); _logger.printElapsedTime(); for (Entry<Path, String> e : outputConfigurationData.entrySet()) { Path outputFile = e.getKey();
_settings.getHaltOnParseError(), "Parse configurations"); _logger.printElapsedTime(); return vendorConfigurations;
_logger.printElapsedTime(); return overlayConfigurations;
private void serializeAwsConfigs( Path testRigPath, Path outputPath, ParseVendorConfigurationAnswerElement pvcae) { Map<Path, String> configurationData = readConfigurationFiles(testRigPath, BfConsts.RELPATH_AWS_CONFIGS_DIR); AwsConfiguration config; try (ActiveSpan parseAwsConfigsSpan = GlobalTracer.get().buildSpan("Parse AWS configs").startActive()) { assert parseAwsConfigsSpan != null; // avoid unused warning config = parseAwsConfigurations(configurationData, pvcae); } _logger.info("\n*** SERIALIZING AWS CONFIGURATION STRUCTURES ***\n"); _logger.resetTimer(); outputPath.toFile().mkdirs(); Path currentOutputPath = outputPath.resolve(BfConsts.RELPATH_AWS_CONFIGS_FILE); _logger.debugf("Serializing AWS to \"%s\"...", currentOutputPath); serializeObject(config, currentOutputPath); _logger.debug("OK\n"); _logger.printElapsedTime(); }
_logger.printElapsedTime(); return s;
_logger.printElapsedTime();
private void saveDataPlane( DataPlane dataPlane, DataPlaneAnswerElement answerElement, boolean compressed) { Path dataPlanePath = compressed ? _testrigSettings.getCompressedDataPlanePath() : _testrigSettings.getDataPlanePath(); Path answerElementPath = compressed ? _testrigSettings.getCompressedDataPlaneAnswerPath() : _testrigSettings.getDataPlaneAnswerPath(); Cache<NetworkSnapshot, DataPlane> cache = compressed ? _cachedCompressedDataPlanes : _cachedDataPlanes; cache.put(getNetworkSnapshot(), dataPlane); _logger.resetTimer(); newBatch("Writing data plane to disk", 0); try (ActiveSpan writeDataplane = GlobalTracer.get().buildSpan("Writing data plane").startActive()) { assert writeDataplane != null; // avoid unused warning serializeObject(dataPlane, dataPlanePath); serializeObject(answerElement, answerElementPath); } _logger.printElapsedTime(); }
.setBgpTopology(newResult._bgpTopology) .build(); _bfLogger.printElapsedTime(); return new ComputeDataPlaneResult(answerElement, finalDataplane);