use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class BdpDataPlanePlugin method computeDataPlane.
@Override
public ComputeDataPlaneResult computeDataPlane(boolean differentialContext) {
Map<String, Configuration> configurations = _batfish.loadConfigurations();
Topology topology = _batfish.getEnvironmentTopology();
return computeDataPlane(differentialContext, configurations, topology);
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class NodesSpecifierTest method getMatchingNodesName.
@Test
public void getMatchingNodesName() {
NodesSpecifier specifier = new NodesSpecifier("name:lhr-.*");
Map<String, Configuration> configurations = new HashMap<>();
String matchingRouter = "lhr-border1";
String nonMatchingRouter1 = "svr-border1";
String nonMatchingRouter2 = "svr-border2";
Configuration matching = new Configuration(matchingRouter, ConfigurationFormat.UNKNOWN);
Configuration nonMatching1 = new Configuration(nonMatchingRouter1, ConfigurationFormat.UNKNOWN);
Configuration nonMatching2 = new Configuration(nonMatchingRouter2, ConfigurationFormat.UNKNOWN);
// to check for accidental role matching
nonMatching2.getRoles().add("lhr-border1");
configurations.put(matchingRouter, matching);
configurations.put(nonMatchingRouter1, nonMatching1);
configurations.put(nonMatchingRouter2, nonMatching2);
Set<String> matchingNodes = specifier.getMatchingNodes(configurations);
assertThat(matchingNodes, hasItem(matchingRouter));
assertThat(matchingNodes, not(hasItem(nonMatchingRouter1)));
assertThat(matchingNodes, not(hasItem(nonMatchingRouter2)));
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class NodesSpecifierTest method getMatchingNodesRole.
@Test
public void getMatchingNodesRole() {
NodesSpecifier specifier = new NodesSpecifier("role:svr.*");
Map<String, Configuration> configurations = new HashMap<>();
String matchingRouter = "lhr-border1";
// name shouldn't match role
String nonMatchingRouter1 = "svr-border1";
String nonMatchingRouter2 = "lhr-border2";
Configuration matching = new Configuration(matchingRouter, ConfigurationFormat.UNKNOWN);
matching.getRoles().add("svr-web");
Configuration nonMatching1 = new Configuration(nonMatchingRouter1, ConfigurationFormat.UNKNOWN);
matching.getRoles().add("web");
Configuration nonMatching2 = new Configuration(nonMatchingRouter2, ConfigurationFormat.UNKNOWN);
nonMatching2.getRoles().add("rtr");
configurations.put(matchingRouter, matching);
configurations.put(nonMatchingRouter1, nonMatching1);
configurations.put(nonMatchingRouter2, nonMatching2);
Set<String> matchingNodes = specifier.getMatchingNodes(configurations);
assertThat(matchingNodes, hasItem(matchingRouter));
assertThat(matchingNodes, not(hasItem(nonMatchingRouter1)));
assertThat(matchingNodes, not(hasItem(nonMatchingRouter2)));
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class Batfish method convertConfigurations.
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;
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class Batfish method computeCompressedDataPlane.
private CompressDataPlaneResult computeCompressedDataPlane(HeaderSpace headerSpace) {
// Since compression mutates the configurations, we must clone them before that happens.
// A simple way to do this is to create a deep clone of each entry using Java serialization.
_logger.info("Computing compressed dataplane");
Map<String, Configuration> clonedConfigs = loadConfigurations().entrySet().parallelStream().collect(toMap(Entry::getKey, entry -> SerializationUtils.clone(entry.getValue())));
Map<String, Configuration> configs = new BatfishCompressor(this, clonedConfigs).compress(headerSpace);
Topology topo = CommonUtil.synthesizeTopology(configs);
DataPlanePlugin dataPlanePlugin = getDataPlanePlugin();
ComputeDataPlaneResult result = dataPlanePlugin.computeDataPlane(false, configs, topo);
_storage.storeCompressedConfigurations(configs, _testrigSettings.getName());
return new CompressDataPlaneResult(configs, result._dataPlane, result._answerElement);
}
Aggregations