use of org.batfish.common.Warning in project batfish by batfish.
the class ConvertConfigurationAnswerElement method prettyPrint.
@Override
public String prettyPrint() {
StringBuilder sb = new StringBuilder("Results from converting vendor configurations\n");
_warnings.forEach((name, warnings) -> {
sb.append("\n " + name + "[Conversion warnings]\n");
for (Warning warning : warnings.getRedFlagWarnings()) {
sb.append(" RedFlag " + warning.getTag() + " : " + warning.getText() + "\n");
}
for (Warning warning : warnings.getUnimplementedWarnings()) {
sb.append(" Unimplemented " + warning.getTag() + " : " + warning.getText() + "\n");
}
for (Warning warning : warnings.getPedanticWarnings()) {
sb.append(" Pedantic " + warning.getTag() + " : " + warning.getText() + "\n");
}
});
_errors.forEach((name, errors) -> {
sb.append("\n " + name + "[Conversion errors]\n");
for (String line : errors.getLineMap()) {
sb.append(" " + line + "\n");
}
});
_undefinedReferences.forEach((hostname, byType) -> {
sb.append("\n " + hostname + "[Undefined references]\n");
byType.forEach((type, byName) -> {
sb.append(" " + type + ":\n");
byName.forEach((name, byUsage) -> {
sb.append(" " + name + ":\n");
byUsage.forEach((usage, lines) -> {
sb.append(" " + usage + ": lines " + lines + "\n");
});
});
});
});
_unusedStructures.forEach((hostname, byType) -> {
sb.append("\n " + hostname + "[Unused structures]\n");
byType.forEach((structureType, byName) -> {
byName.forEach((name, lines) -> {
sb.append(" " + structureType + ": " + name + ":" + lines + "\n");
});
});
});
return sb.toString();
}
use of org.batfish.common.Warning in project batfish by batfish.
the class Batfish method serializeNetworkConfigs.
private void serializeNetworkConfigs(Path testRigPath, Path outputPath, ParseVendorConfigurationAnswerElement answerElement, SortedMap<String, VendorConfiguration> overlayHostConfigurations) {
Map<Path, String> configurationData = readConfigurationFiles(testRigPath, BfConsts.RELPATH_CONFIGURATIONS_DIR);
Map<String, VendorConfiguration> vendorConfigurations;
try (ActiveSpan parseNetworkConfigsSpan = GlobalTracer.get().buildSpan("Parse network configs").startActive()) {
// avoid unused warning
assert parseNetworkConfigsSpan != null;
vendorConfigurations = parseVendorConfigurations(configurationData, answerElement, ConfigurationFormat.UNKNOWN);
}
if (vendorConfigurations == null) {
throw new BatfishException("Exiting due to parser errors");
}
_logger.infof("Testrig:%s in container:%s has total number of network configs:%d", getTestrigName(), getContainerName(), vendorConfigurations.size());
_logger.info("\n*** SERIALIZING VENDOR CONFIGURATION STRUCTURES ***\n");
_logger.resetTimer();
CommonUtil.createDirectories(outputPath);
Map<Path, VendorConfiguration> output = new TreeMap<>();
vendorConfigurations.forEach((name, vc) -> {
if (name.contains(File.separator)) {
// iptables will get a hostname like configs/iptables-save if they
// are not set up correctly using host files
_logger.errorf("Cannot serialize configuration with hostname %s\n", name);
answerElement.addRedFlagWarning(name, new Warning("Cannot serialize network config. Bad hostname " + name.replace("\\", "/"), "MISCELLANEOUS"));
} else {
// apply overlay if it exists
VendorConfiguration overlayConfig = overlayHostConfigurations.get(name);
if (overlayConfig != null) {
vc.setOverlayConfiguration(overlayConfig);
overlayHostConfigurations.remove(name);
}
Path currentOutputPath = outputPath.resolve(name);
output.put(currentOutputPath, vc);
}
});
// warn about unused overlays
overlayHostConfigurations.forEach((name, overlay) -> {
answerElement.getParseStatus().put(name, ParseStatus.ORPHANED);
});
serializeObjects(output);
_logger.printElapsedTime();
}
use of org.batfish.common.Warning in project batfish by batfish.
the class Batfish method serializeHostConfigs.
private SortedMap<String, VendorConfiguration> serializeHostConfigs(Path testRigPath, Path outputPath, ParseVendorConfigurationAnswerElement answerElement) {
SortedMap<Path, String> configurationData = readConfigurationFiles(testRigPath, BfConsts.RELPATH_HOST_CONFIGS_DIR);
// read the host files
SortedMap<String, VendorConfiguration> allHostConfigurations;
try (ActiveSpan parseHostConfigsSpan = GlobalTracer.get().buildSpan("Parse host configs").startActive()) {
// avoid unused warning
assert parseHostConfigsSpan != null;
allHostConfigurations = parseVendorConfigurations(configurationData, answerElement, ConfigurationFormat.HOST);
}
if (allHostConfigurations == null) {
throw new BatfishException("Exiting due to parser errors");
}
_logger.infof("Testrig:%s in container:%s has total number of host configs:%d", getTestrigName(), getContainerName(), allHostConfigurations.size());
// split into hostConfigurations and overlayConfigurations
SortedMap<String, VendorConfiguration> overlayConfigurations = allHostConfigurations.entrySet().stream().filter(e -> ((HostConfiguration) e.getValue()).getOverlay()).collect(toMap(Entry::getKey, Entry::getValue, (v1, v2) -> v1, TreeMap::new));
SortedMap<String, VendorConfiguration> nonOverlayHostConfigurations = allHostConfigurations.entrySet().stream().filter(e -> !((HostConfiguration) e.getValue()).getOverlay()).collect(toMap(Entry::getKey, Entry::getValue, (v1, v2) -> v1, TreeMap::new));
// read and associate iptables files for specified hosts
SortedMap<Path, String> iptablesData = new TreeMap<>();
readIptableFiles(testRigPath, allHostConfigurations, iptablesData, answerElement);
SortedMap<String, VendorConfiguration> iptablesConfigurations = parseVendorConfigurations(iptablesData, answerElement, ConfigurationFormat.IPTABLES);
for (VendorConfiguration vc : allHostConfigurations.values()) {
HostConfiguration hostConfig = (HostConfiguration) vc;
if (hostConfig.getIptablesFile() != null) {
Path path = Paths.get(testRigPath.toString(), hostConfig.getIptablesFile());
String relativePathStr = _testrigSettings.getBasePath().relativize(path).toString();
if (iptablesConfigurations.containsKey(relativePathStr)) {
hostConfig.setIptablesVendorConfig((IptablesVendorConfiguration) iptablesConfigurations.get(relativePathStr));
}
}
}
// now, serialize
_logger.info("\n*** SERIALIZING VENDOR CONFIGURATION STRUCTURES ***\n");
_logger.resetTimer();
CommonUtil.createDirectories(outputPath);
Map<Path, VendorConfiguration> output = new TreeMap<>();
nonOverlayHostConfigurations.forEach((name, vc) -> {
Path currentOutputPath = outputPath.resolve(name);
output.put(currentOutputPath, vc);
});
serializeObjects(output);
// serialize warnings
serializeObject(answerElement, _testrigSettings.getParseAnswerPath());
_logger.printElapsedTime();
return overlayConfigurations;
}
use of org.batfish.common.Warning in project batfish by batfish.
the class InitInfoAnswerElement method prettyPrint.
@Override
public String prettyPrint() {
final StringBuilder sb = new StringBuilder();
int pedanticCount = 0;
int redFlagCount = 0;
int unimplementedCount = 0;
int emptyCount = 0;
int failedCount = 0;
int ignoredCount = 0;
int orphanedCount = 0;
int passedCount = 0;
int unknownCount = 0;
int unrecognizedCount = 0;
int unsupportedCount = 0;
if (!_warnings.isEmpty()) {
sb.append("DETAILED WARNINGS\n");
for (String name : _warnings.keySet()) {
sb.append(" " + name + ":\n");
for (Warning warning : _warnings.get(name).getRedFlagWarnings()) {
sb.append(" RedFlag " + warning.getTag() + " : " + warning.getText() + "\n");
redFlagCount++;
}
for (Warning warning : _warnings.get(name).getUnimplementedWarnings()) {
sb.append(" Unimplemented " + warning.getTag() + " : " + warning.getText() + "\n");
unimplementedCount++;
}
for (Warning warning : _warnings.get(name).getPedanticWarnings()) {
sb.append(" Pedantic " + warning.getTag() + " : " + warning.getText() + "\n");
pedanticCount++;
}
}
}
sb.append("PARSING SUMMARY\n");
for (Entry<String, ParseStatus> e : _parseStatus.entrySet()) {
String hostname = e.getKey();
ParseStatus status = e.getValue();
switch(status) {
case FAILED:
sb.append(" " + hostname + ": failed to parse\n");
failedCount++;
break;
case PARTIALLY_UNRECOGNIZED:
sb.append(" " + hostname + ": contained at least one unrecognized line\n");
unrecognizedCount++;
break;
case PASSED:
passedCount++;
break;
case EMPTY:
sb.append(" " + hostname + ": empty file\n");
emptyCount++;
break;
case IGNORED:
sb.append(" " + hostname + ": explicitly ignored by user\n");
ignoredCount++;
break;
case ORPHANED:
sb.append(" " + hostname + ": is an orphaned overlay configuration\n");
orphanedCount++;
break;
case UNKNOWN:
sb.append(" " + hostname + ": unknown configuration format\n");
unknownCount++;
break;
case UNSUPPORTED:
sb.append(" " + hostname + ": known but unsupported configuration format\n");
unsupportedCount++;
break;
default:
break;
}
}
if (!_errors.isEmpty()) {
sb.append("DETAILED ERRORS\n");
for (String name : _errors.keySet()) {
sb.append(" Failed to parse " + name + ":\n");
for (BatfishStackTrace stackTrace : _errors.get(name)) {
for (String line : stackTrace.getLineMap()) {
sb.append(" " + line + "\n");
}
}
}
}
sb.append("STATISTICS\n");
if (!_warnings.isEmpty()) {
sb.append(" Total warnings:\n");
if (redFlagCount > 0) {
sb.append(" Red Flag: " + redFlagCount + "\n");
}
if (unimplementedCount > 0) {
sb.append(" Unimplemented: " + unimplementedCount + "\n");
}
if (pedanticCount > 0) {
sb.append(" Pedantic: " + pedanticCount + "\n");
}
}
sb.append(" Parsing results:\n");
if (passedCount > 0) {
sb.append(" Parsed successfully: " + passedCount + "\n");
}
if (unrecognizedCount > 0) {
sb.append(" Contained unrecognized line(s): " + unrecognizedCount + "\n");
}
if (emptyCount > 0) {
sb.append(" Empty file: " + emptyCount + "\n");
}
if (ignoredCount > 0) {
sb.append(" Explicitly ignored by user: " + ignoredCount + "\n");
}
if (orphanedCount > 0) {
sb.append(" Is an orphaned overlay configuration: " + orphanedCount + "\n");
}
if (failedCount > 0) {
sb.append(" Failed to parse: " + failedCount + "\n");
}
if (unknownCount > 0) {
sb.append(" Unknown configuration format: " + unknownCount + "\n");
}
if (unsupportedCount > 0) {
sb.append(" Known but unsupported configuration format: " + unsupportedCount + "\n");
}
return sb.toString();
}
Aggregations