use of com.att.aro.core.exception.TsharkException in project VideoOptimzer by attdevsupport.
the class AROServiceImpl method analyzeFile.
/**
* Launches an analysis of a traceFile with the results populating an
* AROTraceData object
*
* @param requests
* list of BestPracticeType bestPractices to analyze
* @param traceFile
* path to a pcap trace file, usually traffic.cap
* @param profile
* device profile used as a model of the device when analyzing
* trace data
* @param filter
* used for filtering information from a trace analysis based on
* a specified time range and set of ApplicationSelection
* objects.
* @return AROTraceData object
* @throws IOException
* if trace file not found
*/
@Override
public AROTraceData analyzeFile(List<BestPracticeType> requests, String traceFile, Profile profile, AnalysisFilter filter) throws IOException {
AROTraceData data = new AROTraceData();
try {
PacketAnalyzerResult result = packetanalyzer.analyzeTraceFile(traceFile, profile, filter);
if (result == null) {
data.setError(ErrorCodeRegistry.getTraceFileNotAnalyzed());
} else {
if (result.getTraceresult().getAllpackets().size() == 0) {
// we set on purpose
data.setError(ErrorCodeRegistry.getUnRecognizedPackets());
data.setSuccess(false);
} else {
List<AbstractBestPracticeResult> bestPractices = analyze(result, requests);
bestPractices.addAll(createEmptyResults());
data.setAnalyzerResult(result);
data.setBestPracticeResults(bestPractices);
data.setSuccess(true);
}
}
} catch (TsharkException ex) {
data.setError(ErrorCodeRegistry.getWiresharkError());
}
return data;
}
use of com.att.aro.core.exception.TsharkException in project VideoOptimzer by attdevsupport.
the class AROServiceImpl method analyzeDirectory.
/**
* Launches an analysis of a trace directory with the results populating an
* AROTraceData object.
* <p>
* Other trace files depend on capture method, platform and version of
* device.
* </p>
*
* @param requests
* list of BestPracticeType bestPractices to analyze
* @param traceDirectory
* path to a trace directory, usually contains traffic.cap
* @param profile
* device profile used as a model of the device when analyzing
* trace data
* @param filter
* used for filtering information from a trace analysis based on
* a specified time range and set of ApplicationSelection
* objects.
* @return AROTraceData object
* @throws IOException
* if trace file not found
*/
@Override
public AROTraceData analyzeDirectory(List<BestPracticeType> requests, String traceDirectory, Profile profile, AnalysisFilter filter) throws IOException {
AROTraceData data = new AROTraceData();
PacketAnalyzerResult result = null;
if (!filemanager.fileExist(traceDirectory + Util.FILE_SEPARATOR + "traffic.cap")) {
data.setError(ErrorCodeRegistry.getTrafficFileNotFound());
data.setSuccess(false);
} else {
try {
result = packetanalyzer.analyzeTraceDirectory(traceDirectory, profile, filter);
} catch (FileNotFoundException ex) {
data.setError(ErrorCodeRegistry.getTraceDirNotFound());
return data;
} catch (TsharkException ex) {
data.setError(ErrorCodeRegistry.getWiresharkError());
return data;
}
if (result == null) {
data.setError(ErrorCodeRegistry.getTraceDirectoryNotAnalyzed());
data.setSuccess(false);
} else {
if (result.getTraceresult() == null) {
// we set this on purpose
data.setSuccess(false);
data.setError(ErrorCodeRegistry.getUnRecognizedPackets());
} else if (result.getTraceresult().getAllpackets() == null || result.getTraceresult().getAllpackets().size() == 0) {
data.setSuccess(false);
data.setError(ErrorCodeRegistry.getPacketsNotFound());
} else {
List<AbstractBestPracticeResult> bestPractices = analyze(result, requests);
bestPractices.addAll(createEmptyResults());
data.setAnalyzerResult(result);
data.setBestPracticeResults(bestPractices);
data.setSuccess(true);
}
}
}
return data;
}
use of com.att.aro.core.exception.TsharkException in project VideoOptimzer by attdevsupport.
the class PacketReaderLibraryImpl method readPacket.
@Override
public void readPacket(String packetfile, IPacketListener listener) throws IOException {
// windows dependency only
if (Util.isWindowsOS()) {
checkNativeLib();
}
FileDetails fileDetails = parseFileDetails(packetfile);
if (!fileDetails.isPcap() && !fileDetails.isPcapNG()) {
LOGGER.error("Not a valid pcap file " + packetfile);
return;
}
long start = System.currentTimeMillis();
// Update system property org.pcap4j.af.inet6 to correct value based on original OS which captured pcap/pcapng file
identifyOSInfo(packetfile);
if (fileDetails.isPcap) {
PcapHandle handle = null;
try {
handle = Pcaps.openOffline(packetfile);
} catch (PcapNativeException e) {
LOGGER.error("Error while reading pcap file " + packetfile, e);
return;
} catch (Exception ee) {
LOGGER.error("Error unknow " + packetfile, ee);
return;
}
try {
int currentPacketNumber = 0;
int totalPacketReads = 0;
while (true) {
try {
++currentPacketNumber;
Packet pcap4jPacket = handle.getNextPacketEx();
// Get last packet's capture timestamp
Timestamp timestamp = handle.getTimestamp();
com.att.aro.core.packetreader.pojo.Packet packet = translatePcap4jPacket(timestamp.getTime() / 1000, timestamp.getNanos() / 1000, pcap4jPacket);
++totalPacketReads;
listener.packetArrived(null, packet);
} catch (EOFException e) {
LOGGER.info(String.format("Finished reading total %d packets out of %d packets for pcap file %s", totalPacketReads, currentPacketNumber - 1, packetfile));
break;
} catch (Exception ex) {
LOGGER.debug("Error while reading packet number " + currentPacketNumber, ex);
}
}
} catch (Exception e) {
LOGGER.error("Error while reading pcap file " + packetfile, e);
} finally {
handle.close();
}
} else {
TSharkConfirmationImpl tsharkConfirmation = new TSharkConfirmationImpl(externalProcessRunner);
if (!tsharkConfirmation.checkTsharkVersion()) {
throw new TsharkException("Wireshark is either not installed on your machine or its not in your path.");
}
handlePCAPNGFile(packetfile, listener);
}
LOGGER.info("Time to read pcap file in ms: " + (System.currentTimeMillis() - start));
}
use of com.att.aro.core.exception.TsharkException in project VideoOptimzer by attdevsupport.
the class Application method runAnalyzer.
/**
* Analyze a trace and produce a report either in json or html<br>
*
* <pre>
* Required command:
* --analyze with path to trace directory of traffic.cap
* --output output file, error if missing
* --format html or json, if missing defaults to json
*
* @param context
* - Spring ApplicationContext
* @param cmds
* - user commands
*/
void runAnalyzer(ApplicationContext context, Commands cmds) {
String trace = cmds.getAnalyze();
IAROService serv = context.getBean(IAROService.class);
AROTraceData results = null;
// analyze trace file or directory?
OutSave outSave = prepareSystemOut();
ImHereThread imHereThread = new ImHereThread(outSave.getOut(), Logger.getRootLogger());
try {
if (serv.isFile(trace)) {
try {
results = serv.analyzeFile(retrieveBestPractices(), trace);
} catch (IOException | TsharkException e) {
errln("Error occured analyzing trace, detail: " + e.getMessage());
System.exit(1);
}
} else {
try {
results = serv.analyzeDirectory(retrieveBestPractices(), trace);
} catch (IOException e) {
errln("Error occured analyzing trace directory, detail: " + e.getMessage());
System.exit(1);
}
}
if (results != null && results.isSuccess()) {
outSave = prepareSystemOut();
if (cmds.getFormat().equals("json")) {
if (serv.getJSonReport(cmds.getOutput(), results)) {
outln("Successfully produced JSON report: " + cmds.getOutput());
} else {
errln("Failed to produce JSON report.");
}
} else {
if (serv.getHtmlReport(cmds.getOutput(), results)) {
println("Successfully produced HTML report: " + cmds.getOutput());
} else {
errln("Failed to produce HTML report.");
}
}
} else {
printError(results == null ? new ErrorCode() : results.getError());
}
} finally {
imHereThread.endIndicator();
while (imHereThread.isRunning()) {
Thread.yield();
}
restoreSystemOut(outSave);
}
System.exit(0);
}
Aggregations